GPU: reject the device-removal fence sentinel before reaping #249

Open
github-bot wants to merge 2 commits from github-bot/gh-249 into main AGit
Owner

@⁠loyodea on GitHub · 2026-11-26 12:40 UTC · original
loyodea:victory-device-removal-context → main · +101 −9 · 1 files · 2 commits · open

Related to #98. D3D12 reports UINT64_MAX from GetCompletedValue when a device is removed. Treat that value as removal before retiring asynchronous work, copying back resources, or reporting completion. Preserve pending command lists for the existing failure reporter and release the submission and queue locks before diagnostics.

Tested

  • The synthetic test distinguishes the removal sentinel from ordinary fence values. The Windows GNU default test build and diagnostics-enabled test compile passed.
  • The serial victory-gpu library suite reported 113 passed, one failed, and four ignored. Clean main 4f62c2a failed the same write-watch assertion.

The test does not induce real device removal. Arc B580 runtime behavior and the cause of #98 remain unverified. #232 edits the same async completion logic and will require rebasing whichever PR lands second. Codex helped implement and test this patch.

**@⁠loyodea** on GitHub · 2026-11-26 12:40 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/249) `loyodea:victory-device-removal-context` → `main` · +101 −9 · 1 files · 2 commits · open Related to #98. D3D12 reports UINT64_MAX from GetCompletedValue when a device is removed. Treat that value as removal before retiring asynchronous work, copying back resources, or reporting completion. Preserve pending command lists for the existing failure reporter and release the submission and queue locks before diagnostics. **Tested** - The synthetic test distinguishes the removal sentinel from ordinary fence values. The Windows GNU default test build and diagnostics-enabled test compile passed. - The serial victory-gpu library suite reported 113 passed, one failed, and four ignored. Clean main 4f62c2a failed the same write-watch assertion. The test does not induce real device removal. Arc B580 runtime behavior and the cause of #98 remain unverified. #232 edits the same async completion logic and will require rebasing whichever PR lands second. Codex helped implement and test this patch.
Do not treat the D3D12 removal sentinel as successful asynchronous GPU completion. Keep pending lists for the existing crash reporter and release the submission and queue locks before diagnostics. Related to #98.

Co-authored-by: Codex <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 12:40:47 +00:00
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:23 UTC · original · reviewed

AI-assisted review. I inspected the fence-removal handling and its unit test statically; I did not run tests or a GPU/game build. This review suggests one focused test seam for the failure path.

**@⁠gut0to** on GitHub · 2026-11-26 16:23 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/249#pullrequestreview-6077493970) · **reviewed** AI-assisted review. I inspected the fence-removal handling and its unit test statically; I did not run tests or a GPU/game build. This review suggests one focused test seam for the failure path.
@ -1137,2 +1147,3 @@
fn reap_completed(&self) -> Result<(), DeviceRemoved> {
// SAFETY: a plain fence query.
let completed = unsafe { self.fence.GetCompletedValue() };
let completed = completed_fence_value(unsafe { self.fence.GetCompletedValue() })?;
Author
Owner

@⁠gut0to on GitHub · 2026-11-26 16:23 UTC · original

AI-assisted review; I did not run tests. Could the sentinel test exercise the reap_completed decision through an injectable completed-value seam, and assert a pending submission remains queued and is not marked finished? The current test proves only that the conversion helper recognizes u64::MAX; it would not catch a caller bypassing that helper or retiring in-flight work before reporting device removal.

**@⁠gut0to** on GitHub · 2026-11-26 16:23 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/249#discussion_r4711059811) AI-assisted review; I did not run tests. Could the sentinel test exercise the `reap_completed` decision through an injectable completed-value seam, and assert a pending submission remains queued and is not marked finished? The current test proves only that the conversion helper recognizes `u64::MAX`; it would not catch a caller bypassing that helper or retiring in-flight work before reporting device removal.
@ -1137,2 +1147,3 @@
fn reap_completed(&self) -> Result<(), DeviceRemoved> {
// SAFETY: a plain fence query.
let completed = unsafe { self.fence.GetCompletedValue() };
let completed = completed_fence_value(unsafe { self.fence.GetCompletedValue() })?;
Author
Owner

@⁠loyodea on GitHub · 2026-11-26 18:53 UTC · original

Agreed. The current test covers sentinel conversion in isolation. Injecting u64::MAX at the fence read used by the reaper would let a test check DeviceRemoved, verify that the pending submission and its list stay queued, and confirm that neither the deferred write nor the finished-fence value changes.

**@⁠loyodea** on GitHub · 2026-11-26 18:53 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/249#discussion_r4712405707) Agreed. The current test covers sentinel conversion in isolation. Injecting `u64::MAX` at the fence read used by the reaper would let a test check `DeviceRemoved`, verify that the pending submission and its list stay queued, and confirm that neither the deferred write nor the finished-fence value changes.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 21:43 UTC · original

Tested on Windows 11 26300 with an RX 7900 XT (driver 32.0.32029.2010) and with WARP. Head 9bc5f30, base 4f62c2a.

On the test seam asked for in the review: a real device removal can test this without a seam. I wrote a local-only test (not committed) that does the following:

  • Builds a Host from a WARP device or from the 7900 XT (Host::from_device).
  • Signals fence 6 and pushes one InFlight entry at fence 7 (finish: None).
  • Calls ID3D12Device5::RemoveDevice.
  • Calls wait_fence(7) or execute(&[]). on_failure is set to a function that panics, and the call is wrapped in catch_unwind.

The results are the same on WARP and on the 7900 XT:

  • After RemoveDevice, fence.GetCompletedValue() returns u64::MAX, as reported on #214.
  • Base, wait_fence(7): returns with no report. The entry is reaped and FINISHED_FENCE goes to 7.
  • Base, execute(&[]): the entry is reaped too. The run then fails with device removed after a submission of 0 lists.
  • PR, both calls: the run fails with device removed while waiting for asynchronous submissions. The entry stays in in_flight and FINISHED_FENCE does not move.

Notes if this goes into the PR:

  • ON_FAILURE is a process-wide OnceLock and FINISHED_FENCE is global. On base, when both cases run in one process, the second wait_fence(7) returns early because FINISHED_FENCE is already 7. Run the test alone (--exact), or use fence values that no other test reaches.
  • fail() reads the removal reason from the global host(), not from the test's host. So in the test, the message has no device removed: part.

Coverage:

  • reap_completed has two callers, wait_fence and drain_in_flight_locked. The PR handles both.
  • wait_in_flight, present, present_over, HostList::reset, HostList::drop and the timeline waits all go through wait_fence.

Test suite (cargo test -p victory-gpu --lib, base and PR runs alternated, other heavy jobs running on the machine):

  • Default features: 13 runs on each side. --features diagnostics with VICTORY_D3D12_WARP=1: 41 runs on each side. The new unit test passed in every PR run.
  • The frame, watch, pipeline::library and query flakes failed on both sides. One queue test (page_mappings_run_after_a_queues_wait) failed once, on the PR side only.
  • The diagnostics binary also crashed without a summary on both sides (base 2 times, PR 3 times).
  • PR diagnostics run 29 had 10 other WARP failures (for example host refused the depth bounds pipeline) and then crashed. Run 30 had one depth bounds failure. None of these came back in the next 11 PR runs. The changed code does not run in test builds, because async submission is off under cfg(test).
  • cargo clippy -p victory-gpu --lib --tests gives the same warnings on base and PR.

Not tested: a real hang or page fault, DRED output with real pending lists, the game, an Arc B580.

**@⁠adrianmjim** on GitHub · 2026-11-26 21:43 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/249#issuecomment-7203998363) Tested on Windows 11 26300 with an RX 7900 XT (driver 32.0.32029.2010) and with WARP. Head 9bc5f30, base 4f62c2a. On the test seam asked for in the review: a real device removal can test this without a seam. I wrote a local-only test (not committed) that does the following: - Builds a `Host` from a WARP device or from the 7900 XT (`Host::from_device`). - Signals fence 6 and pushes one `InFlight` entry at fence 7 (`finish: None`). - Calls `ID3D12Device5::RemoveDevice`. - Calls `wait_fence(7)` or `execute(&[])`. `on_failure` is set to a function that panics, and the call is wrapped in `catch_unwind`. The results are the same on WARP and on the 7900 XT: - After `RemoveDevice`, `fence.GetCompletedValue()` returns `u64::MAX`, as reported on #214. - Base, `wait_fence(7)`: returns with no report. The entry is reaped and `FINISHED_FENCE` goes to 7. - Base, `execute(&[])`: the entry is reaped too. The run then fails with `device removed after a submission of 0 lists`. - PR, both calls: the run fails with `device removed while waiting for asynchronous submissions`. The entry stays in `in_flight` and `FINISHED_FENCE` does not move. Notes if this goes into the PR: - `ON_FAILURE` is a process-wide `OnceLock` and `FINISHED_FENCE` is global. On base, when both cases run in one process, the second `wait_fence(7)` returns early because `FINISHED_FENCE` is already 7. Run the test alone (`--exact`), or use fence values that no other test reaches. - `fail()` reads the removal reason from the global `host()`, not from the test's host. So in the test, the message has no `device removed:` part. Coverage: - `reap_completed` has two callers, `wait_fence` and `drain_in_flight_locked`. The PR handles both. - `wait_in_flight`, `present`, `present_over`, `HostList::reset`, `HostList::drop` and the timeline waits all go through `wait_fence`. Test suite (`cargo test -p victory-gpu --lib`, base and PR runs alternated, other heavy jobs running on the machine): - Default features: 13 runs on each side. `--features diagnostics` with `VICTORY_D3D12_WARP=1`: 41 runs on each side. The new unit test passed in every PR run. - The frame, watch, pipeline::library and query flakes failed on both sides. One queue test (`page_mappings_run_after_a_queues_wait`) failed once, on the PR side only. - The diagnostics binary also crashed without a summary on both sides (base 2 times, PR 3 times). - PR diagnostics run 29 had 10 other WARP failures (for example `host refused the depth bounds pipeline`) and then crashed. Run 30 had one depth bounds failure. None of these came back in the next 11 PR runs. The changed code does not run in test builds, because async submission is off under `cfg(test)`. - `cargo clippy -p victory-gpu --lib --tests` gives the same warnings on base and PR. Not tested: a real hang or page fault, DRED output with real pending lists, the game, an Arc B580.
This pull request can be merged automatically.
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 '+refs/pull/249/head:github-bot/gh-249'
git switch 'github-bot/gh-249'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-249'
git switch 'github-bot/gh-249'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-249'
git switch 'github-bot/gh-249'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-249'
git switch 'main'
git merge --squash 'github-bot/gh-249'
git switch 'main'
git merge --ff-only 'github-bot/gh-249'
git switch 'main'
git merge 'github-bot/gh-249'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.