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

Manually merged
github merged 1 commit from gh-pr/335/head into gh-pr/335/base 2026-11-26 04:20:26 +00:00
Owner

@⁠ozimchuk on GitHub · 2026-11-23 23:47 UTC · original
ozimchuk:cbv-stride → main · +24 −3 · 2 files · 1 commits · merged 2026-11-24 00:03 UTC

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

  • #175: the black image with the diagonal on Linux.
    • @⁠notdxbi localised it to the menu's element VS, then found this cause independently (their item 1).
    • @⁠jvyden saw the same quad outline.
    • @⁠FilipeSilvens traced the title's own descriptor (stride 16), which settled the encoding.
    • @⁠wiktorekdev reached the loading screen with the same change.
  • #307: the report of this cause and the question it asked: why the menus draw on some setups without the change.
  • #257: the Linux guide these runs follow (relaxed vkd3d-proton, ignore_shared_fence, an audio device).
  • #283 and #244: on top of this change they take the title on to the intro video and the first-run settings screens (tested here, not part of this PR).

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

  • Linux (kernel 7.0), NVIDIA GPU (32-lane waves), WineHQ Staging 11.21, vkd3d-proton 3.1 relaxed as described in #175 with VKD3D_CONFIG=ignore_shared_fence, DXVK dxgi; Rust 1.100.0, x86_64-pc-windows-gnu, release.
  • cargo test -p xcl --lib under Wine, without a GPU, main and this branch: 613 passed / 12 failed / 21 ignored on main, 614 / 12 / 21 here. The extra pass is the new test, and the 12 failures are the same on both: tests that need a D3D12 device or the LLVM corpus.
  • A retail game, frame dumps (XCL_FRAME_DUMP=1):
    • main: black, plus the diagonal (479 white texels of 518 400);
    • this branch: the first-run account prompt with its footer.
    • With #244 and #283 on top, the intro video and the first-run settings screens at 30 fps.

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

  • Windows, and scripts/smoke.ps1 itself (no Windows machine here).
  • AMD GPUs.
  • Other titles.
  • The GPU tests (the suite above ran without a GPU).
  • Why the same title writes this descriptor itself on some setups and calls CreateConstantBufferView on others (#307). Either way, the CBV path now writes what the title would.

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.

**@⁠ozimchuk** on GitHub · 2026-11-23 23:47 UTC · [original](https://github.com/xcl-dev/xcl/pull/335) `ozimchuk:cbv-stride` → `main` · +24 −3 · 2 files · 1 commits · merged 2026-11-24 00:03 UTC 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** - #175: the black image with the diagonal on Linux. - @⁠notdxbi localised it to the menu's element VS, then found this cause independently (their item 1). - @⁠jvyden saw the same quad outline. - @⁠FilipeSilvens traced the title's own descriptor (stride 16), which settled the encoding. - @⁠wiktorekdev reached the loading screen with the same change. - #307: the report of this cause and the question it asked: why the menus draw on some setups without the change. - #257: the Linux guide these runs follow (relaxed vkd3d-proton, `ignore_shared_fence`, an audio device). - #283 and #244: on top of this change they take the title on to the intro video and the first-run settings screens (tested here, not part of this PR). **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** - Linux (kernel 7.0), NVIDIA GPU (32-lane waves), WineHQ Staging 11.21, vkd3d-proton 3.1 relaxed as described in #175 with `VKD3D_CONFIG=ignore_shared_fence`, DXVK dxgi; Rust 1.100.0, `x86_64-pc-windows-gnu`, release. - `cargo test -p xcl --lib` under Wine, without a GPU, main and this branch: 613 passed / 12 failed / 21 ignored on main, 614 / 12 / 21 here. The extra pass is the new test, and the 12 failures are the same on both: tests that need a D3D12 device or the LLVM corpus. - A retail game, frame dumps (`XCL_FRAME_DUMP=1`): - main: black, plus the diagonal (479 white texels of 518 400); - this branch: the first-run account prompt with its footer. - With #244 and #283 on top, the intro video and the first-run settings screens at 30 fps. **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** - Windows, and `scripts/smoke.ps1` itself (no Windows machine here). - AMD GPUs. - Other titles. - The GPU tests (the suite above ran without a GPU). - Why the same title writes this descriptor itself on some setups and calls `CreateConstantBufferView` on others (#307). Either way, the CBV path now writes what the title would. **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](https://claude.com/claude-code) AI-assisted.
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 (#175, #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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:20:25 +00:00
github manually merged commit 01a7446be8 into gh-pr/335/base 2026-11-26 04:20:26 +00:00
Author
Owner

@⁠throny on GitHub · 2026-11-23 23:56 UTC · original · edited 2026-11-23 23:58 UTC

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.
**@⁠throny** on GitHub · 2026-11-23 23:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/335#issuecomment-7117520872) · edited 2026-11-23 23:58 UTC 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.
Author
Owner

@⁠ivall on GitHub · 2026-11-24 00:03 UTC · original

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.

**@⁠ivall** on GitHub · 2026-11-24 00:03 UTC · [original](https://github.com/xcl-dev/xcl/pull/335#issuecomment-7117660644) 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.
Author
Owner

@⁠ryosen0 on GitHub · 2026-11-24 00:06 UTC · original

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.

**@⁠ryosen0** on GitHub · 2026-11-24 00:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/335#issuecomment-7117709507) 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.