[WebGPU] Make WebGPURenderPipeline and WebGPUComputePipeline inherit from GPUObjectBase
authorjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Sep 2019 22:31:02 +0000 (22:31 +0000)
committerjustin_fan@apple.com <justin_fan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 14 Sep 2019 22:31:02 +0000 (22:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201207

Reviewed by Dean Jackson.

Make remaining WebGPU "client" classes manage their error scopes, instead of the internal classes.
Matches Web/GPUBuffer, and allows "invalid" WebGPU objects to create errors.

Covered by existing tests.

* Modules/webgpu/WebGPUComputePipeline.cpp:
(WebCore::WebGPUComputePipeline::create):
(WebCore::WebGPUComputePipeline::WebGPUComputePipeline):
* Modules/webgpu/WebGPUComputePipeline.h:
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::createRenderPipeline const):
(WebCore::WebGPUDevice::createComputePipeline const):
* Modules/webgpu/WebGPURenderPipeline.cpp:
(WebCore::WebGPURenderPipeline::create):
(WebCore::WebGPURenderPipeline::WebGPURenderPipeline):
* Modules/webgpu/WebGPURenderPipeline.h:
* WebCore.xcodeproj/project.pbxproj:
* platform/graphics/gpu/GPUComputePipeline.h:
* platform/graphics/gpu/GPURenderPipeline.h:
* platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm:
(WebCore::GPUComputePipeline::tryCreate):
(WebCore::GPUComputePipeline::GPUComputePipeline):
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::GPURenderPipeline::tryCreate):
(WebCore::GPURenderPipeline::GPURenderPipeline):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WebGPUComputePipeline.cpp
Source/WebCore/Modules/webgpu/WebGPUComputePipeline.h
Source/WebCore/Modules/webgpu/WebGPUDevice.cpp
Source/WebCore/Modules/webgpu/WebGPURenderPipeline.cpp
Source/WebCore/Modules/webgpu/WebGPURenderPipeline.h
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/graphics/gpu/GPUComputePipeline.h
Source/WebCore/platform/graphics/gpu/GPURenderPipeline.h
Source/WebCore/platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm
Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm

index c2ac90b..7ddfa41 100644 (file)
@@ -1,3 +1,36 @@
+2019-09-14  Justin Fan  <justin_fan@apple.com>
+
+        [WebGPU] Make WebGPURenderPipeline and WebGPUComputePipeline inherit from GPUObjectBase
+        https://bugs.webkit.org/show_bug.cgi?id=201207
+
+        Reviewed by Dean Jackson.
+
+        Make remaining WebGPU "client" classes manage their error scopes, instead of the internal classes.
+        Matches Web/GPUBuffer, and allows "invalid" WebGPU objects to create errors.
+
+        Covered by existing tests.
+
+        * Modules/webgpu/WebGPUComputePipeline.cpp:
+        (WebCore::WebGPUComputePipeline::create):
+        (WebCore::WebGPUComputePipeline::WebGPUComputePipeline):
+        * Modules/webgpu/WebGPUComputePipeline.h:
+        * Modules/webgpu/WebGPUDevice.cpp:
+        (WebCore::WebGPUDevice::createRenderPipeline const):
+        (WebCore::WebGPUDevice::createComputePipeline const):
+        * Modules/webgpu/WebGPURenderPipeline.cpp:
+        (WebCore::WebGPURenderPipeline::create):
+        (WebCore::WebGPURenderPipeline::WebGPURenderPipeline):
+        * Modules/webgpu/WebGPURenderPipeline.h:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/graphics/gpu/GPUComputePipeline.h:
+        * platform/graphics/gpu/GPURenderPipeline.h:
+        * platform/graphics/gpu/cocoa/GPUComputePipelineMetal.mm:
+        (WebCore::GPUComputePipeline::tryCreate):
+        (WebCore::GPUComputePipeline::GPUComputePipeline):
+        * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
+        (WebCore::GPURenderPipeline::tryCreate):
+        (WebCore::GPURenderPipeline::GPURenderPipeline):
+
 2019-09-14  Yusuke Suzuki  <ysuzuki@apple.com>
 
         Retire x86 32bit JIT support
index 13c2448..cd11ecb 100644 (file)
 
 namespace WebCore {
 
-Ref<WebGPUComputePipeline> WebGPUComputePipeline::create(RefPtr<GPUComputePipeline>&& pipeline)
+Ref<WebGPUComputePipeline> WebGPUComputePipeline::create(RefPtr<GPUComputePipeline>&& pipeline, GPUErrorScopes& errorScopes)
 {
-    return adoptRef(*new WebGPUComputePipeline(WTFMove(pipeline)));
+    return adoptRef(*new WebGPUComputePipeline(WTFMove(pipeline), errorScopes));
 }
 
-WebGPUComputePipeline::WebGPUComputePipeline(RefPtr<GPUComputePipeline>&& pipeline)
-    : m_computePipeline { WTFMove(pipeline) }
+WebGPUComputePipeline::WebGPUComputePipeline(RefPtr<GPUComputePipeline>&& pipeline, GPUErrorScopes& errorScopes)
+    : GPUObjectBase(makeRef(errorScopes))
+    , m_computePipeline { WTFMove(pipeline) }
 {
 }
 
index 9a758c0..2ed7c98 100644 (file)
 #if ENABLE(WEBGPU)
 
 #include "GPUComputePipeline.h"
-#include <wtf/RefCounted.h>
+#include "GPUObjectBase.h"
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
-class WebGPUComputePipeline : public RefCounted<WebGPUComputePipeline> {
+class WebGPUComputePipeline : public GPUObjectBase {
 public:
-    static Ref<WebGPUComputePipeline> create(RefPtr<GPUComputePipeline>&&);
+    static Ref<WebGPUComputePipeline> create(RefPtr<GPUComputePipeline>&&, GPUErrorScopes&);
 
     const GPUComputePipeline* computePipeline() const { return m_computePipeline.get(); }
 
 private:
-    WebGPUComputePipeline(RefPtr<GPUComputePipeline>&&);
+    WebGPUComputePipeline(RefPtr<GPUComputePipeline>&&, GPUErrorScopes&);
 
     RefPtr<GPUComputePipeline> m_computePipeline;
 };
index fb95ded..5ebf083 100644 (file)
@@ -214,10 +214,10 @@ Ref<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(const WebGPURenderP
 
     auto gpuDescriptor = descriptor.tryCreateGPURenderPipelineDescriptor(m_errorScopes);
     if (!gpuDescriptor)
-        return WebGPURenderPipeline::create(nullptr);
+        return WebGPURenderPipeline::create(nullptr, m_errorScopes);
 
     auto pipeline = m_device->tryCreateRenderPipeline(*gpuDescriptor, m_errorScopes);
-    return WebGPURenderPipeline::create(WTFMove(pipeline));
+    return WebGPURenderPipeline::create(WTFMove(pipeline), m_errorScopes);
 }
 
 Ref<WebGPUComputePipeline> WebGPUDevice::createComputePipeline(const WebGPUComputePipelineDescriptor& descriptor) const
@@ -226,10 +226,10 @@ Ref<WebGPUComputePipeline> WebGPUDevice::createComputePipeline(const WebGPUCompu
 
     auto gpuDescriptor = descriptor.tryCreateGPUComputePipelineDescriptor(m_errorScopes);
     if (!gpuDescriptor)
-        return WebGPUComputePipeline::create(nullptr);
+        return WebGPUComputePipeline::create(nullptr, m_errorScopes);
 
     auto pipeline = m_device->tryCreateComputePipeline(*gpuDescriptor, m_errorScopes);
-    return WebGPUComputePipeline::create(WTFMove(pipeline));
+    return WebGPUComputePipeline::create(WTFMove(pipeline), m_errorScopes);
 }
 
 Ref<WebGPUCommandEncoder> WebGPUDevice::createCommandEncoder() const
index 1dc4ddf..17aedc6 100644 (file)
 
 namespace WebCore {
 
-Ref<WebGPURenderPipeline> WebGPURenderPipeline::create(RefPtr<GPURenderPipeline>&& pipeline)
+Ref<WebGPURenderPipeline> WebGPURenderPipeline::create(RefPtr<GPURenderPipeline>&& pipeline, GPUErrorScopes& errorScopes)
 {
-    return adoptRef(*new WebGPURenderPipeline(WTFMove(pipeline)));
+    return adoptRef(*new WebGPURenderPipeline(WTFMove(pipeline), errorScopes));
 }
 
-WebGPURenderPipeline::WebGPURenderPipeline(RefPtr<GPURenderPipeline>&& pipeline)
-    : m_renderPipeline(WTFMove(pipeline))
+WebGPURenderPipeline::WebGPURenderPipeline(RefPtr<GPURenderPipeline>&& pipeline, GPUErrorScopes& errorScopes)
+    : GPUObjectBase(makeRef(errorScopes))
+    , m_renderPipeline(WTFMove(pipeline))
 {
 }
 
index f39cfed..8f00ca6 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPUObjectBase.h"
 #include "GPURenderPipeline.h"
-#include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
 
-class WebGPURenderPipeline : public RefCounted<WebGPURenderPipeline> {
+class WebGPURenderPipeline : public GPUObjectBase {
 public:
-    static Ref<WebGPURenderPipeline> create(RefPtr<GPURenderPipeline>&&);
+    static Ref<WebGPURenderPipeline> create(RefPtr<GPURenderPipeline>&&, GPUErrorScopes&);
 
     const GPURenderPipeline* renderPipeline() const { return m_renderPipeline.get(); }
 
 private:
-    WebGPURenderPipeline(RefPtr<GPURenderPipeline>&&);
+    WebGPURenderPipeline(RefPtr<GPURenderPipeline>&&, GPUErrorScopes&);
 
     RefPtr<GPURenderPipeline> m_renderPipeline;
 };
index 2b1d5ce..cd7889d 100644 (file)
                                D03C849E21FFCF000002227F /* GPUCompareFunction.idl */,
                                D03C84A221FFD7230002227F /* GPUDepthStencilStateDescriptor.idl */,
                                D09AFB0622D417B300C4538C /* GPUErrorFilter.idl */,
+                               D03586B222D7F2EA00DA0284 /* GPUErrorScopes.cpp */,
+                               D03586B122D7F2EA00DA0284 /* GPUErrorScopes.h */,
                                D026F480220A2B7000AC5F49 /* GPUExtent3D.idl */,
                                D08AA02D220D0B9C0058C502 /* GPULoadOp.idl */,
                                D0CCA94922299F97006979B6 /* GPUOrigin3D.h */,
index 3f8f719..cafc6e4 100644 (file)
@@ -27,7 +27,6 @@
 
 #if ENABLE(WEBGPU)
 
-#include "GPUObjectBase.h"
 #include "WHLSLPrepare.h"
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -38,13 +37,14 @@ OBJC_PROTOCOL(MTLComputePipelineState);
 namespace WebCore {
 
 class GPUDevice;
+class GPUErrorScopes;
 
 struct GPUComputePipelineDescriptor;
 
 using PlatformComputePipeline = MTLComputePipelineState;
 using PlatformComputePipelineSmartPtr = RetainPtr<MTLComputePipelineState>;
 
-class GPUComputePipeline : public GPUObjectBase {
+class GPUComputePipeline : public RefCounted<GPUComputePipeline> {
 public:
     static RefPtr<GPUComputePipeline> tryCreate(const GPUDevice&, const GPUComputePipelineDescriptor&, GPUErrorScopes&);
 
@@ -53,7 +53,7 @@ public:
     WHLSL::ComputeDimensions computeDimensions() const { return m_computeDimensions; }
 
 private:
-    GPUComputePipeline(PlatformComputePipelineSmartPtr&&, WHLSL::ComputeDimensions, GPUErrorScopes&);
+    GPUComputePipeline(PlatformComputePipelineSmartPtr&&, WHLSL::ComputeDimensions);
 
     PlatformComputePipelineSmartPtr m_platformComputePipeline;
     WHLSL::ComputeDimensions m_computeDimensions { 0, 0, 0 };
index 39eec1f..83c8e1d 100644 (file)
@@ -27,7 +27,6 @@
 
 #if ENABLE(WEBGPU)
 
-#include "GPUObjectBase.h"
 #include "GPURenderPipelineDescriptor.h"
 #include <wtf/Optional.h>
 #include <wtf/RefCounted.h>
@@ -42,11 +41,12 @@ OBJC_PROTOCOL(MTLRenderPipelineState);
 namespace WebCore {
 
 class GPUDevice;
+class GPUErrorScopes;
 
 using PlatformRenderPipeline = MTLRenderPipelineState;
 using PlatformRenderPipelineSmartPtr = RetainPtr<MTLRenderPipelineState>;
 
-class GPURenderPipeline : public GPUObjectBase {
+class GPURenderPipeline : public RefCounted<GPURenderPipeline> {
 public:
     static RefPtr<GPURenderPipeline> tryCreate(const GPUDevice&, const GPURenderPipelineDescriptor&, GPUErrorScopes&);
 
@@ -59,7 +59,7 @@ public:
 
 private:
 #if USE(METAL)
-    GPURenderPipeline(RetainPtr<MTLDepthStencilState>&&, PlatformRenderPipelineSmartPtr&&, GPUPrimitiveTopology, Optional<GPUIndexFormat>, GPUErrorScopes&);
+    GPURenderPipeline(RetainPtr<MTLDepthStencilState>&&, PlatformRenderPipelineSmartPtr&&, GPUPrimitiveTopology, Optional<GPUIndexFormat>);
 
     RetainPtr<MTLDepthStencilState> m_depthStencilState;
 #endif // USE(METAL)
index c61b8ad..7d8f8b2 100644 (file)
@@ -30,6 +30,7 @@
 
 #import "GPUComputePipelineDescriptor.h"
 #import "GPUDevice.h"
+#import "GPUErrorScopes.h"
 #import "GPUPipelineMetalConvertLayout.h"
 #import "WHLSLPrepare.h"
 #import <Metal/Metal.h>
@@ -193,12 +194,11 @@ RefPtr<GPUComputePipeline> GPUComputePipeline::tryCreate(const GPUDevice& device
     if (!createResult)
         return nullptr;
 
-    return adoptRef(new GPUComputePipeline(WTFMove(createResult->pipelineState), createResult->computeDimensions, errorScopes));
+    return adoptRef(new GPUComputePipeline(WTFMove(createResult->pipelineState), createResult->computeDimensions));
 }
 
-GPUComputePipeline::GPUComputePipeline(RetainPtr<MTLComputePipelineState>&& pipeline, WHLSL::ComputeDimensions computeDimensions, GPUErrorScopes& errorScopes)
-    : GPUObjectBase(makeRef(errorScopes))
-    , m_platformComputePipeline(WTFMove(pipeline))
+GPUComputePipeline::GPUComputePipeline(RetainPtr<MTLComputePipelineState>&& pipeline, WHLSL::ComputeDimensions computeDimensions)
+    : m_platformComputePipeline(WTFMove(pipeline))
     , m_computeDimensions(computeDimensions)
 {
 }
index 6368d1a..2824087 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(WEBGPU)
 
 #import "GPUDevice.h"
+#import "GPUErrorScopes.h"
 #import "GPULimits.h"
 #import "GPUPipelineMetalConvertLayout.h"
 #import "GPUUtils.h"
@@ -525,12 +526,11 @@ RefPtr<GPURenderPipeline> GPURenderPipeline::tryCreate(const GPUDevice& device,
     if (!pipeline)
         return nullptr;
 
-    return adoptRef(new GPURenderPipeline(WTFMove(depthStencil), WTFMove(pipeline), descriptor.primitiveTopology, descriptor.vertexInput.indexFormat, errorScopes));
+    return adoptRef(new GPURenderPipeline(WTFMove(depthStencil), WTFMove(pipeline), descriptor.primitiveTopology, descriptor.vertexInput.indexFormat));
 }
 
-GPURenderPipeline::GPURenderPipeline(RetainPtr<MTLDepthStencilState>&& depthStencil, RetainPtr<MTLRenderPipelineState>&& pipeline, GPUPrimitiveTopology topology, Optional<GPUIndexFormat> format, GPUErrorScopes& errorScopes)
-    : GPUObjectBase(makeRef(errorScopes))
-    , m_depthStencilState(WTFMove(depthStencil))
+GPURenderPipeline::GPURenderPipeline(RetainPtr<MTLDepthStencilState>&& depthStencil, RetainPtr<MTLRenderPipelineState>&& pipeline, GPUPrimitiveTopology topology, Optional<GPUIndexFormat> format)
+    : m_depthStencilState(WTFMove(depthStencil))
     , m_platformRenderPipeline(WTFMove(pipeline))
     , m_primitiveTopology(topology)
     , m_indexFormat(format)