perf(vk): the load at create lets a program's shader modules go once its noted pipelines are built (RX_VK_DROP_LOADED_MODULES) #1844
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!1844
Loading…
Reference in a new issue
No description provided.
Delete branch "GummiNaomi/Longshot:perf/drop-loaded-modules"
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
With programs loaded at their create calls (
RX_VK_LOAD=create, the default), every program the load reads keeps its vertex and fragment shader modules for the session, and NVIDIA's Windows driver keeps each module's SPIR-V in the game's private memory while the module lives: in a Market stand on my PC, 915 MB of the game's private memory were modules made by the load at create, nearly all for programs whose pipelines the load had already built. This lets a loaded program's modules go once every noted pipeline of its variant is built, and makes them again fromlongshot_programs.binif play ever builds a new pipeline state of it (RX_VK_DROP_LOADED_MODULES). In two Market stands a side: working set 13.5 -> 12.2-12.3 GB, private memory 22.2 / 21.9 -> 20.8 / 20.6 GB, steady frames and loads the same; a 7-area tour peaked at 13.1 GB instead of 15.3 GB, with 15,393 modules let go and none made again. On by default;=0keeps them, as before.Why: the 915 MB is what a temporary census of the process's allocations by call stack (not in this PR) put under
vkCreateShaderModule<-make_module<-program_cache_read<-load_work. The pipelines built from a module don't need it once they are made. Linux already lets modules go after the start-up precompile (program_cache_drop_modules, forRX_VK_LOAD=starton 20 GB or less), and #1488 (open) proposes that release on Windows on request; neither reaches the load at create, which is where a default start's modules come from. Also in that census, not changed here: the recordings' descriptor pools held 339 MB of the game's private memory on NVIDIA's Windows driver (48 pools, about 7 MB each), which bears on #1158's note that NVIDIA is unaffected.What changes:
load_work(gpu/vk/vk_programs.cpp) counts, for each graphics program, the noted pipelines of its variant it built and those it left (deferred to their draw, cold, or a note that did not read). When every one was built and the switch is on,program_cache_drop_loaded(gpu/vk/vk_progcache.cpp) destroys the program's modules while it is still in the load job's own list, so no other thread holds it, and records it in the table Linux's release uses. A build of a new state for it goes throughprogram_cache_complete_graphicsfirst, which reads the stages back fromlongshot_programs.binand makes the modules on that worker, as after Linux's release;build_graphicsand the quick pipeline already refuse a program whose modules are gone. Kept: compute and mesh-fallback programs, a program with a stage that cannot be read back from the file, and a second program of the same key and variant. The census linevk: program loads at create (...)counts the modules let go and the programs that had them made again. Unchanged: the load itself, the pipelines, the program cache's file, Linux's release after the precompile.Read first:
program_cache_drop_loadedingpu/vk/vk_progcache.cpp, the notes loop inload_work(gpu/vk/vk_programs.cpp), thentests/test_loaded_modules_drop.py.Testing
Tested: Windows 11, RTX 4070 SUPER (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB: two Market stands of 150 s a side and one 7-area teleport tour a side from the
kokiri-startsave,RX_VK_DROP_LOADED_MODULES=0against unset, on a build of main @f505340bwith #1810-#1813's changes and this one; with it on, the census line counted the modules let go (5,582 in a stand, 15,393 in the tour) and 0 programs' modules made again; the tour's pictures alike in all 7 areas both ways.Checks:
tests/test_loaded_modules_drop.py(the notes loop's counting as it is in the source; the drop and the remake run on a real program cache file: a graphics program's two modules go and come back with the same SPIR-V, counted; a mesh fallback program, a compute program, a stage not in the file and a second program of the same key keep theirs; the switch on unset, off for 0/off/false/no) passes on this head on Windows (clang) and Linux (g++ 13.3, WSL Ubuntu 24.04);tests/test_program_load_wait.pypasses with its fixture's two new counters, andtests/test_module_ids.pyandtests/test_switch_table.pypass.Suite:
tests/run_all.pywith every check on main @068fb8ebin WSL Ubuntu 24.04 (740 pass, 61 fail, 69 skipped: no clang or spirv-val there), then this head's--changedchecks in WSL (51 pass, 6 fail, 3 skipped) and on Windows (55 run, 9 fail). Every failure also fails on main @068fb8ebon the same OS: in WSL and on Windowstest_crash_dialog,test_dev_ab,test_frame_overlap,test_linux_pressure,test_present_queue_default,test_vk_occlusion_queries; on Windows onlytest_driver_env_choose,test_mesh_fallback_layout,test_native_float_atomic_add. (On Windows the changed checks ran on the head before its last test fixes;test_loaded_modules_dropwere run again on this head and passed, as in WSL.) (On Windows most of them are compile errors with this PC's compiler wrapper, on main as here.) These ran on the head as it was on main @068fb8eb; it was then rebased onto main @3f2c9b3c, whose two new commits change only the NFC menu (gpu/vk/menu/nfc.cppand its test), none of this PR's files.Still to test:
RX_VK_DROP_LOADED_MODULES=0against unset, expecting about 1 GB less private memory unset, and the loads at create and the frames the same (by hand)Measurements
Verdict: about 1.3 GB less working set and private memory in the Market on this PC, with the steady frames, the loads at create and the tour's pictures the same; the tour, one a side, peaked 2.1 GB lower. The remake path was not needed in any run.
Setup: Windows 11 Pro 26200, RTX 4070 SUPER 12 GB (NVIDIA 617.42), Ryzen 9 9950X3D with SMT off, 32 GB; from
kokiri-start, a teleport to the Market and 150 s there (the working set's median over the last third of the log's memory lines, frames over the last 100 s), and a teleport tour of 7 areas, 20 s each; 2560x1440, no window (HOS_HEADLESS=1), uncapped, 16 cores; in both armsRX_VK_LOAD=create RX_VK_ASTC_BC_ALL=1 RX_VK_IMAGE_BLOCK_MB=32 RX_VK_BC_LAYERS=8 RX_VK_LATE_FIX=1 RX_VK_TEX_MOVE=1 RX_VK_TEX_AHEAD=2 HOS_NVN_FRAME_OVERLAP=1 RX_VK_FRAME_TRACE=1.Baseline: builds of main @
f505340b(before the tooling revamp068fb8eb, which changes none of this code) with #1810-#1813's changes, this change and the pipeline cache's Windows rule (its own PR, #1845). Before:RX_VK_DROP_LOADED_MODULES=0 RX_VK_PCACHE_LOAD=1, main's behaviour on this PC, on a build that also held the temporary census (off) and that rule without its RAM limit (overridden by=1). After: the final build at its defaults, which on this 32 GB PC reads the pipeline cache file as main does. The two sides' stands were not interleaved.RX_VK_DROP_LOADED_MODULES=0(as main) @f505340bf505340bThe stands' mean frame, after against before: -0.004 ms (95 % interval -0.033 to +0.027). The tour is one run a side: its frame rows are within run to run, not a claim.
RX_VK_DROP_LOADED_MODULES(new, a kill switch) ships on, chosen by the stands above: less memory, nothing slower;=0keeps the modules for the session, as on main.Risks
What could break: a draw that needs a new pipeline state of a program whose modules went waits for its worker to read the stages back and make them (a file read and two module creates), and gets no quick pipeline meanwhile, so it is left out or waits as for any full build; this path is the one Linux's release has used since #223, but it did not run in these Windows runs (0 made again). #1809 (open) moves the SPIR-V to a shared store; the remake reads it through the program cache's own reader, so whichever lands second adapts that one call. Turning it off:
RX_VK_DROP_LOADED_MODULES=0. After updating, a player on Windows with NVIDIA has about 1 GB less of the game in RAM; nothing changes for saves,longshot_options.inior the caches.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. (Two stands and one tour a side, not interleaved, on a build of main @f505340bwith four open PRs' changes, as Baseline says.)third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.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
Possibly related, for context:
WIP: perf(vk): the load at create lets a program's shader modules go once its noted pipelines are built (RX_VK_DROP_LOADED_MODULES)to perf(vk): the load at create lets a program's shader modules go once its noted pipelines are built (RX_VK_DROP_LOADED_MODULES)