microsoft / DirectXShaderCompiler

This repo hosts the source for the DirectX Shader Compiler which is based on LLVM/Clang.
Other
3.11k stars 697 forks source link

DXIL Validation: Stop setting `EnableRawAndStructuredBuffers` in DXC and Validator #7003

Open tex3d opened 2 weeks ago

tex3d commented 2 weeks ago

Description DxilModule::CollectShaderFlagsForModule sets shader flag EnableRawAndStructuredBuffers when an SRV of RawBuffer or StructuredBuffer is present in the resources list.

https://github.com/microsoft/DirectXShaderCompiler/blob/ac36a797d3470e8ee906b98457a59270d01db30d/lib/DXIL/DxilModule.cpp#L357

This flag was originally added to mirror the DXBC global flag enableRawAndStructuredBuffers, or D3D11_SB_GLOBAL_FLAG_ENABLE_RAW_AND_STRUCTURED_BUFFERS as the value, when doing conversion from DXBC to DXIL in DxilConv. Originally this made sense when we were keeping the shader model and all the flags from the converted shader, but later we upgraded all shaders to shader model 6.0.

This global flag was only set by FXC when the shader was ps_4_0 or ps_4_1 because this was an added feature at that time. It was never used for shader model 5.0 or above, or for compute stage (which was also supported in shader model 4.0+).

There is no reason to set this flag for DXIL, since there's no optional feature exposure here. There should be no regression risk in drivers because converted DXBC wouldn't have set this flag in many scenarios, including ones with indistinguishable DXIL from ones that do set the flag other than this flag setting. In other words, the same shader would produce same DXIL except the flag set or clear depending on whether the DXBC was ps_4_0 or ps_5_0.

Right now, since this flag is set in DxilModule::CollectShaderFlagsForModule, it is also checked by DXIL validation, impacting what we must output from the new clang compiler. We should stop setting this flag, so we don't have to keep carrying this unneeded flag into the future in the new compiler.

Steps to Reproduce https://godbolt.org/z/7xesd8388

Note metadata:

!dx.entryPoints = !{!27}
...
!27 = !{void ()* @main, !"main", !28, !20, !33}
...
!33 = !{i32 0, i64 16}

i64 16 is the EnableRawAndStructuredBuffers flag we should stop setting.

Environment