Repository navigation
GPU: an opt-in slow-pipeline guard, VICTORY_SLOW_PIPELINES=1 (stacked on #2721) - #2911
0xkn0wh3r3 wants to merge 12 commits into
Conversation
…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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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_PIPELINESoff (andVICTORY_FRAME_TIMING != 1),skips()andtiming()stay lock-free relaxed atomic checks without allocating query heaps/readback buffers or takingGUARD. Timestamp deltas safely usesaturating_subandfrequency.max(1). - Observations / Suggestions (non-blocking):
- Stale log hint (
crates/victory-gpu/src/frame_budget.rs:584, testL1136): The!timedmessage still reads"GPU work (commands are not timed with VICTORY_SLOW_PIPELINES=0)". Now that timing is split out behindVICTORY_FRAME_TIMING=1, pointing users toVICTORY_FRAME_TIMING=1avoids nudging someone who only wants command timings to turn on the drop guard. - Lock contention while any pipeline is banned (
frame_budget.rs:471, 492-501): OnceANY_BANNEDflips true (for 60s–16m), every recording thread takes the globalMutex<Option<Guard>>on everyState::bind(even for unbanned pipelines), contending withran()/presented(). Using anRwLock(read lock inskips()) would keep parallel list recording uncontended. - 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.
- Stale log hint (
Local Verification (VICTORY_D3D12_DEBUG=1)
- RTX 5090:
frame_budget::tests15/15,draw::tests21/21 (includinga_banned_pipeline_is_dropped_from_lists_recorded_after_the_ban),pipeline::21/21,host::tests(non-descriptor) 12/12. - WARP (
--features diagnostics):frame_budget::tests15/15,draw::tests::a_banned_pipeline_is_dropped_from_lists_recorded_after_the_ban1/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.
|
@fuzeofficlal thanks, both notes are addressed:
The guard stays opt-in ( |
|
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 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 ( CI: passing. Generated by Claude Code |
|
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 |
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.State::bind).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
skips.draw::tests::a_banned_pipeline_is_dropped_from_lists_recorded_after_the_banchecks on the host GPU that a list recorded before the ban still runs it, and one recorded after doesn't.--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.