[WHLSL] Resources don't work when only a subset of a bind group is referenced by...
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Sep 2019 23:08:38 +0000 (23:08 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 1 Sep 2019 23:08:38 +0000 (23:08 +0000)
commitf9c522779d9ad97964309732d72c8201d7045741
tree4f1cdb676ecaeee6ba458db0e38d5500f60d1ad3
parent6ad87d2af9c0bd16c976a444bd78ad43b28b4643
[WHLSL] Resources don't work when only a subset of a bind group is referenced by a shader
https://bugs.webkit.org/show_bug.cgi?id=201383

Reviewed by Dean Jackson.

Source/WebCore:

Bind groups correspond to argument buffers in Metal. Both the Metal API and Metal Shading Language
have to agree on the layout of exactly which resources lie at which byte offsets within an argument
buffer.

Before this patch, we only emitted code for the items in the argument buffer that were actually
referenced by the shader source code. However, because these items are held inside a struct, if
we omit one item from the middle of the struct, the byte offets of all the successive items would
be wrong. This means that the Metal API and the shader would disagree about how to access these
resources, making the resources inaccessible (and causing security problems).

Tests: webgpu/whlsl/sparse-bind-group-2.html
       webgpu/whlsl/sparse-bind-group-3.html
       webgpu/whlsl/sparse-bind-group.html

* Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp:
(WebCore::WHLSL::Metal::EntryPointScaffolding::emitResourceHelperTypes):
(WebCore::WHLSL::Metal::VertexEntryPointScaffolding::emitHelperTypes):
(WebCore::WHLSL::Metal::FragmentEntryPointScaffolding::emitHelperTypes):
(WebCore::WHLSL::Metal::ComputeEntryPointScaffolding::emitHelperTypes):
* Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.h:
* Modules/webgpu/WHLSL/WHLSLSemanticMatcher.cpp:
(WebCore::WHLSL::matchResources):
(WebCore::WHLSL::matchVertexAttributes):
(WebCore::WHLSL::matchColorAttachments):

LayoutTests:

* webgpu/whlsl/compute.html:
* webgpu/whlsl/sparse-bind-group-2-expected.txt: Added.
* webgpu/whlsl/sparse-bind-group-2.html: Added.
* webgpu/whlsl/sparse-bind-group-3-expected.txt: Added.
* webgpu/whlsl/sparse-bind-group-3.html: Added.
* webgpu/whlsl/sparse-bind-group-expected.txt: Added.
* webgpu/whlsl/sparse-bind-group.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249369 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/whlsl/compute.html
LayoutTests/webgpu/whlsl/sparse-bind-group-2-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl/sparse-bind-group-2.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl/sparse-bind-group-3-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl/sparse-bind-group-3.html [new file with mode: 0644]
LayoutTests/webgpu/whlsl/sparse-bind-group-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl/sparse-bind-group.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.cpp
Source/WebCore/Modules/webgpu/WHLSL/Metal/WHLSLEntryPointScaffolding.h
Source/WebCore/Modules/webgpu/WHLSL/WHLSLSemanticMatcher.cpp
Source/WebCore/platform/graphics/gpu/cocoa/GPUBindGroupLayoutMetal.mm