[SPIR-V] -fvk-use-dx-layout doesn't apply DirectX cbuffer layout to [[vk::push_constant]] blocks
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
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時間
- マージ済み PR(30日)
- 45
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信