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.07k stars 564 forks source link

MSL: no matching function for 'ldexp' when using with uvec4 #1115

Closed jiradeto closed 5 years ago

jiradeto commented 5 years ago

On MacOS 10.14, when using uvec4 type as the argument of the ldexp function, the MSL compiler gives the following error:

result.msl:14:22: error: no matching function for call to 'ldexp'
    out._GLF_color = ldexp(float4(1.0), popcount(uint4(1u)));
                     ^~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/metal/macos/lib/clang/902.1/include/metal/metal_math:2185:26: note: candidate function not
      viable: no known conversion from 'unsigned int __attribute__((ext_vector_type(4)))' (vector of 4 'unsigned int' values) to 'vec<int, 4>' (vector of 4 'int' values) for 2nd
      argument
  METAL_ASM vec<float,4> ldexp(vec<float,4> x, vec<int,4> k) __asm("air." _AIR_PREFIX_float "ldexp.v4f32");
                         ^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/metal/macos/lib/clang/902.1/include/metal/metal_math:1340:18: note: candidate function not
      viable: no known conversion from 'float4' (vector of 4 'float' values) to 'half' for 1st argument
  METAL_ASM half ldexp(half x, int k) __asm("air." _AIR_PREFIX_half "ldexp.f16");

The GLSL fragment shader:

layout(location = 0) out vec4 _GLF_color;

void main()
{
 _GLF_color = ldexp(vec4(1.0), bitCount(uvec4(1u)));
}

MSL obtained by SPIRV-Cross:

fragment main0_out main0()
{
    main0_out out = {};
    out._GLF_color = ldexp(float4(1.0), popcount(uint4(1u)));
    return out;
}

Versions:

Steps to reproduce:

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

Issue found using GraphicsFuzz.

HansKristian-Work commented 5 years ago

This bug kinda "fixed itself" with the popcount fix, but ldexp only takes int, so need to fix that explicitly ...