KhronosGroup / glslang

Khronos-reference front end for GLSL/ESSL, partial front end for HLSL, and a SPIR-V generator.
Other
2.91k stars 816 forks source link

HLSL: function matching for two structs with same members works in fxc but not glslang #1639

Open danginsburg opened 5 years ago

danginsburg commented 5 years ago

The following shader compiles with fxc 9.29.952.3111 (fxc.exe /EMainPs /Tps_5_0 test.frag), but does not compile in glslangValidator.

struct PS_INPUT_TEST1
{
    float3 vPositionWs              : TEXCOORD0;
    float3 vFootPos                 : TEXCOORD1;
};

struct PS_INPUT_TEST2
{
    float3 vPositionWs              : TEXCOORD0;
    float3 vFootPos                 : TEXCOORD1;
};
float4 TestFunc( PS_INPUT_TEST2 i, int2 vOffset, int nValue )
{
    return float4( i.vPositionWs , 1.0 );
}
float4 MainPs( PS_INPUT_TEST1 i ) : SV_Target0
{
    return TestFunc( i, int2( 0, 0), 0 ) ;
}

With glslangValidator.exe -D -V -e MainPs test.frag I get the following errors:

ERROR: test.frag:18: 'TestFunc' : no matching overloaded function found test.frag(18): error at column 39, HLSL parsing failed. ERROR: 2 compilation errors. No code generated.

Apparently fxc is allowing casting between two structs with the same member variables.

johnkslang commented 5 years ago

Seems doable. Some things to be careful about.

One question is how much the structss must be the same, but glslang could accept things just based on matching lists of member types. I supposed this should work recursively though, with member types that are themselves structures.

The other is what assumptions consumers might have about such matches in the AST and whether an explicit cast should appear, just like when calling a float with an int, etc.