gfx-rs / wgpu

A cross-platform, safe, pure-Rust graphics API.
https://wgpu.rs
Apache License 2.0
12.32k stars 904 forks source link

[naga/spv-in] spv-in can not consume SPIR-V where arrays of textures are passed as function arguments #4857

Open chyyran opened 10 months ago

chyyran commented 10 months ago

Description SPIR-V with an OpFunctionCall with an image array fails to compile.

Repro steps Shader Playground link: https://shader-playground.timjones.io/d87861b3fcc78063347366c88651b276

  1. Compile this GLSL to SPIR-V with glslang
    
    #version 450

layout(location = 0) out vec4 color; layout(set = 0, binding = 1) uniform texture2D[2] tex; layout(set = 0, binding = 2) uniform sampler _sampler;

void access(texture2D[2] tex1, sampler arg_sampler) { color = texture(sampler2D(tex1[0], arg_sampler), vec2(0.0)); }

void main() { access(tex, _sampler); }



2. Use Naga to parse SPIR-V and it fails with `InvalidGlobalVar(FunctionArgument(0))`.
chyyran commented 10 months ago

https://shader-playground.timjones.io/2d02a87f59ed403ffef77b83d45a9b51

Putting the OpAccessLoad within the outer function also does not work

#version 450

layout(location = 0) out vec4 color;
layout(set = 0, binding = 1) uniform texture2D[2] tex;
layout(set = 0, binding = 2) uniform sampler _sampler;

void access(texture2D tex1, sampler arg_sampler) {
    color = texture(sampler2D(tex1, arg_sampler), vec2(0.0));
}

void main() {
    access(tex[0], _sampler);
}