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

Closed
mutlusinan wants to merge 1 commit from upstream-pr/242 into main
mutlusinan commented 2026-11-27 20:04:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mutlusinan on 2026-11-27T20:04:23Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5532443675 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-27T20:04:23Z. --- ### 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.
mutlusinan commented 2026-11-27 20:21:25 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mutlusinan on 2026-11-27T20:21:25Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7227422631 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242#issuecomment-7227422631). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-27T20:21:25Z. --- ### 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`.
1tsethan commented 2026-11-27 23:00:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by 1tsethan on 2026-11-27T23:00:17Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7229792741 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242#issuecomment-7229792741). Originally posted by [1tsethan](https://github.com/1tsethan) on 2026-11-27T23:00:17Z. --- 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 -->
cloph-dsp commented 2026-11-28 02:20:38 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by cloph-dsp on 2026-11-28T02:20:38Z.


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).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232298383 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242#issuecomment-7232298383). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T02:20:38Z. --- 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).
trustno1-coder commented 2026-11-28 02:49:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T02:49:29Z.


Merged into main (8fc2254) and shipped in v2026.11.27.10. The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232617256 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/242#issuecomment-7232617256). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-28T02:49:29Z. --- Merged into main (8fc2254) and shipped in [v2026.11.27.10](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.27.10). The commit keeps you as its author, so it counts toward the contributors list. GitHub shows this as closed rather than merged only because the commits were applied on top of the newest main (new commit IDs). Thank you!

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!242
No description provided.