fix(gpu): a background fence wait reports what went wrong instead of carrying on #242

Open
github-bot wants to merge 1 commit from github-bot/gh-242 into main AGit
Owner

@⁠mutlusinan on GitHub · 2026-11-27 20:04 UTC · original
mutlusinan:fix/fence-wait-checks → main · +48 −16 · 1 files · 1 commits · open

Problem

Two background threads wait on the host fence:

  • the late helper (late_helper), which settles flights once the card has run them;
  • the relay worker (relay_worker), which lands shader writes back into title memory.

Both used SetEventOnCompletion(target, event).is_ok() and ignored the result. If the call failed, the late helper went straight on to the landing step with nothing run — settling flights off a value the card never reached — and the relay slept 1 ms and retried in a loop.

A removed device was worse than either: GetCompletedValue returns u64::MAX, which compares greater than every target, so every wait returned immediately and every landable() check treated all flights as done while the card had run nothing.

Fix

fn fence_reached(completed: u64, target: u64) -> bool {
    completed != u64::MAX && completed >= target
}

unsafe fn wait_host_fence(fence: &ID3D12Fence, target: u64, event: HANDLE, context: &str)

checks the completion call, the wait's result and the fence value, and fails with a named context ("late helper", "relay") instead of carrying on. The relay also checks for completed == u64::MAX before landing anything.

Verification

  • cargo check -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked — clean.
  • New pure unit test host_fence_completion_rejects_removed_device (not run here: victory-gpu needs Windows to build).

Ported from DexNom/VIctory d036cea (pull request #1366), GPL-3.0.

**@⁠mutlusinan** on GitHub · 2026-11-27 20:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242) `mutlusinan:fix/fence-wait-checks` → `main` · +48 −16 · 1 files · 1 commits · open ### Problem Two background threads wait on the host fence: - the **late helper** (`late_helper`), which settles flights once the card has run them; - the **relay worker** (`relay_worker`), which lands shader writes back into title memory. Both used `SetEventOnCompletion(target, event).is_ok()` and ignored the result. If the call failed, the late helper went straight on to the landing step with nothing run — settling flights off a value the card never reached — and the relay slept 1 ms and retried in a loop. A removed device was worse than either: `GetCompletedValue` returns `u64::MAX`, which compares greater than every target, so every wait returned immediately and every `landable()` check treated all flights as done while the card had run nothing. ### Fix ```rust fn fence_reached(completed: u64, target: u64) -> bool { completed != u64::MAX && completed >= target } unsafe fn wait_host_fence(fence: &ID3D12Fence, target: u64, event: HANDLE, context: &str) ``` checks the completion call, the wait's result and the fence value, and fails with a named context (`"late helper"`, `"relay"`) instead of carrying on. The relay also checks for `completed == u64::MAX` before landing anything. ### Verification - `cargo check -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked` — clean. - New pure unit test `host_fence_completion_rejects_removed_device` (not run here: `victory-gpu` needs Windows to build). Ported from DexNom/VIctory `d036cea` (pull request #1366), GPL-3.0.
Two helper threads wait on the host fence with `SetEventOnCompletion` and
`WaitForSingleObject`. Both ignored a failed call: the late helper then went
straight to the landing step with nothing run, settling flights off a value
the card never reached, and the relay slept 1 ms and tried again. A removed
device was worse than either: `GetCompletedValue` answers `u64::MAX`, which
compares greater than every target, so every wait and every landing check
passed at once while the card had run nothing.

`wait_host_fence` checks the completion call, the wait's result and the
fence value, and fails with a named context; `fence_reached` treats
`u64::MAX` as "never reached". The relay's device-removal read is checked
too, before it lands anything.

Ported from DexNom/VIctory d036cea (pull request #1366), GPL-3.0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:09:57 +00:00
Author
Owner

@⁠mutlusinan on GitHub · 2026-11-27 20:21 UTC · original

Risk assessment (porting review)

  • Behavior change: a failed SetEventOnCompletion, a failed WaitForSingleObject, or a fence value of u64::MAX now ends the run through fail() (with the removal reason and the debug layer's message) instead of falling through to the landing step (late helper) or sleeping 1 ms and retrying (relay).
  • On device removal this is the right outcome. The case worth watching is a non-fatal wait failure — for example a handle closed during shutdown — which would now abort at exit instead of continuing.
  • The relay's landing step can no longer see unsent fences; fence_reached treats u64::MAX as "never reached".
  • Compatibility: merges cleanly and type-checks against main at e69e39c.
**@⁠mutlusinan** on GitHub · 2026-11-27 20:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242#issuecomment-7227422631) ### Risk assessment (porting review) - **Behavior change:** a failed `SetEventOnCompletion`, a failed `WaitForSingleObject`, or a fence value of `u64::MAX` now ends the run through `fail()` (with the removal reason and the debug layer's message) instead of falling through to the landing step (late helper) or sleeping 1 ms and retrying (relay). - On device removal this is the right outcome. The case worth watching is a non-fatal wait failure — for example a handle closed during shutdown — which would now abort at exit instead of continuing. - The relay's landing step can no longer see unsent fences; `fence_reached` treats `u64::MAX` as "never reached". - **Compatibility:** merges cleanly and type-checks against `main` at `e69e39c`.
Author
Owner

@⁠1tsethan on GitHub · 2026-11-27 23:00 UTC · original

Independent Windows validation of PR #242.

Tested commit: 671e25f9850abca01266bab096fed096b7fd0606.

cargo test --locked -p victory-gpu host_fence_completion_rejects -- --nocapture --test-threads=1

Exit: 0.

  • test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 455 filtered out; finished in 0.00s

Coverage here is the fence-completion predicate test, not fault injection into an actual native wait.

Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result.

**@⁠1tsethan** on GitHub · 2026-11-27 23:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242#issuecomment-7229792741) Independent Windows validation of PR #242. Tested commit: `671e25f9850abca01266bab096fed096b7fd0606`. `cargo test --locked -p victory-gpu host_fence_completion_rejects -- --nocapture --test-threads=1` Exit: **0**. - test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 455 filtered out; finished in 0.00s Coverage here is the fence-completion predicate test, not fault injection into an actual native wait. Independent verification with OpenAI Codex assistance. Windows 11 Pro build 26200; Rust 1.98.1 MSVC; Windows SDK libraries from Microsoft.Windows.SDK.CPP.x64 10.0.28000.2957. Test harness used an RTX 3070 Ti / AMD integrated-GPU host; adapter identity was not captured for every test. These are focused checks on the stated PR commit, not gameplay, FPS, or a merged-main integration result. <!-- victory-native-validation-20261128 -->
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-28 02:20 UTC · original

Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #242 at head 671e25f9850abca01266bab096fed096b7fd0606; the PR is a single commit on parent 0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3 (1 file, +48/-16 in crates/victory-gpu/src/host.rs). NOTE: the shallow local clone cannot compute git merge-base origin/main <pr> (returns empty), so the PR's actual single-commit parent was used as the base.
  • cargo test --locked -p victory-gpu --lib -- host::host_fence_completion_rejects_removed_device --exact --test-threads=1 --quiet → 1 passed, 0 failed, 455 filtered, exit 0.
  • git grep -F for the test name on the base returned no hits (test is new on this PR); git diff --check 0cef07e9 HEAD clean.
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain). Pre-existing compiler warnings only.
  • GPU/driver: N/A (CPU test, synthetic removed-device fence wait). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

**@⁠cloph-dsp** on GitHub · 2026-11-28 02:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242#issuecomment-7232298383) Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #242 at head `671e25f9850abca01266bab096fed096b7fd0606`; the PR is a single commit on parent `0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3` (1 file, +48/-16 in `crates/victory-gpu/src/host.rs`). NOTE: the shallow local clone cannot compute `git merge-base origin/main <pr>` (returns empty), so the PR's actual single-commit parent was used as the base. - `cargo test --locked -p victory-gpu --lib -- host::host_fence_completion_rejects_removed_device --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 455 filtered, exit 0. - `git grep -F` for the test name on the base returned no hits (test is new on this PR); `git diff --check 0cef07e9 HEAD` clean. - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally (no clippy component on this toolchain). Pre-existing compiler warnings only. - GPU/driver: N/A (CPU test, synthetic removed-device fence wait). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
This pull request can be merged automatically.
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 '+refs/pull/242/head:github-bot/gh-242'
git switch 'github-bot/gh-242'

Merge

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