WIP: perf(vk): a draw's program checks its textures with each handle read once, a plain one in place #3303
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
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!3303
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:perf/vk-pick-handles-once"
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
Each draw asks
program_forfor its program. It keeps the variant it picked last for the same inputs, and the handles ofthe textures that variant was picked for (each texture's slot and the slot's version); a draw checks those against the
textures bound now. That check read every handle through
answer_handle(descriptor_handle,stage_cbuf_word,driver_bank_word: a chain of calls and range tests for each), and when any handle differed it read them all again tocheck their types (
still_valid). It runs on the render thread at nearly every draw: over a million rechecks in 45 s ofMarket.
This reads each handle once. A handle that is a plain driver bank 2 word (no handle program, no second word, no shift:
handle_bank2_offset, the conditions under whichdescriptor_handlereturns that word as it is) is read in place, at theword's offset in the
NvnState, found once when the program is picked (pick_places); any other throughanswer_handleas before. On a difference every answer is checked over the handles just read, by
still_valid's own rule, so the answer(the same handles / other textures of the same types / other types) and the handles kept are the same as before.
driver_bank2_slot(vk_bank.cpp) isdriver_bank_word's map of bank 2, whichdriver_bank_wordnow reads through, sothe two cannot disagree about where a handle lives.
On the render thread's replay of one Market frame (2,226 draws, 8.74 ms) it takes 0.229 ms off (95 % interval
0.155-0.260 ms, about 2.6 %). In play at Market, an A/B with the switch flipped within each run:
program_for's timeon the render thread is 0.36 ms a frame less (−20 %) and the whole draw translation's 0.34 ms less, in both runs; fps
+1.6 %, inside the series' spread (Measurements).
RX_VK_PICK_ONCE(a kill switch, read at each recording's start, so HOS_AB flips it within a run):=0reads as before;=checkruns both ways at every recheck, takes the old one's answer, logs any difference and says it is checking at itsfirst recheck.
Overlaps siantm's #2954 (an 8-way
prog_fastcache and inline c2fast_answersinprogram_for), which reads c2-resident handles against theNvnStatetoo, as part of a larger change.This one is the recheck alone, held to the old way's answers by a check mode and a test; whichever lands second rebases
over the other. My older WIP #795 (the fast path kept across
texture registrations, so fewer draws take the full pick) touches
program_fortoo; it has not moved since 2026-11-15and would rebase over this.
Read first:
gpu/vk/vk_shader.cpp(handle_bank2_offset,pick_places,pick_recheck_once,pick_recheck,program_for),gpu/vk/vk_bank.cpp(driver_bank2_slot,driver_bank_word).Testing
Tested: Windows 11 (22631), Ryzen 9 3900X, RTX 3080 (NVIDIA 621.47). This commit over main
de091ae29, packed over the3b3ea2cb3base, withRX_VK_PICK_ONCE=check: Continue, then a teleport to Market, Hyrule Field and Kakariko, 45 s of playin each, threaded rendering on. Every run compared both ways at every recheck: Market 1,048,576+, Hyrule Field
2,097,152+, Kakariko 2,097,152+ (twice), 0 differ. One launch (the first Kakariko one) lost the GPU during start-up
(Windows: nvlddmkm 153, then "stopped responding and has successfully recovered"), before the first frame and before any
recheck had run (the check logs its first, and had not); its two reruns played through, and it is the only device loss in
the PC's last 142 game runs. The A/B in Measurements ran 2 more runs of play.
tests/test_pick_once.py(new):vk_shader.cpp's andvk_bank.cpp's own code, cut out of the sources and built overthe real
Program,Stageand descriptor types:driver_bank2_slotis the old bank 2 map at every stage and byteoffset; over random programs (every descriptor kind: plain bank 2 words, other banks, word pairs, shifted words, handle
programs, misaligned and out-of-range offsets, stages out of range) and random changes of the bound state, the pool's
slots and their types, the new, old and
=checkways give the same answers and keep the same handles (116,700rechecks), also against a copy of the state with the first scrambled; a slot unbound then bound to slot 0;
=checkwhere the two ways differ (it logs, and answers as before); a thread with no recording begun; the switch's values and
HOS_AB. Thirteen broken versions of the change make it fail (each checked).
tests/test_tex_desc_memo.pycutsdriver_bank2_slotwithdriver_bank_word;tests/test_hos_ab.pylists the switch;the three fixtures that cut
draw_begin_recording(tests/draw_stream_visibility_test.cpp,fsr_uniform_ownership_test.cpp,recording_admission_test.cpp) stubpick_begin_recordingbeside its neighbours.more broken versions for the test) are in.
tests/run_all.py --strict(Windows, llvm-mingw) on this head,f513f7e75: 887 passed, 15 failed, 55 skipped. Thesame 15 fail on main
0b284cc76run the same way on this PC (884 passed, 17 failed there: these 15, andtest_run_all_outputandtest_seed_reader, which pass here). Ten lack a tool this PC doesn't have under--strict(glslang, spirv-val, llvm-mc, zstandard:
test_fixed_share_upscale_shader,test_framegen_hdr,test_fsr3fi_hud_layer,test_fsr3fi_hudless_colour,test_fsr4_tune,test_gfx_effects,test_lifter,test_native_zstd,test_rt_refl_lamps,test_temporal_present_bandwidth); five fail on main here for reasons oftheir own (
test_dev_update,test_float_add_subgroup,test_helpers_extract,test_longshot_ctl,test_rt_light_grid). The branch's first full run failed three more: the fixtures that cutdraw_begin_recordinglacked a stub for its new call; they have one in this commit and pass.
Still to test:
RX_VK_PICK_ONCE=check, expectingvk: pick: RX_VK_PICK_ONCE=check: N rechecks compared, 0 differlines in the log and no difference in the picture (@Beanstalk play Market for a minute onthe Steam Deck with RX_VK_PICK_ONCE=check and report the "rechecks compared" lines)
Measurements
Setup: Windows 11 (22631), Ryzen 9 3900X, RTX 3080 (NVIDIA 621.47); Market, child (crowded): Continue, then a
teleport; window 1720x720, output 3440x1440, render resolution 67 %, quality Custom, frame generation off, V-Sync off,
uncapped (
HOS_FPS_MAX=1000), threaded rendering on; the frame trace (RX_VK_FRAME_TRACE=1), 40 s in each run after awarm-up until no frame waits for a pipeline.
dev.py ab --scene market --runs 2 --env RX_VK_PICK_ONCE=0, each run atiming job of the PC's queue, the switch flipped every 3 s within each run (HOS_AB), so both sides share each run's
scene, heat and background.
Baseline: one build, this change over main
de091ae29(a4d4e380a, before its rebase):RX_VK_PICK_ONCE=0(theold way, as on main) against unset (this change). The head is the same renderer code rebased onto
a2b7abf9e; the sixcommits between touch no file under
gpu/.The render thread's phases are the frame trace's columns, the mean a frame over each side's frames (transitions left
out); fps and frame times are
dev.py ab's.RX_VK_PICK_ONCE=0: this PR @ a4d4e380aprograms_ms(program_for, the pick)draw_ms(the draw translation, all of it)desc_ms(descriptors)cmds_ms(commands, the push)game_ms(the game thread)Verdict: the pick's own time on the render thread is 0.36 ms a frame less, the same in both runs, and the draw
translation's 0.34 ms less; nothing else on the render thread moves. fps is up 1.6 % and the frame time's interval holds
0: at this setting the frame follows the game's own time (
game_ms16.6 ms of a 17.8 ms frame), and the present waitsfor the render thread 0.02 ms a frame (
wait_render_ms), so the render thread's saving shows in fps only where the renderthread sets the pace (a slower CPU, more draws; not measured here).
Risks
vk_shader.cpp,vk_bank.cppandvk_state.hare in the shader stamp: players' programs are translated again once,at the launcher's shader preparation (as for any change to those files).
handle_bank2_offsetmirrorsdescriptor_handle's conditions, the test holds the two to each other over every descriptor kind, and=checkfoundno difference in play.
RX_VK_PICK_ONCE=0restores the old way;=checkshows a difference in the log.settings.tomlor the caches beyond the re-translation; a revert is enough.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened:tests/test_tex_desc_memo.pycutsdriver_bank_wordwith thedriver_bank2_slotit now reads through; the three fixtures that cutdraw_begin_recordingstub its new
pick_begin_recording()call.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.🤖 Generated with Claude Code
Tested in game: Windows 11 (22631), Ryzen 9 3900X, RTX 3080 (NVIDIA 621.47), threaded rendering on. This change over main
de091ae29with RX_VK_PICK_ONCE=check: Continue, then a teleport to Market, Hyrule Field and Kakariko, 45 s of play in each, each run played to its end; every recheck compared both ways (Market 1,048,576+, Hyrule Field 2,097,152+, Kakariko 2,097,152+ twice), 0 differ. Then 2 runs of 40 s at Market with the switch flipped within each run (Measurements): program_for 0.36 ms a frame less on the render thread. One Kakariko launch lost the GPU during start-up, before any recheck had run (nvlddmkm 153); its two reruns played through.Possibly related, for context:
@Beanstalk play Market for a minute on the Steam Deck with RX_VK_PICK_ONCE=check and report the "rechecks compared" lines (expected:
vk: pick: RX_VK_PICK_ONCE=check: N rechecks compared, 0 differ), and whether the picture looks as on main.Beanstalk test farm · ⚠️ couldn't be judged on steamdeck
Commit
f513f7e· approved by dyst (reviewed) · dashboard⚠️ Note: Check mode runs both implementations and returns the old answer, so this plan cannot measure the claimed speed-up or independently verify the default fast path's picture.
Done (started 03:26 UTC, last report 08:40 UTC). Comment
@Beanstalkto run it again.steamdeckCouldn't be judged: the tester's PC could not finish the test. The farm tries another PC, or the same one after a fix; it says nothing about the PR on its own.
steamdeck, report 1:the main base failed (exit 1): 11 shader cache files from <data>/builder/bases/main-seedsteamdeck, report 2:the main base failed (exit 1): 11 shader cache files from <data>/builder/bases/main-seedWhat was tested
What will be tested · AI plan (
gpt-6.1-terra)On Steam Deck, the plan starts at the daytime Market entrance, compares a stationary picture with main, and runs a minute in Market with RX_VK_PICK_ONCE=check on the PR. Three starts per side provide repeated picture comparisons, while the logs report the recheck counts and differences. A crash, a missing check line, a reported mismatch, or a picture difference above the threshold fails the PR.
check(PR only).market-entrance(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0; switchesHOS_OUTPUT_RES=1280x720,RX_VK_AUTO_TUNE=0), then take the picture market-entrance to compare with main, move the stick; 3 runs on each side.Measurements on `steamdeck`, for the PR description
Verdict: could not be judged on steamdeck (2 reports).
Hardware: 1: linux+amd+radv+igpu+handheld
AMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAM; 2: linux+amd+radv+igpu+handheldAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMScene: market-check, from the repository's save market-entrance (vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, HOS_OUTPUT_RES=1280x720, RX_VK_AUTO_TUNE=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-check: 3 game starts a side; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)Nothing was measured: no metric came back.
Flags and settings
RX_VK_PICK_ONCEcheckAs Markdown for the PR description:
The testers' hardware
steamdeckAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMsteamdeckAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.