WIP: perf(vk): a draw keeps its program across texture registrations and uniform updates that do not touch its answers #795
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!795
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:perf/vk-program-pick-fast"
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?
Type: perf · Risk: low · Tested on: Windows 11 (the game-free checks; the game A/B is next) · Needs: a game run on NVIDIA, AMD and Intel
Why
A draw finds its shader program variant through a fast path that only held while no texture had been registered and no uniform updated since, and the game does both between most draws as it streams. So most draws of the same program with the same textures went through the full pick (a hash, a map lookup, rebuilding the answers' handles) for the same answer. Found in an audit of the renderer's per-draw path; no issue on the tracker.
What changed
For programs whose texture answers are all read from c2, the fast path now holds while the picks entry it came from is unchanged and none of the slots its answers name was registered anew. Programs with handle programs or c3+ handles, and compute, keep the exact checks.
Pick::gen,ProgFast::pick/pick_gen,pick_slots_keptand the slots path inprogram_for(gpu/vk/vk_shader.cpp)tests/test_pick_slots.pyreplays random binds, registrations, updates and draws through the realprogram_forand checks the same program for every drawMeasurements
Verdict: not measured yet: A/B runs in the game (this PR against main on one base, interleaved) are next and will replace this section.
Flags and settings
One switch for an A/B.
RX_VK_PICK_REG_GEN=1=1for an A/BTesting
Tested: Windows 11, llvm-mingw (the builder's v2.0.14 tools): the new and changed checks; every check that reads the
changed code;
-fsyntax-onlyof the changed renderer files with the build's flags and headers; python -I -B tests/run_all.py on this branch and on main @aa95d35f, same PC and environment: the same results apart from the newtest_pick_slots; the failures main has here are named in the first comment.Not tested: the game yet. This PR is WIP until its A/B is in (next: this PR against main on one dev_packs base of
main @
aa95d35f, on an RTX 3080 with a Ryzen 9 3900X, Windows 11; AMD and Intel need other testers).Must be tested:
vk: program picks:line counting most kept picksby their slots(Test Farm: @Beanstalk any, those scenes, the log line)Risks
What could break: A program kept whose variant should have changed with a texture's type: a material drawn with the wrong variant (wrong colours) until its next full pick. The slots its answers depend on are checked by version.
Turning it off:
RX_VK_PICK_REG_GEN=1Compatibility:
gpu/vk/vk_shader.cppis one of the shader translator's stamped files: a player's shader caches are translated again after the update (as with every change to it). No settings or vk ABI change.Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why. Not ticked yet: Testing says the game is not tested yet; only game-free checks and a syntax check are named, and game files changed.
in Risks. Not ticked yet: Measurements only says not measured yet, and the per-pick FlatMap lookup cost it adds is unmeasured.
main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.🤖 Generated with Claude Code
The checks on this PC (Windows 11, RTX 3080, Ryzen 9 3900X, llvm-mingw from the builder's v2.0.14 tools):
python -I -B tests/run_all.pyon main @aa95d35ffails these 19 here, and so does this branch:test_appimage_player_build.py,test_bake_portability.py,test_cpm_discovery.py,test_cpp_preflight.py,test_crash_dialog.py,test_env_on.py,test_fpx_sticky.py,test_lift_cleanup_error.py,test_linux_preflight.py,test_make_game_cache.py,test_make_game_prepare.py,test_missing_nup.py,test_oot_state_tap.py,test_options_budget_once.py,test_readback_late.py,test_spawn_emit.py,test_tested_configurations.py,test_vk_pgo.py,test_walk_key.py. Any other failure in a full run on this branch was rerun on its own and passed (the full runs shared the PC with dev_packs builds: timing checks).Next: an interleaved A/B in the game against main on one dev_packs base of
aa95d35f; the numbers will replace the Measurements section.62e59cc76d71eca88277Rebased onto
main@7bacf846. One conflict in gpu/vk/vk_shader.cpp (program_for): main added a comment block abovePick& pk = picks[key]while this PR moved that line below thekeeplambda; I kept the PR's order and moved the comment with the line. Pushed as71eca882. No tests were run here; the test boxes stay yours.A follow-up to this morning's rebase, pushed as
2b66bff0on top of it.The rebase onto
mainbrought in #231 (#231), which madepicksaFlatMap. AFlatMapinsert can move every entry (flat_map.h), where anunordered_mapnever moved one. This PR'sProgFast::pickkept a pointer intopicksfrom one draw to the next, so once a draw with a new key made the table grow,pick_slots_keptreadf.pick->genandf.pick->handlesfrom the freed array. That isn't a text conflict, so neither the rebase nor the forge showed it.The fix: a kept pick keeps its entry's key (
has_pick,pick_key) andpick_slots_keptlooks the entry up again (picks.find), returning it for immediate use before any insert.keep()takes the key alongside the entry. At the 65,536-entry clear the kept picks still forget their entries, as before.tests/test_pick_slots.pyfollows: its needles name the key, it checks noPickpointer is kept, and its fixture includesflat_map.h, which it needed since the rebase anyway.No tests were run here; the test boxes stay yours. Please check it against your intent, in particular that
pick_slots_keptnow does oneFlatMaplookup per kept pick, which should be cheap next to the full pick it saves.Thanks @HumanBean:
2b66bff0is the right fix, and I missed this. I reviewed the first version assuming picks was an unordered_map, whose entries never move. Since #231 it is a FlatMap, andProgFast::pickheld a pointer into it from one draw to the next, so a grown table left that pointer on freed memory.Read against the intent, the fix keeps it:
pick_slots_keptfinds the entry again withpicks.find. The pointer it returns is used at once, by the keep before any insert.This stays WIP. Its tests haven't been run on the rebased branch (test_pick_slots with flat_map.h, and the vk_shader.cpp checks), and it has no measurement yet: the one RX_VK_BENCH run so far is too few to call. The stamped-file cost holds: shipping it re-translates players' shader caches.
Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
**Not testable by hand:**line saying why and what stands in for it. Then tick it.#795 on today's main: the standard test, no change in fps or CPU
I measured this PR on a second PC, on today's main.
Verdict: no measurable change in fps or CPU time a frame. The arms' medians are 67.79 against 67.14 fps and 69.9
against 69.2 CPU ms. With three pairs, the harness calls a result under 5 % diagnostic. Frame times, the game clock and
the GPU didn't move either.
The renderer's own replay times did move. In all three PR runs,
drawis lower than in every control run (5.70-5.84against 6.24-6.86 ms a frame), and so are
descriptors(2.27-2.33 against 2.58-2.92). The render thread's jobs a frameare the same in both arms (13.75 against 13.72 ms), so the frame doesn't get shorter.
The new path is taken but rarely here:
by their slotsis about 0.7 % of all picks. At 3.4 M picks the PR runs log21,350-23,105 picks kept by their slots, and the total kept is the same as the control's (2,384,106-2,390,146 against
2,383,134-2,386,106).
What was run
ef6038ab(2026-11-18 03:06Z), built as one development base with llvm-mingw 20261104, asthe official builds are. Control and PR share the same
longshot.exe(0a53b387). The renderer DLL is the base's(ed1771bb) for the control and the PR's (2d430447) for the PR arm, built over the same base from the same objects
(
scripts/dev_packs.py).71eca882and2b66bff0(head2b66bff0), were cherry-picked ontoef6038ab.71eca882had one conflict, ingpu/vk/vk_shader.cppprogram_for, in the comment block above theprog_fastloop. Main's #1390 (03788b38) has since deleted theRX_VK_PICK_BIND_GENkill switch: its commentsentence and the
static const bool by_bindline. I kept main's comment line, droppedby_bind(unused on main), andkept all of the PR's new lines (the
by_regcomment,by_reg,by_slots).2b66bff0applied cleanly. The resultingdiff against
ef6038abhas exactly the added and removed lines of your branch against its base7bacf846(288+/15-).vk_shader.cppis a stamped translator file. The PR runtime was prepared again before any runwith the game's own
--prepare-shaders --compile-shaders most, as the builder does. It took 32 min here (theprograms 10.4 min, then the pipelines). The counts match the base's preparation: 38,809 programs, 46,598 new, 69
failed; 32,825 noted pipelines and 9,689 compute pipelines. Players get this re-prepare with the update, as the PR
says.
std_test.py604af9c9,run_profile.py6d998641). It runs Hyrule Field from a fixedsave, with the camera turning at full speed (right stick held from the load). The game runs in a 1280x720 window
(16:9), with the frame rate unlocked (
HOS_FPS_MAX=240) and the game clock checked (HOS_FPS_LOG=1, 1.000 ±0.01). The render thread is on (
RX_VK_ASYNC=1, as Threaded rendering Auto gives a 16-thread CPU), and the fixedtest settings file is used. The window is 20 s after the load, with 3 alternating pairs, no warm-up and no
replacements.
frame at 100 fps, in its own window. On this PC, AMD's driver otherwise keeps the RX 9070 XT at ~1,550-1,850 MHz
because the game's bursty load never reaches its boost threshold. Runs then measure a slower GPU and compare
poorly. With the load, both arms run at ~2,450-2,580 MHz.
within 15 min before the runs, and a disk-write probe was clean (max 0.4 ms).
Numbers
Per run, in run order.
RT jobsandRT idleare the render thread's own line (vk: the render thread (600 presents ...): its jobs a frame, split into submits, presents and others).draw,descriptorsandprogramscome fromvk: a frame's replay time (ms). Each is the mean of the last two lines inside the window.error linescounts lineswith error, fail, VUID, lost or validation. In every run of both arms it is one line, the crash watcher's start line.
No run was rejected, and no frame went over 100 ms in any run. The one frame over 50 ms in every run is the same in
both arms.
Checked, not checked
tests/run_all.py --changed ef6038ab) on the cherry-picked tree,and the same checks on
ef6038ab.tests/test_pick_slots.pypasses. The 4 failures (test_dev_packs,test_linux_pressure,test_recorder_sync,test_switch_table) fail onef6038abtoo, on this PC.test_switch_table.pygains one line here, "RX_VK_PICK_REG_GEN is read (gpu/vk/vk_shader.cpp) and has no row ingpu/vk/switches.def". Main's switch table (#1300) wants a row for it when you rebase.
the base (69). I also made one extra unmeasured run per runtime with
RX_VK_SHOTS(a picture every 600 presents)and looked at the pictures. They showed the menu, the load and the turning field with the HUD, and nothing was wrong:
no missing or wrong-coloured textures, objects or HUD parts. This is a glance, not an image comparison: the camera is
at a different angle in each run.
RX_VK_PICK_REG_GEN=1(the PR's off switch;the control is main without the PR), NVIDIA, Intel, Linux and the Steam Deck. No image comparison, no validation
layers, no code review.
How to reproduce
(
devpacks.shis this PC's front forscripts/dev_packs.py;std_test.pyis our standard-test harness.)View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.