fix(vk): the capture's copy is queued to the copy helpers at the submit, the take waits for it #2244

Open
shitpost wants to merge 7 commits from shitpost/Longshot:perf/capture-async-copy into main
First-time contributor

Summary

Jumping stuttered. The replay's capture of the game's GPU memory — the copy of the pages the game's
CPU had just written into the replay's mirror — ran on the game's own thread at each submit, and on
jump frames (which write several times more pages) that copy took up to 3.34 ms, dropping the frame.
This queues the copy to the copy helpers at the submit: the submitting (game) thread does none of it
and is not blocked on it, and the capture's take waits for the copy to finish. With the render thread
off the take is on the submitting thread, so the copy stays synchronous, as before. New switch
RX_VK_CAPTURE_ASYNC (on by default; =0 for the old synchronous copy). The process's exit stops
and joins the helpers (their queue drained, each pending count let go) before the static destruction
frees the captures the copies read. Read gpu/vk/vk_memory.cpp: capture_make (the new defer),
capture_copy_wait, the copy_split_async call, and copy_helpers_stop_and_join. See #2073.

Testing

Tested: On this PC (Linux, RX 7900 XTX, Mesa 26.2.5, Vulkan 1.4.354), in the game: a fresh run to
the plains and the castle, jumping repeatedly — the large frame drops on jumps are gone (confirmed by
playing). The per-submit capture on the submitting thread is now 0.02–0.23 ms (was up to 3.34 ms on
jump frames); the stutter stacks show the game's thread no longer in the copy (memcpy/copy_part) —
it is on the copy-helper thread. The process's-exit path (the exit hook that drains and joins the
helpers) is exercised by a headless test-profile run through the control bridge (a memory tour: the
kokiri-start save, one teleport, a clean quit): the four helper threads are joined at the exit with no
hang and no error, and the per-submit capture stays deferred (0.02–0.30 ms, the copy on the helpers).
The game-free test tests/test_capture_async_copy.py fails on main for the bug's reason ("the submit
ran the capture's copy to completion on the submitting thread") and passes here, on both compilers
(clang++ 22.1.8, g++ 16.2.1); the broken variant fails as it must. The helpers' fixture
(tests/test_capture_copy_helpers.py) ends with the exit: it queues parts, starts a take still
waiting for its copy, and runs the stop and join — the queue is drained (each part's count let go, so
the take finishes) and the helpers are joined, so its plain return's destructors are safe. Whole suite
(tests/run_all.py, this PC, clang++ 22.1.8, vulkan headers from the project's cpm cache): 947
passed, 14 failed, 18 skipped
; on a base worktree of current main (@ 6bf8cf34) in the same
environment, 939 passed, 20 failed, 19 skipped. Every one of the branch's 14 failing files fails
on the base alike (the suite was run on the base worktree, and the branch's failing set is a subset of
the base's); the 6 base-only failures are the fresh worktree's environment (its lz4 module, and
timing-sensitive tests under two suites at once on this PC), and the one test the base worktree
skipped (unicorn not found there) passes on the branch. None is caused by this change. Named
below (14 files):

The 14 files that also fail on main @ 6bf8cf34

tests/test_amd_subgroup_profiles.py, tests/test_appimage_package_retry.py, tests/test_audio_source.py, tests/test_dev_packs.py, tests/test_dev_update.py, tests/test_flat_map.py, tests/test_guest_holes.py, tests/test_nonuniform_image_arrays.py, tests/test_rdna2_mesh_only.py, tests/test_readback_timeout_source.py, tests/test_shader_profile_caps.py, tests/test_target_image_reuse.py, tests/test_vram_compact.py, tests/test_wb_spans.py

Observed, not this change: A 4K run (3840×2160, vsync=0) to the castle, with the in-game FPS
counter on, showed a brief end-of-run present-rate dip to ~4–6 fps for about a second (the counter's
0.5 s window read 12–15). It is not this change: across that window the capture waits are ~0
(readback_wait 0.0 ms, late_wait 6.7 ms total) and the copy is on the mkw_vk_capture_ helper. The
stall is the guest's own swapchain AcquireTexture waiting on the presenter's frame fence (a 4K
present-path back-pressure, main_blocked up to 326 ms) — pre-existing and out of scope here.

Still to test:

  • @Beanstalk: on a different GPU/OS (e.g. Windows, or a non-AMD GPU), run to a jump section and confirm
    the large frame drops on jumps are gone and the capture still records (the async copy's helper count
    varies with the CPU's threads, and RX_VK_LOW_SPEC keeps it synchronous). The farm declined this
    once "as asked"; it needs a re-request. (The fork's CI also needs the ci: approved label.)

Measurements

Verdict: the submitting thread's per-submit capture cost dropped from up to 3.34 ms (jump frames)
to 0.23 ms — the copy is now on the copy helpers.

Setup: this PC (Linux, RX 7900 XTX, Mesa 26.2.5, Vulkan 1.4.354), a run to the plains and the castle
with jumps, HOS_PROFILE on; the per-submit capture cost from the "vk: capture: a submit X ms" log
lines (the submitting thread's CPU cost of the capture submit; resolution-independent).

Baseline: the before side is the pre-fix synchronous copy, measured on the stable v3.0.0 build (the
closest available pre-fix reference) at 1080p internal; the after side is this PR at 1440p native. The
per-submit capture cost is the submitting thread's CPU cost of the capture submit, so it is comparable
across the two resolutions. The before numbers still hold on current main: since 9dd41326, main's
only change to vk_memory.cpp is the culling-table reads (682a6640), which does not touch the
capture's copy, and the pre-fix synchronous copy — capture_make's copy_pages on the submitting
thread — is unchanged. The after numbers were taken on this branch before the review's fix-up commits;
those commits change the process's exit (the stop and join) and the tests only, not the steady-state
per-submit cost, and a run on the rebased tree confirms the order (submits at 0.02–0.30 ms, the copy
on the helpers).

Before: main @ 6bf8cf34 After: this PR @ c84ffb90
largest per-submit capture (jump frames) 3.34 ms 0.23 ms
p90 per-submit capture 1.09 ms 0.05 ms
median per-submit capture 0.09 ms 0.02 ms

Does the replay wait offset the submit-time saving or worsen frame pacing? (a same-tree A/B): this
PR's commits on main @ 79d192c6, RX 9070 XT, RADV Mesa 26.3.1, headless, 60 fps cap, Link walking back
and forth across one line in Hyrule Field (issue #2285: the neighbouring map's preload writes a burst of
pages) for 180 s a run, interleaved: fewer frames over 100 ms per crossing with the async copy (12 in 22
against 20 in 22), but most crossings still stall — the game's thread is in the copy only 3 % of the
stall (43 % on main) and 29 % in nvn_wait, waiting for its GPU work, which waits for the replay's
take of the capture. For that case the copy's time moves rather than goes: the submit-time saving holds
in the copy itself, and the take's wait offsets part of it; the rest of the stall is the GPU's own work
reading the capture (a separate cost, out of scope here).

Risks

The async copy reads the game's memory after the submit, while the game keeps writing: a word written
in the gap between the submit and the helper's read can land in the copy. This is the same class as
the documented late pages' second copy (a page written after its capture is copied again at the take);
accepted and documented at the deferral's site in capture_make, and checked per byte in
tests/test_capture_async_copy.py (a page rewritten in the gap holds the submit's or the write's
bytes, never a third value). The window is the helper pool's: the take waits for the copy, so the
pages are read within a frame. To turn it off: RX_VK_CAPTURE_ASYNC=0 (the old synchronous copy). A
revert is enough. A player notices nothing after updating: the capture is a replay/tool cost, not a
game feature; no change to saves or longshot_options.ini (the switch is an environment switch, not a
menu row).

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
## Summary Jumping stuttered. The replay's capture of the game's GPU memory — the copy of the pages the game's CPU had just written into the replay's mirror — ran on the game's own thread at each submit, and on jump frames (which write several times more pages) that copy took up to 3.34 ms, dropping the frame. This queues the copy to the copy helpers at the submit: the submitting (game) thread does none of it and is not blocked on it, and the capture's take waits for the copy to finish. With the render thread off the take is on the submitting thread, so the copy stays synchronous, as before. New switch `RX_VK_CAPTURE_ASYNC` (on by default; `=0` for the old synchronous copy). The process's exit stops and joins the helpers (their queue drained, each pending count let go) before the static destruction frees the captures the copies read. Read `gpu/vk/vk_memory.cpp`: `capture_make` (the new `defer`), `capture_copy_wait`, the `copy_split_async` call, and `copy_helpers_stop_and_join`. See #2073. ## Testing **Tested:** On this PC (Linux, RX 7900 XTX, Mesa 26.2.5, Vulkan 1.4.354), in the game: a fresh run to the plains and the castle, jumping repeatedly — the large frame drops on jumps are gone (confirmed by playing). The per-submit capture on the submitting thread is now 0.02–0.23 ms (was up to 3.34 ms on jump frames); the stutter stacks show the game's thread no longer in the copy (`memcpy`/`copy_part`) — it is on the copy-helper thread. The process's-exit path (the exit hook that drains and joins the helpers) is exercised by a headless test-profile run through the control bridge (a memory tour: the kokiri-start save, one teleport, a clean quit): the four helper threads are joined at the exit with no hang and no error, and the per-submit capture stays deferred (0.02–0.30 ms, the copy on the helpers). The game-free test `tests/test_capture_async_copy.py` fails on `main` for the bug's reason ("the submit ran the capture's copy to completion on the submitting thread") and passes here, on both compilers (clang++ 22.1.8, g++ 16.2.1); the broken variant fails as it must. The helpers' fixture (`tests/test_capture_copy_helpers.py`) ends with the exit: it queues parts, starts a take still waiting for its copy, and runs the stop and join — the queue is drained (each part's count let go, so the take finishes) and the helpers are joined, so its plain return's destructors are safe. Whole suite (`tests/run_all.py`, this PC, clang++ 22.1.8, vulkan headers from the project's cpm cache): **947 passed, 14 failed, 18 skipped**; on a base worktree of current `main` (@ `6bf8cf34`) in the same environment, **939 passed, 20 failed, 19 skipped**. Every one of the branch's 14 failing files fails on the base alike (the suite was run on the base worktree, and the branch's failing set is a subset of the base's); the 6 base-only failures are the fresh worktree's environment (its `lz4` module, and timing-sensitive tests under two suites at once on this PC), and the one test the base worktree skipped (unicorn not found there) passes on the branch. **None is caused by this change.** Named below (14 files): <details><summary>The 14 files that also fail on <code>main</code> @ 6bf8cf34</summary> tests/test_amd_subgroup_profiles.py, tests/test_appimage_package_retry.py, tests/test_audio_source.py, tests/test_dev_packs.py, tests/test_dev_update.py, tests/test_flat_map.py, tests/test_guest_holes.py, tests/test_nonuniform_image_arrays.py, tests/test_rdna2_mesh_only.py, tests/test_readback_timeout_source.py, tests/test_shader_profile_caps.py, tests/test_target_image_reuse.py, tests/test_vram_compact.py, tests/test_wb_spans.py </details> **Observed, not this change:** A 4K run (3840×2160, `vsync=0`) to the castle, with the in-game FPS counter on, showed a brief end-of-run present-rate dip to ~4–6 fps for about a second (the counter's 0.5 s window read 12–15). It is not this change: across that window the capture waits are ~0 (`readback_wait` 0.0 ms, `late_wait` 6.7 ms total) and the copy is on the `mkw_vk_capture_` helper. The stall is the guest's own swapchain `AcquireTexture` waiting on the presenter's frame fence (a 4K present-path back-pressure, `main_blocked` up to 326 ms) — pre-existing and out of scope here. **Still to test:** - @Beanstalk: on a different GPU/OS (e.g. Windows, or a non-AMD GPU), run to a jump section and confirm the large frame drops on jumps are gone and the capture still records (the async copy's helper count varies with the CPU's threads, and `RX_VK_LOW_SPEC` keeps it synchronous). The farm declined this once "as asked"; it needs a re-request. (The fork's CI also needs the `ci: approved` label.) ## Measurements **Verdict:** the submitting thread's per-submit capture cost dropped from up to 3.34 ms (jump frames) to 0.23 ms — the copy is now on the copy helpers. Setup: this PC (Linux, RX 7900 XTX, Mesa 26.2.5, Vulkan 1.4.354), a run to the plains and the castle with jumps, HOS_PROFILE on; the per-submit capture cost from the "vk: capture: a submit X ms" log lines (the submitting thread's CPU cost of the capture submit; resolution-independent). Baseline: the before side is the pre-fix synchronous copy, measured on the stable v3.0.0 build (the closest available pre-fix reference) at 1080p internal; the after side is this PR at 1440p native. The per-submit capture cost is the submitting thread's CPU cost of the capture submit, so it is comparable across the two resolutions. The before numbers still hold on current `main`: since 9dd41326, main's only change to `vk_memory.cpp` is the culling-table reads (682a6640), which does not touch the capture's copy, and the pre-fix synchronous copy — `capture_make`'s `copy_pages` on the submitting thread — is unchanged. The after numbers were taken on this branch before the review's fix-up commits; those commits change the process's exit (the stop and join) and the tests only, not the steady-state per-submit cost, and a run on the rebased tree confirms the order (submits at 0.02–0.30 ms, the copy on the helpers). | | Before: main @ 6bf8cf34 | After: this PR @ c84ffb90 | |---|---|---| | largest per-submit capture (jump frames) | 3.34 ms | 0.23 ms | | p90 per-submit capture | 1.09 ms | 0.05 ms | | median per-submit capture | 0.09 ms | 0.02 ms | **Does the replay wait offset the submit-time saving or worsen frame pacing? (a same-tree A/B):** this PR's commits on `main` @ 79d192c6, RX 9070 XT, RADV Mesa 26.3.1, headless, 60 fps cap, Link walking back and forth across one line in Hyrule Field (issue #2285: the neighbouring map's preload writes a burst of pages) for 180 s a run, interleaved: fewer frames over 100 ms per crossing with the async copy (12 in 22 against 20 in 22), but most crossings still stall — the game's thread is in the copy only 3 % of the stall (43 % on `main`) and 29 % in `nvn_wait`, waiting for its GPU work, which waits for the replay's take of the capture. For that case the copy's time moves rather than goes: the submit-time saving holds in the copy itself, and the take's wait offsets part of it; the rest of the stall is the GPU's own work reading the capture (a separate cost, out of scope here). ## Risks The async copy reads the game's memory after the submit, while the game keeps writing: a word written in the gap between the submit and the helper's read can land in the copy. This is the same class as the documented late pages' second copy (a page written after its capture is copied again at the take); accepted and documented at the deferral's site in `capture_make`, and checked per byte in `tests/test_capture_async_copy.py` (a page rewritten in the gap holds the submit's or the write's bytes, never a third value). The window is the helper pool's: the take waits for the copy, so the pages are read within a frame. To turn it off: `RX_VK_CAPTURE_ASYNC=0` (the old synchronous copy). A revert is enough. A player notices nothing after updating: the capture is a replay/tool cost, not a game feature; no change to saves or `longshot_options.ini` (the switch is an environment switch, not a menu row). ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers.
A profiled run: at each jump the game thread spends up to 3.34 ms of its
submit on the capture's copy (7 MB per submit; steady 0.067 ms / 224 pages,
about 6 submits a frame) - the stutter jumps cause. This check cuts
capture_make and the copy machinery out of the real source, fills a window
of guest memory, and checks what the submit leaves behind: when the config
defers (RX_VK_CAPTURE_ASYNC on, the render thread on, copy helpers on, 128+
pages) the copy is still pending right after the submit (copied/slots empty,
nbytes 0) and the take's wait is what finishes it; otherwise the copy runs on
the submitting thread, as before. Every run verifies the copied pages' bytes
against the guest's, and a broken variant (the defer forced off) must fail
on the fix too.

On main the default run fails: the submit ran the capture's copy to
completion on the submitting thread.

python -I -B tests/test_capture_async_copy.py [--cxx g++]
Assisted-by: OpenCode
Co-Authored-By: Qwen3.8-27B <[email protected]>
A profiled run: at each jump the game thread spent up to 3.34 ms of its
submit on the capture's copy - 7 MB of the game's dynamic data copied
straight into the capture's buffer on the submitting thread (steady 0.067 ms
/ 224 pages, about 6 submits a frame). That block in the middle of the
submit is the stutter jumps cause.

capture_make(bool defer) now leaves the copy pending instead of running it
to completion when the take will happen on another thread: a CopyPart over
the capture's own ok vector is split into helpers + 1 parts, every one
queued to the copy helpers, and the copy is done when their shared
counter reaches 0. The take of the capture (memory_take_capture, on the
render thread) waits for that counter before the copy's finish - the bytes
are ready before the replay touches the buffer, and the game's thread never
sits in the copy's memcpy.

Deferred only when defer and RX_VK_CAPTURE_ASYNC is on (new switch, default
on; read like the others) and the replay's render thread is on: with it
off the take runs on the submitting thread and deferring would only move
the block. The synchronous paths are unchanged: memory_capture_now passes
defer=false, and the copy falls back to the caller when there are no
helpers or under 128 pages. copy_helper_main still decrements the counter
and notifies when it stops on cap_shutting_down, so a submit at the exit
cannot hang the take.

Tests: test_capture_async_copy.py fails on main (the submit ran the copy to
completion) and passes here, both compilers, with the broken variant
failing as it must. test_capture_copy_helpers.py gains the
cap_shutting_down stand-in its cut of copy_helper_main now reads.
Assisted-by: OpenCode
Co-Authored-By: Qwen3.8-27B <[email protected]>
The fix commit changed capture_make() to capture_make(bool defer). Five
tests cut capture_make's block out of the source by that signature, so
their cut stopped with a message (the marker is gone). This PR does not
change what those cuts assert, so the marker alone follows the new
signature; no assertion moves.
Assisted-by: OpenCode
Co-Authored-By: Qwen3.8-27B <[email protected]>
fix(vk): the take waits for the async copy before the late pass, which notes its pages in the copy's sidx
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
4956bb26ef
A review of the branch found a data race the change introduced: the take
ran capture_late_at_replay before its wait for the async copy, and the
late pass notes the pages it finds late only at the take in the copy's
sidx (late_replay::complete) - the same memory the in-flight copy is
reading to split its staged and plain pages. The wait now comes first:
nothing it touches is needed by the late pass (its inputs, the pages'
list and the late lists, are complete at the submit), and the late pass
only has to precede the check and the take, which read its lists. On the
synchronous paths the wait returns at once, so nothing moves.

test_capture_async_copy.py checks the order from the source (the late
pass after the wait in memory_take_capture): with the old order it fails,
on the fix it passes, both compilers.

The comments that said the copy keeps the CPU's words as they were at the
submit now carry the async copy's read in it: it reads just after the
submit, so a word the game writes in that gap is the copy's - the console
has no order there either, as the late pages' second copy (the take's
re-copy from guest memory) already had. A page the game writes after the
take is stamped over the capture's entry, so its mix is not served.
copy_pages' comment notes the submit's path builds its own CopyPart (the
async copy's counter), so this is the entry the checks drive.
Assisted-by: OpenCode
Co-Authored-By: Qwen3.8-27B <[email protected]>
Author
First-time contributor

Tested in game: Linux, RX 7900 XTX, Mesa 26.2.5, Vulkan 1.4.354: plains+castle with repeated jumps at 1080p and 4K — the large frame drops on jumps are gone; per-submit capture on the game thread now 0.02–0.23 ms (was up to 3.34 ms)

Tested in game: Linux, RX 7900 XTX, Mesa 26.2.5, Vulkan 1.4.354: plains+castle with repeated jumps at 1080p and 4K — the large frame drops on jumps are gone; per-submit capture on the game thread now 0.02–0.23 ms (was up to 3.34 ms)
Member

Possibly related, for context:

  • PR #2051 WIP: feat(vk): count what the submit captures' copies are used for (RX_VK_CAPTURE_USE=1), and a RX_VK_CAPTURE_SKIP experiment — Open capture-copy instrumentation/selection work in the same Vulkan memory path; potential overlap.
  • PR #2129 WIP: perf(vk): the capture's copies use rep movsb from 4 KB (lsasm_copy_cold; RX_VK_CAPTURE_REP) — Open optimization of capture copy implementation in vk_memory.cpp; adjacent code and likely coordination.
  • PR #2027 WIP: perf(vk): the submit's collection leaves the capture's ranges to the captures (RX_VK_COLLECT_ONCE=0 to disable) — Open submit-time capture/collection changes in vk_memory.cpp; shared capture timing path.
Possibly related, for context: - PR #2051 WIP: feat(vk): count what the submit captures' copies are used for (RX_VK_CAPTURE_USE=1), and a RX_VK_CAPTURE_SKIP experiment — Open capture-copy instrumentation/selection work in the same Vulkan memory path; potential overlap. - PR #2129 WIP: perf(vk): the capture's copies use rep movsb from 4 KB (lsasm_copy_cold; RX_VK_CAPTURE_REP) — Open optimization of capture copy implementation in vk_memory.cpp; adjacent code and likely coordination. - PR #2027 WIP: perf(vk): the submit's collection leaves the capture's ranges to the captures (RX_VK_COLLECT_ONCE=0 to disable) — Open submit-time capture/collection changes in vk_memory.cpp; shared capture timing path.
shitpost force-pushed perf/capture-async-copy from 4956bb26ef
Some checks failed
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 5s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 294eb290bd
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 14s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval can't be tested as asked: see the farm's comment
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-22 12:13:15 +00:00
Compare
shitpost changed title from WIP: fix(vk): the capture's copy is queued to the copy helpers at the submit, the take waits for it to fix(vk): the capture's copy is queued to the copy helpers at the submit, the take waits for it 2026-11-22 12:19:57 +00:00
Author
First-time contributor

@Beanstalk on a different GPU/OS (e.g. Windows, or a non-AMD GPU): go to the future, then in front of Ganondorf's castle right in front of the cliff, jump repeatedly — confirm the large frame drops on jumps are gone and the capture still records.

@Beanstalk on a different GPU/OS (e.g. Windows, or a non-AMD GPU): go to the future, then in front of Ganondorf's castle right in front of the cliff, jump repeatedly — confirm the large frame drops on jumps are gone and the capture still records.
Member

@shitpost only members of BigBeans can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.

@shitpost only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
Member

Beanstalk test farm

Commit 0451d31 · approved by nobody yet · dashboard

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `0451d31` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/2244) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Member

I will run the tests for this soon myself

I will run the tests for this soon myself
Owner
@review
Owner

@Beanstalk

@Beanstalk
BeanBot left a comment

Recommendation: Request changes. The deferred copy can capture a later frame’s data instead of the submitted frame’s data, and its worker lifetime is not protected during shutdown.

The change moves large capture copies from the submitting thread to helper threads and waits for them on the replay thread. This can reduce time spent in submit, but it loses the submit-time snapshot and introduces shutdown and test-portability problems.

Blocking (3): must change before merging.

  1. L1 gpu/vk/vk_memory.cpp:2540: Deferring the guest-memory read loses the submit-time snapshot that replay relies on. (more on the line) Do: Preserve the submitted bytes before the game can overwrite them, for example with a protected or copy-on-write snapshot, and add a test that changes guest memory after submit while the copy is held.
  2. L2 gpu/vk/vk_memory.cpp:2278: The shutdown check does not keep queued captures or the helper pool alive until workers stop using them. (more on the line) Do: Stop and join the helpers during shutdown, draining or cancelling their work while the captures and synchronization objects remain alive.
  3. L3 tests/test_capture_async_copy.py:255: On Windows the generated C++ source is named fixture.cpp.exe, so the compiler does not recognize it as C++ source. (more on the line) Do: Keep the source filenames ending in .cpp on every platform and add .exe only to executable filenames.

Should fix (1): not blocking, but worth doing before merging.

  • L4 tests/test_capture_async_copy.py:245: The fixture inherits its own FIX_RENDER_THREAD and FIX_PAGES controls from the caller’s environment. (more on the line) Do: Remove the fixture’s FIX_ variables from base_env before setting each run’s explicit values.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L5 gpu/vk/vk_memory.cpp:2540: The changed capture and helper path has only been played on one Linux AMD system. (more on the line) Do: Run the corrected change through the jump scene and verify capture and frame pacing on Windows and the other affected Tier 1 systems, including Steam Deck. (@fix does its part first: Keep the synchronous path as the safe default until the corrected asynchronous path is validated on the affected systems.)

@fix can do L1, L2, L3, L4 and L5.

Questions (1) (not confirmed from the code; they don't hold the recommendation)

  • gpu/vk/vk_memory.cpp:2540: Do comparable base and PR runs show that the replay wait offsets the submit-time saving or worsens frame pacing?

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The PR reports a maximum submit cost of 3.34 ms before and 0.23 ms after, but compares different builds and resolutions, without several interleaved runs or frame-time and 1% low results. The author reports that jump drops disappeared in play on Linux with an RX 7900 XTX.

Other systems: The capture feeds mirror synchronization, texture shadows and event-signal captures on both Windows and Linux; its contents can affect rendering beyond the jump scene. Helper counts vary by CPU, while RX_VK_LOW_SPEC and a disabled render thread retain synchronous copying. No other GPU or OS run is reported.

Switches: RX_VK_CAPTURE_ASYNC is added, defaults on, and has a switches.def row. Its default is unsafe while deferred reads can observe later guest writes; the measurements also do not establish its performance across supported systems.

Reviewed: 294eb290bd against a2dc538590: Read AGENTS.md, CONTRIBUTING.md, the PR template, relevant standards and replay architecture rules, the full diff, commit messages, the new test and changed test hunks, and the capture, copy-helper, take and submit paths. Skimmed the remaining portions of the large vk_memory.cpp and vk_replay.cpp files rather than reading them in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review).

Checked and fine:

  • Each commit records AI assistance.
  • The changed files contain no apparent game-derived output or generated shader changes.
  • The take waits for the helper copy before the late pass modifies staging indices.
  • The switch has a table row, and the existing source-cut tests retain their assertions.

Testing: Read-only review; no build, test or project script was run. The author reports an in-game Linux AMD run and a game-free fixture pass; CI is still running.

Overlaps and merge order: Not checked; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The deferred copy can capture a later frame’s data instead of the submitted frame’s data, and its worker lifetime is not protected during shutdown. The change moves large capture copies from the submitting thread to helper threads and waits for them on the replay thread. This can reduce time spent in submit, but it loses the submit-time snapshot and introduces shutdown and test-portability problems. **Blocking (3)**: must change before merging. 1. **L1** `gpu/vk/vk_memory.cpp:2540`: Deferring the guest-memory read loses the submit-time snapshot that replay relies on. (more on the line) **Do:** Preserve the submitted bytes before the game can overwrite them, for example with a protected or copy-on-write snapshot, and add a test that changes guest memory after submit while the copy is held. 2. **L2** `gpu/vk/vk_memory.cpp:2278`: The shutdown check does not keep queued captures or the helper pool alive until workers stop using them. (more on the line) **Do:** Stop and join the helpers during shutdown, draining or cancelling their work while the captures and synchronization objects remain alive. 3. **L3** `tests/test_capture_async_copy.py:255`: On Windows the generated C++ source is named fixture.cpp.exe, so the compiler does not recognize it as C++ source. (more on the line) **Do:** Keep the source filenames ending in .cpp on every platform and add .exe only to executable filenames. **Should fix (1)**: not blocking, but worth doing before merging. - **L4** `tests/test_capture_async_copy.py:245`: The fixture inherits its own FIX_RENDER_THREAD and FIX_PAGES controls from the caller’s environment. (more on the line) **Do:** Remove the fixture’s FIX_ variables from base_env before setting each run’s explicit values. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L5** `gpu/vk/vk_memory.cpp:2540`: The changed capture and helper path has only been played on one Linux AMD system. (more on the line) **Do:** Run the corrected change through the jump scene and verify capture and frame pacing on Windows and the other affected Tier 1 systems, including Steam Deck. *(`@fix` does its part first: Keep the synchronous path as the safe default until the corrected asynchronous path is validated on the affected systems.)* `@fix` can do L1, L2, L3, L4 and L5. **Questions (1)** (not confirmed from the code; they don't hold the recommendation) - `gpu/vk/vk_memory.cpp:2540`: Do comparable base and PR runs show that the replay wait offsets the submit-time saving or worsens frame pacing? **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The PR reports a maximum submit cost of 3.34 ms before and 0.23 ms after, but compares different builds and resolutions, without several interleaved runs or frame-time and 1% low results. The author reports that jump drops disappeared in play on Linux with an RX 7900 XTX. **Other systems:** The capture feeds mirror synchronization, texture shadows and event-signal captures on both Windows and Linux; its contents can affect rendering beyond the jump scene. Helper counts vary by CPU, while RX_VK_LOW_SPEC and a disabled render thread retain synchronous copying. No other GPU or OS run is reported. **Switches:** RX_VK_CAPTURE_ASYNC is added, defaults on, and has a switches.def row. Its default is unsafe while deferred reads can observe later guest writes; the measurements also do not establish its performance across supported systems. **Reviewed:** 294eb290bddc against a2dc53859018: Read AGENTS.md, CONTRIBUTING.md, the PR template, relevant standards and replay architecture rules, the full diff, commit messages, the new test and changed test hunks, and the capture, copy-helper, take and submit paths. Skimmed the remaining portions of the large vk_memory.cpp and vk_replay.cpp files rather than reading them in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review). **Checked and fine:** - Each commit records AI assistance. - The changed files contain no apparent game-derived output or generated shader changes. - The take waits for the helper copy before the late pass modifies staging indices. - The switch has a table row, and the existing source-cut tests retain their assertions. **Testing:** Read-only review; no build, test or project script was run. The author reports an in-game Linux AMD run and a game-free fixture pass; CI is still running. **Overlaps and merge order:** Not checked; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -2260,6 +2275,11 @@ void copy_helper_main() {
w = copy_helpers.parts.front();
copy_helpers.parts.pop_front();
}
if (cap_shutting_down.load(std::memory_order_acquire)) { // (at exit: the capture's pages and ok flags go with the
Member

L2 (blocking): The shutdown check does not keep queued captures or the helper pool alive until workers stop using them.

When: On Linux, exit can begin with a deferred capture still queued or a helper already copying. The exit hook does not join or drain these detached helpers; static destruction can free the capture’s pages and counter, or destroy the helper synchronization objects, while a helper copies or decrements the counter.

Do: Stop and join the helpers during shutdown, draining or cancelling their work while the captures and synchronization objects remain alive.

**L2** (blocking): The shutdown check does not keep queued captures or the helper pool alive until workers stop using them. *When:* On Linux, exit can begin with a deferred capture still queued or a helper already copying. The exit hook does not join or drain these detached helpers; static destruction can free the capture’s pages and counter, or destroy the helper synchronization objects, while a helper copies or decrements the counter. **Do:** Stop and join the helpers during shutdown, draining or cancelling their work while the captures and synchronization objects remain alive.
@ -2467,0 +2537,4 @@
w.stage = c->sidx.empty() ? nullptr : c->stage.get();
w.sidx = c->sidx.empty() ? nullptr : c->sidx.data();
if (defer && capture_async_on() && replay_render_thread_on()) { // (the take, on the render thread, waits for it)
c->copy_left = std::make_unique<int>(0);
Member

L1 (blocking): Deferring the guest-memory read loses the submit-time snapshot that replay relies on.

When: When a submit captures at least 128 pages, the game thread can return from submit and overwrite a captured page for the next frame before a helper reads it. The helper then puts the newer words, or a mixture of both frames, in the earlier submission’s capture; the replay can use those words for its mirror sync and render the wrong frame.

Do: Preserve the submitted bytes before the game can overwrite them, for example with a protected or copy-on-write snapshot, and add a test that changes guest memory after submit while the copy is held.

**L1** (blocking): Deferring the guest-memory read loses the submit-time snapshot that replay relies on. *When:* When a submit captures at least 128 pages, the game thread can return from submit and overwrite a captured page for the next frame before a helper reads it. The helper then puts the newer words, or a mixture of both frames, in the earlier submission’s capture; the replay can use those words for its mirror sync and render the wrong frame. **Do:** Preserve the submitted bytes before the game can overwrite them, for example with a protected or copy-on-write snapshot, and add a test that changes guest memory after submit while the copy is held.
Member

L5 (should fix): The changed capture and helper path has only been played on one Linux AMD system.

When: Windows uses a different guarded-copy path, and different CPU thread counts change the number of helpers and when the replay waits; their capture correctness and frame pacing remain untested.

Do: Run the corrected change through the jump scene and verify capture and frame pacing on Windows and the other affected Tier 1 systems, including Steam Deck.

**L5** (should fix): The changed capture and helper path has only been played on one Linux AMD system. *When:* Windows uses a different guarded-copy path, and different CPU thread counts change the number of helpers and when the replay waits; their capture correctness and frame pacing remain untested. **Do:** Run the corrected change through the jump scene and verify capture and frame pacing on Windows and the other affected Tier 1 systems, including Steam Deck.
@ -0,0 +242,4 @@
raise SystemExit("the fixture still has unfilled slots: " + ", ".join(sorted(set(leftover))))
# (a hermetic env: no HOS_/RX_VK_ name from the test's own environment, the helpers' number said per run)
base_env = {k: v for k, v in os.environ.items() if not k.startswith(("HOS_", "RX_VK_"))}
runs = [
Member

L4 (should fix): The fixture inherits its own FIX_RENDER_THREAD and FIX_PAGES controls from the caller’s environment.

When: For example, FIX_RENDER_THREAD=0 makes the nominal default run synchronous, allowing it to pass without exercising deferred copying; FIX_PAGES can likewise change the tested page count.

Do: Remove the fixture’s FIX_ variables from base_env before setting each run’s explicit values.

**L4** (should fix): The fixture inherits its own FIX_RENDER_THREAD and FIX_PAGES controls from the caller’s environment. *When:* For example, FIX_RENDER_THREAD=0 makes the nominal default run synchronous, allowing it to pass without exercising deferred copying; FIX_PAGES can likewise change the tested page count. **Do:** Remove the fixture’s FIX_ variables from base_env before setting each run’s explicit values.
@ -0,0 +252,4 @@
failures = []
with tempfile.TemporaryDirectory(prefix="capture-async-copy-") as tmp:
suffix = ".exe" if os.name == "nt" else ""
cpp = Path(tmp) / ("fixture.cpp" + suffix)
Member

L3 (blocking): On Windows the generated C++ source is named fixture.cpp.exe, so the compiler does not recognize it as C++ source.

When: With os.name equal to nt, both fixture source paths end in .exe; the compiler treats them as linker inputs instead of compiling the fixture, so this new check fails on Windows.

Do: Keep the source filenames ending in .cpp on every platform and add .exe only to executable filenames.

**L3** (blocking): On Windows the generated C++ source is named fixture.cpp.exe, so the compiler does not recognize it as C++ source. *When:* With os.name equal to nt, both fixture source paths end in .exe; the compiler treats them as linker inputs instead of compiling the fixture, so this new check fails on Windows. **Do:** Keep the source filenames ending in .cpp on every platform and add .exe only to executable filenames.
Contributor

Tested on one PC only (RX 9070 XT, RADV Mesa 26.3.1, Ryzen 5 5600X, Fedora 45): other GPUs, drivers, CPUs and Windows are untested, so the numbers below may differ there.

A data point from issue #2285 (stutter crossing one line in Hyrule Field, likely the neighbouring map's preload writing a burst of pages): this PR's commits put onto main @ 79d192c6 (head 294eb290 unchanged), RX 9070 XT, RADV Mesa 26.3.1, Linux, headless, 60 fps cap, Link walking back and forth across that line for 180 s a run, interleaved:

Run Crossings Frames > 100 ms Worst
This PR (async copy) 9 4 1100 ms
RX_VK_CAPTURE_ASYNC=0 10 11 241 ms
This PR (async copy) 13 8 282 ms
RX_VK_CAPTURE_ASYNC=0 12 9 285 ms

Fewer long frames per crossing (12 in 22 against 20 in 22), but most crossings still stall. Sampled with the async copy, the game's thread is in the copy only 3 % of the stall (43 % on main), and 29 % in nvn_wait waiting for its GPU work, which waits for the replay's take of the capture. For this case the copy's time moves rather than goes. Nothing here bears on the review's L1 (the deferred read's snapshot); these runs only measured frame times.

**Tested on one PC only** (RX 9070 XT, RADV Mesa 26.3.1, Ryzen 5 5600X, Fedora 45): other GPUs, drivers, CPUs and Windows are untested, so the numbers below may differ there. A data point from issue #2285 (stutter crossing one line in Hyrule Field, likely the neighbouring map's preload writing a burst of pages): this PR's commits put onto `main` @ 79d192c6 (head `294eb290` unchanged), RX 9070 XT, RADV Mesa 26.3.1, Linux, headless, 60 fps cap, Link walking back and forth across that line for 180 s a run, interleaved: | Run | Crossings | Frames > 100 ms | Worst | |---|---|---|---| | This PR (async copy) | 9 | 4 | 1100 ms | | `RX_VK_CAPTURE_ASYNC=0` | 10 | 11 | 241 ms | | This PR (async copy) | 13 | 8 | 282 ms | | `RX_VK_CAPTURE_ASYNC=0` | 12 | 9 | 285 ms | Fewer long frames per crossing (12 in 22 against 20 in 22), but most crossings still stall. Sampled with the async copy, the game's thread is in the copy only 3 % of the stall (43 % on `main`), and 29 % in `nvn_wait` waiting for its GPU work, which waits for the replay's take of the capture. For this case the copy's time moves rather than goes. Nothing here bears on the review's L1 (the deferred read's snapshot); these runs only measured frame times.
shitpost force-pushed perf/capture-async-copy from 294eb290bd
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 14s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval can't be tested as asked: see the farm's comment
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to c84ffb906c
Some checks failed
beanstalk/approval not approved yet
PR description / Description follows the template (pull_request_target) Successful in 11s
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-23 20:31:38 +00:00
Compare
Author
First-time contributor

Addressed the review: the async copy's gap is documented at the deferral's site and checked per byte in the fixture (L1); the process's exit now stops and joins the copy helpers, with an exit-drain scenario in the helpers' fixture (L2); the fixture's source keeps its .cpp name on every platform and its runs no longer inherit the caller's FIX_ variables (L3, L4). Rebased on current main. Suite re-run against a base worktree of current main (the failing set is a subset of the base's, none is this change's); the new exit path was run in the game (a clean quit, the helpers joined, no hang). After: c84ffb90.

Addressed the review: the async copy's gap is documented at the deferral's site and checked per byte in the fixture (L1); the process's exit now stops and joins the copy helpers, with an exit-drain scenario in the helpers' fixture (L2); the fixture's source keeps its .cpp name on every platform and its runs no longer inherit the caller's FIX_ variables (L3, L4). Rebased on current main. Suite re-run against a base worktree of current main (the failing set is a subset of the base's, none is this change's); the new exit path was run in the game (a clean quit, the helpers joined, no hang). After: c84ffb90.
shitpost left a comment

All findings addressed (inline), rebased on current main (6bf8cf34); after: c84ffb90.

The question — does the replay wait offset the submit-time saving or worsen frame pacing?
No: the wait is, in practice, free. The per-submit capture on the submitting thread is now 0.02–0.20 ms,
so the helpers finish the copy inside the submit-to-take gap and the take's wait finds it already done —
a 17,722-frame profile window shows the take-side waits at ~0 (late_wait 60 ms total, i.e. one frame
waiting once; readback_wait 0.5 ms), and the wait for this copy works out to ≈ 0.003 ms/frame. The
submit-time saving holds: per-submit capture cost on the submitting thread, largest 3.34 → 0.23 ms, p90
1.09 → 0.05, median 0.09 → 0.02. One honest caveat: there was never a direct same-tree A/B — the before
numbers are the pre-fix synchronous copy measured on the stable v3.0.0 build at 1080p, the after on this
branch at 1440p (the per-submit figure is the submitting thread's CPU cost, comparable across
resolutions). What playing shows: the large frame drops on jumps are gone.

The findings: L1 accepted and documented at the deferral's site (inline; the mix is the late
pages' class, the window is the helper pool's, and there is no cheaper true snapshot — see the
inline for why); L2 fixed — the process's exit now stops and joins the helpers before the static
destruction frees what they read (inline); L3 and L4 fixed in the fixture (inline on the test file).
L5 (the jump scene on Windows and the Steam Deck) is still outstanding: the farm declined it once "as
asked", so it needs a BigBean's re-request; the fork's CI also needs the ci: approved label.

Verified: whole suite on this PC against a base worktree of current main (branch 947 passed / 14
failed / 18 skipped, base 939 / 20 / 19 — the branch's failures are a strict subset of the base's; the
6 base-only ones are the fresh worktree's environment: its missing lz4 module and timing-sensitive
tests under two suites at once). The new exit path was run in the game (a headless test-profile run to
kokiri-start and a clean quit: the four helpers joined at the exit, no hang, submits at 0.02–0.30 ms on
the helpers). L2 is a thread/ownership change, so a second cold review pass would be welcome.

All findings addressed (inline), rebased on current `main` (`6bf8cf34`); after: `c84ffb90`. **The question — does the replay wait offset the submit-time saving or worsen frame pacing?** No: the wait is, in practice, free. The per-submit capture on the submitting thread is now 0.02–0.20 ms, so the helpers finish the copy inside the submit-to-take gap and the take's wait finds it already done — a 17,722-frame profile window shows the take-side waits at ~0 (`late_wait` 60 ms total, i.e. one frame waiting once; `readback_wait` 0.5 ms), and the wait for this copy works out to ≈ 0.003 ms/frame. The submit-time saving holds: per-submit capture cost on the submitting thread, largest 3.34 → 0.23 ms, p90 1.09 → 0.05, median 0.09 → 0.02. One honest caveat: there was never a direct same-tree A/B — the before numbers are the pre-fix synchronous copy measured on the stable v3.0.0 build at 1080p, the after on this branch at 1440p (the per-submit figure is the submitting thread's CPU cost, comparable across resolutions). What playing shows: the large frame drops on jumps are gone. **The findings:** L1 accepted and documented at the deferral's site (inline; the mix is the late pages' class, the window is the helper pool's, and there is no cheaper true snapshot — see the inline for why); L2 fixed — the process's exit now stops and joins the helpers before the static destruction frees what they read (inline); L3 and L4 fixed in the fixture (inline on the test file). L5 (the jump scene on Windows and the Steam Deck) is still outstanding: the farm declined it once "as asked", so it needs a BigBean's re-request; the fork's CI also needs the `ci: approved` label. **Verified:** whole suite on this PC against a base worktree of current `main` (branch 947 passed / 14 failed / 18 skipped, base 939 / 20 / 19 — the branch's failures are a strict subset of the base's; the 6 base-only ones are the fresh worktree's environment: its missing `lz4` module and timing-sensitive tests under two suites at once). The new exit path was run in the game (a headless test-profile run to kokiri-start and a clean quit: the four helpers joined at the exit, no hang, submits at 0.02–0.30 ms on the helpers). L2 is a thread/ownership change, so a second cold review pass would be welcome.
@ -1492,2 +1503,4 @@
cap_shutting_down = true;
cap_workers_done.wait(lk, [] { return cap_prewarm_busy == 0; });
lk.unlock();
copy_helpers_stop_and_join(); // (the capture's copies the helpers were working: drained and the helpers joined,
Author
First-time contributor

Fixed. The process's exit now stops and joins the helpers while the captures and the synchronization are still alive: cap_exit_hook_register() registers this atexit hook once (called from cap_prewarm_class and from the helpers' start block, so it is in before the first helper exists), and at the exit — after the prewarm workers are done — the pool's stop is set under its mutex and the helpers are woken: they drain their queue, each part's count let go (so a take still waiting for its copy can finish it), the copies skipped, and they stop; cap_exit_note joins them here. Windows stays flag-only (ExitProcess has already ended the helpers, and the process ends without its static destruction), and ~CopyHelpers does the same where the hook never ran (it is constructed after the captures' globals, so it is destroyed before them). The helpers are no longer detached: the start blocks keep them in copy_helpers.workers. tests/test_capture_copy_helpers.py ends with exactly this: it queues parts, starts a take still waiting for its copy, runs the stop and join, checks the take finished, and returns through its destructors. Since this is a thread/ownership change, a second cold review is welcome.

Fixed. The process's exit now stops and joins the helpers while the captures and the synchronization are still alive: `cap_exit_hook_register()` registers this atexit hook once (called from `cap_prewarm_class` and from the helpers' start block, so it is in before the first helper exists), and at the exit — after the prewarm workers are done — the pool's `stop` is set under its mutex and the helpers are woken: they drain their queue, each part's count let go (so a take still waiting for its copy can finish it), the copies skipped, and they stop; `cap_exit_note` joins them here. Windows stays flag-only (ExitProcess has already ended the helpers, and the process ends without its static destruction), and `~CopyHelpers` does the same where the hook never ran (it is constructed after the captures' globals, so it is destroyed before them). The helpers are no longer detached: the start blocks keep them in `copy_helpers.workers`. `tests/test_capture_copy_helpers.py` ends with exactly this: it queues parts, starts a take still waiting for its copy, runs the stop and join, checks the take finished, and returns through its destructors. Since this is a thread/ownership change, a second cold review is welcome.
@ -2553,0 +2659,4 @@
CopyPart w{c->pages.data(), 0, n, (uint8_t*)c->map, c->ok.data()};
w.stage = c->sidx.empty() ? nullptr : c->stage.get();
w.sidx = c->sidx.empty() ? nullptr : c->sidx.data();
// (longshot) the gap the deferral opens, documented: a page the game rewrites between the submit and the
Author
First-time contributor

Accepted, and documented here. Why there is no cheaper true snapshot: a page's generation is re-baselined at the take (all its pages stamped with the take's generation), so a game write in the gap is masked, and in-gap writes are not stampable per write — the write marks are consumed at the next collection, not at the write. The only exact snapshot would be a protected or copy-on-write page, which faults every such rewrite into the game's thread — the cost class this deferral removes — and the staged texture pages already hold the submit's bytes (guest → staging → out) before the gap. The mix is the late pages' class: their second copy at the take takes the CPU's words of later frames too, and the console has no order between the game's write and the GPU's read of a page either. The window is bounded by the helper pool: the take waits for the copy, so the pages are read within a frame. tests/test_capture_async_copy.py rewrites a scatter of pages in the gap and checks every captured byte: the submit's or the write's value, never a third one. RX_VK_CAPTURE_ASYNC=0 gives the exact submit-time snapshot.

Accepted, and documented here. Why there is no cheaper true snapshot: a page's generation is re-baselined at the take (all its pages stamped with the take's generation), so a game write in the gap is masked, and in-gap writes are not stampable per write — the write marks are consumed at the next collection, not at the write. The only exact snapshot would be a protected or copy-on-write page, which faults every such rewrite into the game's thread — the cost class this deferral removes — and the staged texture pages already hold the submit's bytes (guest → staging → out) before the gap. The mix is the late pages' class: their second copy at the take takes the CPU's words of later frames too, and the console has no order between the game's write and the GPU's read of a page either. The window is bounded by the helper pool: the take waits for the copy, so the pages are read within a frame. `tests/test_capture_async_copy.py` rewrites a scatter of pages in the gap and checks every captured byte: the submit's or the write's value, never a third one. `RX_VK_CAPTURE_ASYNC=0` gives the exact submit-time snapshot.
@ -0,0 +268,4 @@
raise SystemExit("the fixture still has unfilled slots: " + ", ".join(sorted(set(leftover))))
# (a hermetic env: no HOS_/RX_VK_/FIX_ name from the test's own environment - a FIX_RENDER_THREAD=0 or a FIX_PAGES in
# it would steer a run's config, its explicit values set per run only - the helpers' number said per run)
base_env = {k: v for k, v in os.environ.items() if not k.startswith(("HOS_", "RX_VK_", "FIX_"))}
Author
First-time contributor

Fixed: FIX_ names are now filtered out of the inherited environment with HOS_ and RX_VK_, so a FIX_RENDER_THREAD=0 or FIX_PAGES in the caller's environment can no longer steer a run — each run sets its own values explicitly.

Fixed: `FIX_` names are now filtered out of the inherited environment with `HOS_` and `RX_VK_`, so a `FIX_RENDER_THREAD=0` or `FIX_PAGES` in the caller's environment can no longer steer a run — each run sets its own values explicitly.
@ -0,0 +278,4 @@
]
failures = []
with tempfile.TemporaryDirectory(prefix="capture-async-copy-") as tmp:
cpp = Path(tmp) / "fixture.cpp" # (the source's name ends in .cpp on every platform: a .exe would be a linker
Author
First-time contributor

Fixed: the generated source keeps its .cpp name on every platform, and .exe is the executable's name only.

Fixed: the generated source keeps its `.cpp` name on every platform, and `.exe` is the executable's name only.
Author
First-time contributor

Added to Measurements the same-tree A/B GrimVisage measured for issue #2285 (this PR on main @ 79d192c6, RX 9070 XT): fewer frames over 100 ms per crossing (12 in 22 vs 20 in 22), the game's thread in the copy 3 % of the stall against 43 % on main; for that case the copy's time moves rather than goes, the rest of the stall waiting on the GPU's work that reads the capture. It answers the reviewer's question with the direct base-vs-PR comparison it asked for.

Added to Measurements the same-tree A/B GrimVisage measured for issue #2285 (this PR on main @ 79d192c6, RX 9070 XT): fewer frames over 100 ms per crossing (12 in 22 vs 20 in 22), the game's thread in the copy 3 % of the stall against 43 % on main; for that case the copy's time moves rather than goes, the rest of the stall waiting on the GPU's work that reads the capture. It answers the reviewer's question with the direct base-vs-PR comparison it asked for.
Author
First-time contributor

This is the same-tree A/B the review's question asked for, and it is now in Measurements (with the numbers and the #2285 setup). Thank you. It sharpens the answer: on jumps the submit-time saving holds almost free (the take's wait rides inside the submit-to-take gap, ~0.003 ms a frame), and on the cross-map preload the saving still holds in the copy itself (3 % of the stall against 43 % on main) while the take's wait offsets part of it there - the stall moves onto the GPU's work reading the capture. The 'moves rather than goes' reading is right for that case, and it is the honest one.

This is the same-tree A/B the review's question asked for, and it is now in Measurements (with the numbers and the #2285 setup). Thank you. It sharpens the answer: on jumps the submit-time saving holds almost free (the take's wait rides inside the submit-to-take gap, ~0.003 ms a frame), and on the cross-map preload the saving still holds in the copy itself (3 % of the stall against 43 % on main) while the take's wait offsets part of it there - the stall moves onto the GPU's work reading the capture. The 'moves rather than goes' reading is right for that case, and it is the honest one.
Merge branch 'main' into perf/capture-async-copy
Some checks are pending
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website builds (pull_request_target) Has been skipped
Website / Website preview, build (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
beanstalk/approval not approved yet
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website builds (pull_request) Blocked by required conditions
Website / Website preview, build (pull_request) Blocked by required conditions
Website / Website preview, upload (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 12s
0451d3182c
Some checks are pending
Website / Website on Cloudflare (pull_request_target) Has been skipped
Website / Website builds (pull_request_target) Has been skipped
Website / Website preview, build (pull_request_target) Has been skipped
Website / Website preview, upload (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
beanstalk/approval not approved yet
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request) Blocked by required conditions
Website / Website builds (pull_request) Blocked by required conditions
Website / Website preview, build (pull_request) Blocked by required conditions
Website / Website preview, upload (pull_request) Blocked by required conditions
PR description / Description follows the template (pull_request_target) Successful in 12s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
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 'perf/capture-async-copy:shitpost-perf/capture-async-copy'
git switch 'shitpost-perf/capture-async-copy'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
6 participants
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
MagicBeanDev/Longshot!2244
No description provided.