gfx-rs/naga

[glsl-out] Array types used as function arguments get dropped

Closed this issue · 1 comments

This shader:

#version 460 core

void f(out vec4 foo[2]) {
    foo[1] = vec4(1.0);
}

void main() {}

When passed through naga (cargo run -- shader.comp output-shader.comp), produces this output:

#version 310 es

precision highp float;
precision highp int;

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;


void f(inout vec4 foo) {
    foo[1] = vec4(1.0);
    return;
}

void main_1() {
    return;
}

void main() {
    main_1();
    return;
}

Which doesn't compile because the argument type of f has changed from an array of vec4 to a single vec4:

$ glslangValidator output-shader.comp 
output-shader.comp
ERROR: 0:10: 'assign' :  cannot convert from ' const 4-component vector of float' to ' temp highp float'
ERROR: 0:10: '' : compilation terminated 
ERROR: 2 compilation errors.  No code generated.

I found the reason — inout and out parameters get translated to pointers in glsl-in, and back::glsl::Writer::write_array_size is only called when the type of the parameter is an array, even though pointers can point to arrays and that should be reflected in the function signature.

I'll open a PR to fix this — sounds trivial enough