fix(gpu): failed swap-chain creation and resize are retried once a second #257

Merged
mutlusinan merged 1 commit from upstream-pr/257 into main 2026-11-28 19:39:39 +00:00
mutlusinan commented 2026-11-27 20:11:44 +00:00 (Migrated from github.com)

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


Problem

When the desktop cannot present — a locked session, a display mode change in progress — every presented frame tried again to create the swap chain or ResizeBuffers. Each failure is expensive, and the warning was logged per frame: an outage lasting a minute cost thousands of DXGI calls and as many log lines.

Fix

Presentation { presenter, retry } replaces Mutex<Option<Presenter>>. SwapChainRetry::attempt(now, op):

  • runs the operation when now >= next_attempt, otherwise returns None (the frame is dropped, as it already was on failure);
  • schedules the next attempt one second after a failure;
  • clears the schedule on success.

Both the swap-chain creation and ResizeBuffers go through it. Presenter creation also reports which step failed (window, DXGI factory, swap chain, copy list), so a persistent failure is diagnosable from one warning.

Verification

  • cargo check -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked — clean.
  • cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked — no new warning in this code.
  • New pure unit test swap_chain_failures_retry_once_per_second_and_success_clears_the_wait: 120 failed attempts over two seconds at 60 Hz make exactly 2 calls; a success clears the wait and the next call goes straight through (not run here: victory-gpu needs Windows to build).

Ported from DexNom/VIctory f0967745, GPL-3.0.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5532524099 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-27T20:11:44Z. --- ### Problem When the desktop cannot present — a locked session, a display mode change in progress — every presented frame tried again to create the swap chain or `ResizeBuffers`. Each failure is expensive, and the warning was logged per frame: an outage lasting a minute cost thousands of DXGI calls and as many log lines. ### Fix `Presentation { presenter, retry }` replaces `Mutex<Option<Presenter>>`. `SwapChainRetry::attempt(now, op)`: - runs the operation when `now >= next_attempt`, otherwise returns `None` (the frame is dropped, as it already was on failure); - schedules the next attempt one second after a failure; - clears the schedule on success. Both the swap-chain creation and `ResizeBuffers` go through it. Presenter creation also reports which step failed (window, DXGI factory, swap chain, copy list), so a persistent failure is diagnosable from one warning. ### Verification - `cargo check -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked` — clean. - `cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-msvc --locked` — no new warning in this code. - New pure unit test `swap_chain_failures_retry_once_per_second_and_success_clears_the_wait`: 120 failed attempts over two seconds at 60 Hz make exactly 2 calls; a success clears the wait and the next call goes straight through (not run here: `victory-gpu` needs Windows to build). Ported from DexNom/VIctory `f0967745`, GPL-3.0.
mutlusinan commented 2026-11-27 20:21:32 +00:00 (Migrated from github.com)

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


Risk assessment (porting review)

  • Visible change: after a failed create or resize, nothing is attempted for one second (before: once per presented frame). Recovery is up to 1 s slower; a failure storm no longer costs a DXGI call and a warning per frame.
  • One SwapChainRetry gates both creation and resize, so a failed creation also spaces resize attempts; intended.
  • While waiting, present returns None, the same result a failed attempt gave before.
  • Presenter creation errors now name the failing step (window / DXGI factory / swap chain / copy list).
  • Compatibility: merges cleanly and type-checks against main at e69e39c.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7227424494 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257#issuecomment-7227424494). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-27T20:21:32Z. --- ### Risk assessment (porting review) - Visible change: after a failed create or resize, nothing is attempted for one second (before: once per presented frame). Recovery is up to 1 s slower; a failure storm no longer costs a DXGI call and a warning per frame. - One `SwapChainRetry` gates both creation and resize, so a failed creation also spaces resize attempts; intended. - While waiting, `present` returns `None`, the same result a failed attempt gave before. - Presenter creation errors now name the failing step (window / DXGI factory / swap chain / copy list). - **Compatibility:** merges cleanly and type-checks against `main` at `e69e39c`.
1tsethan commented 2026-11-27 23:00:23 +00:00 (Migrated from github.com)

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


Independent Windows validation of PR #257.

Tested commit: 76f787e0f2eb41ccf93ed43491494fc3801de3e1.

cargo test --locked -p victory-gpu swap_chain_failures_retry -- --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 retry timing regression, not a live display-lock or mode-change recovery run.

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:7229794121 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257#issuecomment-7229794121). Originally posted by [1tsethan](https://github.com/1tsethan) on 2026-11-27T23:00:23Z. --- Independent Windows validation of PR #257. Tested commit: `76f787e0f2eb41ccf93ed43491494fc3801de3e1`. `cargo test --locked -p victory-gpu swap_chain_failures_retry -- --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 retry timing regression, not a live display-lock or mode-change recovery run. 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:37 +00:00 (Migrated from github.com)

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


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

  • PR #257 at head 76f787e0f2eb41ccf93ed43491494fc3801de3e1; the PR is a single commit on parent 0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3 (1 file, +67/-11 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::tests::swap_chain_failures_retry_once_per_second_and_success_clears_the_wait --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 swap-chain failure sequence). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7232298125 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257#issuecomment-7232298125). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T02:20:37Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #257 at head `76f787e0f2eb41ccf93ed43491494fc3801de3e1`; the PR is a single commit on parent `0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3` (1 file, +67/-11 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::tests::swap_chain_failures_retry_once_per_second_and_success_clears_the_wait --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 swap-chain failure sequence). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
mutlusinan commented 2026-11-28 12:01:33 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mutlusinan on 2026-11-28T12:01:33Z.


Rebased onto current main (one conflict resolved)

Rebased onto 63b902f (force-with-lease). host.rs moved under this change, so the ResizeBuffers hunk conflicted: main now passes chain_flags(p.tearing) instead of DXGI_SWAP_CHAIN_FLAG(0). The resolution keeps main's flags and only wraps the call in retry.attempt(...); the retry logic is unchanged.

Re-verified: cargo check --workspace --target x86_64-pc-windows-msvc --locked clean, and cargo clippy -p victory-gpu --all-targets reports nothing in the new code.

The risk note above still holds. CI shows action_required (maintainer approval to run a fork's workflow).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7238940292 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257#issuecomment-7238940292). Originally posted by [mutlusinan](https://github.com/mutlusinan) on 2026-11-28T12:01:33Z. --- ### Rebased onto current `main` (one conflict resolved) Rebased onto `63b902f` (force-with-lease). `host.rs` moved under this change, so the `ResizeBuffers` hunk conflicted: `main` now passes `chain_flags(p.tearing)` instead of `DXGI_SWAP_CHAIN_FLAG(0)`. The resolution keeps `main`'s flags and only wraps the call in `retry.attempt(...)`; the retry logic is unchanged. Re-verified: `cargo check --workspace --target x86_64-pc-windows-msvc --locked` clean, and `cargo clippy -p victory-gpu --all-targets` reports nothing in the new code. The risk note above still holds. CI shows `action_required` (maintainer approval to run a fork's workflow).
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!257
No description provided.