WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT) #2003

Draft
siantm wants to merge 6 commits from siantm/Longshot:perf/vk-tex-hit-flat into main
Contributor

Summary

texture_view_of (gpu/vk/vk_draw.cpp) keeps what each texture handle resolved to (view, texture, level) by slot, view type, use and storage format. Main keeps them in handle_hits, a FlatMap (#231) whose entries each hold their own destroy generation. This adds the branch's table beside it, behind a switch, on by default (RX_VK_TEX_HIT_FLAT=0 gives main's map), so both can be compared in one build: one array of 40-byte places (HitSlot) found by the key's hash, the next place on a collision, at most half full; the destroy generation kept once for the table as an era (a place resolved in an older era is stale, as the generation only goes up); the texture touched once a submission as before. A new key is searched once: the place the search gave is used for it after the resolution unless the resolution changed the table. The bound is the map's 65,536 keys, checked where the map's is, at a submission's first recording: there a full table starts over and gives its places back; until then a new key past the bound is resolved and not kept, the keys kept serving on (nothing is cleared inside a recording). Growth whose memory is refused leaves the table as it was and the view is returned uncached. A miss is the same resolution as ever. The expected result is a cheaper lookup for every texture binding; it is not measured.

A behaviour fix of its own, both ways (this changes the map's way too): a view refused for want of memory this frame (the texture's view_failed_frame) is not kept, so it is made again from the next frame on, as cached_image_view retries it, instead of the dummy standing until the slot or the destroy generation moves. The frame it is compared with is read once before the resolution, so a refusal is not kept either when another thread's present moves the frame on meanwhile. The lookups are counted only with RX_VK_LOG_HITS=1, the same counts both ways; its 200,000-binding line is logged both ways, and with the table also a frame-log line (vk: a frame: ... texture handles kept as resolved, every 120 presents), whose last figure is the times a thread's table found its places stale (one count a table, not the generation's own moves). Off, nothing is counted.

Switch: RX_VK_TEX_HIT_FLAT (kind kill, on by default as the change proposes, docs/dev/standards.md, Switches; its row in gpu/vk/switches.def). Unset, 1 or any value but those below: the flat table. 0 (or an empty value, false, off or no, in any case, spaces around it not counted): main's map, and only its bound is kept at a submission's start. It is read once, at its first use (so HOS_AB cannot alternate it); its first read logs what it chose.

From 2816697a on exp/x86-asm-sync.

Read first: the comment above HitSlot, HitTable, resolved_handles_new_submission and texture_view_of in gpu/vk/vk_draw.cpp.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 09f185c9 on main @ 9dd41326 (the branch's earlier commits unchanged by the rebase, git range-diff), in jobs dyl-2003 (light, two checks at once) and dyh-2003 (build) of the PC's job queue, each check in a hidden console of its own, the Vulkan headers from the builder's CPM cache (RX_CPM):

  • Its own, through tests/run_all.py --strict --exact: tests/test_tex_hit_flat.py (the table against a model of the map's rules over random keys, slot re-registrations, generation moves (also inside a resolution), a resolution that puts another key first, epochs with the bound kept at a submission's start, tiny and real bounds and an era wrap; then the bound and memory refused for more places, case by case; the switch's reader in fresh processes: unset and 1, on and another value on, 0, off, false, no, empty and spaces off, twice each, set to the other answer after its first read with the setter's result checked; its kill row), tests/test_flat_map.py (the real texture_view_of with RX_VK_TEX_HIT_FLAT unset (the table), 0 (the map) and 1 against a std::unordered_map reference, every stub call compared, the destroy generation moved inside some resolutions; RX_VK_LOG_HITS unset counts nothing, set logs the 200,000-binding line both ways; a view refused for want of memory is not kept, also when the frame moves on between the refusal and texture_view_of's look at it), tests/test_handle_lookup.py, tests/test_switch_table.py: pass.
  • At the test commit ddfa3fda (the earlier code with these checks): test_flat_map.py fails (std::unordered_map: a view refused as the frame moved on was kept) and test_tex_hit_flat.py fails (no kill row); at the head both pass.
  • tests/test_recording_admission.py, tests/test_draw_stream_visibility.py and tests/test_fsr_uniform_ownership.py (the fixtures whose draw_begin_recording stub this PR changes) fail at the head and at the test commit; both test_draw_stream_visibility.py and test_fsr_uniform_ownership.py fail on main @ 9dd41326 too, the same way (job dyh-2003); test_recording_admission.py (worker slot ownership, the parallel case that fails now and then on main as well, 3 of 5 runs on f1f2dc5b in the earlier round's job fb-2003-3) passed at the head in the --changed run below.
  • gpu/vk/vk_draw.cpp compiled (no object) with the game build's own command for it, from a local build's compile_commands.json: no error.
  • The 182 checks that read a file this change touches (tests/run_all.py --changed origin/main, RX_CPM set; job dyh-2003, build, 8 at once): 158 passed, 18 failed, 6 skipped (Linux only). Each failure fails on main @ 9dd41326 too, the same way, run in the same job: tests/test_crash_dialog.py, tests/test_dev_ab.py, tests/test_dev_packs.py, tests/test_device_lost_exit.py, tests/test_draw_binds.py, tests/test_draw_stream_visibility.py, tests/test_frame_overlap.py, tests/test_fsr_uniform_ownership.py, tests/test_linux_pressure.py, tests/test_mesh_conv.py, tests/test_pipeline_play_cache.py, tests/test_prepare_cache_save.py, tests/test_present_queue_default.py, tests/test_recorder_own_idle.py, tests/test_sampler_admission.py, tests/test_target_reuse_memory.py, tests/test_upscaler_rows.py, tests/test_vk_occlusion_queries.py. None stopped for want of the Vulkan headers. tests/test_vbytes.py is not among them and was not run.

It has NOT run in the game on this PC yet.

Still to test:

  • Windows 11, i7-9700, RTX 4060 (this PC): start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main @ 9dd41326, this PR unset (the table, as it ships) and this PR with RX_VK_TEX_HIT_FLAT=0 (the map), each warmed a minute in the scene first, then interleaved (main, =0, unset, unset, =0, main), two runs each, with RX_VK_PROF_FINE=1: the replay's CPU time a frame (vk: a frame's replay time (ms), its texture lookups part, and the textures part of vk: a frame (fine): ms:), beside FPS and p99, expecting the same picture all three ways, =0 as main, and unset the texture lookups' time lower than =0's beyond the spread; then one run each with RX_VK_LOG_HITS=1, the log's texture handles kept as resolved line read for its hits (by hand)
  • Windows 11, i7-9700, RTX 4060 (this PC): the same three ways in a heavy or streaming scene (Hyrule Field at a gallop, then into Kakariko Village), warmed and interleaved as above, with the same replay and lookup times, average FPS, 1% lows, median and p99 frame time, and the process's RAM after the heavy part gives way to the light one, at the same settings and build type (by hand). If unset is not faster than =0 beyond the spread, the switch goes off or the change is dropped, and this description says which
  • Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest and a heavy or streaming scene (the light walk never reaches the 65,536-key bound or a start-over), main against this PR unset and with RX_VK_TEX_HIT_FLAT=0, warmed, in ABBA order, expecting the same picture every way and no crash or validation error, with the replay's CPU time (RX_VK_PROF_FINE=1, its textures line) and RAM beside p99 (by hand or on the farm, not run yet)
  • Linux (any GPU): build the renderer and run tests/test_tex_hit_flat.py, tests/test_handle_lookup.py, tests/test_flat_map.py with --cxx g++ and --cxx clang++, expecting PASS (by hand)

Measurements

Verdict: not measured in play yet: no micro-benchmark of the table and no run in the game on this PC yet; the in-game A/B is in Still to test. RX_VK_TEX_HIT_FLAT ships on (kind kill, 0 gives main's map), the value this change proposes (docs/dev/standards.md, Switches); it goes off, or the change is dropped, if that A/B goes against it.

Risks

Unset (the default) it is the table; RX_VK_TEX_HIT_FLAT=0 is main's map. Both ways two things change: a view refused for want of memory is made again from the next frame on instead of being kept as the dummy, and the lookups are counted only with RX_VK_LOG_HITS=1. With the table: a stale place taken as good would show another texture's view, or a freed one (a crash): the era stands for the destroy generation as the map's per-entry generation did, and the tests check the table against the map's rules and run the real texture_view_of both ways against the map's. The table costs memory: up to 131,072 places of 40 bytes on each thread that resolves textures (about 5 MB a thread at the bound), given back when it starts over at a submission's start; below the bound it keeps its size, as the map does. A frame that meets more than 65,536 keys resolves the new ones again until the next submission. A thread that resolves handles but never runs draw_begin_recording never starts its table over: at the bound it would keep no new key for good (each resolved again at every lookup, a cost in time only), where the map grows on (the comment at resolved_handles_new_submission says so). The renderer is compiled again after updating.

Overlap: #1232 (jcabarca's, not a draft) also changes texture_view_of in gpu/vk/vk_draw.cpp; the two conflict there. #1232 goes first; this PR rebases onto it.

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. Not yet: it has not run in the game.
  • mise run test passes (any failure that also fails on main is named). Not yet: only the checks in Testing ran.
  • Measured against main, or Measurements says why there is nothing to measure. Not yet (Measurements).
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def. Its row is in; it ships on, as the change proposes (docs/dev/standards.md, Switches), not measured yet.
  • 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. Not yet: vk_draw.cpp compiled with the game build's command (Testing); no full build.
  • 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.
## Summary `texture_view_of` (`gpu/vk/vk_draw.cpp`) keeps what each texture handle resolved to (view, texture, level) by slot, view type, use and storage format. Main keeps them in `handle_hits`, a `FlatMap` (#231) whose entries each hold their own destroy generation. This adds the branch's table beside it, behind a switch, on by default (`RX_VK_TEX_HIT_FLAT=0` gives main's map), so both can be compared in one build: one array of 40-byte places (`HitSlot`) found by the key's hash, the next place on a collision, at most half full; the destroy generation kept once for the table as an era (a place resolved in an older era is stale, as the generation only goes up); the texture touched once a submission as before. A new key is searched once: the place the search gave is used for it after the resolution unless the resolution changed the table. The bound is the map's 65,536 keys, checked where the map's is, at a submission's first recording: there a full table starts over and gives its places back; until then a new key past the bound is resolved and not kept, the keys kept serving on (nothing is cleared inside a recording). Growth whose memory is refused leaves the table as it was and the view is returned uncached. A miss is the same resolution as ever. The expected result is a cheaper lookup for every texture binding; it is not measured. A behaviour fix of its own, both ways (this changes the map's way too): a view refused for want of memory this frame (the texture's `view_failed_frame`) is not kept, so it is made again from the next frame on, as `cached_image_view` retries it, instead of the dummy standing until the slot or the destroy generation moves. The frame it is compared with is read once before the resolution, so a refusal is not kept either when another thread's present moves the frame on meanwhile. The lookups are counted only with `RX_VK_LOG_HITS=1`, the same counts both ways; its 200,000-binding line is logged both ways, and with the table also a frame-log line (`vk: a frame: ... texture handles kept as resolved`, every 120 presents), whose last figure is the times a thread's table found its places stale (one count a table, not the generation's own moves). Off, nothing is counted. Switch: `RX_VK_TEX_HIT_FLAT` (kind kill, on by default as the change proposes, docs/dev/standards.md, Switches; its row in `gpu/vk/switches.def`). Unset, `1` or any value but those below: the flat table. `0` (or an empty value, `false`, `off` or `no`, in any case, spaces around it not counted): main's map, and only its bound is kept at a submission's start. It is read once, at its first use (so `HOS_AB` cannot alternate it); its first read logs what it chose. From 2816697a on `exp/x86-asm-sync`. Read first: the comment above `HitSlot`, `HitTable`, `resolved_handles_new_submission` and `texture_view_of` in `gpu/vk/vk_draw.cpp`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 09f185c9 on main @ 9dd41326 (the branch's earlier commits unchanged by the rebase, `git range-diff`), in jobs `dyl-2003` (light, two checks at once) and `dyh-2003` (build) of the PC's job queue, each check in a hidden console of its own, the Vulkan headers from the builder's CPM cache (`RX_CPM`): - Its own, through `tests/run_all.py --strict --exact`: `tests/test_tex_hit_flat.py` (the table against a model of the map's rules over random keys, slot re-registrations, generation moves (also inside a resolution), a resolution that puts another key first, epochs with the bound kept at a submission's start, tiny and real bounds and an era wrap; then the bound and memory refused for more places, case by case; the switch's reader in fresh processes: unset and `1`, `on` and another value on, `0`, `off`, `false`, `no`, empty and spaces off, twice each, set to the other answer after its first read with the setter's result checked; its `kill` row), `tests/test_flat_map.py` (the real `texture_view_of` with `RX_VK_TEX_HIT_FLAT` unset (the table), `0` (the map) and `1` against a std::unordered_map reference, every stub call compared, the destroy generation moved inside some resolutions; `RX_VK_LOG_HITS` unset counts nothing, set logs the 200,000-binding line both ways; a view refused for want of memory is not kept, also when the frame moves on between the refusal and `texture_view_of`'s look at it), `tests/test_handle_lookup.py`, `tests/test_switch_table.py`: pass. - At the test commit ddfa3fda (the earlier code with these checks): `test_flat_map.py` fails (`std::unordered_map: a view refused as the frame moved on was kept`) and `test_tex_hit_flat.py` fails (no `kill` row); at the head both pass. - `tests/test_recording_admission.py`, `tests/test_draw_stream_visibility.py` and `tests/test_fsr_uniform_ownership.py` (the fixtures whose `draw_begin_recording` stub this PR changes) fail at the head and at the test commit; both `test_draw_stream_visibility.py` and `test_fsr_uniform_ownership.py` fail on main @ 9dd41326 too, the same way (job `dyh-2003`); `test_recording_admission.py` (worker slot ownership, the parallel case that fails now and then on main as well, 3 of 5 runs on f1f2dc5b in the earlier round's job fb-2003-3) passed at the head in the `--changed` run below. - `gpu/vk/vk_draw.cpp` compiled (no object) with the game build's own command for it, from a local build's compile_commands.json: no error. - The 182 checks that read a file this change touches (`tests/run_all.py --changed origin/main`, `RX_CPM` set; job `dyh-2003`, build, 8 at once): 158 passed, 18 failed, 6 skipped (Linux only). Each failure fails on main @ 9dd41326 too, the same way, run in the same job: `tests/test_crash_dialog.py`, `tests/test_dev_ab.py`, `tests/test_dev_packs.py`, `tests/test_device_lost_exit.py`, `tests/test_draw_binds.py`, `tests/test_draw_stream_visibility.py`, `tests/test_frame_overlap.py`, `tests/test_fsr_uniform_ownership.py`, `tests/test_linux_pressure.py`, `tests/test_mesh_conv.py`, `tests/test_pipeline_play_cache.py`, `tests/test_prepare_cache_save.py`, `tests/test_present_queue_default.py`, `tests/test_recorder_own_idle.py`, `tests/test_sampler_admission.py`, `tests/test_target_reuse_memory.py`, `tests/test_upscaler_rows.py`, `tests/test_vk_occlusion_queries.py`. None stopped for want of the Vulkan headers. `tests/test_vbytes.py` is not among them and was not run. It has NOT run in the game on this PC yet. **Still to test:** - Windows 11, i7-9700, RTX 4060 (this PC): start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main @ 9dd41326, this PR unset (the table, as it ships) and this PR with `RX_VK_TEX_HIT_FLAT=0` (the map), each warmed a minute in the scene first, then interleaved (main, =0, unset, unset, =0, main), two runs each, with `RX_VK_PROF_FINE=1`: the replay's CPU time a frame (`vk: a frame's replay time (ms)`, its texture lookups part, and the `textures` part of `vk: a frame (fine): ms:`), beside FPS and p99, expecting the same picture all three ways, =0 as main, and unset the texture lookups' time lower than =0's beyond the spread; then one run each with `RX_VK_LOG_HITS=1`, the log's `texture handles kept as resolved` line read for its hits (by hand) - Windows 11, i7-9700, RTX 4060 (this PC): the same three ways in a heavy or streaming scene (Hyrule Field at a gallop, then into Kakariko Village), warmed and interleaved as above, with the same replay and lookup times, average FPS, 1% lows, median and p99 frame time, and the process's RAM after the heavy part gives way to the light one, at the same settings and build type (by hand). If unset is not faster than =0 beyond the spread, the switch goes off or the change is dropped, and this description says which - Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: Kokiri Forest and a heavy or streaming scene (the light walk never reaches the 65,536-key bound or a start-over), main against this PR unset and with `RX_VK_TEX_HIT_FLAT=0`, warmed, in ABBA order, expecting the same picture every way and no crash or validation error, with the replay's CPU time (`RX_VK_PROF_FINE=1`, its textures line) and RAM beside p99 (by hand or on the farm, not run yet) - Linux (any GPU): build the renderer and run `tests/test_tex_hit_flat.py`, `tests/test_handle_lookup.py`, `tests/test_flat_map.py` with `--cxx g++` and `--cxx clang++`, expecting PASS (by hand) ## Measurements **Verdict:** not measured in play yet: no micro-benchmark of the table and no run in the game on this PC yet; the in-game A/B is in Still to test. `RX_VK_TEX_HIT_FLAT` ships on (kind kill, `0` gives main's map), the value this change proposes (docs/dev/standards.md, Switches); it goes off, or the change is dropped, if that A/B goes against it. ## Risks Unset (the default) it is the table; `RX_VK_TEX_HIT_FLAT=0` is main's map. Both ways two things change: a view refused for want of memory is made again from the next frame on instead of being kept as the dummy, and the lookups are counted only with `RX_VK_LOG_HITS=1`. With the table: a stale place taken as good would show another texture's view, or a freed one (a crash): the era stands for the destroy generation as the map's per-entry generation did, and the tests check the table against the map's rules and run the real `texture_view_of` both ways against the map's. The table costs memory: up to 131,072 places of 40 bytes on each thread that resolves textures (about 5 MB a thread at the bound), given back when it starts over at a submission's start; below the bound it keeps its size, as the map does. A frame that meets more than 65,536 keys resolves the new ones again until the next submission. A thread that resolves handles but never runs `draw_begin_recording` never starts its table over: at the bound it would keep no new key for good (each resolved again at every lookup, a cost in time only), where the map grows on (the comment at `resolved_handles_new_submission` says so). The renderer is compiled again after updating. Overlap: #1232 (jcabarca's, not a draft) also changes `texture_view_of` in `gpu/vk/vk_draw.cpp`; the two conflict there. #1232 goes first; this PR rebases onto it. ## Checklist ### Ready for review - [x] 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. Not yet: it has not run in the game. - [ ] `mise run test` passes (any failure that also fails on `main` is named). Not yet: only the checks in Testing ran. - [ ] Measured against `main`, or Measurements says why there is nothing to measure. Not yet (Measurements). - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [ ] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. Its row is in; it ships on, as the change proposes (docs/dev/standards.md, Switches), not measured yet. - [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. Not yet: `vk_draw.cpp` compiled with the game build's command (Testing); no full build. - [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.
perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT, on)
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 11s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
9fd4c4b46e
texture_view_of keeps what each texture handle resolved to (view, texture, level) by slot, view type, use and
storage format. Main keeps them in handle_hits, a FlatMap (#231) whose entries each hold their own destroy
generation. This adds the branch's table beside it, behind a switch, so both can be compared in one build: one array
of 40-byte places (HitSlot) found by the key's hash, linear probing, at most half full; the destroy generation kept
once for the table as an `era` (a place resolved in an older era is stale, which is the map's "its generation is not
the one now", as the generation only goes up); the texture touched once a submission as before; a bound of 65536
keys at which it starts over (the map's bound). A miss is the same resolution as ever. The frame log gets a line
counting the table's hits, misses by reason and generation moves (draw_skip_report).

The frame log's counts of the table's lookups (`vk: a frame: ... texture handles kept as resolved`) are relaxed
atomics, each replay thread counting into them without a locked add (st_bump).

Switch: RX_VK_TEX_HIT_FLAT, kill, on by default (the branch's default); =0 (or false, off, no) is main's map. Read
once, at its first use. Row in gpu/vk/switches.def.
Its saving was not measured on the branch (2816697a: "unreviewed"); not measured in play.

Tests: tests/test_tex_hit_flat.py (new) cuts HitSlot and HitTable and runs them against a model of the map's rules
over random keys, slot re-registrations, generation moves (also inside a resolution), epochs, a tiny bound, the real
bound and an era wrap, reads texture_view_of for how it uses the table, and the switch's reader runs in fresh
processes (unset, 0, off, false, 1, on and another value, twice each, set again after its first read).
test_handle_lookup.py also checks the table is searched once and put once a lookup. test_flat_map.py compiles the
table with its cut and runs the map's branch (RX_VK_TEX_HIT_FLAT=0), which it compares against std::unordered_map.

Assisted-by: Claude Code
Member

Possibly related, for context:

  • PR #1232 fix(vk): name the view's format in custom border colours of packed 16-bit textures — Overlapping texture_view_of changes in vk_draw.cpp; potential conflict.
Possibly related, for context: - PR #1232 fix(vk): name the view's format in custom border colours of packed 16-bit textures — Overlapping texture_view_of changes in vk_draw.cpp; potential conflict.
BeanBot left a comment

Recommendation: Request changes. The default path adds a shared counter update to every lookup and can clear 5 MiB of cache slots in the middle of recording a draw. It also caches transient image-view failures past the intended retry frame, and the reported tests never execute the flat branch of texture_view_of.

Adds a smaller cache entry for resolved Vulkan texture handles and keeps main's FlatMap as a fallback. The intended gain is cheaper descriptor building. The new path adds another probing implementation, always-on instrumentation, and a cache that retains its peak allocation until the replay thread exits.

@fix will do (12)

  1. L1 gpu/vk/vk_draw.cpp:3830: A transient vkCreateImageView allocation failure is cached as a valid null result until the slot version or destroy generation changes. (more on the line)
  2. L2 (its part an edit can do) gpu/vk/vk_draw.cpp:3772: Use RX_VK_LOG_HITS to guard lookup counters and bulk reporting. The existing replay lock also serializes the current writers and reporter, so counters kept under that lock can use ordinary increments.
  3. L3 (its part an edit can do) gpu/vk/vk_draw.cpp:3668: Skip insertion of new keys at the cap and defer the reset to the next submission boundary. Keep serving existing entries until then.
  4. L4 (its part an edit can do) gpu/vk/vk_draw.cpp:3629: Release oversized backing storage on a cap reset or after sustained low occupancy, and retain small tables for reuse.
  5. L5 gpu/vk/vk_draw.cpp:3654: An allocation failure in the optional cache can escape replay after the texture has already resolved. (more on the line)
  6. L6 tests/test_tex_hit_flat.py:241: The fixture runs a hand-written copy of the hit and touch logic. (more on the line)
  7. L7 (minor) gpu/vk/vk_draw.cpp:3667: A new key repeats the same unsuccessful probe three times when the table can accept it without growing or clearing. (more on the line)
  8. L8 (minor) gpu/vk/vk_draw.cpp:3781: RX_VK_LOG_HITS=1 no longer produces its documented 200,000-binding diagnostic in the default configuration. (more on the line)
  9. L9 (minor) gpu/vk/vk_draw.cpp:3709: The log labels observations by individual tables as moves of the global destroy generation. (more on the line)
  10. L10 (minor) gpu/vk/vk_draw.cpp:6224: An on-mode recording still constructs the fallback FlatMap and registers it for TLS cleanup even if that thread never looks up a texture. Guard this maintenance with the selected implementation and update the source check to allow the guard.
  11. L11 (minor) gpu/vk/switches.def:696: The row says any other value enables the table, but an explicitly empty or whitespace-only value disables it. (more on the line)
  12. L12 (minor) tests/test_flat_map.py:273: When the changed check is invoked directly, it ignores CXX and the configured llvm-mingw directory. A Windows builder with its compiler outside PATH gets a skip even when CXX points to the correct compiler. Use the same compiler selection as the new check or share the lookup.

For the author (4) (a run, a measurement or a decision)

  • L2 gpu/vk/vk_draw.cpp:3772: The default path performs diagnostics in every timed lookup while main's lookup counters default off. (more on the line)
  • L3 gpu/vk/vk_draw.cpp:3668: The first new key after the table fills clears every slot inside an active recording. (more on the line)
  • L4 gpu/vk/vk_draw.cpp:3629: A replay thread keeps the largest table it ever needed, including after a saturated area gives way to a light scene. (more on the line)
  • L13 (minor): The PR opened before the required author game run. The proposed single-scene check also leaves the shipping default unproven. Build the full renderer on Windows and Linux, verify sampled and storage output in game, and run the interleaved comparison in Kokiri and a heavy or streaming scene on the affected Tier 1 hardware. Record replay and lookup time, average FPS, 1% lows, median and p99 frame times, RAM and VRAM with matched settings and build types.

Checks: Still running: CI / Conventional Commit title (pull_request), CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request), CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request), CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request), CI / Workflow lint (actionlint) (pull_request), CI / Website build and checks (pull_request), Guide screenshots / Guide images and local UI source review (pull_request), Third-party parts / As their notes say (pull_request), Third-party parts / The same as upstream (pull_request), PR description / Description follows the template (pull_request_target).

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

Does it help: Unproven. The PR reports 158 passing Windows source checks and 18 failures also seen on base 75317e1f. There are no game runs, lookup timings, frame-time distributions, or RAM comparisons for head 9fd4c4b4.

Other systems: Both paths feed sampled and storage descriptors for graphics and compute, as well as upscaler and frame-generation dispatches. The changed code is shared across Windows and Linux, GPU vendors, and Steam Deck. Replay holds replay_mu around lookup and frame reporting, and the slot versions retain their existing atomic publication order. Texture retirement, queue ordering, and descriptor reuse still use the same generation source. The table itself consumes host RAM. Its effect on Vulkan work, frame pacing, and shared-memory systems still needs in-game verification. The diff leaves saves, audio, input, the renderer API, and shader generation untouched.

Switches: RX_VK_TEX_HIT_FLAT is a developer kill switch, on when unset, read once and fixed for the process. Its row is present. Main's map is selected by 0, false, off, no, or an empty value. The on default is suitable for gathering WIP evidence and has no shipping measurements yet. RX_VK_LOG_HITS still defaults off, but its existing output only works with the flat table disabled.

Reviewed: 9fd4c4b46e against 75317e1f31: Read all five diffs, the full three Python tests, the complete changed C++ sections, and the switch row and its neighbors. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, and the developer standards. Read the relevant FlatMap, TLS ownership, replay locking, slot publication, image-view retry, descriptor and upscaler callers, and test-runner sections. Skimmed unrelated parts of vk_draw.cpp and switches.def and the referenced architecture and switch docs. The supplied Testing summary is the available run record. The named logs and sibling Tooling checkout were unavailable locally. There are no changed translations or generated files.; nothing run (a code review).

Checked and fine:

  • The era uses the generation sampled before resolution. This preserves invalidation when texture_get advances the generation during a miss.
  • With the production cap, growth stays in range, an empty slot terminates probing, and era wrap clears old entries before era 1 is reused.
  • The cache uses the existing TLS owner and releases its vector on normal thread exit. The current replay lock serializes frame reporting and counter writes.
  • The commit carries an Assisted-by trailer. No game-derived data, vendor SDKs, generated files, or third-party changes are in the diff.
  • Tests use the standard library, temporary fixtures, and controlled child settings for the new switch. No downloads, installs, or unrelated side effects are in the change.

Testing: Read-only review. The author reports that the three targeted checks passed on Windows with llvm-mingw. The 176 changed-source checks had 18 failures also seen on main. Full renderer builds, gameplay and Tier 1 runs, the complete test suite, and CI results are outstanding.

Overlaps and merge order: The FlatMap work from #231 is already in the base. No other overlap is visible in the supplied material or local history.


Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The default path adds a shared counter update to every lookup and can clear 5 MiB of cache slots in the middle of recording a draw. It also caches transient image-view failures past the intended retry frame, and the reported tests never execute the flat branch of texture_view_of. Adds a smaller cache entry for resolved Vulkan texture handles and keeps main's FlatMap as a fallback. The intended gain is cheaper descriptor building. The new path adds another probing implementation, always-on instrumentation, and a cache that retains its peak allocation until the replay thread exits. **`@fix` will do (12)** 1. **L1** `gpu/vk/vk_draw.cpp:3830`: A transient vkCreateImageView allocation failure is cached as a valid null result until the slot version or destroy generation changes. (more on the line) 2. **L2** (its part an edit can do) `gpu/vk/vk_draw.cpp:3772`: Use RX_VK_LOG_HITS to guard lookup counters and bulk reporting. The existing replay lock also serializes the current writers and reporter, so counters kept under that lock can use ordinary increments. 3. **L3** (its part an edit can do) `gpu/vk/vk_draw.cpp:3668`: Skip insertion of new keys at the cap and defer the reset to the next submission boundary. Keep serving existing entries until then. 4. **L4** (its part an edit can do) `gpu/vk/vk_draw.cpp:3629`: Release oversized backing storage on a cap reset or after sustained low occupancy, and retain small tables for reuse. 5. **L5** `gpu/vk/vk_draw.cpp:3654`: An allocation failure in the optional cache can escape replay after the texture has already resolved. (more on the line) 6. **L6** `tests/test_tex_hit_flat.py:241`: The fixture runs a hand-written copy of the hit and touch logic. (more on the line) 7. **L7** (minor) `gpu/vk/vk_draw.cpp:3667`: A new key repeats the same unsuccessful probe three times when the table can accept it without growing or clearing. (more on the line) 8. **L8** (minor) `gpu/vk/vk_draw.cpp:3781`: RX_VK_LOG_HITS=1 no longer produces its documented 200,000-binding diagnostic in the default configuration. (more on the line) 9. **L9** (minor) `gpu/vk/vk_draw.cpp:3709`: The log labels observations by individual tables as moves of the global destroy generation. (more on the line) 10. **L10** (minor) `gpu/vk/vk_draw.cpp:6224`: An on-mode recording still constructs the fallback FlatMap and registers it for TLS cleanup even if that thread never looks up a texture. Guard this maintenance with the selected implementation and update the source check to allow the guard. 11. **L11** (minor) `gpu/vk/switches.def:696`: The row says any other value enables the table, but an explicitly empty or whitespace-only value disables it. (more on the line) 12. **L12** (minor) `tests/test_flat_map.py:273`: When the changed check is invoked directly, it ignores CXX and the configured llvm-mingw directory. A Windows builder with its compiler outside PATH gets a skip even when CXX points to the correct compiler. Use the same compiler selection as the new check or share the lookup. **For the author (4)** (a run, a measurement or a decision) - **L2** `gpu/vk/vk_draw.cpp:3772`: The default path performs diagnostics in every timed lookup while main's lookup counters default off. (more on the line) - **L3** `gpu/vk/vk_draw.cpp:3668`: The first new key after the table fills clears every slot inside an active recording. (more on the line) - **L4** `gpu/vk/vk_draw.cpp:3629`: A replay thread keeps the largest table it ever needed, including after a saturated area gives way to a light scene. (more on the line) - **L13** (minor): The PR opened before the required author game run. The proposed single-scene check also leaves the shipping default unproven. Build the full renderer on Windows and Linux, verify sampled and storage output in game, and run the interleaved comparison in Kokiri and a heavy or streaming scene on the affected Tier 1 hardware. Record replay and lookup time, average FPS, 1% lows, median and p99 frame times, RAM and VRAM with matched settings and build types. **Checks:** Still running: `CI / Conventional Commit title (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request)`, `CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request)`, `CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request)`, `CI / Workflow lint (actionlint) (pull_request)`, `CI / Website build and checks (pull_request)`, `Guide screenshots / Guide images and local UI source review (pull_request)`, `Third-party parts / As their notes say (pull_request)`, `Third-party parts / The same as upstream (pull_request)`, `PR description / Description follows the template (pull_request_target)`. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The PR reports 158 passing Windows source checks and 18 failures also seen on base 75317e1f. There are no game runs, lookup timings, frame-time distributions, or RAM comparisons for head 9fd4c4b4. **Other systems:** Both paths feed sampled and storage descriptors for graphics and compute, as well as upscaler and frame-generation dispatches. The changed code is shared across Windows and Linux, GPU vendors, and Steam Deck. Replay holds replay_mu around lookup and frame reporting, and the slot versions retain their existing atomic publication order. Texture retirement, queue ordering, and descriptor reuse still use the same generation source. The table itself consumes host RAM. Its effect on Vulkan work, frame pacing, and shared-memory systems still needs in-game verification. The diff leaves saves, audio, input, the renderer API, and shader generation untouched. **Switches:** RX_VK_TEX_HIT_FLAT is a developer kill switch, on when unset, read once and fixed for the process. Its row is present. Main's map is selected by 0, false, off, no, or an empty value. The on default is suitable for gathering WIP evidence and has no shipping measurements yet. RX_VK_LOG_HITS still defaults off, but its existing output only works with the flat table disabled. **Reviewed:** 9fd4c4b46e76 against 75317e1f31ff: Read all five diffs, the full three Python tests, the complete changed C++ sections, and the switch row and its neighbors. Read AGENTS.md, CONTRIBUTING.md, the Forgejo template, and the developer standards. Read the relevant FlatMap, TLS ownership, replay locking, slot publication, image-view retry, descriptor and upscaler callers, and test-runner sections. Skimmed unrelated parts of vk_draw.cpp and switches.def and the referenced architecture and switch docs. The supplied Testing summary is the available run record. The named logs and sibling Tooling checkout were unavailable locally. There are no changed translations or generated files.; nothing run (a code review). **Checked and fine:** - The era uses the generation sampled before resolution. This preserves invalidation when texture_get advances the generation during a miss. - With the production cap, growth stays in range, an empty slot terminates probing, and era wrap clears old entries before era 1 is reused. - The cache uses the existing TLS owner and releases its vector on normal thread exit. The current replay lock serializes frame reporting and counter writes. - The commit carries an Assisted-by trailer. No game-derived data, vendor SDKs, generated files, or third-party changes are in the diff. - Tests use the standard library, temporary fixtures, and controlled child settings for the new switch. No downloads, installs, or unrelated side effects are in the change. **Testing:** Read-only review. The author reports that the three targeted checks passed on Windows with llvm-mingw. The 176 changed-source checks had 18 failures also seen on main. Full renderer builds, gameplay and Tier 1 runs, the complete test suite, and CI results are outstanding. **Overlaps and merge order:** The FlatMap work from #231 is already in the base. No other overlap is visible in the supplied material or local history. </details> --- <sub>Automated code review by BeanBot (gpt-6.2-sol), on the pull request's opening. Nothing was run; a maintainer decides.</sub>
@ -693,6 +693,7 @@ SW(RX_VK_TEX_AHEAD_MS, tune, float, "12 ms", "<n>: the time in ms a light frame
SW(RX_VK_TEX_CAPTURE, kill, bool, "on, when the capture is on", "0 keeps the storage of textures uploaded from guest memory out of the submit-time capture.")
SW(RX_VK_TEX_CAPTURE_MAX_MB, tune, int, "2048 MB, in effect any size", "Sets the largest uploaded texture whose storage joins the submit-time memory capture; it was 8 MB before.")
SW(RX_VK_TEX_CAPTURE_OFF_FILE, diag, string, "not set: uploads read the captured copies", "A path: while that file exists, texture uploads read live guest memory as before, for A/B runs in one session.")
SW(RX_VK_TEX_HIT_FLAT, kill, bool, "on: texture_view_of keeps the resolved texture handles in a flat table of its own, the destroy generation kept once for the table as an era", "=0 (or false, off, no): the handle_hits map, as before; any other value is on. Read once, at its first use (HOS_AB cannot alternate it). The views found are the same either way (tests/test_tex_hit_flat.py); the frame log's `vk: a frame: ... texture handles kept as resolved` line counts its lookups.")
Member

L11 (minor): The row says any other value enables the table, but an explicitly empty or whitespace-only value disables it. Describe the shared parser's behavior in the row and PR summary. Add switch fixture cases for no and whitespace, which the current matrix omits.

**L11** (minor): The row says any other value enables the table, but an explicitly empty or whitespace-only value disables it. Describe the shared parser's behavior in the row and PR summary. Add switch fixture cases for `no` and whitespace, which the current matrix omits.
@ -3591,0 +3626,4 @@
static size_t home(uint64_t key, size_t mask) {
return (size_t)((key * 0x9E3779B97F4A7C15ull) >> 32) & mask;
}
void wipe() {
Member

L4: A replay thread keeps the largest table it ever needed, including after a saturated area gives way to a light scene. Main's cap-triggered clear releases the backing array. Compare retained RAM after a heavy-to-light transition, including on Steam Deck and with threaded rendering off.

**L4**: A replay thread keeps the largest table it ever needed, including after a saturated area gives way to a light scene. Main's cap-triggered clear releases the backing array. Compare retained RAM after a heavy-to-light transition, including on Steam Deck and with threaded rendering off.
@ -3591,0 +3651,4 @@
}
}
void grow() {
std::vector<HitSlot> old(slots.empty() ? (size_t)256 : slots.size() * 2);
Member

L5: An allocation failure in the optional cache can escape replay after the texture has already resolved. For example, growth from 32,768 to 32,769 keys asks for a fresh 5 MiB block while main still has room in its existing table. On allocation failure, keep the old table intact and return the resolved view uncached. Apply the same fallback to first-use table allocation.

**L5**: An allocation failure in the optional cache can escape replay after the texture has already resolved. For example, growth from 32,768 to 32,769 keys asks for a fresh 5 MiB block while main still has room in its existing table. On allocation failure, keep the old table intact and return the resolved view uncached. Apply the same fallback to first-use table allocation.
@ -3591,0 +3664,4 @@
/// The key's place for a resolution just made: the one it had, or a new one, taken (its key and this era set; the caller
/// fills in the rest). At `most` keys the table starts over first. Places are never more than half taken, so a search ends
HitSlot& put(uint64_t key) {
if (HitSlot* s = find(key)) return *s;
Member

L7 (minor): A new key repeats the same unsuccessful probe three times when the table can accept it without growing or clearing. The caller searches, put calls find again, and insertion walks the collision chain again. Carry the matched or first empty slot across resolution and reprobe only when growth or reset invalidates it. The current source-count check misses both probes inside put.

**L7** (minor): A new key repeats the same unsuccessful probe three times when the table can accept it without growing or clearing. The caller searches, put calls find again, and insertion walks the collision chain again. Carry the matched or first empty slot across resolution and reprobe only when growth or reset invalidates it. The current source-count check misses both probes inside put.
@ -3591,0 +3665,4 @@
/// fills in the rest). At `most` keys the table starts over first. Places are never more than half taken, so a search ends
HitSlot& put(uint64_t key) {
if (HitSlot* s = find(key)) return *s;
if (used >= most) wipe();
Member

L3: The first new key after the table fills clears every slot inside an active recording. For example, if the table starts a recording with 65,536 entries, the next new binding discards even the still-valid entries that later draws in that recording need. Main checks its cap at a recording boundary. Measure the cap-crossing frame and the following frames.

**L3**: The first new key after the table fills clears every slot inside an active recording. For example, if the table starts a recording with 65,536 entries, the next new binding discards even the still-valid entries that later draws in that recording need. Main checks its cap at a recording boundary. Measure the cap-crossing frame and the following frames.
@ -3591,0 +3706,4 @@
double a[7];
for (int i = 0; i < 7; i++) a[i] = (now[i] - last[i]) / frames, last[i] = now[i];
logf("vk: a frame: %.0f texture handles kept as resolved (%.0f of them touched for their submission, %.0f by the whole check), "
"%.0f resolved again (%.0f first met, %.0f whose slot was registered anew, %.0f after the destroy generation moved); "
Member

L9 (minor): The log labels observations by individual tables as moves of the global destroy generation. One table observing a jump from 10 to 13 counts once, and two populated tables can each count the same move. Label the number as table invalidations or report the global generation delta separately.

**L9** (minor): The log labels observations by individual tables as moves of the global destroy generation. One table observing a jump from 10 to 13 counts once, and two populated tables can each count the same move. Label the number as table invalidations or report the global generation delta separately.
@ -3648,0 +3769,4 @@
}
h->epoch = texture_epoch();
}
st_bump(st_flat_hits);
Member

L2: The default path performs diagnostics in every timed lookup while main's lookup counters default off. A texture-heavy frame pays for these updates even when nobody requested the counts. Gate the stats and time base, flat off, and flat on with diagnostics disabled on all three sides. Collect hit breakdowns separately with diagnostics enabled.

**L2**: The default path performs diagnostics in every timed lookup while main's lookup counters default off. A texture-heavy frame pays for these updates even when nobody requested the counts. Gate the stats and time base, flat off, and flat on with diagnostics disabled on all three sides. Collect hit breakdowns separately with diagnostics enabled.
@ -3648,0 +3778,4 @@
else if (h->version != version) st_bump(st_flat_ver);
else st_bump(st_flat_gen);
} else {
static const bool log_hits = env_on("RX_VK_LOG_HITS");
Member

L8 (minor): RX_VK_LOG_HITS=1 no longer produces its documented 200,000-binding diagnostic in the default configuration. Keep that diagnostic available on both paths or explicitly document the replacement and the switch combination needed for the old output.

**L8** (minor): RX_VK_LOG_HITS=1 no longer produces its documented 200,000-binding diagnostic in the default configuration. Keep that diagnostic available on both paths or explicitly document the replacement and the switch combination needed for the old output.
@ -3678,1 +3828,3 @@
handle_hits()[key] = {view, tex, dgen, level, version, texture_epoch(), use == ViewUse::Sample || use == ViewUse::Storage};
if (flat) { // (its place asked for here, not kept from the search above: this is where the table grows or starts over)
HitSlot& h = flat_hits().put(key);
h.view = view, h.tex = tex, h.version = version, h.epoch = texture_epoch(), h.era = era, h.level = level;
Member

L1: A transient vkCreateImageView allocation failure is cached as a valid null result until the slot version or destroy generation changes. A texture that remains registered can keep sampling the dummy after memory recovers, because the handle cache bypasses cached_image_view's next-frame retry. The fallback already has this gap. Preserve negative caching for permanent misses and give transient failures a frame-limited entry or skip caching them in the shared resolution path.

**L1**: A transient vkCreateImageView allocation failure is cached as a valid null result until the slot version or destroy generation changes. A texture that remains registered can keep sampling the dummy after memory recovers, because the handle cache bypasses cached_image_view's next-frame retry. The fallback already has this gap. Preserve negative caching for permanent misses and give transient failures a frame-limited entry or skip caching them in the shared resolution path.
@ -0,0 +238,4 @@
a.cxx = compiler(a.cxx)
src = (ROOT / "gpu" / "vk" / "vk_draw.cpp").read_text(encoding="utf-8")
# ---- how texture_view_of uses it ----
Member

L6: The fixture runs a hand-written copy of the hit and touch logic. The existing executable fixture forces the map branch. A mistake such as clearing a cached storage view just before the hit return can leave both fixtures green. Extend the executable fixture to run the actual flat and map branches with controlled initial switch values. Compare the view, texture, level and touch calls, including a generation bump during resolution.

**L6**: The fixture runs a hand-written copy of the hit and touch logic. The existing executable fixture forces the map branch. A mistake such as clearing a cached storage view just before the hit return can leave both fixtures green. Extend the executable fixture to run the actual flat and map branches with controlled initial switch values. Compare the view, texture, level and touch calls, including a generation bump during resolution.
siantm changed title from WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT, on) to WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT, off by default) 2026-11-21 08:19:38 +00:00
siantm force-pushed perf/vk-tex-hit-flat from 9fd4c4b46e
Some checks failed
PR description / Description follows the template (pull_request_target) Successful in 11s
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
to 76ab28dd4e
Some checks failed
PR description / Description follows the template (pull_request_target) Has been cancelled
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
2026-11-21 08:19:40 +00:00
Compare
Author
Contributor

Thank you for the review (#issuecomment-63405). Pushed 76ab28dd, rebased on main @ b62932a9 (the branch's own commit unchanged by the rebase, git range-diff); test commit 5bed75f2 (its checks fail on the branch's earlier code: job fb-2003-6, as c4f200e3), fix 76ab28dd. The checks ran at c17363c2 on main @ 7c23d2be (job fb-2003-8); b62932a9 adds only pipeline lists under assets/. All checks named below ran in those jobs on this PC; nothing has run in the game.

Default: there is no measurement in play, so RX_VK_TEX_HIT_FLAT is now off by default (kind attempt): unset is main's map. The in-game A/B that could turn it on is in Still to test.

  • L1 (#issuecomment-63395), a transient image-view failure cached: fixed in 76ab28dd in the shared resolution path, both ways: a view refused for want of memory this frame (the texture's view_failed_frame) is not kept, so it is made again from the next frame on as cached_image_view retries it; permanent misses are still kept. tests/test_flat_map.py refuses one view in the real texture_view_of and checks it is resolved again that frame and has a view the next, on the map, the flat table and the std::unordered_map reference.
  • L2 (#issuecomment-63396), counters on every lookup: fixed in 76ab28dd: every count is behind RX_VK_LOG_HITS, both ways, the same counts with the map and the table; off, nothing is counted (test_flat_map.py runs texture_view_of with it unset and set and checks the counts; test_handle_lookup.py checks no count is outside the switch). I kept them relaxed atomics without a locked add rather than plain integers: they cost nothing with the switch off and stay free of a data race should two recorders count at once. The gated three-way timing is pending (Still to test).
  • L3 (#issuecomment-63397), a clear inside a recording: fixed in 76ab28dd as you suggest: at its bound put keeps no new key (resolved and returned uncached) and the others keep serving; the table starts over only at a submission's first recording, where the map's bound is checked (resolved_handles_new_submission). test_tex_hit_flat.py checks it case by case and in its model runs (never started over inside a recording). The cap-crossing frames are not measured (Still to test).
  • L4 (#issuecomment-63398), the largest table kept: fixed in 76ab28dd for the bound: starting over at a submission's start gives the places back (the first growth makes 256 again); below the bound it keeps its size, as the map does. No sustained-low-occupancy shrink. The RAM after a heavy-to-light change is pending (Still to test, with the heavy scene).
  • L5 (#issuecomment-63399), an allocation failure escaping: fixed in 76ab28dd: grow catches it and leaves the table as it was, put returns null and the view is returned uncached, the first places too. test_tex_hit_flat.py refuses the memory (its own operator new) for a first and a later growth.
  • L6 (#issuecomment-63400), a hand-written copy of the hit logic: fixed in 5bed75f2: test_flat_map.py now runs the real texture_view_of with RX_VK_TEX_HIT_FLAT unset, 0 and 1 against the std::unordered_map reference (forced to the map), comparing view, texture, level, every stub call in order (touches included) and the destroy generation, which texture_get now moves inside some resolutions.
  • L7 (#issuecomment-63401), three probes for a new key: fixed in 76ab28dd: seek gives the key's place or the empty place its search ends at, and put takes it unless the table's stamp moved during the resolution (a put, a growth or a start-over). The model run puts another key in one resolution in five, so a stale place is searched again; test_handle_lookup.py checks one seek and one put a lookup.
  • L8 (#issuecomment-63402), the 200,000-binding line: fixed in 76ab28dd: logged both ways (test_flat_map.py checks the table logs it as often as the map); the frame-log line is the table's addition, with RX_VK_LOG_HITS=1. Both rows say so.
  • L9 (#issuecomment-63403), the generation-move label: fixed in 76ab28dd: the figure is now "a thread's table found its places stale ... times a frame", and the comment says it is one count a table, not the generation's moves.
  • L10 (in 63405), the map built on the table's threads: fixed in 76ab28dd: draw_begin_recording calls resolved_handles_new_submission, which keeps the bound of the way in use only; the three fixtures that cut draw_begin_recording stub it, and test_tex_hit_flat.py checks neither table is touched there directly.
  • L11 (#issuecomment-63404), the row and the shared parser: fixed in 76ab28dd (row, description) and 5bed75f2: the switch's fixture has no, empty and spaces among the off values, and checks the setter's result and the value read back.
  • L12 (in 63405), test_flat_map.py's compiler: fixed in 5bed75f2: it uses test_tex_hit_flat.py's lookup (--cxx, CXX, the configured llvm-mingw, then PATH); it ran with no compiler on PATH and found llvm-mingw through LONGSHOT_MINGW. test_tex_hit_flat.py also no longer declares {cxx} to the runner, whose lookup skips the configured llvm-mingw (the same as #2005's L1).
  • L13 (in 63405), the author's runs: pending, for the owner: the full renderer builds on Windows and Linux, the in-game picture with sampled and storage output, and the interleaved runs in Kokiri Forest and a heavy scene on Tier 1 hardware with replay and lookup time, FPS, 1% lows, median and p99, RAM and VRAM. Still to test lists them; the description says plainly that nothing is measured.
Thank you for the review (#issuecomment-63405). Pushed 76ab28dd, rebased on main @ b62932a9 (the branch's own commit unchanged by the rebase, `git range-diff`); test commit 5bed75f2 (its checks fail on the branch's earlier code: job fb-2003-6, as c4f200e3), fix 76ab28dd. The checks ran at c17363c2 on main @ 7c23d2be (job fb-2003-8); b62932a9 adds only pipeline lists under `assets/`. All checks named below ran in those jobs on this PC; nothing has run in the game. **Default:** there is no measurement in play, so `RX_VK_TEX_HIT_FLAT` is now off by default (kind attempt): unset is main's map. The in-game A/B that could turn it on is in Still to test. - **L1** ([#issuecomment-63395](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63395)), a transient image-view failure cached: fixed in 76ab28dd in the shared resolution path, both ways: a view refused for want of memory this frame (the texture's `view_failed_frame`) is not kept, so it is made again from the next frame on as `cached_image_view` retries it; permanent misses are still kept. `tests/test_flat_map.py` refuses one view in the real `texture_view_of` and checks it is resolved again that frame and has a view the next, on the map, the flat table and the std::unordered_map reference. - **L2** ([#issuecomment-63396](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63396)), counters on every lookup: fixed in 76ab28dd: every count is behind `RX_VK_LOG_HITS`, both ways, the same counts with the map and the table; off, nothing is counted (`test_flat_map.py` runs `texture_view_of` with it unset and set and checks the counts; `test_handle_lookup.py` checks no count is outside the switch). I kept them relaxed atomics without a locked add rather than plain integers: they cost nothing with the switch off and stay free of a data race should two recorders count at once. The gated three-way timing is pending (Still to test). - **L3** ([#issuecomment-63397](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63397)), a clear inside a recording: fixed in 76ab28dd as you suggest: at its bound `put` keeps no new key (resolved and returned uncached) and the others keep serving; the table starts over only at a submission's first recording, where the map's bound is checked (`resolved_handles_new_submission`). `test_tex_hit_flat.py` checks it case by case and in its model runs (never started over inside a recording). The cap-crossing frames are not measured (Still to test). - **L4** ([#issuecomment-63398](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63398)), the largest table kept: fixed in 76ab28dd for the bound: starting over at a submission's start gives the places back (the first growth makes 256 again); below the bound it keeps its size, as the map does. No sustained-low-occupancy shrink. The RAM after a heavy-to-light change is pending (Still to test, with the heavy scene). - **L5** ([#issuecomment-63399](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63399)), an allocation failure escaping: fixed in 76ab28dd: `grow` catches it and leaves the table as it was, `put` returns null and the view is returned uncached, the first places too. `test_tex_hit_flat.py` refuses the memory (its own `operator new`) for a first and a later growth. - **L6** ([#issuecomment-63400](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63400)), a hand-written copy of the hit logic: fixed in 5bed75f2: `test_flat_map.py` now runs the real `texture_view_of` with `RX_VK_TEX_HIT_FLAT` unset, 0 and 1 against the std::unordered_map reference (forced to the map), comparing view, texture, level, every stub call in order (touches included) and the destroy generation, which `texture_get` now moves inside some resolutions. - **L7** ([#issuecomment-63401](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63401)), three probes for a new key: fixed in 76ab28dd: `seek` gives the key's place or the empty place its search ends at, and `put` takes it unless the table's stamp moved during the resolution (a put, a growth or a start-over). The model run puts another key in one resolution in five, so a stale place is searched again; `test_handle_lookup.py` checks one seek and one put a lookup. - **L8** ([#issuecomment-63402](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63402)), the 200,000-binding line: fixed in 76ab28dd: logged both ways (`test_flat_map.py` checks the table logs it as often as the map); the frame-log line is the table's addition, with `RX_VK_LOG_HITS=1`. Both rows say so. - **L9** ([#issuecomment-63403](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63403)), the generation-move label: fixed in 76ab28dd: the figure is now "a thread's table found its places stale ... times a frame", and the comment says it is one count a table, not the generation's moves. - **L10** (in 63405), the map built on the table's threads: fixed in 76ab28dd: `draw_begin_recording` calls `resolved_handles_new_submission`, which keeps the bound of the way in use only; the three fixtures that cut `draw_begin_recording` stub it, and `test_tex_hit_flat.py` checks neither table is touched there directly. - **L11** ([#issuecomment-63404](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63404)), the row and the shared parser: fixed in 76ab28dd (row, description) and 5bed75f2: the switch's fixture has `no`, empty and spaces among the off values, and checks the setter's result and the value read back. - **L12** (in 63405), `test_flat_map.py`'s compiler: fixed in 5bed75f2: it uses `test_tex_hit_flat.py`'s lookup (`--cxx`, `CXX`, the configured llvm-mingw, then PATH); it ran with no compiler on PATH and found llvm-mingw through `LONGSHOT_MINGW`. `test_tex_hit_flat.py` also no longer declares `{cxx}` to the runner, whose lookup skips the configured llvm-mingw (the same as #2005's L1). - **L13** (in 63405), the author's runs: pending, for the owner: the full renderer builds on Windows and Linux, the in-game picture with sampled and storage output, and the interleaved runs in Kokiri Forest and a heavy scene on Tier 1 hardware with replay and lookup time, FPS, 1% lows, median and p99, RAM and VRAM. Still to test lists them; the description says plainly that nothing is measured.
Author
Contributor

@Beanstalk This adds RX_VK_TEX_HIT_FLAT, off by default: with RX_VK_TEX_HIT_FLAT=1 the renderer's texture handle lookups for every draw and dispatch go through a new resolved-handle table instead of main's (gpu/vk/vk_draw.cpp); unset, main's way. It has not run in the game on these PCs yet. Please play Kokiri Forest for three minutes after a minute's warm-up, the PR against main on the same PC, on the PR's side with RX_VK_TEX_HIT_FLAT=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash and no validation error; set, frame time p99 equal to unset or better; unset, as main's.

@Beanstalk This adds RX_VK_TEX_HIT_FLAT, off by default: with RX_VK_TEX_HIT_FLAT=1 the renderer's texture handle lookups for every draw and dispatch go through a new resolved-handle table instead of main's (gpu/vk/vk_draw.cpp); unset, main's way. It has not run in the game on these PCs yet. Please play Kokiri Forest for three minutes after a minute's warm-up, the PR against main on the same PC, on the PR's side with RX_VK_TEX_HIT_FLAT=1 and with it unset, with a picture compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture, no crash and no validation error; set, frame time p99 equal to unset or better; unset, as main's.
Member

@siantm only members of BigBeans can start the farm.

One of them can approve this request by reacting 👍 to it or to this comment. This request was for 76ab28d, and the PR has changed since (09f185c), so a 👍 no longer approves it. Comment @Beanstalk again to ask for the new commit.

@siantm only members of `BigBeans` can start the farm. ~~One of them can approve this request by reacting 👍 to it or to this comment.~~ This request was for `76ab28d`, and the PR has changed since (`09f185c`), so a 👍 no longer approves it. Comment `@Beanstalk` again to ask for the new commit.
dyst left a comment

Verdict: Request changes. The code now answers every BeanBot point and I found no bug in the table. But the switch was turned off because it is unmeasured, which standards rule out ("ships at that value from the branch's first push ... never off just because it is new or unmeasured"). As pushed, testers, the farm and the PR's own runs play main's map unless they set it by hand.

For a player it is meant to make every texture and storage-image binding a cheaper lookup (one 40-byte place in a flat table instead of a FlatMap entry with its own destroy generation). That is a CPU gain in descriptor building, not measured yet. Unset, it is main's way plus one real fix both ways: a view refused for want of memory is no longer kept as the dummy.

Reviewed: 76ab28dd against b62932a9 (the merge base with main; it merges cleanly into current main). I read in full: gpu/vk/vk_draw.cpp (HitSlot/HitTable, tex_hit_flat, resolved_handles_new_submission, the counters, tex_hits_report, all of texture_view_of, draw_begin_recording's change), the switches.def rows, the three tests/*_test.cpp stubs, tests/test_tex_hit_flat.py, and the test_flat_map.py and test_handle_lookup.py diffs. Also read: cached_image_view and texture_view in vk_texture.cpp (for L1) and env_value_off in longshot_env.h (for L11). I checked each point against BeanBot's review at 9fd4c4b4, which is still reachable through #2058. Nothing run (a code review).
Fixed in this review: nothing.
Checked and fine:

  • L1: again holds back from both ways only a view cached_image_view refused this frame (view_failed_frame == frame_no). Permanent misses are still kept. texture_view passes the null through rather than swapping in a dummy. test_flat_map.py's refused case fails if the !again guard is undone, because the second call would hit with no texture_of in the trace.
  • L2: every st_bump sits behind log_hits (the && short-circuits). Off, nothing is counted in either way.
  • L3: put refuses a new key at most and never wipes. A start-over happens only in new_submission, from draw_begin_recording.
  • L4: a start-over at the bound swaps the vector away, so the first growth makes 256 places again.
  • L5: grow is noexcept and catches inside, so the old array is untouched on failure, and put returns null. The fixture's operator new checks both the first growth and a later one.
  • L6: test_flat_map.py now compiles the real texture_view_of with the table and compares view, texture, level, the stub trace and the destroy generation against the unordered_map reference, with generation moves inside a resolution.
  • L7: one seek before the resolution. put searches again only when stamp moved (a put, a growth or a wipe). An era move without a wrap changes no place, so leaving stamp alone there is right.
  • L8: the 200,000-binding line is logged both ways.
  • L9: the stale-table label is fixed.
  • L10: the map is touched only when it is the way in use.
  • L11: the row matches env_value_off (trimmed, any case; empty is off).
  • L12: compiler lookup.
  • The era is taken before the resolution and stored as such. A generation that moves during texture_get therefore leaves the new place stale, as the map's stored dgen does. After a wrap, an outer resolution's old era cannot be met as current for another 2^32 moves.
  • sampling worked out from use equals what the map stores, because use is in the key. sizeof(HitSlot) == 40. The table holds at most 65,536 keys in 131,072 places (about 5 MB a thread).
  • The tests compile and run fixtures in temporary folders, read source and set env vars only. They download nothing and reach nothing outside the repository.

Blocking (to change before merge)

  1. gpu/vk/switches.def:698: RX_VK_TEX_HIT_FLAT ships attempt/off "until a measurement in play chooses its default". Standards say a switch ships at its intended default from the first push, WIP or not, and goes off only if measurements go against it. (BeanBot's L2 was about the counters; it called the on default fine for WIP evidence.) The farm, testers and your own A/B should run the branch as it would merge. Fix: on by default again, kind kill (0 gives main's map), the reader env_on_or(..., 1), and update the row, test_tex_hit_flat.py's attempt check and default, the description and the @Beanstalk request. If the in-game A/B goes against it, turn it off or drop it then, and say which.

Suggestions (the author may take or leave)

  • gpu/vk/vk_draw.cpp:3872: again reads texture_frame_no() after the resolution. If frame_no moves on another thread between cached_image_view's failure and this line, the refused view is kept as null until its slot or the generation moves, which is the L1 gap in a narrow window. Reading the frame once before the resolution and testing tex->view_failed_frame >= that closes it.
  • The L1 fix changes main's path for everyone, a second (small) topic beside the table. It is worth one line in Summary or Risks as a behaviour fix in its own right (it is already in Risks), or a PR of its own if a reviewer asks.
  • Threads that resolve handles but never run draw_begin_recording (if an upscaler or present-side call ever runs off the recording thread) never start their table over. At 65,536 keys they would stop keeping new ones for good, where the map grows. This only costs time, and a handful of keys will never reach the bound, but a comment at resolved_handles_new_submission would say so.

Questions

  • None that change the verdict.

Testing: the author's checks on Windows (llvm-mingw) pass: test_tex_hit_flat.py, test_flat_map.py, test_handle_lookup.py, test_switch_table.py. The test commit fails on the earlier code, and vk_draw.cpp compiles with the game's command. Missing, and holding the merge: any run in the game, including the author's own on the RTX 4060 (Kokiri and a heavy/streaming scene, three ways). Also missing: a full Windows and Linux build, Tier 1 hardware, and a measurement. CI is pending. The @Beanstalk request should follow the default change. When it is re-asked, it should add Windows AMD and a heavy or streaming scene (the light Kokiri walk never reaches the 65,536-key bound or a start-over). Its criteria should be the replay's CPU time (RX_VK_PROF_FINE=1, the textures line) and RAM beside p99: a CPU-side lookup saving rarely moves p99 frame time on a GPU-bound or capped run.
Overlaps and merge order:

  • #2058 (prefetch into this table) stacks on this PR's old head 9fd4c4b4, before every fix here. It needs rebasing onto 76ab28dd (or later), and its prefetch works only with the table on. This one goes first.
  • #2055 changes texture_view_of's signature (version passed in). That is a textual conflict at the function's head, compatible in meaning; whichever merges second rebases.
  • #2059, #2049, #2048 and #2047 edit the three tests/*_test.cpp stubs next to the handle_hits stub line this PR replaces. That may be a small textual conflict there; they don't touch texture_view_of.
  • #2057, #2056, #2046 and #2045 don't overlap.
  • switches.def is a row conflict with most open PRs.
**Verdict: Request changes.** The code now answers every BeanBot point and I found no bug in the table. But the switch was turned off because it is unmeasured, which [standards](https://git.magicbean.dev/MagicBeanDev/Longshot/src/branch/main/docs/dev/standards.md#switches) rule out ("ships at that value from the branch's first push ... never off just because it is new or unmeasured"). As pushed, testers, the farm and the PR's own runs play main's map unless they set it by hand. For a player it is meant to make every texture and storage-image binding a cheaper lookup (one 40-byte place in a flat table instead of a FlatMap entry with its own destroy generation). That is a CPU gain in descriptor building, not measured yet. Unset, it is main's way plus one real fix both ways: a view refused for want of memory is no longer kept as the dummy. **Reviewed:** 76ab28dd against b62932a9 (the merge base with main; it merges cleanly into current main). I read in full: `gpu/vk/vk_draw.cpp` (HitSlot/HitTable, `tex_hit_flat`, `resolved_handles_new_submission`, the counters, `tex_hits_report`, all of `texture_view_of`, `draw_begin_recording`'s change), the `switches.def` rows, the three `tests/*_test.cpp` stubs, `tests/test_tex_hit_flat.py`, and the `test_flat_map.py` and `test_handle_lookup.py` diffs. Also read: `cached_image_view` and `texture_view` in `vk_texture.cpp` (for L1) and `env_value_off` in `longshot_env.h` (for L11). I checked each point against BeanBot's review at 9fd4c4b4, which is still reachable through https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2058. Nothing run (a code review). **Fixed in this review:** nothing. **Checked and fine:** - L1: `again` holds back from both ways only a view `cached_image_view` refused this frame (`view_failed_frame == frame_no`). Permanent misses are still kept. `texture_view` passes the null through rather than swapping in a dummy. `test_flat_map.py`'s `refused` case fails if the `!again` guard is undone, because the second call would hit with no `texture_of` in the trace. - L2: every `st_bump` sits behind `log_hits` (the `&&` short-circuits). Off, nothing is counted in either way. - L3: `put` refuses a new key at `most` and never wipes. A start-over happens only in `new_submission`, from `draw_begin_recording`. - L4: a start-over at the bound swaps the vector away, so the first growth makes 256 places again. - L5: `grow` is `noexcept` and catches inside, so the old array is untouched on failure, and `put` returns null. The fixture's `operator new` checks both the first growth and a later one. - L6: `test_flat_map.py` now compiles the real `texture_view_of` with the table and compares view, texture, level, the stub trace and the destroy generation against the unordered_map reference, with generation moves inside a resolution. - L7: one `seek` before the resolution. `put` searches again only when `stamp` moved (a put, a growth or a wipe). An era move without a wrap changes no place, so leaving `stamp` alone there is right. - L8: the 200,000-binding line is logged both ways. - L9: the stale-table label is fixed. - L10: the map is touched only when it is the way in use. - L11: the row matches `env_value_off` (trimmed, any case; empty is off). - L12: compiler lookup. - The era is taken before the resolution and stored as such. A generation that moves during `texture_get` therefore leaves the new place stale, as the map's stored `dgen` does. After a wrap, an outer resolution's old era cannot be met as current for another 2^32 moves. - `sampling` worked out from `use` equals what the map stores, because `use` is in the key. `sizeof(HitSlot) == 40`. The table holds at most 65,536 keys in 131,072 places (about 5 MB a thread). - The tests compile and run fixtures in temporary folders, read source and set env vars only. They download nothing and reach nothing outside the repository. **Blocking** (to change before merge) 1. `gpu/vk/switches.def:698`: `RX_VK_TEX_HIT_FLAT` ships `attempt`/off "until a measurement in play chooses its default". Standards say a switch ships at its intended default from the first push, WIP or not, and goes off only if measurements go against it. (BeanBot's L2 was about the counters; it called the on default fine for WIP evidence.) The farm, testers and your own A/B should run the branch as it would merge. Fix: on by default again, kind `kill` (`0` gives main's map), the reader `env_on_or(..., 1)`, and update the row, `test_tex_hit_flat.py`'s `attempt` check and default, the description and the @Beanstalk request. If the in-game A/B goes against it, turn it off or drop it then, and say which. **Suggestions** (the author may take or leave) - `gpu/vk/vk_draw.cpp:3872`: `again` reads `texture_frame_no()` after the resolution. If `frame_no` moves on another thread between `cached_image_view`'s failure and this line, the refused view is kept as null until its slot or the generation moves, which is the L1 gap in a narrow window. Reading the frame once before the resolution and testing `tex->view_failed_frame >= that` closes it. - The L1 fix changes main's path for everyone, a second (small) topic beside the table. It is worth one line in Summary or Risks as a behaviour fix in its own right (it is already in Risks), or a PR of its own if a reviewer asks. - Threads that resolve handles but never run `draw_begin_recording` (if an upscaler or present-side call ever runs off the recording thread) never start their table over. At 65,536 keys they would stop keeping new ones for good, where the map grows. This only costs time, and a handful of keys will never reach the bound, but a comment at `resolved_handles_new_submission` would say so. **Questions** - None that change the verdict. **Testing:** the author's checks on Windows (llvm-mingw) pass: `test_tex_hit_flat.py`, `test_flat_map.py`, `test_handle_lookup.py`, `test_switch_table.py`. The test commit fails on the earlier code, and `vk_draw.cpp` compiles with the game's command. Missing, and holding the merge: any run in the game, including the author's own on the RTX 4060 (Kokiri and a heavy/streaming scene, three ways). Also missing: a full Windows and Linux build, Tier 1 hardware, and a measurement. CI is pending. The @Beanstalk request should follow the default change. When it is re-asked, it should add Windows AMD and a heavy or streaming scene (the light Kokiri walk never reaches the 65,536-key bound or a start-over). Its criteria should be the replay's CPU time (`RX_VK_PROF_FINE=1`, the textures line) and RAM beside p99: a CPU-side lookup saving rarely moves p99 frame time on a GPU-bound or capped run. **Overlaps and merge order:** - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2058 (prefetch into this table) stacks on this PR's old head 9fd4c4b4, before every fix here. It needs rebasing onto 76ab28dd (or later), and its prefetch works only with the table on. This one goes first. - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2055 changes `texture_view_of`'s signature (version passed in). That is a textual conflict at the function's head, compatible in meaning; whichever merges second rebases. - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2059, https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2049, https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2048 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2047 edit the three `tests/*_test.cpp` stubs next to the `handle_hits` stub line this PR replaces. That may be a small textual conflict there; they don't touch `texture_view_of`. - https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2057, https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2056, https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2046 and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2045 don't overlap. - `switches.def` is a row conflict with most open PRs.
@ -695,6 +695,7 @@ SW(RX_VK_TEX_AHEAD_MS, tune, float, "12 ms", "<n>: the time in ms a light frame
SW(RX_VK_TEX_CAPTURE, kill, bool, "on, when the capture is on", "0 keeps the storage of textures uploaded from guest memory out of the submit-time capture.")
SW(RX_VK_TEX_CAPTURE_MAX_MB, tune, int, "2048 MB, in effect any size", "Sets the largest uploaded texture whose storage joins the submit-time memory capture; it was 8 MB before.")
SW(RX_VK_TEX_CAPTURE_OFF_FILE, diag, string, "not set: uploads read the captured copies", "A path: while that file exists, texture uploads read live guest memory as before, for A/B runs in one session.")
SW(RX_VK_TEX_HIT_FLAT, attempt, bool, "off: texture_view_of keeps the resolved texture handles in the handle_hits map", "1 (any value but an empty one, 0, false, off or no, in any case, spaces around it not counted): a flat table of its own, the destroy generation kept once for the table as an era; a thread's table starts over at 65536 keys at a submission's start, its places given back, and keeps no new key past them until then. Not measured in play. Read once, at its first use (HOS_AB cannot alternate it). The views found are the same either way (tests/test_flat_map.py runs texture_view_of both ways); RX_VK_LOG_HITS=1 counts its lookups.")
Member

Blocking: this ships off because it is unmeasured, which standards rule out (a switch ships at its intended default from the first push; off only if measurements go against it). On by default again, kind kill, the reader env_on_or(..., 1), and the test, description and @Beanstalk request updated to match.

Blocking: this ships off because it is unmeasured, which standards rule out (a switch ships at its intended default from the first push; off only if measurements go against it). On by default again, kind kill, the reader env_on_or(..., 1), and the test, description and @Beanstalk request updated to match.
@ -3680,1 +3870,3 @@
handle_hits()[key] = {view, tex, dgen, level, version, texture_epoch(), use == ViewUse::Sample || use == ViewUse::Storage};
// (a view not made for want of memory this frame (cached_image_view: the texture's view_failed_frame) is made again from
// the next frame on: not kept, either way, or the dummy would stand for it until its slot or the destroy generation moved)
const bool again = tex && !view && tex->view_failed_frame == texture_frame_no();
Member

Suggestion: texture_frame_no() is read after the resolution. If frame_no moves between cached_image_view's failure and here, the refused view is kept as null again (L1 in a narrow window). Read the frame once before the resolution and test view_failed_frame >= it.

Suggestion: texture_frame_no() is read after the resolution. If frame_no moves between cached_image_view's failure and here, the refused view is kept as null again (L1 in a narrow window). Read the frame once before the resolution and test view_failed_frame >= it.
siantm force-pushed perf/vk-tex-hit-flat from 76ab28dd4e
Some checks failed
PR description / Description follows the template (pull_request_target) Has been cancelled
beanstalk/approval waiting for a BigBean's 👍 on the request
Website / Website on Cloudflare (pull_request_target) Has been skipped
CI / Conventional Commit title (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been cancelled
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been cancelled
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been cancelled
CI / Workflow lint (actionlint) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
Guide screenshots / Guide images and local UI source review (pull_request) Has been cancelled
Third-party parts / As their notes say (pull_request) Has been cancelled
Third-party parts / The same as upstream (pull_request) Has been cancelled
Website / Website on Cloudflare (pull_request) Has been cancelled
to 09f185c90f
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) 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 4s
beanstalk/approval waiting for a BigBean's 👍 on the request
2026-11-21 10:37:38 +00:00
Compare
Author
Contributor

@Beanstalk This makes the renderer's texture binding lookups for every draw and dispatch go through a flat resolved-handle table (gpu/vk/vk_draw.cpp), on by default; RX_VK_TEX_HIT_FLAT=0 turns it off (main's map). This head is on main 9dd41326: please compare with main at that merge base. Please play Kokiri Forest for two minutes, then Hyrule Field galloping into Kakariko Village (a heavy, streaming scene), with RX_VK_PROF_FINE=1 on both sides, the PR against main on the same PC, on the PR's side with the switch unset and with RX_VK_TEX_HIT_FLAT=0, with a picture in each scene compared with main's, on Windows with AMD, Linux with NVIDIA, Linux with AMD (RADV) and the Steam Deck. The same picture, no crash or validation error; please report the replay CPU time from the log's textures line and RAM beside frame time p99; unset, p99 equal to main's or better and to the switch off.

@Beanstalk This makes the renderer's texture binding lookups for every draw and dispatch go through a flat resolved-handle table (gpu/vk/vk_draw.cpp), on by default; RX_VK_TEX_HIT_FLAT=0 turns it off (main's map). This head is on main 9dd41326: please compare with main at that merge base. Please play Kokiri Forest for two minutes, then Hyrule Field galloping into Kakariko Village (a heavy, streaming scene), with RX_VK_PROF_FINE=1 on both sides, the PR against main on the same PC, on the PR's side with the switch unset and with RX_VK_TEX_HIT_FLAT=0, with a picture in each scene compared with main's, on Windows with AMD, Linux with NVIDIA, Linux with AMD (RADV) and the Steam Deck. The same picture, no crash or validation error; please report the replay CPU time from the log's textures line and RAM beside frame time p99; unset, p99 equal to main's or better and to the switch off.
Member

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

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
siantm changed title from WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT, off by default) to WIP: perf(vk): resolved texture handles in a flat table by era (RX_VK_TEX_HIT_FLAT) 2026-11-21 10:48:50 +00:00
Author
Contributor

Thank you for the review (#issuecomment-65681). Pushed 09f185c9, rebased on main @ 9dd41326 (the branch's earlier commits unchanged by the rebase, git range-diff): test commit ddfa3fda, fix 429ae236, default 09f185c9. The checks named below ran in job dyl-2003 of this PC's queue (Windows 11, llvm-mingw clang 23): the PR's own at the head and at the test commit, and vk_draw.cpp compiled with the game build's command; the --changed checks and their failures on main are in job dyh-2003, queued, and the description will give them. Nothing has run in the game.

  • Blocking 1 (#issuecomment-65679, switches.def:698): you are right. RX_VK_TEX_HIT_FLAT is on by default again, restored per docs/dev/standards.md (Switches), in 09f185c9: kind kill, the reader env_on_or(..., 1), =0 (or empty, false, off, no) gives main's map; the row, the log line and RX_VK_LOG_HITS's row match. test_tex_hit_flat.py checks the kill row and unset as on; test_flat_map.py runs unset as the table (ddfa3fda). Still to test now plans =0 against unset, with the replay's CPU time and RAM beside p99 and a heavy or streaming scene; if that A/B goes against it the switch goes off or the change is dropped, and the description will say which. The farm request is made again for this head (#issuecomment-65983), with the default on, Windows AMD, Hyrule Field into Kakariko Village and the replay's CPU time and RAM beside p99.
  • vk_draw.cpp:3872 (#issuecomment-65680): taken. texture_view_of now reads the frame once before the resolution and holds back a refused view when view_failed_frame >= that frame (429ae236). test_flat_map.py (ddfa3fda) has the refusal move the frame on before texture_view_of looks, as another thread's present can, and checks the next call resolves it again and gets its view, on the map, the table and the reference. At the test commit it fails with the earlier code (std::unordered_map: a view refused as the frame moved on was kept); at the head it passes.
  • The L1 fix as a topic of its own: kept in this PR; Summary now opens its second paragraph by calling it a behaviour fix of its own, both ways, beside Risks. If a reviewer asks for it apart, I'll split it out.
  • Threads that never run draw_begin_recording: the comment at resolved_handles_new_submission now says such a thread never starts its table over and, at the bound, keeps no new key for good (each resolved again, a cost in time only) where the map grows on (09f185c9). No code change.
  • Overlaps: #2058 needs rebasing onto 09f185c9; its owner has the new head. #2055 and the tests/*_test.cpp stub lines: whichever merges second rebases.
Thank you for the review (#issuecomment-65681). Pushed 09f185c9, rebased on main @ 9dd41326 (the branch's earlier commits unchanged by the rebase, `git range-diff`): test commit ddfa3fda, fix 429ae236, default 09f185c9. The checks named below ran in job `dyl-2003` of this PC's queue (Windows 11, llvm-mingw clang 23): the PR's own at the head and at the test commit, and `vk_draw.cpp` compiled with the game build's command; the `--changed` checks and their failures on main are in job `dyh-2003`, queued, and the description will give them. Nothing has run in the game. - **Blocking 1** ([#issuecomment-65679](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-65679), `switches.def:698`): you are right. `RX_VK_TEX_HIT_FLAT` is on by default again, restored per docs/dev/standards.md (Switches), in 09f185c9: kind `kill`, the reader `env_on_or(..., 1)`, `=0` (or empty, `false`, `off`, `no`) gives main's map; the row, the log line and `RX_VK_LOG_HITS`'s row match. `test_tex_hit_flat.py` checks the `kill` row and unset as on; `test_flat_map.py` runs unset as the table (ddfa3fda). Still to test now plans `=0` against unset, with the replay's CPU time and RAM beside p99 and a heavy or streaming scene; if that A/B goes against it the switch goes off or the change is dropped, and the description will say which. The farm request is made again for this head ([#issuecomment-65983](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-65983)), with the default on, Windows AMD, Hyrule Field into Kakariko Village and the replay's CPU time and RAM beside p99. - **`vk_draw.cpp:3872`** ([#issuecomment-65680](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-65680)): taken. `texture_view_of` now reads the frame once before the resolution and holds back a refused view when `view_failed_frame >= that frame` (429ae236). `test_flat_map.py` (ddfa3fda) has the refusal move the frame on before `texture_view_of` looks, as another thread's present can, and checks the next call resolves it again and gets its view, on the map, the table and the reference. At the test commit it fails with the earlier code (`std::unordered_map: a view refused as the frame moved on was kept`); at the head it passes. - **The L1 fix as a topic of its own**: kept in this PR; Summary now opens its second paragraph by calling it a behaviour fix of its own, both ways, beside Risks. If a reviewer asks for it apart, I'll split it out. - **Threads that never run `draw_begin_recording`**: the comment at `resolved_handles_new_submission` now says such a thread never starts its table over and, at the bound, keeps no new key for good (each resolved again, a cost in time only) where the map grows on (09f185c9). No code change. - **Overlaps**: #2058 needs rebasing onto 09f185c9; its owner has the new head. #2055 and the `tests/*_test.cpp` stub lines: whichever merges second rebases.
Author
Contributor

Description: Risks now says that this conflicts with #1232 in texture_view_of (gpu/vk/vk_draw.cpp), the overlap BeanBot pointed to (#issuecomment-63304), and that #1232 goes first, this one rebasing onto it. No push.

Description: Risks now says that this conflicts with #1232 in `texture_view_of` (`gpu/vk/vk_draw.cpp`), the overlap BeanBot pointed to ([#issuecomment-63304](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2003#issuecomment-63304)), and that #1232 goes first, this one rebasing onto it. No push.
Author
Contributor

@Beanstalk One correction to my request 65983 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.

@Beanstalk One correction to my request 65983 above, for its picture point: please take each picture 5 s (300 frames at 60 fps) after the first frame whose picture is not a single uniform colour, with no input in between, and take the main-against-itself picture from the same point. A picture taken during the load's fade-in from black is not comparable: run 70269 on #2156 caught the fade in 3 of 4 starts.
Member

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

@siantm only members of `BigBeans` can start the farm. One of them can approve this request by reacting 👍 to it or to this comment.
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) 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 4s
beanstalk/approval waiting for a BigBean's 👍 on the request
This pull request is marked as a work in progress.
Some workflows are waiting to be reviewed.
This branch is out-of-date with the base branch
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/vk-tex-hit-flat:siantm-perf/vk-tex-hit-flat'
git switch 'siantm-perf/vk-tex-hit-flat'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 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!2003
No description provided.