WIP: perf(vk): a stage's descriptors are kept across draws in a recording part while what they were resolved from stands #794
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/upscaling
beanstalk: approved @ 1697603
beanstalk: approved @ 2c5a62e
beanstalk: approved @ 4fd82b7
beanstalk: approved @ 64d6d09
beanstalk: approved @ 6f91fae
beanstalk: approved @ 70a78f9
beanstalk: approved @ 8015c9a
beanstalk: approved @ 8d361dc
beanstalk: approved @ 9d8356e
beanstalk: approved @ abf2227
beanstalk: approved @ d82f202
beanstalk: approved @ e5f1e40
beanstalk: approved @ ee8ab5f
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
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
testing wanted
ci: approved
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!794
Loading…
Reference in a new issue
No description provided.
Delete branch "dyst/Longshot:perf/vk-descriptor-cache"
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: medium · Tested on: Windows 11 (the game-free checks; the game A/B is next) · Needs: a game run on NVIDIA, AMD and Intel
Why
Every draw rebuilt its descriptors from scratch on the replay thread, because any bind anywhere counted as a change and the game binds a new uniform buffer for nearly every draw. In Kokiri Forest that rebuild (
build_descriptors) is about 1.3 ms of the serial replay thread a frame (docs/cpu-profile.md), most of it resolving textures, samplers and buffers that had not changed since the draw before. Found in an audit of the renderer's per-draw path; no issue on the tracker.What changed
Each program's stages now keep, for one recording part, the texture, storage-buffer and uniform-buffer descriptors their last build resolved, and use them while what they came from stands. Anything that has to be noted at each draw (written buffers, storage images) or that reads guest memory without a generation (handles from c3+, handle programs, compute/task/mesh stages) is still resolved every time.
kept_program,KeptStage,kept_tex_holds,kept_buf_holds,kept_ubo_holds,desc_keep_textures,desc_keep_storageand the kept paths inbuild_descriptors(gpu/vk/vk_draw.cpp);desc_kept_partcounted indraw_begin_recordingguest_pools_stamp()(gpu/vk/vk_memory.cpp),ub_list_generation()(gpu/vk/vk_replay.cpp), read by the keystests/test_desc_keep.py; three fixtures that compiledraw_begin_recordingget the new counterMeasurements
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
Switches:
RX_VK_DESC_KEEP=0=0for an A/B or if a draw shows the wrong textureRX_VK_TRACE_TEX,RX_VK_LOG_IMG,RX_VK_WATCH_PROG,RX_VK_DRAW_STATS,RX_VK_PEEK_PROG,RX_VK_LOG_TABLE,RX_VK_SLOW_DESC,RX_VK_ASYNC_IMPORT(existing, unchanged)Testing
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_desc_keep; 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:
RX_VK_DESC_KEEP=0: Kokiri Forest, Castle Town and a dungeon a few minutes each, expecting the same picture (no wrong or flickering textures, no missing objects) and a lower replay time (vk: a frame's replay time (ms): submit) (Test Farm: @Beanstalk any, those scenes with and without RX_VK_DESC_KEEP=0)Risks
What could break: A kept descriptor that should have changed: an object drawn with another's texture or buffer for the rest of a recording part (about 120 draws). Every input the build reads is in a key or excluded from keeping; the parallel replay's workers keep their own.
Turning it off:
RX_VK_DESC_KEEP=0Compatibility: Nothing changes: no caches, settings or vk ABI involved.
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.tests/that reads changed source updated in this PR, not weakened.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.First in-game numbers (RTX 3080, Ryzen 9 3900X, Windows 11; dev_packs runtimes of this PR and main @
aa95d35fon one base; Kokiri Forest from the repo save kokiri-start): this is slower, not faster, as it stands. The descriptors' time went up in every run:Likely cause, not yet confirmed with RX_VK_PROF_FINE's kept counters: few kept stages are used (keys that move often: the texture destroy and epoch generations, ub_gen with every uniform update), while every build now also pays for the handles read twice, the slot versions and refilling the kept vectors. Next: the fine counters' hit rates, then either keys that hold or this closed. Stays WIP.
1f00672f8e86389b3583View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.