microsoft / microsoft/DirectXShaderCompiler
DXIL Validation: Stop setting `EnableRawAndStructuredBuffers` in DXC and Validator
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
DxilModule::CollectShaderFlagsForModule sets shader flag EnableRawAndStructuredBuffers when an SRV of RawBuffer or StructuredBuffer is present in the resources list.
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
- DXC version: any
- Host Operating System: any
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lib/DXIL/DxilModule.cpp at DxilModule::CollectShaderFlagsForModule and compare its handling of RawBuffer and StructuredBuffer resources with the DXIL validation behavior described in the issue. Use the linked Godbolt reproduction to inspect the entry-point metadata; done means the unnecessary i64 16 EnableRawAndStructuredBuffers flag is no longer emitted for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100