Skip to content

GPU: hoist and batch indirect argument clamps into the list prelude - #2472

Open
ESAT586 wants to merge 2 commits into
Marvisak:mainfrom
ESAT586:gpu/hoist-indirect-clamps
Open

ESAT586 wants to merge 2 commits into
Marvisak:mainfrom
ESAT586:gpu/hoist-indirect-clamps

Conversation

@ESAT586

@ESAT586 ESAT586 commented Nov 25, 2026 •

Copy link
Copy Markdown

Summary

Hoists and batches indirect draw argument clamps (indirect::bound) from inline per-draw compute dispatches into a single batched compute pass inside HostList::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 ExecuteIndirect call ran inline:

  1. Global UAV(None) barrier,
  2. Compute root signature + clamp PSO bind + 1-group Dispatch(1, 1, 1) (clobbering self.host_pipeline = 0),
  3. Global UAV(None) + UNORDERED_ACCESS -> INDIRECT_ARGUMENT barrier,
  4. Graphics PSO rebind + ExecuteIndirect,
  5. INDIRECT_ARGUMENT -> COMMON barrier (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

  • Non-destructive scratch-buffer batched clamp (BATCH_SOURCE in crates/victory-gpu/src/indirect.rs):
    • Reads packed 32-byte clamp jobs [kind, stride, records, src_offset, dst_offset, 0, 0, 0] from a persistent per-HostList upload buffer (mirrored in host RAM so mid-list growth never reads back from write-combined upload memory, and reused across HostList::reset() with zero per-frame allocations in steady state).
    • Reads title argument buffers read-only through an SRV (never mutating 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_ARGUMENT in the prelude, restored to COMMON once at end_hoisted_indirect() / HostList::close()).
    • Applies the exact same clamping bounds (2^24 vertices, 2^26 vertex instances, 65535 groups/dim, 2^20 dispatch groups, 2^27 per-list budget) and exact sequential budget charging as the inline shader.
    • Fast path clamps up to 64 consecutive single-record (records == 1) jobs in parallel across all 64 lanes in one wave, falling back seamlessly to the 64-lane tiled loop for records > 1, with explicit [branch] / [loop] + break guards so FXC never emits out-of-bounds root-SRV or LDS loads.
    • Runs one Dispatch(1, 1, 1) per contiguous run sharing (src_gpu, dst_gpu) (with a UAV(None) barrier between distinct runs to keep both budget and adjacent slices of the same scratch chunk coherent), preceded by one UAV(None) barrier for earlier lists' writes and followed by a single batched [UAV(budget), Transition(chunk: UNORDERED_ACCESS -> INDIRECT_ARGUMENT)...] barrier.
  • Strict prefix & hazard soundness:
    • Only graphics/mesh indirect calls (kind != DISPATCH) whose pipeline does not write to any buffer UAV (!pipeline_writes_uav(p) — checking marks, root_uavs, memory_dirty, heap_writes, table ResourceType::Uav, and ROOT_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_for runs before enqueueing a hoisted clamp, so dropped draws no longer clamp arguments or spend list budget.
    • Any subsequent compute dispatch, UAV-writing draw, ClearUnorderedAccessView*, external::record, non-hoistable indirect call, or HostList::close() calls HostList::end_hoisted_indirect(), transitioning hoisted scratch chunks back INDIRECT_ARGUMENT -> COMMON once and falling back to the existing inline bound/done path for the remainder of the list.
    • Re-submitting a closed HostList without reset() preserves its hoisted jobs and re-clamps cleanly.

Verification

  • Hardware benchmark (cargo test --release -p victory-gpu --locked -- --ignored --nocapture benchmark_hoisted_vs_inline_indirect_clamps on 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).
  • Hardware / Debug Layer + GBV / WARP (indirect::, latest c673921):
    • RTX 3060 Ti: 12 passed, 0 failed (25/25 across indirect:: + draw::).
    • D3D12 Debug Layer + GPU-Based Validation (VICTORY_D3D12_DEBUG=1 VICTORY_D3D12_GBV=1 RUST_LOG=warn, --features diagnostics): 12 passed, 0 failed, zero D3D12 warnings or errors.
    • WARP (VICTORY_D3D12_WARP=1, --features diagnostics): 12 passed, 0 failed.
  • Clippy & policy:
    • 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.)

@Bj0rnis

Bj0rnis commented Nov 25, 2026

Copy link
Copy Markdown

Independent Windows 11 hardware + WARP verification of #2472 at ec12173a (clean git merge-tree with origin/main 940d32f, Rust 1.98.1 MSVC):

  • NVIDIA GeForce RTX 5070 Ti (real hardware): 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 Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744 NVIDIA 1M view-heap baseline failures also present on main 940d32f). All 11 non-ignored indirect::tests (6 new hoisted/batched clamp tests + 5 existing), plus draw::tests and host::tests, passed on RTX 5070 Ti.
  • WARP (VICTORY_D3D12_WARP=1): 152 passed, 0 failed, 3 ignored (1.04s).
  • Clippy: cargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warnings -> 0 warnings.
  • Asset policy: cargo xtask policy -> 182 files ok.

Not tested: live game workload / frame-time benchmark (benchmark_hoisted_vs_inline_indirect_clamps was not run).

AI-assisted test run and summary.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Hoisting and batching indirect argument clamps into the list prelude passes all 11 live GPU indirect tests and draw tests cleanly under both default and diagnostics builds.
  • 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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@r4tedx

r4tedx commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Tested ec12173a on 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:: with VICTORY_D3D12_DEBUG=1: 12 passed, 2 ignored, with no debug-layer messages from the prelude, the job buffer or the GENERIC_READ transitions. 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, 2ec823e) to the hoist API:

    • 160 mixed executions: draws, indexed draws, dispatches and mesh dispatches, with 1-150 records each and garbage group counts;
    • heavy records, so the budget runs out partway;
    • 150 hoisted (30 of them alternating with a second buffer), then 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.

    GPU ms per call hoisted no clamps
    whole list 105.44 32.80 31.68
    clamps alone 40.33 0.22 -

    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:

  1. With GPU: scope indirect clamp UAV barriers and skip zero-record clamps #2168 (count-aware clamp): the per-call path stops charging records past a separate count, but the batch shader still charges all records. A hoisted counted call would then use up the budget faster than the same call clamped per call.
  2. Hoisting ends early: a zero-record call (span returns None) and any overlap end hoisting for the rest of the list. That costs speed only. GPU: scope indirect clamp UAV barriers and skip zero-record clamps #2168's early return for zero records would avoid the first.
  3. Dropped draws and the budget: on the hoisted path, prepare runs 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.
  4. Buffer state: hoisted argument buffers stay in GENERIC_READ until 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.
  5. Dispatches: the API accepts dispatch records, but the draw path never hoists dispatches. So the dispatch parts of the test check the shader, not a path a title takes.

The title was not used in these tests.

AI-assisted

@ESAT586

ESAT586 commented Nov 25, 2026

Copy link
Copy Markdown
Author

Thanks for the RTX 5090, RTX 5070 Ti, and WARP / equivalence / benchmark verification @DenRakEiw, @Bj0rnis, and @r4tedx!

Addressed point #2 from @r4tedx in 1b1fedd:

  • Zero-record indirect calls (max == 0): Draw::indirect now returns rue early when max == 0 instead of letting span return None and prematurely calling end_hoisted_indirect() for the rest of the command list.
  • Re-verified on RTX 3060 Ti + WARP (indirect::tests + draw::tests: 16/16 passed), strict Clippy (--all-targets & --all-features, 0 warnings), and cargo xtask policy (182 files ok).

(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.)

@Vedoxdev123

Copy link
Copy Markdown

Tested on Windows with AMD Ryzen 5 5600X + NVIDIA GeForce RTX 4060:

cargo test -p victory-gpu --lib -> 147 passed; 2 failed; 3 ignored

All 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_released and lists_share_a_table_and_copies_keep_their_views from #1744).

@ESAT586
ESAT586 force-pushed the gpu/hoist-indirect-clamps branch from 1b1fedd to 187db6f Compare November 25, 2026 16:09

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate (kept). Re-reviewed at c673921. The only new commit since the last verdict hardens BATCH_SOURCE in crates/victory-gpu/src/indirect.rs:

  • Root-SRV job loads are now under a [branch] guard, so tail lanes never read past jobs.
  • The single-run scan no longer uses &&, which FXC does not short-circuit and which could read costs[64].
  • The GROUPS / g.z test is nested under a g.z != 0 check.
  • Job words are mirrored in host RAM (payload), so a grown upload buffer is filled from memory rather than read back from write-combined memory.
  • Runs are separated by a full 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: check passing.


Generated by Claude Code

@ESAT586

ESAT586 commented Nov 25, 2026

Copy link
Copy Markdown
Author

Rebased onto origin/main (67e8ae1) at 187db6f and adapted cleanly to 315cea1's non-destructive scratch-buffer clamp design:

  • Title argument buffers are never mutated and never transitioned: HoistedClamps reads the title's argument buffers via SRV(t1) and writes clamped records into per-list 256 KiB scratch chunks (COMMON -> UNORDERED_ACCESS -> INDIRECT_ARGUMENT in the prelude, INDIRECT_ARGUMENT -> COMMON once at end_hoisted_indirect() / HostList::close()). This eliminates overlap tracking, drops the capture.rs diff completely, and resolves point Loader: keep the cleared TLS callback pointer out of base relocations #4 from @r4tedx (no title-buffer state change during the prefix).
  • Exact 315cea1 parity: BATCH_SOURCE matches SOURCE word-for-word (including zeroing word 0 past BUDGET and preserving trailing fields), and hoisted_transitions_start_from_current_states_and_never_touch_title_buffer verifies every emitted barrier with host::tests::issued() + replay().
  • Benchmark (RTX 3060 Ti, --release): 9000 indirect draw clamps: inline 45.28 ms/frame vs hoisted 2.14 ms/frame (21.1x) (~43.1 ms/frame saved).
  • Verified: RTX 3060 Ti (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!

@kotekompotek

Copy link
Copy Markdown

Traced the full path; the design is sound and the hazards I went looking for are covered:

  • Ordering: the prelude clamp reads only the title arg buffers (SRV, never transitioned) and writes private scratch — and since every shadow refresh is a CPU-side deferred step that runs before submission, prelude reads see fully-refreshed data. GPU writers inside the list are covered by end_hoisted_indirect at every site I could find that emits a write: bind (compute or pipeline_writes_uav), clear_unordered, external::record, close, plus the non-hoistable branches of indirect() itself.
  • Budget semantics preserved: the batch shader charges sequentially in lane order (lane==0 prefix walk), PAST = 0xffffffff is unreachable as a real cost (draw ≤2^26, dispatch ≤2^23), the budget zero-step is registered once per list via budget_zeroed, and per-run UAV(None) barriers keep both budget and 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.
  • Minor: the body describes a per-buffer BTreeMap overlap 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_once raw-pointer dedup, and the restored idempotence for re-submit-without-reset all check out. The 32x benchmark number is believable given ~18k eliminated barriers per frame.

clquwu added a commit to clquwu/leonida-ultimate that referenced this pull request Nov 25, 2026
…g & shared indirect rendering scopes

- Replace per-ExecuteIndirect vkCreateBuffer/vkAllocateMemory in IndirectDispatchCounter::Batch
  with a persistent per-slot/per-queue reusable device-local ring buffer (64 KiB initial,
  16-byte aligned bump suballocation, 2x growth with overflow retention until GPU completion,
  reset_for_reuse() frees overflow rings and zeroes cursor; bounded pool of 8 rings on
  VulkanQueue for ZERO vkAllocateMemory per frame in steady state).
  Adapted from fxceless/victory-fork#1000 (PiloteCode, GPL-3.0).
- Add IndirectDispatchCounter::emit_batch() emitting 1 before-barrier, 1 compute pipeline bind,
  N back-to-back disjoint dispatches, and 1 tightly-scoped COMPUTE_SHADER -> DRAW_INDIRECT
  after-barrier (replacing per-draw ALL_COMMANDS -> COMPUTE / COMPUTE -> ALL_COMMANDS barriers).
- Add plan_indirect_clamp_batches() in vulkan_replay.h to hoist and batch indirect clamps across
  contiguous barrier-free draw runs (ExecuteIndirect DRAW/DRAW_INDEXED and Draw mesh_indirect)
  and indirect dispatch runs ahead of the rendering scope, keeping compatible indirect and direct
  draws inside one unbroken dynamic rendering scope (#1877).
  Adapted from Marvisak/VIctory#2472 (ESAT586, GPL-3.0) and fxceless/victory-fork#1000 (GPL-3.0).
- Verify ubiquitarianism/leonida#1929 (zero-Z mesh draw drop in CommandList::draw(Draw&&)) is
  already superseded by CommandList::has_draw_work() and add explicit regression coverage.
- Add unit and live-GPU validation tests for zero-alloc steady-state ring reuse, 2x growth,
  pre-scope clamp batching with unbroken rendering scopes, and multi-frame GPU parity.
@ESAT586

ESAT586 commented Nov 25, 2026

Copy link
Copy Markdown
Author

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.

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review (same-list GPU-write hazard audit) and RTX 5090 + WARP verification at head c673921cc134 merged cleanly onto main (63bcca43c6a0):

  • Same-list data-hazard audit: HoistedClamps is restricted strictly to the initial GPU-write-free prefix of each command list (indirect.rs:386-392). Every GPU-write path irreversibly terminates hoisting via list.end_hoisted_indirect() (transitioning used scratch chunks back from INDIRECT_ARGUMENT to COMMON and setting hoistable = false): compute dispatches (draw.rs:617-619), UAV-writing graphics pipelines (pipeline_writes_uav at draw.rs:2002-2017, covering marks, root UAVs, s.memory, heap_writes, table/root UAVs, and ROOT_UAV_VIEW), clear_uav (draw.rs:1081), external::record (external.rs:44), indirect dispatches (draw.rs:1775, 1821), and HostList::close (host.rs:1768). Subsequent indirect calls fall back to inline indirect::bound, while CPU-side deferred copies/refreshes complete before the prelude and record_prelude opens with a global UAV barrier.
  • Verified (Windows 11, NVIDIA RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • WARP (--features diagnostics, indirect::tests draw::tests host::tests): 63/63 passed, 1 ignored (benchmark_hoisted_vs_inline_indirect_clamps)
    • RTX 5090 (indirect::tests draw::tests host::tests): 62/62 passed with 0 Debug Layer errors (including all 5 new hoisted_* tests; excluding only the pre-existing NVIDIA 1M heap-cap baseline test descriptor::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.

@MeMako

MeMako commented Nov 26, 2026

Copy link
Copy Markdown

Independent verification of c673921 on AMD Radeon RX 9070 XT (adapter 0, driver 32.0.32029.2010, Ryzen 9 7950X, Windows 11 10.0.26200 x64).

CI checks & synthetic GPU benchmark:

  • cargo clippy -p victory-gpu -p victory --all-targets --locked -- -D warnings (and --all-features): pass
  • cargo test -p victory-gpu --locked: 240 passed, 0 failed (all 12 indirect::tests pass 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 842b0cb containing a separate-handle workaround equivalent to #2122, DYNAMIC = 1 << 19, and #2051; before/after compared against the exact same branch without #2472.)

Metric (draws >= 200, excluding menus/pause) Without #2472 (n=29) With #2472 (n=31) Delta
GPU time (median / avg) 183.1 ms / 182.0 ms 161.8 ms / 174.1 ms -21.3 ms (-11.6%)
Frame time (median) 572.2 ms (1.70 fps) 523.2 ms (1.90 fps) -49.0 ms (+11.8%)
Indirect drops / GPU faults / device removals 0 / 0 / 0 0 / 0 / 0 Clean

The run later ended in an unrelated title-side access violation (0xfc00fc00fc007c00 read 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.

Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 26, 2026
… chunk buffer

Port of RVZO6 Marvisak#2168 onto the hoisted bound_chunk model (our always-hoist
chunk-hoist is already landed; Marvisak#2168 targets the old per-call bound() and
does not apply). Picks the small clamp PR over Marvisak#2472 (1.1k-line prelude
batch pass, no hardware A/B available) and Marvisak#242 (conflicting branch).

- bound_chunk: leading global NULL-resource UAV flush becomes targeted
  barriers on each clamp's argument copy (deduplicated) and any distinct
  count buffer; per-request trailing global barrier becomes a barrier on
  the shared budget only. Same order, same transitions.
- Zero-record requests run no dispatch and need no barriers; their slice
  is never read. execute_indirect with max == 0 skips refresh, clamp and
  execution entirely, counting the draw/dispatch.
- HostList::budget now hands out the budget buffer with its address, for
  the targeted budget barrier.
- The chunk clamps into slices of one argument buffer at increasing
  16-byte offsets (was: every request at offset 0 of the same cached
  buffer, so every execution of a multi-request chunk read the last
  clamp's records, and transitions mismatched under the debug layer).
  run_pending executes at the request's offset; done_chunk reverts once.
- Test: chunk_scopes_uav_barriers_and_zero_records (barrier scope,
  slice offsets, transition balance via replay).
@steven-seagull27

steven-seagull27 commented Nov 26, 2026 •

Copy link
Copy Markdown

The batch prelude needs the same mesh-grid rule as #2996 when these two patches meet. I tested the clean merge of c673921c with 9a851cd3 and counted actual mesh shader SV_GroupID values 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 direct DispatchMesh control 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 PR

The 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-pick 0689282

@steven-seagull27

Copy link
Copy Markdown

@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.

Synthetic input Total groups executed Direct and inline Batch before Batch with fix
One (3,2,4) record, 12-byte stride 24 24 3 24
Two small records, 16-byte stride 8 6 2 6
66 records crossing the 64-record boundary, 20-byte stride 512 27 3 27

Multiple 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_indirect decision. 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 5385cc6 with 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.

git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2472-translated-mesh-groups

AI-assisted with Codex. Synthetic draws and readbacks.

@imjustprism

Copy link
Copy Markdown
Contributor

ran this in the title on an rx 9070 xt, merged onto 63bcca4 plus #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:

draws per frame gpu ms, before gpu ms, with this frame lines before / with
500 to 800 67 73 20 / 9
800 to 1100 86 83 17 / 12
1100 to 1500 100 88 12 / 9
1500 to 2500 110 140 6 / 10
2500 to 3500 176 164 2 / 11
above 3500 178 172 5 / 8

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.

  • the hoisted path runs prepare before the clamp, the inline path clamps first. a call that prepare drops 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_prelude returns a bool that HostList drops, and a missing budget resource skips the prelude silently. i believe neither can happen once can_hoist said yes, but if it ever does, the body runs ExecuteIndirect on chunks that were never clamped. a fail there would make it loud.
  • the tests drive 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.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed c673921c across draw.rs, external.rs, host.rs, and indirect.rs, and confirmed a clean git merge-tree against origin/main (63bcca43).

Key invariants checked:

  • Hoisting is strictly confined to a list's initial non-writing prefix: end_hoisted_indirect() closes the prefix and returns all used scratch chunks INDIRECT_ARGUMENT -> COMMON once before any compute bind, UAV/memory/heap-writing graphics pipeline (pipeline_writes_uav), clear_unordered, non-hoistable indirect call, external::record, or close().
  • BATCH_SOURCE (c673921c) guards tail lanes with [branch] before root-SRV loads and avoids FXC non-short-circuiting on costs[64]; relative src_offset + len <= u32::MAX and HOIST_CHUNK bounds are enforced in HoistedClamps::push; prelude barriers (UAV(None) -> chunk COMMON -> UAV -> per-run UAV(None) -> UAV(budget) + chunk UAV -> 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 ok
  • RTX 5090 indirect::: 12/12 passed (1 ignored benchmark)
  • RTX 5090 + VICTORY_D3D12_DEBUG=1 indirect::: 12/12 passed with zero Debug Layer warnings/errors (including hoisted_prelude_orders_after_earlier_list_compute_write)
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1) + VICTORY_D3D12_DEBUG=1 indirect::: 12/12 passed
  • RTX 5090 release benchmark (benchmark_hoisted_vs_inline_indirect_clamps, 9,000 draws): inline 38.45 ms/frame vs hoisted 2.35 ms/frame (16.3x)

LGTM.

@KainanP

KainanP commented Nov 26, 2026

Copy link
Copy Markdown

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 427db00). It runs ExecuteIndirect through 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's Close is timed with the calls. For these runs only, I also timed HostList::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.

ns per call main 63bcca4 + #2472 + #3197, window off + #3197, VICTORY_CLAMP_WINDOW=1
ExecuteIndirect, indexed draw, 1 thread 4,870 3,212 4,881 3,186
same, 5 threads (per thread) 8,759 7,769 8,517 8,922
ExecuteIndirect, dispatch, 1 thread 3,042 3,072 2,984 3,018

The 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:

ns per call stack + #2472 + #3197, window off + #3197, window on
indexed draw, 1 thread 3,260 1,449 3,135 1,449
same, 5 threads (per thread) 4,345 2,742 4,141 2,687
dispatch, 1 thread 2,740 2,644 2,706 2,773
  • On the CPU, this PR removes almost all of the per-call clamp cost: about 1.7–1.8 µs per indirect draw. What is left above a plain 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.
  • On main, 5 threads barely move with either PR. The per-draw texture locks dominate there. On the stack, both PRs take 5 threads from 4.3 to 2.7 µs.
  • Both PRs leave indirect dispatches alone (~3.0 µs vs 0.86 µs for a plain Dispatch on main), by design.
  • This bench is the best case for both PRs: the list never writes, so here this PR hoists the whole list and GPU: clamp consecutive indirect draws in one pass (VICTORY_CLAMP_WINDOW, opt-in) #3197 fills windows of 64. In game the coverage differs. This PR stops at a list's first writing command, and GPU: clamp consecutive indirect draws in one pass (VICTORY_CLAMP_WINDOW, opt-in) #3197 ends a window at any other draw. I have no game numbers for either.

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, c673921 merged on 63bcca4, cargo test -p victory-gpu --release --lib:

  • RTX 4060: 235 passed, 2 failed.
  • Intel UHD, selected with a local adapter hook: 234 passed, 3 failed.
  • WARP (--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 12 indirect:: tests pass on all three adapters, including the six new ones. On RTX, memory_tests::heap_direct_texture_reads_mark_their_heap_index was 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.