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

Closed
github-bot wants to merge 1 commit from gh-pr/513/head into gh-pr/513/base
Owner

@⁠oscarlosu-lab on GitHub · 2026-11-24 06:40 UTC · original
oscarlosu-lab:pr/cbv-vsharp-stride → main · +19 −6 · 3 files · 1 commits · closed without merging

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.

**@⁠oscarlosu-lab** on GitHub · 2026-11-24 06:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/513) `oscarlosu-lab:pr/cbv-vsharp-stride` → `main` · +19 −6 · 3 files · 1 commits · closed without merging 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.
CreateConstantBufferView wrote the CBV's raw V# with STRIDE 0. A buffer access
with idxen adds index x STRIDE to the address, so a program that indexes its
constant buffer by 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, and with
stride 0 every UI shape fell on the line x = y.

STRIDE is now 16, a constant buffer's row. NUM_RECORDS stays the view's size in
bytes with OOB_SELECT RAW, which bounds a MUBUF access by its offset rather than
index x STRIDE, so that bound is unchanged; an s_buffer_load bound becomes
NUM_RECORDS x STRIDE. d3d12_compute_test checks the new words; the descriptor
notes in docs/d3d12_vulkan.md describe the CBV V# (they still listed CBVs and
buffer SRVs as unwritten).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:05:04 +00:00
github-bot closed this pull request 2026-11-26 09:05:04 +00:00
Author
Owner

@⁠sodove on GitHub · 2026-11-24 07:09 UTC · original

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.

**@⁠sodove** on GitHub · 2026-11-24 07:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/513#issuecomment-7124688847) 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.
Author
Owner

@⁠oscarlosu-lab on GitHub · 2026-11-25 07:39 UTC · original

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!

**@⁠oscarlosu-lab** on GitHub · 2026-11-25 07:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/513#issuecomment-7156104060) 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

This discussion has been locked. Commenting is limited to contributors.
No description provided.