[SPIR-V] -fvk-use-dx-layout doesn't apply DirectX cbuffer layout to [[vk::push_constant]] blocks
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 48/100
Research direction
Start in tools/clang/lib/SPIRV/DeclResultIdMapper.cpp and SpirvEmitter.cpp, where the issue says push constants use sBufferLayoutRule while cbuffers use cBufferLayoutRule; compare how -fvk-use-dx-layout sets those rules. Reproduce with the HLSL example and compare SPIR-V offsets and array strides against DXIL reflection. Done means push-constant arrays and matrices follow the intended DirectX cbuffer layout without regressing existing cases.
Written by the indexing model from the issue text.
Description
Description
With -fvk-use-dx-layout, a [[vk::push_constant]] block is packed with structured-buffer rules (tightly packed, scalar-like), not cbuffer rules. In DXIL the same struct is an ordinary constant buffer with DirectX's 16-byte rows. Scalars and vectors happen to agree, but arrays and matrices sit at different offsets with different element spacing, so one application-side struct can't feed both backends.
The cause appears to be that push constants take spirvOptions.sBufferLayoutRule, which -fvk-use-dx-layout sets to FxcSBuffer, whereas cbuffers get cBufferLayoutRule (FxcCTBuffer) (tools/clang/lib/SPIRV/DeclResultIdMapper.cpp, SpirvEmitter.cpp). The docs describe the DX layout rules as applying to "uniform buffers and storage buffers" and never mention push constants, so this may be an omission rather than intent. The flag's stated purpose is to allow packing data on the application side that can be shared with DirectX, and a push constant block (root constants on D3D12) is exactly that kind of struct.
Steps to Reproduce
dxc -T cs_6_2 -E main -spirv -fvk-use-dx-layout repro.hlsl, compared with dxc -T cs_6_2 -E main repro.hlsl:
[[vk::push_constant]] struct PC { float a; float arr[3]; float tail; } pc;
RWByteAddressBuffer o;
[numthreads(1, 1, 1)]
void main(uint id : SV_DispatchThreadID) { o.Store<float>(0, pc.a + pc.arr[2] + pc.tail); }
A standalone repro comparing DXIL reflection against SPIRV-Reflect is attached (repro_push_constant_dx_layout.cpp).
Actual Behavior
SPIR-V:
OpDecorate %_arr_float_uint_3 ArrayStride 4
OpMemberDecorate %type_PushConstant_PC 0 Offset 0
OpMemberDecorate %type_PushConstant_PC 1 Offset 4
OpMemberDecorate %type_PushConstant_PC 2 Offset 16
DXIL:
; float a; ; Offset: 0
; float arr[3]; ; Offset: 16
; float tail; ; Offset: 52
All cases:
struct PC { float a; float3 b; float c; } a 0/0, b 4/4, c 16/16
struct PC { float a; float arr[3]; float tail; } arr 16/4, tail 52/16 <-- differs
struct PC { float a; float2x2 m; float4x4 big; } m 16/4, big 48/20 <-- differs
(DXIL/SPIR-V)
Environment
- DXC version: <latest release, from
dxc --version>; also reproduces on main, libdxcompiler.so: 1.11(5563-75fba619)(1.10.0.15563) - Host Operating System: Windows (release); Linux x86_64 (main)
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 926
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 45
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
More from microsoft/DirectXShaderCompiler
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9173 ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
microsoft/DirectXShaderCompiler#9155 · 4 comments ·
Maintainers usually reply within 2 days
-
bug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/DirectXShaderCompiler#9135 ·
Maintainers usually reply within 2 days
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSLPossibly taken @rj123-nv claimed this 18 days ago. Openbug needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9087 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/DirectXShaderCompiler#9086 ·
Maintainers usually reply within 2 days
All issues in microsoft/DirectXShaderCompiler
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
table_translator 当一个 Prism 键映射到多个原码时,首个候选未按权重排序Possibly taken A pull request linked to this issue is open or already merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
arch-based bug niri
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
noctalia-dev/noctalia#5552 ·
Maintainers usually reply within 1 day