GPU: hoist and batch indirect argument clamps into the list prelude #2470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2472"
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?
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T14:18:15Z.
## Summary
Hoists and batches indirect draw argument clamps (
indirect::bound) from inline per-draw compute dispatches into a single batched compute pass insideHostList::prelude, eliminating per-draw global UAV barriers, graphics-to-compute context switches, buffer state transitions, and forced graphics PSO rebinds (self.host_pipeline = 0) across runs of indirect draws.Why this matters
Previously, every
ExecuteIndirectcall ran inline:UAV(None)barrier,Dispatch(1, 1, 1)(clobberingself.host_pipeline = 0),UAV(None)+UNORDERED_ACCESS -> INDIRECT_ARGUMENTbarrier,ExecuteIndirect,INDIRECT_ARGUMENT -> COMMONbarrier (indirect::done).In scenes with ~9,000 indirect draws per frame, this inserts ~18,000 global UAV barriers, ~18,000 resource transitions, and ~9,000 graphics/compute switches per frame.
Design & Soundness Invariants
BATCH_SOURCEincrates/victory-gpu/src/indirect.rs):[kind, stride, records, src_offset, dst_offset, 0, 0, 0]from a persistent per-HostListupload buffer (mirrored in host RAM so mid-list growth never reads back from write-combined upload memory, and reused acrossHostList::reset()with zero per-frame allocations in steady state).nevermutating or transitioning title-owned buffers) and writes clamped records into disjoint 16-byte-aligned slices of the list's own scratch chunks (COMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENTin the prelude, restored toCOMMONonce atend_hoisted_indirect()/HostList::close()).2^24vertices,2^26vertex instances,65535groups/dim,2^20dispatch groups,2^27per-list budget) and exact sequential budget charging as the inline shader.records == 1) jobs in parallel across all 64 lanes in one wave, falling back seamlessly to the 64-lane tiled loop forrecords > 1, with explicit[branch]/[loop]+breakguards so FXC never emits out-of-bounds root-SRV or LDS loads.Dispatch(1, 1, 1)per contiguous run sharing(src_gpu, dst_gpu)(with aUAV(None)barrier between distinct runs to keep bothbudgetand adjacent slices of the same scratch chunk coherent), preceded by oneUAV(None)barrier for earlier lists' writes and followed by a single batched[UAV(budget), Transition(chunk: UNORDERED_ACCESS -> INDIRECT_ARGUMENT)...]barrier.kind != DISPATCH) whose pipeline does not write to any buffer UAV (!pipeline_writes_uav(p)— checkingmarks,root_uavs,memory_dirty,heap_writes, tableResourceType::Uav, andROOT_UAV_VIEW) are hoisted. (No per-buffer overlap map is needed because hoisted jobs read title buffers strictly read-only and write disjoint scratch offsets.)prepare/prepare_forruns before enqueueing a hoisted clamp, so dropped draws no longer clamp arguments or spend list budget.ClearUnorderedAccessView*,external::record, non-hoistable indirect call, orHostList::close()callsHostList::end_hoisted_indirect(), transitioning hoisted scratch chunks backINDIRECT_ARGUMENT -> COMMONonce and falling back to the existing inlinebound/donepath for the remainder of the list.HostListwithoutreset()preserves its hoisted jobs and re-clamps cleanly.Verification
cargo test --release -p victory-gpu --locked -- --ignored --nocapture benchmark_hoisted_vs_inline_indirect_clampson NVIDIA GeForce RTX 3060 Ti, Windows 11):9000 indirect draw clamps: inline 45.28 ms/frame vs hoisted 2.14 ms/frame (21.1x)(measuring clamp dispatches + barriers alone, before savings from eliminating interleaved graphics PSO rebinds and graphics/compute switches).indirect::, latestc673921):25/25acrossindirect::+draw::).VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_GBV=1 RUST_LOG=warn,--features diagnostics): 12 passed, 0 failed, zero D3D12 warnings or errors.VICTORY_D3D12_WARP=1,--features diagnostics): 12 passed, 0 failed.cargo clippy -p victory-gpu --all-targets --all-features --locked— 0 warnings in modified files.cargo xtask policy—asset policy: 184 files ok.(Authored and verified with AI assistance; synthetic GPU tests and benchmarks only, no game files or data.)
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:35:19Z.
Review: APPROVED
Verified against
origin/main(940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:diagnosticsbuilds.cargo test -p victory-gpu indirect::: 11/11 passed on RTX 5090, 11/11 passed on WARP (1 benchmark ignored).cargo test -p victory-gpu draw::tests: 5/5 passed on RTX 5090.cargo clippy -p victory-gpu --all-targets -- -D warnings(both default and--features diagnostics): 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:57:37Z.
Review: COMMENTED
Hoist and batch indirect argument clamps (+973). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Large perf change; needs hardware validation.
Imported from Marvisak/VIctory. Originally posted by Bj0rnis on 2026-11-25T14:26:58Z.
Independent Windows 11 hardware + WARP verification of #2472 at
ec12173a(cleangit merge-treewithorigin/main940d32f, Rust 1.98.1 MSVC):cargo test -p victory-gpu --features diagnostics --lib --locked -- --test-threads=1-> 150 passed, 2 failed, 3 ignored (the 2 failures are the pre-existing #1744 NVIDIA 1M view-heap baseline failures also present onmain940d32f). All 11 non-ignoredindirect::tests(6 new hoisted/batched clamp tests + 5 existing), plusdraw::testsandhost::tests, passed on RTX 5070 Ti.VICTORY_D3D12_WARP=1): 152 passed, 0 failed, 3 ignored (1.04s).cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings-> 0 warnings.cargo xtask policy-> 182 files ok.Not tested: live game workload / frame-time benchmark (
benchmark_hoisted_vs_inline_indirect_clampswas not run).AI-assisted test run and summary.
Imported from Marvisak/VIctory. Originally posted by r4tedx on 2026-11-25T15:09:21Z.
Tested
ec12173aon WARP (VICTORY_D3D12_WARP=1, diagnostics build,--test-threads=1). Nice approach: clamping the prefix in the prelude leaves no clamp work in the list itself, and the overlap check makes it safe to move the in-place clamp.cargo test -p victory-gpu --features diagnostics --lib: 153 passed, 0 failed, 4 ignored.indirect::withVICTORY_D3D12_DEBUG=1: 12 passed, 2 ignored, with no debug-layer messages from the prelude, the job buffer or theGENERIC_READtransitions. The one error printed is a SAMPLER_HEAP root-signature message raised during the first test of the run, before any hoisting; we see it on other branches too.Equivalence with per-call clamping. I ported the equivalence test from our batched-clamp branch (r4tedx/VIctory
gpu/batched-clamps-upstream, 2ec823e4) to thehoistAPI:end_hoisted_indirect, then 10 clamped per call.Every word matches 160 per-call clamps (471 draw records ran, 569 ran empty). Happy to send the test if you want it in the PR.
Bench (WARP, synthetic): 1,500 indirect dispatches of no groups, median of 7. The first timestamp is in a list submitted before the measured one, so the prelude is counted.
Recording took 2.01 ms per call and 4.59 ms hoisted, in an unoptimised test build, so only the ratio means anything.
Points that may matter as other PRs land:
records. A hoisted counted call would then use up the budget faster than the same call clamped per call.spanreturnsNone) and any overlap end hoisting for the rest of the list. That costs speed only. #2168's early return for zero records would avoid the first.prepareruns before the clamp is queued, so a draw that gets dropped no longer charges budget. The per-call path still clamps first. When a dropped draw is heavy, the two paths therefore give later draws different budgets. Either is fine, but it is a difference.GENERIC_READuntil the prefix ends. A prefix pipeline that reads one of them through a UAV view without counting as a writer would see a state mismatch. I didn't check this with GPU-based validation.The title was not used in these tests.
AI-assisted
Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T15:14:19Z.
Thanks for the RTX 5090, RTX 5070 Ti, and WARP / equivalence / benchmark verification @DenRakEiw, @Bj0rnis, and @r4tedx!
Addressed point #2 from @r4tedx in
1b1fedd:(Note on point #1: once #2168's count_buf clamp lands on main, we can trivially extend the packed job descriptor with has_count / count_offset + count_buf SRV binding.)
Imported from Marvisak/VIctory. Originally posted by Vedoxdev123 on 2026-11-25T15:53:44Z.
Tested on Windows with AMD Ryzen 5 5600X + NVIDIA GeForce RTX 4060:
cargo test -p victory-gpu --lib-> 147 passed; 2 failed; 3 ignoredAll existing and new tests in this branch pass on RTX 4060; the only 2 failures are the known 1,000,000 view heap cap tests (
dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_viewsfrom #1744).Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T16:20:51Z.
Rebased onto
origin/main(67e8ae1) at187db6fand adapted cleanly to315cea1's non-destructive scratch-buffer clamp design:HoistedClampsreads the title's argument buffers viaSRV(t1)and writes clamped records into per-list 256 KiB scratch chunks (COMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENTin the prelude,INDIRECT_ARGUMENT -> COMMONonce atend_hoisted_indirect()/HostList::close()). This eliminates overlap tracking, drops thecapture.rsdiff completely, and resolves point #4 from @r4tedx (no title-buffer state change during the prefix).315cea1parity:BATCH_SOURCEmatchesSOURCEword-for-word (including zeroing word 0 pastBUDGETand preserving trailing fields), andhoisted_transitions_start_from_current_states_and_never_touch_title_bufferverifies every emitted barrier withhost::tests::issued()+replay().--release):9000 indirect draw clamps: inline 45.28 ms/frame vs hoisted 2.14 ms/frame (21.1x)(~43.1 ms/frame saved).indirect::+draw::+twin::25/25), D3D12 Debug Layer (12/12, 0 warnings), WARP (25/25), strict Clippy (--all-targets&--all-features, 0 warnings),cargo xtask policy(184 files ok).Thanks also to @Vedoxdev123 for the RTX 4060 run!
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:10:59Z.
Automated triage for the maintainers.
Merge candidate (kept). Re-reviewed at
c673921. The only new commit since the last verdict hardensBATCH_SOURCEincrates/victory-gpu/src/indirect.rs:[branch]guard, so tail lanes never read pastjobs.&&, which FXC does not short-circuit and which could readcosts[64].GROUPS / g.ztest is nested under ag.z != 0check.payload), so a grown upload buffer is filled from memory rather than read back from write-combined memory.UAV(None)barrier.These are all safety fixes. The clamp bounds and in-order budget charging still match
SOURCE, and the hoisting conditions are unchanged from the head I reviewed before.The known differences are still worth a maintainer's note. A hoisted draw that is dropped no longer charges the budget. After #2168, the batched path would need its own count-aware charge. The speedup comes from synthetic benchmarks only. Merges cleanly; CI:
checkpassing.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:06:12Z.
Traced the full path; the design is sound and the hazards I went looking for are covered:
end_hoisted_indirectat every site I could find that emits a write:bind(compute orpipeline_writes_uav),clear_unordered,external::record,close, plus the non-hoistable branches ofindirect()itself.lane==0prefix walk),PAST = 0xffffffffis unreachable as a real cost (draw ≤2^26, dispatch ≤2^23), the budget zero-step is registered once per list viabudget_zeroed, and per-runUAV(None)barriers keep bothbudgetand same-chunk tail slices coherent between dispatches.g.x * g.y > GROUPS / max(g.z,1)survives in u32 by 131 KiB of headroom (65535² < 2^32) — correct, but worth a comment; a future "just clamp to 2^17" would silently overflow into garbage costs.BTreeMapoverlap check for hoisted arg spans — there's none in the diff. Not a hazard (hoisted jobs are read-only on src and write disjoint scratch), so the check was presumably dropped as dead weight — but the body should say so.alloc_room's chunk reuse,payload/upload mirroring on grow,keep_onceraw-pointer dedup, and therestoredidempotence for re-submit-without-reset all check out. The 32x benchmark number is believable given ~18k eliminated barriers per frame.Imported from Marvisak/VIctory. Originally posted by ESAT586 on 2026-11-25T20:27:05Z.
Thanks for the thorough trace and verification, @kotekompotek! Updated the PR description to match the current non-destructive scratch design (removing the obsolete BTreeMap overlap-check description from the pre-315cea1 in-place revision). Good catch on 65535² < 2^32 headroom as well.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T00:38:34Z.
Code review (same-list GPU-write hazard audit) and RTX 5090 + WARP verification at head
c673921cc134merged cleanly ontomain(63bcca43c6a0):HoistedClampsis restricted strictly to the initial GPU-write-free prefix of each command list (indirect.rs:386-392). Every GPU-write path irreversibly terminates hoisting vialist.end_hoisted_indirect()(transitioning used scratch chunks back fromINDIRECT_ARGUMENTtoCOMMONand settinghoistable = false): compute dispatches (draw.rs:617-619), UAV-writing graphics pipelines (pipeline_writes_uavatdraw.rs:2002-2017, coveringmarks, root UAVs,s.memory,heap_writes, table/root UAVs, andROOT_UAV_VIEW),clear_uav(draw.rs:1081),external::record(external.rs:44), indirect dispatches (draw.rs:1775, 1821), andHostList::close(host.rs:1768). Subsequent indirect calls fall back to inlineindirect::bound, while CPU-side deferred copies/refreshes complete before the prelude andrecord_preludeopens with a global UAV barrier.VICTORY_D3D12_DEBUG=1, Rust 1.98.1):--features diagnostics,indirect::tests draw::tests host::tests): 63/63 passed, 1 ignored (benchmark_hoisted_vs_inline_indirect_clamps)indirect::tests draw::tests host::tests): 62/62 passed with 0 Debug Layer errors (including all 5 newhoisted_*tests; excluding only the pre-existing NVIDIA 1M heap-cap baseline testdescriptor::host::tests::dynamic_slots_are_held_until_released)cargo xtask policy:191 files ok;cargo clippy --locked -p victory-gpu --tests -- -D warnings(default +--features diagnostics): 0 warnings.Hazard boundaries are airtight and hardware/WARP runs are clean; LGTM.
Imported from Marvisak/VIctory. Originally posted by MeMako on 2026-11-26T01:18:38Z.
Independent verification of
c673921on AMD Radeon RX 9070 XT (adapter 0, driver32.0.32029.2010, Ryzen 9 7950X, Windows 1110.0.26200x64).CI checks & synthetic GPU benchmark:
cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings(and--all-features): passcargo test -p victory-gpu --locked: 240 passed, 0 failed (all 12indirect::testspass on RX 9070 XT)benchmark_hoisted_vs_inline_indirect_clamps(release build, RX 9070 XT):9000 indirect draw clamps: inline 52.02 ms/frame vs hoisted 2.50 ms/frame (20.8x)Live title run (release build, warm shader & pipeline cache):
(Note: merged cleanly onto a local RX 9070 XT playtest branch on
842b0cbcontaining a separate-handle workaround equivalent to #2122,DYNAMIC = 1 << 19, and #2051; before/after compared against the exact same branch without #2472.)draws >= 200, excluding menus/pause)n=29)n=31)183.1 ms/182.0 ms161.8 ms/174.1 ms572.2 ms(1.70 fps)523.2 ms(1.90 fps)0/0/00/0/0The run later ended in an unrelated title-side access violation (
0xfc00fc00fc007c00read on title worker threads) with no GPU removal or indirect errors.No game data, shader names, or screenshots are included, per
docs/asset-policy.md. Hardware runs were performed by me on my RX 9070 XT; comment drafted with Antigravity.Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T03:02:07Z.
The batch prelude needs the same mesh-grid rule as #2996 when these two patches meet. I tested the clean merge of
c673921cwith9a851cd3and counted actual mesh shaderSV_GroupIDvalues on RTX 5080 and WARP.On the merged tree, a single valid
(3,2,4)record ran 24 groups through the inline fallback and 3 through the hoisted path. A set of 66 small records ran 512 groups inline and 132 hoisted. The directDispatchMeshcontrol matched inline at every coordinate on both adapters.In the scratch build I applied #2996's bounded-grid decision to the mesh branch reading
src_args.Load3(src_at)in the batch HLSL. With that change the hoisted path matched the inline and direct controls across all 64 coordinate counters for all three fixtures, including padded strides and the 64-record boundary. The merge applies cleanly as written, so Git alone won't surface the missing change. Companion PRThe change is now available as a single cherry-pick on top of the two PRs. It credits the original mesh-grid implementation and adds an explicit
[10, 4, 3]readback to the batch-versus-inline regression. The updated regression passed on both adapters. Cherry-pick0689282Imported from Marvisak/VIctory. Originally posted by steven-seagull27 on 2026-11-26T04:06:46Z.
@andrewpozdnakov7-jpg’s translated mesh-group fix changes what #2472 should put into the precomputed argument buffer. The earlier integration preserved the three grid dimensions. VIctory supplies the translated mesh shader with a scalar group index derived from X. If the batch kernel preserves Y and Z after the inline kernel has started flattening the grid, it schedules the right number of groups with repeated indices.
I merged the original commits and compared direct scalar-index dispatch, inline clamping and batch clamping. The table counts distinct scalar indices touched, with every one of the 64 counters checked. RTX 5080 and Windows WARP gave the same results in two fresh processes each.
(3,2,4)record, 12-byte strideMultiple records start numbering at zero, so a correct counter can receive more than one hit. For the single record the old batch hit the same three counters eight times. The corrected batch hit each of 24 counters once.
On RTX I also ran a read-only translated mesh shader through the normal
State::execute_indirectdecision. The test confirmed the list actually queued the batch clamp. Its(3,2,4)draw covered 3 of 24 depth columns before the change and all 24 after, in agreement with inline. WARP’s evidence above is from group-counter readbacks. The separate WARP depth probe did not provide a valid pixel result. This checks VIctory’s current scalar input convention; console hardware numbering for multidimensional dispatch remains unmeasured.Integration commit. The branch includes both PRs, the earlier batch integration, and the original
5385cc6with its author. The new commit also checks that a valid(10,4,3)record becomes(120,1,1)in the batch buffer. The four stock mesh/batch tests passed on both adapters, as did strict all-feature GPU Clippy and asset policy.AI-assisted with Codex. Synthetic draws and readbacks.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:51:04Z.
Review: APPROVED
Reviewed
c673921cacrossdraw.rs,external.rs,host.rs, andindirect.rs, and confirmed a cleangit merge-treeagainstorigin/main(63bcca43).Key invariants checked:
end_hoisted_indirect()closes the prefix and returns all used scratch chunksINDIRECT_ARGUMENT -> COMMONonce before any compute bind, UAV/memory/heap-writing graphics pipeline (pipeline_writes_uav),clear_unordered, non-hoistable indirect call,external::record, orclose().BATCH_SOURCE(c673921c) guards tail lanes with[branch]before root-SRV loads and avoids FXC non-short-circuiting oncosts[64]; relativesrc_offset + len <= u32::MAXandHOIST_CHUNKbounds are enforced inHoistedClamps::push; prelude barriers (UAV(None)-> chunkCOMMON -> UAV-> per-runUAV(None)->UAV(budget)+ chunkUAV -> INDIRECT_ARGUMENT) order cleanly after earlier lists' compute writes and allow re-submission of closed hoisted lists.Verified locally on Windows 11 (RTX 5090 + WARP +
VICTORY_D3D12_DEBUG=1):cargo clippy --workspace --all-targets [--all-features] -- -D warnings: clean;cargo xtask policy:184 files okindirect::: 12/12 passed (1 ignored benchmark)VICTORY_D3D12_DEBUG=1indirect::: 12/12 passed with zero Debug Layer warnings/errors (includinghoisted_prelude_orders_after_earlier_list_compute_write)--features diagnostics,VICTORY_D3D12_WARP=1) +VICTORY_D3D12_DEBUG=1indirect::: 12/12 passedbenchmark_hoisted_vs_inline_indirect_clamps, 9,000 draws):inline 38.45 ms/framevshoisted 2.35 ms/frame(16.3x)LGTM.
Imported from Marvisak/VIctory. Originally posted by imjustprism on 2026-11-26T09:26:37Z.
ran this in the title on an rx 9070 xt, merged onto
63bcca4plus #2122 (this card's driver crashes in its shader compiler without that one). nothing broke: about six minutes in the world, no device removed, no warnings, dropped draws per frame in the same range as before. i did not compare pictures.i could not measure a change in gpu time though. this is gpu ms per frame from the frame lines, bucketed by draws per frame because the scene moves on at a different pace in each run:
diag build with the diagnostics feature and no switches set, series-x, the same key presses, warm shader and pipeline caches, one run of 11 minutes each, about 60 world lines each. with one run each, 10 ms in a bucket is noise.
a line fit over all world lines gives 60 ms + 26 us per draw before and 69 ms + 27 us per draw with it. so on this card most of the gpu time is a fixed part per frame, and the cost per indirect call is not where it goes.
what may explain the missing gain: a captured world frame here has about 1,100 indirect calls and about 490 of them are dispatches, which this change leaves inline and which end the prefix. i did not count how many calls took the hoisted path in the title. a hoisted / inline count in the frame line would answer that, and would show what the 3060 ti number turns into in a real frame.
from reading the diff, three small things, none of them a wrong result that i could find. the prefix rule holds on every path i followed (compute or uav-writing bind, uav clear, the non-hoistable branch, external record, close), and the cpu refresh of the arguments lands before the prelude reads them.
preparebefore the clamp, the inline path clamps first. a call thatpreparedrops used to charge the list budget and now does not, so later records can run where they were zeroed before. fine by me, but the description says the charging is exactly the same.record_preludereturns a bool thatHostListdrops, and a missing budget resource skips the prelude silently. i believe neither can happen oncecan_hoistsaid yes, but if it ever does, the body runs ExecuteIndirect on chunks that were never clamped. afailthere would make it loud.hoist()directly. none records a dispatch, a uav-writing draw or a uav clear earlier in the same list and checks that hoisting stopped, and that rule is the whole correctness argument.Imported from Marvisak/VIctory. Originally posted by KainanP on 2026-11-26T16:22:56Z.
CPU cost per call of
c673921, measured with the list bench from #2586 next to #3197. The same numbers are on #3197.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 the batched clamp this PR records at submission counts against it. 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:DrawIndexedInstanced(2.7 µs on main, 1.1 µs on the stack) is ~0.3–0.5 µs (argument refresh and job write, not split further). The prelude's batched pass is included in these figures.Dispatchon main), by design.Your GPU benchmark on another card (
benchmark_hoisted_vs_inline_indirect_clamps, 9,000 clamps, CPU recording excluded): RTX 4060 Laptop 37.6–39.5 ms inline vs 2.10–2.12 ms hoisted (17.7–18.8×, 3 runs). Intel UHD (a78b) 67.3 vs 3.1 ms (21.7×).Tests,
c673921merged on63bcca4,cargo test -p victory-gpu --release --lib:--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. 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.
Imported from Marvisak/VIctory. Originally posted by Coderlord on 2026-11-26T22:03:09Z.
A data point on the GPU-time question (the RX 9070 XT run above saw no change), from an NVIDIA card. It is not this PR's code: it is the same idea in fxceless/victory-fork, whose clamp windows (
VICTORY_INDIRECT_WINDOW=1,VICTORY_WINDOW_JUMP=1) and gathered clamps (VICTORY_INDIRECT_GATHER=1,VICTORY_GATHER_SEGMENTS=1,VICTORY_GATHER_DISPATCHES=1) clamp a list's indirect records in a few passes instead of one clamp dispatch between barriers per call. So read it as a measurement of what the per-call barriers cost, not of this implementation.RTX 5080 (driver 621.40), Windows 11, Series S profile at half render scale, standing in the first room of the prologue; two timing runs (
VICTORY_GPU_TIMING=1, each list timed alone), card time a frame:With per-call clamps each one-record indirect call took about 10 µs of card time, whatever it drew: the card drains at the barriers around each clamp. On this card that drain is most of the indirect commands' cost, so batching the clamps (this PR, or #3197's windows) should show on NVIDIA even where it does not on RDNA 4.
Found, written and tested with Claude Code.
Imported from Marvisak/VIctory. Originally posted by TheGrayOrange on 2026-11-27T01:38:07Z.
Verified
c673921on WARP through the actual recording paths, addressing the earlier same-list UAV-clear coverage concern.Two eligible indirect draws remained hoisted, followed by a UAV clear and an inline indirect draw. Pipeline statistics returned the expected vertex counts
[3, 6, 1].Removing only the clear's batch boundary produced
[3, 6, 6], confirming that the fixture detects stale arguments.Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T04:13:31Z.
Tested in game on an RTX 5090 (driver 620.73.04), Linux, GE-Proton11-14 Wine with its vkd3d-proton, GTA VI's opening prison yard, on
mainplus the unmerged PRs this setup needs (#3312, #3318 and others; full list in #3425).Under Wine the batched clamp never runs. Wine's
D3DCompile(vkd3d-shader HLSL) rejectsRWByteAddressBuffer::Loadand ignores[RootSignature], sobatch_clamp()isNoneand every draw falls back to the single clamp. Every run's log shows:Fix, as #1279/#2969 did for the single clamp: the budget becomes a
RWStructuredBuffer<uint>, and the root signature is built in Rust in the orderrecord_preludebinds. That's52622595, with a test (every_clamp_compiles_without_a_root_signature_attribute) that compiles every clamp shader without a device, so CI under Wine catches it.The hoist also stops at the first G-buffer draw.
pipeline_writes_uavrefuses any pipeline withp.marks.is_some(), and nearly every pixel shader has marks because it read-marks the textures it takes from the heap. A write mark can't exist without one of the flags the predicate already tests:mark_view_writeonly marks heap-made unordered views, which come from tables (used), the heap (heap_writes) or root UAVs (root_uavs/ROOT_UAV_VIEW), and title-memory writes go throughmemory. Without those flags the marks are read marks into our own bitmap (u1, space 2), which is never title memory, so never an argument or count buffer.aef55c74dropsmarksfrom the predicate (merged with #3197'smay_storeinto one), with a CPU test per disqualifying case.Measured (untimed, 600 s, medians of the last 30 frame-rate lines, adjacent runs so drift between periods doesn't enter):
A timed run before the fix counted 4,909 inline clamps per frame, 35.4 ms of GPU time (7.3 µs each, 23% of command time). Pictures at two late frames match the control (mean difference 2/255). On the GPU (vkd3d-proton, RTX 5090) all 22
indirect::tests::pass on the combined branch, including #3197's six window tests and the hoist tests, and the 5draw::tests::clamp-gate tests pass.AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by neonbyte1 on 2026-11-27T04:23:36Z.
Timed follow-up (same setup,
VICTORY_GPU_TIMING=1, every command in the table, last 30 reports), before and after the commits above:So the draws themselves got about three times cheaper, not only the clamps: with a barrier, a one-group dispatch and a rebind between every two indirect draws, the draw stream itself paid far more than the clamps' own 7 µs each. The 1,133 clamps left are the 920 indirect dispatches (never batched) plus window openers.
AI-assisted (Claude); measured on my machine, no game data shared.
Imported from Marvisak/VIctory. Originally posted by zed6000 on 2026-11-27T12:08:57Z.
An AMD measurement alongside #3197's (details and setup in my comment there): RX 7900 XTX, diagnostics builds merged onto
main63bcca4, intro cutscene, two runs each, medians of 36 frame-report lines.GPU ms/frame:
main153.1 and 152.0; this PR 151.5 and 151.5; #3197 132.5 and 132.4.cargo test -p victory-gpu --lib: 237 passed, merged cleanly.In this title the rule here (from a list's start to its first writing command) rarely applies. In a similar attempt of ours, only about 12 of 5,130 indirect executions per frame qualified, so the batched pass seldom forms. #3197's windows reach far more draws.
Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-27T22:33:41Z.
Native Windows / NVIDIA at
c673921c(the PR as is; base67e8ae14): RTX 3070 8 GB (driver 616.56), Windows 11 26100.batch_argument_clamp_builds, which assertsbatch_clamp().is_some()when a host GPU is present, passes. Under Wine the same shader failsD3DCompile(#3425), so the "no effect" row there is the inline fallback, not this change.cargo test -p victory-gpu --lib indirect::: 12 passed, 0 failed in each of 3 runs, the hoisted-vs-inline, multi-buffer, state-transition, resubmission and prelude-ordering tests included. The fullvictory-gpulib: 199 passed, 2 failed, the two capped-heap NVIDIA tests that fail onmaintoo.benchmark_hoisted_vs_inline_indirect_clamps, release, 3 runs:That is for 9,000 indirect draws a frame, the count the description gives. No title run here.
AI-assisted (Claude Code, Claude Opus 5.5 ran the tests and the benchmark).
Imported from Marvisak/VIctory. Originally posted by xianyu408 on 2026-11-30T09:29:37Z.
A-B measurement of this branch against the other approach, same card, same data and shader cache
(RX 6700 XT 12 GB, RDNA2, Series S profile, 1080p output). All three builds are upstream
mainplusone change, so the numbers compare like for like; in-world samples, ~18 per run, seconds apart:
VICTORY_CLAMP_WINDOW=1So on this card both help against main, and the window takes a bit more off than the hoist
(-15% against -7%). The spread between runs is large here (upstream
maincopies 220-250 MB a frameand is CPU-bound on this machine), so I would not read much into the 8% gap between the two; the
"either one, not both" call is probably not going to be decided by this card.
What would decide it here: the hoist only covers a list's initial non-writing stretch, and this title
seems to interleave draws with commands that write buffers, so fewer clamps can move. The window
recovers them anywhere in the list. If a cheap counter of "clamps hoisted of clamps seen" is easy to
print under diagnostics in this PR, that number on a real scene would settle it.
Context: on the AMD-tuned fork the reporter runs (3,400 clamps a frame, 67-77 ms of GPU time inside a
196 ms frame), the clamps are a much larger share than on upstream main, so both PRs should be worth
more there than these numbers suggest.
Reporter: xianyu408, also commenting on #3197 and issue #3876.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.