WebKit Bugzilla
Attachment 359350 Details for
Bug 193457
: [WebGPU] WebGPUProgrammablePassEncoder::setBindGroup prototype
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-193457-20190116211918.patch (text/plain), 29.04 KB, created by
Justin Fan
on 2019-01-16 21:19:18 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Justin Fan
Created:
2019-01-16 21:19:18 PST
Size:
29.04 KB
patch
obsolete
>Subversion Revision: 240102 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 2dd9d50fe636288195f458eb51848519ec65a993..6b03b04ea991f90ca34657d262f7b9520b02f1da 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,40 @@ >+2019-01-15 Justin Fan <justin_fan@apple.com> >+ >+ [WebGPU] WebGPUProgrammablePassEncoder::setBindGroup prototype >+ https://bugs.webkit.org/show_bug.cgi?id=193457 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ No new tests (OOPS!). >+ >+ * Sources.txt: >+ * WebCore.xcodeproj/project.pbxproj: >+ * platform/graphics/gpu/GPUBindGroup.h: >+ (WebCore::GPUBindGroup::layout const): >+ (WebCore::GPUBindGroup::bindings const): >+ * platform/graphics/gpu/GPUBindGroupLayout.h: >+ (WebCore::GPUBindGroupLayout::argumentEncoders const): >+ * platform/graphics/gpu/GPUCommandBuffer.h: >+ (WebCore::GPUCommandBuffer::device const): >+ * platform/graphics/gpu/GPUProgrammablePassEncoder.cpp: Copied from Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm. >+ (WebCore::GPUProgrammablePassEncoder::GPUProgrammablePassEncoder): >+ * platform/graphics/gpu/GPUProgrammablePassEncoder.h: >+ (WebCore::GPUProgrammablePassEncoder::setVertexBuffer): >+ (WebCore::GPUProgrammablePassEncoder::setFragmentBuffer): >+ * platform/graphics/gpu/GPURenderPassEncoder.h: >+ * platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm: >+ (WebCore::GPUCommandBuffer::create): >+ (WebCore::GPUCommandBuffer::GPUCommandBuffer): >+ * platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm: >+ (WebCore::GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder): >+ (WebCore::GPUProgrammablePassEncoder::setBindGroup): >+ * platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm: >+ (WebCore::GPURenderPassEncoder::create): >+ (WebCore::GPURenderPassEncoder::GPURenderPassEncoder): >+ (WebCore::GPURenderPassEncoder::useResource): >+ (WebCore::GPURenderPassEncoder::setVertexBuffer): >+ (WebCore::GPURenderPassEncoder::setFragmentBuffer): >+ > 2019-01-16 Justin Fan <justin_fan@apple.com> > > [WebGPU] Update vertex-buffer-triangle-strip.html to actually use vertex buffer >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBindGroup.h b/Source/WebCore/Modules/webgpu/WebGPUBindGroup.h >index 0a04709553bd4e9acaf2f8a1a1458e17131bcb83..504da950f5ce4097930ebbada132d6b9b6d69df1 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUBindGroup.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUBindGroup.h >@@ -37,6 +37,8 @@ class WebGPUBindGroup : public RefCounted<WebGPUBindGroup> { > public: > static Ref<WebGPUBindGroup> create(RefPtr<GPUBindGroup>&&); > >+ const GPUBindGroup* bindGroup() const { return m_bindGroup.get(); } >+ > private: > explicit WebGPUBindGroup(RefPtr<GPUBindGroup>&&); > >diff --git a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp b/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp >index c1bc8e601d339019f2623c9f58bf900fdd389bb2..f6f5ea6d334657719cab51b78fd3e001f82ac336 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp >@@ -29,6 +29,7 @@ > #if ENABLE(WEBGPU) > > #include "GPUProgrammablePassEncoder.h" >+#include "WebGPUBindGroup.h" > #include "WebGPURenderPipeline.h" > > namespace WebCore { >@@ -44,6 +45,16 @@ Ref<WebGPUCommandBuffer> WebGPUProgrammablePassEncoder::endPass() > return m_commandBuffer.copyRef(); > } > >+void WebGPUProgrammablePassEncoder::setBindGroup(unsigned long index, const WebGPUBindGroup& bindGroup) const >+{ >+ if (!bindGroup.bindGroup()) { >+ LOG(WebGPU, "WebGPUProgrammablePassEncoder::setBindGroup(): Invalid WebGPUBindGroup!"); >+ return; >+ } >+ // FIXME: Any validation (e.g. index duplicates, not in pipeline layout). >+ passEncoder().setBindGroup(index, *bindGroup.bindGroup()); >+} >+ > void WebGPUProgrammablePassEncoder::setPipeline(Ref<WebGPURenderPipeline>&& pipeline) > { > passEncoder().setPipeline(pipeline->renderPipeline()); >diff --git a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h b/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h >index ef10c1daffed2164f410ed4b66cd41a06a2242b2..acfd1fbfe46f949cf9ec0ee3e727e19939af123d 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h >@@ -28,12 +28,12 @@ > #if ENABLE(WEBGPU) > > #include "WebGPUCommandBuffer.h" >- > #include <wtf/RefCounted.h> > > namespace WebCore { > > class GPUProgrammablePassEncoder; >+class WebGPUBindGroup; > class WebGPURenderPipeline; > > class WebGPUProgrammablePassEncoder : public RefCounted<WebGPUProgrammablePassEncoder> { >@@ -41,6 +41,7 @@ public: > virtual ~WebGPUProgrammablePassEncoder() = default; > > Ref<WebGPUCommandBuffer> endPass(); >+ void setBindGroup(unsigned long, const WebGPUBindGroup&) const; > void setPipeline(Ref<WebGPURenderPipeline>&&); > > protected: >diff --git a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl b/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl >index 35361d969d374afd8eba15ee242609abf8e0a26b..3acd63945683c4eed682fe528a31d2a8c47dd4b4 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl >+++ b/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl >@@ -24,18 +24,14 @@ > */ > // https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl > >+typedef unsigned long u32; >+ > [ > Conditional=WEBGPU, > EnabledAtRuntime=WebGPU, > SkipVTableValidation > ] interface WebGPUProgrammablePassEncoder { > WebGPUCommandBuffer endPass(); >- >- // FIXME: Only support render pipelines for prototype. >- void setPipeline(WebGPURenderPipeline pipeline); >-/* Not Yet Implemented >- // Allowed in both compute and render passes >- // TODO: setPushConstants() ? >- void setBindGroup(u32 index, WebGPUBindGroup bindGroup); >-*/ >+ void setBindGroup(u32 index, WebGPUBindGroup bindGroup/*, optional sequence<u32> dynamicOffsets*/); >+ void setPipeline(WebGPURenderPipeline pipeline); // FIXME: Support WebGPUComputePipelines. > }; >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index b6124192ce94452f6d1fe4bbf309fcdac41b472a..91229629ade6feaca92c4bae09c5759eeb3e65a1 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -1791,6 +1791,7 @@ platform/graphics/filters/SpotLightSource.cpp > platform/graphics/gpu/GPUBindGroup.cpp > platform/graphics/gpu/GPUDevice.cpp > platform/graphics/gpu/GPUPipelineLayout.cpp >+platform/graphics/gpu/GPUProgrammablePassEncoder.cpp > platform/graphics/gpu/legacy/GPULegacyBuffer.cpp > platform/graphics/gpu/legacy/GPULegacyCommandBuffer.cpp > platform/graphics/gpu/legacy/GPULegacyCommandQueue.cpp >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index c498fa8a2bfefd5c7903115bf23708966f924115..433d1be771461f756154e606bdebcde31dbcabc5 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -13908,6 +13908,7 @@ > D00F595421701D8C000D71DB /* WebGPUDevice.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUDevice.idl; sourceTree = "<group>"; }; > D01A27AB10C9BFD800026A42 /* SpaceSplitString.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpaceSplitString.cpp; sourceTree = "<group>"; }; > D01A27AC10C9BFD800026A42 /* SpaceSplitString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpaceSplitString.h; sourceTree = "<group>"; }; >+ D01D0F9821EE77C70073D14D /* GPUProgrammablePassEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = GPUProgrammablePassEncoder.cpp; sourceTree = "<group>"; }; > D0232B5821CB49B7009483B9 /* GPUBindGroupLayoutMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUBindGroupLayoutMetal.mm; sourceTree = "<group>"; }; > D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayout.h; sourceTree = "<group>"; }; > D02B83ED21C8397A00F85473 /* WebGPUBindGroupLayoutDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBindGroupLayoutDescriptor.idl; sourceTree = "<group>"; }; >@@ -18278,6 +18279,7 @@ > D003288621C9A4E500622AA6 /* GPUPipelineLayout.h */, > D003288421C9A20D00622AA6 /* GPUPipelineLayoutDescriptor.h */, > 312FF8C221A4C2F300EB199D /* GPUPipelineStageDescriptor.h */, >+ D01D0F9821EE77C70073D14D /* GPUProgrammablePassEncoder.cpp */, > D03211CF21AC954E00763CF2 /* GPUProgrammablePassEncoder.h */, > 312FF8C121A4C2F200EB199D /* GPUQueue.h */, > D001D9A921B0C6730023B9BC /* GPURenderPassColorAttachmentDescriptor.h */, >diff --git a/Source/WebCore/platform/graphics/gpu/GPUBindGroup.h b/Source/WebCore/platform/graphics/gpu/GPUBindGroup.h >index 806138367971de6bad5cb65af19f75510cc33092..2cdc073736011eaa02b0e6637ea2d4310c6e7324 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUBindGroup.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUBindGroup.h >@@ -41,6 +41,9 @@ class GPUBindGroup : public RefCounted<GPUBindGroup> { > public: > static Ref<GPUBindGroup> create(GPUBindGroupDescriptor&&); > >+ const GPUBindGroupLayout& layout() const { return m_layout.get(); } >+ const Vector<GPUBindGroupBinding>& bindings() const { return m_bindings; } >+ > private: > explicit GPUBindGroup(GPUBindGroupDescriptor&&); > >diff --git a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h b/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >index f2ad89e70df0f31ed93e6684216501c671d37a3e..6244443b287c90fe8a9e12b8eee0e68ec75e6867 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >@@ -52,6 +52,7 @@ public: > > using BindingsMapType = HashMap<unsigned long long, GPUBindGroupLayoutBinding, WTF::IntHash<unsigned long long>, WTF::UnsignedWithZeroKeyHashTraits<unsigned long long>>; > const BindingsMapType& bindingsMap() const { return m_bindingsMap; } >+ const ArgumentEncoders& argumentEncoders() const { return m_argumentEncoders; } > > private: > GPUBindGroupLayout(BindingsMapType&&, ArgumentEncoders&&); >diff --git a/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h b/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h >index 81e8e99e2806a2bd5d161d6704229ba35d125fbf..07a2416735ab18a70c5665ea5672239f2f4b0ed4 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h >@@ -27,6 +27,7 @@ > > #if ENABLE(WEBGPU) > >+#include "GPUDevice.h" > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> > #include <wtf/RetainPtr.h> >@@ -35,21 +36,21 @@ OBJC_PROTOCOL(MTLCommandBuffer); > > namespace WebCore { > >-class GPUDevice; >- > using PlatformCommandBuffer = MTLCommandBuffer; > using PlatformCommandBufferSmartPtr = RetainPtr<MTLCommandBuffer>; > > class GPUCommandBuffer : public RefCounted<GPUCommandBuffer> { > public: >- static RefPtr<GPUCommandBuffer> create(GPUDevice&); >+ static RefPtr<GPUCommandBuffer> create(Ref<GPUDevice>); > > PlatformCommandBuffer* platformCommandBuffer() const { return m_platformCommandBuffer.get(); } >+ Ref<GPUDevice> device() const { return m_device.copyRef(); } > > private: >- GPUCommandBuffer(PlatformCommandBufferSmartPtr&&); >+ GPUCommandBuffer(PlatformCommandBufferSmartPtr&&, Ref<GPUDevice>&&); > > PlatformCommandBufferSmartPtr m_platformCommandBuffer; >+ Ref<GPUDevice> m_device; > }; > > } // namespace WebCore >diff --git a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp b/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >index 11329ee85e51b02bd31c81b3fe2a2139432d74f3..41524a587dac1e8aaf407c8b92764e2ffb6ee335 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >+++ b/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >@@ -32,6 +32,7 @@ > #include "GPUBindGroupLayoutDescriptor.h" > #include "GPUBuffer.h" > #include "GPUBufferDescriptor.h" >+#include "GPUCommandBuffer.h" > #include "GPUPipelineLayout.h" > #include "GPUPipelineLayoutDescriptor.h" > #include "GPURenderPipeline.h" >diff --git a/Source/WebCore/platform/graphics/gpu/GPUDevice.h b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >index 376d0fe62fbd33fbf7e2e16c064bdb22a04ff497..6e6d5153185b8baede4b349cb05a2317cba18a4a 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUDevice.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >@@ -27,9 +27,7 @@ > > #if ENABLE(WEBGPU) > >-#include "GPUCommandBuffer.h" > #include "GPUQueue.h" >- > #include <wtf/RefCounted.h> > #include <wtf/RefPtr.h> > #include <wtf/RetainPtr.h> >@@ -43,6 +41,7 @@ using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>; > > class GPUBindGroupLayout; > class GPUBuffer; >+class GPUCommandBuffer; > class GPUPipelineLayout; > class GPURenderPipeline; > class GPUShaderModule; >diff --git a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.cpp b/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..2cab177cac4efc45f1dc6ae45a943b4cdb658650 >--- /dev/null >+++ b/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.cpp >@@ -0,0 +1,40 @@ >+/* >+ * Copyright (C) 2019 Apple Inc. All rights reserved. >+ * >+ * Redistribution and use in source and binary forms, with or without >+ * modification, are permitted provided that the following conditions >+ * are met: >+ * 1. Redistributions of source code must retain the above copyright >+ * notice, this list of conditions and the following disclaimer. >+ * 2. Redistributions in binary form must reproduce the above copyright >+ * notice, this list of conditions and the following disclaimer in the >+ * documentation and/or other materials provided with the distribution. >+ * >+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' >+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, >+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR >+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS >+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR >+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF >+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS >+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN >+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) >+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF >+ * THE POSSIBILITY OF SUCH DAMAGE. >+ */ >+ >+#include "config.h" >+#include "GPUProgrammablePassEncoder.h" >+ >+#if ENABLE(WEBGPU) >+ >+namespace WebCore { >+ >+GPUProgrammablePassEncoder::GPUProgrammablePassEncoder(Ref<GPUDevice>&& device) >+ : m_device(WTFMove(device)) >+{ >+} >+ >+} // namespace WebCore >+ >+#endif // ENABLE(WEBGPU) >diff --git a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h b/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h >index 948c0c886a93a958581590c9a52b544a4bd726e5..4a4bc749e982ece1116333277f61283d3d59afe3 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h >@@ -27,12 +27,18 @@ > > #if ENABLE(WEBGPU) > >+#include "GPUBindGroupBinding.h" >+#include "GPUDevice.h" > #include <wtf/RefCounted.h> > >+OBJC_PROTOCOL(MTLArgumentEncoder); >+OBJC_PROTOCOL(MTLBuffer); > OBJC_PROTOCOL(MTLCommandEncoder); >+OBJC_PROTOCOL(MTLResource); > > namespace WebCore { > >+class GPUBindGroup; > class GPURenderPipeline; > > using PlatformProgrammablePassEncoder = MTLCommandEncoder; >@@ -42,13 +48,22 @@ public: > virtual ~GPUProgrammablePassEncoder() = default; > > void endPass(); >- >+ void setBindGroup(unsigned long, const GPUBindGroup&); > virtual void setPipeline(Ref<GPURenderPipeline>&&) = 0; > > protected: >+ explicit GPUProgrammablePassEncoder(Ref<GPUDevice>&&); > virtual PlatformProgrammablePassEncoder* platformPassEncoder() const = 0; > > private: >+ void setResourceAsBufferOnEncoder(MTLArgumentEncoder *, const GPUBindingResource&, unsigned long, const char* const); >+ virtual void useResource(MTLResource *, unsigned long) = 0; >+ >+ // Render command encoder methods. >+ virtual void setVertexBuffer(MTLBuffer *, unsigned long, unsigned long) { } >+ virtual void setFragmentBuffer(MTLBuffer *, unsigned long, unsigned long) { } >+ >+ Ref<GPUDevice> m_device; > bool m_isEncoding { true }; > }; > >diff --git a/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h b/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h >index 501aa3d1521472911f2e008fdad26d8122612c12..042f7d098c81f2b9a610cb47cf405af7e4a9f24d 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h >+++ b/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h >@@ -41,6 +41,7 @@ namespace WebCore { > > class GPUBuffer; > class GPUCommandBuffer; >+class GPUDevice; > > struct GPURenderPassDescriptor; > >@@ -57,11 +58,16 @@ public: > void draw(unsigned long, unsigned long, unsigned long, unsigned long); > > private: >- GPURenderPassEncoder(PlatformRenderPassEncoderSmartPtr&&); >+ GPURenderPassEncoder(PlatformRenderPassEncoderSmartPtr&&, Ref<GPUDevice>&&); > ~GPURenderPassEncoder() { endPass(); } // Ensure that encoding has ended before release. > > PlatformProgrammablePassEncoder* platformPassEncoder() const final; > >+ // GPUProgrammablePassEncoder >+ void useResource(MTLResource *, unsigned long) final; >+ void setVertexBuffer(MTLBuffer *, unsigned long, unsigned long) final; >+ void setFragmentBuffer(MTLBuffer *, unsigned long, unsigned long) final; >+ > PlatformRenderPassEncoderSmartPtr m_platformRenderPassEncoder; > RefPtr<GPURenderPipeline> m_pipeline; > }; >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >index 61259d234fb3a124f991784a5d8fd6887037e208..c69f27700e04fe54febcf02d3b0cfce817dd4242 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >@@ -37,14 +37,14 @@ > > namespace WebCore { > >-RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUDevice& device) >+RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(Ref<GPUDevice> device) > { >- if (!device.platformDevice()) { >+ if (!device->platformDevice()) { > LOG(WebGPU, "GPUCommandBuffer::create(): Invalid GPUDevice!"); > return nullptr; > } > >- auto gpuCommandQueue = device.getQueue(); >+ auto gpuCommandQueue = device->getQueue(); > if (!gpuCommandQueue) > return nullptr; > >@@ -63,11 +63,12 @@ RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUDevice& device) > return nullptr; > } > >- return adoptRef(new GPUCommandBuffer(WTFMove(buffer))); >+ return adoptRef(new GPUCommandBuffer(WTFMove(buffer), WTFMove(device))); > } > >-GPUCommandBuffer::GPUCommandBuffer(PlatformCommandBufferSmartPtr&& buffer) >+GPUCommandBuffer::GPUCommandBuffer(PlatformCommandBufferSmartPtr&& buffer, Ref<GPUDevice>&& device) > : m_platformCommandBuffer(WTFMove(buffer)) >+ , m_device(WTFMove(device)) > { > UNUSED_PARAM(m_platformCommandBuffer); > } >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm >index 2e643638146a1b89ca7f8c9686653d2725d3418e..166e1016fd6ded8a2809264543875b0695507335 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm >@@ -28,7 +28,11 @@ > > #if ENABLE(WEBGPU) > >+#import "GPUBindGroup.h" >+#import "GPUBindGroupLayoutBinding.h" >+#import "Logging.h" > #import <Metal/Metal.h> >+#import <wtf/BlockObjCExceptions.h> > > namespace WebCore { > >@@ -41,6 +45,99 @@ void GPUProgrammablePassEncoder::endPass() > m_isEncoding = false; > } > >+void GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder(MTLArgumentEncoder *argumentEncoder, const GPUBindingResource& resource, unsigned long index, const char* const functionName) >+{ >+#if LOG_DISABLED >+ UNUSED_PARAM(functionName); >+#endif >+ if (!argumentEncoder) { >+ LOG(WebGPU, "%s: No argument encoder for requested stage found!", functionName); >+ return; >+ } >+ >+ if (!WTF::holds_alternative<GPUBufferBinding>(resource)) { >+ LOG(WebGPU, "%s: Resource is not a buffer type!", functionName); >+ return; >+ } >+ >+ auto& bufferBinding = WTF::get<GPUBufferBinding>(resource); >+ auto buffer = bufferBinding.buffer->platformBuffer(); >+ >+ if (!buffer) { >+ LOG(WebGPU, "%s: Invalid MTLBuffer in GPUBufferBinding!", functionName); >+ return; >+ } >+ >+ BEGIN_BLOCK_OBJC_EXCEPTIONS; >+ >+ [argumentEncoder setBuffer:buffer offset:bufferBinding.offset atIndex:index]; >+ useResource(buffer, MTLResourceUsageRead); >+ >+ END_BLOCK_OBJC_EXCEPTIONS; >+} >+ >+void GPUProgrammablePassEncoder::setBindGroup(unsigned long index, const GPUBindGroup& bindGroup) >+{ >+ const char* const functionName = "GPUProgrammablePassEncoder::setBindGroup()"; >+#if LOG_DISABLED >+ UNUSED_PARAM(functionName); >+#endif >+ // Create argument buffers for each MTLArgumentEncoder in the pipeline layout. >+ if (!m_device->platformDevice()) { >+ LOG(WebGPU, "%s: Invalid MTLDevice!", functionName); >+ return; >+ } >+ >+ const auto& encoders = bindGroup.layout().argumentEncoders(); >+ RetainPtr<MTLBuffer> vertexArgumentBuffer, fragmentArgumentBuffer, computeArgumentBuffer; >+ >+ BEGIN_BLOCK_OBJC_EXCEPTIONS; >+ >+ if (encoders.vertex) { >+ vertexArgumentBuffer = adoptNS([m_device->platformDevice() newBufferWithLength:encoders.vertex.get().encodedLength options:0]); >+ [encoders.vertex setArgumentBuffer:vertexArgumentBuffer.get() offset:0]; >+ setVertexBuffer(vertexArgumentBuffer.get(), 0, index); >+ } >+ if (encoders.fragment) { >+ fragmentArgumentBuffer = adoptNS([m_device->platformDevice() newBufferWithLength:encoders.fragment.get().encodedLength options:0]); >+ [encoders.fragment setArgumentBuffer:fragmentArgumentBuffer.get() offset:0]; >+ setFragmentBuffer(fragmentArgumentBuffer.get(), 0, index); >+ } >+ if (encoders.compute) { >+ computeArgumentBuffer = adoptNS([m_device->platformDevice() newBufferWithLength:encoders.compute.get().encodedLength options:0]); >+ [encoders.compute setArgumentBuffer:computeArgumentBuffer.get() offset:0]; >+ // FIXME: Finish support for compute. >+ } >+ >+ END_BLOCK_OBJC_EXCEPTIONS; >+ >+ // Set each resource on each MTLArgumentEncoder it should be visible on. >+ const auto& bindingsMap = bindGroup.layout().bindingsMap(); >+ for (const auto& binding : bindGroup.bindings()) { >+ auto iterator = bindingsMap.find(binding.binding); >+ if (iterator == bindingsMap.end()) { >+ LOG(WebGPU, "%s: GPUBindGroupBinding %lu not found in GPUBindGroupLayout!", functionName, binding.binding); >+ return; >+ } >+ auto bindGroupLayoutBinding = iterator->value; >+ >+ switch (bindGroupLayoutBinding.type) { >+ // FIXME: Support more resource types, and support compute stage resources. >+ case GPUBindGroupLayoutBinding::BindingType::UniformBuffer: >+ case GPUBindGroupLayoutBinding::BindingType::StorageBuffer: { >+ if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::VERTEX) >+ setResourceAsBufferOnEncoder(encoders.vertex.get(), binding.resource, binding.binding, functionName); >+ if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::FRAGMENT) >+ setResourceAsBufferOnEncoder(encoders.fragment.get(), binding.resource, binding.binding, functionName); >+ break; >+ } >+ default: >+ LOG(WebGPU, "%s: Resource type not yet implemented.", functionName); >+ return; >+ } >+ } >+} >+ > } // namespace WebCore > > #endif // ENABLE(WEBGPU) >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm >index 5565063f6400b403854353daac67e35051401473..f73a95381b184514f7a0157a5db83fab8ff28e73 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm >@@ -30,6 +30,7 @@ > > #import "GPUBuffer.h" > #import "GPUCommandBuffer.h" >+#import "GPUDevice.h" > #import "GPURenderPassDescriptor.h" > #import "GPURenderPipeline.h" > #import "Logging.h" >@@ -65,11 +66,12 @@ RefPtr<GPURenderPassEncoder> GPURenderPassEncoder::create(const GPUCommandBuffer > return nullptr; > } > >- return adoptRef(new GPURenderPassEncoder(WTFMove(mtlEncoder))); >+ return adoptRef(new GPURenderPassEncoder(WTFMove(mtlEncoder), buffer.device())); > } > >-GPURenderPassEncoder::GPURenderPassEncoder(PlatformRenderPassEncoderSmartPtr&& encoder) >- : m_platformRenderPassEncoder(WTFMove(encoder)) >+GPURenderPassEncoder::GPURenderPassEncoder(PlatformRenderPassEncoderSmartPtr&& encoder, Ref<GPUDevice>&& device) >+ : GPUProgrammablePassEncoder(WTFMove(device)) >+ , m_platformRenderPassEncoder(WTFMove(encoder)) > { > } > >@@ -118,6 +120,21 @@ void GPURenderPassEncoder::draw(unsigned long vertexCount, unsigned long instanc > baseInstance:firstInstance]; > } > >+void GPURenderPassEncoder::useResource(MTLResource *resource, MTLResourceUsage usage) >+{ >+ [m_platformRenderPassEncoder useResource:resource usage:usage]; >+} >+ >+void GPURenderPassEncoder::setVertexBuffer(MTLBuffer *buffer, unsigned long offset, unsigned long index) >+{ >+ [m_platformRenderPassEncoder setVertexBuffer:buffer offset:offset atIndex:index]; >+} >+ >+void GPURenderPassEncoder::setFragmentBuffer(MTLBuffer *buffer, unsigned long offset, unsigned long index) >+{ >+ [m_platformRenderPassEncoder setFragmentBuffer:buffer offset:offset atIndex:index]; >+} >+ > } // namespace WebCore > > #endif // ENABLE(WEBGPU) >diff --git a/LayoutTests/webgpu/buffer-resource-triangle-strip.html b/LayoutTests/webgpu/buffer-resource-triangle-strip.html >new file mode 100644 >index 0000000000000000000000000000000000000000..eb36d27dc7a8c4142065e915e5d3181fd0d81a42 >--- /dev/null >+++ b/LayoutTests/webgpu/buffer-resource-triangle-strip.html >@@ -0,0 +1,94 @@ >+<!DOCTYPE html> >+<meta charset="utf-8"> >+<title>WebGPU Hello Triangles</title> >+<meta name="assert" content="WebGPU correctly renders a green canvas."> >+<link rel="match" href="vertex-buffer-triangle-strip-expected.html"> >+<p>Pass if square canvas below is completely green.</p> >+<canvas width="400" height="400"></canvas> >+<script src="js/webgpu-functions.js"></script> >+<script> >+const shaderCode = ` >+#include <metal_stdlib> >+ >+using namespace metal; >+ >+struct Vertex >+{ >+ float4 position [[position]]; >+}; >+ >+struct Arguments { >+ device Vertex* vertexBuffer; >+}; >+ >+vertex Vertex vertex_main(const device Arguments& args [[buffer(0)]], uint vid [[vertex_id]]) >+{ >+ return args.vertexBuffer[vid]; >+} >+ >+fragment float4 fragment_main(Vertex v [[stage_in]]) >+{ >+ return float4(0.0, 1.0, 0.0, 1.0); >+} >+` >+ >+const bufferSize = 4 * 4 * 4; >+ >+function createVertexBuffer(device) { >+ const buffer = device.createBuffer({ size: bufferSize, usage: WebGPUBufferUsage.VERTEX }); >+ >+ let arrayBuffer = buffer.mapping; >+ let floatArray = new Float32Array(arrayBuffer); >+ >+ floatArray[0] = -1; >+ floatArray[1] = 1; >+ floatArray[2] = 0; >+ floatArray[3] = 1; >+ >+ floatArray[4] = -1; >+ floatArray[5] = -1; >+ floatArray[6] = 0; >+ floatArray[7] = 1; >+ >+ floatArray[8] = 1; >+ floatArray[9] = 1; >+ floatArray[10] = 0; >+ floatArray[11] = 1; >+ >+ floatArray[12] = 1; >+ floatArray[13] = -1; >+ floatArray[14] = 0; >+ floatArray[15] = 1; >+ >+ return buffer; >+} >+ >+async function test() { >+ const device = await getBasicDevice(); >+ const canvas = document.querySelector("canvas"); >+ const context = createBasicContext(canvas, device); >+ // FIXME: Replace with non-MSL shaders. >+ const shaderModule = device.createShaderModule({ code: shaderCode }); >+ >+ const layoutBinding = { binding: 0, visibility: WebGPUShaderStageBit.VERTEX, type: "uniformBuffer" }; >+ const bindGroupLayout = device.createBindGroupLayout({ bindings: [layoutBinding] }); >+ const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [bindGroupLayout] }); >+ const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout); >+ >+ const vertexBuffer = createVertexBuffer(device); >+ const bufferBinding = { buffer: vertexBuffer, offset: 0, size: bufferSize }; >+ const bindGroupBinding = { binding: 0, resource: bufferBinding }; >+ const bindGroup = device.createBindGroup({ layout: bindGroupLayout, bindings: [bindGroupBinding] }); >+ >+ const commandBuffer = device.createCommandBuffer(); >+ const passEncoder = beginBasicRenderPass(context, commandBuffer); >+ passEncoder.setBindGroup(0, bindGroup); >+ const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline); >+ const queue = device.getQueue(); >+ >+ queue.submit([endCommandBuffer]); >+ context.present(); >+} >+ >+test(); >+</script> >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 193457
:
359192
|
359337
|
359350
|
359503
|
359508
|
359510
|
359523
|
359541