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
2 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.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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.