From 24c8440eb65ba88abd17a63dd55895f0a60fbfb8 Mon Sep 17 00:00:00 2001 From: David Neto Date: Fri, 9 Dec 2022 19:53:27 +0000 Subject: [PATCH] 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 Auto-Submit: David Neto Reviewed-by: David Neto Kokoro: Kokoro Commit-Queue: David Neto --- docs/tint/spirv-reader-overview.md | 41 +++++------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/docs/tint/spirv-reader-overview.md b/docs/tint/spirv-reader-overview.md index 8cc7de27a4..7411e163da 100644 --- a/docs/tint/spirv-reader-overview.md +++ b/docs/tint/spirv-reader-overview.md @@ -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, sparam : ptr) -> vec4 { - let x_24 : vec4 = textureSampleLevel(imparam, sparam, vec2(0.0f, 0.0f), 0.0f); - return x_24; - } - - fn main_1() { - var v : vec4; - let x_31 : vec4 = 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; - - @group(0) @binding(1) var s : sampler; - fn helper_t21_p1_(imparam : texture_2d, sparam : sampler) -> vec4 { let x_24 : vec4 = textureSampleLevel(imparam, sparam, vec2(0.0f, 0.0f), 0.0f); return x_24;