perf(vk): a texture the game's heap compaction moved keeps its image (RX_VK_TEX_MOVE, off by default) #1810

Closed
GummiNaomi wants to merge 2 commits from GummiNaomi/Longshot:perf/tex-move-keeps-image into main
Member

Summary

The game tidies its texture memory by moving textures (a heap compaction, at most one round a second since #1478). Every move reached the renderer as a brand-new texture, made, hashed and uploaded again, twice per move. With RX_VK_TEX_MOVE=1 the renderer recognises a move and keeps the texture's image under its new address. It does that only once the texture's first draw has compared every byte of the new storage with the old one; then nothing is made or uploaded. A move it cannot prove is made as before.

The switch stays off by default. In Castle Town's market, turning it on measured slower in one session (+0.05 ms a frame on 16 cores, +0.14 ms on 4) and faster in the next (-0.06 ms and -0.14 ms). Either way the effect was smaller than this PC's drift from run to run, so I found no gain to ship it on for. The first-draw compare is what the review asked for, and it catches real cases: in a six-area tour it refused 15 moves whose new storage no longer matched, and 2 or 3 in each of two market stands. The first version of this PR would have kept the old picture for those.

Why a move looked like a new texture: the game keeps every texture in one 2.4 GB heap. A compaction round copies a texture's storage to a work heap, then to its new place. After each copy it makes the same NVN texture again over the copy at the same slot (Finalize, Initialize of the same object, RegisterTexture at the same id; the game's f_807981f0). The renderer keys images by storage address.

Read first:

  • gpu/vk/tex_move.h (new): what makes a pair a move. It must be the same object finalized and made again back to back on one thread, with the same description, layout, pool and size, both storages in the game's own memory and apart. The bytes must match at 34 sampled places; that is only a filter that turns pairs away early. The header also holds the queue of noted moves, storages_equal (the whole compare, in 1 MB pieces) and judge (the first draw's verdict).
  • gpu/vk/vk_texture.cpp: move_take, the first draw. The image must still be there, not uploaded since, not drawn into, not sparse, and its old storage not written since its upload. Then every byte of the new storage, as an upload would read it at that draw (guest_bytes: guest memory, or the pages the capture kept as submitted), must equal the old storage's. The image's upload generation is the one read before that compare, so a write the compare did not see is uploaded at a later draw. texture_move_* note the move on the game's thread and confirm it at the registration; move_log writes the counts every 600 presents.
  • gpu/vk/vk_replay.cpp: the hooks (texture_released_of / texture_created_of on the game's thread; the registration job, in order with the submits).
  • host/nvn_native.c: with the switch on, a texture's packaged data that is its own storage is not copied onto itself. The switch is read through atomics, because the first textures are made on several threads at once.
  • gpu/vk/switches.def: the RX_VK_TEX_MOVE row (attempt, off; =2 also compares whole storages on the game's thread, as a check of the samples).
  • tests/test_tex_move.py / tests/test_tex_move.cpp (new). They cover the rules and the compare in pieces, and a move's whole life in simulated guest memory: a write into the new storage between Initialize and the first draw, and a difference between the sampled places, both refused. Source checks cover the hooks, the compare, the generation read before it, the host's atomic read and both defaults.

See #1478, #1608

Testing

Tested: Windows 11 Pro 26200, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D (SMT off), headless.

  • In the game at this head, Castle Town's market, standing (Measurements): main, this PR unset and this PR with =1 on 4 cores, two runs each; main and =1 on 16 cores, one run each. 0 error lines in every log.
  • The same code as this head with its default set on (85919ba7, build tm20): eight more market stands, plus two six-area tours with the game compacting every frame (HOS_TEX_COMPACT_MS=0), =2 against =0. The pictures look the same; the differences (0.5-2.3 % of pixels) are Navi, Link's pose and the insects. In the =2 tour the game's thread compared every byte of all 78,413 noted moves and the samples missed nothing; at the first draw 15 of them no longer matched and were made as before.

Checks:

  • tests/test_tex_move.py and tests/test_switch_table.py pass on Windows and in WSL (Ubuntu 24.04, g++).
  • Of the 130 checks that read the files this PR changes (run_all.py --changed since 65488813), 111 pass on Windows. 18 fail, and all 18 fail on 65488813 too: test_crash_dialog, test_dev_ab, test_dev_packs, test_early_split_before_draw, test_frame_overlap, test_hle_guest_ranges, test_hold_gpu, test_host_guest_writes, test_linux_pressure, test_profiling_mode, test_readback_early, test_readback_late, test_readback_timeout_source, test_slow_frames, test_split_before_draw, test_upscaler_rows, test_walk_key, test_wrote_regions.
  • In WSL, 168 pass, 31 fail and 8 are skipped; all 31 fail on 65488813 too.
  • The changed renderer and host files compile with the Windows build's flags, and the game builds.
  • The new test cases fail on this PR's first version: with the compare taken out of judge, four cases fail (the destination writes, the unsampled byte, the verdict). The new source checks stop at e841323c's move_take and nvnTextureInitialize.

Still to test:

  • steamdeck: Castle Town's market standing two minutes with RX_VK_TEX_MOVE=1 and unset, expecting no wrong textures, and whether =1 has fewer long frames there (@Beanstalk steamdeck, Castle Town's market 2 minutes with RX_VK_TEX_MOVE=1 against unset)
  • windows, an AMD GPU of 8 GB: the same, plus a six-area teleport tour with RX_VK_TEX_MOVE=2, expecting the same pictures and the log's other bytes now count shown (@Beanstalk amd 8gb, the market with RX_VK_TEX_MOVE=1 against unset, and a six-area tour with RX_VK_TEX_MOVE=2)
  • Linux, an NVIDIA or AMD GPU: the host part builds and the market stand runs with RX_VK_TEX_MOVE=1 (@Beanstalk linux, Castle Town's market 2 minutes with RX_VK_TEX_MOVE=1 against unset)
  • windows, an NVIDIA card of 12 GB: Castle Town's market standing two minutes on main, on this PR unset and on this PR with RX_VK_TEX_MOVE=1, several runs each, all cores and with the game held to 4 cores, expecting this PR unset to match main and showing whether =1 gains anything (@Beanstalk windows 12gb, Castle Town's market 2 minutes, main against this PR unset and with RX_VK_TEX_MOVE=1, all cores and 4 cores)
  • windows, any GPU: Castle Town's market standing two minutes with the game compacting its textures every frame (HOS_TEX_COMPACT_MS=0), main against this PR with RX_VK_TEX_MOVE=1, expecting fewer long frames with it and the log's other bytes now count shown (@Beanstalk windows, Castle Town's market 2 minutes with HOS_TEX_COMPACT_MS=0, main against this PR with RX_VK_TEX_MOVE=1)

Measurements

Rebased: this head, 4b7f1fed, is cd5f4bf4 rebased onto main 89c3d21e with no conflicts. The code is the same: in these files main changed only gpu/vk/switches.def (other rows) and added #1158's three-line framegen_idle call in do_present, away from this PR's hooks. The numbers below are from cd5f4bf4 on 65488813. At 4b7f1fed, tests/test_tex_move.py and tests/test_switch_table.py pass on Windows (clang).

Verdict: no gain I can show, so RX_VK_TEX_MOVE stays off. Against main on 4 cores, =1 measured -0.32 ms a frame and frames over 16.7 ms went 2.44 → 1.15 %. But this PR with the switch unset, where none of the new code runs past one check per texture, also measured -0.18 ms against main, which is drift (main ran first and last). The earlier session on the same code measured =1 +0.14 ms slower than off on 4 cores and +0.05 ms on 16. Pooled over both sessions' four 4-core off/on pairs, the mean frame is 13.16 ms on both sides.

Setup: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D (SMT off), 32 GB. Castle Town's market (child), standing 130 s after a debug teleport from the kokiri-start save. Output 2560x1440, uncapped (HOS_FPS_MAX=1000), no window, otherwise the game's defaults. "4 cores": the game held to cores 8-11 (affinity 0xF00); "16 cores": no affinity. RX_VK_FRAME_TRACE=1, the trace's last 100 s: fps, frames of 16.7 ms or more and of 33 ms or more, p99, the median. Δ is the difference of the mean frame time, with a 95 % bootstrap interval over 3 s blocks. On 4 cores two runs a side, interleaved (main, =1, unset, unset, =1, main), the builds swapped between runs; on 16 cores one run each of main and =1 (the round was stopped there to cap the runs).

Before: main @ 65488813 After: this PR @ cd5f4bf4 After, RX_VK_TEX_MOVE=1: this PR @ cd5f4bf4 Δ =1 against main (95 %)
4 cores: fps, ≥16.7 ms, ≥33 ms, p99, median 74.5 fps, 2.44 %, 0, 17.67 ms, 13.14 ms 75.5 fps, 1.42 %, 0, 17.08 ms, 13.00 ms 76.3 fps, 1.15 %, 0, 16.90 ms, 12.88 ms -0.315 ms (-0.404 to -0.227)
16 cores, one run each: fps, ≥16.7 ms, ≥33 ms, p99, median 89.8 fps, 0.03 %, 0, 13.64 ms, 11.09 ms not run 90.2 fps, 0.03 %, 0, 13.34 ms, 11.03 ms -0.055 ms (-0.087 to -0.025)
  tm20m-main4-a   7396 frames  74.0 fps  >=16.7 2.74 %  >=33 0  p99 17.91  median 13.23  mean 13.522 ms
  tm20m-on4-a     7604 frames  76.0 fps  >=16.7 1.30 %  >=33 0  p99 17.23  median 12.90  mean 13.152 ms
  tm20m-pr4-a     7558 frames  75.6 fps  >=16.7 1.43 %  >=33 0  p99 17.20  median 12.99  mean 13.233 ms
  tm20m-pr4-b     7540 frames  75.4 fps  >=16.7 1.42 %  >=33 0  p99 17.00  median 13.02  mean 13.264 ms
  tm20m-on4-b     7652 frames  76.5 fps  >=16.7 1.01 %  >=33 0  p99 16.71  median 12.85  mean 13.070 ms
  tm20m-main4-b   7501 frames  75.0 fps  >=16.7 2.13 %  >=33 0  p99 17.54  median 13.05  mean 13.332 ms
4 cores, this PR unset - main: -0.178 ms (-0.261 to -0.095); =1 - main: -0.315 ms (-0.404 to -0.227); =1 - unset: -0.137 ms (-0.203 to -0.067)
  tm20m-main16-a  8979 frames  89.8 fps  >=16.7 0.03 %  >=33 0  p99 13.64  median 11.09  mean 11.137 ms
  tm20m-on16-a    9024 frames  90.2 fps  >=16.7 0.03 %  >=33 0  p99 13.34  median 11.03  mean 11.083 ms
16 cores, =1 - main: -0.055 ms (-0.087 to -0.025), one run each
on4-a:  at the first draw  672 kept their image (207 MB), made again as before: 78 not confirmed, 0 image gone, 0 uploaded since, 14 drawn into or not plain, 18 written since, 0 other bytes now
on4-b:  at the first draw  982 kept their image (412 MB), made again as before: 10 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 30 written since, 0 other bytes now
on16-a: at the first draw  988 kept their image (398 MB), made again as before: 217 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 58 written since, 3 other bytes now

The earlier session, on the same code with its default on (85919ba7, build tm20; RX_VK_TEX_MOVE=0 against unset, ABBA, two runs a side):

16 cores: off 88.9 fps, >=16.7 0.03 %, >=33 0, p99 13.63 ms | on 88.5 fps, 0.03 %, 0, p99 13.84 ms | on - off +0.049 ms (+0.025 to +0.073)
 4 cores: off 76.5 fps, >=16.7 1.09 %, >=33 0, p99 16.78 ms | on 75.7 fps, 1.53 %, 0, p99 17.14 ms | on - off +0.136 ms (+0.071 to +0.203)
on16a: at the first draw 1531 kept their image (623 MB), made again as before: 63 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 22 written since, 0 other bytes now
on16b: at the first draw 1490 kept their image (593 MB), made again as before: 45 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 121 written since, 2 other bytes now
on4a:  at the first draw  555 kept their image (185 MB), made again as before: 34 not confirmed, 0 image gone, 0 uploaded since, 2 drawn into or not plain, 14 written since, 0 other bytes now
on4b:  at the first draw 1019 kept their image (424 MB), made again as before: 31 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 10 written since, 0 other bytes now
tour, =2, HOS_TEX_COMPACT_MS=0: 78435 made again over another storage, 78413 noted (refused: 22 another description, 0 other bytes, 0 unreadable); at the first draw 2842 kept their image (1435 MB), made again as before: 2625 not confirmed, 34 image gone, 0 uploaded since, 65 drawn into or not plain, 647 written since, 15 other bytes now

The PR's first version measured a gain, but it compared samples only and had no first-draw compare. That was on main @ f505340b, with RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8 RX_VK_LATE_FIX=0, one run a side on 4 cores. Frames over 16.7 ms went 2.6 → 1.4 % (73.4 → 75.3 fps), and 20.0 → 7.5 % with compaction every frame. That gain does not reproduce at this head with the game's defaults. Whether the cost is the whole compare or main's changes since is not isolated.

RX_VK_TEX_MOVE ships off (attempt). Turned on, it was slower in one session and faster in the other, by less than this PC's drift between runs, so neither shows a gain.

Not measured: this PR unset on 16 cores, a second 16-core pair, compaction every frame on 4 cores at this head, which part of the cost is the whole compare, and any other GPU, CPU or OS.

Risks

  • Off (the default): the game's thread copies the finalized texture's description once per release, the host makes one atomic read per texture made, and a texture's first draw does one atomic check. Against main on 4 cores it measured within this PC's drift between runs (Measurements).
  • Turned on: a move proven wrongly would show another texture's picture until the texture is uploaded again. Each move is checked on the game's thread, at the registration and at the first draw, where every byte is compared before an image is kept. It showed no gain on this PC, and in one session a cost of 0.05-0.14 ms a frame (Measurements).
  • Turning it off: leave RX_VK_TEX_MOVE unset, or revert.
  • After updating: nothing changes for saves, longshot_options.ini or the caches.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit. (Rebased onto main 89c3d21e as 4b7f1fed; it still merges cleanly with #1813.)
  • 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, on Windows and Linux; every failure is named in Testing and also fails on 65488813.)
  • 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. (Fails on this PR's first version, e841323c, where the review found the bugs.)
  • 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. (Built on Windows; no Linux build on this PC, in Still to test.)
  • 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 The game tidies its texture memory by moving textures (a heap compaction, at most one round a second since #1478). Every move reached the renderer as a brand-new texture, made, hashed and uploaded again, twice per move. With `RX_VK_TEX_MOVE=1` the renderer recognises a move and keeps the texture's image under its new address. It does that only once the texture's first draw has compared every byte of the new storage with the old one; then nothing is made or uploaded. A move it cannot prove is made as before. The switch **stays off by default**. In Castle Town's market, turning it on measured slower in one session (+0.05 ms a frame on 16 cores, +0.14 ms on 4) and faster in the next (-0.06 ms and -0.14 ms). Either way the effect was smaller than this PC's drift from run to run, so I found no gain to ship it on for. The first-draw compare is what the review asked for, and it catches real cases: in a six-area tour it refused 15 moves whose new storage no longer matched, and 2 or 3 in each of two market stands. The first version of this PR would have kept the old picture for those. Why a move looked like a new texture: the game keeps every texture in one 2.4 GB heap. A compaction round copies a texture's storage to a work heap, then to its new place. After each copy it makes the same NVN texture again over the copy at the same slot (Finalize, Initialize of the same object, RegisterTexture at the same id; the game's f_807981f0). The renderer keys images by storage address. Read first: - `gpu/vk/tex_move.h` (new): what makes a pair a move. It must be the same object finalized and made again back to back on one thread, with the same description, layout, pool and size, both storages in the game's own memory and apart. The bytes must match at 34 sampled places; that is only a filter that turns pairs away early. The header also holds the queue of noted moves, `storages_equal` (the whole compare, in 1 MB pieces) and `judge` (the first draw's verdict). - `gpu/vk/vk_texture.cpp`: `move_take`, the first draw. The image must still be there, not uploaded since, not drawn into, not sparse, and its old storage not written since its upload. Then every byte of the new storage, as an upload would read it at that draw (`guest_bytes`: guest memory, or the pages the capture kept as submitted), must equal the old storage's. The image's upload generation is the one read before that compare, so a write the compare did not see is uploaded at a later draw. `texture_move_*` note the move on the game's thread and confirm it at the registration; `move_log` writes the counts every 600 presents. - `gpu/vk/vk_replay.cpp`: the hooks (`texture_released_of` / `texture_created_of` on the game's thread; the registration job, in order with the submits). - `host/nvn_native.c`: with the switch on, a texture's packaged data that is its own storage is not copied onto itself. The switch is read through atomics, because the first textures are made on several threads at once. - `gpu/vk/switches.def`: the `RX_VK_TEX_MOVE` row (`attempt`, off; `=2` also compares whole storages on the game's thread, as a check of the samples). - `tests/test_tex_move.py` / `tests/test_tex_move.cpp` (new). They cover the rules and the compare in pieces, and a move's whole life in simulated guest memory: a write into the new storage between Initialize and the first draw, and a difference between the sampled places, both refused. Source checks cover the hooks, the compare, the generation read before it, the host's atomic read and both defaults. See #1478, #1608 ## Testing **Tested:** Windows 11 Pro 26200, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D (SMT off), headless. - In the game at this head, Castle Town's market, standing (Measurements): main, this PR unset and this PR with `=1` on 4 cores, two runs each; main and `=1` on 16 cores, one run each. 0 error lines in every log. - The same code as this head with its default set on (85919ba7, build tm20): eight more market stands, plus two six-area tours with the game compacting every frame (`HOS_TEX_COMPACT_MS=0`), `=2` against `=0`. The pictures look the same; the differences (0.5-2.3 % of pixels) are Navi, Link's pose and the insects. In the `=2` tour the game's thread compared every byte of all 78,413 noted moves and the samples missed nothing; at the first draw 15 of them no longer matched and were made as before. Checks: - `tests/test_tex_move.py` and `tests/test_switch_table.py` pass on Windows and in WSL (Ubuntu 24.04, g++). - Of the 130 checks that read the files this PR changes (`run_all.py --changed` since 65488813), 111 pass on Windows. 18 fail, and all 18 fail on 65488813 too: test_crash_dialog, test_dev_ab, test_dev_packs, test_early_split_before_draw, test_frame_overlap, test_hle_guest_ranges, test_hold_gpu, test_host_guest_writes, test_linux_pressure, test_profiling_mode, test_readback_early, test_readback_late, test_readback_timeout_source, test_slow_frames, test_split_before_draw, test_upscaler_rows, test_walk_key, test_wrote_regions. - In WSL, 168 pass, 31 fail and 8 are skipped; all 31 fail on 65488813 too. - The changed renderer and host files compile with the Windows build's flags, and the game builds. - The new test cases fail on this PR's first version: with the compare taken out of `judge`, four cases fail (the destination writes, the unsampled byte, the verdict). The new source checks stop at e841323c's `move_take` and `nvnTextureInitialize`. **Still to test:** - steamdeck: Castle Town's market standing two minutes with `RX_VK_TEX_MOVE=1` and unset, expecting no wrong textures, and whether `=1` has fewer long frames there (@Beanstalk steamdeck, Castle Town's market 2 minutes with RX_VK_TEX_MOVE=1 against unset) - windows, an AMD GPU of 8 GB: the same, plus a six-area teleport tour with `RX_VK_TEX_MOVE=2`, expecting the same pictures and the log's `other bytes now` count shown (@Beanstalk amd 8gb, the market with RX_VK_TEX_MOVE=1 against unset, and a six-area tour with RX_VK_TEX_MOVE=2) - Linux, an NVIDIA or AMD GPU: the host part builds and the market stand runs with `RX_VK_TEX_MOVE=1` (@Beanstalk linux, Castle Town's market 2 minutes with RX_VK_TEX_MOVE=1 against unset) - windows, an NVIDIA card of 12 GB: Castle Town's market standing two minutes on main, on this PR unset and on this PR with `RX_VK_TEX_MOVE=1`, several runs each, all cores and with the game held to 4 cores, expecting this PR unset to match main and showing whether `=1` gains anything (@Beanstalk windows 12gb, Castle Town's market 2 minutes, main against this PR unset and with RX_VK_TEX_MOVE=1, all cores and 4 cores) - windows, any GPU: Castle Town's market standing two minutes with the game compacting its textures every frame (`HOS_TEX_COMPACT_MS=0`), main against this PR with `RX_VK_TEX_MOVE=1`, expecting fewer long frames with it and the log's `other bytes now` count shown (@Beanstalk windows, Castle Town's market 2 minutes with HOS_TEX_COMPACT_MS=0, main against this PR with RX_VK_TEX_MOVE=1) ## Measurements **Rebased:** this head, 4b7f1fed, is cd5f4bf4 rebased onto main 89c3d21e with no conflicts. The code is the same: in these files main changed only `gpu/vk/switches.def` (other rows) and added #1158's three-line `framegen_idle` call in `do_present`, away from this PR's hooks. The numbers below are from cd5f4bf4 on 65488813. At 4b7f1fed, `tests/test_tex_move.py` and `tests/test_switch_table.py` pass on Windows (clang). **Verdict:** no gain I can show, so `RX_VK_TEX_MOVE` stays off. Against main on 4 cores, `=1` measured -0.32 ms a frame and frames over 16.7 ms went 2.44 → 1.15 %. But this PR with the switch unset, where none of the new code runs past one check per texture, also measured -0.18 ms against main, which is drift (main ran first and last). The earlier session on the same code measured `=1` +0.14 ms slower than off on 4 cores and +0.05 ms on 16. Pooled over both sessions' four 4-core off/on pairs, the mean frame is 13.16 ms on both sides. Setup: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D (SMT off), 32 GB. Castle Town's market (child), standing 130 s after a debug teleport from the `kokiri-start` save. Output 2560x1440, uncapped (`HOS_FPS_MAX=1000`), no window, otherwise the game's defaults. "4 cores": the game held to cores 8-11 (affinity 0xF00); "16 cores": no affinity. `RX_VK_FRAME_TRACE=1`, the trace's last 100 s: fps, frames of 16.7 ms or more and of 33 ms or more, p99, the median. Δ is the difference of the mean frame time, with a 95 % bootstrap interval over 3 s blocks. On 4 cores two runs a side, interleaved (main, `=1`, unset, unset, `=1`, main), the builds swapped between runs; on 16 cores one run each of main and `=1` (the round was stopped there to cap the runs). | | Before: main @ 65488813 | After: this PR @ cd5f4bf4 | After, RX_VK_TEX_MOVE=1: this PR @ cd5f4bf4 | Δ `=1` against main (95 %) | |---|---|---|---|---| | 4 cores: fps, ≥16.7 ms, ≥33 ms, p99, median | 74.5 fps, 2.44 %, 0, 17.67 ms, 13.14 ms | 75.5 fps, 1.42 %, 0, 17.08 ms, 13.00 ms | 76.3 fps, 1.15 %, 0, 16.90 ms, 12.88 ms | -0.315 ms (-0.404 to -0.227) | | 16 cores, one run each: fps, ≥16.7 ms, ≥33 ms, p99, median | 89.8 fps, 0.03 %, 0, 13.64 ms, 11.09 ms | not run | 90.2 fps, 0.03 %, 0, 13.34 ms, 11.03 ms | -0.055 ms (-0.087 to -0.025) | ``` tm20m-main4-a 7396 frames 74.0 fps >=16.7 2.74 % >=33 0 p99 17.91 median 13.23 mean 13.522 ms tm20m-on4-a 7604 frames 76.0 fps >=16.7 1.30 % >=33 0 p99 17.23 median 12.90 mean 13.152 ms tm20m-pr4-a 7558 frames 75.6 fps >=16.7 1.43 % >=33 0 p99 17.20 median 12.99 mean 13.233 ms tm20m-pr4-b 7540 frames 75.4 fps >=16.7 1.42 % >=33 0 p99 17.00 median 13.02 mean 13.264 ms tm20m-on4-b 7652 frames 76.5 fps >=16.7 1.01 % >=33 0 p99 16.71 median 12.85 mean 13.070 ms tm20m-main4-b 7501 frames 75.0 fps >=16.7 2.13 % >=33 0 p99 17.54 median 13.05 mean 13.332 ms 4 cores, this PR unset - main: -0.178 ms (-0.261 to -0.095); =1 - main: -0.315 ms (-0.404 to -0.227); =1 - unset: -0.137 ms (-0.203 to -0.067) tm20m-main16-a 8979 frames 89.8 fps >=16.7 0.03 % >=33 0 p99 13.64 median 11.09 mean 11.137 ms tm20m-on16-a 9024 frames 90.2 fps >=16.7 0.03 % >=33 0 p99 13.34 median 11.03 mean 11.083 ms 16 cores, =1 - main: -0.055 ms (-0.087 to -0.025), one run each on4-a: at the first draw 672 kept their image (207 MB), made again as before: 78 not confirmed, 0 image gone, 0 uploaded since, 14 drawn into or not plain, 18 written since, 0 other bytes now on4-b: at the first draw 982 kept their image (412 MB), made again as before: 10 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 30 written since, 0 other bytes now on16-a: at the first draw 988 kept their image (398 MB), made again as before: 217 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 58 written since, 3 other bytes now ``` The earlier session, on the same code with its default on (85919ba7, build tm20; `RX_VK_TEX_MOVE=0` against unset, ABBA, two runs a side): ``` 16 cores: off 88.9 fps, >=16.7 0.03 %, >=33 0, p99 13.63 ms | on 88.5 fps, 0.03 %, 0, p99 13.84 ms | on - off +0.049 ms (+0.025 to +0.073) 4 cores: off 76.5 fps, >=16.7 1.09 %, >=33 0, p99 16.78 ms | on 75.7 fps, 1.53 %, 0, p99 17.14 ms | on - off +0.136 ms (+0.071 to +0.203) on16a: at the first draw 1531 kept their image (623 MB), made again as before: 63 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 22 written since, 0 other bytes now on16b: at the first draw 1490 kept their image (593 MB), made again as before: 45 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 121 written since, 2 other bytes now on4a: at the first draw 555 kept their image (185 MB), made again as before: 34 not confirmed, 0 image gone, 0 uploaded since, 2 drawn into or not plain, 14 written since, 0 other bytes now on4b: at the first draw 1019 kept their image (424 MB), made again as before: 31 not confirmed, 0 image gone, 0 uploaded since, 0 drawn into or not plain, 10 written since, 0 other bytes now tour, =2, HOS_TEX_COMPACT_MS=0: 78435 made again over another storage, 78413 noted (refused: 22 another description, 0 other bytes, 0 unreadable); at the first draw 2842 kept their image (1435 MB), made again as before: 2625 not confirmed, 34 image gone, 0 uploaded since, 65 drawn into or not plain, 647 written since, 15 other bytes now ``` The PR's first version measured a gain, but it compared samples only and had no first-draw compare. That was on main @ f505340b, with `RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_LOAD=create RX_VK_BC_LAYERS=8 RX_VK_LATE_FIX=0`, one run a side on 4 cores. Frames over 16.7 ms went 2.6 → 1.4 % (73.4 → 75.3 fps), and 20.0 → 7.5 % with compaction every frame. That gain does not reproduce at this head with the game's defaults. Whether the cost is the whole compare or main's changes since is not isolated. `RX_VK_TEX_MOVE` ships off (`attempt`). Turned on, it was slower in one session and faster in the other, by less than this PC's drift between runs, so neither shows a gain. Not measured: this PR unset on 16 cores, a second 16-core pair, compaction every frame on 4 cores at this head, which part of the cost is the whole compare, and any other GPU, CPU or OS. ## Risks - **Off (the default):** the game's thread copies the finalized texture's description once per release, the host makes one atomic read per texture made, and a texture's first draw does one atomic check. Against main on 4 cores it measured within this PC's drift between runs (Measurements). - **Turned on:** a move proven wrongly would show another texture's picture until the texture is uploaded again. Each move is checked on the game's thread, at the registration and at the first draw, where every byte is compared before an image is kept. It showed no gain on this PC, and in one session a cost of 0.05-0.14 ms a frame (Measurements). - **Turning it off:** leave `RX_VK_TEX_MOVE` unset, or revert. - **After updating:** nothing changes for saves, `longshot_options.ini` or the caches. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. (Rebased onto main 89c3d21e as 4b7f1fed; it still merges cleanly with #1813.) - [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, on Windows and Linux; every failure is named in Testing and also fails on 65488813.) - [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. (Fails on this PR's first version, e841323c, where the review found the bugs.) - [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. (Built on Windows; no Linux build on this PC, in Still to test.) - [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)
perf(vk): a texture the game's heap compaction moved keeps its image (RX_VK_TEX_MOVE, off by default)
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
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 12s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 17s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
CI / Workflow lint (actionlint) (pull_request) Successful in 19s
Third-party parts / As their notes say (pull_request) Successful in 23s
beanstalk/approval held by the security check: see the farm's comment
e9799a315a
OoT's texture manager compacts its 2.4 GB heap: a round copies a texture's storage
elsewhere and makes the same NVN texture again over the copy, at the same slot. The
renderer keys images by storage address, so each move was a new texture: an image
made, the storage hashed and copied or uploaded again, twice a move.

With RX_VK_TEX_MOVE=1 a move is recognised as the game makes it (the same object
finalized and made again on one thread, the same description, layout, pool and size,
the bytes the same where sampled), checked again at the registration and at the first
draw, and the new texture takes the old one's image. A move it cannot prove is made as
before. =2 compares the whole storage instead of samples. The host also skips copying
a texture's packaged data onto its own storage.

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

Possibly related, for context:

  • issue #1608 How many texture re-uploads bring the same bytes the image already holds? Nothing in the renderer compares them — Tracks redundant texture re-uploads; distinct trigger, adjacent upload optimization
  • PR #1281 WIP: perf(vk): a new ASTC texture's blocks are hashed at upload only when a finalized one has its shape — Open texture-image reuse work; hashes ASTC for reuse, not moved storage
Possibly related, for context: - issue #1608 How many texture re-uploads bring the same bytes the image already holds? Nothing in the renderer compares them — Tracks redundant texture re-uploads; distinct trigger, adjacent upload optimization - PR #1281 WIP: perf(vk): a new ASTC texture's blocks are hashed at upload only when a finalized one has its shape — Open texture-image reuse work; hashes ASTC for reuse, not moved storage
futondestroyer left a comment

Recommendation: Request changes. Reusing a moved texture can hide a later destination write. The opt-in fast path also treats sampled bytes as proof of equality.

Does it help: Unproven for the submitted revision. GummiNaomi's earlier Windows RTX 4070 SUPER A/B reports 73.4 to 75.3 FPS and 2.6% to 1.4% of frames over 16.7 ms with four cores, but no clear benefit with sixteen. The earlier full-compare tour reported 143,391 moves with zero mismatches. This is encouraging coverage for that route and build. The exact head has focused checks but no gameplay run, and the comparison does not establish safety after a destination write.

Other systems: The path changes common host/replay texture handling. Recheck Linux, Deck, AMD and lower-VRAM hardware after correctness is fixed.
Switches: RX_VK_TEX_MOVE defaults off. Mode 1 uses sampling; mode 2 compares the whole storage at initialization.
Reviewed: e9799a31 against 0de25c3e, with exact Graphify maps and source. Read the host initialize hook, renderer registration and cache paths, and the source-backed fixture. Nothing run.
Fixed in this review: Nothing.
Checked and fine: The new hint table is bounded. Registration checks the old slot serial; first use checks image ID and upload generation.

Blocking

  1. gpu/vk/vk_texture.cpp:2855,2884: after Initialize compares the storages, a CPU write to the destination before first use can leave the old image stale. The reuse check reads CPU dirtiness only on the source, then stamps the moved image with the current generation at its new address. A destination write already included in that generation can go unseen by the normal upload check. Record the destination's validated generation and reject intervening writes, or compare against the actual replay-visible bytes at consumption. Test a destination-only update between Initialize and first draw.
  2. gpu/vk/vk_texture.cpp:2922: for a large texture, a changed block between samples can still pass mode 1 if the object, layout and slot are reused. The sample match should only be a rejection filter before an exact comparison or a proven copy-identity check. Add a fixture with a difference outside the sampled regions.
  3. host/nvn_native.c:782–783: the new writable static can be initialized concurrently on the first texture creations, even when the switch is unset. Use thread-safe initialization or precompute it before guest workers start.

Testing: Rebase, bring the description/checklist up to date, and validate exact-head gameplay and the current default. CI's description and Guide screenshots checks are red; the source jobs listed as skipped provide no coverage.
Overlaps and merge order: Texture-ahead at #1813 shares the queue and cache path. The changes should be tested together after their individual correctness gates. #1811 and #1812 touch the same host/replay files and need rebase reconciliation. The banking and virtual-core changes are shared-route performance variables, not prerequisites for this texture fix.

**Recommendation: Request changes.** Reusing a moved texture can hide a later destination write. The opt-in fast path also treats sampled bytes as proof of equality. **Does it help:** Unproven for the submitted revision. GummiNaomi's earlier Windows RTX 4070 SUPER A/B reports 73.4 to 75.3 FPS and 2.6% to 1.4% of frames over 16.7 ms with four cores, but no clear benefit with sixteen. The earlier full-compare tour reported 143,391 moves with zero mismatches. This is encouraging coverage for that route and build. The exact head has focused checks but no gameplay run, and the comparison does not establish safety after a destination write. **Other systems:** The path changes common host/replay texture handling. Recheck Linux, Deck, AMD and lower-VRAM hardware after correctness is fixed. **Switches:** RX_VK_TEX_MOVE defaults off. Mode 1 uses sampling; mode 2 compares the whole storage at initialization. **Reviewed:** e9799a31 against 0de25c3e, with exact Graphify maps and source. Read the host initialize hook, renderer registration and cache paths, and the source-backed fixture. Nothing run. **Fixed in this review:** Nothing. **Checked and fine:** The new hint table is bounded. Registration checks the old slot serial; first use checks image ID and upload generation. **Blocking** 1. `gpu/vk/vk_texture.cpp:2855,2884`: after Initialize compares the storages, a CPU write to the destination before first use can leave the old image stale. The reuse check reads CPU dirtiness only on the source, then stamps the moved image with the current generation at its new address. A destination write already included in that generation can go unseen by the normal upload check. Record the destination's validated generation and reject intervening writes, or compare against the actual replay-visible bytes at consumption. Test a destination-only update between Initialize and first draw. 2. `gpu/vk/vk_texture.cpp:2922`: for a large texture, a changed block between samples can still pass mode 1 if the object, layout and slot are reused. The sample match should only be a rejection filter before an exact comparison or a proven copy-identity check. Add a fixture with a difference outside the sampled regions. 3. `host/nvn_native.c:782–783`: the new writable static can be initialized concurrently on the first texture creations, even when the switch is unset. Use thread-safe initialization or precompute it before guest workers start. **Testing:** Rebase, bring the description/checklist up to date, and validate exact-head gameplay and the current default. CI's description and Guide screenshots checks are red; the source jobs listed as skipped provide no coverage. **Overlaps and merge order:** Texture-ahead at https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1813 shares the queue and cache path. The changes should be tested together after their individual correctness gates. https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1811 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1812 touch the same host/replay files and need rebase reconciliation. The banking and virtual-core changes are shared-route performance variables, not prerequisites for this texture fix.
@ -2819,0 +2881,4 @@
src->gpu = t->gpu, src->guest = host->gpu_guest(t->gpu);
// (its contents are its new storage's as of now: the game's copy into it was written before this draw's submit, and is in the
// page generations; what the CPU writes there later is uploaded as for any texture)
src->upload_gen = memory_generation();
Member

This stamps later CPU writes to the destination as already uploaded. Keep a destination validation generation and reject newer writes before reusing the image.

This stamps later CPU writes to the destination as already uploaded. Keep a destination validation generation and reject newer writes before reusing the image.
@ -2819,0 +2919,4 @@
const uint8_t* p = host->gpu_ptr(mv_fin.gpu, &a);
const uint8_t* q = host->gpu_ptr(t->gpu, &b);
if (!p || !q || a < n || b < n) return void(mv.unreadable++);
bool same = tex_move::samples_match(p, q, n);
Member

An unsampled changed block can pass mode 1. Use an exact equality or copy identity check before accepting reuse.

An unsampled changed block can pass mode 1. Use an exact equality or copy identity check before accepting reuse.
@ -780,0 +780,4 @@
over its copy so (f_807981f0: SetPackagedTextureData(builder, the new storage)). The bytes are there already: copying them
onto themselves cost a memcpy of the whole texture on the game's thread and marked every page written for the memory sync */
static int same_skip = -1;
if (same_skip < 0) same_skip = getenv("RX_VK_TEX_MOVE") && atoi(getenv("RX_VK_TEX_MOVE")) > 0;
Member

Concurrent first texture initialization can race on this writable static even with the option unset. Initialize it before workers or use a thread-safe once operation.

Concurrent first texture initialization can race on this writable static even with the option unset. Initialize it before workers or use a thread-safe once operation.
Owner

Let's beanstalk and try enable for all? Let's test on/off and see if we should just enable by default

@Beanstalk

Let's beanstalk and try enable for all? Let's test on/off and see if we should just enable by default @Beanstalk
Member
Beanstalk test farm · an earlier run: commit cd5f4bf (the newer results are in a comment below)

Commit cd5f4bf · tier reviewed · approved by GummiNaomi · dashboard

What will be tested · AI plan (gpt-6.1-terra)

On Steam Deck, Linux, and Windows PCs with 8 GB AMD and 12 GB NVIDIA GPUs, the plan teleports from kokiri-start to the child Market and stands for two minutes. It compares main with the PR’s default-equivalent off mode and opt-in mode, recording frame times, hitches, screenshots, and the first-draw rejection count; crashes, substantial performance regressions, or large image differences fail. The requested GPU-size combinations may wait for matching online testers. Each tester needs about 43 minutes; per-frame compaction is omitted to stay within the run-time limit, and frame tracing is not permitted by the farm.

  • Where: steamdeck (1-2 reports), linux (1-2 reports), windows+amd+vram8gb (8 GB VRAM, 1-2 reports), windows+nvidia+vram12gb (12 GB VRAM, 1-2 reports).
  • Matrix: 2 cells, each on main and the PR: RX_VK_TEX_MOVE 0 or 1 (PR only).
  • child-market: from the repository's save kokiri-start, then teleport to Market, measure market for 2 min (after 0 s warm-up), take the picture market-after-compaction to compare with main; 1 run on each side for each of 2 cells (2 game starts a run).
  • Measured: crashes, frame times, stutters and hitches, numbers from the game's log.
  • The PR fails if: it crashes; or a picture differs from main by more than 8%; or frame time (p99) is more than 25% above main.
  • Time: about 28 min of game runs per tester (4 game starts), plus the two builds.

Started at 13:15 UTC.

Estimate: done in about 15 h 30 min, from the queue and the testers online now; some jobs can't start yet.

Target Reports Crash Frame p99 (ms) vs main VRAM peak (MB) vs main Result
steamdeck 0/1 — — — queued
linux 0/1 — — — queued
windows+amd+vram8gb 0/1 — — — running
windows+nvidia+vram12gb 0/1 — — — queued
Scenario · matrix cell Target Frame p99 (ms) vs main Result
child-market · RX_VK_TEX_MOVE=0 (PR only) steamdeck — —
child-market · RX_VK_TEX_MOVE=0 (PR only) linux — —
child-market · RX_VK_TEX_MOVE=0 (PR only) windows+amd+vram8gb — —
child-market · RX_VK_TEX_MOVE=0 (PR only) windows+nvidia+vram12gb — —
child-market · RX_VK_TEX_MOVE=1 (PR only) steamdeck — —
child-market · RX_VK_TEX_MOVE=1 (PR only) linux — —
child-market · RX_VK_TEX_MOVE=1 (PR only) windows+amd+vram8gb — —
child-market · RX_VK_TEX_MOVE=1 (PR only) windows+nvidia+vram12gb — —
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>cd5f4bf</code> (the newer results are in a comment below)</summary> Commit `cd5f4bf` · tier **reviewed** · approved by GummiNaomi · [dashboard](https://beanstalk.magicbean.dev/prs/1810) **What will be tested** · AI plan (`gpt-6.1-terra`) On Steam Deck, Linux, and Windows PCs with 8 GB AMD and 12 GB NVIDIA GPUs, the plan teleports from kokiri-start to the child Market and stands for two minutes. It compares main with the PR’s default-equivalent off mode and opt-in mode, recording frame times, hitches, screenshots, and the first-draw rejection count; crashes, substantial performance regressions, or large image differences fail. The requested GPU-size combinations may wait for matching online testers. Each tester needs about 43 minutes; per-frame compaction is omitted to stay within the run-time limit, and frame tracing is not permitted by the farm. - **Where:** steamdeck (1-2 reports), linux (1-2 reports), windows+amd+vram8gb (8 GB VRAM, 1-2 reports), windows+nvidia+vram12gb (12 GB VRAM, 1-2 reports). - **Matrix:** 2 cells, each on main and the PR: RX_VK_TEX_MOVE `0` or `1` (PR only). - **child-market:** from the repository's save `kokiri-start`, then teleport to Market, measure market for 2 min (after 0 s warm-up), take the picture market-after-compaction to compare with main; 1 run on each side for each of 2 cells (2 game starts a run). - **Measured:** crashes, frame times, stutters and hitches, numbers from the game's log. - **The PR fails if:** it crashes; or a picture differs from main by more than 8%; or frame time (p99) is more than 25% above main. - **Time:** about 28 min of game runs per tester (4 game starts), plus the two builds. Started at 13:15 UTC. **Estimate:** done in about 15 h 30 min, from the queue and the testers online now; some jobs can't start yet. | Target | Reports | Crash | Frame p99 (ms) vs main | VRAM peak (MB) vs main | Result | | --- | --- | --- | --- | --- | --- | | steamdeck | 0/1 | — | — | — | queued | | linux | 0/1 | — | — | — | queued | | windows+amd+vram8gb | 0/1 | — | — | — | running | | windows+nvidia+vram12gb | 0/1 | — | — | — | queued | | Scenario · matrix cell | Target | Frame p99 (ms) vs main | Result | | --- | --- | --- | --- | | child-market · `RX_VK_TEX_MOVE=0 (PR only)` | steamdeck | — | — | | child-market · `RX_VK_TEX_MOVE=0 (PR only)` | linux | — | — | | child-market · `RX_VK_TEX_MOVE=0 (PR only)` | windows+amd+vram8gb | — | — | | child-market · `RX_VK_TEX_MOVE=0 (PR only)` | windows+nvidia+vram12gb | — | — | | child-market · `RX_VK_TEX_MOVE=1 (PR only)` | steamdeck | — | — | | child-market · `RX_VK_TEX_MOVE=1 (PR only)` | linux | — | — | | child-market · `RX_VK_TEX_MOVE=1 (PR only)` | windows+amd+vram8gb | — | — | | child-market · `RX_VK_TEX_MOVE=1 (PR only)` | windows+nvidia+vram12gb | — | — | </details>
GummiNaomi force-pushed perf/tex-move-keeps-image from e9799a315a
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
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 12s
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Failing after 17s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
CI / Workflow lint (actionlint) (pull_request) Successful in 19s
Third-party parts / As their notes say (pull_request) Successful in 23s
beanstalk/approval held by the security check: see the farm's comment
to 7b30e1762c
Some checks failed
beanstalk/approval not approved yet
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
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 11s
PR description / Description follows the template (pull_request_target) Failing after 17s
CI / Workflow lint (actionlint) (pull_request) Successful in 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 18s
Third-party parts / As their notes say (pull_request) Successful in 21s
CI / Website build and checks (pull_request) Has been cancelled
2026-11-20 07:46:43 +00:00
Compare
GummiNaomi force-pushed perf/tex-move-keeps-image from 7b30e1762c
Some checks failed
beanstalk/approval not approved yet
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
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 11s
PR description / Description follows the template (pull_request_target) Failing after 17s
CI / Workflow lint (actionlint) (pull_request) Successful in 20s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 18s
Third-party parts / As their notes say (pull_request) Successful in 21s
CI / Website build and checks (pull_request) Has been cancelled
to e841323c89
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
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 10s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 13s
beanstalk/approval not approved yet
PR description / Description follows the template (pull_request_target) Failing after 10s
CI / Website build and checks (pull_request) Has been cancelled
2026-11-20 07:51:13 +00:00
Compare
Contributor

Tested #1810 at e9799a31 plus two fixes, on main 068fb8eb with a local stand-in for #1815 in both arms. Steam Deck OLED, 1280×800, fullscreen Game Mode, HDR on, GPU held at peak clocks as main does on Deck.

Threaded rendering defaults off on Deck. The first fix confirms moves on the synchronous path. The second keeps an image only if the new storage still holds its original bytes, including after chained moves. Links on deck-1810-fixes, rebased onto e841323c:

Standing in the Market, I alternated RX_VK_TEX_MOVE=0 and 1; #1814 and #1780 stayed off. Two pairs, 60 s per run. Medians, off → on: 21.6 → 21.95 fps (+1.6%), 1% low 15.35 → 17.25 fps, p99 65 → 58 ms. Frames over 50 ms went from 12.3% to 10.0%, but only one pair improved on that measure.

The two on runs kept 476 images (131 MB) and 266 (85 MB). With all three on, Market standing kept 176–556 images (44–161 MB). The newer round-2 combo kept 420 and 488.

Moving, the Field walk was main → all three on, not #1810 alone: 21.85 → 22.7 fps (+3.9%), 1% low 12.45 → 14.7 fps, p99 80 → 68 ms, frames over 50 ms 16.3% → 8.55%. The combo kept 556 images (257 MB) and 466 (383 MB). Two pairs are a first check.

Tested #1810 at `e9799a31` plus two fixes, on main `068fb8eb` with a local stand-in for #1815 in both arms. Steam Deck OLED, 1280×800, fullscreen Game Mode, HDR on, GPU held at peak clocks as main does on Deck. Threaded rendering defaults off on Deck. The first fix confirms moves on the synchronous path. The second keeps an image only if the new storage still holds its original bytes, including after chained moves. Links on `deck-1810-fixes`, rebased onto `e841323c`: - [Confirm synchronous moves](https://git.magicbean.dev/dukenheimer/Longshot/commit/aee1e36188b04280fa53fec6d554bacf2cc24e05) - [Check the backing bytes](https://git.magicbean.dev/dukenheimer/Longshot/commit/8cd8f6d99108cb069ca594c856996cc3751e32f5) - [Test for both fixes](https://git.magicbean.dev/dukenheimer/Longshot/commit/a7f4d5e81c47514a19a4a89439d58927ec348451) Standing in the Market, I alternated `RX_VK_TEX_MOVE=0` and `1`; #1814 and #1780 stayed off. Two pairs, 60 s per run. Medians, off → on: 21.6 → 21.95 fps (+1.6%), 1% low 15.35 → 17.25 fps, p99 65 → 58 ms. Frames over 50 ms went from 12.3% to 10.0%, but only one pair improved on that measure. The two on runs kept 476 images (131 MB) and 266 (85 MB). With all three on, Market standing kept 176–556 images (44–161 MB). The newer round-2 combo kept 420 and 488. Moving, the Field walk was **main → all three on**, not #1810 alone: 21.85 → 22.7 fps (+3.9%), 1% low 12.45 → 14.7 fps, p99 80 → 68 ms, frames over 50 ms 16.3% → 8.55%. The combo kept 556 images (257 MB) and 466 (383 MB). Two pairs are a first check.
fix(vk): a moved texture keeps its image only when every byte matches at its first draw (RX_VK_TEX_MOVE stays off)
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 11s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 15s
CI / Workflow lint (actionlint) (pull_request) Successful in 17s
Third-party parts / As their notes say (pull_request) Successful in 17s
PR description / Description follows the template (pull_request_target) Failing after 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval approved by GummiNaomi (reviewed)
beanstalk/steamdeck 0/1 pass, 0 running, 2 queued
beanstalk/linux 0/1 pass, 0 running, 2 queued
beanstalk/windows+amd+vram8gb 0/1 pass, 1 running, 1 queued
beanstalk/windows+nvidia+vram12gb 0/1 pass, 0 running, 2 queued
CI / Website build and checks (pull_request) Has been cancelled
cd5f4bf4e5
Review of #1810. The game's thread compared the old and new storages at Initialize (by
samples with =1), and the first draw asked only whether the OLD storage was written
since: a CPU write into the new storage between Initialize and the first draw, or a
difference between the samples, let the old image through, stamped with a generation
that already held that write, so it was never uploaded.

Now the samples only turn pairs away early on the game's thread. At the first draw,
when every other check holds, every byte of the new storage, as an upload would read it
then (guest_bytes: guest memory, or the pages the capture kept as submitted), is
compared with the old storage's (tex_move::storages_equal, in 1 MB pieces); the image's
upload generation is the one read before that compare. A difference is counted ("other
bytes now") and the texture is made as before.

The host's switch read in nvnTextureInitialize was a plain static written by whichever
thread made the first textures: now through atomics.

Still off by default: with these fixes, on against off at this change (16 and 4 cores,
Castle Town's market, the game's defaults) cost 0.05 and 0.14 ms a frame; the runs are in
the pull request.

tests/test_tex_move: a destination-only write between Initialize and the first draw, a
difference outside the sampled places, the whole compare in pieces, and source checks of
the compare, the generation read before it, the host's atomic read and both defaults (off).

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

Thanks, all three were real; fixed in cd5f4bf4 (one commit on top of e841323c, a fast-forward).

1. A destination write between Initialize and the first draw (gpu/vk/vk_texture.cpp, move_take; gpu/vk/tex_move.h, storages_equal and judge). The first draw no longer trusts what the game's thread saw. When every other check holds, it compares every byte of the new storage, as an upload there would read it then (guest_bytes: guest memory, or the pages the capture kept as submitted), with the old storage's, which nothing has written since the image's upload. That compare runs in 1 MB pieces. The image's upload generation is now the one read before that compare (const uint64_t gen = memory_generation() ahead of judge, then src->upload_gen = gen), so a write the compare did not see is stamped later and uploaded at a later draw. A difference is counted (other bytes now in the log line) and the texture is made as before. This happens in real play. In a six-area tour on this code (85919ba7, which differs from cd5f4bf4 only in the unset default) with RX_VK_TEX_MOVE=2 and HOS_TEX_COMPACT_MS=0, the game's thread compared every byte of 78,413 moves at Initialize and found none different. At the first draw, 15 of them differed. In plain 16-core market stands, 2 of 1,490 differed (85919ba7) and 3 of 988 (cd5f4bf4). e841323c would have kept the old image for those.
Test: tests/test_tex_move.cpp simulates a move's whole life in guest memory (the game's copy, Initialize, the registration, the first draw). One case is a one-byte write into the new storage after Initialize, another 64 KB cleared there; the old storage's page generations say nothing in both. Both must be refused (Verdict::differs). tests/test_tex_move.py checks that move_take compares through storages_equal/guest_bytes and reads the generation before the compare and not again after it.

2. Mode 1's samples treated as proof (tex_move.h). The samples are now only a filter on the game's thread, so a pair whose samples differ is turned away early. Every move that would be taken, in mode 1 or 2, goes through the whole compare above at its first draw. =2 still also compares whole storages on the game's thread, as a check of the filter.
Test: a fixture whose one differing byte lies half way between two sampled pieces. The test asserts that samples_match passes it (the filter's known gap) and that the first draw's verdict is differs. There are also cases for the compare in pieces: the last short piece, the first byte of the second piece, unreadable, and two read buffers.

3. The host's writable static (host/nvn_native.c, nvnTextureInitialize). same_skip is now read and written only through __atomic_load_n/__atomic_store_n, so the first texture creations racing on several threads are fine, the switch set or not. tests/test_tex_move.py fails if any line there touches same_skip without an atomic.

Each new case fails on e841323c's code and passes now. I checked that by compiling the new test with the compare line taken out of judge (4 FAILs: the differing verdict, the two destination writes, the unsampled byte) and by running the new source checks against e841323c's vk_texture.cpp and nvn_native.c (they stop at the missing compare and at the missing atomic).

Default: kept off. HumanBean asked whether to enable it for everyone, so I tested that. The measurements show no gain to ship it on for. Castle Town's market, standing 130 s (the last 100 s of the frame trace), the game's defaults, 2560x1440, uncapped, RTX 4070 SUPER and 9950X3D:

  • At this head, against main @ 65488813, 4 cores (affinity 0xF00), two runs each, interleaved: =1 measured -0.315 ms a frame (95 %: -0.404 to -0.227), with frames ≥16.7 ms going 2.44 → 1.15 % and none ≥33 ms. But this PR unset also measured -0.178 ms against main, and with the switch off none of the new code runs past one check per texture. That is drift (main ran first and last), and =1 against unset is -0.137 ms.
  • 16 cores, one run each of main and =1: -0.055 ms; frames ≥16.7 ms 0.03 % on both, none ≥33 ms.
  • An earlier session the same morning, on the same code with its default on (85919ba7), ABBA, two runs a side: =1 against =0 was +0.136 ms on 4 cores (frames ≥16.7 ms 1.09 → 1.53 %) and +0.049 ms on 16.

So the sign flips between sessions, and the size of the effect is below this PC's drift between runs. Pooled over all four 4-core off/on pairs, the mean frame is 13.16 ms on both sides. The 4-core gain I reported on f505340b (2.6 → 1.4 % of frames ≥16.7 ms) does not reproduce at this head with the game's defaults. I have not isolated whether the whole compare costs what the moves save. It stays an opt-in attempt.

Not measured, and in Still to test for the Test Farm: this PR unset on 16 cores, more 16-core pairs, compaction every frame at this head, the Deck, AMD, 8 GB cards and Linux. I stopped the local round there to keep testing to what's needed.

Tests: on Windows, 111 of the 130 checks that read the changed files pass and 18 fail; on Linux (WSL, g++), 168 pass and 31 fail. Every one of those failures also fails on the base 65488813. The branch merges cleanly with main 89c3d21e and with #1813 (415777aa); #1813's pending-move skip in texture_ahead_run is untouched.

Thanks, all three were real; fixed in cd5f4bf4 (one commit on top of e841323c, a fast-forward). **1. A destination write between Initialize and the first draw** (`gpu/vk/vk_texture.cpp`, `move_take`; `gpu/vk/tex_move.h`, `storages_equal` and `judge`). The first draw no longer trusts what the game's thread saw. When every other check holds, it compares every byte of the new storage, as an upload there would read it then (`guest_bytes`: guest memory, or the pages the capture kept as submitted), with the old storage's, which nothing has written since the image's upload. That compare runs in 1 MB pieces. The image's upload generation is now the one read *before* that compare (`const uint64_t gen = memory_generation()` ahead of `judge`, then `src->upload_gen = gen`), so a write the compare did not see is stamped later and uploaded at a later draw. A difference is counted (`other bytes now` in the log line) and the texture is made as before. This happens in real play. In a six-area tour on this code (85919ba7, which differs from cd5f4bf4 only in the unset default) with `RX_VK_TEX_MOVE=2` and `HOS_TEX_COMPACT_MS=0`, the game's thread compared every byte of 78,413 moves at Initialize and found none different. At the first draw, 15 of them differed. In plain 16-core market stands, 2 of 1,490 differed (85919ba7) and 3 of 988 (cd5f4bf4). e841323c would have kept the old image for those. Test: `tests/test_tex_move.cpp` simulates a move's whole life in guest memory (the game's copy, Initialize, the registration, the first draw). One case is a one-byte write into the new storage after Initialize, another 64 KB cleared there; the old storage's page generations say nothing in both. Both must be refused (`Verdict::differs`). `tests/test_tex_move.py` checks that `move_take` compares through `storages_equal`/`guest_bytes` and reads the generation before the compare and not again after it. **2. Mode 1's samples treated as proof** (`tex_move.h`). The samples are now only a filter on the game's thread, so a pair whose samples differ is turned away early. Every move that would be taken, in mode 1 or 2, goes through the whole compare above at its first draw. `=2` still also compares whole storages on the game's thread, as a check of the filter. Test: a fixture whose one differing byte lies half way between two sampled pieces. The test asserts that `samples_match` passes it (the filter's known gap) and that the first draw's verdict is `differs`. There are also cases for the compare in pieces: the last short piece, the first byte of the second piece, unreadable, and two read buffers. **3. The host's writable static** (`host/nvn_native.c`, `nvnTextureInitialize`). `same_skip` is now read and written only through `__atomic_load_n`/`__atomic_store_n`, so the first texture creations racing on several threads are fine, the switch set or not. `tests/test_tex_move.py` fails if any line there touches `same_skip` without an atomic. Each new case fails on e841323c's code and passes now. I checked that by compiling the new test with the compare line taken out of `judge` (4 FAILs: the differing verdict, the two destination writes, the unsampled byte) and by running the new source checks against e841323c's `vk_texture.cpp` and `nvn_native.c` (they stop at the missing compare and at the missing atomic). **Default: kept off.** HumanBean asked whether to enable it for everyone, so I tested that. The measurements show no gain to ship it on for. Castle Town's market, standing 130 s (the last 100 s of the frame trace), the game's defaults, 2560x1440, uncapped, RTX 4070 SUPER and 9950X3D: - At this head, against main @ 65488813, 4 cores (affinity 0xF00), two runs each, interleaved: `=1` measured -0.315 ms a frame (95 %: -0.404 to -0.227), with frames ≥16.7 ms going 2.44 → 1.15 % and none ≥33 ms. But this PR *unset* also measured -0.178 ms against main, and with the switch off none of the new code runs past one check per texture. That is drift (main ran first and last), and `=1` against unset is -0.137 ms. - 16 cores, one run each of main and `=1`: -0.055 ms; frames ≥16.7 ms 0.03 % on both, none ≥33 ms. - An earlier session the same morning, on the same code with its default on (85919ba7), ABBA, two runs a side: `=1` against `=0` was **+0.136 ms** on 4 cores (frames ≥16.7 ms 1.09 → 1.53 %) and +0.049 ms on 16. So the sign flips between sessions, and the size of the effect is below this PC's drift between runs. Pooled over all four 4-core off/on pairs, the mean frame is 13.16 ms on both sides. The 4-core gain I reported on f505340b (2.6 → 1.4 % of frames ≥16.7 ms) does not reproduce at this head with the game's defaults. I have not isolated whether the whole compare costs what the moves save. It stays an opt-in `attempt`. Not measured, and in Still to test for the Test Farm: this PR unset on 16 cores, more 16-core pairs, compaction every frame at this head, the Deck, AMD, 8 GB cards and Linux. I stopped the local round there to keep testing to what's needed. Tests: on Windows, 111 of the 130 checks that read the changed files pass and 18 fail; on Linux (WSL, g++), 168 pass and 31 fail. Every one of those failures also fails on the base 65488813. The branch merges cleanly with main 89c3d21e and with #1813 (415777aa); #1813's pending-move skip in `texture_ahead_run` is untouched.
Author
Member

@Beanstalk steamdeck, windows (an 8 GB AMD card if there is one, and a 12 GB NVIDIA one) and linux: Castle Town's market (child), standing 2 minutes after a teleport from kokiri-start, RX_VK_FRAME_TRACE=1: main against this PR unset and this PR with RX_VK_TEX_MOVE=1, and on one Windows PC also with the game compacting every frame (HOS_TEX_COMPACT_MS=0). Expecting this PR unset to match main, no wrong textures with =1, and the log's at the first draw ... other bytes now line; the question is whether =1 has fewer long frames anywhere, since this PC showed no gain and it ships off.

(The farm's runs on #1846 and #1847 today ended in error before building: its checkout of main failed git rev-parse --verify HEAD^{commit} in packs.py's cmd_base.)

@Beanstalk steamdeck, windows (an 8 GB AMD card if there is one, and a 12 GB NVIDIA one) and linux: Castle Town's market (child), standing 2 minutes after a teleport from kokiri-start, `RX_VK_FRAME_TRACE=1`: main against this PR unset and this PR with `RX_VK_TEX_MOVE=1`, and on one Windows PC also with the game compacting every frame (`HOS_TEX_COMPACT_MS=0`). Expecting this PR unset to match main, no wrong textures with `=1`, and the log's `at the first draw ... other bytes now` line; the question is whether `=1` has fewer long frames anywhere, since this PC showed no gain and it ships off. (The farm's runs on #1846 and #1847 today ended in `error` before building: its checkout of main failed `git rev-parse --verify HEAD^{commit}` in packs.py's cmd_base.)
GummiNaomi force-pushed perf/tex-move-keeps-image from cd5f4bf4e5
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 11s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 15s
CI / Workflow lint (actionlint) (pull_request) Successful in 17s
Third-party parts / As their notes say (pull_request) Successful in 17s
PR description / Description follows the template (pull_request_target) Failing after 6s
Website / Website on Cloudflare (pull_request_target) Has been skipped
beanstalk/approval approved by GummiNaomi (reviewed)
beanstalk/steamdeck 0/1 pass, 0 running, 2 queued
beanstalk/linux 0/1 pass, 0 running, 2 queued
beanstalk/windows+amd+vram8gb 0/1 pass, 1 running, 1 queued
beanstalk/windows+nvidia+vram12gb 0/1 pass, 0 running, 2 queued
CI / Website build and checks (pull_request) Has been cancelled
to 4b7f1fed61
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
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 16s
PR description / Description follows the template (pull_request_target) Failing after 6s
beanstalk/approval not approved yet
CI / Website build and checks (pull_request) Failing after 2m50s
2026-11-20 13:19:53 +00:00
Compare
Member

Beanstalk test farm

Commit 4b7f1fe · 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 `4b7f1fe` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/1810) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
Contributor

@GummiNaomi before the Steam Deck farm run: 4b7f1fed still has register_texture_queued returning straight to register_texture_locked when !async_on(). On the Deck threaded rendering is Auto-off (no mirrors), so registrations never go through the render thread's job and no move is ever confirmed. In our Deck runs at e9799a31 without a fix, RX_VK_TEX_MOVE=1 kept 0 images. So the farm's Deck cell would compare main with main.

The fix is the first commit linked in my results comment above, aee1e361: with no render thread it reads the slot, registers and confirms under replay_mu, as the job does. Your new whole-storage compare at the first draw covers what our second commit did, so only that first one is needed.

@GummiNaomi before the Steam Deck farm run: 4b7f1fed still has `register_texture_queued` returning straight to `register_texture_locked` when `!async_on()`. On the Deck threaded rendering is Auto-off (no mirrors), so registrations never go through the render thread's job and no move is ever confirmed. In our Deck runs at e9799a31 without a fix, `RX_VK_TEX_MOVE=1` kept 0 images. So the farm's Deck cell would compare main with main. The fix is the first commit linked in my results comment above, [aee1e361](https://git.magicbean.dev/dukenheimer/Longshot/commit/aee1e36188b04280fa53fec6d554bacf2cc24e05): with no render thread it reads the slot, registers and confirms under `replay_mu`, as the job does. Your new whole-storage compare at the first draw covers what our second commit did, so only that first one is needed.
Author
Member

Closing: no gain I can show. Pooled over both sessions' 4-core off/on pairs the mean frame is 13.16 ms on both sides, and the one session where RX_VK_TEX_MOVE=1 looked faster had the same drift with the switch unset. If a later profile shows moved textures costing arrivals, this can come back.

Closing: no gain I can show. Pooled over both sessions' 4-core off/on pairs the mean frame is 13.16 ms on both sides, and the one session where `RX_VK_TEX_MOVE=1` looked faster had the same drift with the switch unset. If a later profile shows moved textures costing arrivals, this can come back.
GummiNaomi closed this pull request 2026-11-20 21:01:57 +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
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 8s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 14s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
Third-party parts / As their notes say (pull_request) Successful in 16s
PR description / Description follows the template (pull_request_target) Failing after 6s
beanstalk/approval not approved yet
CI / Website build and checks (pull_request) Failing after 2m50s

Pull request closed

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!1810
No description provided.