D3D12.X: a wait for a list not submitted yet waits on the GPU (#505) #769

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

@⁠ezbyDev on GitHub · 2026-11-24 05:01 UTC · original
ezbyDev:d3d12x/wait-for-later-writer → main · +382 −15 · 2 files · 1 commits · closed without merging

A retail title submits a list whose Wait64BitValueX waits for a counter before the list, on another queue, that writes it – from one thread, and at times before that list is even recorded (@⁠vibryxcx's trace in #505). XCL checked the wait on the CPU before submitting the waiting list, so the thread was held 2 s per wait and the writer was submitted only after the timeouts; the waiting lists ran without the value. Frames stopped and the title's watchdog ended it at +0x23cf683. Part of #505.

A wait that is not met when its list is submitted now becomes ID3D12CommandQueue::Wait on a fence of its own, as on the console, and the list goes to the GPU at once. The fence is signalled on the writer's queue right after the writer list is submitted. The writer is a list recorded already, or the first one recorded later that writes a value meeting the wait. A watcher thread signals the fence instead when the memory meets the wait (a CPU write) or after 10 s, and a writer list that is reset or released lets it go. With no queue or no fence, the wait stays a CPU wait as before.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: lists keep the values of their Write32/64BitValue…X until submitted (value_writes), later_writer, wait_before_submit (in execute_with_waits and KickoffX), the gates signalled in after_submit, the watcher (WATCHED), and two tests.
  • crates/xcl/src/hle/d3d12x/real.rs: execute_with_waits gets the queue.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Intel Core i7-9700K; Windows 11 Pro 26300; Rust 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11; debug for the tests, release for the title.
  • cargo test --workspace -- --test-threads=4 on 6c61607: 703 passed, 0 failed, 41 ignored, no SKIPPED (--no-fail-fast). An earlier run of the same commit failed placed_title_textures_share_vram_and_preserve_pixels (+2 follow-on) – the cubemap page-count flake that fails on main here too and that #447 fixes
  • New tests: a_later_writer_is_a_list_not_submitted_whose_value_meets_the_wait (the lookup) and a_wait_for_a_later_list_holds_the_gpu_not_the_submitting_thread (GPU: two queues; for a writer recorded before, recorded after the submit, released instead, and the CPU writing the counter, the submit returns at once, the waiting queue does not run before its writer, and goes on after it). With the GPU wait turned off the second fails (the submit waited 2.03 s on the CPU); without claiming a writer recorded later, its third round fails.
  • The retail title on this PC (interactive, XCL_NETWORK=0): with this change, Wait64BitValueX … waits on the GPU for list …, which writes it and is not submitted yet for the waits @⁠vibryxcx traced (at 177 s and 230 s in two runs). One wait whose writer was not recorded yet still timed out on the CPU in those runs; the commit now covers it. The title still ends at +0x23cf683 in these runs: the frames stop before these waits, while compute pipelines are built (up to 116 s for one on this driver). This change removes one cause of the stall, not all of it.

Regression run

main:

PR:

Not tested

  • NVIDIA, Intel and RDNA2/3; a run that gets past the watchdog; whether the title reads anything wrong when a wait is let go after 10 s.
  • KickoffX with a gated wait is covered by the same functions but not by its own test.

AI use

  • Claude Code (Claude Opus 5.5): found the fix from @⁠vibryxcx's trace, wrote the code, the tests and this description; the runs above were made on this PC.

🤖 Generated with Claude Code

**@⁠ezbyDev** on GitHub · 2026-11-24 05:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/769) `ezbyDev:d3d12x/wait-for-later-writer` → `main` · +382 −15 · 2 files · 1 commits · closed without merging A retail title submits a list whose `Wait64BitValueX` waits for a counter before the list, on another queue, that writes it – from one thread, and at times before that list is even recorded (@⁠vibryxcx's trace in #505). XCL checked the wait on the CPU before submitting the waiting list, so the thread was held 2 s per wait and the writer was submitted only after the timeouts; the waiting lists ran without the value. Frames stopped and the title's watchdog ended it at `+0x23cf683`. Part of #505. A wait that is not met when its list is submitted now becomes `ID3D12CommandQueue::Wait` on a fence of its own, as on the console, and the list goes to the GPU at once. The fence is signalled on the writer's queue right after the writer list is submitted. The writer is a list recorded already, or the first one recorded later that writes a value meeting the wait. A watcher thread signals the fence instead when the memory meets the wait (a CPU write) or after 10 s, and a writer list that is reset or released lets it go. With no queue or no fence, the wait stays a CPU wait as before. **What is in it** - `crates/xcl/src/hle/d3d12x/list_x.rs`: lists keep the values of their `Write32/64BitValue…X` until submitted (`value_writes`), `later_writer`, `wait_before_submit` (in `execute_with_waits` and `KickoffX`), the gates signalled in `after_submit`, the watcher (`WATCHED`), and two tests. - `crates/xcl/src/hle/d3d12x/real.rs`: `execute_with_waits` gets the queue. **Tested** - AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Intel Core i7-9700K; Windows 11 Pro 26300; Rust 1.100.0 stable-x86_64-pc-windows-msvc; DXC 1.8.2502.11; debug for the tests, release for the title. - `cargo test --workspace -- --test-threads=4` on `6c61607`: 703 passed, 0 failed, 41 ignored, no SKIPPED (`--no-fail-fast`). An earlier run of the same commit failed `placed_title_textures_share_vram_and_preserve_pixels` (+2 follow-on) – the cubemap page-count flake that fails on `main` here too and that #447 fixes - New tests: `a_later_writer_is_a_list_not_submitted_whose_value_meets_the_wait` (the lookup) and `a_wait_for_a_later_list_holds_the_gpu_not_the_submitting_thread` (GPU: two queues; for a writer recorded before, recorded after the submit, released instead, and the CPU writing the counter, the submit returns at once, the waiting queue does not run before its writer, and goes on after it). With the GPU wait turned off the second fails (`the submit waited 2.03 s on the CPU`); without claiming a writer recorded later, its third round fails. - The retail title on this PC (interactive, `XCL_NETWORK=0`): with this change, `Wait64BitValueX … waits on the GPU for list …, which writes it and is not submitted yet` for the waits @⁠vibryxcx traced (at 177 s and 230 s in two runs). One wait whose writer was not recorded yet still timed out on the CPU in those runs; the commit now covers it. The title still ends at `+0x23cf683` in these runs: the frames stop before these waits, while compute pipelines are built (up to 116 s for one on this driver). This change removes one cause of the stall, not all of it. **Regression run** main: PR: **Not tested** - NVIDIA, Intel and RDNA2/3; a run that gets past the watchdog; whether the title reads anything wrong when a wait is let go after 10 s. - `KickoffX` with a gated wait is covered by the same functions but not by its own test. **AI use** - Claude Code (Claude Opus 5.5): found the fix from @⁠vibryxcx's trace, wrote the code, the tests and this description; the runs above were made on this PC. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A retail game submits a list with a Wait64BitValueX on a counter before
the list, on another queue, that writes the counter, from one thread -
at times before that list is even recorded. XCL evaluated the wait on
the CPU before submitting the waiting list, so the thread was held 2 s
per wait and the writer came only after the timeouts; the waiting lists
ran without the value. The title's frames stopped and its watchdog
ended it (+0x23cf683).

A wait that is not met when its list is submitted now becomes
ID3D12CommandQueue::Wait on a fence of its own. Lists remember the
values their Write32/64BitValue*X put at each address until they are
submitted; the list that writes the value - recorded already, or the
first one recorded later - signals the fence on its queue right after
its submission. A watcher thread signals it instead when the memory
meets the wait (a CPU write) or after 10 s, and a writer list that is
reset or released lets it go. Without a queue or a fence the wait stays
a CPU wait.

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

@⁠ezbyDev on GitHub · 2026-11-24 05:15 UTC · original

Closing in favour of #708, which covers the same waits (a waiting list submitted before the list that writes its counter) and was opened first; I missed it when I searched. I'll test #708 on an RX 9060 XT (RDNA4) with the retail title and report there.

AI use: Claude Code (Claude Opus 5.5).

**@⁠ezbyDev** on GitHub · 2026-11-24 05:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/769#issuecomment-7122783180) Closing in favour of #708, which covers the same waits (a waiting list submitted before the list that writes its counter) and was opened first; I missed it when I searched. I'll test #708 on an RX 9060 XT (RDNA4) with the retail title and report there. AI use: Claude Code (Claude Opus 5.5).
Author
Owner

@⁠itsd-effex on GitHub · 2026-11-24 05:17 UTC · original

Linux (Wine + vkd3d-proton) test of 6c61607: no Wait64BitValueX timeouts and no heartbeat abort. The run then ends the way vibryxcx's warm run in #505 did.

Tested

  • RTX 3080 Ti 12 GB (NVIDIA 620.73.04), i7-11700KF, 32 GB RAM + 36 GB swap, Linux. Wine from Proton Experimental, vkd3d-proton master 30b0eb9b with the #257 kit's patch. Release, cross-compiled with cargo-xwin.
  • Tree: main f4ce27c + #684 + #273 + #533 + #267 (merged locally as in my #505 comment), then this PR: 084b291, which merged without conflicts.
  • Workspace suite under Wine (as in #257): 716 passed, 4 failed, 41 ignored. That's the tree without this PR plus its two new tests, and the same 4 Wine/vkd3d-proton failures. Run by name, both new tests pass, including a_wait_for_a_later_list_holds_the_gpu_not_the_submitting_thread.
  • Retail 1.0.2.1, unattended (XCL_PRESS_A_AT), XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=1 XCL_COMPUTE_PSO_WAIT_MS=1, caches warm (#690 preload of 1221 shader sets, 121 driver blobs reused). One run.

Compared with the same tree without this PR (same settings; one of the three with XCL_PSO_PRELOAD=0): three runs ended at the heartbeat abort (+0x23cf683, 226–269 s) after 16–40 Wait64BitValueX timed out after 2000 ms each. A fourth ended earlier, before the world, at an NVIDIA driver out-of-memory error.

With this PR

  • 0 timeouts. 8 waits logged waits on the GPU for list …, which writes it and is not submitted yet (220.2–221.7 s, want 0x7c6).
  • No heartbeat abort. World at 216.7 s (#101).
  • At 220–221 s the 1 ms compute limit skips a lot: dispatches skipped go from 1024 to 3384 and draws skipped to 512. From ~224 s there are 0 submits and 0 presents.
  • At 248 s: 0xc0000005 in game_scarlett_master.exe+0x5024b9b (read at address 0xffffffffffffffff), rax=0x3f19999a3f19999a, stack +0x4f414a5, +0x71bfd00, +0xa28c96, …. That's the same kind of read as vibryxcx's +0x4ddbfc4 after skipped dispatches in #505.

Control run (the same, but XCL_COMPUTE_PSO_WAIT_MS=0: no compute skips), one run:

  • Still 0 Wait64BitValueX timeouts. 0 dispatches skipped. World at 187.2 s.
  • Title threads wait long for compute pipelines instead: waited 20.9 s for compute pipeline … (built in this thread), then 18.4, 11.0, 10.1 and 8.6 s.
  • One wait went to the GPU at 202.9 s (want 0x708, for list 0x5ab07c0). About 8–9 s later the kernel logged NVRM: Xid 109 … CTX SWITCH TIMEOUT for the process. XCL then reported D3D12 device removed: 0x887a0005 at 215.3 s, and the run ended there. The first run's 8 GPU waits caused no Xid, so I can't say this wait caused the timeout, only that a queue was in a GPU-side wait when it happened. I didn't log whether list 0x5ab07c0 had been submitted by then.

So on this card, after this PR, skipping compute leads to the 0xffffffffffffffff read, and waiting for it leads to multi-second stalls. In this one run there was also a GPU context-switch timeout while a GPU-side wait was pending.

Not tested: Windows. The default 4000 ms limits. More than one run of each. Whether the Xid repeats.

AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the suite and the runs, read the logs and drafted this comment. The runs are mine, on the hardware above.

**@⁠itsd-effex** on GitHub · 2026-11-24 05:17 UTC · [original](https://github.com/xcl-dev/xcl/pull/769#issuecomment-7122814850) Linux (Wine + vkd3d-proton) test of `6c61607`: no `Wait64BitValueX` timeouts and no heartbeat abort. The run then ends the way vibryxcx's warm run in #505 did. **Tested** - RTX 3080 Ti 12 GB (NVIDIA 620.73.04), i7-11700KF, 32 GB RAM + 36 GB swap, Linux. Wine from Proton Experimental, vkd3d-proton `master` `30b0eb9b` with the #257 kit's patch. Release, cross-compiled with cargo-xwin. - Tree: `main` `f4ce27c` + #684 + #273 + #533 + #267 (merged locally as in my #505 comment), then this PR: `084b291`, which merged without conflicts. - Workspace suite under Wine (as in #257): 716 passed, 4 failed, 41 ignored. That's the tree without this PR plus its two new tests, and the same 4 Wine/vkd3d-proton failures. Run by name, both new tests pass, including `a_wait_for_a_later_list_holds_the_gpu_not_the_submitting_thread`. - Retail 1.0.2.1, unattended (`XCL_PRESS_A_AT`), `XCL_NETWORK=0 XCL_ACTIVITY=1 XCL_PSO_WAIT_MS=1 XCL_COMPUTE_PSO_WAIT_MS=1`, caches warm (#690 preload of 1221 shader sets, 121 driver blobs reused). One run. **Compared with the same tree without this PR** (same settings; one of the three with `XCL_PSO_PRELOAD=0`): three runs ended at the heartbeat abort (`+0x23cf683`, 226–269 s) after 16–40 `Wait64BitValueX timed out after 2000 ms` each. A fourth ended earlier, before the world, at an NVIDIA driver out-of-memory error. **With this PR** - **0 timeouts.** 8 waits logged `waits on the GPU for list …, which writes it and is not submitted yet` (220.2–221.7 s, `want 0x7c6`). - **No heartbeat abort.** World at 216.7 s (`#101`). - At 220–221 s the 1 ms compute limit skips a lot: dispatches skipped go from 1024 to 3384 and draws skipped to 512. From ~224 s there are 0 submits and 0 presents. - At 248 s: `0xc0000005 in game_scarlett_master.exe+0x5024b9b (read at address 0xffffffffffffffff)`, `rax=0x3f19999a3f19999a`, stack `+0x4f414a5, +0x71bfd00, +0xa28c96, …`. That's the same kind of read as vibryxcx's `+0x4ddbfc4` after skipped dispatches in #505. **Control run** (the same, but `XCL_COMPUTE_PSO_WAIT_MS=0`: no compute skips), one run: - Still 0 `Wait64BitValueX` timeouts. 0 dispatches skipped. World at 187.2 s. - Title threads wait long for compute pipelines instead: `waited 20.9 s for compute pipeline … (built in this thread)`, then 18.4, 11.0, 10.1 and 8.6 s. - One wait went to the GPU at 202.9 s (`want 0x708`, for list `0x5ab07c0`). About 8–9 s later the kernel logged `NVRM: Xid 109 … CTX SWITCH TIMEOUT` for the process. XCL then reported `D3D12 device removed: 0x887a0005` at 215.3 s, and the run ended there. The first run's 8 GPU waits caused no Xid, so I can't say this wait caused the timeout, only that a queue was in a GPU-side wait when it happened. I didn't log whether list `0x5ab07c0` had been submitted by then. So on this card, after this PR, skipping compute leads to the `0xffffffffffffffff` read, and waiting for it leads to multi-second stalls. In this one run there was also a GPU context-switch timeout while a GPU-side wait was pending. **Not tested:** Windows. The default 4000 ms limits. More than one run of each. Whether the Xid repeats. **AI use:** Claude Code (Claude Opus 5.5) merged and built the trees, ran the suite and the runs, read the logs and drafted this comment. The runs are mine, on the hardware above.

Pull request closed

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