KhronosGroup / glslang

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

HLSL: reject-valid: can't return empty struct #2758

Open Ace17 opened 2 years ago

Ace17 commented 2 years ago

The following program is accepted by fxc.exe:

( http://shader-playground.timjones.io/8188336997c14f2d8f2c5ffd8a4ea729 )

struct TEmptyStruct {};

TEmptyStruct PSMain()
{
    TEmptyStruct o = (TEmptyStruct)0;
    return o;
}

Howerver, it is rejected by glslang :

$ glslangValidator -V100 --spirv-val -S frag -D --target-env vulkan1.0 /tmp/input.frag.hlsl -e PSMain
/tmp/input.frag.hlsl
error: SPIRV-Tools Validation Errors
error: Interface variable id <17> is used by entry point 'PSMain' id <4>, but is not listed as an interface
  %_entryPointOutput = OpVariable %_ptr_Output_TEmptyStruct Output
greg-lunarg commented 2 years ago

Currently glslang creates an output variable of type struct of 0 bytes and a constant 0 of the same type and generates an assignment of the constant to the variable. The error is for failing to put the variable in the interface.

fxc creates a function that just does a ret with no input or output recorded for the interface. That is essentially what I think that glslang should do as well.