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

Open
github-bot wants to merge 2 commits from github-bot/gh-2472 into main AGit
Owner

@⁠ESAT586 on GitHub · 2026-11-25 14:18 UTC · original
ESAT586:gpu/hoist-indirect-clamps → main · +1096 −45 · 4 files · 2 commits · open

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

**@⁠ESAT586** on GitHub · 2026-11-25 14:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472) `ESAT586:gpu/hoist-indirect-clamps` → `main` · +1096 −45 · 4 files · 2 commits · open ## 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.)*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:54 +00:00
Author
Owner

@⁠Bj0rnis on GitHub · 2026-11-25 14:26 UTC · original

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

**@⁠Bj0rnis** on GitHub · 2026-11-25 14:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7165294872) 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 #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.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-25 15:09 UTC · original

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, 2ec823e4) 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 #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. #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

**@⁠r4tedx** on GitHub · 2026-11-25 15:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7166390578) 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`, 2ec823e4) 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 #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. #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
Author
Owner

@⁠ESAT586 on GitHub · 2026-11-25 15:14 UTC · original

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

**@⁠ESAT586** on GitHub · 2026-11-25 15:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7166521204) 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.)*
Author
Owner

@⁠Vedoxdev123 on GitHub · 2026-11-25 15:53 UTC · original

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

**@⁠Vedoxdev123** on GitHub · 2026-11-25 15:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7167407631) 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 16:10 UTC · original · edited 2026-11-26 00:23 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 16:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7167665874) · edited 2026-11-26 00:23 UTC <!-- victory-triage v1 head=c673921cc1344758dbe1d646858c8f6b646066b9 verdict=merge-candidate at=2026-11-26T00:23:51Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠ESAT586 on GitHub · 2026-11-25 16:20 UTC · original

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 #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!

**@⁠ESAT586** on GitHub · 2026-11-25 16:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7167816601) 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 #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!
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:06 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7169007667) 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.
Author
Owner

@⁠ESAT586 on GitHub · 2026-11-25 20:27 UTC · original

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.

**@⁠ESAT586** on GitHub · 2026-11-25 20:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7173690911) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 00:38 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 00:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7178968061) 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.
Author
Owner

@⁠MeMako on GitHub · 2026-11-26 01:18 UTC · original

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.

**@⁠MeMako** on GitHub · 2026-11-26 01:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7179645334) 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.
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 03:02 UTC · original · edited 2026-11-26 03:14 UTC

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** on GitHub · 2026-11-26 03:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7181336550) · edited 2026-11-26 03:14 UTC 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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/2996) 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`](https://github.com/steven-seagull27/VIctory/commit/0689282711fbe7765380e91edd6fa536d0eee815)
Author
Owner

@⁠steven-seagull27 on GitHub · 2026-11-26 04:06 UTC · original

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

**@⁠steven-seagull27** on GitHub · 2026-11-26 04:06 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7182304476) @⁠andrewpozdnakov7-jpg’s [translated mesh-group fix](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/5385cc62cbfbaece4c8eb2dde871b14703f119cb) 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](https://github.com/steven-seagull27/VIctory/commit/857d8d5dbde2d62c3764dc7cc938c1e7ad96c35d). 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. ```sh git fetch https://github.com/steven-seagull27/VIctory.git refs/heads/codex/pr2472-translated-mesh-groups ``` AI-assisted with Codex. Synthetic draws and readbacks.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 14:35 UTC · original · approved these changes

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

**@⁠DenRakEiw** on GitHub · 2026-11-25 14:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#pullrequestreview-6059635775) · **approved these changes** 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).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 14:57 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#pullrequestreview-6059996795) · **reviewed** 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.
Author
Owner

@⁠imjustprism on GitHub · 2026-11-26 09:26 UTC · original

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.
**@⁠imjustprism** on GitHub · 2026-11-26 09:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7187996227) 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 09:51 UTC · original · approved these changes

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 09:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#pullrequestreview-6071872662) · **approved these changes** 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.
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 16:22 UTC · original

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 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 #3197 fills windows of 64. In game the coverage differs. This PR stops at a list's first writing command, and #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.

**@⁠KainanP** on GitHub · 2026-11-26 16:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/2472#issuecomment-7197569095) 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](https://github.com/KainanP/VIctory/tree/perf/list-call-bench) now has `VICTORY_LIST_BENCH_INDIRECT=1` (commit 427db003). 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 #3197 fills windows of 64. In game the coverage differs. This PR stops at a list's first writing command, and #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._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2472/head:github-bot/gh-2472'
git switch 'github-bot/gh-2472'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2472'
git switch 'github-bot/gh-2472'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2472'
git switch 'github-bot/gh-2472'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2472'
git switch 'main'
git merge --squash 'github-bot/gh-2472'
git switch 'main'
git merge --ff-only 'github-bot/gh-2472'
git switch 'main'
git merge 'github-bot/gh-2472'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2472
No description provided.