WIP: perf(vk): a descriptor build asks its diagnostics' switches once, not at every texture binding #2057

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

Summary

Every texture and image binding in build_descriptors (gpu/vk/vk_draw.cpp) asked five things that are the same for the whole build and off in play: dump_on (twice), log_img_wanted (a snprintf of the program's key when RX_VK_LOG_IMG is set), watch_prog, and trace_tex_wanted, which walked its list even with RX_VK_TRACE_TEX unset. The build now asks them once before its first stage (trace_tex_on reads RX_VK_TRACE_TEX once) and the loops read the answers. The same diagnostics when they are on; the result expected is less work a binding.

No switch; a revert gives back main's code.

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

Read first: the answers made before the stage loop of build_descriptors and trace_tex_on in gpu/vk/vk_draw.cpp.

Testing

Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 4827e543 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-desc-diag-once):

  • Its own: tests/test_desc_diag_once.py (new: the answers made once before the stage loop, none of the calls left in the texture and image loops): pass.
  • The 161 checks that read a file this change touches (--changed 75317e1f; its own are among them): 142 passed, 19 failed. Failed: tests/test_sampler_admission.py, tests/test_fsr_uniform_ownership.py, tests/test_pipeline_play_cache.py, tests/test_draw_stream_visibility.py, tests/test_device_lost_exit.py, tests/test_dev_packs.py, tests/test_draw_binds.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. tests/test_jobs_wait_runs_queued.py, tests/test_fallback_buffer_cleanup.py, tests/test_mesh_args_cleanup.py and tests/test_pipeline_cache_save.py also failed in that run, each stopped at its 60-second limit, and passed when run again on this head (log t-dc4-vk-desc-diag-once).

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 and the replay's time a frame the same as or lower than main's; then once with RX_VK_TRACE_TEX and RX_VK_LOG_IMG set, expecting their log lines as on main (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_desc_diag_once.py with --cxx g++ and --cxx clang++, expecting PASS (by hand)

Measurements

Verdict: a build with 8-32 texture bindings takes 2.5-3.5x less time in its diagnostics' asks (45-188 ns less a build), with one texture 1.24-1.33x (2-3 ns); a build with no texture or image binding is 2.7-3.1 ns slower (0.47-0.50x: the four asks made once and not needed). A micro-benchmark on authored input; not measured in play.

Micro-benchmark (vk_desc_diag_once_bench.py: a script on this PC, not in this PR): the switches' functions cut out of vk_draw.cpp and vk_dump.h and compiled in the same file as the bindings, as in the build; the bindings' diagnostic lines as each side has them, every switch unset as in play; the rest of a binding an authored view lookup; 512 builds a repetition; 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 build, 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 @ 4827e543 ฮ” (old/new)
tex8-img1: 8 texture bindings and 1 image a build; x86-64 baseline 69.53 ns (69.53-69.53) 23.44 ns (23.44-23.44) 2.97x
tex8-img1: 8 texture bindings and 1 image a build; -march=native 74.81 ns (74.81-74.81) 29.88 ns (29.69-29.88) 2.50x
tex32-img2: 32 textures and 2 images; x86-64 baseline 262 ns (262-262) 74.61 ns (74.61-74.61) 3.51x
tex32-img2: 32 textures and 2 images; -march=native 280 ns (280-280) 98.05 ns (98.05-98.24) 2.85x
tex1-img0: 1 texture; x86-64 baseline 10.94 ns (10.94-10.94) 8.20 ns (8.20-8.20) 1.33x
tex1-img0: 1 texture; -march=native 11.13 ns (11.13-11.33) 8.98 ns (8.79-8.98) 1.24x
tex0-img0: no texture or image binding; x86-64 baseline 2.73 ns (2.73-2.73) 5.47 ns (5.47-5.66) 0.50x
tex0-img0: no texture or image binding; -march=native 2.73 ns (2.73-2.73) 5.86 ns (5.86-5.86) 0.47x

Risks

A diagnostic whose answer changes during one build (a frame dump that starts in the middle of a build) is now seen from the next build on: a dump could miss one build's bindings. In play all of them are off. A revert is enough (no switch). The renderer is compiled again after updating.

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 image binding in `build_descriptors` (`gpu/vk/vk_draw.cpp`) asked five things that are the same for the whole build and off in play: `dump_on` (twice), `log_img_wanted` (a `snprintf` of the program's key when `RX_VK_LOG_IMG` is set), `watch_prog`, and `trace_tex_wanted`, which walked its list even with `RX_VK_TRACE_TEX` unset. The build now asks them once before its first stage (`trace_tex_on` reads `RX_VK_TRACE_TEX` once) and the loops read the answers. The same diagnostics when they are on; the result expected is less work a binding. No switch; a revert gives back main's code. From 2816697a on `exp/x86-asm-sync`. Read first: the answers made before the stage loop of `build_descriptors` and `trace_tex_on` in `gpu/vk/vk_draw.cpp`. ## Testing **Tested:** Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head 4827e543 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-desc-diag-once`): - Its own: `tests/test_desc_diag_once.py` (new: the answers made once before the stage loop, none of the calls left in the texture and image loops): pass. - The 161 checks that read a file this change touches (`--changed 75317e1f`; its own are among them): 142 passed, 19 failed. Failed: `tests/test_sampler_admission.py`, `tests/test_fsr_uniform_ownership.py`, `tests/test_pipeline_play_cache.py`, `tests/test_draw_stream_visibility.py`, `tests/test_device_lost_exit.py`, `tests/test_dev_packs.py`, `tests/test_draw_binds.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. `tests/test_jobs_wait_runs_queued.py`, `tests/test_fallback_buffer_cleanup.py`, `tests/test_mesh_args_cleanup.py` and `tests/test_pipeline_cache_save.py` also failed in that run, each stopped at its 60-second limit, and passed when run again on this head (log `t-dc4-vk-desc-diag-once`). 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 and the replay's time a frame the same as or lower than main's; then once with `RX_VK_TRACE_TEX` and `RX_VK_LOG_IMG` set, expecting their log lines as on main (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_desc_diag_once.py` with `--cxx g++` and `--cxx clang++`, expecting PASS (by hand) ## Measurements **Verdict:** a build with 8-32 texture bindings takes 2.5-3.5x less time in its diagnostics' asks (45-188 ns less a build), with one texture 1.24-1.33x (2-3 ns); a build with no texture or image binding is 2.7-3.1 ns slower (0.47-0.50x: the four asks made once and not needed). A micro-benchmark on authored input; not measured in play. Micro-benchmark (`vk_desc_diag_once_bench.py`: a script on this PC, not in this PR): the switches' functions cut out of `vk_draw.cpp` and `vk_dump.h` and compiled in the same file as the bindings, as in the build; the bindings' diagnostic lines as each side has them, every switch unset as in play; the rest of a binding an authored view lookup; 512 builds a repetition; 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 build, 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 @ 4827e543 | ฮ” (old/new) | |---|---|---|---| | tex8-img1: 8 texture bindings and 1 image a build; x86-64 baseline | 69.53 ns (69.53-69.53) | 23.44 ns (23.44-23.44) | 2.97x | | tex8-img1: 8 texture bindings and 1 image a build; -march=native | 74.81 ns (74.81-74.81) | 29.88 ns (29.69-29.88) | 2.50x | | tex32-img2: 32 textures and 2 images; x86-64 baseline | 262 ns (262-262) | 74.61 ns (74.61-74.61) | 3.51x | | tex32-img2: 32 textures and 2 images; -march=native | 280 ns (280-280) | 98.05 ns (98.05-98.24) | 2.85x | | tex1-img0: 1 texture; x86-64 baseline | 10.94 ns (10.94-10.94) | 8.20 ns (8.20-8.20) | 1.33x | | tex1-img0: 1 texture; -march=native | 11.13 ns (11.13-11.33) | 8.98 ns (8.79-8.98) | 1.24x | | tex0-img0: no texture or image binding; x86-64 baseline | 2.73 ns (2.73-2.73) | 5.47 ns (5.47-5.66) | 0.50x | | tex0-img0: no texture or image binding; -march=native | 2.73 ns (2.73-2.73) | 5.86 ns (5.86-5.86) | 0.47x | ## Risks A diagnostic whose answer changes during one build (a frame dump that starts in the middle of a build) is now seen from the next build on: a dump could miss one build's bindings. In play all of them are off. A revert is enough (no switch). The renderer is compiled again after updating. ## 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 descriptor build asks its diagnostics' switches once, not at every texture binding
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 9s
beanstalk/approval waiting for a BigBean's ๐Ÿ‘ on the request
4827e543e5
Every texture and image binding in build_descriptors asked five things that are the same for the whole build and
off in play: dump_on (twice), log_img_wanted (an snprintf of the program's key when RX_VK_LOG_IMG is set),
watch_prog, and trace_tex_wanted, which walked its list even with RX_VK_TRACE_TEX unset. The build now asks them once
before its first stage (dumping, img_logged, tracing, watching; trace_tex_on reads RX_VK_TRACE_TEX once) and the
loops read the answers. The same diagnostics when they are on.

From the branch's 2816697a (with the flat texture-handle table, its own change here). Not measured on the branch or
in play.

Test: tests/test_desc_diag_once.py reads build_descriptors: the answers made once before the stage loop, none of
the calls left in the texture and image loops. No switch.

Assisted-by: Claude Code
Author
Contributor

@Beanstalk This changes the renderer's descriptor builds so their diagnostic is checked 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 so their diagnostic is checked 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 65771 on this head, so that it follows the farm's picture and hardware rules. This makes a descriptor build ask its diagnostics' switches once instead of at every texture binding (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 65771 on this head, so that it follows the farm's picture and hardware rules. This makes a descriptor build ask its diagnostics' switches once instead of at every texture binding (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 69702 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 69702 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 9s
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-desc-diag-once:siantm-perf/vk-desc-diag-once'
git switch 'siantm-perf/vk-desc-diag-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!2057
No description provided.