GPU: clamp consecutive indirect draws in one pass (VICTORY_CLAMP_WINDOW, opt-in) #3197
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3197
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3197"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Slay326 on GitHub · 2026-11-26 12:06 UTC · original
Slay326:pr/clamp-window→main· +760 −18 · 5 files · 4 commits · openRelation to #2472
This overlaps with #2472 by ESAT586, which takes the same approach: it batches the per-draw argument clamps of runs of indirect draws into fewer passes. Either this PR or #2472 should be merged, not both. Both batch the same clamps but reach different draws: #2472 the start of each list up to its first writing command, this PR anywhere in the list (each window ends at the next other draw). If #2472 is merged, I will close this and only bring the remaining windows back as a follow-up on top of it if in-game numbers show it matters.
I am opening it because we measured this version in game, so the numbers below may help with the decision. The differences I can see:
VICTORY_CLAMP_WINDOW=1; with the variable unset it is the same path asmain.Problem
Each indirect execution gets its own argument clamp (
indirect::bound). That is a UAV barrier, a one-group compute dispatch, another barrier and a transition, then the draw with the graphics pipeline bound again. In the world that comes to about 5,100 clamp passes a frame. The card switches from drawing to compute and back for every record, and no draw overlaps the next. Measured with GPU timestamps, the clamps alone took about 29 ms a frame.Change
Only
crates/victory-gpuchanges. WithVICTORY_CLAMP_WINDOW=1:indirect.rs: an indirect draw (not a dispatch) whose pipeline stores to no buffer opens a window. The window costs one UAV barrier and one clamp dispatch, placed where the single clamp would be. The clamp shader reads a table in the list's upload memory. The CPU fills that table while it records the following draws, and the GPU reads it only when the list runs. Each following draw that can join appends its record and reads its arguments from its part of the window's buffer. It needs no pass, barrier, transition or pipeline rebind of its own. The budget is charged in draw order, with the same bounds as the single clamp.A window ends at:
external.rs)host.rs)A new window starts when one is full (64 draws, 64 KiB, 4,096 records) or when the arguments come from a fifth source buffer.
draw.rs:execute_indirectuses the window when it can, and the single clamp as before when it cannot.may_storedecides.copystat.rs(diagnostics only): a "clamps per frame" line, printed only with the variable set. It counts single passes, windows, draws per window, and the draws clamped alone because they may store.The switch is off by default. With the variable unset, the only added work is one cached flag check per draw and one at each list close and reset. The clamp shader is compiled by the host, so the translator's source hash and shader caches stay as they are.
Tested
Windows 11 Pro 26200, RTX 3070 8 GB (driver 610.88), title 1.0.2.1, release +
diagnostics, BVH on,VICTORY_BACK_THREADS=4. 480 s runs in A-B-A order, same shader cache.mainalone cannot be measured on this card: it runs at 0.1 fps because the view heap overflows without #1779. The numbers therefore come from our test stack, an older main plus open NVIDIA PRs (among them #1762, #1779 and #2242/#2280/#2409). This commit, with the variable set, was the only change between A and B:VICTORY_CLAMP_WINDOW=1Unit tests, all with synthetic data (garbage records, no game data):
windows_clamp_as_single_clamps_do: a window gives the single clamp's results word for word. Cases: garbage records, the budget running out mid-window, more than 64 draws, two sources, and a 100-record draw across two tiles.a_window_after_a_spent_budget_runs_emptya_store_ends_the_window: includes the counter-check that a window left open would read the old value.a_window_clamps_max_records_whatever_the_countwindows_leave_the_argument_buffer_common: in any list order.Checks on this branch (
origin/main63bcca4+ this commit), RTX 3070:cargo test -p victory-gpu --release -- --test-threads=1: 249 passed / 2 failed withdiagnostics, 234 passed / 2 failed without. The two failures are the known heap-size pair on NVIDIA (dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views), which fail onmaintoo.cargo clippy -p victory-gpu -p victory-hle --all-targets -- -D warnings: clean with and withoutdiagnostics.cargo xtask policy: ok.Not addressed
draw.rs,host.rsandexternal.rsend windows is covered only by the game runs.AI-assisted.
@steven-seagull27 on GitHub · 2026-11-26 12:13 UTC · original
Tested the library-recording boundary on RTX 5080 and Windows WARP. I recorded two valid draw-argument records, replaced both records with a native GPU
CopyBufferRegionthrough the publicexternal::recordcallback, then clamped the same two offsets again. Each result below repeated in two fresh processes per adapter.63bcca43cf33c260c673921cAs a negative control I removed only the
end_window(host)call inexternal::record. The source buffer still contained all eight replacement words, but the clamp returned eight stale words out of eight after the callback on each adapter. For example, the first updated draw was[9, 3, 11, 2]and the unclosed window returned[3, 1, 7, 0].This exercises the actual public library callback and GPU copy. The harness called the clamp entry points directly and read their output buffers. It establishes ordering at that boundary, without drawing a frame or estimating frame time. Alternative PR
@Dukestar69 on GitHub · 2026-11-26 12:51 UTC · original · approved these changes
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-gpu --lib indirect:: -- --test-threads=1: 11/11 passed on RTX 5090 and WARP (includinga_store_ends_the_window,a_window_after_a_spent_budget_runs_empty,a_window_clamps_max_records_whatever_the_count,windows_clamp_as_single_clamps_do, andwindows_leave_the_argument_buffer_common).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Clean opt-in
VICTORY_CLAMP_WINDOWbatching for consecutive indirect draw clamps.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@slauko on GitHub · 2026-11-26 13:29 UTC · original
Ported this window to a Linux/Wine line (RTX 3080 Ti, vkd3d-proton
ec20719, uiliannn's base) — it is the piece that finally served this title's mesh draws, and the numbers may help your decision with #2472:Before (
VICTORY_CLAMP_WINDOWoff, this line's older step-based window on): 1,757 to 1,796 indirect clamps a frame in the cell — 313 to 360 compute dispatches, 1,186 to 1,230 mesh draws (kind 10) clamped one at a time, ~250 draws. The mesh records lie in one ~100 MB argument buffer, 16 to 33,056 bytes apart from one draw to the next, so no step-based window can serve them (m42/m44).With your window (
VICTORY_CLAMP_WINDOW=1): 295 to 355 clamps a frame — only the compute dispatches are left, the mesh draws all join (m48). The cell's first steady line came 79 s after the launch, and the frame is in the 230s at ~3,600 draws in the run I could read before the steady stop; the settled-cell A/B is running now and I will add it.Two things a porter may hit on a tree that has an older step window as well:
m48) the count looked right but the two could overwrite each other's records. On this line the step window now yields whenVICTORY_CLAMP_WINDOWis set, and the clean run ism49.I did not take
may_store(this line'stranslated().storesis an ISA decode over the same accesses), thearguments-as-scratch, or the external/clear hooks (no such sites here).@slauko on GitHub · 2026-11-26 13:33 UTC · original
The settled-cell numbers, and they go the other way here — worth knowing before #2472's decision:
Same build, same switch set, only
VICTORY_CLAMP_WINDOWdiffers, the cell at ~5,000 draws:on the GPU, msm47)m49)So it does exactly what it promises for the counts — the 1,190 mesh draws that no step can serve all join, only the compute dispatches remain — and it loses 66 ms on the card. The reason is visible in the shader: the window's pass is one group that loops over every record of the run (
for tile ..., one group, to charge the budget in exact order). A run here holds a few thousand records, so that serial walk costs more than the ~1,790 per-call passes it replaces — where a step window's pass is64threads over one group of records and ends.What would win on this stack, if you take it further: the same table, but the records' bounds computed per group (one group per tile of 64, like the single clamp does) and the budget charged with the interlocked walk the single clamp uses, so the pass stops being serial. Your table is the part that is right; the pass's shape is what costs.
(The port is in my tree behind
VICTORY_CLAMP_WINDOW, off. Two porters' notes: the two window kinds must not run together — both write the list's indirect scratch at offset 0 — and a draw that cannot join has to end the open window before the single clamp writes that buffer.)@andrewpozdnakov7-jpg on GitHub · 2026-11-26 13:45 UTC · original
@Slay326 I checked
cf33c26together with #2996 at5385cc6. They merge cleanly as text, but the mesh argument clamp differs when the window is enabled. The same valid(3, 2, 4)input read back as[24, 1, 1]through the single clamp and[3, 1, 1]through the window. This drops 21 of the 24 mesh groups.The integration
d16ae7dretains both exact heads and applies #2996's group-count rule to the window too. The same GPU readback then agreed on both paths for(3, 2, 4)→[24, 1, 1]and(2, 3, 5)→[30, 1, 1]. The existing draw-order and budget tests passed.App-local Agility 1.620.2/WARP 1.0.22: 13 indirect tests passed. Full GPU diagnostics with
VICTORY_CLAMP_WINDOW=0and=1each had 255 passes, 0 failures and 1 ignored. Strict GPU Clippy with all features passed. This checks GPU argument readback with synthetic inputs.If both changes are taken, the integration is ready for the mesh-clamp side. Please retain the Git author on cherry-pick or rebase, or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>if folding the resolution into another commit. AI-assisted with Codex.@slauko on GitHub · 2026-11-26 13:49 UTC · original
I took the parallel shape you'd want next, and it is worse than the serial pass here — the numbers, so nobody spends the day on it:
m49/m50, the cell, ~5,000 drawsm47)on the GPU, msThe parallel version: one group per tile of 64 records, each tile's bounds worked out by its own lanes exactly as the single clamp does them, and the budget charged through the interlocked walk on the budget word (load, walk the tile, compare-exchange, retry).
The walk is the price. 64 groups retry one word and each retry walks its tile again; the exact order a single clamp had — one call at a time, each seeing the budget the one before left — is not recoverable by contending groups. So on this stack the ~1,790 tiny passes are cheaper than charging the budget in order, in both shapes, and the switch stays off.
What that leaves, if the count is what you want to fix: the order only matters for the budget. A window whose records are charged in table order on one group but with the tile's bounds precomputed (a first pass, one group per tile, writing each record's cost into the table) would take the serial walk down to 64 additions per tile — that is the shape I'd try next, but I'm not building a third variant before something else pays here.
@Slay326 on GitHub · 2026-11-26 15:14 UTC · original
Thanks for testing and for the detailed reports, I'm on it.
indirect.rs(single clamp and window), so a rule change like #2996 merges cleanly and then silently diverges. I have a fix that moves the rule into one sharedmesh_groups()function used by both shaders, plus a test that compares both paths word for word. I'm verifying it on hardware now and will push it here once it passes.AI-assisted.
@Slay326 on GitHub · 2026-11-26 15:20 UTC · original
Pushed the fix (
bdc4167, plus the testdff6c00): the single clamp and the window now share onemesh_groups()function, so a rule change like #2996 can no longer diverge silently between the two paths. No behaviour change on its own.Checked on an RTX 3070 (indirect tests):
windowed_mesh_grids_are_the_single_clampsfails withsingle [24, 1, 1], windowed [3, 1, 1], as reportedAI-assisted.
@KainanP on GitHub · 2026-11-26 16:22 UTC · original
CPU cost per call of
0c997d4, measured with the list bench from #2586 next to #2472. The same table is on #2472.Method. KainanP/VIctory@perf/list-call-bench now has
VICTORY_LIST_BENCH_INDIRECT=1(commit 427db003). It runsExecuteIndirectthrough the title's method table: one indexed draw or one dispatch per call, 2,000 calls per list, on 1 thread and on 5 threads at once, each thread with its own list. The pipeline reads six table textures, two root CBVs and four root constants, and stores nothing, so every draw in the list is eligible here. The list'sCloseis timed with the calls. For these runs only, I also timedHostList::prelude()at each close through a local test accessor (not on the branch), so #2472's batched clamp, which it records at submission, counts against #2472. This PR's window pass is recorded in the list, so it is timed with the calls. Each value is the best of 5 × 5,000 calls. Builds were interleaved, with the median of 7 runs on the stack and of 21 runs on main (three sets of 7). RTX 4060 Laptop, i7-14650HX, Windows 11, release. Four unrelated Python jobs were using the CPU throughout, which is why the builds were interleaved.63bcca4VICTORY_CLAMP_WINDOW=1The same on main + #1978 + #2821 + #3258 + #3274 + #3275 (the draw path with the texture-lock contention mostly gone,
perf/list-scale-base), median of 7:main, as described.Dispatchon main), by design.Tests,
0c997d4on63bcca4,cargo test -p victory-gpu --release --lib, each run once withVICTORY_CLAMP_WINDOWunset and once with it set to 1, with the same results:--features diagnostics,--test-threads=1): 252 passed, 0 failed.The failures are the same as on main on each adapter (the NVIDIA heap pair; on Intel that pair plus
a_texture_written_in_one_format_reads_in_another_through_a_placed_view). All 12indirect::tests pass on all three adapters, including the six new ones (windowed_mesh_grids_are_the_single_clampsamong them). On RTX,memory_tests::heap_direct_texture_reads_mark_their_heap_indexwas skipped because it access-violates on main here.AI use: Claude Code (Claude Opus 5.5) extended the benchmark, ran the measurements and drafted this comment.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 17:43 UTC · original
The latest
0c997d4shared mesh rule composes with #2996 once its flattening is applied in that helper. I also resolved the buffer-state conflict against #3307. On verified app-local WARP, the mixed window/single test preserved all records through a buffer grow and returned its buffers to COMMON. The translated mesh test visited the 24 expected indices with the window switch off and on, and all 15 indirect tests passed. Exact integration, full-suite results and the one transient descriptor-test failure. AI-assisted with Codex.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.