Skip to content

GPU: a pipeline waited for in vain is not waited for again - #3071

Open
ntgata1-dotcom wants to merge 1 commit into
Marvisak:mainfrom
ntgata1-dotcom:pipeline-give-up
Open

ntgata1-dotcom wants to merge 1 commit into
Marvisak:mainfrom
ntgata1-dotcom:pipeline-give-up

Conversation

@ntgata1-dotcom

Copy link
Copy Markdown

What is wrong

Draws wait for a host pipeline that is being made, for up to BUDGET (500 ms) per frame. If the host compiler takes seconds for a pipeline, or never finishes it, that wait is paid again in every frame that draws with the pipeline, not just the first.

Under Wine with vkd3d-proton (GE-Proton11-14, RX 9070 XT, RADV), 22 of the shader pack's 27,160 pipelines never finished in translate --cache --pipelines. In the world, the frame line showed dropped 1.0/frame without a host pipeline: being made in every frame.

Thread stacks taken in the world (VICTORY_STACKS, four dumps over two minutes, diag build) show the cost. In 3 of the 4 dumps, one recording thread was in pipeline::make::ready (called from draw::State::dispatch), and every other title thread was waiting on the title's own objects. No title thread was running.

What changes

Once a single wait for a pipeline has lasted 100 ms (GIVE_UP) without the pipeline being made, later draws don't wait for it. The pipeline is still made in the background, and its draws are dropped until it's ready. That is what already happens once a frame's budget is spent. The first wait is unchanged, so a pipeline made within 100 ms behaves as before. VICTORY_PIPELINE_GIVE_UP=0 restores the old behaviour.

This is separate from #2111 (one budget correctly shared across recording threads) and #275 (an adaptive budget). Those bound the wait per frame; this one stops paying it again for the same pipeline. It touches the same function as #2111, so whichever lands second needs a small rebase.

Tested

  • In game: same machine and save, the first mission's opening cutscene, diag builds with a warm cache from translate --cache --pipelines. The only difference between the two runs is this change. Both also had two local changes that aren't in this PR: queues on a worker thread, and a wineserver with its memory views in a tree. World frame times, grouped by draw count:

    Draws per frame before after
    1,000–2,500 731 ms 344 ms
    2,500–4,000 851 ms 490 ms
    4,000+ 888 ms 593 ms

    The log showed two pipelines given up on, each after a 500 ms first wait.

  • New test: a_pipeline_waited_for_in_vain_is_not_waited_for_again passes under Wine, with and without diagnostics.

  • Clippy: clean for x86_64-pc-windows-msvc, with and without --all-features.

  • Not run on Windows. CI runs the Windows tests.

AI-assisted (Claude Code); numbers from my own runs.

Draws wait for a pipeline being made, up to 500 ms a frame over all
threads. A pipeline the host's compiler takes seconds for, or never
finishes (some do under vkd3d-proton: 22 of the pack's 27,160 here), so
cost every frame the whole budget. In the world on Linux the title's
threads all stood behind one such wait: a recording thread in
pipeline::make::ready, every other title thread on the title's own
objects, in each of the stack dumps taken, with "dropped 1.0/frame
without a host pipeline: being made" every frame.

Once one wait for a pipeline has lasted 100 ms in vain, later draws do
not wait for it: it is still made in the background and its draws are
dropped until then, as they are once the budget is spent.
VICTORY_PIPELINE_GIVE_UP=0 waits as before.

The test makes a pipeline nothing makes and waits for it twice: the
first wait lasts at least 100 ms, the second returns at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@Dukestar69 Dukestar69 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.

Tested locally merged onto origin/main (63bcca4) on Windows 11 x64:

  • Diff review: Adding Pending::given_up and setting it when a wait exceeds GIVE_UP (100 ms) without the pipeline finishing (toggleable via VICTORY_PIPELINE_GIVE_UP=0) prevents a slow or hung pipeline compile from burning the entire frame wait budget on every subsequent frame while still letting background compilation complete.
  • cargo test -p victory-gpu --features diagnostics pipeline::make::tests -- --test-threads=1: 4 passed, 0 failed (including a_pipeline_waited_for_in_vain_is_not_waited_for_again).
  • cargo clippy -p victory-gpu --features diagnostics --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@kotekompotek kotekompotek 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.

Verified: BUDGET=500ms so a single wait can reach the 100ms GIVE_UP mark; given_up only sets when the pipeline is still unmade after the wait (made.get().is_none() gate), swap() keeps the once-only info log, and later draws return immediately. Opt-out env var preserved. Test exercises first-wait burn + later-frame skip.

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 26, 2026
…w classes & single-timeout PSO wait

Keep Xbox Series X (XboxScarlettAnaconda = 7) while eliminating 95% VRAM-spill storms on <=10.5 GiB GPUs:
- Raise default VRAM steering reserve on 8-10.5 GiB discrete GPUs to 1,792 MiB (<=6 GiB stays 512 MiB).
- Enable boot-time auto 1-mip drop on >=1024px streamed 2D BCn textures (MipLevels >= 4) on <=10.5 GiB GPUs, escalating to 2-mip drop on >=2048px (MipLevels >= 5) above 76% VRAM.
- Cap default XSystemGetAppMemoryUsageLimit() to Series X retail limit (13,824 MiB, clamped to host RAM if smaller) while keeping LEONIDA_TITLE_MEMORY_MB override and XSystemGetDeviceType() = 7.
- Fix RT-PLACED-DEFER-STAGED shared-zero image deferral when implicit_cast / view_formats_ are attached (canonicalized view_formats in ZeroShape).
- Add emergency OOM relief + retry in DeviceState::allocate() (reclaim retired slabs/arena/deferred deletions, trim staging/slab pools, evict stale title windows, spillable HOST_VISIBLE retry fallback; adapted from avatarmanz/VIctory-7900XTX#92 & fxceless/victory-fork#1082, GPL-3.0).
- Skip refresh_shadows() on internal staging flushes and skip shader-only title-window shadow scans on non-shader copy/barrier/clear submissions while keeping explicit slot-133 buffer shadows coherent.
- Enforce Vulkan BC image-view compatibility classes (adapted from ubiquitarianism/leonida#2223, GPL-3.0, author GGandCo) and never re-wait on a PSO whose wait already timed out once (adapted from Marvisak/VIctory#3071, GPL-3.0, author ntgata1-dotcom).

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested natively on Windows 11 x64 (rustc 1.98.1, RTX 5090 + WARP; note CI workflow run #45767613588 is currently action_required awaiting first-time contributor approval rather than failing):

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --all-features): clean.
  • cargo test -p victory-gpu --lib --locked -- pipeline::make::tests --test-threads=1: 3 passed, 0 failed (including a_pipeline_waited_for_in_vain_is_not_waited_for_again).
  • cargo test -p victory-gpu --lib --features diagnostics --locked -- pipeline::make::tests (WARP, both --test-threads=1 and default parallel threads): 4 passed, 0 failed.
  • cargo xtask policy: 191 files ok.

The core given_up latch (made.get().is_none() gate, once-only swap(true) log, background compilation still running, VICTORY_PIPELINE_GIVE_UP=0 opt-out) works cleanly and solves the repeated per-frame stall.

Two small non-blocking refinements worth considering:

  1. Queue backlog vs. slow compile (pipeline/make.rs:54-56): started.elapsed() includes time spent waiting in QUEUES before any worker picks up p. During a large first-frame burst (1,000+ pipelines queued across 2–8 below-normal-priority workers), a fast pipeline waiting >100 ms in the queue can be permanently marked given_up before compilation even starts. Gating given_up on p.taken.load(Ordering::Relaxed) (so a pipeline is only given up on once a worker has actually started compiling it) avoids false positives from queue congestion while still catching slow/hung compiles.
  2. Release DONE mutex before logging (pipeline/make.rs:53-62): dropping held right after the while loop avoids holding the global DONE lock across tracing::info! formatting/I/O while workers are trying to acquire DONE for notify_all().

LGTM once CI is approved to run.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: needs work. The problem is real: pipeline::make::wait pays up to BUDGET every frame for a pipeline that never finishes. The fix in wait (Pending::given_up after one wait of GIVE_UP = 100 ms) is small. But it changes what every Windows run does by default, and the only evidence is from Wine/vkd3d-proton with two other local changes.

What it needs:

  • A Windows run (loading and the first world frames, where 1,200+ pipelines are queued at once) compared with main. Give the number of pipelines given up and the draws dropped. A wait there can last 100 ms just from queueing behind other pipelines, not because the pipeline is slow. With this change, that pipeline's draws in the following frames are dropped instead of waited for.
  • The switch documented: VICTORY_PIPELINE_GIVE_UP needs a row in the README's switch table. It's read directly here; crate::switch::on is the repo's helper for on/off switches.

CI: not run on this head yet (needs a maintainer's approval for this contributor).


Generated by Claude Code

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.

5 participants