WIP: perf(vk): a texture binding's slot version read once and handed to the fingerprint and the view #2055

Draft
siantm wants to merge 1 commit from siantm/Longshot:perf/vk-slot-version-once into main
Contributor

Summary

Every texture and storage-image binding of a descriptor build (build_descriptors, gpu/vk/vk_draw.cpp) asked gpu/vk/vk_bank.cpp for its texture slot's version twice: once for the Descriptor reuse fingerprint (desc_fp_note) and once more at the top of texture_view_of. This reads it once a binding and hands the value to both, so both also see the same version. texture_view_of and desc_fp_note keep their forms without the version (the upscalers' and the movies' callers), which read it as before. The descriptors and the fingerprint are the same; the result expected is a little less work for the replay thread at every textured draw.

No switch: the same descriptors either way; a revert gives back main's code.

From c0b017ac on exp/x86-asm-sync.

Read first: the texture and image loops of build_descriptors, texture_view_of and desc_fp_note in gpu/vk/vk_draw.cpp.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head f854c8f9 on main @ 75317e1f. Every check ran through tests/run_all.py --strict --exact in build jobs of the PC's job queue, in a hidden console (log t-dc3-vk-slot-version):

  • Its own: tests/test_slot_version_once.py (new: cuts desc_fp_note's two forms and runs them with a counting texture_slot_version, and checks the loops read the version once and hand it to both): pass.
  • The 161 checks that read a file this change touches (--changed 75317e1f; its own are among them): 146 passed, 15 failed. Failed: tests/test_sampler_admission.py, tests/test_fsr_uniform_ownership.py, tests/test_draw_stream_visibility.py, tests/test_pipeline_play_cache.py, tests/test_device_lost_exit.py, tests/test_draw_binds.py, tests/test_dev_packs.py, tests/test_frame_overlap.py, tests/test_linux_pressure.py, tests/test_mesh_conv.py, tests/test_prepare_cache_save.py, tests/test_recorder_own_idle.py, tests/test_upscaler_rows.py, tests/test_vk_occlusion_queries.py: each fails on main @ 75317e1f too (the same checks on main in the same queue batch, log t-dc3-base). tests/test_recording_admission.py fails on main @ 75317e1f too, now and then: its "worker slot ownership" case failed on main in 7 of 10 runs made alternately with this branch's (logs t-dc5-base-ra-*), with the same message.

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 @ 75317e1f against this PR, each warmed a minute in the scene first, then interleaved (main, this PR, this PR, main), two runs each, expecting the same picture (no wrong, missing or flickering texture) and the replay's time a frame the same as or lower than main's (by hand)
  • Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main against this PR, warmed, in ABBA order, expecting the same picture every way and no crash or validation error (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest a minute, main against this PR, ABBA, the same picture)
  • Linux (any GPU): build the renderer and run tests/test_slot_version_once.py with --cxx g++ and --cxx clang++, expecting PASS (by hand)

Measurements

Verdict: with the fingerprint on (Descriptor reuse) a binding takes 1.14-1.52x less time (1.7-4.2 ns); with it off, 1.10-1.13x in the baseline build; with -march=native 1.08x for handle tables and no gain for distinct handles (0.98x, 0.2 ns slower). The view's lookup is a stand-in: only the version reads' cost is measured here. A micro-benchmark on authored input; not measured in play.

Micro-benchmark (vk_slot_version_bench.py: a script on this PC, not in this PR): desc_fp_note cut out of vk_draw.cpp at both commits and texture_slot_version out of vk_bank.cpp, compiled in a file of its own (a call a read, as in the build); texture_view_of is a stand-in kept out of line (its old form reads the version itself, its new form is given it), then an authored table of hits; the texture binding loop as each side has it; 4,096 bindings a repetition, slots under 8,192; three rounds run alone in this PC's job queue (2026-11-22, 01:21-01:23 UTC; log bench-vk-walks.log), the builder's llvm-mingw clang 23.1.5 at -O2 for baseline x86-64 and at -O2 -march=native (this PC's i7-9700, as the game is built here), 301 repetitions a case, old and new taking turns on the same authored inputs, their results equal at every repetition. Each cell: ns per binding, the median of the three rounds' medians, in parentheses the lowest and highest of them; Δ: old over new (above 1, this PR is quicker).

Case (input; build) Before: main @ 75317e1f After: this PR @ f854c8f9 Δ (old/new)
fp-on-distinct: fingerprint on (Descriptor reuse), distinct handles; x86-64 baseline 14.26 ns (14.16-14.40) 10.67 ns (10.67-10.86) 1.34x
fp-on-distinct: fingerprint on (Descriptor reuse), distinct handles; -march=native 13.57 ns (13.48-13.60) 11.91 ns (11.72-11.99) 1.14x
fp-on-table-repeats: on, handle tables with repeated (half) and 0 (an eighth) entries; x86-64 baseline 12.35 ns (12.33-12.50) 8.11 ns (8.11-8.23) 1.52x
fp-on-table-repeats: on, handle tables with repeated (half) and 0 (an eighth) entries; -march=native 11.91 ns (11.89-11.96) 8.96 ns (8.96-8.98) 1.33x
fp-off-distinct: fingerprint off, distinct handles; x86-64 baseline 11.08 ns (10.99-11.13) 9.79 ns (9.77-9.84) 1.13x
fp-off-distinct: fingerprint off, distinct handles; -march=native 9.81 ns (9.77-9.91) 9.98 ns (9.91-10.08) 0.98x
fp-off-table-repeats: off, repeated and 0 entries; x86-64 baseline 8.32 ns (8.28-8.32) 7.54 ns (7.52-7.57) 1.10x
fp-off-table-repeats: off, repeated and 0 entries; -march=native 7.93 ns (7.91-7.98) 7.32 ns (7.30-7.35) 1.08x

Risks

A texture resolved against a slot version read earlier than before (once, before the fingerprint, instead of again inside texture_view_of): a slot registered again between the two reads now gives a fingerprint and a view of the same, older version, which the next build sees as changed and builds again. What could show is a wrong texture for a draw; a revert is enough (no switch). The renderer is compiled again after updating, as for any renderer change; no cache or setting changes.

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

  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not yet: only the checks' cuts compiled (Testing).
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
## Summary Every texture and storage-image binding of a descriptor build (`build_descriptors`, `gpu/vk/vk_draw.cpp`) asked `gpu/vk/vk_bank.cpp` for its texture slot's version twice: once for the Descriptor reuse fingerprint (`desc_fp_note`) and once more at the top of `texture_view_of`. This reads it once a binding and hands the value to both, so both also see the same version. `texture_view_of` and `desc_fp_note` keep their forms without the version (the upscalers' and the movies' callers), which read it as before. The descriptors and the fingerprint are the same; the result expected is a little less work for the replay thread at every textured draw. No switch: the same descriptors either way; a revert gives back main's code. From c0b017ac on `exp/x86-asm-sync`. Read first: the texture and image loops of `build_descriptors`, `texture_view_of` and `desc_fp_note` in `gpu/vk/vk_draw.cpp`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head f854c8f9 on main @ 75317e1f. Every check ran through `tests/run_all.py --strict --exact` in build jobs of the PC's job queue, in a hidden console (log `t-dc3-vk-slot-version`): - Its own: `tests/test_slot_version_once.py` (new: cuts `desc_fp_note`'s two forms and runs them with a counting `texture_slot_version`, and checks the loops read the version once and hand it to both): pass. - The 161 checks that read a file this change touches (`--changed 75317e1f`; its own are among them): 146 passed, 15 failed. Failed: `tests/test_sampler_admission.py`, `tests/test_fsr_uniform_ownership.py`, `tests/test_draw_stream_visibility.py`, `tests/test_pipeline_play_cache.py`, `tests/test_device_lost_exit.py`, `tests/test_draw_binds.py`, `tests/test_dev_packs.py`, `tests/test_frame_overlap.py`, `tests/test_linux_pressure.py`, `tests/test_mesh_conv.py`, `tests/test_prepare_cache_save.py`, `tests/test_recorder_own_idle.py`, `tests/test_upscaler_rows.py`, `tests/test_vk_occlusion_queries.py`: each fails on main @ 75317e1f too (the same checks on main in the same queue batch, log `t-dc3-base`). `tests/test_recording_admission.py` fails on main @ 75317e1f too, now and then: its "worker slot ownership" case failed on main in 7 of 10 runs made alternately with this branch's (logs `t-dc5-base-ra-*`), with the same message. 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 @ 75317e1f against this PR, each warmed a minute in the scene first, then interleaved (main, this PR, this PR, main), two runs each, expecting the same picture (no wrong, missing or flickering texture) and the replay's time a frame the same as or lower than main's (by hand) - Linux NVIDIA and AMD, Windows AMD and Intel, Steam Deck: start in Kokiri Forest from the scene's save, play a minute (walking, turning the camera), main against this PR, warmed, in ABBA order, expecting the same picture every way and no crash or validation error (@Beanstalk linux+nvidia, linux+amd, windows+amd, windows+intel, steamdeck: Kokiri Forest a minute, main against this PR, ABBA, the same picture) - Linux (any GPU): build the renderer and run `tests/test_slot_version_once.py` with `--cxx g++` and `--cxx clang++`, expecting PASS (by hand) ## Measurements **Verdict:** with the fingerprint on (Descriptor reuse) a binding takes 1.14-1.52x less time (1.7-4.2 ns); with it off, 1.10-1.13x in the baseline build; with -march=native 1.08x for handle tables and no gain for distinct handles (0.98x, 0.2 ns slower). The view's lookup is a stand-in: only the version reads' cost is measured here. A micro-benchmark on authored input; not measured in play. Micro-benchmark (`vk_slot_version_bench.py`: a script on this PC, not in this PR): `desc_fp_note` cut out of `vk_draw.cpp` at both commits and `texture_slot_version` out of `vk_bank.cpp`, compiled in a file of its own (a call a read, as in the build); `texture_view_of` is a stand-in kept out of line (its old form reads the version itself, its new form is given it), then an authored table of hits; the texture binding loop as each side has it; 4,096 bindings a repetition, slots under 8,192; three rounds run alone in this PC's job queue (2026-11-22, 01:21-01:23 UTC; log `bench-vk-walks.log`), the builder's llvm-mingw clang 23.1.5 at -O2 for baseline x86-64 and at -O2 -march=native (this PC's i7-9700, as the game is built here), 301 repetitions a case, old and new taking turns on the same authored inputs, their results equal at every repetition. Each cell: ns per binding, the median of the three rounds' medians, in parentheses the lowest and highest of them; Δ: old over new (above 1, this PR is quicker). | Case (input; build) | Before: main @ 75317e1f | After: this PR @ f854c8f9 | Δ (old/new) | |---|---|---|---| | fp-on-distinct: fingerprint on (Descriptor reuse), distinct handles; x86-64 baseline | 14.26 ns (14.16-14.40) | 10.67 ns (10.67-10.86) | 1.34x | | fp-on-distinct: fingerprint on (Descriptor reuse), distinct handles; -march=native | 13.57 ns (13.48-13.60) | 11.91 ns (11.72-11.99) | 1.14x | | fp-on-table-repeats: on, handle tables with repeated (half) and 0 (an eighth) entries; x86-64 baseline | 12.35 ns (12.33-12.50) | 8.11 ns (8.11-8.23) | 1.52x | | fp-on-table-repeats: on, handle tables with repeated (half) and 0 (an eighth) entries; -march=native | 11.91 ns (11.89-11.96) | 8.96 ns (8.96-8.98) | 1.33x | | fp-off-distinct: fingerprint off, distinct handles; x86-64 baseline | 11.08 ns (10.99-11.13) | 9.79 ns (9.77-9.84) | 1.13x | | fp-off-distinct: fingerprint off, distinct handles; -march=native | 9.81 ns (9.77-9.91) | 9.98 ns (9.91-10.08) | 0.98x | | fp-off-table-repeats: off, repeated and 0 entries; x86-64 baseline | 8.32 ns (8.28-8.32) | 7.54 ns (7.52-7.57) | 1.10x | | fp-off-table-repeats: off, repeated and 0 entries; -march=native | 7.93 ns (7.91-7.98) | 7.32 ns (7.30-7.35) | 1.08x | ## Risks A texture resolved against a slot version read earlier than before (once, before the fingerprint, instead of again inside `texture_view_of`): a slot registered again between the two reads now gives a fingerprint and a view of the same, older version, which the next build sees as changed and builds again. What could show is a wrong texture for a draw; a revert is enough (no switch). The renderer is compiled again after updating, as for any renderer change; no cache or setting changes. ## 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 - [ ] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. Not yet: only the checks' cuts compiled (Testing). - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers.
perf(vk): a texture binding's slot version read once and handed to the fingerprint and the view
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 32s
beanstalk/approval waiting for a BigBean's 👍 on the request
f854c8f9aa
build_descriptors called texture_slot_version (vk_bank.cpp) twice for every texture and storage image binding: once
in desc_fp_note (the Descriptor reuse fingerprint) and once at the top of texture_view_of. It now reads it once per
binding and gives that value to both, so both also see the same version. texture_view_of has a form taking the
version; the form without one (the upscalers' and movies' callers) reads it as before. desc_fp_note likewise.

Not measured for this port: no micro-benchmark, no run in play.

Test: tests/test_slot_version_once.py cuts desc_fp_note's two forms and runs them with a counting
texture_slot_version, and checks that the texture and image loops read the version once, before the fingerprint,
and hand it to both. No switch (same descriptors, same fingerprint).

Assisted-by: Claude Code
Author
Contributor

@Beanstalk This changes the renderer's descriptor builds for every textured draw: a slot's version is read once (gpu/vk). No switch: a revert gives back main's code. It has not run in the game on these PCs yet. Please play Kokiri Forest and Hyrule Field, two minutes each, the PR against main on the same PC, with a picture in each compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture as main, no crash, device lost, validation error or FATAL line; frame time p99 equal to main's or better, within the run-to-run spread.

@Beanstalk This changes the renderer's descriptor builds for every textured draw: a slot's version is read once (gpu/vk). No switch: a revert gives back main's code. It has not run in the game on these PCs yet. Please play Kokiri Forest and Hyrule Field, two minutes each, the PR against main on the same PC, with a picture in each compared with main's, on Linux with NVIDIA, Linux with AMD (RADV), Windows with Intel and the Steam Deck. The same picture as main, no crash, device lost, validation error or FATAL line; frame time p99 equal to main's or better, within the run-to-run spread.
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.
Author
Contributor

@Beanstalk This replaces my request 65766 on this head, so that it follows the farm's picture and hardware rules. This reads a texture binding's slot version once and hands it to the fingerprint and the view, in every textured draw's descriptor build (gpu/vk). No switch: a revert gives back main's code. Please start from the kokiri-start save and take the picture right after it loads and settles, before any input, with a main-against-itself picture on the same PC at that point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with an RTX 4070, Windows with an Arc B580, Linux with an RX 6600 (RADV) and the Steam Deck. The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL, device lost or validation error line.

@Beanstalk This replaces my request 65766 on this head, so that it follows the farm's picture and hardware rules. This reads a texture binding's slot version once and hands it to the fingerprint and the view, in every textured draw's descriptor build (gpu/vk). No switch: a revert gives back main's code. Please start from the kokiri-start save and take the picture right after it loads and settles, before any input, with a main-against-itself picture on the same PC at that point; then, for frame times only, play Kokiri Forest and Hyrule Field, two minutes each; at least two starts a side, interleaved, the PR against main on the same PC, on Windows with an RTX 4070, Windows with an Arc B580, Linux with an RX 6600 (RADV) and the Steam Deck. The same picture as main within main's own difference from itself; frame time p99 equal to main's or better, within the run-to-run spread. The log must have no FATAL, device lost or validation error line.
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.
Author
Contributor

Measurements: a micro-benchmark on authored input (old against new, three rounds, x86-64 baseline and -march=native; not measured in play) and the Verdict rewritten to match.

Measurements: a micro-benchmark on authored input (old against new, three rounds, x86-64 baseline and -march=native; not measured in play) and the Verdict rewritten to match.
Author
Contributor

@Beanstalk One correction to my request 69698 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 69698 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_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 32s
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-slot-version-once:siantm-perf/vk-slot-version-once'
git switch 'siantm-perf/vk-slot-version-once'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 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!2055
No description provided.