Skip to content

perf(gpu): eliminate per-frame pipeline stalls, fix indirect windows, reduce recording lock contention, and enable levels on demand - #867

Open
powplusplus wants to merge 5 commits into
fxceless:mainfrom
powplusplus:perf/gpu-60fps
Open

powplusplus wants to merge 5 commits into
fxceless:mainfrom
powplusplus:perf/gpu-60fps

Conversation

@powplusplus

Copy link
Copy Markdown

Summary

Targeted GPU and recording-thread frame-time optimizations independently rebased onto main (9376fd6), verified on live 3D world gameplay (RTX 3080 12 GB, GE-Proton11-14) with zero crashes and zero device loss over 420 s:

  1. One-frame pipeline wait budget (pipeline/make.rs): Track Pending::waited_frame so a slow or still-compiling pipeline only consumes the synchronous wait budget on the first frame it is requested. Menus and one-off bakes still finish on frame 1, while subsequent world frames compile asynchronously instead of stalling 416-500 ms/frame.
  2. Fix and enable indirect argument windows (draw.rs, list.rs, indirect.rs):
    • Fixes the out-of-bounds argument read when args.left(arguments) < step (fit == 0 previously clamped 1 record of step bytes past the buffer end) by requiring fit >= 2 before widening.
    • Fixes the D3D12 resource-state mismatch / per-hit barrier churn by keeping the window's scratch buffer in INDIRECT_ARGUMENT across hits and transitioning it back to COMMON via State::close_window before list close/cut, UAV/buffer barriers, buffer copies, or buffer-writing dispatches/draws.
    • Uses dense stride-based windowing when diff is a multiple of stride so skipped/culled slots still hit, raises WINDOW_MOST to 256, and enables VICTORY_INDIRECT_WINDOW by default (=0 disables).
  3. Deduplicate redundant global UAV barriers (host.rs, draw.rs, list.rs, indirect.rs): Track per-list uav_dirty state (covering compute, buffer stores, root UAVs, table UAVs, and dynamic-indexed UAVs) so barrier_groups skips redundant global UAV barriers when no UAV write occurred since the last barrier.
  4. Coalesced 64-thread CARD_COMPARE + VICTORY_CARD_REHASH_RUNS on by default (host.rs, indirect.rs): Upgrades CARD_COMPARE from 1 thread per 64 KiB piece (4,096 serial strided reads) to 1 64-thread workgroup per 64 KiB piece with coalesced 1,024-byte Load4 bursts and groupshared reduction.
  5. Eliminate cross-thread recording lock contention (descriptor/host.rs, shadow.rs, draw.rs, list.rs):
    • Lock-free AtomicU64 fast-path (made_keys) in HostHeap::mirror for already-made slots.
    • Convert shadow::BUFFERS and shadow::LOOSE from Mutex to RwLock with shared read-lock fast paths in lookup and loose.
    • Stack-allocate common-case per-draw user-data constants (<= 64 dwords) and RTV handle arrays (<= 8 targets).
    • Word-wise (u64) skip in shadow::merge_piece to avoid byte-by-byte reads and unnecessary writes on unchanged words.
  6. Cap per-frame texture staging budget & enable VICTORY_LEVELS_ON_DEMAND by default (draw.rs, tiles.rs):
    • Lowers default VICTORY_TEXTURE_STAGE_MS from 250 ms (750 ms catchup) to 20 ms (40 ms catchup) so initial world streaming no longer freezes recording threads for 750+ ms/frame.
    • Enables VICTORY_LEVELS_ON_DEMAND by default (=0 disables), saving ~4.0-4.9 GB VRAM on 12 GB cards.

Verification

  • cargo clippy --target x86_64-pc-windows-gnu -p victory-gpu --all-targets (default and --features diagnostics): zero new warnings.
  • Windows unit tests under GE-Proton11-14 (pipeline::make::, indirect::, descriptor::host::, shadow::, host::, watch::, list::): 90/90 passed, including new slow_pipeline_waits_at_most_one_frame and card_compare_hlsl_compiles tests.
  • Live 420 s RTX 3080 12 GB gameplay run (victory-bench.exe with perf/gpu-60fps + PR shader: merge multiple loop back edges into one latch and raise pipeline stack #737):
    • Zero crashes, zero device loss, visually verified neon night cutscene and live interactive gameplay (BF GRETA vehicle HUD + minimap).
    • Pipeline wait: 416-500 ms/frame -> 0.0 ms/frame.
    • Recording (list calls across 6 threads): 632-731 ms/frame -> 214.0 ms/frame (3.2x faster).
    • Texture staging pass (heap_textures): 750-850 ms/frame -> 43-68 ms/frame (12x faster).
    • Indirect windows: 544-671 hits/frame with zero device loss.
    • VRAM usage: 11.4 GB -> 6.5 GB (4.9 GB saved).
    • 3D world framerate: peaked at 4.1 fps (241.5 ms/frame) (up from 0.1-0.2 fps baseline and 1.9-2.0 fps in PR perf(gpu,hle): optimize view-memory guards, xmem alias mapping, texture waits, and relay card copy-back #824).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T11:17:31.456767Z 377fdc3 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 377fdc38f1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

fn windows() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_INDIRECT_WINDOW").is_some_and(|v| v == "1"))
*ON.get_or_init(|| std::env::var_os("VICTORY_INDIRECT_WINDOW").is_none_or(|v| v != "0"))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve budget charging when reusing indirect records

When a list alternates read-only direct draws with single-record indirect draws reusing the same argument offset, the now-default window survives the direct draws and serves subsequent executions from the cache. Those hits bypass record_clamp_as, which charges the per-list work budget. A mesh record containing (65535, 1, 1) can consequently execute 1,000 times while being charged once, instead of being emptied after 16 executions. Previously, each intervening direct draw invalidated the window and forced another budget charge. This defeats the cumulative hang guard and can permit GPU timeouts; debit re-executed entries or prevent repeated cache hits before enabling this by default.

Useful? React with 👍 / 👎.

Comment on lines +3076 to +3078
&& diff % u64::from(stride) == 0
{
(u64::from(stride), true)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve observed spacing when widening indirect windows

For single-record calls with a 16-byte signature stride and arguments stored 32 bytes apart, diff % stride == 0 does not establish that the intervening slots contain arguments. Choosing stride here makes bound_ahead interpret padding or metadata as additional draw records and charge their counts against the shared budget. For example, valid (3, 1) draw counts at each 32-byte boundary with (65536, 1024) metadata halfway between exhaust the entire 2^27 budget in the first widened window, causing subsequent valid draws to be clamped to zero. The previous observed 32-byte step avoids this. Preserve the observed spacing unless dense packing is independently established.

Useful? React with 👍 / 👎.

@MamaLeVrai

Copy link
Copy Markdown

Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head d7785fb into main f85101b in a throwaway tree (no conflict). cargo clippy --workspace --all-targets --locked -- -D warnings fails with exactly the errors main itself has on this machine (placed_filler_twins, depth_written, a sort; PR #841 fixes them), also with --all-features; this PR adds none. cargo test --workspace --locked: run 1: 557 passed, 0 failed, 11 ignored; run 2: 557 passed, 0 failed, 11 ignored (main alone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data.

AI-assisted (Claude Code); no game data.

triippywhale pushed a commit to triippywhale/victory-fork that referenced this pull request Nov 25, 2026
…ing pass; buffer lookups under a shared lock

Hand port of PalmVIDev fxceless#221 (3b8b22f3, from fxceless fxceless#867, powplusplus):
- pipeline/make.rs: a pipeline that is not made is waited for only in
  the first frame that asks for it (VICTORY_PIPELINE_WAIT_ONCE=0 waits
  every frame, as before). Measured there: waits 416-500 ms/frame -> 0.
- draw.rs: VICTORY_TEXTURE_STAGE_MS 250 -> 20 by default, backlog
  catch-up 3x -> 2x; user-data words on the stack.
- shadow.rs: BUFFERS is a reader-writer lock; lookup returns a made
  copy under the shared lock.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017V7WBCi8h4eymnRhdth77t
@HrHd

HrHd commented Nov 25, 2026

Copy link
Copy Markdown

Took the five commits onto current main (with our clamp ring, needs spaced gather and the present stretch already in) and it removes the device here on an RTX 4060 Ti, native NVIDIA, Windows 11: host GPU device removed ... 0x887A0006, twice out of two launches, about three minutes into the prison scene, each announced first by drvwatch ("the graphics driver reported an error n=2"), at 4-5k draws.

Bisect, by reverting from the tip (each step a fresh build and a fresh launch):

  • defaults first: VICTORY_INDIRECT_WINDOW=0, VICTORY_DEFER_NEW_VIEWS=0, VICTORY_CARD_REHASH_RUNS=0 - still removed, so it is not the new default flips;
  • 96a7937, d7785fb, d4fc3c2, ca1379c reverted - still removed;
  • so the fault is in the base, d4e6556 (the pipeline wait budget or the hashing rewrite; the two are in one commit here so I cannot split them further).

Two smaller things from the port, for the record: jump_windows/jump_window are gone from draw.rs but five tests still call them, and window_line/WINDOW_WHY (ours, from main) collide with WINDOW_STATS - I kept both sets rather than deleting either.

The tree is back on the base for now (250-263 ms, 0 removals, 4.2 fps at 4.8k draws). If it helps, the last 96 operations log line read "between submissions, nothing of ours running on the card, 0 lists" when it went.

Copy link
Copy Markdown

I reproduced the wait reported in #1181 and tested the pipeline hunk from your d4e6556 on Windows WARP. With four entries held in MAKING and a shared 20 ms budget, main charged a wait every frame. Your change eliminated it after frame one.

One detail showed up when several pipelines were first bound together. The first entry spent the budget. ready() also set waited_frame on the remaining three before wait() discovered that the budget was empty. Those three consequently lost their first opportunity even when a later frame had time. I moved the claim under the existing budget lock, after checking for positive time. On the same six-frame replay, pipelines 1–4 each got one wait on successive frames, then both remaining frames recorded zero. Shared and unshared modes passed. A completed WARP compute pipeline was available on its next bind with zero additional wait.

The correction applies cleanly to your current head d7785fb. I kept your original change credited and put the correction and replay in separate commits. The replay runs with cargo test --locked -p victory-gpu --features diagnostics four_inflight_frames_and_late_completion -- --nocapture. Correction · Regression replay

@HrHd

HrHd commented Nov 26, 2026

Copy link
Copy Markdown

Split d4e6556 by file and measured each half, on an RTX 4060 Ti, native NVIDIA, Windows 11, ~4.8k draws, 70 s between samples:

  • pipeline/make.rs (the one-frame wait budget) alone: clean, 251-258 ms, 0 removals.
  • the other four files (card fetch inside flights, the CARD_COMPARE rewrite) on top of it: clean, 0 removals.
  • VICTORY_CARD_FETCH_INFLIGHT=1 alone: 516.3-530.0 ms against 193.3-211.3 with it off — it more than doubles the frame here. CARD_REHASH_RUNS=1 alone is neutral (194.0-198.9).
  • with both of the later commits on top (96a7937, ca1379c), the device removes in about three minutes ("no breadcrumbs", 0x887A0006, drvwatch n=2 first); ca1379c alone dies sooner, with 0xc0000005 in the translated image.

The base split is the fastest rung this machine has measured (5 fps, 0.041 ms/draw, 0 removals over 15+ minutes), so both flips are off by default here and the two later commits are out for now. 96a7937 on its own was stable but 15 % slower (217-226), and not because of levels-on-demand (210-212 with VICTORY_LEVELS_ON_DEMAND=0).

milesah3ad added a commit to milesah3ad/victory-fork that referenced this pull request Nov 26, 2026
A pipeline the worker has not made within a frame's wait budget (a slow or
stuck driver compile) was waited for again in every frame that drew with it,
each taking the whole budget (VICTORY_PIPELINE_WAIT_MS, 500 ms): world frames
waited 500 ms each while four pipelines stayed MAKING (fxceless#1181), felt in play as
a freeze while moving that the pause menu (no world draws) let go.

Now the first frame with budget left claims the pipeline's one wait; later
frames drop its draws until it is made, as past the budget before. The claim
is taken under the budget lock and only with time left, so a pipeline first
bound after another spent the frame's budget keeps its wait for a later
frame. VICTORY_PIPELINE_WAIT_EVERY_FRAME=1 restores the old behaviour.

The one-frame cap is from powplusplus' fxceless#867; claiming only with budget left
is BradRoland's correction posted there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mrtacoguy01 pushed a commit to mrtacoguy01/victory-fork that referenced this pull request Nov 26, 2026
A pipeline the worker has not made within a frame's wait budget (a slow or
stuck driver compile) was waited for again in every frame that drew with it,
each taking the whole budget (VICTORY_PIPELINE_WAIT_MS, 500 ms): world frames
waited 500 ms each while four pipelines stayed MAKING (fxceless#1181), felt in play as
a freeze while moving that the pause menu (no world draws) let go.

Now the first frame with budget left claims the pipeline's one wait; later
frames drop its draws until it is made, as past the budget before. The claim
is taken under the budget lock and only with time left, so a pipeline first
bound after another spent the frame's budget keeps its wait for a later
frame. VICTORY_PIPELINE_WAIT_EVERY_FRAME=1 restores the old behaviour.

The one-frame cap is from powplusplus' fxceless#867; claiming only with budget left
is BradRoland's correction posted there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants