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

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

@⁠mutlusinan on GitHub · 2026-11-27 20:11 UTC · original
mutlusinan:fix/swapchain-retry → main · +67 −11 · 1 files · 1 commits · open

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** on GitHub · 2026-11-27 20:11 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257) `mutlusinan:fix/swapchain-retry` → `main` · +67 −11 · 1 files · 1 commits · open ### 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.
When the desktop cannot present (a locked session, a display change in
progress), every presented frame tried once more to make or resize the swap
chain: a failed create or ResizeBuffers is expensive, and the warning is
logged for every frame, so an outage of a minute cost thousands of calls
and as many log lines.

`Presentation` keeps the swap chain and a `SwapChainRetry` next to it: a
failed attempt waits a second before the next, a success clears the wait,
and a frame that comes while waiting is dropped as before. The presenter's
creation now says which step failed (window, DXGI factory, swap chain, copy
list).

Ported from DexNom/VIctory f0967745, GPL-3.0.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 20:16:07 +00:00
Author
Owner

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

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.
**@⁠mutlusinan** on GitHub · 2026-11-27 20:21 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257#issuecomment-7227424494) ### 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`.
Author
Owner

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

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.

**@⁠1tsethan** on GitHub · 2026-11-27 23:00 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257#issuecomment-7229794121) 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 -->
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 #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).

**@⁠cloph-dsp** on GitHub · 2026-11-28 02:20 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/257#issuecomment-7232298125) 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).
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/257/head:github-bot/gh-257'
git switch 'github-bot/gh-257'

Merge

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