victory-gpu: drop an indirect call before its clamp, not after (1 400-1 750 a frame) #1635

Manually merged
github merged 1 commit from gh-pr/1635/head into gh-pr/1635/base 2026-11-26 04:39:08 +00:00
Owner

@⁠pes7 on GitHub · 2026-11-24 20:12 UTC · original
pes7:perf/indirect-skip-clamp → main · +13 −0 · 1 files · 1 commits · merged 2026-11-25 00:18 UTC

1 400-1 750 indirect calls a frame are dropped because their pipeline is not built yet, and each one has already copied its arguments and dispatched the argument clamp before finding that out. Moving the check ahead of the clamp takes a copy and a GPU dispatch out of every one of them.

State::execute_indirect refreshes the argument buffer from title memory and calls indirect::bound, which dispatches a compute shader that clamps the records - then calls prepare, which fails when the pipeline is not there, and drops the call. The drop counts are the ones in the reports: 1 400-1 750 indirect executions a frame on an RTX 5070 Ti (#400), 1 294 a frame on an RX 7800 XT (#255), 64/frame "prepare failed (compute false, mesh false)" plus 282 compute pipelines refused in #748 - all of it while the world builds its pipelines, which is exactly when the frame is slow.

What changes

host_pipeline(self.pipeline) is asked first. It is the same lookup prepare does a few lines later and returns None for a pipeline the worker threads have not made yet; with None the call cannot run, so it is dropped before the refresh and before the clamp. No behaviour change for a call that can run: same refresh, same clamp, same execution.

This is the order the file already uses for skipped pipelines, with the comment "Skip before the argument clamp can mutate the indirect buffer" - the same argument, extended from the skipped case to the much more common not-built-yet one.

What it saves

Per dropped call, on the CPU and on the GPU:

  • the argument refresh (Shadow::refresh over stride * max bytes, copy_mapped);
  • the clamp dispatch: a compute pipeline bind, a descriptor write, a dispatch of records threads and the UAV barrier around it (indirect::bound / indirect::done), which also serialises the list on the GPU.

At 1 400-1 750 calls a frame that is 1 400-1 750 dispatch-and-barrier pairs removed from every frame while the world loads, and the copies that go with them.

Not measured in the title

I cannot run the title, so I cannot show the frame time before and after - the count of dropped calls is from the reporters above, and the code order is verifiable: args.refresh and indirect::bound both run before prepare, unconditionally. What I can say is that the work removed is real, per call, and that the counters already distinguish no host pipeline from prepare failed, so the first copystat/frame line after this lands shows it: the "dropped without a host pipeline" reasons should keep their counts while the clamp dispatches behind them stop.

Correctness

Dropping a call earlier is safe: nothing reads the clamp's result for a call that does not execute, the clamp is per call (records at arguments, stride * max bytes), and a later call that does run clamps its own range first. cargo test --workspace --locked, both clippy configurations with -D warnings, cargo xtask policy.

No game data used.

**@⁠pes7** on GitHub · 2026-11-24 20:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1635) `pes7:perf/indirect-skip-clamp` → `main` · +13 −0 · 1 files · 1 commits · merged 2026-11-25 00:18 UTC **1 400-1 750 indirect calls a frame are dropped because their pipeline is not built yet, and each one has already copied its arguments and dispatched the argument clamp before finding that out.** Moving the check ahead of the clamp takes a copy and a GPU dispatch out of every one of them. `State::execute_indirect` refreshes the argument buffer from title memory and calls `indirect::bound`, which dispatches a compute shader that clamps the records - then calls `prepare`, which fails when the pipeline is not there, and drops the call. The drop counts are the ones in the reports: **1 400-1 750 indirect executions a frame** on an RTX 5070 Ti (#400), 1 294 a frame on an RX 7800 XT (#255), 64/frame "prepare failed (compute false, mesh false)" plus 282 compute pipelines refused in #748 - all of it while the world builds its pipelines, which is exactly when the frame is slow. ## What changes `host_pipeline(self.pipeline)` is asked first. It is the same lookup `prepare` does a few lines later and returns `None` for a pipeline the worker threads have not made yet; with `None` the call cannot run, so it is dropped before the refresh and before the clamp. No behaviour change for a call that can run: same refresh, same clamp, same execution. This is the order the file already uses for skipped pipelines, with the comment *"Skip before the argument clamp can mutate the indirect buffer"* - the same argument, extended from the skipped case to the much more common not-built-yet one. ## What it saves Per dropped call, on the CPU and on the GPU: - the argument refresh (`Shadow::refresh` over `stride * max` bytes, `copy_mapped`); - the clamp dispatch: a compute pipeline bind, a descriptor write, a dispatch of `records` threads and the UAV barrier around it (`indirect::bound` / `indirect::done`), which also serialises the list on the GPU. At 1 400-1 750 calls a frame that is 1 400-1 750 dispatch-and-barrier pairs removed from every frame while the world loads, and the copies that go with them. ## Not measured in the title I cannot run the title, so I cannot show the frame time before and after - the count of dropped calls is from the reporters above, and the code order is verifiable: `args.refresh` and `indirect::bound` both run before `prepare`, unconditionally. What I can say is that the work removed is real, per call, and that the counters already distinguish `no host pipeline` from `prepare failed`, so the first `copystat`/frame line after this lands shows it: the "dropped without a host pipeline" reasons should keep their counts while the clamp dispatches behind them stop. ## Correctness Dropping a call earlier is safe: nothing reads the clamp's result for a call that does not execute, the clamp is per call (records at `arguments`, `stride * max` bytes), and a later call that does run clamps its own range first. `cargo test --workspace --locked`, both clippy configurations with `-D warnings`, `cargo xtask policy`. No game data used.
`State::execute_indirect` refreshes the argument buffer from title memory
and dispatches the argument clamp (`indirect::bound`) before it asks
whether the call can run. When the pipeline has not been built yet -
`prepare` returning false, which #400 measures at 1 400-1 750 indirect
calls a frame, #255 at 1 294, #748 at 64 plus 282 refused compute
pipelines - the call is dropped after paying a copy and a GPU dispatch
with its barrier, for records nothing reads.

Ask `host_pipeline` first. It is the same lookup `prepare` does a few
lines later, and `None` means the call cannot run, so it is dropped
before the refresh and the clamp. A call that can run is unchanged: same
refresh, same clamp, same execution.

That is the order the file already uses for skipped pipelines ("Skip
before the argument clamp can mutate the indirect buffer"), extended to
the much more common not-built-yet case. Dropping earlier is safe: the
clamp is per call, and a later call that runs clamps its own range first.

Not measured in the title - I cannot run it - but the work removed is one
refresh and one dispatch per dropped call, and the diagnostics already
separate "no host pipeline" from "prepare failed", so the next frame line
shows the clamp dispatches behind those drops stop.

cargo test --workspace --locked; both clippy configurations with
-D warnings; cargo xtask policy.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:39:06 +00:00
github manually merged commit 4e60ea3a38 into gh-pr/1635/base 2026-11-26 04:39:08 +00:00
Author
Owner

@⁠pes7 on GitHub · 2026-11-24 22:41 UTC · original

@⁠catminou4 - on the Windows hardware check: @⁠mercuryVM already ran one at 6dcf40a on Windows 11 / RTX 5070 / MSVC (build, cargo test --workspace --no-fail-fast 638 passed, 0 failed, merged into their fork's main) and walked the same three paths you would check - prepare, prepare_for and the dispatch arm all gate on host_pipeline(self.pipeline) being Some, so the early return drops exactly the calls that were dropped a few lines later, and it comes before indirect::bound, so the buffer never gets its INDIRECT_ARGUMENT state and the root signature is never replaced.

What the change does and does not touch, for a source-only read:

if crate::pipeline::host_pipeline(self.pipeline as This).is_none() {
    #[cfg(feature = "diagnostics")]
    crate::pipeline::note_drop(self.pipeline as This);
    why("no host pipeline");
    return false;
}
  • the predicate is the one the old not-ran path used; only its position moved, so the set of dropped calls cannot change - it is the same Option test on the same handle;
  • return false is what the existing is_skipped early return above already returns, so the caller sees the same thing;
  • in diagnostics builds the drop is still counted through note_drop, so the 1 400-1 750 a frame in #400 stay visible after this lands, which is how the claim can be confirmed in the title rather than by reading.

There is no test in draw.rs for the indirect path at all today - the module's tests cover root views, textures and heaps, and the indirect path needs a State pointed at a title pipeline handle plus argument records in shadow memory, which is a harness of its own. If you would rather have a synthetic test than the hardware run above, say so and I will write one against the existing compile_cs helpers in that module; I did not add it because it would be more code than the change it covers.

**@⁠pes7** on GitHub · 2026-11-24 22:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/1635#issuecomment-7146521033) @⁠catminou4 - on the Windows hardware check: @⁠mercuryVM already ran one at `6dcf40a` on Windows 11 / RTX 5070 / MSVC (build, `cargo test --workspace --no-fail-fast` 638 passed, 0 failed, merged into their fork's main) and walked the same three paths you would check - `prepare`, `prepare_for` and the dispatch arm all gate on `host_pipeline(self.pipeline)` being `Some`, so the early return drops exactly the calls that were dropped a few lines later, and it comes before `indirect::bound`, so the buffer never gets its `INDIRECT_ARGUMENT` state and the root signature is never replaced. What the change does and does not touch, for a source-only read: ```rust if crate::pipeline::host_pipeline(self.pipeline as This).is_none() { #[cfg(feature = "diagnostics")] crate::pipeline::note_drop(self.pipeline as This); why("no host pipeline"); return false; } ``` - the predicate is the one the old `not-ran` path used; only its position moved, so the set of dropped calls cannot change - it is the same `Option` test on the same handle; - `return false` is what the existing `is_skipped` early return above already returns, so the caller sees the same thing; - in diagnostics builds the drop is still counted through `note_drop`, so the 1 400-1 750 a frame in #400 stay visible after this lands, which is how the claim can be confirmed in the title rather than by reading. There is no test in `draw.rs` for the indirect path at all today - the module's tests cover root views, textures and heaps, and the indirect path needs a `State` pointed at a title pipeline handle plus argument records in shadow memory, which is a harness of its own. If you would rather have a synthetic test than the hardware run above, say so and I will write one against the existing `compile_cs` helpers in that module; I did not add it because it would be more code than the change it covers.
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!1635
No description provided.