D3D12-GPU-AWAKE-FENCE-REMOVED-OVERFLOW: handle device-removed fence value and wrap event handle #2980

Open
bobcatchris wants to merge 1 commit from upstream-pr/2980 into main
bobcatchris commented 2026-12-01 22:20:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-12-01T22:20:44Z.


Summary

Claimed in the coordination issue as: D3D12-GPU-AWAKE-FENCE-REMOVED-OVERFLOW (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7325032752).

Fixes arithmetic overflow on ID3D12Fence::GetCompletedValue() == u64::MAX (D3D12 device removal) and event-handle leak on error/unwind in d3d12/crates/leonida-gpu/src/host/awake.rs:

  • Extracts fence_action(completed, value) which handles completed == u64::MAX explicitly (FenceAction::DeviceRemoved) and checks value >= 2 && value.saturating_sub(completed) >= 2 without overflow/wrapping.
  • On FenceAction::DeviceRemoved, queries device.GetDeviceRemovedReason() and breaks out of the keep-awake loop cleanly instead of waiting on INFINITE.
  • Guards the shutdown wait against completed == u64::MAX before calling SetEventOnCompletion / WaitForSingleObject(INFINITE).
  • Wraps the CreateEventW HANDLE in an RAII EventHandle with Drop so early ? returns or unwinds close the handle once.

Tests & Verification

  • Scope precision: In debug / overflow-checked builds, GetCompletedValue() + 2 panics on device removal (u64::MAX) and skips CloseHandle; in release builds (overflow-checks = false), u64::MAX + 2 wraps to 1 and takes the wait path before GetDeviceRemovedReason() ends the loop. fence_action and EventHandle handle both cleanly.
  • GPUs tested: AMD Radeon RX 7900 XTX 24 GB (author unit/device test, Windows 11); third-party verified on RTX 4060 (@MoonEyes in-game batch PASS), RTX 4070 SUPER & Radeon RADV (@merzleckeier Wine), and WARP (@Kal0s-design RemoveDevice()).
  • Hardware / OS: Windows 11, AMD Radeon RX 7900 XTX 24 GB (driver 32.0.32029.2010), Rust 1.98.1, no game files needed.
  • Red -> Green:
    • Reverting fence_action to completed + 2 <= value: host::awake::tests::fence_action_handles_device_removed_without_overflow FAILS (RED_EXIT=101, attempt to add with overflow).
    • With the fix: cargo test --locked -p leonida-gpu --lib -- host::awake::tests — 2 passed, 0 failed (including live D3D12 hardware test mapped_card_memory_is_written_by_the_cpu_and_read_by_the_card).
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: exit 0.
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/host/awake.rs: exit 0.

AI Assistance

AI-assisted: Gemini 4 Neon (including a separate read-only independent review pass, APPROVE).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5595639182 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-12-01T22:20:44Z. --- ## Summary Claimed in the coordination issue as: `D3D12-GPU-AWAKE-FENCE-REMOVED-OVERFLOW` (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7325032752). Fixes arithmetic overflow on `ID3D12Fence::GetCompletedValue() == u64::MAX` (D3D12 device removal) and event-handle leak on error/unwind in `d3d12/crates/leonida-gpu/src/host/awake.rs`: - Extracts `fence_action(completed, value)` which handles `completed == u64::MAX` explicitly (`FenceAction::DeviceRemoved`) and checks `value >= 2 && value.saturating_sub(completed) >= 2` without overflow/wrapping. - On `FenceAction::DeviceRemoved`, queries `device.GetDeviceRemovedReason()` and breaks out of the keep-awake loop cleanly instead of waiting on `INFINITE`. - Guards the shutdown wait against `completed == u64::MAX` before calling `SetEventOnCompletion` / `WaitForSingleObject(INFINITE)`. - Wraps the `CreateEventW` `HANDLE` in an RAII `EventHandle` with `Drop` so early `?` returns or unwinds close the handle once. ## Tests & Verification - **Scope precision**: In debug / overflow-checked builds, `GetCompletedValue() + 2` panics on device removal (`u64::MAX`) and skips `CloseHandle`; in release builds (`overflow-checks = false`), `u64::MAX + 2` wraps to `1` and takes the wait path before `GetDeviceRemovedReason()` ends the loop. `fence_action` and `EventHandle` handle both cleanly. - **GPUs tested**: AMD Radeon RX 7900 XTX 24 GB (author unit/device test, Windows 11); third-party verified on RTX 4060 (`@MoonEyes` in-game batch PASS), RTX 4070 SUPER & Radeon RADV (`@merzleckeier` Wine), and WARP (`@Kal0s-design` `RemoveDevice()`). - **Hardware / OS**: Windows 11, AMD Radeon RX 7900 XTX 24 GB (driver `32.0.32029.2010`), Rust 1.98.1, no game files needed. - **Red -> Green**: - Reverting `fence_action` to `completed + 2 <= value`: `host::awake::tests::fence_action_handles_device_removed_without_overflow` **FAILS** (`RED_EXIT=101`, `attempt to add with overflow`). - With the fix: `cargo test --locked -p leonida-gpu --lib -- host::awake::tests` — **2 passed, 0 failed** (including live D3D12 hardware test `mapped_card_memory_is_written_by_the_cpu_and_read_by_the_card`). - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md`: exit 0. - `python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/host/awake.rs`: exit 0. ## AI Assistance AI-assisted: Gemini 4 Neon (including a separate read-only independent review pass, APPROVE).
andrew-ai commented 2026-12-01 22:24:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-01T22:24:33Z.


Verified the new EventHandle destructor on native Windows at 12c14a999. I added a temporary test that created a separately named Win32 event for each exit path. OpenEventW found each event while the guard owned it, and the test closed its observer handle immediately. After a normal return, an early Result::Err, and a caught Rust unwind, opening the same name returned ERROR_FILE_NOT_FOUND in all three cases.

The two stock host::awake::tests also passed. This verifies kernel-object lifetime directly and covers the device-removal sentinel through the existing arithmetic test. No physical device removal was induced. Codex-assisted for #2570.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7327796516 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#issuecomment-7327796516). Originally posted by [andrew-ai](https://github.com/andrew-ai) on 2026-12-01T22:24:33Z. --- Verified the new EventHandle destructor on native Windows at 12c14a999. I added a temporary test that created a separately named Win32 event for each exit path. OpenEventW found each event while the guard owned it, and the test closed its observer handle immediately. After a normal return, an early Result::Err, and a caught Rust unwind, opening the same name returned ERROR_FILE_NOT_FOUND in all three cases. The two stock host::awake::tests also passed. This verifies kernel-object lifetime directly and covers the device-removal sentinel through the existing arithmetic test. No physical device removal was induced. Codex-assisted for #2570.
MoonEyes commented 2026-12-02 12:33:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T12:33:49Z.


This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).

Could you, or anyone with a working setup, post a run report on the current head merged onto current main:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone for comparison, if you can.

Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7345527061 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#issuecomment-7345527061). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T12:33:49Z. --- This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists). Could you, or anyone with a working setup, post a run report on the **current head** merged onto current `main`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone for comparison, if you can. Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough. AI-assisted (Claude Code).
Kal0s-design commented 2026-12-02 14:46:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-02T14:46:58Z.


Ran natively on Windows 11, head 12c14a999 merged into current main (2fc7383b9, clean merge), debug build, --locked.

Check Result
host::awake::tests 2 passed, 0 failed
cargo test -p leonida-gpu --lib 696 passed, 0 failed, 59 ignored
cargo clippy -p leonida-gpu --all-targets nothing in awake.rs; the one finding (unused mut in host.rs) is already on main

The earlier report here covered the event handle. This one covers the other half: a real device removal under a running keep-awake thread, which nobody had induced yet.

How: a throwaway test (not committed) creates its own device (hardware adapter, or WARP), starts start(&device, || true), lets it run 200 ms, calls ID3D12Device5::RemoveDevice(), and then polls the thread's JoinHandle::is_finished() for up to 5 s without setting the stop flag. A panic hook counts panics on the leonida-card-awake thread. One removal per process, so the shared test device is never touched. The same test ran against main's awake.rs and against this head. In all 200 runs a probe fence on the removed device read u64::MAX and GetDeviceRemovedReason returned 0x887A0005.

awake.rs Adapter Runs Awake thread panicked Ended by itself, median Still running after ~4.8 s
main hardware 80 2 (at awake.rs:207, the GetCompletedValue() + 2 line; a later rerun printed attempt to add with overflow there) 32 ms 4 (2 of them not finished at 5 s)
this head hardware 80 0 30 ms 5 (2 of them not finished at 5 s)
main WARP 20 0 122 ms 0
this head WARP 20 0 93 ms 0

What this shows:

  • The overflow is real, but the window is narrow: 2 of 80 on hardware, 0 of 20 on WARP. From the code, the other runs on main probably leave the loop through a different error first (Signal, SetEventOnCompletion, or GetDeviceRemovedReason after the wait), and only a removal that lands just before the comparison reaches the + 2. I did not instrument which path each run took. In a release build that line would wrap to 1 instead of panicking. Reading the code, main would then take the Wait branch and exit through GetDeviceRemovedReason, but I did not run that. With this head there was no panic in 100 runs. That is consistent with the fix but does not prove it on its own: at 2 in 80, getting zero in 80 runs by chance is plausible. The deterministic evidence is the new unit test.
  • The occasional ~5 s tail is not from this change. It shows up at about the same rate on main and on this head, and only on the hardware adapter. I did not find out where the thread waits in those runs. Other work was using the same card during these runs, so contention may be part of it.
  • The extra completed != u64::MAX guard on the shutdown wait is harmless but already implied: completed < value can never hold when completed == u64::MAX, so main could not hang there either.
  • Other GetCompletedValue() users on main either check for u64::MAX, use wrapping_add, or only compare (I read them; I did not run them under removal). One of them, replay/gpu.rs:45 (l.2 <= done), would treat every list as finished on a removed device. That is outside this PR.
  • fence_action gives the same answer as the old completed + 2 <= value for every non-overflowing input (value.saturating_sub(completed) >= 2). The new unit test covers the edges, including u64::MAX - 1.

Not checked: the --features diagnostics build and suite on this merge, an in-game run (the gate asked for above), a release build of the removal test, a real TDR or driver reset (only RemoveDevice), where the thread waits in the ~5 s tail.

GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7349129595 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#issuecomment-7349129595). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-02T14:46:58Z. --- Ran natively on Windows 11, head `12c14a999` merged into current `main` (`2fc7383b9`, clean merge), debug build, `--locked`. | Check | Result | |---|---| | `host::awake::tests` | 2 passed, 0 failed | | `cargo test -p leonida-gpu --lib` | 696 passed, 0 failed, 59 ignored | | `cargo clippy -p leonida-gpu --all-targets` | nothing in `awake.rs`; the one finding (`unused mut` in `host.rs`) is already on `main` | The earlier report here covered the event handle. This one covers the other half: a real device removal under a running keep-awake thread, which nobody had induced yet. **How:** a throwaway test (not committed) creates its own device (hardware adapter, or WARP), starts `start(&device, || true)`, lets it run 200 ms, calls `ID3D12Device5::RemoveDevice()`, and then polls the thread's `JoinHandle::is_finished()` for up to 5 s without setting the stop flag. A panic hook counts panics on the `leonida-card-awake` thread. One removal per process, so the shared test device is never touched. The same test ran against `main`'s `awake.rs` and against this head. In all 200 runs a probe fence on the removed device read `u64::MAX` and `GetDeviceRemovedReason` returned `0x887A0005`. | `awake.rs` | Adapter | Runs | Awake thread panicked | Ended by itself, median | Still running after ~4.8 s | |---|---|---|---|---|---| | `main` | hardware | 80 | **2** (at `awake.rs:207`, the `GetCompletedValue() + 2` line; a later rerun printed `attempt to add with overflow` there) | 32 ms | 4 (2 of them not finished at 5 s) | | this head | hardware | 80 | 0 | 30 ms | 5 (2 of them not finished at 5 s) | | `main` | WARP | 20 | 0 | 122 ms | 0 | | this head | WARP | 20 | 0 | 93 ms | 0 | What this shows: - The overflow is real, but the window is narrow: 2 of 80 on hardware, 0 of 20 on WARP. From the code, the other runs on `main` probably leave the loop through a different error first (`Signal`, `SetEventOnCompletion`, or `GetDeviceRemovedReason` after the wait), and only a removal that lands just before the comparison reaches the `+ 2`. I did not instrument which path each run took. In a release build that line would wrap to 1 instead of panicking. Reading the code, `main` would then take the `Wait` branch and exit through `GetDeviceRemovedReason`, but I did not run that. With this head there was no panic in 100 runs. That is consistent with the fix but does not prove it on its own: at 2 in 80, getting zero in 80 runs by chance is plausible. The deterministic evidence is the new unit test. - The occasional ~5 s tail is not from this change. It shows up at about the same rate on `main` and on this head, and only on the hardware adapter. I did not find out where the thread waits in those runs. Other work was using the same card during these runs, so contention may be part of it. - The extra `completed != u64::MAX` guard on the shutdown wait is harmless but already implied: `completed < value` can never hold when `completed == u64::MAX`, so `main` could not hang there either. - Other `GetCompletedValue()` users on `main` either check for `u64::MAX`, use `wrapping_add`, or only compare (I read them; I did not run them under removal). One of them, `replay/gpu.rs:45` (`l.2 <= done`), would treat every list as finished on a removed device. That is outside this PR. - `fence_action` gives the same answer as the old `completed + 2 <= value` for every non-overflowing input (`value.saturating_sub(completed) >= 2`). The new unit test covers the edges, including `u64::MAX - 1`. Not checked: the `--features diagnostics` build and suite on this merge, an in-game run (the gate asked for above), a release build of the removal test, a real TDR or driver reset (only `RemoveDevice`), where the thread waits in the ~5 s tail. GPUs tested: one NVIDIA desktop card + WARP. AI-assisted: yes (Claude Code).
merzleckeier commented 2026-12-02 15:06:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-02T15:06:50Z.

Review: COMMENTED


Independent Wine check of 12c14a99 on 43fc605e. Both stock host::awake::tests passed on AMD Radeon (RADV 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.4), through VKD3D-Proton on Wine 11.22.

I also called the actual keep-awake worker in a local test that required a D3D12 device and checked its return result. On both adapters the production loop handled ten work requests, took the normal stop path, and returned success. This checks that the worker got past initialization, which a successful spawn or mapped-buffer read by itself cannot establish. Device loss in this run was covered by the synthetic fence-value test. Fence contract

The head still merges cleanly onto 83046a71, whose intervening change is in play-nvidia.ps1, and a Git merge-tree check found no conflict with #3151. This was an isolated hardware smoke test using synthetic work. AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6153475519 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#pullrequestreview-6153475519). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-02T15:06:50Z. **Review:** COMMENTED --- Independent Wine check of `12c14a99` on `43fc605e`. Both stock `host::awake::tests` passed on AMD Radeon (RADV 26.3.1) and RTX 4070 SUPER (NVIDIA 620.73.4), through VKD3D-Proton on Wine 11.22. I also called the actual keep-awake worker in a local test that required a D3D12 device and checked its return result. On both adapters the production loop handled ten work requests, took the normal stop path, and returned success. This checks that the worker got past initialization, which a successful spawn or mapped-buffer read by itself cannot establish. Device loss in this run was covered by the synthetic fence-value test. [Fence contract](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12fence-getcompletedvalue) The head still merges cleanly onto `83046a71`, whose intervening change is in `play-nvidia.ps1`, and a Git merge-tree check found no conflict with #3151. This was an isolated hardware smoke test using synthetic work. AI-assisted with OpenAI Codex.
MoonEyes commented 2026-12-02 16:10:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T16:10:22Z.


RUN (in game, batch of five render-path pull requests), each head merged with git merge --no-ff onto main 3c106eb2f, in one build: #2993 ddc10507d, #2889 bc390c26f, #2851 cf8f7be78, #2980 12c14a999, #2994 fccce4485. RTX 4060 8 GB, driver 610.88, Windows 11. Series S, -Resolution 1080, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world.

What Result
Device lost / device removed 0
Exceptions, panics, hang watchdog, GPU stall, title suspended 0
Process alive at the end yes, stopped by the time limit
Rendered fps, last 240 s (48 samples) median 17.2, mean 17.3
Rendered fps, last 120 s median 17.3

For reference, the same machine and route rendered 13.3 to 16.7 fps today on main with single pull requests or other batches. These fps are a check that nothing fell over, not a measurement of a gain.

Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch. If one of these pull requests changes its head, this run no longer covers it.

Limits: one run; free system memory median 2.5 GB; arrival in the world was driven by keys and not checked on pictures.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7351549605 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#issuecomment-7351549605). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T16:10:22Z. --- RUN (in game, batch of five render-path pull requests), each head merged with `git merge --no-ff` onto main `3c106eb2f`, in one build: #2993 `ddc10507d`, #2889 `bc390c26f`, #2851 `cf8f7be78`, #2980 `12c14a999`, #2994 `fccce4485`. RTX 4060 8 GB, driver 610.88, Windows 11. Series S, `-Resolution 1080`, frame generation 2x, the same walking route as the other runs on this machine, 330 s after reaching the world. | What | Result | |---|---| | Device lost / device removed | 0 | | Exceptions, panics, hang watchdog, GPU stall, title suspended | 0 | | Process alive at the end | yes, stopped by the time limit | | Rendered fps, last 240 s (48 samples) | median 17.2, mean 17.3 | | Rendered fps, last 120 s | median 17.3 | For reference, the same machine and route rendered 13.3 to 16.7 fps today on main with single pull requests or other batches. These fps are a check that nothing fell over, not a measurement of a gain. Verdict: PASS for the in-game gate (300 s or more in the world, no device loss) for this batch. If one of these pull requests changes its head, this run no longer covers it. Limits: one run; free system memory median 2.5 GB; arrival in the world was driven by keys and not checked on pictures. AI-assisted (Claude Code).
MoonEyes commented 2026-12-02 18:12:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:12:24Z.


Reviewed #2980 (code review only, not built here: Windows-only). Correct, and covered by an in-game PASS at this head; one precision for the description.

Head 12c14a9991 (unchanged since 1 December)
Merge with main 45dc41f95c clean (git merge-tree); merge base 66c79286f6, 342 commits behind
Switches registry on the merge exit 0
Earlier checks on this head andrew-ai (Windows, destructor), Kal0s-design (merged onto 2fc7383b9), MoonEyes in-game PASS (2 December 16:10, batch of five)

Review of d3d12/crates/leonida-gpu/src/host/awake.rs

  • fence_action(completed, value): value >= 2 && value.saturating_sub(completed) >= 2 is the old completed + 2 <= value without the overflow, and completed == u64::MAX (what GetCompletedValue returns after device removal) now ends the loop with GetDeviceRemovedReason(). The final wait also skips SetEventOnCompletion when the device is gone. The unit test covers the boundaries, including u64::MAX - 1.
  • EventHandle closes the event on every exit path, including a panic or the new break; before, only the straight-line path reached CloseHandle. Good.
  • Precision: in release builds (d3d12/Cargo.toml sets no overflow-checks, so they are off for release, diag and play) u64::MAX + 2 wrapped to 1 and took the wait branch, then GetDeviceRemovedReason ended the loop, so the old behaviour was a panic only in debug or overflow-checked builds (a panic that also skipped CloseHandle). Saying so in the description would size the fix correctly; it does not change the verdict.
  • Process: no GPUs tested: line, and the AI line names no model.

Verdict: ready.

AI-assisted: Claude Opus 5.5 (Claude Code), review only.

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7354121202 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#issuecomment-7354121202). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:12:24Z. --- **Reviewed #2980 (code review only, not built here: Windows-only). Correct, and covered by an in-game PASS at this head; one precision for the description.** | | | |---|---| | Head | `12c14a9991` (unchanged since 1 December) | | Merge with `main` `45dc41f95c` | clean (`git merge-tree`); merge base `66c79286f6`, 342 commits behind | | Switches registry on the merge | exit 0 | | Earlier checks on this head | andrew-ai (Windows, destructor), Kal0s-design (merged onto `2fc7383b9`), MoonEyes in-game PASS (2 December 16:10, batch of five) | **Review of `d3d12/crates/leonida-gpu/src/host/awake.rs`** - `fence_action(completed, value)`: `value >= 2 && value.saturating_sub(completed) >= 2` is the old `completed + 2 <= value` without the overflow, and `completed == u64::MAX` (what `GetCompletedValue` returns after device removal) now ends the loop with `GetDeviceRemovedReason()`. The final wait also skips `SetEventOnCompletion` when the device is gone. The unit test covers the boundaries, including `u64::MAX - 1`. - `EventHandle` closes the event on every exit path, including a panic or the new `break`; before, only the straight-line path reached `CloseHandle`. Good. - Precision: in release builds (`d3d12/Cargo.toml` sets no `overflow-checks`, so they are off for `release`, `diag` and `play`) `u64::MAX + 2` wrapped to 1 and took the wait branch, then `GetDeviceRemovedReason` ended the loop, so the old behaviour was a panic only in debug or overflow-checked builds (a panic that also skipped `CloseHandle`). Saying so in the description would size the fix correctly; it does not change the verdict. - Process: no `GPUs tested:` line, and the AI line names no model. **Verdict: ready.** AI-assisted: Claude Opus 5.5 (Claude Code), review only. AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
bobcatchris commented 2026-12-02 21:02:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-12-02T21:02:27Z.


@MoonEyes Thank you for the review, and thank you @Kal0s-design, @andrew-ai, and @merzleckeier for the native RemoveDevice(), handle-lifetime, and Wine/VKD3D-Proton verifications.

  • Updated the PR description with the debug-panic vs release-wrap distinction, explicit GPUs tested: line, and Gemini 4 Neon AI disclosure.
  • Head 12c14a999 is left untouched so @MoonEyes's 16:10:22Z in-game batch PASS remains valid.

AI-assisted: Gemini 4 Neon

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7358701806 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#issuecomment-7358701806). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-12-02T21:02:27Z. --- @MoonEyes Thank you for the review, and thank you `@Kal0s-design`, `@andrew-ai`, and `@merzleckeier` for the native `RemoveDevice()`, handle-lifetime, and Wine/VKD3D-Proton verifications. - Updated the PR description with the debug-panic vs release-wrap distinction, explicit `GPUs tested:` line, and `Gemini 4 Neon` AI disclosure. - Head `12c14a999` is left untouched so `@MoonEyes`'s `16:10:22Z` in-game batch PASS remains valid. AI-assisted: Gemini 4 Neon
fiestorra commented 2026-12-03 04:21:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T04:21:27Z.


VERIFY-2980 — aplica limpio y toca un solo fichero sin test, con un título que promete dos cosas

git cherry-pick (sobre 516c9eaab)   1 file changed
título: D3D12-GPU-AWAKE-FENCE-REMOVED-OVERFLOW: handle device-removed fence value and wrap e…

Y no trae test. La suite de leonida-gpu da el número de main, o sea que el cambio no añade ninguna prueba.

Lo que el título dice que arregla son dos casos raros y peligrosos: un valor de fence que vale UINT64_MAX como «dispositivo retirado», y el desbordamiento circular del contador. Los dos son aritmética pura — y la aritmética pura es justo lo que un test puede probar sin GPU: darle el valor límite a la función que decide y ver qué devuelve.

Así que esto es un +N de código sin test en el único sitio donde un test cuesta dos líneas. No digo que el cambio esté mal — digo que el 99 % de los casos de un wrap son el 0 y el máximo, y esos se escriben en una tabla.

Lo que no verifiqué: el dispositivo retirado de verdad — eso necesita una GPU que se caiga, y no la tengo; lo que sí se puede verificar es la decisión, y no hay dónde.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7367549812 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2980#issuecomment-7367549812). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-03T04:21:27Z. --- ## VERIFY-2980 — aplica limpio y toca **un solo fichero sin test**, con un título que promete dos cosas ``` git cherry-pick (sobre 516c9eaab) 1 file changed título: D3D12-GPU-AWAKE-FENCE-REMOVED-OVERFLOW: handle device-removed fence value and wrap e… ``` **Y no trae test.** **La suite de `leonida-gpu` da el número de `main`**, **o sea que el cambio no añade ninguna prueba.** **Lo que el título dice que arregla son dos casos raros y peligrosos**: **un valor de *fence* que vale `UINT64_MAX` como «dispositivo retirado»**, **y el desbordamiento circular del contador.** **Los dos son aritmética pura** — **y la aritmética pura es justo lo que un test puede probar sin GPU**: **darle el valor límite a la función que decide y ver qué devuelve.** **Así que esto es un `+N` de código sin test en el único sitio donde un test cuesta dos líneas.** **No digo que el cambio esté mal** — **digo que el 99 % de los casos de un `wrap` son el 0 y el máximo, y esos se escriben en una tabla.** **Lo que no verifiqué**: **el dispositivo retirado de verdad** — **eso necesita una GPU que se caiga, y no la tengo**; **lo que sí se puede verificar es la decisión, y no hay dónde.**
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2980:upstream-pr/2980'
git switch 'upstream-pr/2980'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2980'
git switch 'upstream-pr/2980'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2980'
git switch 'upstream-pr/2980'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2980'
git switch 'main'
git merge --squash 'upstream-pr/2980'
git switch 'main'
git merge --ff-only 'upstream-pr/2980'
git switch 'main'
git merge 'upstream-pr/2980'
git push origin 'main'
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
ProjectLeonida/mandy!2980
No description provided.