[SPIR-V] -fvk-use-dx-layout doesn't apply DirectX cbuffer layout to [[vk::push_constant]] blocks

未关闭
#9,018 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp
领域
compilers

调研方向

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 内容生成。

描述

bug needs-triage spirv

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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/DirectXShaderCompiler 的其他 Issue

查看 microsoft/DirectXShaderCompiler 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。