Skip to content

GPU & CLI: configurable/uncapped FPS limit, high-res pacing, high-refresh modes, and tearing swapchain - #250

Open
wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/configurable-fps-limit
Open

wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/configurable-fps-limit

Conversation

@wbkepler

Copy link
Copy Markdown
Contributor

Summary

Makes console frame pacing configurable (including uncapped) and upgrades host presentation for high-refresh displays:

  • Config & CLI (victory-core, victory.example.toml, apps/victory):
    • Adds optional [graphics] section (fps_limit, allow_tearing) with #[serde(default)] to FileConfig (victory.example.toml updated).
    • Adds --fps <N> CLI flag on victory run (0 = uncapped) and VICTORY_FPS_LIMIT / VICTORY_ALLOW_TEARING env overrides (precedence: --fps > env > victory.toml > title default).
  • Frame pacing (victory-gpu/src/frame.rs):
    • Exposes frame::set_fps_limit(Option<u32>) overriding SetFrameIntervalX (Some(0) returns immediately while advancing tokens/ticks; Some(n) sets round(1_000_000 / n) us logged once at info!).
    • Replaces coarse thread::sleep with a thread-local Windows high-resolution waitable timer (CREATE_WAITABLE_TIMER_HIGH_RESOLUTION) plus 500 us spin tail (with thread::sleep fallback).
    • Tracks monotonic FrameStats via frame::stats() while keeping the COM statistics entry point safe.
  • High-refresh DXGI modes & tearing swapchain (dxgi.rs, host.rs):
    • Advertises 4K progressive modes at 60/120/144/240 Hz (plus host display refresh if distinct) in dxgi.rs with DXGI MORE_DATA semantics.
    • Upgrades host.rs flip-model swapchain to 3 buffers and probes IDXGIFactory5::CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING), passing ALLOW_TEARING on creation, ResizeBuffers, and Present(0, flags) with automatic fallback to Present(0, 0).
  • Adds unit tests across victory-core (10/10) and victory-gpu (45/45).

Verification

  • cargo clippy --workspace --all-targets — passed (zero new warnings)
  • cargo clippy -p victory --features diagnostics --all-targets — passed
  • cargo test --workspace — passed
  • cargo xtask policy — passed (151 files ok)

@GamingRipperDoc

Copy link
Copy Markdown

First test report, on Windows 10 + AMD: the uncapped limit works, but only until the title starts loading the story; from there on frames are paced at exactly 30 fps again.

Setup: Windows 10 22H2 19045.7846, RX 9070 XT (driver 32.0.32015.7029), Ryzen 9 9900X, 3840x2160 window. main d2a4bae + #175 (Agility SDK, needed on Windows 10) + #336 + this PR at 8a84e85. One conflict with #175 in apps/victory/src/main.rs: both add lines to show_config at the same spot; I kept both (d3d12 sdk then fps_limit/tearing). Diag build, VICTORY_FPS_LIMIT=0.

  • victory config shows fps_limit : uncapped with the env var and (title default) without it; tearing : true.
  • At startup: frame interval overridden: uncapped (fps_limit = 0) title_interval=33.333ms and presenting to a window width=3840 height=2160 format=28 buffers=3 tearing=true.

From the runtime's per-5 s fps, ms/frame lines:

phase before (same base without this PR) with this PR, uncapped
first ~15 s 30.0 fps 685–778 fps (1.3–1.5 ms)
next ~15 s 30.0 fps 274–308 fps (3.2–3.7 ms)
from the moment the title opens its story packs (frame ~13,866 here) through the intro, menus and loading 30.0 fps 30.0 fps, 33.3 ms, with ~1–2 ms of preparation and ~1 ms on the GPU
world ~1 fps ~0.2–1.6 fps (no change expected)

The uncapped part looked right to me: no visible speed-up of animation or audio, and no tearing I noticed. But after the switch the frames sit at exactly 33.3 ms while the work takes ~3 ms, so something keeps pacing them at 30 that set_fps_limit doesn't override: the title calling SetFrameIntervalX again, a wait kind this PR doesn't cover, or the title's own timing. I didn't run with VICTORY_LOG=victory_gpu::frame=debug, which would show the frame wait kind=… timeout_ms=… lines; happy to, if that helps.

No game data used.

AI-assisted (Claude Code); I played the run.

@jeremygold02

Copy link
Copy Markdown
Contributor

Tested current PR head 8a84e85c9d88f45205e40e235aaa5093e9edf085.

  • cargo test --locked -p victory-core --lib config -- --test-threads=1: 6 passed. This covers optional graphics defaults, file parsing, environment-over-file precedence for FPS/tearing, and invalid environment values.
  • cargo test --locked -p victory-gpu --lib frame -- --test-threads=1: 2 passed. The cases cover title-default, uncapped, and 60/120/144/240-FPS interval math; timeout/origin/flip token sequencing; an immediate uncapped loop; and frame statistics (clock tests).
  • cargo test --locked -p victory-gpu --lib output_enumerates_high_refresh_modes -- --test-threads=1: 1 passed. It checks 4K 60/120/144/240-Hz modes, a custom host rate, duplicate removal, and the undersized-buffer MORE_DATA case (mode test).
  • cargo test --locked -p victory -- --test-threads=1: 1 passed and the CLI package built. cargo run --locked -p victory -- run --help also displays the new --fps option and its documented precedence; no title was run.

These tests do not exercise a real swapchain, adapter/display tearing support, or the reported return to 30 FPS during story loading. The CLI package test is an existing loader-lock test, so it does not verify the --fps override in a running title.

@wbkepler

Copy link
Copy Markdown
Contributor Author

Thanks @GamingRipperDoc for the detailed report!

I audited every frame-pacing, wait, and present path across victory-gpu (frame.rs, queue.rs, host.rs, dxgi.rs, device.rs) and victory-hle:

  • SetFrameIntervalX re-calls: FPS_LIMIT is set once at startup (Some(0) for uncapped) and never reset. Any subsequent SetFrameIntervalX call re-runs effective_interval(title_interval, Some(0)) -> None, so the uncapped override stays active.
  • All WaitFrameEventX event kinds: when interval is None, next_tick(kind) returns Duration::ZERO for every event kind (ORIGIN, VBLANK, FLIP, etc.), so frame::wait returns S_OK with zero sleep.
  • PresentX / DXGI: Host::present passes SyncInterval = 0 with DXGI_PRESENT_ALLOW_TEARING (and SyncInterval = 0 on fallback), and IDXGIOutput has no WaitForVBlank sleep path.

That strongly points to the lock-back to 30.0 fps (33.3 ms) around frame ~13,866 being the title's own CPU-side frame/simulation limiter (e.g. a QPC + Sleep/timer loop targeting 33.3 ms once it leaves early boot and enters the intro/menu/loading loop), rather than a second pacing path inside victory-gpu.

Pushed a small follow-up commit to frame.rs so repeated SetFrameIntervalX calls also log at debug (instead of being silenced by Once), plus a test covering repeated set_interval calls across all event kinds in uncapped mode. If you do another quick run with VICTORY_LOG=victory_gpu::frame=debug, checking whether frame wait still logs wait_us=0 during the 30.0 fps phase (and whether any frame interval re-set lines appear) will confirm conclusively whether victory-gpu is sleeping at all there.

@wbkepler

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (ffe310e) as 6fa50e2; conflicts were in config.rs (upstream's flat test_titles file config vs this PR's [paths]/[graphics] split; its tests now use FileConfig) and the show_config output (kept both data_dir and the fps lines). Gate (clippy -D warnings, tests, policy) clean.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

@wbkepler
wbkepler force-pushed the gpu/configurable-fps-limit branch 2 times, most recently from 6fa50e2 to 6c2c141 Compare November 24, 2026 22:17
@wbkepler

Copy link
Copy Markdown
Contributor Author

Rebased onto 70564ae as 6c2c141 (squashed to one commit). Adapted: kept upstream's fidelityfx_dir config key and show_config line alongside the new [graphics] section/fps_limit output, and kept upstream's 50 ms tick in the frame pacing test (the PR's module-level FLIP constant replaces the test-local one). Gate: clippy -D warnings (core, gpu, victory, victory+diagnostics), tests and cargo xtask policy pass; two pre-existing view-heap-cap tests fail identically on plain upstream on this host.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/frame.rs, crates/victory-gpu/src/lib.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

…resh modes, tearing swapchain

Adds [graphics] fps_limit/allow_tearing, --fps, VICTORY_FPS_LIMIT, an override of
the title's SetFrameIntervalX interval, a high-resolution waitable timer, 60-240 Hz
display modes and a 3-buffer ALLOW_TEARING swapchain.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wbkepler
wbkepler force-pushed the gpu/configurable-fps-limit branch from 6c2c141 to 1899bb5 Compare November 25, 2026 07:13
@wbkepler

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (940d32f) as 1899bb5; conflicts were with the frame-wait tick now taken before the sleep (kept upstream's, the uncapped path takes its tick too), the swap-chain retry/error steps (tearing flags folded into them) and run now returning the exit status (fps added).

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants