[WebGPU] Update GPUComputePipeline errors to match GPURenderPipeline implementation
authorjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 28 Jul 2019 00:47:00 +0000 (00:47 +0000)
committerjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 28 Jul 2019 00:47:00 +0000 (00:47 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200097

Reviewed by Myles C. Maxfield.

Remove passing around a functionName in GPUComputePipeline creation in favor of setting it on the GPUErrorScopes.
Also, WebGPU objects no longer create new Ref<>s unless object creation succeeds.

No new tests. Covered by existing tests.

* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::createBuffer const):
(WebCore::WebGPUDevice::createBufferMapped const):
(WebCore::WebGPUDevice::createComputePipeline const):
* platform/graphics/gpu/GPUBuffer.h:
* platform/graphics/gpu/GPUComputePipeline.h:
* platform/graphics/gpu/GPUDevice.cpp:
(WebCore::GPUDevice::tryCreateBuffer):
(WebCore::GPUDevice::tryCreateComputePipeline const):
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/GPUErrorScopes.cpp:
(WebCore::GPUErrorScopes::generatePrefixedError): Only validaton errors have messages right now.
* platform/graphics/gpu/GPUErrorScopes.h:
* platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
(WebCore::GPUBuffer::validateBufferUsage):
(WebCore::GPUBuffer::tryCreate):
(WebCore::GPUBuffer::GPUBuffer):
* platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm:
(WebCore::trySetMetalFunctions):
(WebCore::trySetFunctions):
(WebCore::convertComputePipelineDescriptor):
(WebCore::tryCreateMTLComputePipelineState):
(WebCore::GPUComputePipeline::tryCreate):
(WebCore::GPUComputePipeline::GPUComputePipeline):
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::trySetMetalFunctions):
(WebCore::trySetFunctions):

These classes were made RefCounted in a previous patch; remove their move ctors to fix build.
* Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h:
* Modules/webgpu/WHLSL/AST/WHLSLArrayType.h:
* Modules/webgpu/WHLSL/AST/WHLSLPointerType.h:
* Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
* Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
* Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@247892 268f45cc-cd09-0410-ab3c-d52691b4dbfc

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLArrayType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLPointerType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h
Source/WebCore/Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h
Source/WebCore/Modules/webgpu/WebGPUDevice.cpp
Source/WebCore/platform/graphics/gpu/GPUBuffer.h
Source/WebCore/platform/graphics/gpu/GPUComputePipeline.h
Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
Source/WebCore/platform/graphics/gpu/GPUDevice.h
Source/WebCore/platform/graphics/gpu/GPUErrorScopes.cpp
Source/WebCore/platform/graphics/gpu/GPUErrorScopes.h
Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm
Source/WebCore/platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm
Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm

index 3f0b535..98c242b 100644 (file)
@@ -1,3 +1,51 @@
+2019-07-27  Justin Fan  <justin_fan@apple.com>
+
+        [WebGPU] Update GPUComputePipeline errors to match GPURenderPipeline implementation
+        https://bugs.webkit.org/show_bug.cgi?id=200097
+
+        Reviewed by Myles C. Maxfield.
+
+        Remove passing around a functionName in GPUComputePipeline creation in favor of setting it on the GPUErrorScopes.
+        Also, WebGPU objects no longer create new Ref<>s unless object creation succeeds.
+
+        No new tests. Covered by existing tests.
+
+        * Modules/webgpu/WebGPUDevice.cpp:
+        (WebCore::WebGPUDevice::createBuffer const):
+        (WebCore::WebGPUDevice::createBufferMapped const):
+        (WebCore::WebGPUDevice::createComputePipeline const):
+        * platform/graphics/gpu/GPUBuffer.h:
+        * platform/graphics/gpu/GPUComputePipeline.h:
+        * platform/graphics/gpu/GPUDevice.cpp:
+        (WebCore::GPUDevice::tryCreateBuffer):
+        (WebCore::GPUDevice::tryCreateComputePipeline const):
+        * platform/graphics/gpu/GPUDevice.h:
+        * platform/graphics/gpu/GPUErrorScopes.cpp:
+        (WebCore::GPUErrorScopes::generatePrefixedError): Only validaton errors have messages right now.
+        * platform/graphics/gpu/GPUErrorScopes.h:
+        * platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
+        (WebCore::GPUBuffer::validateBufferUsage):
+        (WebCore::GPUBuffer::tryCreate):
+        (WebCore::GPUBuffer::GPUBuffer):
+        * platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm:
+        (WebCore::trySetMetalFunctions):
+        (WebCore::trySetFunctions):
+        (WebCore::convertComputePipelineDescriptor):
+        (WebCore::tryCreateMTLComputePipelineState):
+        (WebCore::GPUComputePipeline::tryCreate):
+        (WebCore::GPUComputePipeline::GPUComputePipeline):
+        * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
+        (WebCore::trySetMetalFunctions):
+        (WebCore::trySetFunctions):
+
+        These classes were made RefCounted in a previous patch; remove their move ctors to fix build.
+        * Modules/webgpu/WHLSL/AST/WHLSLArrayReferenceType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLArrayType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLPointerType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLReferenceType.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLTypeReference.h:
+        * Modules/webgpu/WHLSL/AST/WHLSLUnnamedType.h:
+
 2019-07-27  Andres Gonzalez  <andresg_22@apple.com>
 
         Expose the aria-label attribute for <video> elements.
index 789962c..51ae44f 100644 (file)
@@ -56,7 +56,6 @@ public:
     virtual ~ArrayReferenceType() = default;
 
     ArrayReferenceType(const ArrayReferenceType&) = delete;
-    ArrayReferenceType(ArrayReferenceType&&) = default;
 
     bool isArrayReferenceType() const override { return true; }
 
index babea6a..b3416e0 100644 (file)
@@ -58,7 +58,6 @@ public:
     virtual ~ArrayType() = default;
 
     ArrayType(const ArrayType&) = delete;
-    ArrayType(ArrayType&&) = default;
 
     bool isArrayType() const override { return true; }
 
index 3c3860a..e050689 100644 (file)
@@ -57,7 +57,6 @@ public:
     virtual ~PointerType() = default;
 
     PointerType(const PointerType&) = delete;
-    PointerType(PointerType&&) = default;
 
     bool isPointerType() const override { return true; }
 
index 09fc788..257d9c4 100644 (file)
@@ -54,7 +54,6 @@ public:
     virtual ~ReferenceType() = default;
 
     ReferenceType(const ReferenceType&) = delete;
-    ReferenceType(ReferenceType&&) = default;
 
     bool isReferenceType() const override { return true; }
 
index f0f96fd..f2ef028 100644 (file)
@@ -60,7 +60,6 @@ public:
     virtual ~TypeReference() = default;
 
     TypeReference(const TypeReference&) = delete;
-    TypeReference(TypeReference&&) = default;
 
     static Ref<TypeReference> wrap(CodeLocation, NamedType& resolvedType);
 
index a48a831..e97cd41 100644 (file)
@@ -51,7 +51,6 @@ public:
     virtual ~UnnamedType() = default;
 
     UnnamedType(const UnnamedType&) = delete;
-    UnnamedType(UnnamedType&&) = default;
 
     bool isUnnamedType() const override { return true; }
     virtual bool isTypeReference() const { return false; }
index 9db0b4c..db8d990 100644 (file)
@@ -87,15 +87,19 @@ WebGPUDevice::WebGPUDevice(Ref<const WebGPUAdapter>&& adapter, Ref<GPUDevice>&&
 
 Ref<WebGPUBuffer> WebGPUDevice::createBuffer(const GPUBufferDescriptor& descriptor) const
 {
-    auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::NotMapped, m_errorScopes.copyRef());
+    m_errorScopes->setErrorPrefix("GPUDevice.createBuffer(): ");
+
+    auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::NotMapped, m_errorScopes);
     return WebGPUBuffer::create(WTFMove(buffer));
 }
 
 Vector<JSC::JSValue> WebGPUDevice::createBufferMapped(JSC::ExecState& state, const GPUBufferDescriptor& descriptor) const
 {
+    m_errorScopes->setErrorPrefix("GPUDevice.createBufferMapped(): ");
+
     JSC::JSValue wrappedArrayBuffer = JSC::jsNull();
 
-    auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::IsMapped, m_errorScopes.copyRef());
+    auto buffer = m_device->tryCreateBuffer(descriptor, GPUBufferMappedOption::IsMapped, m_errorScopes);
     if (buffer) {
         auto arrayBuffer = buffer->mapOnCreation();
         wrappedArrayBuffer = toJS(&state, JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject()), arrayBuffer);
@@ -166,11 +170,13 @@ Ref<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(const WebGPURenderP
 
 Ref<WebGPUComputePipeline> WebGPUDevice::createComputePipeline(const WebGPUComputePipelineDescriptor& descriptor) const
 {
+    m_errorScopes->setErrorPrefix("GPUDevice.createComputePipeline(): ");
+
     auto gpuDescriptor = descriptor.tryCreateGPUComputePipelineDescriptor(m_errorScopes);
     if (!gpuDescriptor)
         return WebGPUComputePipeline::create(nullptr);
 
-    auto pipeline = m_device->tryCreateComputePipeline(*gpuDescriptor, m_errorScopes.copyRef());
+    auto pipeline = m_device->tryCreateComputePipeline(*gpuDescriptor, m_errorScopes);
     return WebGPUComputePipeline::create(WTFMove(pipeline));
 }
 
index 5f6f2f0..6550a40 100644 (file)
@@ -71,7 +71,7 @@ public:
 
     ~GPUBuffer();
 
-    static RefPtr<GPUBuffer> tryCreate(Ref<GPUDevice>&&, const GPUBufferDescriptor&, GPUBufferMappedOption, Ref<GPUErrorScopes>&&);
+    static RefPtr<GPUBuffer> tryCreate(GPUDevice&, const GPUBufferDescriptor&, GPUBufferMappedOption, GPUErrorScopes&);
 
     PlatformBuffer *platformBuffer() const { return m_platformBuffer.get(); }
     size_t byteLength() const { return m_byteLength; }
@@ -110,7 +110,7 @@ private:
         PendingMappingCallback(MappingCallback&&);
     };
 
-    GPUBuffer(PlatformBufferSmartPtr&&, Ref<GPUDevice>&&, size_t, OptionSet<GPUBufferUsage::Flags>, GPUBufferMappedOption, Ref<GPUErrorScopes>&&);
+    GPUBuffer(PlatformBufferSmartPtr&&, GPUDevice&, size_t, OptionSet<GPUBufferUsage::Flags>, GPUBufferMappedOption, GPUErrorScopes&);
     static bool validateBufferUsage(const GPUDevice&, OptionSet<GPUBufferUsage::Flags>, GPUErrorScopes&);
 
     JSC::ArrayBuffer* stagingBufferForRead();
index 46b7adc..3f8f719 100644 (file)
@@ -46,14 +46,14 @@ using PlatformComputePipelineSmartPtr = RetainPtr<MTLComputePipelineState>;
 
 class GPUComputePipeline : public GPUObjectBase {
 public:
-    static RefPtr<GPUComputePipeline> tryCreate(const GPUDevice&, const GPUComputePipelineDescriptor&, Ref<GPUErrorScopes>&&);
+    static RefPtr<GPUComputePipeline> tryCreate(const GPUDevice&, const GPUComputePipelineDescriptor&, GPUErrorScopes&);
 
     const PlatformComputePipeline* platformComputePipeline() const { return m_platformComputePipeline.get(); }
 
     WHLSL::ComputeDimensions computeDimensions() const { return m_computeDimensions; }
 
 private:
-    GPUComputePipeline(PlatformComputePipelineSmartPtr&&, WHLSL::ComputeDimensions, Ref<GPUErrorScopes>&&);
+    GPUComputePipeline(PlatformComputePipelineSmartPtr&&, WHLSL::ComputeDimensions, GPUErrorScopes&);
 
     PlatformComputePipelineSmartPtr m_platformComputePipeline;
     WHLSL::ComputeDimensions m_computeDimensions { 0, 0, 0 };
index 30cef68..54d6f15 100644 (file)
@@ -52,9 +52,9 @@
 
 namespace WebCore {
 
-RefPtr<GPUBuffer> GPUDevice::tryCreateBuffer(const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, Ref<GPUErrorScopes>&& errorScopes)
+RefPtr<GPUBuffer> GPUDevice::tryCreateBuffer(const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, GPUErrorScopes& errorScopes)
 {
-    return GPUBuffer::tryCreate(makeRef(*this), descriptor, isMapped, WTFMove(errorScopes));
+    return GPUBuffer::tryCreate(*this, descriptor, isMapped, errorScopes);
 }
 
 RefPtr<GPUTexture> GPUDevice::tryCreateTexture(const GPUTextureDescriptor& descriptor) const
@@ -87,9 +87,9 @@ RefPtr<GPURenderPipeline> GPUDevice::tryCreateRenderPipeline(const GPURenderPipe
     return GPURenderPipeline::tryCreate(*this, descriptor, errorScopes);
 }
 
-RefPtr<GPUComputePipeline> GPUDevice::tryCreateComputePipeline(const GPUComputePipelineDescriptor& descriptor, Ref<GPUErrorScopes>&& errorScopes) const
+RefPtr<GPUComputePipeline> GPUDevice::tryCreateComputePipeline(const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes) const
 {
-    return GPUComputePipeline::tryCreate(*this, descriptor, WTFMove(errorScopes));
+    return GPUComputePipeline::tryCreate(*this, descriptor, errorScopes);
 }
 
 RefPtr<GPUCommandBuffer> GPUDevice::tryCreateCommandBuffer() const
index b948c8a..c8fb025 100644 (file)
@@ -70,7 +70,7 @@ class GPUDevice : public RefCounted<GPUDevice>, public CanMakeWeakPtr<GPUDevice>
 public:
     static RefPtr<GPUDevice> tryCreate(const Optional<GPURequestAdapterOptions>&);
 
-    RefPtr<GPUBuffer> tryCreateBuffer(const GPUBufferDescriptor&, GPUBufferMappedOption, Ref<GPUErrorScopes>&&);
+    RefPtr<GPUBuffer> tryCreateBuffer(const GPUBufferDescriptor&, GPUBufferMappedOption, GPUErrorScopes&);
     RefPtr<GPUTexture> tryCreateTexture(const GPUTextureDescriptor&) const;
     RefPtr<GPUSampler> tryCreateSampler(const GPUSamplerDescriptor&) const;
 
@@ -79,7 +79,7 @@ public:
 
     RefPtr<GPUShaderModule> tryCreateShaderModule(const GPUShaderModuleDescriptor&) const;
     RefPtr<GPURenderPipeline> tryCreateRenderPipeline(const GPURenderPipelineDescriptor&, GPUErrorScopes&) const;
-    RefPtr<GPUComputePipeline> tryCreateComputePipeline(const GPUComputePipelineDescriptor&, Ref<GPUErrorScopes>&&) const;
+    RefPtr<GPUComputePipeline> tryCreateComputePipeline(const GPUComputePipelineDescriptor&, GPUErrorScopes&) const;
 
     RefPtr<GPUCommandBuffer> tryCreateCommandBuffer() const;
 
index c1256a9..ff93855 100644 (file)
@@ -63,9 +63,9 @@ void GPUErrorScopes::generateError(const String& message, GPUErrorFilter filter)
     iterator->error = createError(filter, message);
 }
 
-void GPUErrorScopes::generatePrefixedError(const String& message, GPUErrorFilter filter)
+void GPUErrorScopes::generatePrefixedError(const String& message)
 {
-    generateError(m_prefix + message, filter);
+    generateError(m_prefix + message, GPUErrorFilter::Validation);
 }
 
 } // namespace WebCore
index e9ee6ea..af88588 100644 (file)
@@ -45,7 +45,7 @@ public:
     Optional<GPUError> popErrorScope(String& failMessage);
 
     void generateError(const String&, GPUErrorFilter = GPUErrorFilter::Validation);
-    void generatePrefixedError(const String&, GPUErrorFilter = GPUErrorFilter::Validation);
+    void generatePrefixedError(const String&);
     void setErrorPrefix(const String& prefix) { m_prefix = prefix; }
 
 private:
index 5cbc648..2b277dc 100644 (file)
@@ -50,7 +50,7 @@ bool GPUBuffer::validateBufferUsage(const GPUDevice& device, OptionSet<GPUBuffer
     }
 
     if (usage.containsAll({ GPUBufferUsage::Flags::MapWrite, GPUBufferUsage::Flags::MapRead })) {
-        errorScopes.generateError("GPUBuffer::tryCreate(): Buffer cannot have both MAP_READ and MAP_WRITE usage!");
+        errorScopes.generatePrefixedError("Buffer cannot have both MAP_READ and MAP_WRITE usage!");
         return false;
     }
 
@@ -62,17 +62,17 @@ bool GPUBuffer::validateBufferUsage(const GPUDevice& device, OptionSet<GPUBuffer
     return true;
 }
 
-RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, Ref<GPUErrorScopes>&& errorScopes)
+RefPtr<GPUBuffer> GPUBuffer::tryCreate(GPUDevice& device, const GPUBufferDescriptor& descriptor, GPUBufferMappedOption isMapped, GPUErrorScopes& errorScopes)
 {
     // MTLBuffer size (NSUInteger) is 32 bits on some platforms.
     NSUInteger size = 0;
     if (!WTF::convertSafely(descriptor.size, size)) {
-        errorScopes->generateError("", GPUErrorFilter::OutOfMemory);
+        errorScopes.generateError("", GPUErrorFilter::OutOfMemory);
         return nullptr;
     }
 
     auto usage = OptionSet<GPUBufferUsage::Flags>::fromRaw(descriptor.usage);
-    if (!validateBufferUsage(device.get(), usage, errorScopes))
+    if (!validateBufferUsage(device, usage, errorScopes))
         return nullptr;
 
 #if PLATFORM(MAC)
@@ -97,22 +97,22 @@ RefPtr<GPUBuffer> GPUBuffer::tryCreate(Ref<GPUDevice>&& device, const GPUBufferD
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
-    mtlBuffer = adoptNS([device->platformDevice() newBufferWithLength:static_cast<NSUInteger>(descriptor.size) options:resourceOptions]);
+    mtlBuffer = adoptNS([device.platformDevice() newBufferWithLength:static_cast<NSUInteger>(descriptor.size) options:resourceOptions]);
 
     END_BLOCK_OBJC_EXCEPTIONS;
 
     if (!mtlBuffer) {
-        errorScopes->generateError("", GPUErrorFilter::OutOfMemory);
+        errorScopes.generateError("", GPUErrorFilter::OutOfMemory);
         return nullptr;
     }
 
-    return adoptRef(*new GPUBuffer(WTFMove(mtlBuffer), WTFMove(device), size, usage, isMapped, WTFMove(errorScopes)));
+    return adoptRef(*new GPUBuffer(WTFMove(mtlBuffer), device, size, usage, isMapped, errorScopes));
 }
 
-GPUBuffer::GPUBuffer(RetainPtr<MTLBuffer>&& buffer, Ref<GPUDevice>&& device, size_t size, OptionSet<GPUBufferUsage::Flags> usage, GPUBufferMappedOption isMapped, Ref<GPUErrorScopes>&& errorScopes)
-    : GPUObjectBase(WTFMove(errorScopes))
+GPUBuffer::GPUBuffer(RetainPtr<MTLBuffer>&& buffer, GPUDevice& device, size_t size, OptionSet<GPUBufferUsage::Flags> usage, GPUBufferMappedOption isMapped, GPUErrorScopes& errorScopes)
+    : GPUObjectBase(makeRef(errorScopes))
     , m_platformBuffer(WTFMove(buffer))
-    , m_device(WTFMove(device))
+    , m_device(makeRef(device))
     , m_byteLength(size)
     , m_usage(usage)
     , m_isMappedFromCreation(isMapped == GPUBufferMappedOption::IsMapped)
index cd7f26c..a4745e5 100644 (file)
 
 namespace WebCore {
 
-static bool trySetMetalFunctions(const char* const functionName, MTLLibrary *computeMetalLibrary, MTLComputePipelineDescriptor *mtlDescriptor, const String& computeEntryPointName, GPUErrorScopes& errorScopes)
+static bool trySetMetalFunctions(MTLLibrary *computeMetalLibrary, MTLComputePipelineDescriptor *mtlDescriptor, const String& computeEntryPointName, GPUErrorScopes& errorScopes)
 {
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
 
     if (!computeMetalLibrary) {
-        errorScopes.generateError(makeString(functionName, ": MTLLibrary for compute stage does not exist!"));
+        errorScopes.generatePrefixedError("MTLLibrary for compute stage does not exist!");
         return false;
     }
 
     auto function = adoptNS([computeMetalLibrary newFunctionWithName:computeEntryPointName]);
     if (!function) {
-        errorScopes.generateError(makeString(functionName, ": Cannot create compute MTLFunction \"", computeEntryPointName, "\"!"));
+        errorScopes.generatePrefixedError(makeString("Cannot create compute MTLFunction '", computeEntryPointName, "'!"));
         return false;
     }
 
@@ -60,7 +60,7 @@ static bool trySetMetalFunctions(const char* const functionName, MTLLibrary *com
     return true;
 }
 
-static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const functionName, const GPUPipelineStageDescriptor& computeStage, const GPUDevice& device, MTLComputePipelineDescriptor* mtlDescriptor, Optional<WHLSL::ComputePipelineDescriptor>& whlslDescriptor, GPUErrorScopes& errorScopes)
+static Optional<WHLSL::ComputeDimensions> trySetFunctions(const GPUPipelineStageDescriptor& computeStage, const GPUDevice& device, MTLComputePipelineDescriptor* mtlDescriptor, Optional<WHLSL::ComputePipelineDescriptor>& whlslDescriptor, GPUErrorScopes& errorScopes)
 {
     RetainPtr<MTLLibrary> computeLibrary;
     String computeEntryPoint;
@@ -76,7 +76,7 @@ static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const func
 
         auto whlslCompileResult = WHLSL::prepare(whlslSource, *whlslDescriptor);
         if (!whlslCompileResult) {
-            errorScopes.generateError(makeString("WHLSL compilation failed. ", whlslCompileResult.error()));
+            errorScopes.generatePrefixedError(makeString("WHLSL compile error: ", whlslCompileResult.error()));
             return WTF::nullopt;
         }
 
@@ -100,7 +100,7 @@ static Optional<WHLSL::ComputeDimensions> trySetFunctions(const char* const func
         computeEntryPoint = computeStage.entryPoint;
     }
 
-    if (trySetMetalFunctions(functionName, computeLibrary.get(), mtlDescriptor, computeEntryPoint, errorScopes))
+    if (trySetMetalFunctions(computeLibrary.get(), mtlDescriptor, computeEntryPoint, errorScopes))
         return computeDimensions;
 
     return WTF::nullopt;
@@ -111,7 +111,7 @@ struct ConvertResult {
     WHLSL::ComputeDimensions computeDimensions;
 };
 
-static Optional<ConvertResult> convertComputePipelineDescriptor(const char* const functionName, const GPUComputePipelineDescriptor& descriptor, const GPUDevice& device, GPUErrorScopes& errorScopes)
+static Optional<ConvertResult> convertComputePipelineDescriptor(const GPUComputePipelineDescriptor& descriptor, const GPUDevice& device, GPUErrorScopes& errorScopes)
 {
     RetainPtr<MTLComputePipelineDescriptor> mtlDescriptor;
 
@@ -120,7 +120,7 @@ static Optional<ConvertResult> convertComputePipelineDescriptor(const char* cons
     END_BLOCK_OBJC_EXCEPTIONS;
 
     if (!mtlDescriptor) {
-        errorScopes.generateError(makeString(functionName, ": Error creating MTLDescriptor!"));
+        errorScopes.generatePrefixedError("Error creating MTLComputePipelineDescriptor!");
         return WTF::nullopt;
     }
 
@@ -136,12 +136,12 @@ static Optional<ConvertResult> convertComputePipelineDescriptor(const char* cons
         if (auto layout = convertLayout(*descriptor.layout))
             whlslDescriptor->layout = WTFMove(*layout);
         else {
-            errorScopes.generateError(makeString(functionName, ": Error converting GPUPipelineLayout!"));
+            errorScopes.generatePrefixedError("Error converting GPUPipelineLayout!");
             return WTF::nullopt;
         }
     }
 
-    if (auto computeDimensions = trySetFunctions(functionName, computeStage, device, mtlDescriptor.get(), whlslDescriptor, errorScopes))
+    if (auto computeDimensions = trySetFunctions(computeStage, device, mtlDescriptor.get(), whlslDescriptor, errorScopes))
         return {{ mtlDescriptor, *computeDimensions }};
 
     return WTF::nullopt;
@@ -152,14 +152,14 @@ struct CreateResult {
     WHLSL::ComputeDimensions computeDimensions;
 };
 
-static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const functionName, const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes)
+static Optional<CreateResult> tryCreateMTLComputePipelineState(const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes)
 {
     if (!device.platformDevice()) {
-        errorScopes.generateError(makeString(functionName, ": Invalid GPUDevice!"));
+        errorScopes.generatePrefixedError("Invalid GPUDevice!");
         return WTF::nullopt;
     }
 
-    auto convertResult = convertComputePipelineDescriptor(functionName, descriptor, device, errorScopes);
+    auto convertResult = convertComputePipelineDescriptor(descriptor, device, errorScopes);
     if (!convertResult)
         return WTF::nullopt;
     ASSERT(convertResult->pipelineDescriptor);
@@ -172,7 +172,7 @@ static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const
     NSError *error = nil;
     pipeline = adoptNS([device.platformDevice() newComputePipelineStateWithDescriptor:mtlDescriptor.get() options:MTLPipelineOptionNone reflection:nil error:&error]);
     if (!pipeline) {
-        errorScopes.generateError(makeString(functionName, ": ", (error ? error.localizedDescription.UTF8String : "Unable to create MTLComputePipelineState!")));
+        errorScopes.generatePrefixedError(error ? error.localizedDescription.UTF8String : "Unable to create MTLComputePipelineState!");
         return WTF::nullopt;
     }
 
@@ -181,19 +181,17 @@ static Optional<CreateResult> tryCreateMTLComputePipelineState(const char* const
     return {{ pipeline, convertResult->computeDimensions }};
 }
 
-RefPtr<GPUComputePipeline> GPUComputePipeline::tryCreate(const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, Ref<GPUErrorScopes>&& errorScopes)
+RefPtr<GPUComputePipeline> GPUComputePipeline::tryCreate(const GPUDevice& device, const GPUComputePipelineDescriptor& descriptor, GPUErrorScopes& errorScopes)
 {
-    const char* const functionName = "GPUComputePipeline::tryCreate()";
-
-    auto createResult = tryCreateMTLComputePipelineState(functionName, device, descriptor, errorScopes);
+    auto createResult = tryCreateMTLComputePipelineState(device, descriptor, errorScopes);
     if (!createResult)
         return nullptr;
 
-    return adoptRef(new GPUComputePipeline(WTFMove(createResult->pipelineState), createResult->computeDimensions, WTFMove(errorScopes)));
+    return adoptRef(new GPUComputePipeline(WTFMove(createResult->pipelineState), createResult->computeDimensions, errorScopes));
 }
 
-GPUComputePipeline::GPUComputePipeline(RetainPtr<MTLComputePipelineState>&& pipeline, WHLSL::ComputeDimensions computeDimensions, Ref<GPUErrorScopes>&& errorScopes)
-    : GPUObjectBase(WTFMove(errorScopes))
+GPUComputePipeline::GPUComputePipeline(RetainPtr<MTLComputePipelineState>&& pipeline, WHLSL::ComputeDimensions computeDimensions, GPUErrorScopes& errorScopes)
+    : GPUObjectBase(makeRef(errorScopes))
     , m_platformComputePipeline(WTFMove(pipeline))
     , m_computeDimensions(computeDimensions)
 {
index a83c0fa..163dbdf 100644 (file)
@@ -344,7 +344,7 @@ static bool trySetMetalFunctions(MTLLibrary *vertexMetalLibrary, MTLLibrary *fra
 
         auto function = adoptNS([vertexMetalLibrary newFunctionWithName:vertexEntryPointName]);
         if (!function) {
-            errorScopes.generatePrefixedError(makeString("Cannot create vertex MTLFunction \"", vertexEntryPointName, "\"!"));
+            errorScopes.generatePrefixedError(makeString("Cannot create vertex MTLFunction '", vertexEntryPointName, "'!"));
             return false;
         }
 
@@ -363,7 +363,7 @@ static bool trySetMetalFunctions(MTLLibrary *vertexMetalLibrary, MTLLibrary *fra
         auto function = adoptNS([fragmentMetalLibrary newFunctionWithName:fragmentEntryPointName]);
 
         if (!function) {
-            errorScopes.generatePrefixedError(makeString("Cannot create fragment MTLFunction \"", fragmentEntryPointName, "\"!"));
+            errorScopes.generatePrefixedError(makeString("Cannot create fragment MTLFunction '", fragmentEntryPointName, "'!"));
             return false;
         }
 
@@ -392,7 +392,7 @@ static bool trySetFunctions(const GPUPipelineStageDescriptor& vertexStage, const
 
         auto whlslCompileResult = WHLSL::prepare(whlslSource, *whlslDescriptor);
         if (!whlslCompileResult) {
-            errorScopes.generatePrefixedError("WHLSL compilation failed!");
+            errorScopes.generatePrefixedError(makeString("WHLSL compile error: ", whlslCompileResult.error()));
             return false;
         }