fix(vk): no more game stalls waiting for GPU work it does not need (culling-table reads wait only for their own bytes) #2366

Merged
HumanBean merged 1 commit from Veix/Longshot:fix/readback-shared-page into main 2026-11-23 16:16:21 +00:00
Contributor

Summary

At 4K the game's job threads stood still in reads of OoT's culling tables, waiting for GPU work that never touches the bytes they read: the table's other slot shares a 4 KB page with them.

OoT keeps four culling tables double-buffered: two slots back to back, of 0x9b040, 0x44b040, 0x8b040 and 0x1b580 bytes, none a whole number of 4 KB pages, so the two slots meet inside one page. Each frame the GPU writes one slot and the game's CPU reads the other, last frame's, long finished. The write-back notes in vk_memory.cpp are kept per 4 KB page, and a read waits for the newest part that wrote any of its pages: the GPU's write of this frame's slot put the shared page on the current part, and the read of the other slot waited for it. Where the GPU runs behind (4K), such a wait took 1 to 8 ms, and the job threads waited with it.

Measured on main with a diagnostic (not in this PR) on the Castle Town route at 4K: about 10,700 reads of each table waited (5,400 of 0x1b580), every one for a part that wrote the neighbouring slot on the shared page, and not one byte of the read range changed during the wait. The 588 waits over 1 ms in that run (2 s in all) were all of this kind.

This keeps, for a page that a write-back covers only in part, which bytes it covered and what the page held before it: two more page tables beside wb_pages / wb_parts, which stay as they are. A read that covers its first or last page only in part waits there for the last write if it touches the read's bytes and for the earlier state if it touches others; every page between is whole, as before. Nothing compares which write is newer (writes in one part or with one value need no case of their own), nothing is evicted, and a read never waits longer than before. Page copies and refreshes stay page-based. With it no read of the four tables waits on the route, and the frames that waited are gone: below.

To see it on main: the Castle Town market at 3840x2160 with DLAA, the frame trace on (RX_VK_FRAME_TRACE=1): frames over 20 ms come with the game's own time (game_ms) at 14 to 20 ms against 8 normally.

Read first: the comment above wb_spans_on and wb_edge_note / wb_edge_take in gpu/vk/vk_memory.cpp, then memory_writeback_value's first and last page, then tests/test_wb_spans.py.

This gives what players got from RX_VK_READBACK_LATE=3980,9b040,8b040,44b040,1b580, exactly instead of late. That list (passed around among players, and in #1725's discussion) read the four tables without their wait, which removed these stalls but would also have handed the game stale bytes whenever a table's own write was still pending. Here the reads skip only the wait for the other slot, and still wait whenever their own bytes are being written: the same result without reading anything late. On the same PC and route at 4K the list and this change measured the same, 74 frames over 20 ms each against 170 on main (one run each, the Market's second stay; the interleaved runs below are against main only). RX_VK_READBACK_LATE's default (0x3980, the culling camera block) is unchanged: that block is a genuine wait, its bytes are written by the part the read waits for. The four table sizes are no longer needed in it.

Testing

Please no automatic fixes on this branch (@fix, bot pushes): review comments are welcome, I make the changes myself.

Tested: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X. The Castle Town route (Market, castle, Market) at 3840x2160 with DLAA, main and this branch interleaved, two runs each (Measurements). Several free-play sessions by hand in Hyrule Field and Castle Town on builds carrying this commit, fire and water looked at on purpose: no wrong picture seen.
Checks: tests/test_wb_spans.py (11 cases: the two slots on one page, the read's own bytes, the page's earlier write, a whole-page write also in the same part, writes over or within a recorded page, many partial writes, the switch off, and 2,000 random write-backs and reads against a per-byte model of which write each byte last had: no read waits for less than its bytes' newest write, and none for a later submission than the page rule) fails on main (at its source check: main keeps no bytes; its rule is the switch's =0, under which the off case shows the read of one slot waiting for the other slot's part) and passes here; it also fails on three deliberately broken versions of the change (the earlier state left out, the last write left out, whole-page writes not clearing). Two checks that compile pieces of vk_memory.cpp follow the change and pass: tests/test_readback_part.py gets a stub for env_on_or (the switch at its default, so it runs the change as it ships), and tests/test_late_fix_build.py cuts wb_pages_note together with the helpers it now calls; tests/test_invalidate_quick.py, tests/test_wb_pages.py, tests/test_switch_table.py and the other test_wb_* checks pass. tests/run_all.py on the head (Windows, llvm-mingw): 817 passed, 14 failed, 127 skipped (Vulkan headers, spirv-val and Linux-only checks); the 14 fail on main 0e32bc10 on this PC the same way: test_auto_handheld, test_crash_dialog, test_dev_ab, test_dev_build, test_dev_migrate, test_dev_packs, test_game_menu_mouse_buttons, test_input_movie, test_linux_preflight, test_pads_after_menu, test_perf_report, test_pipeline_state_computes, test_saveload_warm_cache, test_sdiv_overflow.

Still to test:
The steps for each (Test Farm), 2 runs a side against main, no switch set, Render resolution 100 % with DLAA or the game's own upscaler, uncapped, V-Sync off: from the save market-entrance, teleport to Market_Child, wait 8 s, run around the Market for 30 s and measure; teleport to HyruleField_Child, wait 8 s, run around for 30 s and measure.

  • Steam Deck, at its own resolution: expecting frametime_p99_ms and frametime_1pct_low_ms (the slowest 1 % of frames, in ms) at or below main's and the same picture; pages written in place take the same path (@Beanstalk)
  • A lower-end GPU at 1080p or 720p, where it runs behind: expecting a lower frametime_p99_ms and frametime_1pct_low_ms than main (here at 4K: 23.3 to 21.6 ms and 26.3 to 24.7 ms) (@Beanstalk)
  • AMD RDNA 2 or later on Windows and Linux, at 4K output where the tester's screen has it: the same, and the same picture (@Beanstalk)

Measurements

Verdict: at 4K, where the GPU runs behind, the game's own p99 falls by 22 % (17.6 to 13.7 ms), frames are 16 % more even from one to the next, the p99 frame falls by 7 %, the 1 % low rises by 7 % and fps by 1.5 %. Systems whose GPU runs behind at lower resolutions (lower-end cards at 720p or 1080p) are expected to gain the same way; that is still to be tested (Testing).

Setup: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X; the Castle Town route, DLAA, uncapped, V-Sync Auto (mailbox), the frame trace on, no other switch on either side; main and this PR interleaved (this, main, this, main), two runs each, the mean of the two (the median of two). Market: from 5 s after the second entry to the end of the stay. 1 % low: 1000 over the mean of the slowest 1 % of frame times. Frame-to-frame change: the mean of |a frame time - the frame time before it|.

Before: main @ 0e32bc10 After: this PR @ ca9f6d2b (the same code as the head) Change
4K Market: fps (average) 61.6 62.5 +1.5 %
4K Market: p99 frame 23.3 ms 21.6 ms -7.3 %
4K Market: 1 % low 38.0 fps 40.6 fps +6.8 %
4K Market: game time p99 17.6 ms 13.7 ms -22.2 %
4K Market: frame-to-frame change 1.69 ms 1.42 ms -16.0 %

The cost, a microbenchmark of a frame's worth of write-back notes and reads (244 notes, 25 reads): 22.4 to 22.8 us with buffers at fixed places, 22.0 to 23.8 us with new places every frame, so 0.4 to 1.8 us a frame (about 0.01 % of a 16.7 ms frame). It compiles vk_memory.cpp's section as the renderer is built (-O2 -march=native) and times wb_pages_note and memory_writeback_value for 7 s on each side.

Risks

  • A read waits for less than before only where a write's bytes on the page do not touch the read's. Every write that reaches guest memory is noted with the bytes it copies (memory_end_submission's runs, the in-place writes' ranges); no page copy writes beyond its noted range. A write noted wider than it was makes the read wait as before.
  • Never longer than before: where the earlier state of a page was written in place by the submission that then wrote the page back by part, the read waits for that part, as the page rule did (the per-byte model checks it).
  • Pages written in place (no mirror: the Steam Deck, integrated GPUs) take the same path, and a read still waits for the whole submission that wrote its own bytes there; the per-byte model includes such writes (one random write in eight).
  • Only what a read waits for changes. Page copies and refreshes (memory_rb_refresh, the mirror syncs, the late pages' fix) stay per page; RX_VK_READBACK_EARLY keeps its own per-page writer lists, unchanged: it now starts only when the read's own bytes are pending, and then may still wait for a write next to them, as before; the sizes in RX_VK_READBACK_LATE are still read without a wait.
  • Bytes the replay writes itself (its CPU words, cut out of the write-back runs as before) were never noted as GPU writes: a read of only those no longer waits for a GPU write next to them on the page.
  • Memory: three page tables like wb_pages, made only for the 256 MB chunks where a partial write lands (512 KB a table a chunk), never freed, as wb_pages.
  • Off: RX_VK_WB_SPANS=0 restores the page rule; a revert is enough. A player notices nothing after updating but fewer slow frames where the GPU was behind.

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

Written with AI assistance (Claude).

## Summary **At 4K the game's job threads stood still in reads of OoT's culling tables, waiting for GPU work that never touches the bytes they read: the table's other slot shares a 4 KB page with them.** OoT keeps four culling tables double-buffered: two slots back to back, of 0x9b040, 0x44b040, 0x8b040 and 0x1b580 bytes, none a whole number of 4 KB pages, so the two slots meet inside one page. Each frame the GPU writes one slot and the game's CPU reads the other, last frame's, long finished. The write-back notes in `vk_memory.cpp` are kept per 4 KB page, and a read waits for the newest part that wrote any of its pages: the GPU's write of this frame's slot put the shared page on the current part, and the read of the other slot waited for it. Where the GPU runs behind (4K), such a wait took 1 to 8 ms, and the job threads waited with it. Measured on `main` with a diagnostic (not in this PR) on the Castle Town route at 4K: about 10,700 reads of each table waited (5,400 of 0x1b580), every one for a part that wrote the neighbouring slot on the shared page, and not one byte of the read range changed during the wait. The 588 waits over 1 ms in that run (2 s in all) were all of this kind. This keeps, for a page that a write-back covers only in part, which bytes it covered and what the page held before it: two more page tables beside `wb_pages` / `wb_parts`, which stay as they are. A read that covers its first or last page only in part waits there for the last write if it touches the read's bytes and for the earlier state if it touches others; every page between is whole, as before. Nothing compares which write is newer (writes in one part or with one value need no case of their own), nothing is evicted, and a read never waits longer than before. Page copies and refreshes stay page-based. With it no read of the four tables waits on the route, and the frames that waited are gone: below. To see it on `main`: the Castle Town market at 3840x2160 with DLAA, the frame trace on (`RX_VK_FRAME_TRACE=1`): frames over 20 ms come with the game's own time (`game_ms`) at 14 to 20 ms against 8 normally. Read first: the comment above `wb_spans_on` and `wb_edge_note` / `wb_edge_take` in `gpu/vk/vk_memory.cpp`, then `memory_writeback_value`'s first and last page, then `tests/test_wb_spans.py`. **This gives what players got from `RX_VK_READBACK_LATE=3980,9b040,8b040,44b040,1b580`, exactly instead of late.** That list (passed around among players, and in #1725's discussion) read the four tables without their wait, which removed these stalls but would also have handed the game stale bytes whenever a table's own write was still pending. Here the reads skip only the wait for the other slot, and still wait whenever their own bytes are being written: the same result without reading anything late. On the same PC and route at 4K the list and this change measured the same, 74 frames over 20 ms each against 170 on `main` (one run each, the Market's second stay; the interleaved runs below are against `main` only). `RX_VK_READBACK_LATE`'s default (0x3980, the culling camera block) is unchanged: that block is a genuine wait, its bytes are written by the part the read waits for. The four table sizes are no longer needed in it. ## Testing **Please no automatic fixes on this branch (`@fix`, bot pushes): review comments are welcome, I make the changes myself.** **Tested:** Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X. The Castle Town route (Market, castle, Market) at 3840x2160 with DLAA, main and this branch interleaved, two runs each (Measurements). Several free-play sessions by hand in Hyrule Field and Castle Town on builds carrying this commit, fire and water looked at on purpose: no wrong picture seen. Checks: `tests/test_wb_spans.py` (11 cases: the two slots on one page, the read's own bytes, the page's earlier write, a whole-page write also in the same part, writes over or within a recorded page, many partial writes, the switch off, and 2,000 random write-backs and reads against a per-byte model of which write each byte last had: no read waits for less than its bytes' newest write, and none for a later submission than the page rule) fails on `main` (at its source check: `main` keeps no bytes; its rule is the switch's `=0`, under which the `off` case shows the read of one slot waiting for the other slot's part) and passes here; it also fails on three deliberately broken versions of the change (the earlier state left out, the last write left out, whole-page writes not clearing). Two checks that compile pieces of `vk_memory.cpp` follow the change and pass: `tests/test_readback_part.py` gets a stub for `env_on_or` (the switch at its default, so it runs the change as it ships), and `tests/test_late_fix_build.py` cuts `wb_pages_note` together with the helpers it now calls; `tests/test_invalidate_quick.py`, `tests/test_wb_pages.py`, `tests/test_switch_table.py` and the other `test_wb_*` checks pass. `tests/run_all.py` on the head (Windows, llvm-mingw): 817 passed, 14 failed, 127 skipped (Vulkan headers, spirv-val and Linux-only checks); the 14 fail on `main` 0e32bc10 on this PC the same way: test_auto_handheld, test_crash_dialog, test_dev_ab, test_dev_build, test_dev_migrate, test_dev_packs, test_game_menu_mouse_buttons, test_input_movie, test_linux_preflight, test_pads_after_menu, test_perf_report, test_pipeline_state_computes, test_saveload_warm_cache, test_sdiv_overflow. **Still to test:** The steps for each (Test Farm), 2 runs a side against `main`, no switch set, Render resolution 100 % with DLAA or the game's own upscaler, uncapped, V-Sync off: from the save `market-entrance`, teleport to `Market_Child`, wait 8 s, run around the Market for 30 s and measure; teleport to `HyruleField_Child`, wait 8 s, run around for 30 s and measure. - Steam Deck, at its own resolution: expecting `frametime_p99_ms` and `frametime_1pct_low_ms` (the slowest 1 % of frames, in ms) at or below `main`'s and the same picture; pages written in place take the same path (@Beanstalk) - A lower-end GPU at 1080p or 720p, where it runs behind: expecting a lower `frametime_p99_ms` and `frametime_1pct_low_ms` than `main` (here at 4K: 23.3 to 21.6 ms and 26.3 to 24.7 ms) (@Beanstalk) - AMD RDNA 2 or later on Windows and Linux, at 4K output where the tester's screen has it: the same, and the same picture (@Beanstalk) ## Measurements **Verdict:** at 4K, where the GPU runs behind, the game's own p99 falls by 22 % (17.6 to 13.7 ms), frames are 16 % more even from one to the next, the p99 frame falls by 7 %, the 1 % low rises by 7 % and fps by 1.5 %. Systems whose GPU runs behind at lower resolutions (lower-end cards at 720p or 1080p) are expected to gain the same way; that is still to be tested (Testing). Setup: Windows 11, RTX 4070 SUPER 12 GB, driver 621.24, Ryzen 9 9900X; the Castle Town route, DLAA, uncapped, V-Sync Auto (mailbox), the frame trace on, no other switch on either side; main and this PR interleaved (this, main, this, main), two runs each, the mean of the two (the median of two). Market: from 5 s after the second entry to the end of the stay. 1 % low: 1000 over the mean of the slowest 1 % of frame times. Frame-to-frame change: the mean of |a frame time - the frame time before it|. | | Before: main @ 0e32bc10 | After: this PR @ ca9f6d2b (the same code as the head) | Change | |---|---|---|---| | 4K Market: fps (average) | 61.6 | 62.5 | +1.5 % | | 4K Market: p99 frame | 23.3 ms | 21.6 ms | -7.3 % | | 4K Market: 1 % low | 38.0 fps | 40.6 fps | +6.8 % | | 4K Market: game time p99 | 17.6 ms | 13.7 ms | -22.2 % | | 4K Market: frame-to-frame change | 1.69 ms | 1.42 ms | -16.0 % | The cost, a microbenchmark of a frame's worth of write-back notes and reads (244 notes, 25 reads): 22.4 to 22.8 us with buffers at fixed places, 22.0 to 23.8 us with new places every frame, so 0.4 to 1.8 us a frame (about 0.01 % of a 16.7 ms frame). It compiles `vk_memory.cpp`'s section as the renderer is built (`-O2 -march=native`) and times `wb_pages_note` and `memory_writeback_value` for 7 s on each side. ## Risks - **A read waits for less than before only where a write's bytes on the page do not touch the read's.** Every write that reaches guest memory is noted with the bytes it copies (`memory_end_submission`'s runs, the in-place writes' ranges); no page copy writes beyond its noted range. A write noted wider than it was makes the read wait as before. - **Never longer than before:** where the earlier state of a page was written in place by the submission that then wrote the page back by part, the read waits for that part, as the page rule did (the per-byte model checks it). - **Pages written in place** (no mirror: the Steam Deck, integrated GPUs) take the same path, and a read still waits for the whole submission that wrote its own bytes there; the per-byte model includes such writes (one random write in eight). - **Only what a read waits for changes.** Page copies and refreshes (`memory_rb_refresh`, the mirror syncs, the late pages' fix) stay per page; `RX_VK_READBACK_EARLY` keeps its own per-page writer lists, unchanged: it now starts only when the read's own bytes are pending, and then may still wait for a write next to them, as before; the sizes in `RX_VK_READBACK_LATE` are still read without a wait. - **Bytes the replay writes itself** (its CPU words, cut out of the write-back runs as before) were never noted as GPU writes: a read of only those no longer waits for a GPU write next to them on the page. - **Memory:** three page tables like `wb_pages`, made only for the 256 MB chunks where a partial write lands (512 KB a table a chunk), never freed, as `wb_pages`. - **Off:** `RX_VK_WB_SPANS=0` restores the page rule; a revert is enough. A player notices nothing after updating but fewer slow frames where the GPU was behind. ## 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] 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. Written with AI assistance (Claude).
fix(vk): no more game stalls waiting for GPU work it does not need (culling-table reads wait only for their own bytes)
Some checks are pending
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
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_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 30s
399abbc23a
OoT keeps its culling tables double-buffered: two slots back to back (0x9b040, 0x44b040, 0x8b040 and
0x1b580 bytes), none a whole number of pages, so the slots' seam is one 4 KB page. The write-back
notes were per page: the GPU's write of this frame's slot put the seam page on the current part, and
the CPU's read of the other slot (last frame's, long written) waited for it. In the Market at 4K
about 10,700 reads of each table did, not one byte changed by the wait; 1-8 ms where the GPU ran
behind, the game's job threads stopped meanwhile.

Only a read's first and last page can name a note that wrote none of its bytes. A page its last
note covered only in part now keeps that note's bytes and what the page held before it (two more
page tables beside wb_pages and wb_parts, which are unchanged); a read that covers its first or
last page only in part waits there for the last note if it touches its bytes and for the page's
earlier state if it touches others. Nothing compares which note is newer, nothing is evicted, and
a read never waits longer than before. In a microbenchmark of a frame's notes and reads, +0.4 us
against main with buffers at fixed places, +1.7 us with new places each frame. RX_VK_WB_SPANS=0
restores the page rule.

tests/test_wb_spans.py: the seam, the read's own bytes, the page's earlier note, a whole-page note
(also in the same part), notes over or within a noted page, many partial notes, the switch off, and
2,000 random write-backs and reads against a per-byte model.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Castle Town route at 3840x2160 and 1280x720 with DLAA, main and this branch interleaved, two runs each; several free-play sessions in Hyrule Field and Castle Town, fire and water looked at on purpose: no wrong picture seen

Tested in game: Castle Town route at 3840x2160 and 1280x720 with DLAA, main and this branch interleaved, two runs each; several free-play sessions in Hyrule Field and Castle Town, fire and water looked at on purpose: no wrong picture seen
Member

Possibly related, for context:

  • issue #241 Game: on a 4 GB laptop GPU, readbacks wait ~6.5 ms for the whole submission (38 fps; 47.5 with RX_VK_NO_READBACK_WAIT=1) — Related readback GPU-wait stutter issue; scope broader than culling-table page overlap
  • PR #238 perf(vk): RX_VK_READBACK_LATE, the readbacks a rule names are read without their wait (opt-in) — Merged opt-in late-readback rule; this PR makes culling table handling exact
  • PR #977 perf(vk): early reads: a read of GPU results waits for its writer's part, not its whole submission (RX_VK_READBACK_EARLY, on without VRAM mirrors) — Merged exact early-readback waits; shares readback path, but targets unmirrored pools
  • PR #2211 WIP: perf(vk): with the render thread, a readback over a texture's storage waits for its place in the queue, not the whole queue (RX_VK_ASYNC_PARTS) — Open Vulkan readback-wait optimization, but specifically texture-storage reads on a different path
Possibly related, for context: - issue #241 Game: on a 4 GB laptop GPU, readbacks wait ~6.5 ms for the whole submission (38 fps; 47.5 with RX_VK_NO_READBACK_WAIT=1) — Related readback GPU-wait stutter issue; scope broader than culling-table page overlap - PR #238 perf(vk): RX_VK_READBACK_LATE, the readbacks a rule names are read without their wait (opt-in) — Merged opt-in late-readback rule; this PR makes culling table handling exact - PR #977 perf(vk): early reads: a read of GPU results waits for its writer's part, not its whole submission (RX_VK_READBACK_EARLY, on without VRAM mirrors) — Merged exact early-readback waits; shares readback path, but targets unmirrored pools - PR #2211 WIP: perf(vk): with the render thread, a readback over a texture's storage waits for its place in the queue, not the whole queue (RX_VK_ASYNC_PARTS) — Open Vulkan readback-wait optimization, but specifically texture-storage reads on a different path
Owner
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The reported 4K results suggest fewer stalls, but the gain and default need confirmation against the PR's merge base and on the other supported hardware affected by the write-back path. Recommend approval; not approved on the forge.

The change tracks partial-page write-backs so a CPU read can avoid waiting for a neighboring range. It adds three persistent page tables and more work under the write-back lock in exchange for potentially better frame pacing.

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

  • L1 gpu/vk/vk_memory.cpp:2113: Confirm the frame-pacing gain against this PR's merge base and report the individual runs or their spread. (more on the line) Do: Run interleaved comparisons against f9fb7449 on the same route and settings, reporting each run's frame times and 1% lows.
  • L2 gpu/vk/vk_memory.cpp:2114: Check the default-on path on the remaining affected Tier 1 systems. (more on the line) Do: Complete the described Test Farm runs on those systems, checking frame pacing and the picture against the base.
  • L3 gpu/vk/vk_memory.cpp:2074: Measure the actual RAM cost during play. (more on the line) Do: Compare process RAM on base and head over the stated route and a longer session, including Steam Deck or another memory-constrained system. (@fix does its part first: Use a compact or sparse representation for partial-page records to reduce the allocation per touched chunk.)

@fix can do L3.

Checks: Still running: 9 checks.

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

Does it help: Unproven against this PR's base: the reported two-run means on one Windows NVIDIA PC show p99 frame time falling from 23.3 to 21.6 ms and 1% low rising from 38.0 to 40.6 fps, but the reported main commit is 0e32bc10 rather than the merge base f9fb7449, and individual run spreads are not given.

Other systems: The changed wait selection also applies to Linux, AMD, Steam Deck and in-place writes. The author reports game sessions on Windows with an RTX 4070 SUPER; the PR lists the other hardware runs as outstanding. Page-based refresh and early-read paths remain in use.

Switches: RX_VK_WB_SPANS is a new kill switch, default on, with a switches.def row. The default helps in the reported Windows NVIDIA runs, but its effect on other supported systems remains to be measured.

Reviewed: 399abbc23a against f9fb744968: Read the repository rules, PR template, commit and diff; inspected the changed write-back code, its callers, page marks, and the new test. Skimmed the existing test fixtures and switch table rather than reading those files in full. The full vk_memory.cpp and switches.def were not read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review).

Checked and fine:

  • The new span tables are accessed under wb_pages_mu.
  • The new test clears RX_VK_WB_SPANS from its inherited environment and exercises both switch settings.
  • The commit records AI assistance, and no generated files or game-derived output appear in the diff.

Testing: No code or tests were run during this read-only review. The author reports game testing and game-free checks; CI is still running.

Overlaps and merge order: Unknown; network access was unavailable.


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

**Recommendation: Approve.** The code is ready: only testing is left. The reported 4K results suggest fewer stalls, but the gain and default need confirmation against the PR's merge base and on the other supported hardware affected by the write-back path. Recommend approval; not approved on the forge. The change tracks partial-page write-backs so a CPU read can avoid waiting for a neighboring range. It adds three persistent page tables and more work under the write-back lock in exchange for potentially better frame pacing. **Testing before merging (3)** (runs on the systems it can change; it doesn't hold the recommendation) - **L1** `gpu/vk/vk_memory.cpp:2113`: Confirm the frame-pacing gain against this PR's merge base and report the individual runs or their spread. (more on the line) **Do:** Run interleaved comparisons against f9fb7449 on the same route and settings, reporting each run's frame times and 1% lows. - **L2** `gpu/vk/vk_memory.cpp:2114`: Check the default-on path on the remaining affected Tier 1 systems. (more on the line) **Do:** Complete the described Test Farm runs on those systems, checking frame pacing and the picture against the base. - **L3** `gpu/vk/vk_memory.cpp:2074`: Measure the actual RAM cost during play. (more on the line) **Do:** Compare process RAM on base and head over the stated route and a longer session, including Steam Deck or another memory-constrained system. *(`@fix` does its part first: Use a compact or sparse representation for partial-page records to reduce the allocation per touched chunk.)* `@fix` can do L3. **Checks:** Still running: 9 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven against this PR's base: the reported two-run means on one Windows NVIDIA PC show p99 frame time falling from 23.3 to 21.6 ms and 1% low rising from 38.0 to 40.6 fps, but the reported main commit is 0e32bc10 rather than the merge base f9fb7449, and individual run spreads are not given. **Other systems:** The changed wait selection also applies to Linux, AMD, Steam Deck and in-place writes. The author reports game sessions on Windows with an RTX 4070 SUPER; the PR lists the other hardware runs as outstanding. Page-based refresh and early-read paths remain in use. **Switches:** RX_VK_WB_SPANS is a new kill switch, default on, with a switches.def row. The default helps in the reported Windows NVIDIA runs, but its effect on other supported systems remains to be measured. **Reviewed:** 399abbc23a4f against f9fb7449683f: Read the repository rules, PR template, commit and diff; inspected the changed write-back code, its callers, page marks, and the new test. Skimmed the existing test fixtures and switch table rather than reading those files in full. The full vk_memory.cpp and switches.def were not read in full. docs/review-checklist.md and ../Tooling/AGENTS.md were absent.; nothing run (a code review). **Checked and fine:** - The new span tables are accessed under wb_pages_mu. - The new test clears RX_VK_WB_SPANS from its inherited environment and exercises both switch settings. - The commit records AI assistance, and no generated files or game-derived output appear in the diff. **Testing:** No code or tests were run during this read-only review. The author reports game testing and game-free checks; CI is still running. **Overlaps and merge order:** Unknown; network access was unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -2053,3 +2110,4 @@
}
void wb_pages_note(uint64_t guest_lo, uint64_t guest_hi, uint64_t value, uint64_t part) {
if (!value || guest_hi <= guest_lo) return;
std::lock_guard lk(wb_pages_mu);
Member

L1 (should fix): Confirm the frame-pacing gain against this PR's merge base and report the individual runs or their spread.

When: The PR compares against main 0e32bc10, while this checkout's merge base is f9fb7449; only the means of two runs are reported, so the size of run-to-run variation is unknown.

Do: Run interleaved comparisons against f9fb7449 on the same route and settings, reporting each run's frame times and 1% lows.

**L1** (should fix): Confirm the frame-pacing gain against this PR's merge base and report the individual runs or their spread. *When:* The PR compares against main 0e32bc10, while this checkout's merge base is f9fb7449; only the means of two runs are reported, so the size of run-to-run variation is unknown. **Do:** Run interleaved comparisons against f9fb7449 on the same route and settings, reporting each run's frame times and 1% lows.
@ -2053,0 +2071,4 @@
return on;
}
WbPages wb_ext; // (lo | hi << 32 of the page's last note when it covered the page in part; 0: the whole page)
WbPages wb_rest_v, wb_rest_p; // (the page's value and part before that note: its other bytes' newest at most)
Member

L3 (should fix): Measure the actual RAM cost during play.

When: Each guest-memory chunk touched by a partial write can allocate three persistent 512 KB tables; the PR states the allocation size but does not report how many chunks a game session uses.

Do: Compare process RAM on base and head over the stated route and a longer session, including Steam Deck or another memory-constrained system.

**L3** (should fix): Measure the actual RAM cost during play. *When:* Each guest-memory chunk touched by a partial write can allocate three persistent 512 KB tables; the PR states the allocation size but does not report how many chunks a game session uses. **Do:** Compare process RAM on base and head over the stated route and a longer session, including Steam Deck or another memory-constrained system.
@ -2053,3 +2111,4 @@
void wb_pages_note(uint64_t guest_lo, uint64_t guest_hi, uint64_t value, uint64_t part) {
if (!value || guest_hi <= guest_lo) return;
std::lock_guard lk(wb_pages_mu);
if (wb_spans_on()) { // (before the pages' values: what a page held is its rest)
Member

L2 (should fix): Check the default-on path on the remaining affected Tier 1 systems.

When: Linux NVIDIA, AMD on Windows and Linux, and Steam Deck use the changed wait selection; the supplied results cover only Windows on an RTX 4070 SUPER.

Do: Complete the described Test Farm runs on those systems, checking frame pacing and the picture against the base.

**L2** (should fix): Check the default-on path on the remaining affected Tier 1 systems. *When:* Linux NVIDIA, AMD on Windows and Linux, and Steam Deck use the changed wait selection; the supplied results cover only Windows on an RTX 4070 SUPER. **Do:** Complete the described Test Farm runs on those systems, checking frame pacing and the picture against the base.
HumanBean deleted branch fix/readback-shared-page 2026-11-23 16:16:25 +00:00
Some checks are pending
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
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_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 30s
Some workflows are waiting to be reviewed.
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!2366
No description provided.