WIP: perf(vk): a large capture is copied after the submits' order lock, so the game's other thread does not wait for it (RX_VK_CAPTURE_UNLOCKED_MB) #2073

Closed
GummiNaomi wants to merge 2 commits from GummiNaomi/Longshot:perf/capture-off-lock into main
Member

Summary

When the game submits work for the GPU, the emulator first copies every page the CPU wrote since the last submit into a
capture, so that the replay later reads the data as it was at the submit and not as the game has changed it since. In play
a capture is under 1 MB; after an area loads it can be 100-250 MB, a copy of 10-60 ms. That copy ran under
submit_order_mu, the lock that keeps the captures in the same order as their jobs, and the game's other submitting thread
needs the same lock at its next submit and at its CPU-side event signal. So while the Presentation thread copied a large
capture, the main thread stood still at its signal for the whole copy: 20-92 ms, 7-12 times in a six-minute teleport tour.

This PR copies a capture of RX_VK_CAPTURE_UNLOCKED_MB (16) MB or more after the lock is let go, on the same thread,
before the thread goes back to the game:

  • capture_make now only takes the pages (the scan, the late pages, the shadow notes: all under the lock as before); the
    new capture_copy makes the buffer, the staging and the copy.
  • memory_capture_submit(CaptureLater*) queues a large capture as pending, in its place and with its job, under the lock;
    submit_q and event_signal_queued call later.finish() once the lock's scope ends. Smaller captures are copied before
    they are queued, as before, so steady play does not change.
  • memory_take_capture (the replay, in order) waits on cap_copied while the capture it takes is pending. The copying
    thread waits for nothing of the replay's (its buffer comes from VMA or the spares, its helpers and the flush are its
    own), so the wait always ends; CaptureLater marks the capture done in a destructor, so a copy that throws cannot leave
    the replay waiting.
  • RX_VK_ASYNC=0 (the take on the same thread) and memory_capture_now copy at once.

Result: the main thread no longer waits for the other thread's large copies (0-1 waits of 20 ms or more a tour, against
7-10 on main and 12 with the switch at 0). See Measurements for what that is in frames: on this PC, a small gain that is
not proven.

Read first: gpu/vk/vk_memory.cpp: memory_capture_submit, CaptureLater::finish, capture_copy, memory_take_capture;
then gpu/vk/vk_replay.cpp: submit_q, event_signal_queued. See #1599 (capture buffers reused by size class: the
buffer's own cost; this PR makes whatever the copy costs not block the other thread) and #1667 (a probe of a slow
capture's parts). Both touch capture_make; whichever lands second rebases.

Testing

Tested: Windows 11 Pro 26200, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB, headless test
profile, uncapped, the switches of my own play (RX_VK_TEX_AHEAD=1 RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8). Two walk tours a side (100 s in the Market, 100 s in Kokiri Forest), three
six-minute teleport tours a side (Market, Hyrule Field, Kakariko, Kokiri Forest, Lost Woods, Zora's River, 23 teleports),
one with RX_VK_CAPTURE_UNLOCKED_MB=0, and one a side with RX_VK_MEM_CHECK=1. Every teleport arrived on both, with no
error lines and the PR's log line ("captures copied after the order lock (32): ...") in every PR run. The memory check
found no take out of order or unpaired (0 of 343,675 on the PR), no sync over the GPU's data, and no page read live after
a write since its capture (0 on both). A temporary probe (not in this PR) logged each wait of 1 ms or more for
submit_order_mu and each capture's parts, on both builds.

Checks: tests/test_capture_unlocked.py (new): the real memory_capture_submit, capture_unlocked_bytes,
CaptureLater::finish, memory_take_capture and struct Capture cut from the source, with a stand-in copy of 400 ms:
another thread's submit takes ~0 ms unset against 353 ms at =0; the take of the large capture waits for its copy; the
order is kept; a copy that throws does not hang the take; no CaptureLater copies at once; the callers' order (lock,
submit, enqueue, the lock's end, finish) checked as text. It fails on main (submit_q no longer has: CaptureLater later;) and passes here. tests/test_mem_check.py and tests/test_vk_range_walk.py follow the moved code (the new
signature; the staging's RangeWalk is now in capture_copy). The three pass on Windows (clang 22.1 and the emsdk's clang 24) and on Linux (WSL Ubuntu 24.04, gcc 13.3), on this head.

The tours ran on the branch's first head, 632e13e6 on main f1f2dc5b. It is rebased since onto main @ 9dd41326, with no
conflicts and the same two patches (git range-diff shows them identical); the 14 commits in between touch none of the
lines it changes. This head (23a685d8) builds on Windows (tools/build.ps1). Of the 218 checks that read the changed
files, 172 pass on Windows and the other 46 fail the same way on main @ 9dd41326 (this PC's compilers and missing tools,
most of them: test_audio_volume, test_capture_read_once, test_capture_readback_visibility, test_crash_dialog, test_crash_record, test_dev_ab, test_dev_packs, test_device_lost_exit, test_draw_stream_visibility, test_driver_env_choose, test_flush_nothing_held, test_frame_overlap, test_fsr_image_retirement, test_fsr_uniform_ownership, test_gpu_wait_stats, test_guest_imported, test_hud_layout_row, test_input_background, test_linux_pressure, test_menu_keys, test_mesh_conv, test_mesh_fallback_layout, test_nonuniform_image_arrays, test_oot_fov, test_pending_guest_import, test_perf_report, test_present_aspect_vulkan, test_present_queue_default, test_present_source_crop, test_profiling_mode, test_readback_wait_bounded, test_recorder_own_idle, test_renderer_new_handler, test_replay_write_order, test_slow_frames, test_sparse_mirror, test_target_reuse_memory, test_texel_buffer_ownership, test_text_size, test_thinlto_tls, test_tracy_funcs, test_ub_update_batch, test_udmabuf_limit_unreadable, test_upscaler_rows, test_vertex_bind, test_vk_occlusion_queries).

Still to test:

  • linux, any GPU: the teleport tour, expecting every teleport to arrive and the "captures copied after the order lock"
    line (@Beanstalk linux, the teleport tour)
  • steamdeck: the teleport tour with RX_VK_CAPTURE_UNLOCKED_MB=0 against unset, expecting no more long frames after the
    arrivals unset (@Beanstalk steamdeck, the teleport tour with RX_VK_CAPTURE_UNLOCKED_MB=0 against unset)
  • 16 cores, Windows: the walk tour against main, expecting the same (by hand)

Measurements

Verdict: the waits it targets are gone; in frames a small gain, inside main's own spread on this PC (no memory pressure).

Setup: as Tested; main @ f1f2dc5b against this PR @ d3467a54, both with the probe, interleaved (main, PR, main, PR, the
PR at =0, main, PR), each build's files kept and put back before each run. The teleport tour's figures cover its 23
teleports; "after arrivals" is the 3 s after each; the later visits (7-23) are the cached ones. The branch was rebased
since onto main @ 9dd41326 with no conflicts (its two commits are the measured change and a fix to the new test only). The
14 commits in between change none of the capture or order-lock code (vk_replay.cpp: #1859's output preview, #2008's
mesh-draw scan, #1977's sprint toggle), so I expect these numbers to hold; not measured again.

Before: main @ f1f2dc5b After: this PR @ d3467a54 After, with RX_VK_CAPTURE_UNLOCKED_MB=0: this PR @ d3467a54
main thread's waits of 20 ms or more for the order lock, a teleport tour 10, 7, 9 0, 1, 0 12
the longest 92, 61, 89 ms 13, 44, 18 ms 56 ms
the order-lock waits in the later visits (teleport to 3 s after arrival) 1336, 1363, 1632 ms 981, 937, 1089 ms 1725 ms
frames >= 33 ms after the later arrivals (their time) 48 (2610 ms), 45 (2124 ms), 48 (2356 ms) 45 (2212 ms), 41 (1987 ms), 43 (2238 ms) 54 (2724 ms)
frames >= 33 ms after all 23 arrivals 70 (3752 ms), 64 (3105 ms), 67 (3365 ms) 59 (3034 ms), 58 (2875 ms), 62 (3291 ms) 72 (3602 ms)
fps over the frames that draw (median) 87.2, 86.9, 87.0 (10.79-10.82 ms) 87.3, 87.7, 87.6 (10.74-10.79 ms) 86.7 (10.79 ms)
the later visits' loads 48.8, 46.5, 47.4 s 47.9, 47.2, 49.1 s 47.5 s
walk tour: waits of 20 ms or more (whole run) 0, 2 (38, 36 ms) 0, 0 (the longest 15 ms)

The frames after the later arrivals average 47 (2363 ms) a tour on main and 43 (2146 ms) on this PR: about 0.2 s less of
long frames a six-minute tour, half of the 0.44 s less order-lock waiting in those windows. But main's best run (2124 ms) beats this PR's worst (2238 ms), so
on this PC that is not proven. (Whole-run fps from the frame log reads lower on this PR, 147 against 165-179, only
because main's longer first-visit loads add ~10 s of loading-screen frames at ~950 a second. Over the frames that draw it
is the same, as above.)

The one wait of 44 ms left is behind four 8 MB captures in a row, which stay under the lock (3.5-19 ms each, 5-11 ms of it
making their buffers: #1599's part). The default of 16 MB: play's captures are under 1-2 MB and an area load's are
16-250 MB, so 16 leaves play as it was; a lower value would take bursts like that one too, not measured.

The first visit of an area loaded faster in every PR run (the six first arrivals: 17.2, 17.2, 16.5 s, and 19.3 s with the
memory check, against 28.6, 28.4, 26.9 s on main, 29.6 s with the check, and 26.7 s at =0; the Market 4.1-4.4 against
9.2-10.3 s). I do not claim it. The long part is a loading screen with only small captures in it, copied the same way by
both, and older builds show the long Market load in 5 of 23 tours at random. It lines up with the switch in all 13 runs
(both tours), and I could not find why.

Risks

  • What a game thread can now do during a large capture's copy: another thread may submit, signal and go on writing; a
    write it makes to a page the copy has not reached yet is in the copy. The lock never kept the game's writes out of a
    copy (a thread that is not at a submit writes on during it), it only held a thread that came to one; and such a write is
    to data of a submission the GPU has not read, made without waiting for it. The submitting thread's own writes stay out
    (it copies before it returns), and the captures' order and their pages' marks are taken under the lock as before.
  • The mirror syncs read more pages live at the replay on the PR (2.40 and 2.90 M against 1.81-2.09 M a tour). With
    RX_VK_MEM_CHECK=1 every extra one is "capture retired" (2.23 M against 2.02 M): the page has not been written since
    its newest capture, but that capture's buffer has already been let go, so the live page holds the captured bytes.
    "Written since their capture" and "never captured" are 0 on both sides, and "not copied" is the same (0.76 M). Why more
    buffers are let go before the sync I did not trace.
  • With RX_VK_MEM_CHECK=1 only: a game thread's capture_made() (under the order lock) can wait for the checker's lock
    while the replay's take_pages walks a large capture's pages, which the replay now takes sooner. One run had two such
    waits (29 and 107 ms). A diag switch's cost; the check's own results are unaffected.
  • The replay waits for a pending copy at its take (~1,200 times a tour, ~2.1 ms each): the time it waited on main for the
    same jobs to be queued.
  • Turn it off with RX_VK_CAPTURE_UNLOCKED_MB=0 (every copy under the lock, as on main); a revert is enough. Nothing
    changes for players after updating (no caches, saves or options touched).

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). (The checks that read the changed files, as
    Testing says: the 46 that fail fail on main too.)
  • 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. (Windows: the builder's own build of this head,
    tools/build.ps1; Linux: not built here, left to someone with a Linux toolchain)
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary When the game submits work for the GPU, the emulator first copies every page the CPU wrote since the last submit into a capture, so that the replay later reads the data as it was at the submit and not as the game has changed it since. In play a capture is under 1 MB; after an area loads it can be 100-250 MB, a copy of 10-60 ms. That copy ran under `submit_order_mu`, the lock that keeps the captures in the same order as their jobs, and the game's other submitting thread needs the same lock at its next submit and at its CPU-side event signal. So while the Presentation thread copied a large capture, the main thread stood still at its signal for the whole copy: 20-92 ms, 7-12 times in a six-minute teleport tour. This PR copies a capture of `RX_VK_CAPTURE_UNLOCKED_MB` (16) MB or more after the lock is let go, on the same thread, before the thread goes back to the game: - `capture_make` now only takes the pages (the scan, the late pages, the shadow notes: all under the lock as before); the new `capture_copy` makes the buffer, the staging and the copy. - `memory_capture_submit(CaptureLater*)` queues a large capture as `pending`, in its place and with its job, under the lock; `submit_q` and `event_signal_queued` call `later.finish()` once the lock's scope ends. Smaller captures are copied before they are queued, as before, so steady play does not change. - `memory_take_capture` (the replay, in order) waits on `cap_copied` while the capture it takes is pending. The copying thread waits for nothing of the replay's (its buffer comes from VMA or the spares, its helpers and the flush are its own), so the wait always ends; `CaptureLater` marks the capture done in a destructor, so a copy that throws cannot leave the replay waiting. - `RX_VK_ASYNC=0` (the take on the same thread) and `memory_capture_now` copy at once. Result: the main thread no longer waits for the other thread's large copies (0-1 waits of 20 ms or more a tour, against 7-10 on main and 12 with the switch at 0). See Measurements for what that is in frames: on this PC, a small gain that is not proven. Read first: `gpu/vk/vk_memory.cpp`: `memory_capture_submit`, `CaptureLater::finish`, `capture_copy`, `memory_take_capture`; then `gpu/vk/vk_replay.cpp`: `submit_q`, `event_signal_queued`. See #1599 (capture buffers reused by size class: the buffer's own cost; this PR makes whatever the copy costs not block the other thread) and #1667 (a probe of a slow capture's parts). Both touch `capture_make`; whichever lands second rebases. ## Testing **Tested:** Windows 11 Pro 26200, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB, headless test profile, uncapped, the switches of my own play (`RX_VK_TEX_AHEAD=1 RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8`). Two walk tours a side (100 s in the Market, 100 s in Kokiri Forest), three six-minute teleport tours a side (Market, Hyrule Field, Kakariko, Kokiri Forest, Lost Woods, Zora's River, 23 teleports), one with `RX_VK_CAPTURE_UNLOCKED_MB=0`, and one a side with `RX_VK_MEM_CHECK=1`. Every teleport arrived on both, with no error lines and the PR's log line ("captures copied after the order lock (32): ...") in every PR run. The memory check found no take out of order or unpaired (0 of 343,675 on the PR), no sync over the GPU's data, and no page read live after a write since its capture (0 on both). A temporary probe (not in this PR) logged each wait of 1 ms or more for `submit_order_mu` and each capture's parts, on both builds. Checks: `tests/test_capture_unlocked.py` (new): the real `memory_capture_submit`, `capture_unlocked_bytes`, `CaptureLater::finish`, `memory_take_capture` and `struct Capture` cut from the source, with a stand-in copy of 400 ms: another thread's submit takes ~0 ms unset against 353 ms at `=0`; the take of the large capture waits for its copy; the order is kept; a copy that throws does not hang the take; no `CaptureLater` copies at once; the callers' order (lock, submit, enqueue, the lock's end, finish) checked as text. It fails on main (`submit_q no longer has: CaptureLater later;`) and passes here. `tests/test_mem_check.py` and `tests/test_vk_range_walk.py` follow the moved code (the new signature; the staging's `RangeWalk` is now in `capture_copy`). The three pass on Windows (clang 22.1 and the emsdk's clang 24) and on Linux (WSL Ubuntu 24.04, gcc 13.3), on this head. The tours ran on the branch's first head, 632e13e6 on main f1f2dc5b. It is rebased since onto main @ 9dd41326, with no conflicts and the same two patches (`git range-diff` shows them identical); the 14 commits in between touch none of the lines it changes. This head (23a685d8) builds on Windows (`tools/build.ps1`). Of the 218 checks that read the changed files, 172 pass on Windows and the other 46 fail the same way on main @ 9dd41326 (this PC's compilers and missing tools, most of them: test_audio_volume, test_capture_read_once, test_capture_readback_visibility, test_crash_dialog, test_crash_record, test_dev_ab, test_dev_packs, test_device_lost_exit, test_draw_stream_visibility, test_driver_env_choose, test_flush_nothing_held, test_frame_overlap, test_fsr_image_retirement, test_fsr_uniform_ownership, test_gpu_wait_stats, test_guest_imported, test_hud_layout_row, test_input_background, test_linux_pressure, test_menu_keys, test_mesh_conv, test_mesh_fallback_layout, test_nonuniform_image_arrays, test_oot_fov, test_pending_guest_import, test_perf_report, test_present_aspect_vulkan, test_present_queue_default, test_present_source_crop, test_profiling_mode, test_readback_wait_bounded, test_recorder_own_idle, test_renderer_new_handler, test_replay_write_order, test_slow_frames, test_sparse_mirror, test_target_reuse_memory, test_texel_buffer_ownership, test_text_size, test_thinlto_tls, test_tracy_funcs, test_ub_update_batch, test_udmabuf_limit_unreadable, test_upscaler_rows, test_vertex_bind, test_vk_occlusion_queries). **Still to test:** - linux, any GPU: the teleport tour, expecting every teleport to arrive and the "captures copied after the order lock" line (@Beanstalk linux, the teleport tour) - steamdeck: the teleport tour with `RX_VK_CAPTURE_UNLOCKED_MB=0` against unset, expecting no more long frames after the arrivals unset (@Beanstalk steamdeck, the teleport tour with RX_VK_CAPTURE_UNLOCKED_MB=0 against unset) - 16 cores, Windows: the walk tour against main, expecting the same (by hand) ## Measurements **Verdict:** the waits it targets are gone; in frames a small gain, inside main's own spread on this PC (no memory pressure). Setup: as Tested; main @ f1f2dc5b against this PR @ d3467a54, both with the probe, interleaved (main, PR, main, PR, the PR at `=0`, main, PR), each build's files kept and put back before each run. The teleport tour's figures cover its 23 teleports; "after arrivals" is the 3 s after each; the later visits (7-23) are the cached ones. The branch was rebased since onto main @ 9dd41326 with no conflicts (its two commits are the measured change and a fix to the new test only). The 14 commits in between change none of the capture or order-lock code (`vk_replay.cpp`: #1859's output preview, #2008's mesh-draw scan, #1977's sprint toggle), so I expect these numbers to hold; not measured again. | | Before: main @ f1f2dc5b | After: this PR @ d3467a54 | After, with `RX_VK_CAPTURE_UNLOCKED_MB=0`: this PR @ d3467a54 | |---|---|---|---| | main thread's waits of 20 ms or more for the order lock, a teleport tour | 10, 7, 9 | 0, 1, 0 | 12 | | the longest | 92, 61, 89 ms | 13, 44, 18 ms | 56 ms | | the order-lock waits in the later visits (teleport to 3 s after arrival) | 1336, 1363, 1632 ms | 981, 937, 1089 ms | 1725 ms | | frames >= 33 ms after the later arrivals (their time) | 48 (2610 ms), 45 (2124 ms), 48 (2356 ms) | 45 (2212 ms), 41 (1987 ms), 43 (2238 ms) | 54 (2724 ms) | | frames >= 33 ms after all 23 arrivals | 70 (3752 ms), 64 (3105 ms), 67 (3365 ms) | 59 (3034 ms), 58 (2875 ms), 62 (3291 ms) | 72 (3602 ms) | | fps over the frames that draw (median) | 87.2, 86.9, 87.0 (10.79-10.82 ms) | 87.3, 87.7, 87.6 (10.74-10.79 ms) | 86.7 (10.79 ms) | | the later visits' loads | 48.8, 46.5, 47.4 s | 47.9, 47.2, 49.1 s | 47.5 s | | walk tour: waits of 20 ms or more (whole run) | 0, 2 (38, 36 ms) | 0, 0 (the longest 15 ms) | | The frames after the later arrivals average 47 (2363 ms) a tour on main and 43 (2146 ms) on this PR: about 0.2 s less of long frames a six-minute tour, half of the 0.44 s less order-lock waiting in those windows. But main's best run (2124 ms) beats this PR's worst (2238 ms), so on this PC that is not proven. (Whole-run fps from the frame log reads lower on this PR, 147 against 165-179, only because main's longer first-visit loads add ~10 s of loading-screen frames at ~950 a second. Over the frames that draw it is the same, as above.) The one wait of 44 ms left is behind four 8 MB captures in a row, which stay under the lock (3.5-19 ms each, 5-11 ms of it making their buffers: #1599's part). The default of 16 MB: play's captures are under 1-2 MB and an area load's are 16-250 MB, so 16 leaves play as it was; a lower value would take bursts like that one too, not measured. The first visit of an area loaded faster in every PR run (the six first arrivals: 17.2, 17.2, 16.5 s, and 19.3 s with the memory check, against 28.6, 28.4, 26.9 s on main, 29.6 s with the check, and 26.7 s at `=0`; the Market 4.1-4.4 against 9.2-10.3 s). I do not claim it. The long part is a loading screen with only small captures in it, copied the same way by both, and older builds show the long Market load in 5 of 23 tours at random. It lines up with the switch in all 13 runs (both tours), and I could not find why. ## Risks - What a game thread can now do during a large capture's copy: another thread may submit, signal and go on writing; a write it makes to a page the copy has not reached yet is in the copy. The lock never kept the game's writes out of a copy (a thread that is not at a submit writes on during it), it only held a thread that came to one; and such a write is to data of a submission the GPU has not read, made without waiting for it. The submitting thread's own writes stay out (it copies before it returns), and the captures' order and their pages' marks are taken under the lock as before. - The mirror syncs read more pages live at the replay on the PR (2.40 and 2.90 M against 1.81-2.09 M a tour). With `RX_VK_MEM_CHECK=1` every extra one is "capture retired" (2.23 M against 2.02 M): the page has not been written since its newest capture, but that capture's buffer has already been let go, so the live page holds the captured bytes. "Written since their capture" and "never captured" are 0 on both sides, and "not copied" is the same (0.76 M). Why more buffers are let go before the sync I did not trace. - With `RX_VK_MEM_CHECK=1` only: a game thread's `capture_made()` (under the order lock) can wait for the checker's lock while the replay's `take_pages` walks a large capture's pages, which the replay now takes sooner. One run had two such waits (29 and 107 ms). A diag switch's cost; the check's own results are unaffected. - The replay waits for a pending copy at its take (~1,200 times a tour, ~2.1 ms each): the time it waited on main for the same jobs to be queued. - Turn it off with `RX_VK_CAPTURE_UNLOCKED_MB=0` (every copy under the lock, as on main); a revert is enough. Nothing changes for players after updating (no caches, saves or options touched). ## 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). (The checks that read the changed files, as Testing says: the 46 that fail fail on main too.) - [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. - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. (Windows: the builder's own build of this head, `tools/build.ps1`; Linux: not built here, left to someone with a Linux toolchain) - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A submit's capture was copied under submit_order_mu, the lock that keeps the captures in the order of their jobs. In the
first frames after an area loads a capture is 100-250 MB (30-58 ms, with 20-32 ms more when it makes a new buffer), and
the game's other thread waited out the whole copy at its next submit or CPU event signal: the main thread blocked in
event_signal_queued while the presentation thread copied, one copy stalling both game threads.

Now a capture of RX_VK_CAPTURE_UNLOCKED_MB (16) or more has its pages taken and is queued, as pending, under the lock
as before, and its buffer and copy are made by the same thread after the lock is let go (CaptureLater::finish), before
it goes back to the game. The replay's take of a pending capture waits for its copy. Kept: the captures' order, the
pages each holds (taken under the lock), the submitting thread's own writes kept out of its copy, and rule 2 (nothing
the replay reads comes from live guest memory). Changed: another game thread may submit, signal and go on while a large
capture copies. Small captures (play's 1-10 MB) stay under the lock. RX_VK_CAPTURE_UNLOCKED_MB=0: every copy under it, as
before. RX_VK_ASYNC=0 and memory_capture_now copy at once.

capture_make now takes the pages; capture_copy makes the buffer and the copy (staging included).
tests/test_capture_unlocked.py runs the queue, the finish and the take from the source with a slow stand-in copy.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
test(vk): the capture-unlocked fixture's mem_check_made_seq stand-in is [[maybe_unused]]
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 12s
CI / Workflow lint (actionlint) (pull_request) Successful in 13s
Third-party parts / As their notes say (pull_request) Successful in 14s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Website build and checks (pull_request) Successful in 2m34s
PR description / Description follows the template (pull_request_target) Successful in 4s
beanstalk/approval can't be tested as asked: see the farm's comment
23a685d8fc
Newer clang (the emsdk's, first on the local runner's PATH) has -Wunused-but-set-global: the cut-out code sets the stand-in
and nothing in the fixture reads it, which -Werror made a compile failure.

Assisted-by: Claude Code
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Member

@Beanstalk steamdeck and linux: the teleport tour from kokiri-start (Castle Town Market, Hyrule Field, Kakariko, Kokiri Forest, Lost Woods, Zora's River, then the same again, about 20 s in each), main against the PR, with RX_VK_CAPTURE_UNLOCKED_MB unset and =0 (main ignores it) and RX_VK_FRAME_TRACE=1. Measure the frames of 33 ms or more in the 3 s after each arrival, each arrival's longest frame, and each load's time, with first visits and later ones kept apart.

Expecting on the Steam Deck fewer and shorter long frames after the arrivals with it unset than at =0 and on main: a large capture's copy is slower there, so the waits this removes should be longer than this PR's Windows numbers show. On Linux, every teleport to arrive and the PR's log to have the line "captures copied after the order lock", with no more long frames than main. The first visits' loads are worth a look too: on Windows they were ~10 s shorter on the PR in every run, for a reason not found yet.

@Beanstalk steamdeck and linux: the teleport tour from kokiri-start (Castle Town Market, Hyrule Field, Kakariko, Kokiri Forest, Lost Woods, Zora's River, then the same again, about 20 s in each), main against the PR, with `RX_VK_CAPTURE_UNLOCKED_MB` unset and `=0` (main ignores it) and `RX_VK_FRAME_TRACE=1`. Measure the frames of 33 ms or more in the 3 s after each arrival, each arrival's longest frame, and each load's time, with first visits and later ones kept apart. Expecting on the Steam Deck fewer and shorter long frames after the arrivals with it unset than at `=0` and on main: a large capture's copy is slower there, so the waits this removes should be longer than this PR's Windows numbers show. On Linux, every teleport to arrive and the PR's log to have the line "captures copied after the order lock", with no more long frames than main. The first visits' loads are worth a look too: on Windows they were ~10 s shorter on the PR in every run, for a reason not found yet.
Member

Beanstalk test farm · ⛔ can't be tested as asked

Commit 23a685d · approved by GummiNaomi (untrusted) · dashboard

Not run: the farm can't test this as asked, so nothing is built or run:

The requested three-second windows and counts of frames at or above 33 ms cannot be measured by the farm’s probes, and a PR-only switch matrix cannot compare an unset switch with =0. The alternative can compare the default PR behavior with main using five-second Market arrival windows and load metrics, but cannot answer the requested per-arrival or switch comparison.

⚠️ Note: The capture summary is logged only after 32 qualifying copies, so its absence is unjudged.
⚠️ Note: Load metrics are aggregated across the tour; first and later loads are not separately judged.

What it could test instead: The alternative runs a two-lap teleport tour from Kokiri on Steam Deck and Linux, comparing the PR’s default behavior with main. It measures five-second frame windows at the first and second Market arrivals, records load times, and compares Market images. Crashes, failed arrivals, major frame-time or load-time regressions, and image differences fail the plan; the capture log is unjudged if the tour does not produce it.

A member of BigBeans can comment @Beanstalk <new words> to ask for something else, or @Beanstalk test it anyway to run the plan regardless.

<!-- beanstalk:sticky --> ### Beanstalk test farm · ⛔ can't be tested as asked Commit `23a685d` · approved by GummiNaomi (untrusted) · [dashboard](https://beanstalk.magicbean.dev/prs/2073) **Not run: the farm can't test this as asked**, so nothing is built or run: > The requested three-second windows and counts of frames at or above 33 ms cannot be measured by the farm’s probes, and a PR-only switch matrix cannot compare an unset switch with =0. The alternative can compare the default PR behavior with main using five-second Market arrival windows and load metrics, but cannot answer the requested per-arrival or switch comparison. ⚠️ **Note:** The capture summary is logged only after 32 qualifying copies, so its absence is unjudged. ⚠️ **Note:** Load metrics are aggregated across the tour; first and later loads are not separately judged. What it could test instead: The alternative runs a two-lap teleport tour from Kokiri on Steam Deck and Linux, comparing the PR’s default behavior with main. It measures five-second frame windows at the first and second Market arrivals, records load times, and compares Market images. Crashes, failed arrivals, major frame-time or load-time regressions, and image differences fail the plan; the capture log is unjudged if the tour does not produce it. A member of `BigBeans` can comment `@Beanstalk <new words>` to ask for something else, or `@Beanstalk test it anyway` to run the plan regardless.
Contributor

Steam Deck result: I ran the switch A/B you asked for on a Steam Deck OLED: the Market, arriving by teleport and then standing, three runs with this PR's default against three with RX_VK_CAPTURE_UNLOCKED_MB=0. Neither the steady Market nor the arrival showed a difference the Deck can resolve: the standing fps was within the runs' spread, and the arrival's long frames (the worst about 0.4-0.5 s) were the same size on both sides. No errors in any log. The tool doesn't run your teleport tour; each run had one area load (the teleport from Kokiri to the Market), and none of the runs logged the captures copied after the order lock (32) line, so fewer than 32 captures of 16 MB or more were taken in a run.

Standing in the Market, 60 s after the warm-up, 3 interleaved pairs

PR default (RX_VK_CAPTURE_UNLOCKED_MB unset, 16 MB) RX_VK_CAPTURE_UNLOCKED_MB=0 (as main) Δ
fps (each run) 26.8 / 25.7 / 25.6 (median 25.7) 26.0 / 26.2 / 26.4 (median 26.2) +1.8 %
1% low fps (1000 / p99) 16.6 17.4 +4.8 %
median frame time 37.21 ms 36.70 ms -0.51 ms
p99 frame time 60.39 ms 57.64 ms -2.75 ms
frames of 50 ms or more (median) 124 108 -16

dev.py ab's verdict: no difference shown: +1.8 % fps (median 26.2 against 25.7) for =0, within the runs' spread (A 25.6 to 26.8, B 26.0 to 26.4).

The arrival: the first 15 s after the teleport to the Market (from the frame trace)

run the four longest frames frames of 50 ms or more of 100 ms or more the main thread blocked, the longest four
default 1 397, 386, 376, 258 ms 47 14 436, 342, 301, 154 ms
default 2 450, 405, 334, 301 ms 51 15 448, 360, 211, 170 ms
default 3 457, 334, 280, 274 ms 60 17 458, 287, 223, 142 ms
=0 1 487, 366, 331, 287 ms 51 16 493, 319, 244, 176 ms
=0 2 423, 369, 341, 263 ms 49 17 366, 337, 234, 201 ms
=0 3 436, 349, 302, 249 ms 43 14 435, 315, 237, 204 ms

The arrival's long frames are uploads and the draws waiting on them on this Deck, on both sides, e.g. vk: slow submit: 67.1 ms: draw 66.9 descriptors 58.8 texture lookups 54.7 uploads 53.5 ... and vk: a frame's uploads took 54 ms: ASTC on the GPU 25 (7.4 MB, 54 ms).

The PR's mode line is in every run: default vk: captures of 16 MB or more copied after the submits' order lock (RX_VK_CAPTURE_UNLOCKED_MB=0: under it, as before), and =0 vk: every capture copied under the submits' order lock, as before (RX_VK_CAPTURE_UNLOCKED_MB=0). No FATAL, device-lost, VK_ERROR or validation line in the 6 logs; every run exited normally.

Hardware: Steam Deck OLED, SteamOS 3.9.5, RADV VANGOGH, Mesa 26.2.0-devel, GPU clock manual 1600 MHz, headless.
Settings: Minimum, Render 50 % (640x400), output 1280x800, uncapped, V-Sync and frame generation off.
Game data: complete (the dump, with the three damaged textures replaced).
Built: this PR @ 23a685d8 (its 2 commits, which sit on main 9dd41326), x86-64-v3, shaders prepared on the Deck; both sides are this build, with and without the switch.
Measured: dev.py ab, Market, 3 interleaved pairs (the project's tool, with a local change to compare two prebuilt runtimes, since the Deck does not build); the arrival from each run's frame trace.

Limits: one area load a run, three runs a side, one Deck, headless. On this Deck the arrival's freezes come from texture uploads (0.4-0.5 s), which may hide a 20-90 ms capture wait; the teleport tour with several large area loads, where the PR's own counter line would appear, was not run.

Steam Deck result: I ran the switch A/B you asked for on a Steam Deck OLED: the Market, arriving by teleport and then standing, three runs with this PR's default against three with `RX_VK_CAPTURE_UNLOCKED_MB=0`. Neither the steady Market nor the arrival showed a difference the Deck can resolve: the standing fps was within the runs' spread, and the arrival's long frames (the worst about 0.4-0.5 s) were the same size on both sides. No errors in any log. The tool doesn't run your teleport tour; each run had one area load (the teleport from Kokiri to the Market), and none of the runs logged the `captures copied after the order lock (32)` line, so fewer than 32 captures of 16 MB or more were taken in a run. **Standing in the Market, 60 s after the warm-up, 3 interleaved pairs** | | PR default (`RX_VK_CAPTURE_UNLOCKED_MB` unset, 16 MB) | `RX_VK_CAPTURE_UNLOCKED_MB=0` (as main) | Δ | |---|---|---|---| | fps (each run) | 26.8 / 25.7 / 25.6 (median 25.7) | 26.0 / 26.2 / 26.4 (median 26.2) | +1.8 % | | 1% low fps (1000 / p99) | 16.6 | 17.4 | +4.8 % | | median frame time | 37.21 ms | 36.70 ms | -0.51 ms | | p99 frame time | 60.39 ms | 57.64 ms | -2.75 ms | | frames of 50 ms or more (median) | 124 | 108 | -16 | `dev.py ab`'s verdict: **no difference shown**: +1.8 % fps (median 26.2 against 25.7) for `=0`, within the runs' spread (A 25.6 to 26.8, B 26.0 to 26.4). **The arrival: the first 15 s after the teleport to the Market (from the frame trace)** | run | the four longest frames | frames of 50 ms or more | of 100 ms or more | the main thread blocked, the longest four | |---|---|---|---|---| | default 1 | 397, 386, 376, 258 ms | 47 | 14 | 436, 342, 301, 154 ms | | default 2 | 450, 405, 334, 301 ms | 51 | 15 | 448, 360, 211, 170 ms | | default 3 | 457, 334, 280, 274 ms | 60 | 17 | 458, 287, 223, 142 ms | | `=0` 1 | 487, 366, 331, 287 ms | 51 | 16 | 493, 319, 244, 176 ms | | `=0` 2 | 423, 369, 341, 263 ms | 49 | 17 | 366, 337, 234, 201 ms | | `=0` 3 | 436, 349, 302, 249 ms | 43 | 14 | 435, 315, 237, 204 ms | The arrival's long frames are uploads and the draws waiting on them on this Deck, on both sides, e.g. `vk: slow submit: 67.1 ms: draw 66.9 descriptors 58.8 texture lookups 54.7 uploads 53.5 ...` and `vk: a frame's uploads took 54 ms: ASTC on the GPU 25 (7.4 MB, 54 ms)`. The PR's mode line is in every run: default `vk: captures of 16 MB or more copied after the submits' order lock (RX_VK_CAPTURE_UNLOCKED_MB=0: under it, as before)`, and `=0` `vk: every capture copied under the submits' order lock, as before (RX_VK_CAPTURE_UNLOCKED_MB=0)`. No `FATAL`, device-lost, `VK_ERROR` or validation line in the 6 logs; every run exited normally. Hardware: Steam Deck OLED, SteamOS 3.9.5, RADV VANGOGH, Mesa 26.2.0-devel, GPU clock manual 1600 MHz, headless. Settings: Minimum, Render 50 % (640x400), output 1280x800, uncapped, V-Sync and frame generation off. Game data: complete (the dump, with the three damaged textures replaced). Built: this PR @ 23a685d8 (its 2 commits, which sit on main 9dd41326), x86-64-v3, shaders prepared on the Deck; both sides are this build, with and without the switch. Measured: `dev.py ab`, Market, 3 interleaved pairs (the project's tool, with a local change to compare two prebuilt runtimes, since the Deck does not build); the arrival from each run's frame trace. Limits: one area load a run, three runs a side, one Deck, headless. On this Deck the arrival's freezes come from texture uploads (0.4-0.5 s), which may hide a 20-90 ms capture wait; the teleport tour with several large area loads, where the PR's own counter line would appear, was not run.
Author
Member

Closing in favour of #2244, which takes the capture's copy off the game's thread entirely (this PR only moved large copies outside the submits' order lock). The Steam Deck A/B here showed no difference it could resolve.

Closing in favour of #2244, which takes the capture's copy off the game's thread entirely (this PR only moved large copies outside the submits' order lock). The Steam Deck A/B here showed no difference it could resolve.
GummiNaomi closed this pull request 2026-11-22 16:31:39 +00:00
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 9s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 12s
CI / Workflow lint (actionlint) (pull_request) Successful in 13s
Third-party parts / As their notes say (pull_request) Successful in 14s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Website build and checks (pull_request) Successful in 2m34s
PR description / Description follows the template (pull_request_target) Successful in 4s
beanstalk/approval can't be tested as asked: see the farm's comment

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 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!2073
No description provided.