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 findLSB() as an argument to clamp built-ins fails on macOS 10.14 #1073

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 that when using the findLSB() as the argument of the clamp function, the MSL compiler gives the following error:

result.msl:17:9: error: no matching function for call to 'clamp'
    if (clamp(47910, findLSB(40365u), 1) > 0)
        ^~~~~

The GLSL fragment shader:

void main()
{
 if(clamp(47910, findLSB(40365u), 1) > 0)
  {
   discard;
  }
}

MSL obtained by SPIRV-Cross:

fragment void main0()
{
    if (clamp(47910, findLSB(40365u), 1) > 0)
    {
        discard_fragment();
    }
}

Versions:

Steps to reproduce:

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

Issue found using GraphicsFuzz.

HansKristian-Work commented 5 years ago

Seems like sign mismatch where findMSB expects to return an int, but it's not, and overload resolution fails.