WebKit Bugzilla
Attachment 359510 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-20190118110226.patch (text/plain), 48.91 KB, created by
Justin Fan
on 2019-01-18 11:02:27 PST
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Justin Fan
Created:
2019-01-18 11:02:27 PST
Size:
48.91 KB
patch
obsolete
>Subversion Revision: 240102 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 2dd9d50fe636288195f458eb51848519ec65a993..0229326bf89abe8dcc797105f50d9fa1709e9d76 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,53 @@ >+2019-01-18 Justin Fan <justin_fan@apple.com> >+ >+ (WIP) [WebGPU] WebGPUProgrammablePassEncoder::setBindGroup prototype >+ https://bugs.webkit.org/show_bug.cgi?id=193457 >+ <rdar://problem/47296678> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Enable WebGPU developers to assign buffer bind groups and access them via render pipeline. >+ Support for compute pipelines to follow shortly. >+ Texture and sampler resources to follow after their requisite interfaces are implemented. >+ >+ Test: webgpu/buffer-resource-triangles.html >+ >+ * Modules/webgpu/WebGPUBindGroup.h: >+ (WebCore::WebGPUBindGroup::bindGroup const): Added getter. >+ * Modules/webgpu/WebGPUProgrammablePassEncoder.cpp: >+ (WebCore::WebGPUProgrammablePassEncoder::setBindGroup const): Added. Delegates call to GPUProgrammablePassEncoder. >+ * Modules/webgpu/WebGPUProgrammablePassEncoder.h: Enable setBindGroup. >+ * Modules/webgpu/WebGPUProgrammablePassEncoder.idl: ditto. >+ * WebCore.xcodeproj/project.pbxproj: >+ * platform/graphics/gpu/GPUBindGroup.h: >+ (WebCore::GPUBindGroup::layout const): Added getter. >+ (WebCore::GPUBindGroup::bindings const): ditto. >+ * platform/graphics/gpu/GPUBindGroupLayout.h: Added ArgumentEncoderBuffer struct to retain ptr tot both MTLArgumentEncoders and their argument MTLBuffers. >+ (WebCore::GPUBindGroupLayout::ArgumentEncoderBuffer::operator! const): >+ (WebCore::GPUBindGroupLayout::vertexArguments const): Added. Getter. >+ (WebCore::GPUBindGroupLayout::fragmentArguments const): ditto. >+ (WebCore::GPUBindGroupLayout::computeArguments const): ditto. >+ * platform/graphics/gpu/GPUDevice.cpp: Refactored unnecessary header include. >+ * platform/graphics/gpu/GPUDevice.h: ditto. >+ * platform/graphics/gpu/GPUProgrammablePassEncoder.h: >+ (WebCore::GPUProgrammablePassEncoder::setVertexBuffer): Added. Delegates to MTLCommandEncoder call. >+ (WebCore::GPUProgrammablePassEncoder::setFragmentBuffer): ditto. >+ * platform/graphics/gpu/GPURenderPassEncoder.h: >+ * platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm: >+ (WebCore::tryCreateArgumentEncoderAndBuffer): Replace newEncoder(). Now create an ArgumentEncoderBuffer object from an array of MTLArgumentDescriptors, if able. >+ (WebCore::GPUBindGroupLayout::tryCreate): Refactor to support ArgumentEncoderBuffers, and allocate MTLBuffers for argument encoders. >+ (WebCore::GPUBindGroupLayout::GPUBindGroupLayout): Support ArgumentEncoderBuffers. >+ (WebCore::newEncoder): Deleted. >+ * platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm: >+ (WebCore::GPUCommandBuffer::GPUCommandBuffer): >+ * platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm: >+ (WebCore::GPUProgrammablePassEncoder::setResourceAsBufferOnEncoder): Set a buffer resource on the MTLArgumentEncoder, and call useResource on the command encoder. >+ (WebCore::GPUProgrammablePassEncoder::setBindGroup): Parses the bind group to assign each resource on its matching MTLArgumentEncoder. >+ * platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm: >+ (WebCore::GPURenderPassEncoder::useResource): Resolves call from GPUProgrammablePassEncoder to call on MTLRenderCommandEncoder. >+ (WebCore::GPURenderPassEncoder::setVertexBuffer): ditto. >+ (WebCore::GPURenderPassEncoder::setFragmentBuffer): ditto. >+ > 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/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index c498fa8a2bfefd5c7903115bf23708966f924115..06a8c6209297cfe525a547025b7c77fe70ae12d3 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -6427,17 +6427,16 @@ > 1C840B9A21EC400900D0500D /* WHLSLGatherEntryPointItems.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLGatherEntryPointItems.h; sourceTree = "<group>"; }; > 1C840B9B21EC400900D0500D /* WHLSLChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLChecker.cpp; sourceTree = "<group>"; }; > 1C904DF90BA9D2C80081E9D0 /* Version.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Version.xcconfig; sourceTree = "<group>"; }; >- 1CA0C2E421EED12A00A11860 /* WHLSLFunctionStageChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLFunctionStageChecker.cpp; sourceTree = "<group>"; }; >- 1CA0C2E521EED12A00A11860 /* WHLSLFunctionStageChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLFunctionStageChecker.h; sourceTree = "<group>"; }; >+ 1C9AE5CA21ED9DF50069D5F2 /* WHLSLHighZombieFinder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLHighZombieFinder.cpp; sourceTree = "<group>"; }; >+ 1C9AE5CB21ED9DF50069D5F2 /* WHLSLHighZombieFinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLHighZombieFinder.h; sourceTree = "<group>"; }; > 1CA0C2DE21EEB5F400A11860 /* WHLSLRecursionChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLRecursionChecker.h; sourceTree = "<group>"; }; > 1CA0C2E021EEB5F500A11860 /* WHLSLRecursionChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLRecursionChecker.cpp; sourceTree = "<group>"; }; >+ 1CA0C2E421EED12A00A11860 /* WHLSLFunctionStageChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLFunctionStageChecker.cpp; sourceTree = "<group>"; }; >+ 1CA0C2E521EED12A00A11860 /* WHLSLFunctionStageChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLFunctionStageChecker.h; sourceTree = "<group>"; }; > 1CA0C2EA21EED6F500A11860 /* WHLSLLiteralTypeChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLLiteralTypeChecker.h; sourceTree = "<group>"; }; > 1CA0C2EC21EED6F600A11860 /* WHLSLLiteralTypeChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLLiteralTypeChecker.cpp; sourceTree = "<group>"; }; >- 1C9AE5CA21ED9DF50069D5F2 /* WHLSLHighZombieFinder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLHighZombieFinder.cpp; sourceTree = "<group>"; }; >- 1C9AE5CB21ED9DF50069D5F2 /* WHLSLHighZombieFinder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLHighZombieFinder.h; sourceTree = "<group>"; }; > 1CA0C2F421EEDAD000A11860 /* WHLSLLoopChecker.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WHLSLLoopChecker.cpp; sourceTree = "<group>"; }; > 1CA0C2F521EEDAD100A11860 /* WHLSLLoopChecker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WHLSLLoopChecker.h; sourceTree = "<group>"; }; >- 1CA0C2F621EEDAD200A11860 /* AST */ = {isa = PBXFileReference; lastKnownFileType = folder; path = AST; sourceTree = "<group>"; }; > 1CA19E030DC255950065A994 /* EventLoopMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = EventLoopMac.mm; sourceTree = "<group>"; }; > 1CA19E150DC255CA0065A994 /* EventLoop.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventLoop.h; sourceTree = "<group>"; }; > 1CAF347E0A6C405200ABE06E /* WebScriptObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebScriptObject.h; sourceTree = "<group>"; }; >@@ -17032,6 +17031,100 @@ > tabWidth = 8; > usesTabs = 0; > }; >+ 1CA0C2F621EEDAD200A11860 /* AST */ = { >+ isa = PBXGroup; >+ children = ( >+ 1C840B9021EC30F900D0500D /* WHLSLAddressSpace.h */, >+ C21BF72521CD89E200227979 /* WHLSLArrayReferenceType.h */, >+ C21BF70921CD89CA00227979 /* WHLSLArrayType.h */, >+ C21BF73021CD89ED00227979 /* WHLSLAssignmentExpression.h */, >+ C21BF70A21CD89CB00227979 /* WHLSLBaseFunctionAttribute.h */, >+ C21BF6FA21CD89BE00227979 /* WHLSLBaseSemantic.h */, >+ C21BF71E21CD89DC00227979 /* WHLSLBlock.h */, >+ C21BF6F621CD89B700227979 /* WHLSLBooleanLiteral.h */, >+ C21BF71A21CD89D800227979 /* WHLSLBreak.h */, >+ C2138A1321DDECD300F516BA /* WHLSLBuiltInSemantic.cpp */, >+ C21BF72221CD89DF00227979 /* WHLSLBuiltInSemantic.h */, >+ C21BF71621CD89D500227979 /* WHLSLCallExpression.h */, >+ C21BF70621CD89C700227979 /* WHLSLCommaExpression.h */, >+ C21BF73321CD89F000227979 /* WHLSLConstantExpression.h */, >+ C21BF6F521CD89B500227979 /* WHLSLContinue.h */, >+ C21BF70121CD89C400227979 /* WHLSLDereferenceExpression.h */, >+ C21BF71821CD89D700227979 /* WHLSLDotExpression.h */, >+ C21BF6FB21CD89BE00227979 /* WHLSLDoWhileLoop.h */, >+ C21BF72821CD89E500227979 /* WHLSLEffectfulExpressionStatement.h */, >+ 1C840B7D21EBE0B800D0500D /* WHLSLEntryPointType.h */, >+ C21BF72021CD89DD00227979 /* WHLSLEnumerationDefinition.h */, >+ C21BF72621CD89E300227979 /* WHLSLEnumerationMember.h */, >+ C21BF70221CD89C400227979 /* WHLSLEnumerationMemberLiteral.h */, >+ C21BF70C21CD89CC00227979 /* WHLSLExpression.h */, >+ C21BF70021CD89C200227979 /* WHLSLFallthrough.h */, >+ C21BF73521CD89F200227979 /* WHLSLFloatLiteral.h */, >+ 1CB69B3821DF03E1006E846A /* WHLSLFloatLiteralType.cpp */, >+ 1CB69B3421DED63A006E846A /* WHLSLFloatLiteralType.h */, >+ C21BF73421CD89F100227979 /* WHLSLForLoop.h */, >+ C21BF70521CD89C700227979 /* WHLSLFunctionAttribute.h */, >+ C21BF6FD21CD89C000227979 /* WHLSLFunctionDeclaration.h */, >+ C21BF6F421CD89B300227979 /* WHLSLFunctionDefinition.h */, >+ C21BF6FF21CD89C200227979 /* WHLSLIfStatement.h */, >+ C21BF6F721CD89B900227979 /* WHLSLIndexExpression.h */, >+ C20F4F6621DFF2360070C45A /* WHLSLIntegerLiteral.cpp */, >+ C21BF6F821CD89BB00227979 /* WHLSLIntegerLiteral.h */, >+ 1CB69B3921DF03F3006E846A /* WHLSLIntegerLiteralType.cpp */, >+ 1CB69B3521DED649006E846A /* WHLSLIntegerLiteralType.h */, >+ C21BF73221CD89EF00227979 /* WHLSLLogicalExpression.h */, >+ C21BF71521CD89D400227979 /* WHLSLLogicalNotExpression.h */, >+ C21BF72D21CD89E900227979 /* WHLSLMakeArrayReferenceExpression.h */, >+ C21BF72C21CD89E900227979 /* WHLSLMakePointerExpression.h */, >+ 1C33277121CF0BE1000DC9F2 /* WHLSLNamedType.h */, >+ C21BF72321CD89E100227979 /* WHLSLNativeFunctionDeclaration.h */, >+ C21BF72A21CD89E700227979 /* WHLSLNativeTypeDeclaration.h */, >+ C21BF72421CD89E100227979 /* WHLSLNode.h */, >+ C21BF70721CD89C800227979 /* WHLSLNullLiteral.h */, >+ 1CB69B3A21DF0403006E846A /* WHLSLNullLiteralType.cpp */, >+ 1CB69B3621DED657006E846A /* WHLSLNullLiteralType.h */, >+ C21BF72121CD89DE00227979 /* WHLSLNumThreadsFunctionAttribute.h */, >+ C21BF72F21CD89EC00227979 /* WHLSLPointerType.h */, >+ C21BF72E21CD89EA00227979 /* WHLSLPropertyAccessExpression.h */, >+ C21BF70B21CD89CC00227979 /* WHLSLQualifier.h */, >+ C21BF71B21CD89D900227979 /* WHLSLReadModifyWriteExpression.h */, >+ C21BF70D21CD89CD00227979 /* WHLSLReferenceType.h */, >+ 1CB69B3221DED40B006E846A /* WHLSLResolvableType.h */, >+ C2138A1521DDECE900F516BA /* WHLSLResourceSemantic.cpp */, >+ C21BF70821CD89C900227979 /* WHLSLResourceSemantic.h */, >+ C21BF70321CD89C500227979 /* WHLSLReturn.h */, >+ C21BF6F921CD89BD00227979 /* WHLSLSemantic.h */, >+ C2138A1621DDECFB00F516BA /* WHLSLSpecializationConstantSemantic.cpp */, >+ C21BF73621CD89F300227979 /* WHLSLSpecializationConstantSemantic.h */, >+ C2138A1721DDED0D00F516BA /* WHLSLStageInOutSemantic.cpp */, >+ C21BF70E21CD89CE00227979 /* WHLSLStageInOutSemantic.h */, >+ C21BF71221CD89D100227979 /* WHLSLStatement.h */, >+ C21BF72721CD89E400227979 /* WHLSLStructureDefinition.h */, >+ C21BF6FE21CD89C100227979 /* WHLSLStructureElement.h */, >+ C21BF71921CD89D700227979 /* WHLSLSwitchCase.h */, >+ C21BF73121CD89EE00227979 /* WHLSLSwitchStatement.h */, >+ C21BF71C21CD89DA00227979 /* WHLSLTernaryExpression.h */, >+ C21BF6F321CD89AD00227979 /* WHLSLTrap.h */, >+ C21BF71D21CD89DB00227979 /* WHLSLType.h */, >+ C288C72D21C991DA002DF5CA /* WHLSLTypeArgument.cpp */, >+ C21BF71121CD89D100227979 /* WHLSLTypeArgument.h */, >+ C21BF72921CD89E600227979 /* WHLSLTypeDefinition.h */, >+ C20F4F6421DFBE5C0070C45A /* WHLSLTypeReference.cpp */, >+ C21BF71F21CD89DC00227979 /* WHLSLTypeReference.h */, >+ 1C33277221CF0D2E000DC9F2 /* WHLSLUnnamedType.h */, >+ C20F4F6721DFF3A70070C45A /* WHLSLUnsignedIntegerLiteral.cpp */, >+ C21BF72B21CD89E800227979 /* WHLSLUnsignedIntegerLiteral.h */, >+ 1CB69B3B21DF041E006E846A /* WHLSLUnsignedIntegerLiteralType.cpp */, >+ 1CB69B3721DED66B006E846A /* WHLSLUnsignedIntegerLiteralType.h */, >+ C21BF6FC21CD89BF00227979 /* WHLSLValue.h */, >+ C21BF71021CD89D000227979 /* WHLSLVariableDeclaration.h */, >+ C21BF71421CD89D300227979 /* WHLSLVariableDeclarationsStatement.h */, >+ C21BF71321CD89D200227979 /* WHLSLVariableReference.h */, >+ C21BF70421CD89C600227979 /* WHLSLWhileLoop.h */, >+ ); >+ path = AST; >+ sourceTree = "<group>"; >+ }; > 1CDD44660BA9C80000F90147 /* Configurations */ = { > isa = PBXGroup; > children = ( >@@ -25508,100 +25601,6 @@ > path = WHLSL; > sourceTree = "<group>"; > }; >- 1CA0C2F621EEDAD200A11860 /* AST */ = { >- isa = PBXGroup; >- children = ( >- 1C840B9021EC30F900D0500D /* WHLSLAddressSpace.h */, >- C21BF72521CD89E200227979 /* WHLSLArrayReferenceType.h */, >- C21BF70921CD89CA00227979 /* WHLSLArrayType.h */, >- C21BF73021CD89ED00227979 /* WHLSLAssignmentExpression.h */, >- C21BF70A21CD89CB00227979 /* WHLSLBaseFunctionAttribute.h */, >- C21BF6FA21CD89BE00227979 /* WHLSLBaseSemantic.h */, >- C21BF71E21CD89DC00227979 /* WHLSLBlock.h */, >- C21BF6F621CD89B700227979 /* WHLSLBooleanLiteral.h */, >- C21BF71A21CD89D800227979 /* WHLSLBreak.h */, >- C2138A1321DDECD300F516BA /* WHLSLBuiltInSemantic.cpp */, >- C21BF72221CD89DF00227979 /* WHLSLBuiltInSemantic.h */, >- C21BF71621CD89D500227979 /* WHLSLCallExpression.h */, >- C21BF70621CD89C700227979 /* WHLSLCommaExpression.h */, >- C21BF73321CD89F000227979 /* WHLSLConstantExpression.h */, >- C21BF6F521CD89B500227979 /* WHLSLContinue.h */, >- C21BF70121CD89C400227979 /* WHLSLDereferenceExpression.h */, >- C21BF71821CD89D700227979 /* WHLSLDotExpression.h */, >- C21BF6FB21CD89BE00227979 /* WHLSLDoWhileLoop.h */, >- C21BF72821CD89E500227979 /* WHLSLEffectfulExpressionStatement.h */, >- 1C840B7D21EBE0B800D0500D /* WHLSLEntryPointType.h */, >- C21BF72021CD89DD00227979 /* WHLSLEnumerationDefinition.h */, >- C21BF72621CD89E300227979 /* WHLSLEnumerationMember.h */, >- C21BF70221CD89C400227979 /* WHLSLEnumerationMemberLiteral.h */, >- C21BF70C21CD89CC00227979 /* WHLSLExpression.h */, >- C21BF70021CD89C200227979 /* WHLSLFallthrough.h */, >- C21BF73521CD89F200227979 /* WHLSLFloatLiteral.h */, >- 1CB69B3821DF03E1006E846A /* WHLSLFloatLiteralType.cpp */, >- 1CB69B3421DED63A006E846A /* WHLSLFloatLiteralType.h */, >- C21BF73421CD89F100227979 /* WHLSLForLoop.h */, >- C21BF70521CD89C700227979 /* WHLSLFunctionAttribute.h */, >- C21BF6FD21CD89C000227979 /* WHLSLFunctionDeclaration.h */, >- C21BF6F421CD89B300227979 /* WHLSLFunctionDefinition.h */, >- C21BF6FF21CD89C200227979 /* WHLSLIfStatement.h */, >- C21BF6F721CD89B900227979 /* WHLSLIndexExpression.h */, >- C20F4F6621DFF2360070C45A /* WHLSLIntegerLiteral.cpp */, >- C21BF6F821CD89BB00227979 /* WHLSLIntegerLiteral.h */, >- 1CB69B3921DF03F3006E846A /* WHLSLIntegerLiteralType.cpp */, >- 1CB69B3521DED649006E846A /* WHLSLIntegerLiteralType.h */, >- C21BF73221CD89EF00227979 /* WHLSLLogicalExpression.h */, >- C21BF71521CD89D400227979 /* WHLSLLogicalNotExpression.h */, >- C21BF72D21CD89E900227979 /* WHLSLMakeArrayReferenceExpression.h */, >- C21BF72C21CD89E900227979 /* WHLSLMakePointerExpression.h */, >- 1C33277121CF0BE1000DC9F2 /* WHLSLNamedType.h */, >- C21BF72321CD89E100227979 /* WHLSLNativeFunctionDeclaration.h */, >- C21BF72A21CD89E700227979 /* WHLSLNativeTypeDeclaration.h */, >- C21BF72421CD89E100227979 /* WHLSLNode.h */, >- C21BF70721CD89C800227979 /* WHLSLNullLiteral.h */, >- 1CB69B3A21DF0403006E846A /* WHLSLNullLiteralType.cpp */, >- 1CB69B3621DED657006E846A /* WHLSLNullLiteralType.h */, >- C21BF72121CD89DE00227979 /* WHLSLNumThreadsFunctionAttribute.h */, >- C21BF72F21CD89EC00227979 /* WHLSLPointerType.h */, >- C21BF72E21CD89EA00227979 /* WHLSLPropertyAccessExpression.h */, >- C21BF70B21CD89CC00227979 /* WHLSLQualifier.h */, >- C21BF71B21CD89D900227979 /* WHLSLReadModifyWriteExpression.h */, >- C21BF70D21CD89CD00227979 /* WHLSLReferenceType.h */, >- 1CB69B3221DED40B006E846A /* WHLSLResolvableType.h */, >- C2138A1521DDECE900F516BA /* WHLSLResourceSemantic.cpp */, >- C21BF70821CD89C900227979 /* WHLSLResourceSemantic.h */, >- C21BF70321CD89C500227979 /* WHLSLReturn.h */, >- C21BF6F921CD89BD00227979 /* WHLSLSemantic.h */, >- C2138A1621DDECFB00F516BA /* WHLSLSpecializationConstantSemantic.cpp */, >- C21BF73621CD89F300227979 /* WHLSLSpecializationConstantSemantic.h */, >- C2138A1721DDED0D00F516BA /* WHLSLStageInOutSemantic.cpp */, >- C21BF70E21CD89CE00227979 /* WHLSLStageInOutSemantic.h */, >- C21BF71221CD89D100227979 /* WHLSLStatement.h */, >- C21BF72721CD89E400227979 /* WHLSLStructureDefinition.h */, >- C21BF6FE21CD89C100227979 /* WHLSLStructureElement.h */, >- C21BF71921CD89D700227979 /* WHLSLSwitchCase.h */, >- C21BF73121CD89EE00227979 /* WHLSLSwitchStatement.h */, >- C21BF71C21CD89DA00227979 /* WHLSLTernaryExpression.h */, >- C21BF6F321CD89AD00227979 /* WHLSLTrap.h */, >- C21BF71D21CD89DB00227979 /* WHLSLType.h */, >- C288C72D21C991DA002DF5CA /* WHLSLTypeArgument.cpp */, >- C21BF71121CD89D100227979 /* WHLSLTypeArgument.h */, >- C21BF72921CD89E600227979 /* WHLSLTypeDefinition.h */, >- C20F4F6421DFBE5C0070C45A /* WHLSLTypeReference.cpp */, >- C21BF71F21CD89DC00227979 /* WHLSLTypeReference.h */, >- 1C33277221CF0D2E000DC9F2 /* WHLSLUnnamedType.h */, >- C20F4F6721DFF3A70070C45A /* WHLSLUnsignedIntegerLiteral.cpp */, >- C21BF72B21CD89E800227979 /* WHLSLUnsignedIntegerLiteral.h */, >- 1CB69B3B21DF041E006E846A /* WHLSLUnsignedIntegerLiteralType.cpp */, >- 1CB69B3721DED66B006E846A /* WHLSLUnsignedIntegerLiteralType.h */, >- C21BF6FC21CD89BF00227979 /* WHLSLValue.h */, >- C21BF71021CD89D000227979 /* WHLSLVariableDeclaration.h */, >- C21BF71421CD89D300227979 /* WHLSLVariableDeclarationsStatement.h */, >- C21BF71321CD89D200227979 /* WHLSLVariableReference.h */, >- C21BF70421CD89C600227979 /* WHLSLWhileLoop.h */, >- ); >- path = AST; >- sourceTree = "<group>"; >- }; > C96F5EBF1B5872260091EA9D /* mediasession */ = { > isa = PBXGroup; > children = ( >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..dbb3a2d78e2f9353083438e2615d27963b7754ff 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUBindGroupLayout.h >@@ -35,6 +35,7 @@ > #include <wtf/RetainPtr.h> > > OBJC_PROTOCOL(MTLArgumentEncoder); >+OBJC_PROTOCOL(MTLBuffer); > > namespace WebCore { > >@@ -42,22 +43,31 @@ class GPUDevice; > > class GPUBindGroupLayout : public RefCounted<GPUBindGroupLayout> { > public: >- struct ArgumentEncoders { >- RetainPtr<MTLArgumentEncoder> vertex; >- RetainPtr<MTLArgumentEncoder> fragment; >- RetainPtr<MTLArgumentEncoder> compute; >- }; >- > static RefPtr<GPUBindGroupLayout> tryCreate(const GPUDevice&, GPUBindGroupLayoutDescriptor&&); > > using BindingsMapType = HashMap<unsigned long long, GPUBindGroupLayoutBinding, WTF::IntHash<unsigned long long>, WTF::UnsignedWithZeroKeyHashTraits<unsigned long long>>; > const BindingsMapType& bindingsMap() const { return m_bindingsMap; } >+#if USE(METAL) >+ struct ArgumentEncoderBuffer { >+ RetainPtr<MTLArgumentEncoder> encoder; >+ RetainPtr<MTLBuffer> buffer; >+ >+ bool operator!() const { return !encoder || !buffer; } >+ }; >+ const ArgumentEncoderBuffer& vertexArguments() const { return m_vertexArguments; } >+ const ArgumentEncoderBuffer& fragmentArguments() const { return m_fragmentArguments; } >+ const ArgumentEncoderBuffer& computeArguments() const { return m_computeArguments; } >+#endif // USE(METAL) > > private: >- GPUBindGroupLayout(BindingsMapType&&, ArgumentEncoders&&); >+#if USE(METAL) >+ GPUBindGroupLayout(BindingsMapType&&, ArgumentEncoderBuffer&&, ArgumentEncoderBuffer&&, ArgumentEncoderBuffer&&); > >+ ArgumentEncoderBuffer m_vertexArguments; >+ ArgumentEncoderBuffer m_fragmentArguments; >+ ArgumentEncoderBuffer m_computeArguments; >+#endif // USE(METAL) > const BindingsMapType m_bindingsMap; >- ArgumentEncoders m_argumentEncoders; > }; > > } // 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.h b/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h >index 948c0c886a93a958581590c9a52b544a4bd726e5..951c438074d7b391041cc96169beaa9474f23950 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUProgrammablePassEncoder.h >@@ -27,12 +27,17 @@ > > #if ENABLE(WEBGPU) > >+#include "GPUBindGroupBinding.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 +47,22 @@ public: > virtual ~GPUProgrammablePassEncoder() = default; > > void endPass(); >- >+ void setBindGroup(unsigned long, const GPUBindGroup&); > virtual void setPipeline(Ref<GPURenderPipeline>&&) = 0; > > protected: > virtual PlatformProgrammablePassEncoder* platformPassEncoder() const = 0; > > private: >+#if USE(METAL) >+ 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) { } >+#endif // USE(METAL) >+ > bool m_isEncoding { true }; > }; > >diff --git a/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h b/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h >index 501aa3d1521472911f2e008fdad26d8122612c12..c8e685a8e56a8756e00a3695f9003bac6177875d 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h >+++ b/Source/WebCore/platform/graphics/gpu/GPURenderPassEncoder.h >@@ -62,6 +62,13 @@ private: > > PlatformProgrammablePassEncoder* platformPassEncoder() const final; > >+#if USE(METAL) >+ // GPUProgrammablePassEncoder >+ void useResource(MTLResource *, unsigned long) final; >+ void setVertexBuffer(MTLBuffer *, unsigned long, unsigned long) final; >+ void setFragmentBuffer(MTLBuffer *, unsigned long, unsigned long) final; >+#endif // USE(METAL) >+ > PlatformRenderPassEncoderSmartPtr m_platformRenderPassEncoder; > RefPtr<GPURenderPipeline> m_pipeline; > }; >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >index f8931ce6629b150c6a9853a1da8ec457b9e75b47..6022c62cc0b6c20c609c22dd64ef52a9ecde5bec 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm >@@ -61,21 +61,38 @@ static void appendArgumentToArray(ArgumentArray& array, RetainPtr<MTLArgumentDes > END_BLOCK_OBJC_EXCEPTIONS; > } > >-static RetainPtr<MTLArgumentEncoder> newEncoder(const GPUDevice& device, ArgumentArray array) >+static GPUBindGroupLayout::ArgumentEncoderBuffer tryCreateArgumentEncoderAndBuffer(const GPUDevice& device, ArgumentArray array) > { >- RetainPtr<MTLArgumentEncoder> encoder; >+ GPUBindGroupLayout::ArgumentEncoderBuffer args; >+ > BEGIN_BLOCK_OBJC_EXCEPTIONS; >- encoder = adoptNS([device.platformDevice() newArgumentEncoderWithArguments:array.get()]); >+ args.encoder = adoptNS([device.platformDevice() newArgumentEncoderWithArguments:array.get()]); > END_BLOCK_OBJC_EXCEPTIONS; >- if (!encoder) >+ if (!args.encoder) { > LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Unable to create MTLArgumentEncoder!"); >+ return { }; >+ } >+ >+ BEGIN_BLOCK_OBJC_EXCEPTIONS; >+ args.buffer = adoptNS([device.platformDevice() newBufferWithLength:args.encoder.get().encodedLength options:0]); >+ [args.encoder setArgumentBuffer:args.buffer.get() offset:0]; >+ END_BLOCK_OBJC_EXCEPTIONS; >+ if (!args.buffer) { >+ LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Unable to create MTLBuffer from MTLArgumentEncoder!"); >+ return { }; >+ } > >- return encoder; >+ return args; > }; > > RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device, GPUBindGroupLayoutDescriptor&& descriptor) > { >- ArgumentArray vertexArguments, fragmentArguments, computeArguments; >+ if (!device.platformDevice()) { >+ LOG(WebGPU, "GPUBindGroupLayout::tryCreate(): Invalid MTLDevice!"); >+ return nullptr; >+ } >+ >+ ArgumentArray vertexArgsArray, fragmentArgsArray, computeArgsArray; > BindingsMapType bindingsMap; > > for (const auto& binding : descriptor.bindings) { >@@ -99,34 +116,36 @@ RefPtr<GPUBindGroupLayout> GPUBindGroupLayout::tryCreate(const GPUDevice& device > mtlArgument.get().index = binding.binding; > > if (binding.visibility & GPUShaderStageBit::VERTEX) >- appendArgumentToArray(vertexArguments, mtlArgument); >+ appendArgumentToArray(vertexArgsArray, mtlArgument); > if (binding.visibility & GPUShaderStageBit::FRAGMENT) >- appendArgumentToArray(fragmentArguments, mtlArgument); >+ appendArgumentToArray(fragmentArgsArray, mtlArgument); > if (binding.visibility & GPUShaderStageBit::COMPUTE) >- appendArgumentToArray(computeArguments, mtlArgument); >+ appendArgumentToArray(computeArgsArray, mtlArgument); > } > >- ArgumentEncoders encoders; >+ ArgumentEncoderBuffer vertex, fragment, compute; > >- if (vertexArguments) { >- if (!(encoders.vertex = newEncoder(device, vertexArguments))) >+ if (vertexArgsArray) { >+ if (!(vertex = tryCreateArgumentEncoderAndBuffer(device, vertexArgsArray))) > return nullptr; > } >- if (fragmentArguments) { >- if (!(encoders.fragment = newEncoder(device, fragmentArguments))) >+ if (fragmentArgsArray) { >+ if (!(fragment = tryCreateArgumentEncoderAndBuffer(device, fragmentArgsArray))) > return nullptr; > } >- if (computeArguments) { >- if (!(encoders.compute = newEncoder(device, computeArguments))) >+ if (computeArgsArray) { >+ if (!(compute = tryCreateArgumentEncoderAndBuffer(device, computeArgsArray))) > return nullptr; > } > >- return adoptRef(new GPUBindGroupLayout(WTFMove(bindingsMap), WTFMove(encoders))); >+ return adoptRef(new GPUBindGroupLayout(WTFMove(bindingsMap), WTFMove(vertex), WTFMove(fragment), WTFMove(compute))); > } > >-GPUBindGroupLayout::GPUBindGroupLayout(BindingsMapType&& bindingsMap, ArgumentEncoders&& encoders) >- : m_bindingsMap(WTFMove(bindingsMap)) >- , m_argumentEncoders(WTFMove(encoders)) >+GPUBindGroupLayout::GPUBindGroupLayout(BindingsMapType&& bindingsMap, ArgumentEncoderBuffer&& vertex, ArgumentEncoderBuffer&& fragment, ArgumentEncoderBuffer&& compute) >+ : m_vertexArguments(WTFMove(vertex)) >+ , m_fragmentArguments(WTFMove(fragment)) >+ , m_computeArguments(WTFMove(compute)) >+ , m_bindingsMap(WTFMove(bindingsMap)) > { > } > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >index 61259d234fb3a124f991784a5d8fd6887037e208..93edc11a80ecb6a06418b52c261463832f1f796b 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm >@@ -69,7 +69,6 @@ RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUDevice& device) > GPUCommandBuffer::GPUCommandBuffer(PlatformCommandBufferSmartPtr&& buffer) > : m_platformCommandBuffer(WTFMove(buffer)) > { >- UNUSED_PARAM(m_platformCommandBuffer); > } > > } // namespace WebCore >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm >index 2e643638146a1b89ca7f8c9686653d2725d3418e..4ffe38750c3314db9d00d52c40a3611098bdb952 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,84 @@ 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 >+ >+ const auto& vertexArgs = bindGroup.layout().vertexArguments(); >+ const auto& fragmentArgs = bindGroup.layout().fragmentArguments(); >+ // FIXME: Finish support for compute. >+ >+ BEGIN_BLOCK_OBJC_EXCEPTIONS; >+ >+ if (vertexArgs.buffer) >+ setVertexBuffer(vertexArgs.buffer.get(), 0, index); >+ if (fragmentArgs.buffer) >+ setFragmentBuffer(fragmentArgs.buffer.get(), 0, index); >+ >+ 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. >+ case GPUBindGroupLayoutBinding::BindingType::UniformBuffer: >+ case GPUBindGroupLayoutBinding::BindingType::StorageBuffer: { >+ if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::VERTEX) >+ setResourceAsBufferOnEncoder(vertexArgs.encoder.get(), binding.resource, binding.binding, functionName); >+ if (bindGroupLayoutBinding.visibility & GPUShaderStageBit::FRAGMENT) >+ setResourceAsBufferOnEncoder(fragmentArgs.encoder.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..594a3370a8449f1d7b9f2d78fa82f7f99267247e 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPassEncoderMetal.mm >@@ -118,6 +118,25 @@ void GPURenderPassEncoder::draw(unsigned long vertexCount, unsigned long instanc > baseInstance:firstInstance]; > } > >+#if USE(METAL) >+ >+void GPURenderPassEncoder::useResource(MTLResource *resource, unsigned long 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]; >+} >+ >+#endif // USE(METAL) >+ > } // namespace WebCore > > #endif // ENABLE(WEBGPU) >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index e856254f6b5005505f8a1dd3c3c961e87901d7c1..a652335d201de746dc0f05066dbcf2c9bf018a24 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,23 @@ >+2019-01-18 Justin Fan <justin_fan@apple.com> >+ >+ (WIP) [WebGPU] WebGPUProgrammablePassEncoder::setBindGroup prototype >+ https://bugs.webkit.org/show_bug.cgi?id=193457 >+ <rdar://problem/47296678> >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Draw 3 triangles via WebGPU to create a green square canvas, with reference. >+ Each vertex is stored in its own WebGPUBuffer and they are mix/matched per bind group. >+ This tests multiple resource bindings in one bind group as well as setting multiple >+ bind groups per draw call and per command encoder. >+ >+ * webgpu/buffer-resource-triangles-expected.html: Added. Reference generated using 2D canvas. >+ * webgpu/buffer-resource-triangles.html: Added. >+ 1) Draw top two triangles using two bind groups in one draw call. >+ 2) Swap first bind group and issue second draw call to draw middle triangle. >+ * webgpu/js/webgpu-functions.js: >+ (createBasicPipeline): Now handles new primitive topologies. >+ > 2019-01-16 Alicia Boya GarcÃa <aboya@igalia.com> > > Unreviewed GTK and WPE test gardening. >diff --git a/LayoutTests/webgpu/buffer-resource-triangles-expected.html b/LayoutTests/webgpu/buffer-resource-triangles-expected.html >new file mode 100644 >index 0000000000000000000000000000000000000000..886f13e8120397a5cc6336c9e2a485e778ba9932 >--- /dev/null >+++ b/LayoutTests/webgpu/buffer-resource-triangles-expected.html >@@ -0,0 +1,12 @@ >+<!DOCTYPE html> >+<meta charset="utf-8"> >+<title>HTML Reference File</title> >+<p>Pass if square canvas below is completely green.</p> >+<canvas width="400" height="400"></canvas> >+<script> >+const canvas = document.querySelector("canvas"); >+const context = canvas.getContext('2d'); >+ >+context.fillStyle = 'rgb(0, 255, 0)'; >+context.fillRect(0, 0, canvas.width, canvas.height); >+</script> >\ No newline at end of file >diff --git a/LayoutTests/webgpu/buffer-resource-triangles.html b/LayoutTests/webgpu/buffer-resource-triangles.html >new file mode 100644 >index 0000000000000000000000000000000000000000..d7115ba6cba2c7850a3be7b9629dd8381c4bc658 >--- /dev/null >+++ b/LayoutTests/webgpu/buffer-resource-triangles.html >@@ -0,0 +1,176 @@ >+<!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="buffer-resource-triangles-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 VertexArguments { >+ device Vertex* v0; >+ device Vertex* v1; >+ device Vertex* v2; >+}; >+ >+vertex Vertex vertex_main( >+ const device VertexArguments& args0 [[buffer(0)]], >+ const device VertexArguments& args1 [[buffer(1)]], >+ uint vid [[vertex_id]]) >+{ >+ switch (vid) >+ { >+ case 0: return args0.v0[0]; >+ case 1: return args0.v1[0]; >+ case 2: return args0.v2[0]; >+ case 3: return args1.v0[0]; >+ case 4: return args1.v1[0]; >+ default: return args1.v2[0]; >+ } >+} >+ >+struct FragmentArguments { >+ device float4* color; >+}; >+ >+fragment float4 fragment_main(const device FragmentArguments& args [[buffer(0)]]) >+{ >+ return args.color[0]; >+} >+` >+ >+const bindingNums = { >+ UL: 0, >+ UM: 1, >+ UR: 2, >+ LL: 3, >+ LR: 4, >+ G: 5 >+}; >+ >+function createUniformBufferBindGroupLayout(bindNum, stage = WebGPUShaderStageBit.VERTEX) { >+ return { >+ binding: bindNum, >+ visibility: stage, >+ type: "uniformBuffer" >+ }; >+} >+ >+const bufferSize = 4 * 4; >+ >+// FIXME: Keep up to date with buffer upload decisions. >+function createFloat4Buffer(device, a, b) { >+ const buffer = device.createBuffer({ size: bufferSize, usage: WebGPUBufferUsage.UNIFORM }); >+ >+ const arrayBuffer = buffer.mapping; >+ const floatArray = new Float32Array(arrayBuffer); >+ >+ floatArray[0] = a; >+ floatArray[1] = b; >+ floatArray[2] = 0; >+ floatArray[3] = 1; >+ >+ return buffer; >+} >+ >+function createBufferBinding(buffer) { >+ return { >+ buffer: buffer, >+ offset: 0, >+ size: bufferSize >+ }; >+} >+ >+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 }); >+ >+ // Create vertex data WebGPUBuffers. >+ const upperLeft = createFloat4Buffer(device, -1, 1); >+ const upperMiddle = createFloat4Buffer(device, 0, 1); >+ const upperRight = createFloat4Buffer(device, 1, 1); >+ const lowerLeft = createFloat4Buffer(device, -1, -1); >+ const lowerRight = createFloat4Buffer(device, 1, -1); >+ >+ // Color data buffer. >+ const green = createFloat4Buffer(device, 0, 1); >+ >+ // Create buffer WebGPUBindGroupLayoutBindings. >+ const layoutUL = createUniformBufferBindGroupLayout(bindingNums.UL); >+ const layoutUM = createUniformBufferBindGroupLayout(bindingNums.UM); >+ const layoutUR = createUniformBufferBindGroupLayout(bindingNums.UR); >+ const layoutLL = createUniformBufferBindGroupLayout(bindingNums.LL); >+ const layoutLR = createUniformBufferBindGroupLayout(bindingNums.LR); >+ const layoutG = createUniformBufferBindGroupLayout(bindingNums.G, WebGPUShaderStageBit.FRAGMENT); >+ >+ // WebGPUBindGroupLayouts >+ const leftTriangleBGLayout = device.createBindGroupLayout({ bindings: [layoutUL, layoutUM, layoutLL, layoutG] }); >+ const rightTriangleBGLayout = device.createBindGroupLayout({ bindings: [layoutUR, layoutUM, layoutLR] }); >+ const middleTriangleBGLayout = device.createBindGroupLayout({ bindings: [layoutUM, layoutLL, layoutLR, layoutG] }); >+ >+ // WebGPUPipelineLayout and WebGPURenderPipeline >+ const pipelineLayout = device.createPipelineLayout({ bindGroupLayouts: [leftTriangleBGLayout, middleTriangleBGLayout, rightTriangleBGLayout] }); >+ const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, null, "triangleList"); >+ >+ // WebGPUBufferBindings >+ const bindingUL = createBufferBinding(upperLeft); >+ const bindingUM = createBufferBinding(upperMiddle); >+ const bindingUR = createBufferBinding(upperRight); >+ const bindingLL = createBufferBinding(lowerLeft); >+ const bindingLR = createBufferBinding(lowerRight); >+ const bindingG = createBufferBinding(green); >+ >+ // WebGPUBindGroupBindings >+ const bgBindingUL = { binding: bindingNums.UL, resource: bindingUL }; >+ const bgBindingUM = { binding: bindingNums.UM, resource: bindingUM }; >+ const bgBindingUR = { binding: bindingNums.UR, resource: bindingUR }; >+ const bgBindingLL = { binding: bindingNums.LL, resource: bindingLL }; >+ const bgBindingLR = { binding: bindingNums.LR, resource: bindingLR }; >+ const bgBindingG = { binding: bindingNums.G, resource: bindingG }; >+ >+ // WebGPUBindGroups >+ const leftTriangleBG = device.createBindGroup({ >+ layout: leftTriangleBGLayout, >+ bindings: [bgBindingUL, bgBindingUM, bgBindingLL, bgBindingG] >+ }); >+ const rightTriangleBG = device.createBindGroup({ >+ layout: rightTriangleBGLayout, >+ bindings: [bgBindingUR, bgBindingUM, bgBindingLR] >+ }); >+ const middleTriangleBG = device.createBindGroup({ >+ layout: middleTriangleBGLayout, >+ bindings: [bgBindingUM, bgBindingLL, bgBindingLR, bgBindingG] >+ }); >+ >+ const commandBuffer = device.createCommandBuffer(); >+ const passEncoder = beginBasicRenderPass(context, commandBuffer); >+ passEncoder.setPipeline(pipeline); >+ >+ // Draw upper triangles. >+ passEncoder.setBindGroup(0, leftTriangleBG); >+ passEncoder.setBindGroup(1, rightTriangleBG); >+ passEncoder.draw(6, 1, 0, 0); >+ // Draw lower triangle. >+ passEncoder.setBindGroup(0, middleTriangleBG); >+ passEncoder.draw(3, 1, 0, 0); >+ >+ const endCommandBuffer = passEncoder.endPass(); >+ const queue = device.getQueue(); >+ queue.submit([endCommandBuffer]); >+ context.present(); >+} >+ >+test(); >+</script> >\ No newline at end of file >diff --git a/LayoutTests/webgpu/js/webgpu-functions.js b/LayoutTests/webgpu/js/webgpu-functions.js >index c75302be8929dfdef0c2029e536a0cd8da6de0b9..767f946521a4ad22213f92f0d4fcb5720c826317 100644 >--- a/LayoutTests/webgpu/js/webgpu-functions.js >+++ b/LayoutTests/webgpu/js/webgpu-functions.js >@@ -12,7 +12,7 @@ function createBasicContext(canvas, device) { > return context; > } > >-function createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor) { >+function createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor, primitiveTopology = "triangleStrip") { > const vertexStageDescriptor = { > module: shaderModule, > entryPoint: "vertex_main" >@@ -26,13 +26,15 @@ function createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDes > const pipelineDescriptor = { > vertexStage: vertexStageDescriptor, > fragmentStage: fragmentStageDescriptor, >- primitiveTopology: "triangleStrip", >- inputState: inputStateDescriptor >+ primitiveTopology: primitiveTopology > }; > > if (pipelineLayout) > pipelineDescriptor.layout = pipelineLayout; > >+ if (inputStateDescriptor) >+ pipelineDescriptor.inputState = inputStateDescriptor; >+ > return device.createRenderPipeline(pipelineDescriptor); > } >
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