KhronosGroup / SPIRV-Cross

SPIRV-Cross is a practical tool and library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.
Apache License 2.0
2.02k stars 558 forks source link

MSL: using the variable identifier as an argument to length built-ins fails on macOS 10.14 #1047

Closed jiradeto closed 5 years ago

jiradeto commented 5 years ago

On MacOS 10.14, I tried to convert SPIR-V to MSL and found an issue that when using a float variable identifier as the argument of a length function, the MSL compiler gives the following error:

result.msl:9:15: error: no matching function for call to 'length'
    float b = length(a);
              ^~~~~~

From Section 6.7 of Metal Shading Language spec, it seems that length is only defined on vector types, so perhaps length(f) in SPIR-V that came from GLSL should be translated to simply f in MSL

The GLSL fragment shader:

void main()
{
float a = 1.0;
float b = length(a);
_GLF_color = vec4(1.0);
}

The MSL shader obtained by SPIRV-Cross:

fragment main0_out main0()
{
   main0_out out = {};
   float a = 1.0;
   float b = length(a); // using the variable identifier as the argument
   out._GLF_color = float4(1.0);
   return out;
}

Versions:

Steps to reproduce:

Note that before running SPIRV-Cross, I also used spirv-val to check that the SPIR-V produced by glslangValidator is valid.

This Archive.zip contains the original fragment shader, the associated SPIR-V, and MSL shader.

Issue found using GraphicsFuzz.

jiradeto commented 5 years ago

Thank you for your fast fix!