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

Open
github-bot wants to merge 12 commits from github-bot/gh-2911 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:50 UTC · original
0xkn0wh3r3:gpu/slow-pipeline-guard → main · +1525 −42 · 6 files · 12 commits · open

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 #2121 fixes also happen on main.

Not run with the title.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2911) `0xkn0wh3r3:gpu/slow-pipeline-guard` → `main` · +1525 −42 · 6 files · 12 commits · open 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 #2121 fixes also happen on main. Not run with the title.
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.
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.
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 (#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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:18 +00:00
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 00:36 UTC · original

@⁠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 #2721 (16aa2a49), 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 (0f845952). 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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 00:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2911#issuecomment-7178928393) @⁠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 #2721 (16aa2a49), 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 (0f845952). 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:20 UTC · original · edited 2026-11-26 07:23 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-26 02:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2911#issuecomment-7180716038) · edited 2026-11-26 07:23 UTC <!-- victory-triage v1 head=0f84595274d6af8115d79f0a167435c7161f920e verdict=needs-work at=2026-11-26T07:23:36Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 06:42 UTC · original

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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 06:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2911#issuecomment-7184700462) 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`.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2911/head:github-bot/gh-2911'
git switch 'github-bot/gh-2911'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2911'
git switch 'github-bot/gh-2911'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2911'
git switch 'github-bot/gh-2911'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2911'
git switch 'main'
git merge --squash 'github-bot/gh-2911'
git switch 'main'
git merge --ff-only 'github-bot/gh-2911'
git switch 'main'
git merge 'github-bot/gh-2911'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2911
No description provided.