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 unpackUnorm4x8 as an argument to outerProduct built-ins fails on macOS 10.14 #1049

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 the unpackUnorm4x8 as the argument of the outerProduct function, the MSL compiler gives the following error:

result.msl:14:16: error: use of undeclared identifier 'outerProduct'
    float4 a = outerProduct(unpack_unorm4x8_to_float(80045u), float2(1.0))[1];
               ^

The GLSL fragment shader:

void main()
{
 vec4 a = outerProduct(unpackUnorm4x8(80045u), vec2(1.0))[1]; 
 _GLF_color = vec4(1.0);
}

MSL obtained by SPIRV-Cross:

fragment main0_out main0()
{
    main0_out out = {};
    float4 a = outerProduct(unpack_unorm4x8_to_float(80045u), float2(1.0))[1];
    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.

cdavis5e commented 5 years ago

The problem is that OpOuterProduct itself is not supported by the MSL backend. It winds up delegating back to the GLSL backend, which emits a call to outerProduct(), which doesn't exist in MSL. I don't think there's anything in the Metal standard library that corresponds directly to this, which is part of why it's unimplemented. The other part is, I suspect that this operation is fairly rare, so it hasn't come up before.

HansKristian-Work commented 5 years ago

Right, I don't think it's implemented at all in MSL yet, I thought it was, but I guess we didn't have any test coverage for it. Should be easy to add though. I'll get to it on Monday.