d3d12: other threads wait for the device-loss report before ending the run #3402

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u origin "fix/removed-report-wait:fix/removed-report-wait"
git switch "fix/removed-report-wait"
Open
leonida/mandy
MoonEyes wants to merge 1 commit from fix/removed-report-wait into main

This branch is out-of-date with the base branch

Conversation
Reviewers 0 approvals
  • No reviewers
Details
This pull request is blocked because it's outdated.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'fix/removed-report-wait:fix/removed-report-wait'
git switch 'fix/removed-report-wait'
Member

Change

When the host device is removed, the first thread that sees it writes the report (log_removal_context in d3d12/crates/leonida-gpu/src/host.rs: "when the host device went: ..." and "device-removed data ..."). Until now a second thread that saw the loss returned at once, and could end the process through fail() before the first thread had written the report. That fits the many 0x887A0005 logs that end with "device-removed data; none" or with no report at all.

The other threads now wait for the report, with a limit: LEONIDA_REMOVAL_WAIT_MS (3000 by default, as Darner; 0 means no wait; at most 60000). The limit covers the case where the writer waits for a lock the waiting thread holds. Nothing changes while the device lives, and nothing changes when no report is written (no DRED, no trail).

The logic is a small ReportOnce type (one thread writes, the others wait a bounded time) so it can be tested without a card. switches.md regenerated (one new line), a note in findings.md.

Credit

Taken from tyr0nsur/Darner commit 6520fb2 (PerchShorthair's patch). Darner is GPL-3.0-or-later like this repository. There, 5 of 13 device losses on an RTX 3090 had no report before the fix.

Tests

  • cargo test -p leonida-gpu --locked: 731 passed, 0 failed, 59 ignored (Windows 11).
  • New unit tests host::report_once_tests: a second thread waits until the first has written the report; a writer that never finishes holds the others up only for the limit.
  • python -I tests/test_d3d12_switches.py: OK. python -I scripts/check_no_game_data.py on the touched files: clean.
  • The game was not run.

In-game run required

Cause a device loss, or wait for one, with LEONIDA_D3D12_DRED on, and check that the log holds the "when the host device went" and "device-removed data" lines before the process ends. Better still: compare how many 0x887A0005 reports come with a report before and after.

AI-assisted: written by Claude Opus 5.5 (claude-opus-5-5) in Claude Code. Independent review: pending (a separate reviewer will post its verdict here).

🤖 Generated with Claude Code

### Change When the host device is removed, the first thread that sees it writes the report (`log_removal_context` in `d3d12/crates/leonida-gpu/src/host.rs`: "when the host device went: ..." and "device-removed data ..."). Until now a second thread that saw the loss returned at once, and could end the process through `fail()` before the first thread had written the report. That fits the many 0x887A0005 logs that end with "device-removed data; none" or with no report at all. The other threads now wait for the report, with a limit: `LEONIDA_REMOVAL_WAIT_MS` (3000 by default, as Darner; 0 means no wait; at most 60000). The limit covers the case where the writer waits for a lock the waiting thread holds. Nothing changes while the device lives, and nothing changes when no report is written (no DRED, no trail). The logic is a small `ReportOnce` type (one thread writes, the others wait a bounded time) so it can be tested without a card. `switches.md` regenerated (one new line), a note in `findings.md`. ### Credit Taken from tyr0nsur/Darner commit `6520fb2` (PerchShorthair's patch). Darner is GPL-3.0-or-later like this repository. There, 5 of 13 device losses on an RTX 3090 had no report before the fix. ### Tests - `cargo test -p leonida-gpu --locked`: 731 passed, 0 failed, 59 ignored (Windows 11). - New unit tests `host::report_once_tests`: a second thread waits until the first has written the report; a writer that never finishes holds the others up only for the limit. - `python -I tests/test_d3d12_switches.py`: OK. `python -I scripts/check_no_game_data.py` on the touched files: clean. - The game was not run. ### In-game run required Cause a device loss, or wait for one, with `LEONIDA_D3D12_DRED` on, and check that the log holds the "when the host device went" and "device-removed data" lines before the process ends. Better still: compare how many 0x887A0005 reports come with a report before and after. AI-assisted: written by Claude Opus 5.5 (claude-opus-5-5) in Claude Code. Independent review: pending (a separate reviewer will post its verdict here). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
When the host device is removed, the first thread that sees it writes the
report (log_removal_context). A second thread that saw it too returned at
once and could end the process through fail() before the report reached
the log, which fits the many 0x887A0005 logs ending in "device-removed data;
none" or with no report at all.

The other threads now wait for the report, bounded: LEONIDA_REMOVAL_WAIT_MS
(3000 by default, 0 for none, at most 60000). Nothing changes while the
device lives, or when no report is written (no DRED, no trail).

Taken from tyr0nsur/Darner 6520fb2 (PerchShorthair's patch; GPL-3.0-or-later
like this repository): 5 of 13 losses on an RTX 3090 had no report there.
Unit tests: host::report_once_tests. AI-assisted (Claude Opus 5.5).

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

Independent code review (separate read-only reviewer, Claude Opus 5.5): ACCEPT for the code; the in-game run is still required before merging.

  • Clean merge with main; test_d3d12_switches.py 22 OK on the branch; check_no_game_data.py clean.
  • No-loss path stays free: the 4 calls of log_removal_context only run after a device loss (draw.rs:2392, draw.rs:4732, host.rs:1525), behind the existing trail/DRED filter (host.rs:1069).
  • No new deadlock: the wait is always bounded (ReportOnce::write_or_wait, host.rs:1121-1135); the writer's locks (TRAIL, GPU_RANGES, LIST_NOTES) never call back into fail().
  • Faithful to Darner 6520fb2, credit present.
  • Minor: if write() panics, done never becomes true, so the others wait the full limit (a Drop guard would fix it); a worker taken out of land::each_view can be held up to 3 s on the crash path; update the findings note after the run.
Independent code review (separate read-only reviewer, Claude Opus 5.5): **ACCEPT** for the code; the in-game run is still required before merging. - Clean merge with main; `test_d3d12_switches.py` 22 OK on the branch; `check_no_game_data.py` clean. - No-loss path stays free: the 4 calls of `log_removal_context` only run after a device loss (`draw.rs:2392`, `draw.rs:4732`, `host.rs:1525`), behind the existing trail/DRED filter (`host.rs:1069`). - No new deadlock: the wait is always bounded (`ReportOnce::write_or_wait`, `host.rs:1121-1135`); the writer's locks (`TRAIL`, `GPU_RANGES`, `LIST_NOTES`) never call back into `fail()`. - Faithful to Darner `6520fb2`, credit present. - Minor: if `write()` panics, `done` never becomes true, so the others wait the full limit (a `Drop` guard would fix it); a worker taken out of `land::each_view` can be held up to 3 s on the crash path; update the findings note after the run.
First-time contributor

RUN — In-game & Test Gate (NVIDIA RTX 5070 12 GB, Windows 11)

Tested PR head 191c904f83 merged cleanly onto main (30c683055), diagnostic release build (-SeriesS, no frame generation, 315 s automated run from the same save), compared against main (30c683055):

Metric main (30c683055) PR #3402 (191c904f83)
World samples (>=1000 draws) 36 (max_draws=5187) 38 (max_draws=5290)
Median FPS / frame time 23.0 fps (43.5 ms) 23.6 fps (42.3 ms)
Slowest 10% / fastest 10% 13.7 / 25.0 fps 15.9 / 25.4 fps
3000-4999 draws/frame median 23.2 fps (28 samples) 24.1 fps (28 samples)
Errors / warnings / device lost 0 / 0 / 0 0 / 0 / 0

Unit & Repo Checks

  • cargo test -p leonida-gpu --lib --locked report_once — 2/2 PASS (a_second_thread_waits_for_the_report, the_wait_runs_out)
  • cargo test -p leonida-gpu --lib --locked removal — 2/2 PASS
  • cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings — 0 warnings
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md — PASS
  • python -I scripts/check_no_game_data.py — PASS

Verdict

PASS — clean merge onto 30c683055, all unit/clippy/switch checks pass, and the 315 s in-game run completed with zero errors and no FPS regression. Ready for merge.

AI-assisted: yes

### RUN — In-game & Test Gate (NVIDIA RTX 5070 12 GB, Windows 11) Tested PR head `191c904f83` merged cleanly onto `main` (`30c683055`), diagnostic release build (`-SeriesS`, no frame generation, 315 s automated run from the same save), compared against `main` (`30c683055`): | Metric | `main` (`30c683055`) | PR `#3402` (`191c904f83`) | | --- | --- | --- | | World samples (`>=1000` draws) | `36` (`max_draws=5187`) | `38` (`max_draws=5290`) | | Median FPS / frame time | `23.0 fps` (`43.5 ms`) | `23.6 fps` (`42.3 ms`) | | Slowest 10% / fastest 10% | `13.7` / `25.0 fps` | `15.9` / `25.4 fps` | | `3000-4999` draws/frame median | `23.2 fps` (`28` samples) | `24.1 fps` (`28` samples) | | Errors / warnings / device lost | `0` / `0` / `0` | `0` / `0` / `0` | ### Unit & Repo Checks - `cargo test -p leonida-gpu --lib --locked report_once` — `2/2` PASS (`a_second_thread_waits_for_the_report`, `the_wait_runs_out`) - `cargo test -p leonida-gpu --lib --locked removal` — `2/2` PASS - `cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings` — `0` warnings - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md` — PASS - `python -I scripts/check_no_game_data.py` — PASS ### Verdict **PASS** — clean merge onto `30c683055`, all unit/clippy/switch checks pass, and the 315 s in-game run completed with zero errors and no FPS regression. Ready for merge. AI-assisted: yes
Sign in to join this conversation.
No description provided.