Skip to content

GPU: the clamped arguments' scratch stays in INDIRECT_ARGUMENT between executions (VICTORY_INDIRECT_KEEP=1) - #780

Closed
LeonardoS11 wants to merge 1 commit into
fxceless:mainfrom
LeonardoS11:pr/indirect-keep
Closed

LeonardoS11 wants to merge 1 commit into
fxceless:mainfrom
LeonardoS11:pr/indirect-keep

Conversation

@LeonardoS11

Copy link
Copy Markdown

What

VICTORY_INDIRECT_KEEP=1 (off by default): the scratch buffer that holds clamped indirect arguments stays in INDIRECT_ARGUMENT between indirect executions and goes back to COMMON only right before a clamp writes it again. Together with VICTORY_INDIRECT_WINDOW=1 it takes about 40 ms a frame off the wait for the card on an RTX 3080 Ti (250–283 → 204–209 ms a frame in a still scene).

Why

  • Every indirect execution ends with indirect::done(), a transition of the scratch back to COMMON. That is a barrier between every two indirect draws — about 4,400 a frame in the world — also between draws that read one window clamped once for all of them.
  • The bare_command_cost test of 310c6eb on this card: a barrier pair between draws about 1.1 µs, a compute pass of ours between draws about 5 µs. Here the transition also has to wait for the execution that just read the buffer.
  • So the window alone saves the clamps but leaves a barrier after every draw, and the switch alone saves the barrier only on the path that still clamps before each draw. Neither does much by itself; the two together leave most indirect draws with nothing between them.

A buffer decays to COMMON when its submission is done, so the next list starts as before.

Numbers

Windows 11, RTX 3080 Ti 12 GB, 64 GB RAM, diag build with diagnostics. A still scene in the prologue (the room with the window onto the yard), about 4,800 draws a frame, 300 s a run, averages of the last 8 frame-rate lines. Measured on 310c6eb with room kept for the buffers' card copies (so the runs are comparable; see #776), not yet on 8dd30ab — I will add those.

ms a frame "on the GPU"
neither switch 283, 250 96, 100
VICTORY_INDIRECT_WINDOW=1 260 110
VICTORY_INDIRECT_KEEP=1 269 97
both 209, 204, 204 64, 61, 60

"dropped … indirect" is 1 a frame in all of them, so the window refuses nothing more than the per-draw path. The picture was compared by eye at 295 s and shows no difference that follows the switches.

Something I tried and dropped, in case it saves someone the time: moving all of a list's clamps into its prelude (one pass, no compute among the draws) by cutting the list after a dispatch that writes arguments. It clamped about 4,050 calls in 35 passes a frame and did not lower the wait at all — the cuts send the rest of the submission down the per-part path, and that costs what the clamps saved.

Suggestion

KEEP on whenever WINDOW is, and both on by default. I left both as they are so the default does not change with this PR.

Tested

  • cargo test -p victory-gpu --lib indirect:: on the card above: 8 passed. The new test, kept_scratch_goes_back_before_a_clamp_and_at_reset: after an execution the scratch is marked as kept; the next clamp takes it back to COMMON before writing; a list may close with it kept and runs; a reset forgets it; without the switch nothing is kept.
  • cargo test --workspace on a branch of ours that carries this commit on 8dd30ab with other changes: 531 passed, 0 failed, 10 ignored.
  • In game: the table above.

No title data in this PR.

🤖 Generated with Claude Code

…n executions (VICTORY_INDIRECT_KEEP=1)

Every indirect execution ended with a transition of its scratch buffer back
to COMMON: a barrier between every two indirect draws, also between those
reading one window clamped once for all of them (VICTORY_INDIRECT_WINDOW).
On an RTX 3080 Ti a barrier between draws costs about 1.1 microseconds and
a compute pass of ours between draws about 5 (`bare_command_cost` (c) and
(h)), and the transition here waits for the execution that just read the
buffer. With the switch the scratch stays in INDIRECT_ARGUMENT and goes
back only before a clamp writes it again; a buffer decays to COMMON when
its submission is done, so a list still starts with it there.

The world, a still scene, Series X, 4,800 draws a frame (ms a frame | GPU):
neither switch 283 and 250 | 96-100; WINDOW=1 260 | 110; KEEP=1 269 | 97;
WINDOW=1 and KEEP=1 209, 204, 204 | 64, 61, 60. The two together are what
helps: the window leaves most draws without a clamp, and the switch leaves
them without the barrier. Proposed: KEEP on whenever WINDOW is, and both on
by default.

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

Copy link
Copy Markdown

I tested 68620ed on top of current fork main 9376fd6 with a desktop RTX 5070 Ti 16 GB, NVIDIA 621.40, Ryzen 7 9850X3D, 32 GB RAM, and Windows 11. Both runs use the same diagnostics executable, Series X profile, copied warm caches, reported 1080p display mode, levels on demand, late wait 3, 70% texture room, and in-flight card fetch off.

One run used both VICTORY_INDIRECT_WINDOW=1 and VICTORY_INDIRECT_KEEP=1. The control had both off. I left the camera at the prison window after the game handed over control. I timed three intervals between captures.

Presents Both off FPS Both on FPS Median draws per frame off / on
1705–1849 4.26 4.31 5,008 / 4,971
1851–1999 4.02 4.58 4,971 / 4,915
2001–2149 3.74 4.78 4,937 / 4,784

Across the 443 timed presents per run, throughput went from 3.99 to 4.55 FPS. In the last interval the median frame time went from 260.28 to 209.63 ms and p95 from 320.49 to 224.92 ms. Median host wait for the GPU went from 134.7 to 93.9 ms per frame. Preparation stayed near 77 ms. The meter reported one indirect drop per frame in both runs. Both runs rendered walls, window mesh, and the yard, with the existing lower-screen blocks present. I stopped both after the sample, and neither logged device removal.

These are single runs with the same camera and different yard animation and draw counts. They measure the two switches together. Nine indirect tests passed on the same source tree, with the benchmark left ignored.

AI-assisted testing and analysis. Settings and aggregate measurements only.

@HLVM04

HLVM04 commented Nov 25, 2026

Copy link
Copy Markdown

A data point from an RTX 5070 Ti (16 GB, wave32 only, NVIDIA 616.64, Ryzen 7 9800X3D), Series S profile, on 9376fd6 + #798 + #783 + #799. Scripted Enter input, first gameplay scene, numbers from the frame lines.

median ms a frame mean ms a frame preparing ms
both off 169 268 106
VICTORY_INDIRECT_KEEP=1 + VICTORY_INDIRECT_WINDOW=1 158 201 77

No device loss in 4 runs. The scene is not identical between runs, so the median gain is small and could partly be variance; the mean and the preparing time moved more.

@LeonardoS11

Copy link
Copy Markdown
Author

Closing: f85101b does this and a little more — the scratch stays in INDIRECT_ARGUMENT after a clamp until the next clamp takes it straight to unordered access, and goes back once when the list closes, so the executions record no barrier of their own. The numbers here and the two reports above (thanks, both) stand as a confirmation of that change on three NVIDIA cards. (Written with Claude Code.)

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.

3 participants