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

Merged
pes7 merged 1 commit from upstream-pr/1635 into main 2026-11-25 00:18:09 +00:00
pes7 commented 2026-11-24 20:12:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T20:12:04Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6590489411 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1635). Originally posted by [pes7](https://github.com/pes7) on 2026-11-24T20:12:04Z. --- **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.
mercuryVM commented 2026-11-24 21:28:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T21:21:36Z.

Review: APPROVED


Tested 6dcf40a on Windows 11, RTX 5070, MSVC: builds, cargo test --workspace --no-fail-fast 638 passed, 0 failed (on our fork main). I didn't measure the frame-time effect.

  • Every path that can run an indirect call needs host_pipeline(self.pipeline) to be Some: prepare, prepare_for, and the dispatch arm. So checking it before the refresh and clamp drops exactly the calls that were dropped before, and nothing more.
  • The early return comes before indirect::bound, so the buffer is never moved to INDIRECT_ARGUMENT and the compute root signature isn't replaced. Skipping the indirect::done transition and the host_pipeline/host_roots reset on that path is therefore correct.
  • In diagnostics builds the drop is still counted through note_drop, as the old not-ran path did for a missing pipeline.

Merged into our fork's main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6047613070 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1635#pullrequestreview-6047613070). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T21:21:36Z. **Review:** APPROVED --- Tested 6dcf40a on Windows 11, RTX 5070, MSVC: builds, `cargo test --workspace --no-fail-fast` 638 passed, 0 failed (on our fork main). I didn't measure the frame-time effect. - Every path that can run an indirect call needs `host_pipeline(self.pipeline)` to be `Some`: `prepare`, `prepare_for`, and the dispatch arm. So checking it before the refresh and clamp drops exactly the calls that were dropped before, and nothing more. - The early return comes before `indirect::bound`, so the buffer is never moved to `INDIRECT_ARGUMENT` and the compute root signature isn't replaced. Skipping the `indirect::done` transition and the `host_pipeline`/`host_roots` reset on that path is therefore correct. - In diagnostics builds the drop is still counted through `note_drop`, as the old not-ran path did for a missing pipeline. Merged into our fork's main. AI-assisted (Claude Code).
catminou4 commented 2026-11-24 23:04:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T22:19:54Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Indirect call dropped before its claim when… (small 1.3K diff in draw.rs, no tests added). Worth a Windows hardware check that the dropped call path is the intended one.

<!-- greyfinch-sync:Marvisak/VIctory:review:6048311832 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1635#pullrequestreview-6048311832). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T22:19:54Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Indirect call dropped before its claim when… (small 1.3K diff in draw.rs, no tests added). Worth a Windows hardware check that the dropped call path is the intended one.
pes7 commented 2026-11-24 23:05:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pes7 on 2026-11-24T22:41:00Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146521033 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1635#issuecomment-7146521033). Originally posted by [pes7](https://github.com/pes7) on 2026-11-24T22:41:00Z. --- @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.
upstream-sync closed this pull request 2026-11-25 01:06:57 +00:00
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1634
No description provided.