Source/WebCore/ChangeLog

 12019-07-26 Justin Fan <justin_fan@apple.com>
 2
 3 [WebGPU] Update GPUComputePipeline errors to match GPURenderPipeline implementation
 4 https://bugs.webkit.org/show_bug.cgi?id=200097
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 Remove passing around a functionName in GPUComputePipeline creation in favor of setting it on the GPUErrorScopes.
 9 Also, WebGPU objects no longer create new Ref<>s unless object creation succeeds.
 10
 11 No new tests. Covered by existing tests.
 12
 13 * Modules/webgpu/WebGPUDevice.cpp:
 14 (WebCore::WebGPUDevice::createBuffer const):
 15 (WebCore::WebGPUDevice::createBufferMapped const):
 16 (WebCore::WebGPUDevice::createComputePipeline const):
 17 * platform/graphics/gpu/GPUBuffer.h:
 18 * platform/graphics/gpu/GPUComputePipeline.h:
 19 * platform/graphics/gpu/GPUDevice.cpp:
 20 (WebCore::GPUDevice::tryCreateBuffer):
 21 (WebCore::GPUDevice::tryCreateComputePipeline const):
 22 * platform/graphics/gpu/GPUDevice.h:
 23 * platform/graphics/gpu/GPUErrorScopes.cpp:
 24 (WebCore::GPUErrorScopes::generatePrefixedError): Only validaton errors have messages right now.
 25 * platform/graphics/gpu/GPUErrorScopes.h:
 26 * platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
 27 (WebCore::GPUBuffer::validateBufferUsage):
 28 (WebCore::GPUBuffer::tryCreate):
 29 (WebCore::GPUBuffer::GPUBuffer):
 30 * platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm:
 31 (WebCore::trySetMetalFunctions):
 32 (WebCore::trySetFunctions):
 33 (WebCore::convertComputePipelineDescriptor):
 34 (WebCore::tryCreateMTLComputePipelineState):
 35 (WebCore::GPUComputePipeline::tryCreate):
 36 (WebCore::GPUComputePipeline::GPUComputePipeline):
 37 * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
 38 (WebCore::trySetMetalFunctions):
 39 (WebCore::trySetFunctions):
 40
 41 These classes were made RefCounted in a previous patch; remove their move ctors to fix build.
 42 * Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h:
 43 * Modules/webgpu/WHLSL/AST/WHLSLArrayType.h:
 44 * Modules/webgpu/WHLSL/AST/WHLSLPointerType.h:
 45 * Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
 46 * Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
 47 * Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h:
 48
1492019-07-26 Brady Eidson <beidson@apple.com>
250
351 Do not fire readystatechange events at documents about to get replaced by javascript URLs.

Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h

@@public:
5656 virtual ~ArrayReferenceType() = default;
5757
5858 ArrayReferenceType(const ArrayReferenceType&) = delete;
59  ArrayReferenceType(ArrayReferenceType&&) = default;
6059
6160 bool isArrayReferenceType() const override { return true; }
6261

Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayType.h

@@public:
5858 virtual ~ArrayType() = default;
5959
6060 ArrayType(const ArrayType&) = delete;
61  ArrayType(ArrayType&&) = default;
6261
6362 bool isArrayType() const override { return true; }
6463

Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPointerType.h

@@public:
5757 virtual ~PointerType() = default;
5858
5959 PointerType(const PointerType&) = delete;
60  PointerType(PointerType&&) = default;
6160
6261 bool isPointerType() const override { return true; }
6362

Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h

@@public:
5454 virtual ~ReferenceType() = default;
5555
5656 ReferenceType(const ReferenceType&) = delete;
57  ReferenceType(ReferenceType&&) = default;
5857
5958 bool isReferenceType() const override { return true; }
6059

Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h

@@public:
6060 virtual ~TypeReference() = default;
6161
6262 TypeReference(const TypeReference&) = delete;
63  TypeReference(TypeReference&&) = default;
6463
6564 static Ref<TypeReference> wrap(CodeLocation, NamedType& resolvedType);
6665

Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h

@@public:
5151 virtual ~UnnamedType() = default;
5252
5353 UnnamedType(const UnnamedType&) = delete;
54  UnnamedType(UnnamedType&&) = default;
5554
5655 bool isUnnamedType() const override { return true; }
5756 virtual bool isTypeReference() const { return false; }

Source/WebCore/Modules/webgpu/WebGPUDevice.cpp

@@WebGPUDevice::WebGPUDevice(Ref<const WebGPUAdapter>&& adapter, Ref<GPUDevice>&&
8787
8888Ref<WebGPUBuffer> WebGPUDevice::createBuffer(const GPUBufferDescriptor& descriptor) const
8989{
90  auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::NotMapped, m_errorScopes.copyRef());
 90 m_errorScopes->setErrorPrefix("GPUDevice.createBuffer(): ");
 91
 92 auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::NotMapped, m_errorScopes);
9193 return WebGPUBuffer::create(WTFMove(buffer));
9294}
9395
9496Vector<JSC::JSValue> WebGPUDevice::createBufferMapped(JSC::ExecState& state, const GPUBufferDescriptor& descriptor) const
9597{
 98 m_errorScopes->setErrorPrefix("GPUDevice.createBufferMapped(): ");
 99
96100 JSC::JSValue wrappedArrayBuffer = JSC::jsNull();
97101
98  auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::IsMapped, m_errorScopes.copyRef());
 102 auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::IsMapped, m_errorScopes);
99103 if (buffer) {
100104 auto arrayBuffer = buffer->mapOnCreation();
101105 wrappedArrayBuffer = toJS(&state, JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject()), arrayBuffer);

@@Ref<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(const WebGPURenderP
166170
167171Ref<WebGPUComputePipeline> WebGPUDevice::createComputePipeline(const WebGPUComputePipelineDescriptor& descriptor) const
168172{
 173 m_errorScopes->setErrorPrefix("GPUDevice.createComputePipeline(): ");
 174
169175 auto gpuDescriptor = descriptor.tryCreateGPUComputePipelineDescriptor(m_errorScopes);
170176 if (!gpuDescriptor)
171177 return WebGPUComputePipeline::create(nullptr);
172178
173  auto pipeline = m_device->tryCreateComputePipeline(*gpuDescriptor, m_errorScopes.copyRef());
 179 auto pipeline = m_device->tryCreateComputePipeline(*gpuDescriptor, m_errorScopes);
174180 return WebGPUComputePipeline::create(WTFMove(pipeline));
175181}
176182

Source/WebCore/platform/graphics/gpu/GPUBuffer.h

@@public:
7171
7272 ~GPUBuffer();
7373
74  static RefPtr<GPUBuffer> tryCreate(Ref<GPUDevice>&&, const GPUBufferDescriptor&, GPUBufferMappedOption, Ref<GPUErrorScopes>&&);
 74 static RefPtr<GPUBuffer> tryCreate(GPUDevice&, const GPUBufferDescriptor&, GPUBufferMappedOption, GPUErrorScopes&);
7575
7676 PlatformBuffer *platformBuffer() const { return m_platformBuffer.get(); }
7777 size_t byteLength() const { return m_byteLength; }

@@private:
110110 PendingMappingCallback(MappingCallback&&);
111111 };
112112
113  GPUBuffer(PlatformBufferSmartPtr&&, Ref<GPUDevice>&&, size_t, OptionSet<GPUBufferUsage::Flags>, GPUBufferMappedOption, Ref<GPUErrorScopes>&&);
 113 GPUBuffer(PlatformBufferSmartPtr&&, GPUDevice&, size_t, OptionSet<GPUBufferUsage::Flags>, GPUBufferMappedOption, GPUErrorScopes&);
114114 static bool validateBufferUsage(const GPUDevice&, OptionSet<GPUBufferUsage::Flags>, GPUErrorScopes&);
115115
116116 JSC::ArrayBuffer* stagingBufferForRead();

Source/WebCore/platform/graphics/gpu/GPUComputePipeline.h

@@using PlatformComputePipelineSmartPtr = RetainPtr<MTLComputePipelineState>;
4646
4747class GPUComputePipeline : public GPUObjectBase {
4848public:
49  static RefPtr<GPUComputePipeline> tryCreate(const GPUDevice&, const GPUComputePipelineDescriptor&, Ref<GPUErrorScopes>&&);
 49 static RefPtr<GPUComputePipeline> tryCreate(const GPUDevice&, const GPUComputePipelineDescriptor&, GPUErrorScopes&);
5050
5151 const PlatformComputePipeline* platformComputePipeline() const { return m_platformComputePipeline.get(); }
5252
5353 WHLSL::ComputeDimensions computeDimensions() const { return m_computeDimensions; }
5454
5555private:
56  GPUComputePipeline(PlatformComputePipelineSmartPtr&&, WHLSL::ComputeDimensions, Ref<GPUErrorScopes>&&);
 56 GPUComputePipeline(PlatformComputePipelineSmartPtr&&, WHLSL::ComputeDimensions, GPUErrorScopes&);
5757
5858 PlatformComputePipelineSmartPtr m_platformComputePipeline;
5959 WHLSL::ComputeDimensions m_computeDimensions { 0, 0, 0 };

Source/WebCore/platform/graphics/gpu/GPUDevice.cpp

5252
5353namespace WebCore {
5454
55 RefPtr<GPUBuffer> GPUDevice::tryCreateBuffer(const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, Ref<GPUErrorScopes>&& errorScopes)
 55RefPtr<GPUBuffer> GPUDevice::tryCreateBuffer(const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, GPUErrorScopes& errorScopes)
5656{
57  return GPUBuffer::tryCreate(makeRef(*this), descriptor, isMapped, WTFMove(errorScopes));
 57 return GPUBuffer::tryCreate(*this, descriptor, isMapped, errorScopes);
5858}
5959
6060RefPtr<GPUTexture> GPUDevice::tryCreateTexture(const GPUTextureDescriptor& descriptor) const

@@RefPtr<GPURenderPipeline> GPUDevice::tryCreateRenderPipeline(const GPURenderPipe
8787 return GPURenderPipeline::tryCreate(*this, descriptor, errorScopes);
8888}
8989
90 RefPtr<GPUComputePipeline> GPUDevice::tryCreateComputePipeline(const GPUComputePipelineDescriptor& descriptor, Ref<GPUErrorScopes>&& errorScopes) const
 90RefPtr<GPUComputePipeline> GPUDevice::tryCreateComputePipeline(const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes) const
9191{
92  return GPUComputePipeline::tryCreate(*this, descriptor, WTFMove(errorScopes));
 92 return GPUComputePipeline::tryCreate(*this, descriptor, errorScopes);
9393}
9494
9595RefPtr<GPUCommandBuffer> GPUDevice::tryCreateCommandBuffer() const

Source/WebCore/platform/graphics/gpu/GPUDevice.h

@@class GPUDevice : public RefCounted<GPUDevice>, public CanMakeWeakPtr<GPUDevice>
7070public:
7171 static RefPtr<GPUDevice> tryCreate(const Optional<GPURequestAdapterOptions>&);
7272
73  RefPtr<GPUBuffer> tryCreateBuffer(const GPUBufferDescriptor&, GPUBufferMappedOption, Ref<GPUErrorScopes>&&);
 73 RefPtr<GPUBuffer> tryCreateBuffer(const GPUBufferDescriptor&, GPUBufferMappedOption, GPUErrorScopes&);
7474 RefPtr<GPUTexture> tryCreateTexture(const GPUTextureDescriptor&) const;
7575 RefPtr<GPUSampler> tryCreateSampler(const GPUSamplerDescriptor&) const;
7676

@@public:
7979
8080 RefPtr<GPUShaderModule> tryCreateShaderModule(const GPUShaderModuleDescriptor&) const;
8181 RefPtr<GPURenderPipeline> tryCreateRenderPipeline(const GPURenderPipelineDescriptor&, GPUErrorScopes&) const;
82  RefPtr<GPUComputePipeline> tryCreateComputePipeline(const GPUComputePipelineDescriptor&, Ref<GPUErrorScopes>&&) const;
 82 RefPtr<GPUComputePipeline> tryCreateComputePipeline(const GPUComputePipelineDescriptor&, GPUErrorScopes&) const;
8383
8484 RefPtr<GPUCommandBuffer> tryCreateCommandBuffer() const;
8585

Source/WebCore/platform/graphics/gpu/GPUErrorScopes.cpp

@@void GPUErrorScopes::generateError(const String& message, GPUErrorFilter filter)
6363 iterator->error = createError(filter, message);
6464}
6565
66 void GPUErrorScopes::generatePrefixedError(const String& message, GPUErrorFilter filter)
 66void GPUErrorScopes::generatePrefixedError(const String& message)
6767{
68  generateError(m_prefix + message, filter);
 68 generateError(m_prefix + message, GPUErrorFilter::Validation);
6969}
7070
7171} // namespace WebCore

Source/WebCore/platform/graphics/gpu/GPUErrorScopes.h

@@public:
4545 Optional<GPUError> popErrorScope(String& failMessage);
4646
4747 void generateError(const String&, GPUErrorFilter = GPUErrorFilter::Validation);
48  void generatePrefixedError(const String&, GPUErrorFilter = GPUErrorFilter::Validation);
 48 void generatePrefixedError(const String&);
4949 void setErrorPrefix(const String& prefix) { m_prefix = prefix; }
5050
5151private:

Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm

@@bool GPUBuffer::validateBufferUsage(const GPUDevice& device, OptionSet<GPUBuffer
5050 }
5151
5252 if (usage.containsAll({ GPUBufferUsage::Flags::MapWrite, GPUBufferUsage::Flags::MapRead })) {
53  errorScopes.generateError("GPUBuffer::tryCreate(): Buffer cannot have both MAP_READ and MAP_WRITE usage!");
 53 errorScopes.generatePrefixedError("Buffer cannot have both MAP_READ and MAP_WRITE usage!");
5454 return false;
5555 }
5656

@@bool GPUBuffer::validateBufferUsage(const GPUDevice& device, OptionSet<GPUBuffer
6262 return true;
6363}
6464
65 RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, Ref<GPUErrorScopes>&& errorScopes)
 65RefPtr<GPUBuffer> GPUBuffer::tryCreate(GPUDevice& device, const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, GPUErrorScopes& errorScopes)
6666{
6767 // MTLBuffer size (NSUInteger) is 32 bits on some platforms.
6868 NSUInteger size = 0;
6969 if (!WTF::convertSafely(descriptor.size, size)) {
70  errorScopes->generateError("", GPUErrorFilter::OutOfMemory);
 70 errorScopes.generateError("", GPUErrorFilter::OutOfMemory);
7171 return nullptr;
7272 }
7373
7474 auto usage = OptionSet<GPUBufferUsage::Flags>::fromRaw(descriptor.usage);
75  if (!validateBufferUsage(device.get(), usage, errorScopes))
 75 if (!validateBufferUsage(device, usage, errorScopes))
7676 return nullptr;
7777
7878#if PLATFORM(MAC)

@@RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferD
9797
9898 BEGIN_BLOCK_OBJC_EXCEPTIONS;
9999
100  mtlBuffer = adoptNS([device->platformDevice() newBufferWithLength:static_cast<NSUInteger>(descriptor.size) options:resourceOptions]);
 100 mtlBuffer = adoptNS([device.platformDevice() newBufferWithLength:static_cast<NSUInteger>(descriptor.size) options:resourceOptions]);
101101
102102 END_BLOCK_OBJC_EXCEPTIONS;
103103
104104 if (!mtlBuffer) {
105  errorScopes->generateError("", GPUErrorFilter::OutOfMemory);
 105 errorScopes.generateError("", GPUErrorFilter::OutOfMemory);
106106 return nullptr;
107107 }
108108
109  return adoptRef(*new GPUBuffer(WTFMove(mtlBuffer), WTFMove(device), size, usage, isMapped, WTFMove(errorScopes)));
 109 return adoptRef(*new GPUBuffer(WTFMove(mtlBuffer), device, size, usage, isMapped, errorScopes));
110110}
111111
112 GPUBuffer::GPUBuffer(RetainPtr<MTLBuffer>&& buffer, Ref<GPUDevice>&& device, size_t size, OptionSet<GPUBufferUsage::Flags> usage, GPUBufferMappedOption isMapped, Ref<GPUErrorScopes>&& errorScopes)
113  : GPUObjectBase(WTFMove(errorScopes))
 112GPUBuffer::GPUBuffer(RetainPtr<MTLBuffer>&& buffer, GPUDevice& device, size_t size, OptionSet<GPUBufferUsage::Flags> usage, GPUBufferMappedOption isMapped, GPUErrorScopes& errorScopes)
 113 : GPUObjectBase(makeRef(errorScopes))
114114 , m_platformBuffer(WTFMove(buffer))
115  , m_device(WTFMove(device))
 115 , m_device(makeRef(device))
116116 , m_byteLength(size)
117117 , m_usage(usage)
118118 , m_isMappedFromCreation(isMapped == GPUBufferMappedOption::IsMapped)

Source/WebCore/platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm

3838
3939namespace WebCore {
4040
41 static bool trySetMetalFunctions(const char* const functionName, MTLLibrary *computeMetalLibrary, MTLComputePipelineDescriptor *mtlDescriptor, const String& computeEntryPointName, GPUErrorScopes& errorScopes)
 41static bool trySetMetalFunctions(MTLLibrary *computeMetalLibrary, MTLComputePipelineDescriptor *mtlDescriptor, const String& computeEntryPointName, GPUErrorScopes& errorScopes)
4242{
4343 BEGIN_BLOCK_OBJC_EXCEPTIONS;
4444
4545 if (!computeMetalLibrary) {
46  errorScopes.generateError(makeString(functionName, ": MTLLibrary for compute stage does not exist!"));
 46 errorScopes.generatePrefixedError("MTLLibrary for compute stage does not exist!");
4747 return false;
4848 }
4949
5050 auto function = adoptNS([computeMetalLibrary newFunctionWithName:computeEntryPointName]);
5151 if (!function) {
52  errorScopes.generateError(makeString(functionName, ": Cannot create compute MTLFunction \"", computeEntryPointName, "\"!"));
 52 errorScopes.generatePrefixedError(makeString("Cannot create compute MTLFunction '", computeEntryPointName, "'!"));
5353 return false;
5454 }
5555

@@static bool trySetMetalFunctions(const char* const functionName, MTLLibrary *com
6060 return true;
6161}
6262
63 static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const functionName, const GPUPipelineStageDescriptor& computeStage, const GPUDevice& device, MTLComputePipelineDescriptor* mtlDescriptor, Optional<WHLSL::ComputePipelineDescriptor>& whlslDescriptor, GPUErrorScopes& errorScopes)
 63static Optional<WHLSL::ComputeDimensions> trySetFunctions(const GPUPipelineStageDescriptor& computeStage, const GPUDevice& device, MTLComputePipelineDescriptor* mtlDescriptor, Optional<WHLSL::ComputePipelineDescriptor>& whlslDescriptor, GPUErrorScopes& errorScopes)
6464{
6565 RetainPtr<MTLLibrary> computeLibrary;
6666 String computeEntryPoint;

@@static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const func
7676
7777 auto whlslCompileResult = WHLSL::prepare(whlslSource, *whlslDescriptor);
7878 if (!whlslCompileResult) {
79  errorScopes.generateError(makeString("WHLSL compilation failed. ", whlslCompileResult.error()));
 79 errorScopes.generatePrefixedError(makeString("WHLSL compile error: ", whlslCompileResult.error()));
8080 return WTF::nullopt;
8181 }
8282

@@static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const func
100100 computeEntryPoint = computeStage.entryPoint;
101101 }
102102
103  if (trySetMetalFunctions(functionName, computeLibrary.get(), mtlDescriptor, computeEntryPoint, errorScopes))
 103 if (trySetMetalFunctions(computeLibrary.get(), mtlDescriptor, computeEntryPoint, errorScopes))
104104 return computeDimensions;
105105
106106 return WTF::nullopt;

@@struct ConvertResult {
111111 WHLSL::ComputeDimensions computeDimensions;
112112};
113113
114 static Optional<ConvertResult> convertComputePipelineDescriptor(const char* const functionName, const GPUComputePipelineDescriptor& descriptor, const GPUDevice& device, GPUErrorScopes& errorScopes)
 114static Optional<ConvertResult> convertComputePipelineDescriptor(const GPUComputePipelineDescriptor& descriptor, const GPUDevice& device, GPUErrorScopes& errorScopes)
115115{
116116 RetainPtr<MTLComputePipelineDescriptor> mtlDescriptor;
117117

@@static Optional<ConvertResult> convertComputePipelineDescriptor(const char* cons
120120 END_BLOCK_OBJC_EXCEPTIONS;
121121
122122 if (!mtlDescriptor) {
123  errorScopes.generateError(makeString(functionName, ": Error creating MTLDescriptor!"));
 123 errorScopes.generatePrefixedError("Error creating MTLComputePipelineDescriptor!");
124124 return WTF::nullopt;
125125 }
126126

@@static Optional<ConvertResult> convertComputePipelineDescriptor(const char* cons
136136 if (auto layout = convertLayout(*descriptor.layout))
137137 whlslDescriptor->layout = WTFMove(*layout);
138138 else {
139  errorScopes.generateError(makeString(functionName, ": Error converting GPUPipelineLayout!"));
 139 errorScopes.generatePrefixedError("Error converting GPUPipelineLayout!");
140140 return WTF::nullopt;
141141 }
142142 }
143143
144  if (auto computeDimensions = trySetFunctions(functionName, computeStage, device, mtlDescriptor.get(), whlslDescriptor, errorScopes))
 144 if (auto computeDimensions = trySetFunctions(computeStage, device, mtlDescriptor.get(), whlslDescriptor, errorScopes))
145145 return {{ mtlDescriptor, *computeDimensions }};
146146
147147 return WTF::nullopt;

@@struct CreateResult {
152152 WHLSL::ComputeDimensions computeDimensions;
153153};
154154
155 static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const functionName, const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes)
 155static Optional<CreateResult> tryCreateMTLComputePipelineState(const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes)
156156{
157157 if (!device.platformDevice()) {
158  errorScopes.generateError(makeString(functionName, ": Invalid GPUDevice!"));
 158 errorScopes.generatePrefixedError("Invalid GPUDevice!");
159159 return WTF::nullopt;
160160 }
161161
162  auto convertResult = convertComputePipelineDescriptor(functionName, descriptor, device, errorScopes);
 162 auto convertResult = convertComputePipelineDescriptor(descriptor, device, errorScopes);
163163 if (!convertResult)
164164 return WTF::nullopt;
165165 ASSERT(convertResult->pipelineDescriptor);

@@static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const
172172 NSError *error = nil;
173173 pipeline = adoptNS([device.platformDevice() newComputePipelineStateWithDescriptor:mtlDescriptor.get() options:MTLPipelineOptionNone reflection:nil error:&error]);
174174 if (!pipeline) {
175  errorScopes.generateError(makeString(functionName, ": ", (error ? error.localizedDescription.UTF8String : "Unable to create MTLComputePipelineState!")));
 175 errorScopes.generatePrefixedError(error ? error.localizedDescription.UTF8String : "Unable to create MTLComputePipelineState!");
176176 return WTF::nullopt;
177177 }
178178

@@static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const
181181 return {{ pipeline, convertResult->computeDimensions }};
182182}
183183
184 RefPtr<GPUComputePipeline> GPUComputePipeline::tryCreate(const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, Ref<GPUErrorScopes>&& errorScopes)
 184RefPtr<GPUComputePipeline> GPUComputePipeline::tryCreate(const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes)
185185{
186  const char* const functionName = "GPUComputePipeline::tryCreate()";
187 
188  auto createResult = tryCreateMTLComputePipelineState(functionName, device, descriptor, errorScopes);
 186 auto createResult = tryCreateMTLComputePipelineState(device, descriptor, errorScopes);
189187 if (!createResult)
190188 return nullptr;
191189
192  return adoptRef(new GPUComputePipeline(WTFMove(createResult->pipelineState), createResult->computeDimensions, WTFMove(errorScopes)));
 190 return adoptRef(new GPUComputePipeline(WTFMove(createResult->pipelineState), createResult->computeDimensions, errorScopes));
193191}
194192
195 GPUComputePipeline::GPUComputePipeline(RetainPtr<MTLComputePipelineState>&& pipeline, WHLSL::ComputeDimensions computeDimensions, Ref<GPUErrorScopes>&& errorScopes)
196  : GPUObjectBase(WTFMove(errorScopes))
 193GPUComputePipeline::GPUComputePipeline(RetainPtr<MTLComputePipelineState>&& pipeline, WHLSL::ComputeDimensions computeDimensions, GPUErrorScopes& errorScopes)
 194 : GPUObjectBase(makeRef(errorScopes))
197195 , m_platformComputePipeline(WTFMove(pipeline))
198196 , m_computeDimensions(computeDimensions)
199197{

Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm

@@static bool trySetMetalFunctions(MTLLibrary *vertexMetalLibrary, MTLLibrary *fra
344344
345345 auto function = adoptNS([vertexMetalLibrary newFunctionWithName:vertexEntryPointName]);
346346 if (!function) {
347  errorScopes.generatePrefixedError(makeString("Cannot create vertex MTLFunction \"", vertexEntryPointName, "\"!"));
 347 errorScopes.generatePrefixedError(makeString("Cannot create vertex MTLFunction '", vertexEntryPointName, "'!"));
348348 return false;
349349 }
350350

@@static bool trySetMetalFunctions(MTLLibrary *vertexMetalLibrary, MTLLibrary *fra
363363 auto function = adoptNS([fragmentMetalLibrary newFunctionWithName:fragmentEntryPointName]);
364364
365365 if (!function) {
366  errorScopes.generatePrefixedError(makeString("Cannot create fragment MTLFunction \"", fragmentEntryPointName, "\"!"));
 366 errorScopes.generatePrefixedError(makeString("Cannot create fragment MTLFunction '", fragmentEntryPointName, "'!"));
367367 return false;
368368 }
369369

@@static bool trySetFunctions(const GPUPipelineStageDescriptor& vertexStage, const
392392
393393 auto whlslCompileResult = WHLSL::prepare(whlslSource, *whlslDescriptor);
394394 if (!whlslCompileResult) {
395  errorScopes.generatePrefixedError("WHLSL compilation failed!");
 395 errorScopes.generatePrefixedError(makeString("WHLSL compile error: ", whlslCompileResult.error()));
396396 return false;
397397 }
398398