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:
SPIRV-Cross: git-d1bdb6d49144d23c75963e89cd6369d9d0406f7d (Most recent version of this writing)
glslangValidator: Glslang Version: 7.12.3226
Steps to reproduce:
Convert the GLSL shader to SPIR-V using glslangValidator with the command glslangValidator -V sample.frag -o sample.spv
Convert the SPIR-V to MSL using SPIRV-Cross with the command spirv-cross --msl sample.spv --output result.msl
Build a Metal library with the command xcrun --sdk macosx10.14 metal -x metal -std=macos-metal1.2 result.msl
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.
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:
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:
The MSL shader obtained by SPIRV-Cross:
Versions:
Steps to reproduce:
glslangValidator -V sample.frag -o sample.spv
spirv-cross --msl sample.spv --output result.msl
xcrun --sdk macosx10.14 metal -x metal -std=macos-metal1.2 result.msl
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.