Update spirv-reader docs: supports texture and sampler func args

Change-Id: I893f050e3377c2aebe933a55d6e75c505c3e23d2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113560
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: David Neto <dneto@google.com>
This commit is contained in:
David Neto 2022-12-09 19:53:27 +00:00 committed by Dawn LUCI CQ
parent ca01ec4689
commit 24c8440eb6
1 changed files with 6 additions and 35 deletions

View File

@ -158,9 +158,6 @@ texture builtin.
### Passing textures and samplers into helper functions
Note: Bug https://crbug.com/tint/1039 is open to support passing
textures and samplers as function arguments.
Glslang generates SPIR-V where texture and sampler formal parameters
are as pointer-to-UniformConstant.
@ -168,9 +165,12 @@ WGSL models them as passing texture and sampler values themselves,
conceptually as opaque handles. This is similar to GLSL, but unlike
SPIR-V.
The tracing logic described in the previous section does not know
what to do when it bottoms out on a formal parameter,
e.g. OpFunctionParameter.
To support textures and samplers as arguments to user-defined functions,
we extend the tracing logic so it knows to bottom out at OpFunctionParameter.
Also, code that generates function declarations now understands formal
parameters declared as a pointer to uniform-constant as
well as direct image and sampler values.
Example GLSL compute shader:
@ -253,35 +253,6 @@ What the SPIR-V Reader currently generates:
@group(0) @binding(1) var s : sampler;
fn helper_t21_p1_(imparam : ptr<none, void>, sparam : ptr<none, void>) -> vec4<f32> {
let x_24 : vec4<f32> = textureSampleLevel(imparam, sparam, vec2<f32>(0.0f, 0.0f), 0.0f);
return x_24;
}
fn main_1() {
var v : vec4<f32>;
let x_31 : vec4<f32> = helper_t21_p1_(&(im), &(s));
v = x_31;
return;
}
@compute @workgroup_size(1i, 1i, 1i)
fn main() {
main_1();
}
with an error:
error: function parameter of pointer type cannot be in 'none' address space
Instead, the generated WGSL should have formal parameters with texture
and sampler types, rather than as pointers to them. So the generated WGSL
should look like this instead:
@group(0) @binding(0) var im : texture_2d<f32>;
@group(0) @binding(1) var s : sampler;
fn helper_t21_p1_(imparam : texture_2d<f32>, sparam : sampler) -> vec4<f32> {
let x_24 : vec4<f32> = textureSampleLevel(imparam, sparam, vec2<f32>(0.0f, 0.0f), 0.0f);
return x_24;