[SPIR-V] -fvk-use-dx-layout places cbuffer matrices with double columns at a different offset than DXIL

Open
#9,017 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp
Domain
compilers

Research direction

Start by searching the compiler for -fvk-use-dx-layout handling of cbuffer matrix member offsets, then look for tests covering DX-layout matrix padding, including the cases referenced in #3463 and #3672. Reproduce with the supplied HLSL and compare SPIR-V member offsets with DXIL reflection. Done means the double-matrix member offset matches DirectX’s 16-byte placement while the shared 32-byte column stride and existing float-matrix and vector cases remain unchanged.

Written by the indexing model from the issue text.

Description

bug needs-triage spirv

Description
Under -fvk-use-dx-layout, a cbuffer matrix whose SPIR-V columns are larger than 16 bytes (3 or 4 doubles) doesn't get DirectX's offset. DirectX starts a cbuffer member on the next 16-byte row, so double a; double3x3 m; puts m at 16. The SPIR-V output instead aligns the matrix to its own 32-byte column stride and puts it at 32. The same HLSL therefore describes different bytes per backend, which defeats the point of the flag: one application-side struct can't serve both backends. Both backends agree on the 32-byte column stride; only the member offset differs.

These cases land identically on both backends:

  • float matrices
  • double vectors
  • double scalars

Related: #3463 / #3672 fixed DX-layout matrix padding for float matrices.

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:

cbuffer CB { double a; double3x3 m; }
RWByteAddressBuffer o;
[numthreads(1, 1, 1)]
void main(uint id : SV_DispatchThreadID) { o.Store<float>(0, (float) (a + m[2][2])); }

A standalone repro comparing DXIL reflection against SPIRV-Reflect is attached (repro_dx_layout_double_matrix_spirv_reflect.cpp).

Actual Behavior
SPIR-V:

OpMemberDecorate %type_CB 0 Offset 0
OpMemberDecorate %type_CB 1 Offset 32
OpMemberDecorate %type_CB 1 MatrixStride 32

DXIL:

;       double a;                                     ; Offset:    0
;       column_major double3x3 m;                     ; Offset:   16

All cases:

cbuffer CB { double a; double3x3 m; }   m: DXIL 16, SPIR-V 32   <-- differs
cbuffer CB { double a; double3x2 m; }   m: DXIL 16, SPIR-V 32   <-- differs
cbuffer CB { float a; float3x3 m; }     m: DXIL 16, SPIR-V 16
cbuffer CB { double a; double3 b; }     b: DXIL 16, SPIR-V 16

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/DirectXShaderCompiler

All issues in microsoft/DirectXShaderCompiler

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.