d3d12: hold a label wait for a write that is still to run #398

Merged
MathiewMay merged 1 commit from upstream-pr/398 into main 2026-11-28 14:41:16 +00:00
MathiewMay commented 2026-11-28 13:29:06 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by MathiewMay on 2026-11-28T13:29:06Z.


Summary

A queue held on a fence label is released after five seconds (STALL in runtime/d3d12/src/commands/memory_wait.rs), for the case where the work that should have written the label was dropped. The release did not look at what the title was doing, and a title can submit the list that waits on a label well before the list that writes it.

ProjectScarlett does: in each frame it records the lists that write a set of labels, submits compute lists that wait on those labels, and submits the writing lists with the rest of the frame. When a frame takes longer than five seconds, the compute lists are released and run before the work they wait for. On a880dfd its first frame that traces rays released four compute queues this way, while the stall report said "no submitted or rejected list writes it": the lists that write those labels were recorded and not submitted yet.

A wait that old now holds while a write that satisfies it is still to run:

  • recorded in a list that no queue has taken yet, or
  • given to another queue, in a batch that has not run.

What the waiting queue itself was given does not count: it has run already, or it is behind the wait and cannot run before the wait ends. A list that is reset, rejected or destroyed holds no queue, and neither do the lists of a batch its queue rejects or drops. A wait nothing is going to satisfy is released after five seconds, as before.

The record is commands/memory_wait/recorded_writes.rs: each label write a list records, with its value, kept while the list's recording is alive and then until the batch it was submitted in has run. It is consulted only once a wait is five seconds old, and then every 100 ms.

This does not use the in-flight writes that wait elision keeps (has_in_flight_write). Those hold ranges without values, any dispatch or draw makes a batch count as writing everything, and the waiting batch is itself in flight until its wait ends, so a wait would hold for itself.

A title that records a write and never submits or resets that list now holds the waiting queue for good, where it was released after five seconds. A console holds it for good too.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: NVIDIA still needs to run them.

Lanes scenario cross-queue-late: the direct queue records a label write, the compute queue submits a list that waits for it, and the direct list is submitted 6.5 s later. The compute queue must not have run by then. Against main's provider it fails ("the compute queue ran before the direct queue wrote the label it waits on"). It adds 6.5 s to the Lanes run.

Unit tests in runtime/d3d12/src/tests/commands/recorded_writes.rs cover the record: a recorded write holds until its list is gone, a submitted one until its batch has run, a write given to the waiting queue itself does not hold, and what has run or is gone is dropped.

In ProjectScarlett, on 6f89916 together with other changes of mine: over six minutes of frames that took 12 to 30 s each, at least 32 waits were held past five seconds, each ended when its write ran, and none was released. That run ended after ten minutes on an assertion in the title's resource loading, which I have not traced to a cause yet; the device was not lost.

GPU, driver and backend: AMD Radeon RX 9070 (1002:7550, RADV GFX1201), Mesa 26.2.7, Linux 7.3, GE-Proton11-14 (--backend proton).

Commands run and their results:

cargo xwin test --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib     (run under Proton)
  245 passed, 0 failed

python tuxbox.py verify --only lanes-selftest --backend proton --adapter 1002:7550
  20 PASS, 0 FAIL    (cross-queue-late: FAIL with main's d3d12_xs.dll in the same package)

python tools/check_d3d12_regressions.py ... --adapter 1002:7550      (its 21 cases)
  21 PASS, 0 FAIL

python tuxbox.py check --no-gpu
  passed   Build the shader compiler, Python tests, Shader compiler tests, DXBC tests,
           XG layout tests, Storage codec tests, D3D12 Windows typecheck

The regression controls ran outside their Bubblewrap/xvfb-run sandbox, which stalls on this machine (it has no Xvfb).

Checks

No evidence JSON changes.

<!-- greyfinch-sync:brcly/TuxBox:issue:5540605361 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/398). Originally posted by [MathiewMay](https://github.com/MathiewMay) on 2026-11-28T13:29:06Z. --- ## Summary A queue held on a fence label is released after five seconds (`STALL` in `runtime/d3d12/src/commands/memory_wait.rs`), for the case where the work that should have written the label was dropped. The release did not look at what the title was doing, and a title can submit the list that waits on a label well before the list that writes it. ProjectScarlett does: in each frame it records the lists that write a set of labels, submits compute lists that wait on those labels, and submits the writing lists with the rest of the frame. When a frame takes longer than five seconds, the compute lists are released and run before the work they wait for. On `a880dfd` its first frame that traces rays released four compute queues this way, while the stall report said "no submitted or rejected list writes it": the lists that write those labels were recorded and not submitted yet. A wait that old now holds while a write that satisfies it is still to run: - recorded in a list that no queue has taken yet, or - given to another queue, in a batch that has not run. What the waiting queue itself was given does not count: it has run already, or it is behind the wait and cannot run before the wait ends. A list that is reset, rejected or destroyed holds no queue, and neither do the lists of a batch its queue rejects or drops. A wait nothing is going to satisfy is released after five seconds, as before. The record is `commands/memory_wait/recorded_writes.rs`: each label write a list records, with its value, kept while the list's recording is alive and then until the batch it was submitted in has run. It is consulted only once a wait is five seconds old, and then every 100 ms. This does not use the in-flight writes that wait elision keeps (`has_in_flight_write`). Those hold ranges without values, any dispatch or draw makes a batch count as writing everything, and the waiting batch is itself in flight until its wait ends, so a wait would hold for itself. A title that records a write and never submits or resets that list now holds the waiting queue for good, where it was released after five seconds. A console holds it for good too. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: **NVIDIA still needs to run them.** Lanes scenario `cross-queue-late`: the direct queue records a label write, the compute queue submits a list that waits for it, and the direct list is submitted 6.5 s later. The compute queue must not have run by then. Against `main`'s provider it fails ("the compute queue ran before the direct queue wrote the label it waits on"). It adds 6.5 s to the Lanes run. Unit tests in `runtime/d3d12/src/tests/commands/recorded_writes.rs` cover the record: a recorded write holds until its list is gone, a submitted one until its batch has run, a write given to the waiting queue itself does not hold, and what has run or is gone is dropped. In ProjectScarlett, on `6f89916` together with other changes of mine: over six minutes of frames that took 12 to 30 s each, at least 32 waits were held past five seconds, each ended when its write ran, and none was released. That run ended after ten minutes on an assertion in the title's resource loading, which I have not traced to a cause yet; the device was not lost. GPU, driver and backend: AMD Radeon RX 9070 (1002:7550, RADV GFX1201), Mesa 26.2.7, Linux 7.3, GE-Proton11-14 (`--backend proton`). Commands run and their results: ```text cargo xwin test --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --lib (run under Proton) 245 passed, 0 failed python tuxbox.py verify --only lanes-selftest --backend proton --adapter 1002:7550 20 PASS, 0 FAIL (cross-queue-late: FAIL with main's d3d12_xs.dll in the same package) python tools/check_d3d12_regressions.py ... --adapter 1002:7550 (its 21 cases) 21 PASS, 0 FAIL python tuxbox.py check --no-gpu passed Build the shader compiler, Python tests, Shader compiler tests, DXBC tests, XG layout tests, Storage codec tests, D3D12 Windows typecheck ``` The regression controls ran outside their Bubblewrap/`xvfb-run` sandbox, which stalls on this machine (it has no Xvfb). ## Checks No evidence JSON changes.
NickStallman commented 2026-11-28 14:19:42 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-28T14:19:42Z.


Correction (29 Nov): this comparison is confounded, so please don't rely on it. During the run with #398 the desktop was locked, and the game presented about one frame per second (659 frames, 98% at about 1,000 ms). The earlier runs I compared it with were mostly unlocked. Fewer forced releases at one frame per second is not evidence that #398 removed them. "About 2 minutes in the world" was also wrong: the profile shows world-sized batches only in the last 10 s or so. The code argument for #398 stands.

An NVIDIA data point for this PR. ProjectScarlett on an RTX 5090 (620.70.10, GE-Proton11-14), with this PR's commit cherry-picked into our integration build. Same caches and settings as our earlier runs.

  • With this PR: the run logged no "released after 5s" for any memory wait, over about 2 minutes in the world.
  • Our previous six runs: they logged 1 to 9 such releases each, within about 25 s of the story load.
  • The pattern it fixes was in our last run without it: three compute queues were released while the direct list that writes their labels was recorded but not yet submitted. Then two of those queues stopped inside one CS_Prop_BatchCull dispatch until the device was lost.

The run still ended in a GPU timeout (Xid 109), but somewhere else: inside a single mesh ExecuteIndirect on the graphics queue, with group count (1,1,1). We're following that up on #232.

<!-- greyfinch-sync:brcly/TuxBox:comment:7240586789 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/398#issuecomment-7240586789). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-28T14:19:42Z. --- > **Correction (29 Nov):** this comparison is confounded, so please don't rely on it. During the run with #398 the desktop was locked, and the game presented about one frame per second (659 frames, 98% at about 1,000 ms). The earlier runs I compared it with were mostly unlocked. Fewer forced releases at one frame per second is not evidence that #398 removed them. "About 2 minutes in the world" was also wrong: the profile shows world-sized batches only in the last 10 s or so. The code argument for #398 stands. An NVIDIA data point for this PR. ProjectScarlett on an RTX 5090 (620.70.10, GE-Proton11-14), with this PR's commit cherry-picked into our integration build. Same caches and settings as our earlier runs. - **With this PR:** the run logged no "released after 5s" for any memory wait, over about 2 minutes in the world. - **Our previous six runs:** they logged 1 to 9 such releases each, within about 25 s of the story load. - **The pattern it fixes was in our last run without it:** three compute queues were released while the direct list that writes their labels was recorded but not yet submitted. Then two of those queues stopped inside one `CS_Prop_BatchCull` dispatch until the device was lost. The run still ended in a GPU timeout (Xid 109), but somewhere else: inside a single mesh `ExecuteIndirect` on the graphics queue, with group count (1,1,1). We're following that up on #232.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!398
No description provided.