d3d12: a constant-buffer view's V# steps 16 bytes a row (RT-CBV-VSHARP-STRIDE) #513

Closed
oscarlosu-lab wants to merge 1 commit from upstream-pr/513 into main
oscarlosu-lab commented 2026-11-24 06:40:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by oscarlosu-lab on 2026-11-24T06:40:26Z.


Claimed in the coordination issue as: RT-CBV-VSHARP-STRIDE

What and why

CreateConstantBufferView wrote the CBV's raw GFX10 V# with STRIDE 0. A translated buffer access with idxen adds index × V# STRIDE to the address (tools/rdna2spirv.py, buffer addressing), so a program that indexes its constant buffer by 16-byte row read row 0 for every index.

ThatRecompDev/five-star-recomp (GPL-3.0), commit 4c6bce59b, measured this on the retail title: the UI's batch programs read each vertex's matrix rows from their CBV by index (row batch × 4 + k); with stride 0 both screen coordinates came out equal and every vector shape of the UI fell on the line x = y (the diagonal across the first-run screens, letters drawn as shapes). Their fix gives a buffer view's record the element stride: 16 for a CBV, the structure for a structured view, the element for a typed one, 0 for raw. In Leonida the structured and typed buffer SRV/UAV paths already write their stride and raw views keep 0, so the CBV is the only gap.

Change

  • runtime/shims/d3d12_vulkan_device.cpp: the CBV V#'s STRIDE is 16 (kConstantBufferRow). NUM_RECORDS stays the view's size in bytes with OOB_SELECT RAW: RAW bounds a MUBUF access by its offset, not index × STRIDE (docs/design.md, Buffer bounds checking), so that bound is unchanged. An s_buffer_load bound becomes NUM_RECORDS × STRIDE, past the end of any constant a program declares.
  • runtime/test/d3d12_compute_test.cpp: the decoded CBV words expect STRIDE 16.
  • docs/d3d12_vulkan.md: describes the CBV V#; the known-gaps list still said CBVs and buffer SRVs were not written.

Tested

Windows 11, MSVC 19.52 x64, NVIDIA GeForce RTX 3060 (driver 621.35): runtime builds with no warnings in the touched files; d3d12_compute_test, d3d12_descriptor_test and d3d12_vulkan_device_test pass. scripts/check_no_game_data.py and tests/test_docs_links.py pass. Not yet measured on a retail boot here; I will add the result when we have it.

AI-assisted (Claude Code). No game files.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5467412753 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/513). Originally posted by [oscarlosu-lab](https://github.com/oscarlosu-lab) on 2026-11-24T06:40:26Z. --- Claimed in the coordination issue as: RT-CBV-VSHARP-STRIDE ### What and why `CreateConstantBufferView` wrote the CBV's raw GFX10 V# with STRIDE 0. A translated buffer access with `idxen` adds index × V# STRIDE to the address (`tools/rdna2spirv.py`, buffer addressing), so a program that indexes its constant buffer by 16-byte row read row 0 for every index. ThatRecompDev/five-star-recomp (GPL-3.0), commit `4c6bce59b`, measured this on the retail title: the UI's batch programs read each vertex's matrix rows from their CBV by index (row batch × 4 + k); with stride 0 both screen coordinates came out equal and every vector shape of the UI fell on the line x = y (the diagonal across the first-run screens, letters drawn as shapes). Their fix gives a buffer view's record the element stride: 16 for a CBV, the structure for a structured view, the element for a typed one, 0 for raw. In Leonida the structured and typed buffer SRV/UAV paths already write their stride and raw views keep 0, so the CBV is the only gap. ### Change - `runtime/shims/d3d12_vulkan_device.cpp`: the CBV V#'s STRIDE is 16 (`kConstantBufferRow`). NUM_RECORDS stays the view's size in bytes with OOB_SELECT RAW: RAW bounds a MUBUF access by its offset, not index × STRIDE (`docs/design.md`, Buffer bounds checking), so that bound is unchanged. An `s_buffer_load` bound becomes NUM_RECORDS × STRIDE, past the end of any constant a program declares. - `runtime/test/d3d12_compute_test.cpp`: the decoded CBV words expect STRIDE 16. - `docs/d3d12_vulkan.md`: describes the CBV V#; the known-gaps list still said CBVs and buffer SRVs were not written. ### Tested Windows 11, MSVC 19.52 x64, NVIDIA GeForce RTX 3060 (driver 621.35): runtime builds with no warnings in the touched files; `d3d12_compute_test`, `d3d12_descriptor_test` and `d3d12_vulkan_device_test` pass. `scripts/check_no_game_data.py` and `tests/test_docs_links.py` pass. Not yet measured on a retail boot here; I will add the result when we have it. AI-assisted (Claude Code). No game files.
sodove commented 2026-11-24 07:09:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-24T07:09:50Z.


Independent GPU verification on Windows 11 26100.7623, RTX 5070 Ti (610.74), MSVC 19.44.35220 Release, with the Khronos Vulkan validation layer enabled.

I reused the two 256-byte CBVs from d3d12_compute_test. A temporary GLSL stand-in used the V# stride for row indexing and read 16 valid rows from each view. Counts below are matching dwords read back from the GPU.

Revision Indexed CBV A Indexed CBV B Linear boundary control Null control
Main d42773d073 4/64 4/64 64/64 64/64
PR a29c21b594 applied to that main 64/64 64/64 64/64 64/64

Main reused row zero. With the PR, the normal d3d12_compute_test also passes with validation enabled. Separately, the translator's semantic harness matched all 32 valid row/word cases for RAW idxen loads at strides 0 and 16.

Synthetic fixtures only. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7124688847 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/513#issuecomment-7124688847). Originally posted by [sodove](https://github.com/sodove) on 2026-11-24T07:09:50Z. --- Independent GPU verification on Windows 11 26100.7623, RTX 5070 Ti (610.74), MSVC 19.44.35220 Release, with the Khronos Vulkan validation layer enabled. I reused the two 256-byte CBVs from d3d12_compute_test. A temporary GLSL stand-in used the V# stride for row indexing and read 16 valid rows from each view. Counts below are matching dwords read back from the GPU. | Revision | Indexed CBV A | Indexed CBV B | Linear boundary control | Null control | | --- | --- | --- | --- | --- | | Main d42773d0734d5fd7b3a32a1bfd536f61186322a5 | 4/64 | 4/64 | 64/64 | 64/64 | | PR a29c21b59487595f84b8696dcb99f978a11630d6 applied to that main | 64/64 | 64/64 | 64/64 | 64/64 | Main reused row zero. With the PR, the normal d3d12_compute_test also passes with validation enabled. Separately, the translator's semantic harness matched all 32 valid row/word cases for RAW idxen loads at strides 0 and 16. Synthetic fixtures only. AI-assisted verification.
oscarlosu-lab commented 2026-11-25 07:39:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by oscarlosu-lab on 2026-11-25T07:39:21Z.


Closing as superseded by #984 and 73c37e19d on main, which already switch CreateConstantBufferView to 16-byte console rows (stride 16) by default with LEONIDA_CBV_RAW=1 fallback. Thanks @sodove for the RTX 5070 Ti verification!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156104060 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/513#issuecomment-7156104060). Originally posted by [oscarlosu-lab](https://github.com/oscarlosu-lab) on 2026-11-25T07:39:21Z. --- Closing as superseded by #984 and 73c37e19d on main, which already switch CreateConstantBufferView to 16-byte console rows (stride 16) by default with LEONIDA_CBV_RAW=1 fallback. Thanks @sodove for the RTX 5070 Ti verification!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!513
No description provided.