GPU: with VICTORY_FPS set, a present waits for the next frame's deadline #2746
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2746
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2746"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@kais7654 on GitHub · 2026-11-25 19:29 UTC · original
kais7654:display/present-pacing→main· +199 −0 · 4 files · 2 commits · openWhat
Adds an opt-in present pacer. When the environment variable
VICTORY_FPSis set to a value between 1 and 1000, the host'spresent()waits until the next frame's deadline before callingPresent(0, ...). Without the variable, nothing changes.Why
The title currently drives presentation with no way to cap the frame rate, so an uncapped run burns GPU/power for frames that are discarded by the compositor anyway. A present-side cap is the one place every frame goes through, it needs no title cooperation, and it helps with thermals, fan noise and frame-time consistency on laptops.
How
crates/victory-gpu/src/pace.rs(#![cfg(windows)]):Pacer::from_env()readsVICTORY_FPSand validates the range (1–1000; an invalid value falls back to no pacing).CreateWaitableTimerExWwithCREATE_WAITABLE_TIMER_HIGH_RESOLUTION), then spins over the last ~2 ms so the present lands close to the deadline without busy-waiting the whole interval.host.present(), which is where the frame boundary already is, so no new threads and no change to the frame pipeline.VICTORY_FPSnext to the other environment variables.Testing
pace.rs(period parsing/validation, deadline chain, late-present restart) pass.cargo clippy --workspace --all-targets --locked -- -D warningsclean (standard and--all-featuresvariants).cargo test -p victory-gpu: 196 passed; the 2 remaining failures are the known heap-cap pair from #1943 (NVIDIA-specific on this machine, unrelated to this diff).AI-assisted: implemented with Mistral Vibe.
@kotekompotek on GitHub · 2026-11-25 20:07 UTC · original
Solid pacing: the deadline chain restarts from now on a late frame (next.max(now)) so presents never burst to catch up, the first present doesn't wait, and the 2 ms spin tail after a high-res timer wait hits the deadline tightly. Clamping to 1..=1000 fps and warning on bad input is tidy. Waiting before Present(0) on the title's thread is exactly where this belongs.
@fuzeofficlal on GitHub · 2026-11-25 20:14 UTC · original
Reviewed and verified
1f32381f(merged cleanly ontomain13f91ca) on Windows 11 (RTX 5090 + WARP).Code review
VICTORY_FPSis unset or invalid,Pacerstoresperiod: Noneandwait()returns immediately without callingInstant::now()or creating a timer.period_ofrejects0, negative, non-integer, and> 1000values with a warning;next.max(Instant::now())prevents catch-up bursts after long stalls while keeping deadline spacing steady when frames arrive on time;Host::presentholds thepresentermutex so concurrent presents are serialized without blocking render queues.pace.rs:64-75fallback condition: WhenSetWaitableTimerfails (on == false),on && ...isfalse, so the fallbackstd::thread::sleep(left - SPIN)is skipped andwait()busy-spins through the entire remaining frame time. This should beif !on || WaitForSingleObject(...) == WAIT_FAILED.Verification (Windows 11, RTX 5090 + WARP)
--features diagnostics):pace::tests3/3 passed,draw::tests --test-threads=111/11 passed.VICTORY_D3D12_WARP=1,--features diagnostics --lib -- --test-threads=1): 201 passed, 0 failed, 1 ignored.cargo clippy -p victory-gpu --all-targets --locked -- -D warnings(default &--features diagnostics): 0 warnings;cargo xtask policy: 185 files ok; cleangit merge-treeagainst13f91caand#2752.@kais7654 on GitHub · 2026-11-25 20:27 UTC · original
@fuzeofficlal Fixed in
9d70ef7: the fallback condition now takes the disjunction —if !on || WaitForSingleObject(...) == WAIT_FAILED— so a failed arm ofSetWaitableTimersleeps the remaining interval instead of leaving the spin to cover the whole frame's rest.cargo clippy -p victory-gpu --all-targets --locked -- -D warningsclean (default and diagnostics), the pace tests pass. Thanks for the catch and the verification.AI-assisted (Mistral Vibe).
@fuzeofficlal on GitHub · 2026-11-25 20:28 UTC · original
Checked
9d70ef7a—if !on || WaitForSingleObject(...) == WAIT_FAILEDresolves the fallback condition cleanly. Looks good to me.@Marvisak on GitHub · 2026-11-25 23:25 UTC · original
Automated triage for the maintainers. This PR conflicts with current
mainincrates/victory-gpu/src/host.rs. It will be reviewed once it is rebased.Generated by Claude Code
@steven-seagull27 on GitHub · 2026-11-26 02:04 UTC · original
@kais7654 I resolved the two
Presenterconflicts against current main. Commit55b0a185has your exact9d70ef7aas first parent and63bcca43as second parent. It keeps both the pacer and the compositor, including the timer-arm fallback fix. To take it ondisplay/present-pacing:I tested the Windows present paths with a hidden swap chain on an RTX 5080, driver 621.40. A local fixture counted
Pacer::waitcalls and timestamped the start of each DXGIPresent. All 188 calls returnedS_OK, with exactly one pacer call each. This included single-plane copy, forced compositor failure with primary-plane fallback, and successful two-plane blending. The existing pixel checks passed on both compositor paths. Empty input returned before pacing.VICTORY_FPSEach median uses 40 steady-state intervals. I inserted a 120 ms sleep between frames; the late call proceeded and the next interval resumed at target. These are CPU call timestamps on Windows 26300.10075, independent of display scanout.
One timing distinction for the PR description: a late wake inside an already-started wait can shorten the next interval. The 120 FPS run included one 12.886 ms / 3.780 ms pair. In a separate controlled 60 FPS test I held the thread just after
sleep_untilreturned. A 9 ms hold produced 25.85 ms then 7.48 ms; a 40 ms hold produced 56.81 ms then 0.04 ms. The pacer schedules from the saved deadline, and the next call returns immediately if that deadline has already passed. This is separate from the between-frame stall above.The three stock pacing tests and warning-denied Clippy for
victory-gpu --all-targetspassed (default and diagnostics). The timing instrumentation stayed local. Tested with Codex assistance.@steven-seagull27 on GitHub · 2026-11-26 02:10 UTC · original
The PR specifies that a late present restarts the chain from that present. I put the late-wake correction in a separate optional commit,
09ccea0, directly on top of the conflict resolution. It schedules the next deadline one period after the wait actually returns. On-time wakes keep their cadence, and the first call still returns immediately.The new virtual-clock test fails with the original calculation: after a 9 ms overshoot at a 20 ms period, the following frame starts at 60 ms instead of 69 ms. It passes with the fix, including a 40 ms overshoot.
In the Windows 60 FPS timer fixture, the interval immediately following 9 ms / 40 ms injected wake delays was 16.67 ms in both cases, up from 7.48 ms / 0.04 ms. The RTX 5080 hidden swap chain still measured median intervals of 33.3335, 16.6668 and 8.3335 ms at 30, 60 and 120 FPS. All four pacing tests and Clippy (default and diagnostics) passed. The conflict-resolution commit alone is available separately.
To take both commits from
display/present-pacing:Tested locally with Codex assistance.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.