WIP: perf(vk): a handle table's places in the resolved handles' table asked for at once #2058
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2058
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/vk-hit-prefetch"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
A texture binding that is a handle table (an array whose elements' handles a program computes, such as the clustered lights) looks every element up in
texture_view_of's table, a cache miss a lookup, one after another.build_descriptors(gpu/vk/vk_draw.cpp) now asks for each element's home place (HitTable::prefetch, both lines of the 40-byte place) right afterstage_handleshas read the table's handles, keyed astexture_view_ofkeys the lookups that follow. A hint only: the table and the descriptors are the same. Only with the flat table on. The result expected is a shorter build for programs with handle tables.Depends on #2003 (the flat table,
HitTable): its commit shows in this diff until it merges.No switch of its own:
RX_VK_TEX_HIT_FLAT=0turns the table and these prefetches off (main's map).From f61b2820 on
exp/x86-asm-sync.Read first:
HitTable::prefetchand the prefetch afterstage_handlesinbuild_descriptors(gpu/vk/vk_draw.cpp).Testing
Tested: Windows 11, i7-9700, RTX 4060, the builder's llvm-mingw clang 23; head
71994e67on #2003's head9fd4c4b4(on main @75317e1f). Every check ran throughtests/run_all.py --strict --exactin build jobs of the PC's job queue, in a hidden console (logt-dc4-vk-hit-prefetch):tests/test_hit_prefetch.py(new: prefetches leave every place as it was; the prefetch's place and key inbuild_descriptors): pass.--changed 9fd4c4b4; its own are among them): 146 passed, 16 failed. Failed:tests/test_fsr_uniform_ownership.py,tests/test_sampler_admission.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 @75317e1ftoo (the same checks on main in the batch before, logt-dc3-base).tests/test_recording_admission.pyfails on main @75317e1ftoo, now and then: its "worker slot ownership" case failed on main in 7 of 10 runs made alternately with this branch's (logst-dc5-base-ra-*), with the same message.tests/test_pipeline_cache_save.pyalso failed in that run, stopped at its 60-second limit, and passed when run again on this head (logt-dc5-vk-hit-prefetch-ra1).It has NOT run in the game on this PC yet.
Still to test:
tests/test_hit_prefetch.pywith--cxx g++and--cxx clang++, expecting PASS (by hand)Measurements
Verdict: with the table's places out of the caches a lookup takes 1.29-1.50x less time (7-18 ns an element) for tables of 8-128 elements, 1.09-1.13x for 2; with the places in cache it is still 1.08-1.13x quicker. How often the places are out of cache in play is not measured. A micro-benchmark on authored input; not measured in play.
Baseline: #2003's head
9fd4c4b4(main @75317e1fwith the flat table,HitTable, which this PR depends on: main has noHitTable).Micro-benchmark (
vk_hit_prefetch_bench.py: a script on this PC, not in this PR):HitSlotandHitTablecut out ofvk_draw.cppat both commits, each filled with the same 40,000 authored keys (131,072 places, 5 MB); handle tables looked up asbuild_descriptorsdoes (the new side prefetching every element's place first), each lookup followed by an authored amount of dependent work (rounds of a multiply-xorshift, a stand-in for the rest oftexture_view_of); 2,048 elements a repetition; three rounds run alone in this PC's job queue (2026-11-22, 01:21-01:23 UTC; logbench-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 element, the median of the three rounds' medians, in parentheses the lowest and highest of them; Δ: old over new (above 1, this PR is quicker).9fd4c4b471994e67Risks
None for the picture: a prefetch changes no value. It could cost a little where the places were already in cache. Turned off with the table by
RX_VK_TEX_HIT_FLAT=0, or a revert. The renderer is compiled again after updating.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named). Not yet: only the checks in Testing ran.main, or Measurements says why there is nothing to measure. Not yet (Measurements).third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def. Its row is in; not measured yet.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Possibly related, for context:
@Beanstalk This makes the renderer prefetch from its texture handle table during bindings (gpu/vk), behind RX_VK_TEX_HIT_FLAT from #2003, whose commit is in its diff; RX_VK_TEX_HIT_FLAT=0 is main's way. 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, on the PR's side with RX_VK_TEX_HIT_FLAT=1 and with RX_VK_TEX_HIT_FLAT=0, 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; with it 1, frame time p99 equal to 0 or better; with it 0, as main's.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.@Beanstalk This replaces my request 65775 on this head, so that it follows the farm's picture and hardware rules. This asks for a handle table's places in the resolved handles' table at once during texture bindings (gpu/vk), behind RX_VK_TEX_HIT_FLAT from #2003, on by default. It sits on #2003, so its diff against its merge base includes that PR's commits; the farm cannot take it as the comparison, so please compare with main. 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 the PR's side unset (the default, on) and with RX_VK_TEX_HIT_FLAT=0 (off), 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; with it unset, frame time p99 equal to main's or better, within the run-to-run spread, and equal to RX_VK_TEX_HIT_FLAT=0 or better. The log must have no FATAL, device lost or validation error line.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.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.
@Beanstalk One correction to my request 69704 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.
@siantm only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.