Skip to content

D3D12.X: constant buffer views are float4 rows (stride 16), not raw buffers - #335

Merged
ivall merged 1 commit into
ivall:mainfrom
ozimchuk:cbv-stride
Nov 24, 2026
Merged

ivall merged 1 commit into
ivall:mainfrom
ozimchuk:cbv-stride

Conversation

@ozimchuk

Copy link
Copy Markdown
Contributor

Fixes #307. The black image with a 1-pixel diagonal reported in #175.

CreateConstantBufferView (real.rs, dev_create_cbv_x) wrote every CBV as a raw V#: stride 0, num_records in bytes. Console shaders also read constant-buffer arrays with buffer_load_* … idxen and the row number as the index. With stride 0 the index is ignored (the recompiler follows the hardware rule base + stride·index), so every such read returns row 0. A retail game's UI element VS (28d887aa04ffa15a) reads its transform as two rows, 4k+2 and 4k+3. With both equal, every vertex lands on x = y and the whole UI collapses onto the screen's diagonal.

Where the title writes this descriptor itself, it writes [base, 0x00100004, 0x00000060, 0x0002403c] for the same 1536-byte buffer (@FilipeSilvens' trace in #175): stride 16, num_records = size / 16. XCL's CBV now matches that. @notdxbi found the same cause independently in #175; @wiktorekdev carries the same change locally.

Discussion

What is in it

  • desc::cbv_words(address, size): stride 16, num_records = ceil(size / 16), format 32_32_32_32_FLOAT.
  • dev_create_cbv_x uses it instead of buffer_words(va, 0, size, 22).
  • Loads by byte offset read the same addresses as before. Scalar loads keep their byte limit, because s_buffer_load bounds at num_records × stride. One difference: a vector load by byte offset is now bounded by the row index (always 0 there), not by the byte size. Reads inside the buffer are unchanged.
  • Test gpu::desc::tests::cbv_is_float4_rows.

Tested

Regression run

Made under Wine on Linux with the equivalent of scripts/smoke.ps1: XCL_NETWORK=0 XCL_RUN_SECONDS=120 XCL_ACTIVITY=1 xcl.exe run <title>, the same block read from the log. Both builds come from clean checkouts of the two commits. Peak commit reads 0 under Wine.

main:

xcl-smoke v1
commit: 85bdf2193e7a793d568485b35f9cae5e8159bc39
gpu: NVIDIA (32-lane waves), Linux, Wine + vkd3d-proton
title: retail-title
seconds: 120
exit: 0x0
frames shown: 3062 (PresentX 3062)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 01a7446be8d72ccceb0cf0ad35fcdb294aedd261
gpu: NVIDIA (32-lane waves), Linux, Wine + vkd3d-proton
title: retail-title
seconds: 120
exit: 0x0
frames shown: 3062 (PresentX 3062)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5): the diagnosis (traces, descriptor reads, frame dumps), the change, the test and this description. The runs were real.

🤖 Generated with Claude Code

AI-assisted.

…uffers

CreateConstantBufferView wrote every CBV as a raw V# (stride 0, num_records in
bytes). Console shaders index constant-buffer arrays with buffer_load_* idxen
and the row as the index; with stride 0 the index is ignored, so every row
read returns row 0. A retail game's UI element shader reads its transform as
two such rows: with both equal, every vertex lands on x = y and the UI
collapses onto the screen's diagonal (ivall#175, ivall#307). Where the title writes
this descriptor itself, it writes stride 16 and num_records = size / 16.

desc::cbv_words: stride 16, num_records = ceil(size / 16). Loads by byte
offset read the same addresses as before; scalar loads keep their byte limit
(num_records x stride).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@throny

throny commented Nov 23, 2026 •

Copy link
Copy Markdown

Test report for 01a7446, merged onto current main 2b4bb43 (clean merge, merge commit dbbb4cd): pass.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 4080 (driver 610.88), Intel i9-12900K, 64 GB; Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 671 passed, 0 failed, 41 ignored (lib: 631 / 0 / 21, gpu::desc::tests::cbv_is_float4_rows ok)
  • SKIPPED on this adapter: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware (no wave64)
  • Negative control: with cbv_words returning main's encoding (buffer_words(address, 0, size, 22)), cbv_is_float4_rows fails (left: (…, 0, 1536, 22), right: (…, 16, 96, 77)).

Reviewed (read the whole diff)

  • Scalar loads: smem limits by num_records × stride when the stride is non-zero, so s_buffer_load keeps the 1536-byte limit. Checked.
  • Vector loads by byte offset (offen, no idxen): with stride 16, in_range becomes 0 < num_records, so a read past the view's end is no longer zeroed. The description says so already; reads inside the view are unchanged.
  • Minor, no effect on raw loads: the title's own dword 3 quoted in the description (0x0002403c) has format field 0x24, while cbv_words writes 77 (32_32_32_32_FLOAT). This would only matter for a buffer_load_format on a CBV.

Not tested

  • No regression run (scripts/smoke.ps1) on a title, and no XCL_SAMPLE_* game-data tests.
  • AMD and wave64 hardware, release build.

AI use

  • Claude Code (Claude Opus 5.5) ran the build, the tests and the negative control, read the diff and wrote this report. The runs above are real, on the hardware named.

@ivall
ivall merged commit f673b54 into ivall:main Nov 24, 2026
2 checks passed
@ivall

ivall commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Merged (a6f5f7a). Checked on an RX 9070 (RDNA4) on main a6f5f7a, together with #335, #322, #331, #330, #338, #318 and #332: cargo test --workspace -- --test-threads=4 - 636 unit tests passed, 0 failed; the retail game reaches its menu and draws it (frame dump) and goes on past it. The menu's UI draws as before on Windows with the stride-16 CBVs.

@ryosen0

ryosen0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Test report on our machine with this PR's head (01a7446) stacked on main db1ddb2 + #300 + #294 + #273 + #236 + #304: Ryzen 7 9800X3D, RTX 3060 Ti 8 GB (wave32), driver 32.0.16.1742, Windows 11.

XCL_NETWORK=0 XCL_RUN_SECONDS=420 XCL_ACTIVITY=1 XCL_TRACE_FAULTS=1 xcl run <retail folder>: clean exit at the timer, 7570 frames shown, no crash, no fault lines, no device removal. The run stayed alive well past the point where an earlier stack died: fps 30 -> ~13-25 while memory grows (t=418 s: 28420 MB committed by the process, 13540 MB local + 4641 MB non-local video memory on the 8 GB card), which looks like continued asset streaming. What is on screen at that point is not something this report can claim - the run was unattended.

For comparison, our previous stack without this PR (main 4017f8f + #300 + #294 + #273/+#208 + #283/+#252) crashed at t=395 s in a 600 s run with 0xc0000005 (write at 0xc43440110, game+0x35a47bc) at ~26.6 GB commit. Different stack, so this is not a controlled A/B of this PR alone - but no regression on our hardware and the run went further.

The artwork-intro slow stretch (4.4-8.6 fps, t~45-165 s) is unchanged with this PR; we measured it identical with and without the audio PRs, so it is not this CBV path either.

Not tested: unit tests for this report (run-only data point); the diagonal-collapse case from #175 (we never saw it on NVIDIA).

AI use: GPT-6.2 Astra (API model selector) ran the build and run and wrote this report; the human contributor reviewed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Constant buffer views are encoded with stride 0, so idxen reads from a CBV ignore the index – measured on Linux, Windows measurement wanted

4 participants