[SPIR-V] -fvk-use-dx-layout doesn't apply DirectX cbuffer layout to [[vk::push_constant]] blocks
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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)
- 主要语言
- C++
- 星标
- 3.7k
- 派生
- 926
- 平均合并
- 3 天 22 小时
- 30 天内合并 PR
- 45
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/DirectXShaderCompiler 的其他 Issue
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/DirectXShaderCompiler#9173 ·
维护者通常 2 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 65/100
microsoft/DirectXShaderCompiler#9155 · 4 条评论 ·
维护者通常 2 天内回复
-
bug needs-triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/DirectXShaderCompiler#9135 ·
维护者通常 2 天内回复
-
DXC emits DW_LANG_C_plus_plus instead of DW_LANG_HLSL for HLSL可能已有人在做 @rj123-nv 于 18 天前认领。 未关闭bug needs-triage
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/DirectXShaderCompiler#9087 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
microsoft/DirectXShaderCompiler#9086 ·
维护者通常 2 天内回复
查看 microsoft/DirectXShaderCompiler 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
feature:config kind:docs os:windows toolchain:cmake triaged
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
arch-based bug niri
难度 2/5 1-3 小时 新手友好度 68/100
noctalia-dev/noctalia#5552 ·
维护者通常 1 天内回复