d3d12: name the device-removed reason and log video memory when the device goes #3385

Code

Clone this repository

Checkout

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

git fetch -u origin "fix/crash-zero-guard:fix/crash-zero-guard"
git switch "fix/crash-zero-guard"
Open
leonida/mandy
MoonEyes wants to merge 1 commit from fix/crash-zero-guard into main

This pull request has changes conflicting with the target branch.

Merge manually to resolve the conflicts.

Conversation
Reviewers 0 approvals
  • No reviewers
Details

This pull request has changes conflicting with the target branch.

Merge manually to resolve the conflicts.

  • d3d12/crates/leonida-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Refs the 0x887A0005 reports (#2821, #3012, #3068, #3255, #3344).

What: fail() adds the DXGI name of the removal reason (removal_reason_name: REMOVED, HUNG, RESET, DRIVER_INTERNAL_ERROR, INVALID_CALL) after the system's text, which is in the player's language; log_removal_context adds one line with the system's video memory budget and use (card and shared) when the device is found removed.

Why: reports come with Turkish, Spanish and German texts and device-removed data; none; whether the card was over its budget is asked in several tickets and only the periodic memory line exists.

Tested: cargo test -p leonida-gpu --lib --locked: 730 passed, 0 failed, including a_removal_reason_is_named. On main the test does not compile (the function does not exist). Log text only, no behaviour change on the hot path (removal_reason_name is only used in fail(), the memory line only once in log_removal_context). check_no_game_data.py clean.

In-game run required: the memory line is written during a real device loss; it was not exercised.

AI-assisted: written by Claude Sonnet 5.5, reviewed read-only by a separate Claude Opus 5.5 judge (accepted). Notes from the review, not addressed here: the memory line is logged at info level; the two other places that detect the loss (draw.rs) do not name the reason.

🤖 Generated with Claude Code

Refs the 0x887A0005 reports (#2821, #3012, #3068, #3255, #3344). **What:** `fail()` adds the DXGI name of the removal reason (`removal_reason_name`: REMOVED, HUNG, RESET, DRIVER_INTERNAL_ERROR, INVALID_CALL) after the system's text, which is in the player's language; `log_removal_context` adds one line with the system's video memory budget and use (card and shared) when the device is found removed. **Why:** reports come with Turkish, Spanish and German texts and `device-removed data; none`; whether the card was over its budget is asked in several tickets and only the periodic memory line exists. **Tested:** `cargo test -p leonida-gpu --lib --locked`: 730 passed, 0 failed, including `a_removal_reason_is_named`. On main the test does not compile (the function does not exist). Log text only, no behaviour change on the hot path (`removal_reason_name` is only used in `fail()`, the memory line only once in `log_removal_context`). `check_no_game_data.py` clean. **In-game run required:** the memory line is written during a real device loss; it was not exercised. AI-assisted: written by Claude Sonnet 5.5, reviewed read-only by a separate Claude Opus 5.5 judge (accepted). Notes from the review, not addressed here: the memory line is logged at info level; the two other places that detect the loss (`draw.rs`) do not name the reason. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The system's text of 0x887A0005 is in the player's language and the log had no
video memory line at the loss. fail() now adds the DXGI name of the reason, and
log_removal_context adds the system's budget and use of the card's and the PC's
shared memory. Log text only.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
First-time contributor

Verified natively on Windows 11 (MSVC, no game files): python -I scripts/red_green.py against main (0043b8d33, PR head 1bc561dd1) — clean merge, 789/789 leonida-gpu tests passed on green (red does not build on base because the new tests reference removal_reason_name). AI-assisted: Gemini 4 Neon (Antigravity).

Verified natively on Windows 11 (MSVC, no game files): `python -I scripts/red_green.py` against `main` (`0043b8d33`, PR head `1bc561dd1`) — clean merge, **789/789** `leonida-gpu` tests passed on green (`red does not build` on base because the new tests reference `removal_reason_name`). AI-assisted: Gemini 4 Neon (Antigravity).
First-time contributor

In-game check of this change during a real device loss (it asks for one under "In-game run required"). AI-assisted: Claude Code (Claude Opus 5.5).

  • BUILD: main 4d9e4d05d + #3400 (404daa462) + this PR (1bc561dd1), merged cleanly; diagnostics,dlss,mimalloc.
  • MACHINE: NVIDIA GeForce RTX 3070 8 GB desktop, driver 621.47, Windows 11 Pro 26200, 16 GB RAM (fixed 24 GB page file), profile M.
  • RUN: gate run from a save with mods/gate_driver idle, Series S, -Dlss quality -NoFrameGen, LEONIDA_VRAM_MARGIN_MB=0 (the A arm of the #3400 A/B, so the same planning as main). Device lost at 588 s, 507 s in the world (exit 0x887A0005), after a 10.2 s gap with no frame presented.

What the two new lines gave:

  • The reason is named after the system's text (which is in Portuguese here): DXGI_ERROR_DEVICE_REMOVED, with its explanation. So on this card it is not HUNG, RESET or DRIVER_INTERNAL_ERROR.
  • The video memory line was written once when the device went: the card's own 7,454 MB in use against a 7,187 MB budget (267 MB over), and 5,381 MB in use of the 7,489 MB shared with the card. The periodic memory line 3 s before said the same, so the budget was crossed well before the loss, not at it.

Both lines read as intended in a non-English Windows. One thing from the review notes that I can confirm: the video memory line is at info level, so it shows with the gate's LEONIDA_LOG; a player's default log level would need to keep info for it to be seen.

In-game check of this change during a real device loss (it asks for one under "In-game run required"). AI-assisted: Claude Code (Claude Opus 5.5). - BUILD: `main` 4d9e4d05d + #3400 (404daa462) + this PR (1bc561dd1), merged cleanly; `diagnostics,dlss,mimalloc`. - MACHINE: NVIDIA GeForce RTX 3070 8 GB desktop, driver 621.47, Windows 11 Pro 26200, 16 GB RAM (fixed 24 GB page file), profile M. - RUN: gate run from a save with `mods/gate_driver` idle, Series S, `-Dlss quality -NoFrameGen`, `LEONIDA_VRAM_MARGIN_MB=0` (the A arm of the #3400 A/B, so the same planning as `main`). Device lost at 588 s, 507 s in the world (exit 0x887A0005), after a 10.2 s gap with no frame presented. What the two new lines gave: - The reason is named after the system's text (which is in Portuguese here): DXGI_ERROR_DEVICE_REMOVED, with its explanation. So on this card it is not HUNG, RESET or DRIVER_INTERNAL_ERROR. - The video memory line was written once when the device went: the card's own 7,454 MB in use against a 7,187 MB budget (267 MB over), and 5,381 MB in use of the 7,489 MB shared with the card. The periodic memory line 3 s before said the same, so the budget was crossed well before the loss, not at it. Both lines read as intended in a non-English Windows. One thing from the review notes that I can confirm: the video memory line is at info level, so it shows with the gate's `LEONIDA_LOG`; a player's default log level would need to keep info for it to be seen.
First-time contributor

Follow-up to my run above, now over four device losses in the #3400 A/B (same build: main 4d9e4d05d + #3400 + this PR). AI-assisted: Claude Code (Claude Opus 5.5).

  • The reason was named in all four (DXGI_ERROR_DEVICE_REMOVED each time).
  • The video memory line ("when the host device went") was written in three of the four. In the fourth the loss was first seen in leonida_gpu::draw while textures picked by index were made ready, as in two of the others, but the next report came from the host's "no host list for a state prelude" path, which names the reason through fail() without reaching log_removal_context, so neither the removal context nor the memory line was logged. That matches the review note in the description (other places that detect the loss do not go through it). READ IN CODE for the path: crates/leonida-gpu/src/host.rs log_removal_context is called only by whoever finds the device removed through it; MEASURED (n=4) for the counts.

So if the memory line is meant for every reported loss, the fail() path is one more place to call it from.

Follow-up to my run above, now over four device losses in the #3400 A/B (same build: `main` 4d9e4d05d + #3400 + this PR). AI-assisted: Claude Code (Claude Opus 5.5). - The reason was named in all four (DXGI_ERROR_DEVICE_REMOVED each time). - The video memory line ("when the host device went") was written in three of the four. In the fourth the loss was first seen in `leonida_gpu::draw` while textures picked by index were made ready, as in two of the others, but the next report came from the host's "no host list for a state prelude" path, which names the reason through `fail()` without reaching `log_removal_context`, so neither the removal context nor the memory line was logged. That matches the review note in the description (other places that detect the loss do not go through it). READ IN CODE for the path: `crates/leonida-gpu/src/host.rs` `log_removal_context` is called only by whoever finds the device removed through it; MEASURED (n=4) for the counts. So if the memory line is meant for every reported loss, the `fail()` path is one more place to call it from.
Collaborator

Naming the reason by DXGI code is the right fix for reports written in other languages, and log_video_memory(when) exists with that shape. One small point: 0x887A0001 (INVALID_CALL) is mapped too, and it is not a removal; if GetDeviceRemovedReason ever returns it the log will blame a removal call. Harmless, but you may want to drop it from the list.

Naming the reason by DXGI code is the right fix for reports written in other languages, and `log_video_memory(when)` exists with that shape. One small point: 0x887A0001 (INVALID_CALL) is mapped too, and it is not a removal; if `GetDeviceRemovedReason` ever returns it the log will blame a removal call. Harmless, but you may want to drop it from the list.
Sign in to join this conversation.
No description provided.