refactor(agc): split a dispatch's device call into a complete and a record step #8278

Merged
m335671 merged 1 commit from upstream-pr/8278 into main 2026-10-23 17:16:27 +00:00
m335671 commented 2026-10-20 08:18:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-20T08:18:56Z.


What

This is step 1 of the dispatch-side series outlined in #7895 (issuecomment-6277297868) and accepted there. It is the dispatch counterpart of the Graphics::Draw prepare/record split, and it changes no behaviour.

VulkanDevice::dispatch used to run both parts of a dispatch's device call in one function. It now does only the complete part, then hands the result to a new function, VulkanDevice::recordCompletedDispatch, which does the record part:

Part Function What it does
complete VulkanDevice::dispatch reaps the presync batches; completes the resources (stage B of a prepared build, a template hit with Revalidate/MovedDispatchBuffers, or a full build), then the cache insert and PatchPushConstants; resolves the compute pipeline
record VulkanDevice::recordCompletedDispatch builds the RecordedDispatch, runs decideIndirect and recordDispatch, then the lease sync, the traces, the recipe and timer.finish

The hand-off is a DispatchCompletion: references to the context, shader, push constants, pipeline objects, resources, content key and the cache outcome, plus the call's DispatchTimer, PerformanceTimer and group text. Both halves keep their code and their place in the file: the diff only adds the struct, the forward declaration, the member declaration and the lines at the cut. Nothing is copied, reordered or moved across the GPU mutex.

The next steps from #7895 build on this cut. Step 2 moves parts of the complete step off the mutex. Step 4 resolves queue-0 dispatch capture and recompile ahead on a helper. Each of those comes behind a switch with before/after timings and a test that writes between prepare and record.

Tested

Windows 11 Pro 26200, RTX 4070, NVIDIA 617.42, WinLibs GCC 15.2.0, Release. Rebased on main 8499ea52e; since the first version, dispatch gained threadGroup (#8066) and htileClear (#7233, #7371), and both are passed on to recordCompletedDispatch like x, y, z.

  • The full ^agc_ suite on main 8499ea52e and on this branch: 889 of 892 pass on both, and the same three tests fail on both (agc_driver_sample_order, agc_driver_sample_order_grid_reference, agc_driver_sample_order_recipe_depth_locations, which also fail on main with -j1 on this machine).
  • The focused dispatch tests (agc_driver_pipelined_dispatch*, agc_driver_dispatch*, agc_driver_gated_dispatch*, agc_driver_indirect_dispatch*, agc_driver_oversized_dispatch*, agc_driver_draw_write_ranges), run with ctest -V, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 on both: 11 of 11 pass on both. Neither log has was not found but was requested by env var VK_INSTANCE_LAYERS or any VUID- line.
  • Behaviour is unchanged, so there are no frame timings from me: no switch, no new path. saarthakpant measured the first version on Ghostrunner 2 (comment above): same dispatch and draw counts, timings within run-to-run spread.
  • python tools/check_conventions.py --base origin/main: all checks passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070, driver 617.42, Windows 11 Pro 26200
  • AI-assisted: yes (Claude Code). The change, the runs and this description were done and written by Claude Code on my machine.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4933009969 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8278). Originally posted by [m335671](https://github.com/m335671) on 2026-10-20T08:18:56Z. --- ### What This is step 1 of the dispatch-side series outlined in #7895 (issuecomment-6277297868) and accepted there. It is the dispatch counterpart of the `Graphics::Draw` prepare/record split, and it changes no behaviour. `VulkanDevice::dispatch` used to run both parts of a dispatch's device call in one function. It now does only the **complete** part, then hands the result to a new function, `VulkanDevice::recordCompletedDispatch`, which does the **record** part: | Part | Function | What it does | | --- | --- | --- | | complete | `VulkanDevice::dispatch` | reaps the presync batches; completes the resources (stage B of a prepared build, a template hit with `Revalidate`/`MovedDispatchBuffers`, or a full build), then the cache insert and `PatchPushConstants`; resolves the compute pipeline | | record | `VulkanDevice::recordCompletedDispatch` | builds the `RecordedDispatch`, runs `decideIndirect` and `recordDispatch`, then the lease sync, the traces, the recipe and `timer.finish` | The hand-off is a `DispatchCompletion`: references to the context, shader, push constants, pipeline objects, resources, content key and the cache outcome, plus the call's `DispatchTimer`, `PerformanceTimer` and group text. Both halves keep their code and their place in the file: the diff only adds the struct, the forward declaration, the member declaration and the lines at the cut. Nothing is copied, reordered or moved across the GPU mutex. The next steps from #7895 build on this cut. Step 2 moves parts of the complete step off the mutex. Step 4 resolves queue-0 dispatch capture and recompile ahead on a helper. Each of those comes behind a switch with before/after timings and a test that writes between prepare and record. ### Tested Windows 11 Pro 26200, RTX 4070, NVIDIA 617.42, WinLibs GCC 15.2.0, Release. Rebased on `main` `8499ea52e`; since the first version, `dispatch` gained `threadGroup` (#8066) and `htileClear` (#7233, #7371), and both are passed on to `recordCompletedDispatch` like `x`, `y`, `z`. - The full `^agc_` suite on `main` `8499ea52e` and on this branch: 889 of 892 pass on both, and the same three tests fail on both (`agc_driver_sample_order`, `agc_driver_sample_order_grid_reference`, `agc_driver_sample_order_recipe_depth_locations`, which also fail on `main` with `-j1` on this machine). - The focused dispatch tests (`agc_driver_pipelined_dispatch*`, `agc_driver_dispatch*`, `agc_driver_gated_dispatch*`, `agc_driver_indirect_dispatch*`, `agc_driver_oversized_dispatch*`, `agc_driver_draw_write_ranges`), run with `ctest -V`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` on both: 11 of 11 pass on both. Neither log has `was not found but was requested by env var VK_INSTANCE_LAYERS` or any `VUID-` line. - Behaviour is unchanged, so there are no frame timings from me: no switch, no new path. saarthakpant measured the first version on Ghostrunner 2 (comment above): same dispatch and draw counts, timings within run-to-run spread. - `python tools/check_conventions.py --base origin/main`: all checks passed. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070, driver 617.42, Windows 11 Pro 26200 - [x] AI-assisted: yes (Claude Code). The change, the runs and this description were done and written by Claude Code on my machine.
saarthakpant commented 2026-10-20 10:21:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by saarthakpant on 2026-10-20T10:21:42Z.


Tested this on Ghostrunner 2 (PPSA09911), Windows 11 10.0.26200, RTX 2060 SUPER (617.42), MinGW GCC 15.2.0, applied on top of main 4b462ef60 + #7687 + #5372 + the 8 MiB written-staging change (the stack this title needs to reach gameplay here), two scripted gameplay runs of about 5 minutes each with APS5_PROFILE_GPU=1 APS5_PROFILE_DRAW=1, against one run of the same stack without this PR.

No behaviour change: same scene progression, no errors or asserts, dispatch and draw counts per 10 s window match. Performance is inside the run-to-run spread of scripted runs of this title (medians over the steady 10 s windows):

without #8278 #8278 run 1 #8278 run 2
presents per 10 s 37 29.5 33
idle gaps per frame 171 ms 241 ms 190 ms
dispatch, total µs per direct dispatch (queue 0) 147 165 150
of which device call 61 75 58
draw, total µs per packet 87 90 80

Two runs of one build in the same session earlier differed by 33 vs 28 presents per 10 s, so the refactor costs nothing measurable here; the draw committer carries the frame on this title (about 65 ms busy per frame against 30 ms on queue worker 0), which is what the series is for.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288745173 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8278#issuecomment-6288745173). Originally posted by [saarthakpant](https://github.com/saarthakpant) on 2026-10-20T10:21:42Z. --- Tested this on Ghostrunner 2 (PPSA09911), Windows 11 10.0.26200, RTX 2060 SUPER (617.42), MinGW GCC 15.2.0, applied on top of `main` 4b462ef60 + #7687 + #5372 + the 8 MiB written-staging change (the stack this title needs to reach gameplay here), two scripted gameplay runs of about 5 minutes each with `APS5_PROFILE_GPU=1 APS5_PROFILE_DRAW=1`, against one run of the same stack without this PR. No behaviour change: same scene progression, no errors or asserts, dispatch and draw counts per 10 s window match. Performance is inside the run-to-run spread of scripted runs of this title (medians over the steady 10 s windows): | | without #8278 | #8278 run 1 | #8278 run 2 | |---|---|---|---| | presents per 10 s | 37 | 29.5 | 33 | | idle gaps per frame | 171 ms | 241 ms | 190 ms | | dispatch, total µs per direct dispatch (queue 0) | 147 | 165 | 150 | | of which device call | 61 | 75 | 58 | | draw, total µs per packet | 87 | 90 | 80 | Two runs of one build in the same session earlier differed by 33 vs 28 presents per 10 s, so the refactor costs nothing measurable here; the draw committer carries the frame on this title (about 65 ms busy per frame against 30 ms on queue worker 0), which is what the series is for.
m335671 commented 2026-10-20 11:13:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by m335671 on 2026-10-20T11:13:55Z.


Thanks for running this on Ghostrunner 2. Matching dispatch and draw counts, with timings inside the run-to-run spread, is what a no-behaviour-change split should show. The draw committer carrying the frame there also matches what we see on Sword of the Sea, which is why the draw-side series matters as much as this one.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289587923 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8278#issuecomment-6289587923). Originally posted by [m335671](https://github.com/m335671) on 2026-10-20T11:13:55Z. --- Thanks for running this on Ghostrunner 2. Matching dispatch and draw counts, with timings inside the run-to-run spread, is what a no-behaviour-change split should show. The draw committer carrying the frame there also matches what we see on Sword of the Sea, which is why the draw-side series matters as much as this one. AI-assisted: yes (Claude Code).
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
boykopovar/AnyPS5!8278
No description provided.