Skip to content

GPU: an opt-in slow-pipeline guard, VICTORY_SLOW_PIPELINES=1 (stacked on #2721) - #2911

Open
0xkn0wh3r3 wants to merge 12 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/slow-pipeline-guard
Open

0xkn0wh3r3 wants to merge 12 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/slow-pipeline-guard

Conversation

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor

Stacked on #2721, the slow-frame report; only the last commit is new. Split out of #2721 after review.

With VICTORY_SLOW_PIPELINES=1 (off by default, because it drops title work), compute dispatches and mesh draws are timed. A pipeline is dropped when one of its commands goes over the limit (VICTORY_SLOW_PIPELINE_MS, 100 ms) in 3 frames in a row, not counting its first 10 frames.

  • Draws and dispatches of it recorded from then on are dropped (State::bind).
  • After 60 s it is tried again. Each later ban doubles, up to 16 minutes, and a frame within the limit lifts it.
  • Lists recorded before a ban still run its commands.

The point: a submission can't be stopped once it runs, and one the host takes 2 s for resets the device. The cost is that what the dropped pipeline computes is missing; each ban and retry is logged.

Tests

  • No strikes during a pipeline's first frames; slow commands within one frame count as a single strike.
  • A frame within the limit clears the strikes; three slow frames in a row ban the pipeline.
  • Bans end and double; a pipeline that is quick when tried again stays allowed.
  • A ban made through the global calls is seen by skips.
  • With the guard off, timed commands strike nothing.
  • draw::tests::a_banned_pipeline_is_dropped_from_lists_recorded_after_the_ban checks on the host GPU that a list recorded before the ban still runs it, and one recorded after doesn't.
  • Clippy is clean, with and without --features diagnostics. The two NVIDIA heap-limit failures that GPU: page view heaps a host caps below the slots shaders index #2121 fixes also happen on main.

Not run with the title.

…ow for it

At 30 frames a second a frame has 33.3 ms. A world frame takes about a
second on current main, and one submission of a few slow passes stops
the title's thread until the GPU is done with it (`Host::execute` waits),
or, past about 2 s, resets the device. Nothing said where a frame's time
went, and a pipeline that is slow on this host ran again every frame.

`crate::budget`:

- Compute dispatches and mesh draws, direct and indirect, are timed on
  the GPU: a timestamp before and after each (`HostList::time_start`,
  `time_end`), resolved when the list closes, read when it has run
  (1,024 timestamps a list; commands past them are not timed). Commands
  other than these are not timed.
- A frame (present to present) past 50 ms is reported, at most one line
  a second with a count of the others: its time, ours before its
  submissions (copies, uploads), the GPU's, pipeline waits, submissions,
  its three slowest timed commands and what the guard dropped.
- The slow-pipeline guard: a pipeline one of whose commands took longer
  than the limit three times is not run any more (`State::bind` drops
  its draws and dispatches as it does others that cannot run), said once
  with the pipeline. What it computes is then missing: visible, logged,
  and the world keeps moving. `VICTORY_SLOW_PIPELINE_MS` sets the limit
  (100 ms); `VICTORY_SLOW_PIPELINES=0` turns timing and the guard off.

Tests (`budget::tests`): a pipeline is dropped after its strikes and not
before, and only it; a frame keeps its slowest commands; frames start
over at each present; on the host GPU a timed dispatch of a long loop
measures far longer than one of a short loop (0.80 ms against 0.009 ms
on an RTX 5070 Ti). Not measured in a title run.

Seen once in five full runs of the GPU tests here, not in eight others
or in three on main: `host::title_copies::copy_back_writes_mapped_pages_only`
failing (it passed five runs alone); `frame::tests::waits_end_on_ticks_and_count_frames`
failed once under load as well, a 50 ms timing check.
Another module of that name (a video memory budget) is in open PRs; the
frame budget's is named for what it keeps.
…nly what is recorded after its ban

A pipeline backing several timed commands was banned within one frame
when each was over the limit, and a one-off hitch (a shader compiled
mid-frame) counted toward a ban for the rest of the session.

Strikes are now per frame (present to present): a frame in which any
of a pipeline's timed commands is over the limit is one strike, however
many were; a frame in which all of them kept to it clears its strikes;
frames in which it was not timed leave them. Three over-limit frames in
a row ban it. Only pipelines timed in a frame are kept for it, with
their slowest command, and tallied when it is presented.

The ban is checked in `State::bind` while recording, so a list closed
before it still runs the pipeline's commands each time it is submitted
again. The warning and the module's docs now say so: draws and
dispatches recorded from then on are dropped.

Tests: three slow commands in one frame do not ban; slow, quick, slow,
slow frames do not; three slow frames in a row do, when the third ends
and not before, and only that pipeline. On the host GPU, a list closed
before its pipeline's ban writes again when resubmitted, and one
recorded after it holds no dispatch (`State::bind` refuses it).
With VICTORY_SLOW_PIPELINES=0 nothing is timed: no timestamps are
recorded, no query heap or read-back buffer is made, no timestamp is
read back, and the guard's lock is never taken. The slow-frame report
keeps running without GPU timing: its tallies are atomics, a few relaxed
adds a submission and swaps at a present, so submissions, waits and
presents take no lock whether the guard is on or off.

With the guard on, a list makes its query heap at its first timed
command (a list that times none never makes one; before, every list
executed made one) and keeps it across resets; only lists that timed
commands are read back, under one lock a list; the queue's timestamp
frequency is asked once.

Pipelines are not struck in the first 10 frames after they are first
timed (first-use hitches). A ban lasts 60 s; the pipeline is then tried
again, said once. Still over the limit 3 frames in a row, it is banned
again for twice as long (up to 16 minutes), said once; a frame within
the limit keeps it and forgets its bans.
The report named the frame's time, ours, the GPU's and pipeline waits,
and the slowest commands by their shader hashes: enough to see that a
frame was slow, not what made it so.

It now splits the frame into its parts and names the largest as what
bound it, with why:

- our work around submissions, each phase on its own: descriptor heap
  sync (and evictions), texture uploads, refreshing host copies of title
  memory, and copy-back of what shaders wrote;
- the GPU's;
- pipeline waits;
- the rest ("outside submissions"): the title's own work on its threads
  and the translation of its command-list calls as it makes them.

With the guard on, the GPU's part is broken down by kind of command
(compute, mesh, and their indirect forms: time and count) and by how
the commands' programs reach memory: title memory by address through
the page table (whose writes set bitmap bits with atomics), write marks
through views, views picked from the heap, view addresses read. The
slowest commands are described the same way, with their group counts:
"600 ms compute 1024x1x1 groups [title memory by address] [compute ..]".

A GPU-bound frame's why reads, for example, "80% of the timed GPU time
is compute work (412 commands); 80% is in programs using title memory
by address". Nothing in it depends on a particular title.

The phases are a few Instant reads per submission and relaxed atomic
adds, as before; with the guard off nothing is timed or locked.
Conflicts: draw.rs (main's new placed-texture tests beside the guard's
test, both kept) and host.rs (main's multi-plane present; the frame
budget's present hook moves into its new present()).
It drops title work, so it is opt-in (review). Commands are timed for the
slow-frame report with the guard, or with VICTORY_FRAME_TIMING=1; without
the guard timed commands strike nothing. Comments trimmed.
…to its own PR

Review: per-command GPU timing, the slow-frame report and the slow-
pipeline guard were one change. This PR keeps the report and the timing
it uses (VICTORY_FRAME_TIMING=1 for the GPU breakdown); the guard, which
drops title work, is a separate opt-in PR stacked on this one.
Stacked on the slow-frame report (Marvisak#2721). With VICTORY_SLOW_PIPELINES=1
(off by default: it drops title work), compute dispatches and mesh draws
are timed and a pipeline with a command over the limit
(VICTORY_SLOW_PIPELINE_MS, 100 ms) in 3 frames in a row, past its first
10 frames, is dropped from draws and dispatches recorded from then on
(State::bind) for 60 s, then tried again; each later ban doubles, up to
16 min. Lists recorded before a ban still run it.

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

Scoped review: opt-in drop of pipelines measured too slow happens at record time (closed lists keep the commands — replay isn't corrupted), and per-op timing via time_start/time_end feeds the decision. One thing to double-check on the base: skipping a draw entirely also skips its resource transitions/barriers the prelude planned — if the next draw assumed the dropped one's final states, a skip could need a state repair; worth confirming the planner handles mid-list holes.

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

Verified head 7abc8fc3 (stacked on #2721) cleanly merged onto origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Code & Concurrency Review

  • Zero-overhead default path: With VICTORY_SLOW_PIPELINES off (and VICTORY_FRAME_TIMING != 1), skips() and timing() stay lock-free relaxed atomic checks without allocating query heaps/readback buffers or taking GUARD. Timestamp deltas safely use saturating_sub and frequency.max(1).
  • Observations / Suggestions (non-blocking):
    1. Stale log hint (crates/victory-gpu/src/frame_budget.rs:584, test L1136): The !timed message still reads "GPU work (commands are not timed with VICTORY_SLOW_PIPELINES=0)". Now that timing is split out behind VICTORY_FRAME_TIMING=1, pointing users to VICTORY_FRAME_TIMING=1 avoids nudging someone who only wants command timings to turn on the drop guard.
    2. Lock contention while any pipeline is banned (frame_budget.rs:471, 492-501): Once ANY_BANNED flips true (for 60s–16m), every recording thread takes the global Mutex<Option<Guard>> on every State::bind (even for unbanned pipelines), contending with ran() / presented(). Using an RwLock (read lock in skips()) would keep parallel list recording uncontended.
    3. Timestamp overlap attribution: Keeping the guard opt-in by default is the right call since non-barrier overlapping GPU commands can attribute a heavy neighbor's timestamp span to a lightweight pipeline.

Local Verification (VICTORY_D3D12_DEBUG=1)

  • RTX 5090: frame_budget::tests 15/15, draw::tests 21/21 (including a_banned_pipeline_is_dropped_from_lists_recorded_after_the_ban), pipeline:: 21/21, host::tests (non-descriptor) 12/12.
  • WARP (--features diagnostics): frame_budget::tests 15/15, draw::tests::a_banned_pipeline_is_dropped_from_lists_recorded_after_the_ban 1/1.
  • cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --features diagnostics) & cargo test -p xtask --locked (6/6, policy ok): clean.

…RY_FRAME_TIMING=1)

Review (fuzeofficlal): it named the guard's switch, which no longer times
commands.
Review (fuzeofficlal): while any pipeline was banned, every bind on
every recording thread took the guard's mutex. The banned names are now
kept in an RwLock that skips() reads; the guard's lock is taken only
when commands are reported and at a present, and the set is rewritten
only when bans change. a_banned_pipeline_is_skipped checks skips() takes
no guard lock.
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

@fuzeofficlal thanks, both notes are addressed:

  1. Log hint: the message for commands that aren't timed now reads "commands are timed with VICTORY_FRAME_TIMING=1". It lives in the report, so the fix is in GPU: a slow-frame report that says what bound the frame and why (guard split out to #2911) #2721 (16aa2a4), merged into this branch.
  2. Lock while a pipeline is banned: skips() now reads the banned names from an RwLock and never takes the guard's mutex (0f84595). The set is rewritten only when bans change. a_banned_pipeline_is_skipped now asserts that skips() takes no guard lock.

The guard stays opt-in (VICTORY_SLOW_PIPELINES=1). The frame budget tests and clippy, with and without diagnostics, pass.

Marvisak commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work (unchanged). Thanks for stating the purpose: the guard keeps the device from being reset when one submission takes about 2 s, and gives up the banned pipeline's output to do it. The head has not changed, so this still carries all of #2721. Please rebase once #2721 is settled, so the diff is only frame_budget.rs and the skips check in draw.rs State::bind.

Whether to ship a switch that drops the title's work is still the maintainer's call. Note also that #2936 traced a loading-time device removal to missing title memory in the page table (memory::CAPACITY), not to a slow pipeline as such. Evidence that the guard's case still happens once that kind of cause is fixed would help the decision.

CI: passing.


Generated by Claude Code

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Understood. I'll rebase this onto main once #2721 lands or closes, so the diff is only the guard. To answer what it's for: it's a way to keep the device alive, not a diagnostic or a frame-rate tool. A submission can't be stopped once it runs, and one that takes the host about 2 s resets the device, which ends the run. The guard trades the dropped pipeline's output (logged per ban and retry) for a run that keeps going. That's why it's off by default and needs VICTORY_SLOW_PIPELINES=1.

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