KhronosGroup / glslang

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

Support the earlydepthstencil attribute in HLSL #1679

Closed onitake closed 5 years ago

onitake commented 5 years ago

As of glslangValidator 7.10.2984, the HLSL earlydepthstencil attribute (see https://docs.microsoft.com/en-us/windows/desktop/direct3dhlsl/sm5-attributes-earlydepthstencil ) is unsupported when compiling to Vulkan SPIR-V and reported as an unknown attribute.

This attribute is crucial for performance when UAV/SSBO writes happen and depth testing should occur before shader execution.

Early depth testing is also supported in Vulkan and OpenGL, and, consequentially, in SPIR-V. In GLSL syntax, the attribute must be specified on the layout (see https://www.khronos.org/opengl/wiki/Early_Fragment_Test ), but aside from that, they are equivalent. SPIR-V has the EarlyFragmentTests OpExecutionMode.

Please implement support for this attribute.

onitake commented 5 years ago

Here is a more or less minimal example illustrating the context where earlydepthstencil would make sense:

RWTexture2D<uint> Values;

struct InputStruct {
    float4 Position : SV_POSITION;
};

[earlydepthstencil]
uint main(InputStruct input) : SV_Target {
    uint oldVal;
    InterlockedExchange(Values[uint2(input.Position.x, input.Position.y)], 1.0, oldVal);
    return oldVal;
}

With glslangValidator 7.10.2984, this produces the output:

WARNING: test.frag.hlsl:8: '' : attribute does not apply to entry point 
onitake commented 5 years ago

Thanks! :+1: