microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] Putting NonWritable/NonReadable on the Struct instead of Variable
Open
@pow2clk is already working on this.
Since Jul 14, 2026.
bug
needs-triage
spirv
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
When generating SPIR-V you will get something such as
OpMemberDecorate %block 0 Offset 0
OpMemberDecorate %block 0 NonWritable
OpDecorate %block Block
OpDecorate %var DescriptorSet 0
OpDecorate %var Binding 0
%runtime = OpTypeRuntimeArray %buffer_type
%block = OpTypeStruct %runtime
%ptr_sb = OpTypePointer StorageBuffer %block
%var = OpVariable %ptr_sb StorageBuffer
but ideally you should have the NonWritable on the OpVariable and not the OpTypeStruct
Discussed in the Vulkan Working Group and decided that the current generated SPIR-V from DXC is incorrect (working on spec-ing and getting spirv-val to help catch this)
Steps to Reproduce
The original shader can be found at https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/12100#issuecomment-4264326920
Actual Behavior
The SPIR-V should look similar to
OpDecorate %block Block
OpDecorate %var NonWritable
OpDecorate %var Binding 0
OpDecorate %var DescriptorSet 0
%runtime = OpTypeRuntimeArray %buffer_type
%block = OpTypeStruct %runtime
%ptr_sb = OpTypePointer StorageBuffer %buffer_type
%_var = OpVariable %ptr_sb StorageBuffer
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.
Assessment
This issue has not been assessed yet.