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

Closed
opened 2026-11-26 04:19:36 +00:00 by github-bot · 3 comments
Owner

@⁠ozimchuk on GitHub · 2026-11-23 23:02 UTC · original

CreateConstantBufferView (real.rs, dev_create_cbv_x) writes every CBV as a raw V#: buffer_words(va, 0, size, 22), i.e. stride 0, num_records in bytes. Console shaders also read constant buffers with buffer_load_* … idxen, the element number as the index. With stride 0 the index is ignored (the hardware rule, which the recompiler follows: base + stride·index), so every such read returns element 0.

Where it shows (Linux, NVIDIA, Wine + relaxed vkd3d-proton, main 9ab7d76): the black image with the 1-pixel diagonal in #175. A retail game's UI element VS (28d887aa04ffa15a) computes each vertex as x = X·A.x + Y·A.y + A.w, y = X·B.x + Y·B.y + B.w, with A and B read by buffer_load_dwordx4 … idxen at elements 4k+2 and 4k+3 of a CBV. The V# it loads from its root table (XCL_TRACE_FRAME=1 XCL_TRACE_SHADERS=28d887aa04ffa15a, and the table read as raw memory at the draw and again at the next present) is [base, 0x4, 0x600, 0x31016fac] – stride 0 both times – so A = B and every vertex lands on x = y.

Experiment: CBVs as float4 elements, buffer_words(va, 16, size / 16, 77). Scalar loads are unaffected (s_buffer_load limits at num_records × stride), offset-addressed loads read the same addresses. Frame dumps (XCL_FRAME_DUMP=1) go from black-with-the-diagonal to the menus; with #244 and #283 on top, the intro video and the first-run settings screens at 30 fps.

What I can't explain, and why a Windows measurement would help: that code has no platform switch, yet the menus draw on Windows and in the stock-vkd3d-proton Linux setup in #175 (FilipeSilvens). Either the CBV reaches the table another way on those setups, or the diagonal has another cause there and the stride change only hides it. On a setup where the menu shows, could someone run

XCL_TRACE_FRAME=1 XCL_TRACE_SHADERS=28d887aa04ffa15a XCL_TRACE_MANY=4

and post the p0 table … [0] - T# […] part of the first frame trace: UI draw line? The second word decides: 0x4 (stride 0) or e.g. 0x100004 (stride 16).

Not known: the console driver's own CBV encoding (stride, out-of-range mode). A merge request waits for this answer.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠ozimchuk** on GitHub · 2026-11-23 23:02 UTC · [original](https://github.com/xcl-dev/xcl/issues/307) `CreateConstantBufferView` (`real.rs`, `dev_create_cbv_x`) writes every CBV as a raw V#: `buffer_words(va, 0, size, 22)`, i.e. stride 0, num_records in bytes. Console shaders also read constant buffers with `buffer_load_* … idxen`, the element number as the index. With stride 0 the index is ignored (the hardware rule, which the recompiler follows: `base + stride·index`), so every such read returns element 0. **Where it shows (Linux, NVIDIA, Wine + relaxed vkd3d-proton, `main` `9ab7d76`):** the black image with the 1-pixel diagonal in #175. A retail game's UI element VS (`28d887aa04ffa15a`) computes each vertex as `x = X·A.x + Y·A.y + A.w`, `y = X·B.x + Y·B.y + B.w`, with A and B read by `buffer_load_dwordx4 … idxen` at elements `4k+2` and `4k+3` of a CBV. The V# it loads from its root table (`XCL_TRACE_FRAME=1 XCL_TRACE_SHADERS=28d887aa04ffa15a`, and the table read as raw memory at the draw and again at the next present) is `[base, 0x4, 0x600, 0x31016fac]` – stride 0 both times – so A = B and every vertex lands on x = y. **Experiment:** CBVs as float4 elements, `buffer_words(va, 16, size / 16, 77)`. Scalar loads are unaffected (`s_buffer_load` limits at `num_records × stride`), offset-addressed loads read the same addresses. Frame dumps (`XCL_FRAME_DUMP=1`) go from black-with-the-diagonal to the menus; with #244 and #283 on top, the intro video and the first-run settings screens at 30 fps. **What I can't explain, and why a Windows measurement would help:** that code has no platform switch, yet the menus draw on Windows and in the stock-vkd3d-proton Linux setup in #175 (FilipeSilvens). Either the CBV reaches the table another way on those setups, or the diagonal has another cause there and the stride change only hides it. On a setup where the menu shows, could someone run ``` XCL_TRACE_FRAME=1 XCL_TRACE_SHADERS=28d887aa04ffa15a XCL_TRACE_MANY=4 ``` and post the `p0 table … [0] - T# […]` part of the first `frame trace: UI draw` line? The second word decides: `0x4` (stride 0) or e.g. `0x100004` (stride 16). Not known: the console driver's own CBV encoding (stride, out-of-range mode). A merge request waits for this answer. AI-assisted (Claude Code, Claude Opus 5.5).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:19:36 +00:00
Author
Owner

@⁠ozimchuk on GitHub · 2026-11-23 23:47 UTC · original

Opened #335 with the change.

What settled it, from #175:

  • @⁠FilipeSilvens' trace: on a setup where the menu draws, the title writes this descriptor itself: [base, 0x00100004, 0x00000060, 0x0002403c], stride 16 and num_records = size / 16. On the setups with the diagonal it calls CreateConstantBufferView instead, and XCL wrote stride 0. #335 makes XCL's CBV match the title's own encoding.
  • @⁠notdxbi found the same cause independently.

Measured for #335 (Linux, NVIDIA, under Wine), main against the PR:

  • 120 s regression runs: identical, 3062 frames, no crashes.
  • Frame dumps: black with the diagonal on main, the account prompt with the PR.
  • Library tests: the same 12 device-dependent failures on both, plus the new test passing.

Still open: what makes the title take one path or the other. It is not 7a033c8, and not the relaxed vkd3d-proton build. With unmodified vkd3d-proton and a vtable hand-back like FilipeSilvens', the title still calls CreateConstantBufferView here. That hand-back also needs the console ResetX (list_x::reset_x) covered, or the title stops after a list Reset returns E_INVALIDARG.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠ozimchuk** on GitHub · 2026-11-23 23:47 UTC · [original](https://github.com/xcl-dev/xcl/issues/307#issuecomment-7117376318) Opened #335 with the change. What settled it, from #175: - @⁠FilipeSilvens' trace: on a setup where the menu draws, the title writes this descriptor itself: `[base, 0x00100004, 0x00000060, 0x0002403c]`, stride 16 and num_records = size / 16. On the setups with the diagonal it calls `CreateConstantBufferView` instead, and XCL wrote stride 0. #335 makes XCL's CBV match the title's own encoding. - @⁠notdxbi found the same cause independently. Measured for #335 (Linux, NVIDIA, under Wine), main against the PR: - 120 s regression runs: identical, 3062 frames, no crashes. - Frame dumps: black with the diagonal on main, the account prompt with the PR. - Library tests: the same 12 device-dependent failures on both, plus the new test passing. Still open: what makes the title take one path or the other. It is not `7a033c8`, and not the relaxed vkd3d-proton build. With unmodified vkd3d-proton and a vtable hand-back like FilipeSilvens', the title still calls `CreateConstantBufferView` here. That hand-back also needs the console `ResetX` (`list_x::reset_x`) covered, or the title stops after a list Reset returns E_INVALIDARG. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

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

Windows measurement, from a setup where the menus draw (RTX 3080 Ti, wave32-only).

Setup: Windows 11 Pro build 26300, Ryzen 7 7800X3D, 32 GB, NVIDIA RTX 3080 Ti 12 GB
(driver 621.24), Rust 1.100.0 stable MSVC, DXC 1.8.2502.11 (SDK 10.0.26100). Built from
main at 4017f8ff8faaae6007fd83910d230a027dd85a33, release. Run with XCL_NETWORK=0
and the requested XCL_TRACE_FRAME=1 XCL_TRACE_SHADERS=28d887aa04ffa15a XCL_TRACE_MANY=4,
60 s (XCL_RUN_SECONDS=60).

The first frame trace: UI draw line (vs 28d887aa04ffa15a, ps b40d9ca24fe3d23d,
pipeline 0x1ed30daf790):

p0 table 0x4e36dbe0: [0] - T# Some([4e36dc00, 100004, 60, 2403c]),
[1] - T# Some([33fe0000, 33fe0000, 33fe0000, 0]),
[2] - T# Some([38000c1b, ab1ffffe, 0, b3eae81e]),
[3] - T# Some([343e8000, 343e8000, 343e8000, 0]); p1 constants [0, 0]

The second word is 0x100004 — stride 16, not 0x4. The next three UI draws in the
same trace show the same [base, 100004, 60, 2403c] shape at different table addresses.
So on this Windows setup the CBV reaches the root table with stride 16, while the Linux
measurement in this issue saw stride 0 ([base, 0x4, 0x600, 0x31016fac]) for the same
shader — consistent with the "the CBV reaches the table another way on those setups"
hypothesis. (Word 3 also differs: 0x60 here vs 0x600 there.)

One nuance from a later run without the shader filter: a different UI vertex shader
(7fda1be8fbc78299) shows [0] - T# Some([4dbc93e0, 4, 80, 31016fac]) — second word
0x4, stride 0 — on the same Windows setup, while entry [2] of that same table is
100004 (stride 16). Both encodings coexist here; the stride-16 answer above is for the
shader this issue asked about (28d887aa04ffa15a).

Run context: the title ran the full 60 s and exited 0x0: 641 frames shown, 641
PresentX calls at 3840×2160, 13.4 fps over the last 300 (first run on this machine, so
#284's coherent-window learning may apply). No assert, no crash, no device removal —
on this same GPU model #301 reported an early 0x80000003 with 0 presents at 9ab7d76;
at this commit it does not reproduce here.

Follow-up runs (same commit, after uma_coherent.txt was learned, 4095 MB coherent
window):
three clean 60 s runs, exit 0x0, 1499–1511 frames at 29.8–30.0 fps over
the last 300 — the #284 first-run penalty (13.4 → ~30 fps) reproduces and clears exactly
as described. One run with XCL_FRAME_DUMP=1 crashed at ~250 presents with
0xc0000005 in nvwgf2umx.dll+0x8d713f (read at 0x3c); the three runs without the
dump were clean. The game's crash reporter attempted an upload during that crash and
failed (WinHttpSendRequest error: 12007 under XCL_NETWORK=0); the ~30 MB minidump
stayed local.

Not tested: other GPUs, the Linux path, a second run after uma_coherent.txt is
learned.

AI use: Gentle Shell (Pi coding agent), model qwen4-max: ran the title and wrote this
report from the trace output; a human reviewed it before posting. No code changes.

**@⁠MonkeyPython** on GitHub · 2026-11-24 00:06 UTC · [original](https://github.com/xcl-dev/xcl/issues/307#issuecomment-7117703559) Windows measurement, from a setup where the menus draw (RTX 3080 Ti, wave32-only). **Setup:** Windows 11 Pro build 26300, Ryzen 7 7800X3D, 32 GB, NVIDIA RTX 3080 Ti 12 GB (driver 621.24), Rust 1.100.0 stable MSVC, DXC 1.8.2502.11 (SDK 10.0.26100). Built from `main` at `4017f8ff8faaae6007fd83910d230a027dd85a33`, release. Run with `XCL_NETWORK=0` and the requested `XCL_TRACE_FRAME=1 XCL_TRACE_SHADERS=28d887aa04ffa15a XCL_TRACE_MANY=4`, 60 s (`XCL_RUN_SECONDS=60`). **The first `frame trace: UI draw` line** (vs `28d887aa04ffa15a`, ps `b40d9ca24fe3d23d`, pipeline `0x1ed30daf790`): ``` p0 table 0x4e36dbe0: [0] - T# Some([4e36dc00, 100004, 60, 2403c]), [1] - T# Some([33fe0000, 33fe0000, 33fe0000, 0]), [2] - T# Some([38000c1b, ab1ffffe, 0, b3eae81e]), [3] - T# Some([343e8000, 343e8000, 343e8000, 0]); p1 constants [0, 0] ``` **The second word is `0x100004` — stride 16**, not `0x4`. The next three UI draws in the same trace show the same `[base, 100004, 60, 2403c]` shape at different table addresses. So on this Windows setup the CBV reaches the root table with stride 16, while the Linux measurement in this issue saw stride 0 (`[base, 0x4, 0x600, 0x31016fac]`) for the same shader — consistent with the "the CBV reaches the table another way on those setups" hypothesis. (Word 3 also differs: `0x60` here vs `0x600` there.) One nuance from a later run without the shader filter: a different UI vertex shader (`7fda1be8fbc78299`) shows `[0] - T# Some([4dbc93e0, 4, 80, 31016fac])` — second word `0x4`, stride 0 — on the same Windows setup, while entry `[2]` of that same table is `100004` (stride 16). Both encodings coexist here; the stride-16 answer above is for the shader this issue asked about (`28d887aa04ffa15a`). **Run context:** the title ran the full 60 s and exited `0x0`: 641 frames shown, 641 PresentX calls at 3840×2160, 13.4 fps over the last 300 (first run on this machine, so #284's coherent-window learning may apply). No assert, no crash, no device removal — on this same GPU model #301 reported an early `0x80000003` with 0 presents at `9ab7d76`; at this commit it does not reproduce here. **Follow-up runs (same commit, after `uma_coherent.txt` was learned, 4095 MB coherent window):** three clean 60 s runs, exit `0x0`, 1499–1511 frames at **29.8–30.0 fps** over the last 300 — the #284 first-run penalty (13.4 → ~30 fps) reproduces and clears exactly as described. One run with `XCL_FRAME_DUMP=1` crashed at ~250 presents with `0xc0000005` in `nvwgf2umx.dll+0x8d713f` (read at `0x3c`); the three runs without the dump were clean. The game's crash reporter attempted an upload during that crash and failed (`WinHttpSendRequest error: 12007` under `XCL_NETWORK=0`); the ~30 MB minidump stayed local. **Not tested:** other GPUs, the Linux path, a second run after `uma_coherent.txt` is learned. **AI use:** Gentle Shell (Pi coding agent), model qwen4-max: ran the title and wrote this report from the trace output; a human reviewed it before posting. No code changes.
Author
Owner

@⁠MonkeyPython on GitHub · 2026-11-24 01:02 UTC · original

Thanks — the code reading matches what we measured, and the trace has one more data
point that fits your "different V# reaching that slot" branch.

The stride-16 word is real in the table: on Windows with the menus drawing, the first
frame trace: UI draw for 28d887aa04ffa15a reads
[0] - T# Some([4e36dc00, 100004, 60, 2403c]) (and the next three UI draws the same
shape). Given dev_create_cbv_x writes stride 0 unconditionally, that entry cannot be
runtime-encoded — and the base (0x4e36dc00) is a title-memory console VA, so a
descriptor written there by the game's own console code, read as-is by the root table,
is the source your analysis leaves open.

The coexistence shows up in a later run at a6f5f7a without the shader filter: a
different UI vertex shader, 7fda1be8fbc78299, has
[0] - T# Some([4dbc93e0, 4, 80, 31016fac]) — stride 0 — while entry [2] of that same
table is [4dbc9200, 100004, 1e, 2403c] — stride 16. Both encodings side by side in one
Windows run, which is what you would expect if some slots hold game-written V#s and
others hold runtime-written ones, rather than a platform switch in the encoder.

So the measurement side says: stride 16 for the asked shader on Windows, stride 0 for
another, same machine same run. Your 4070 Ti trace will show whether the same shader
gets the same word on a second Windows setup.

AI use: Gentle Shell (Pi coding agent), model qwen4-max: ran the traces and wrote
this reply from their output; a human reviewed it before posting. No code changes.

**@⁠MonkeyPython** on GitHub · 2026-11-24 01:02 UTC · [original](https://github.com/xcl-dev/xcl/issues/307#issuecomment-7118690478) Thanks — the code reading matches what we measured, and the trace has one more data point that fits your "different V# reaching that slot" branch. The stride-16 word is real in the table: on Windows with the menus drawing, the first `frame trace: UI draw` for `28d887aa04ffa15a` reads `[0] - T# Some([4e36dc00, 100004, 60, 2403c])` (and the next three UI draws the same shape). Given `dev_create_cbv_x` writes stride 0 unconditionally, that entry cannot be runtime-encoded — and the base (`0x4e36dc00`) is a title-memory console VA, so a descriptor written there by the game's own console code, read as-is by the root table, is the source your analysis leaves open. The coexistence shows up in a later run at `a6f5f7a` without the shader filter: a different UI vertex shader, `7fda1be8fbc78299`, has `[0] - T# Some([4dbc93e0, 4, 80, 31016fac])` — stride 0 — while entry `[2]` of that same table is `[4dbc9200, 100004, 1e, 2403c]` — stride 16. Both encodings side by side in one Windows run, which is what you would expect if some slots hold game-written V#s and others hold runtime-written ones, rather than a platform switch in the encoder. So the measurement side says: stride 16 for the asked shader on Windows, stride 0 for another, same machine same run. Your 4070 Ti trace will show whether the same shader gets the same word on a second Windows setup. **AI use:** Gentle Shell (Pi coding agent), model qwen4-max: ran the traces and wrote this reply from their output; a human reviewed it before posting. No code changes.
This discussion has been locked. Commenting is limited to contributors.
No description provided.