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 refract built-ins fails on macOS 10.14 #1056

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 refract function, the MSL compiler gives the following error:

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

The GLSL fragment shader:

void main()
{
    float a = 1.0;
    float b = refract(1.0, 1.0, a);
    _GLF_color = vec4(10.0);
}

The MSL shader obtained by SPIRV-Cross:

fragment main0_out main0()
{
    main0_out out = {};
    float a = 1.0;
    float b = refract(1.0, 1.0, a);
    out._GLF_color = float4(10.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.

cdavis5e commented 5 years ago

That is because MSL lacks overloads of refract() for scalars. Most of the functions in <metal_geometric>, like the length() function (as you discovered in #1047), lack scalar overloads.

HansKristian-Work commented 5 years ago

Odd that this is even allowed in SPIR-V, another easy fix I guess ...