Skip to content

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 into
ProjectLeonida:mainfrom
oscarlosu-lab:pr/cbv-vsharp-stride
Closed

oscarlosu-lab wants to merge 1 commit into
ProjectLeonida:mainfrom
oscarlosu-lab:pr/cbv-vsharp-stride

Conversation

@oscarlosu-lab

Copy link
Copy Markdown
Contributor

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.

…P-STRIDE)

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 <noreply@anthropic.com>
@sodove

sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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 d42773d 4/64 4/64 64/64 64/64
PR a29c21b 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.

demoz53 added a commit to demoz53/leonida that referenced this pull request Nov 24, 2026
whoalin1 added a commit to whoalin1/leonida-continued that referenced this pull request Nov 25, 2026
Measured on the RDNA2 iGPU (gfx1036, tools/f16_interp_probe.py, 98,304
samples over 12 native draws): the SPI writes P10/P20 for a 16-bit
channel as per-half f16 differences (round to nearest even), the
weighted sum stays f32, and v_interp_p2_f16 narrows toward zero --
the driver's ISA runs the pair inside s_round_mode 0x000c, so the
narrow is toward zero whatever the shader's own MODE writes are.
The rdna2 model explains 98,274 of 98,304 samples; the previous
translation (f32 deltas, nearest-even narrow) explains 62,226.

- Gen.f16_round: f32 -> nearest-f16 value via f16_bits +
  UnpackHalf2x16 (integer-built bits, so no driver folds the round
  trip away, ProjectLeonida#512/ProjectLeonida#513); applied to the P1-P0 / P2-P0 deltas of
  16-bit-channel reads in attribute().
- v_interp_p2_f16 narrows with f16_bits(rtz=True) and keeps the
  SHADER-430 partial-write high half via write_lo16.
- vk_harness: scan both stages for Float16 / StorageInputOutput16 /
  Float64 capabilities (77 when the device lacks them), enable the
  matching Vulkan 1.1/1.2 features, VKH_PC_BYTES to shrink the
  push-constant range for hand-written fixtures, and VKH_SHADER_INFO
  to dump the driver's fragment disassembly.
- tests/semantic/test_interp_f16_round.py: the two telling cases
  (f16 delta overflow to inf; toward-zero vs nearest-even tie).
- tests/semantic/test_interp_p1lv_f16.py: reference oracle updated
  to the measured model (f16 deltas, f32 sum, toward-zero narrow).
- docs/design.md: 16-bit interpolation row records the SHADER-468
  measurements and remaining unverified items.

Co-Authored-By: Devin <noreply@cognition.ai>
aslan2142 pushed a commit that referenced this pull request Nov 25, 2026
…first-run UI

Build on the public frame-loop integration in #321. Carry the texture-view and depth work from #213 and #261, the layout provider from #461, the responsive window from #526, and the rectangle generator from #682. Integrate the Xbox constant-buffer row addressing measured in #513 and the draw-time rectangle selection in #722. Keep all fixtures synthetic.

The Windows GPU path resolves title-owned shader objects, retires geometry uploads per submission, materializes texture views on use, maps linear surfaces, and delivers completed GPU label writes. A first-run UI launch selects the tested settings for these paths.
@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 25, 2026
@oscarlosu-lab

Copy link
Copy Markdown
Contributor Author

Closing as superseded by #984 and 73c37e1 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!

whoalin1 added a commit to whoalin1/leonida-continued that referenced this pull request Nov 25, 2026
Measured on the RDNA2 iGPU (gfx1036, tools/f16_interp_probe.py, 98,304
samples over 12 native draws): the SPI writes P10/P20 for a 16-bit
channel as per-half f16 differences (round to nearest even), the
weighted sum stays f32, and v_interp_p2_f16 narrows toward zero --
the driver's ISA runs the pair inside s_round_mode 0x000c, so the
narrow is toward zero whatever the shader's own MODE writes are.
The rdna2 model explains 98,274 of 98,304 samples; the previous
translation (f32 deltas, nearest-even narrow) explains 62,226.

- Gen.f16_round: f32 -> nearest-f16 value via f16_bits +
  UnpackHalf2x16 (integer-built bits, so no driver folds the round
  trip away, ProjectLeonida#512/ProjectLeonida#513); applied to the P1-P0 / P2-P0 deltas of
  16-bit-channel reads in attribute().
- v_interp_p2_f16 narrows with f16_bits(rtz=True) and keeps the
  SHADER-430 partial-write high half via write_lo16.
- vk_harness: scan both stages for Float16 / StorageInputOutput16 /
  Float64 capabilities (77 when the device lacks them), enable the
  matching Vulkan 1.1/1.2 features, VKH_PC_BYTES to shrink the
  push-constant range for hand-written fixtures, and VKH_SHADER_INFO
  to dump the driver's fragment disassembly.
- tests/semantic/test_interp_f16_round.py: the two telling cases
  (f16 delta overflow to inf; toward-zero vs nearest-even tie).
- tests/semantic/test_interp_p1lv_f16.py: reference oracle updated
  to the measured model (f16 deltas, f32 sum, toward-zero narrow).
- docs/design.md: 16-bit interpolation row records the SHADER-468
  measurements and remaining unverified items.

Co-Authored-By: Devin <noreply@cognition.ai>
@oscarlosu-lab
oscarlosu-lab deleted the pr/cbv-vsharp-stride branch November 26, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants