perf(vk): let go of the shader modules of ready programs after the start on Windows too, on request (#1474) #1488
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!1488
Loading…
Reference in a new issue
No description provided.
Delete branch "mooki/Longshot:perf/windows-drop-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?
Type: perf · Risk: low · Tested on: Linux, RTX 4090 (the shared path; no Windows PC has run it) · Needs: Windows, Intel Arc or any GPU, for the follow-up measurement
TL;DR
Since #223 Linux lets go of the shader modules of ready programs after the start-up precompile. This PR makes that release work on Windows too, but only on request: on Windows nothing is let go unless
RX_VK_DROP_MODULES=1is set, so no Windows player's behaviour changes. One tested function now decides for both systems (Linux's rule is as it was), the log says why, and the Intel owed-build guard keeps the compute module a later optimized build needs. Making it the Windows default waits for a controlled Windows keep/drop comparison.Breakdown
RX_VK_DROP_MODULES=1(private commit ends long sessions on 16 GB PCs, #1474), and the follow-up that measures it.#ifdef __linux__, driven by/proc/meminfo, and the call that notes which programs' pipelines the precompile built was Linux's too, soRX_VK_DROP_MODULES=1did nothing on Windows.gpu/vk/module_drop.h) for both systems. On Windows it keeps every module unlessRX_VK_DROP_MODULES=1forces the release; the RAM line and the commit-headroom shortfall are read for the log and for a later default, not acted on. The log names the reason.RX_VK_LOAD=createstart, where few modules exist at the start to let go.RX_VK_DROP_MODULES=1. Reverting the commits restores the old behaviour.Why
#1474 asks for Linux's module release (#223) on Windows, where private commit is what ends long sessions on 16 GB PCs. The review of the first version of this PR (default on for 20 GB of RAM or less) asked for a Windows measurement before such a default; none exists yet, so this version makes the release opt-in. Refs #1474.
What changed
On Windows the shader-module release now exists but is off unless asked for: one pure rule decides for both systems,
RX_VK_DROP_MODULES=1is the only way to let the modules go on Windows, and Linux keeps its rule. The rest is what that needed (the Windows readers, the program cache's counters, the Intel owed-build guard) and the docs.gpu/vk/module_drop.h(new, pure):decide()andsay()for both systems,by_default()for the device policy. Windows has its own input: with no switch the answer is "kept: opt-in until measured". Switch order as on Linux: the preparation process and left-over precompile workers keep,RX_VK_KEEP_MODULESkeeps,RX_VK_DROP_MODULESforces.gpu/vk/vk_draw.cpp:pipeline_cache_playasks the rule on both systems and logs the reason, the unchangedN shader modules let goline, and the release time with the process's private memory across it;precompile_runnotes built programs on Windows too;malloc_trimstays glibc-only (Windows runs nothing: the modules live in the driver's heap, whichHeapCompactwould not reach).gpu/vk/vk_progcache.cpp: the drop keeps a compute module while its optimized build is still owed (Intel's quick compute builds, Windows); remake counters.gpu/vk/vk_texture.cpp: Windows readers for the log (RAM, commit headroom under the commit reserve, private bytes), reusing the texture budget's own headroom reader.gpu/vk/device_policy.h: the policy field followsmodule_drop::by_default(Linux with 20 GB or less; never on Windows).gpu/vk/switches.defanddocs/development.md: rows say Windows is opt-in.tests/module_drop_test.cppandtests/test_module_drop.py(new: the rule, the Windows opt-in cases and the source needles),tests/test_device_policy.py(the Windows rows are false again;by_defaultedges),linux_pressure_test.cpp,test_commit_room.cppandtest_linux_pressure.pyupdated, none weakened.get_pipelinealso callsprogram_cache_complete_graphicson the replay thread withRX_VK_SYNC_PIPELINES=1and before the optional graphics-pipeline-library link (RX_VK_GPL=1), and the file read andvkCreateShaderModuleare then replay-thread work. The development guide says so.Measurements
Verdict: Windows: not run yet: the case is staged on the Intel Arc laptop for tonight's run. Nothing here is a speed or memory claim. The default on Windows is unchanged (everything is kept unless
RX_VK_DROP_MODULES=1, as the rule's test shows; no Windows PC has run it), so there is nothing to measure for players who do not opt in. Linux, one run each beside another game: this PR lets go of the same modules as main (50,196 and 50,190, the 6 being 3 more programs in this PR's precompile), 3 of the 22,509 let-go programs were made again in 3.8 ms and none could not be made again, exit 0, no kernel lines.Hardware: Linux, RTX 4090, NVIDIA 615.78.08, i9-13900K, 96 GB; beside another game (side lane,
RX_VK_VRAM_MB=9000): ordinary runs, observationsScene: Kokiri Forest (child) save, then 8 teleports (Hyrule Field, Castle Town, Kakariko Village, Kokiri Forest, twice)
Method: log lines counted by a script, one run each: no speed or memory claim
How to reproduce: a copy of each build with a prepared cache, then
RX_VK_LOAD=start RX_VK_PRECOMPILE=1 RX_VK_DROP_MODULES=1 RX_VK_LOG_PROGRAM_LIFE=1on this PR and on mainRX_VK_LOAD=start,RX_VK_DROP_MODULES=1310e7c9dfc3239a09ashader modules let go after the precompile: RX_VK_DROP_MODULES=1 lets them gomalloc_trimon Linux)Other runs of this head (observations beside another game; one run each):
c3239a09aRX_VK_DROP_MODULES=1, default load (create)RX_VK_DROP_MODULES=1 lets them gokept: 96233 MB of RAM, more than 20480 MB, and nothing shortRX_VK_LOAD=start,RX_VK_KEEP_MODULES=1kept: RX_VK_KEEP_MODULES=1 keeps themWhat this shows: on Linux this PR lets go of the modules of the programs its precompile built, as main does, through the shared rule: 50,196 modules against 50,190, the 6 being 3 more programs in this PR's precompile (27,118 against 27,115, two modules each). The two copies' caches had each had their own warm route run before, which I take to be why (not checked in the cache files). The new lines say why (the decision line), how long the release took and what the private memory did across it (10,455 -> 6,236 MB,
malloc_trimincluded: the game's own numbers, an observation); 3 of the 22,509 let-go programs were made again by the route, in 3.8 ms, and none could not be made again (main prints no such line). The run that keeps every module held about 11 GB at its first memory line against about 6.9 GB for the two drop runs, beside another game with a different load: an observation. Its frame figures are lower (mean 46.9 against about 65) while the load average went from 12.3 to 22.8; one run, no speed claim, and its log has 2vcores: ... ran without a core after 2000 mslines (the game's own thread scheduler) that the other four have none of. The draws left out and the waits at close (1,089 and none on this PR, 4,944 and 1 on main) are counts of one run each that depend on timing and load, so I read them as neither a gain nor a cost. The default-load runs let go nothing (no precompile at the start), so the one 217.7 ms first-use wait of the switch-on run is not the release's; the run with nothing set had none. The picture shows the end of laps 1 and 2 of this PR with the switch, main, and this PR keeping every module: the same dark cave, rock faces, ground and HUD draw alike (in the last keep picture the camera is closer to Link), with no black patches, stripes or missing tiles. Thekernel.txtof all five runs is empty and their summaries say kernel=0 and nvrm=0 with the journal window complete.Main's line in the same run's place:
vk: programs: 50190 shader modules let go after the precompile (RX_VK_KEEP_MODULES=1 keeps them). The five run summaries, whole except the local path of the one folder the tools write outside the run (left out); the load averages are the machine's, not the game's:Flags and settings
RX_VK_DROP_MODULESandRX_VK_KEEP_MODULESchange meaning on Windows (no new switch).RX_VK_DROP_MODULES=0/1RX_VK_KEEP_MODULES=1Testing
Tested: on this PC (Linux, RTX 4090), game-free: the rule's test fails on the previous head and passes here (19 mutants of the first version were killed; the opt-in cases are new); the whole suite on this head and on main: this head 707 passed, 44 failed, 17 skipped, main @
310e7c9df705 passed, 45 failed, 17 skipped, every one of this head's 44 failing names also failing on main (named in the checklist); the Windows-target syntax check (llvm-mingw,-Werror): the newtests/module_drop_test.cpppasses it,test_commit_room's fixture (9 errors, the CRT's deprecatedmemcpy) andtest_device_policy's (2 errors, deprecatedgetenvingpu/vk/compat/longshot_env.h) fail it the same way on main, andtest_linux_pressure's driver stops at the stale needlepool_pressed = true;that also fails it in the suite on main; Windows cross-builds of this head and of main (llvm-mingw clang 23.1.5, a fresh lift of each): both link the renderer DLL and the executable, 66 of 66 host units compiled, 0 warnings, never run on Windows; the game on Linux, windowless, in the side lane beside another game (ordinary runs, counts, log lines and pictures): five runs of two laps each, this PR and main withRX_VK_DROP_MODULES=1atRX_VK_LOAD=start, this PR withRX_VK_KEEP_MODULES=1atRX_VK_LOAD=start, and this PR at the default load with the switch and with nothing set; all five exited 0 with no fatal, crash, device-lost or kernel lines (Measurements has the counts and the picture). How, step by step: the tests were written first and run over the previous source (they fail to build there); the rule's fixture, the policy test and the source test ran green with g++ and clang++; the whole suite ran in clean worktrees of the same layout; the game ran from a copy of a local save through the workbench's run wrapper (windowless, GPU gate) and its lap driver, which teleports over the control bridge (docs/control.md); the public tools are in ls-workbench, the private ones are the GPU gate, the idle gate and the hold chain.Not testable by hand: the Windows trigger and remake: no Windows PC is here. The laptop case (A/B/A/B of
RX_VK_DROP_MODULES=1againstRX_VK_KEEP_MODULES=1on this head, main once, private commit, working set and commit headroom every 3 s, pictures at fixed points) is staged on the Intel Arc laptop for tonight's run and has not been run.Not tested: Windows execution of the new fixtures (syntax-checked only), Windows memory, remake cost and replay-thread placement, Intel's owed optimized build in the game, AMD and NVIDIA on Windows.
Must be tested:
RX_VK_DROP_MODULES=1againstRX_VK_KEEP_MODULES=1on this head and main once, expecting a log line that names the reason, N modules let go withRX_VK_LOAD=start, private memory before and after the release, and nocould not be made again(by hand: the owner runs the case and reads those lines)RX_VK_DROP_MODULES=1, expecting private commit lower with it, no left-out draws beyond main's and nocould not be made again, before the release becomes the Windows default (by hand: the tester reads the log lines and the commit numbers)Risks
What could break: only with
RX_VK_DROP_MODULES=1on Windows: a new state of a let-go program has no unoptimized pipeline to draw with until the worker has read its modules again and built the full one (omitted draws; replay-thread reads withRX_VK_SYNC_PIPELINES=1orRX_VK_GPL=1); the drop holds the program table's locks while it destroys the modules (a start-up pause, shown by therelease tookline); the memory may not return to Windows if the driver keeps it. Intel Windows: the owed-build guard keeps some modules.Turning it off: leave
RX_VK_DROP_MODULESunset (the Windows default), orRX_VK_KEEP_MODULES=1, or revert the commits.Compatibility: Nothing changes for saves, options, caches or the program cache's format (the translator stamp is unchanged).
Overlaps: #223 (merged: the Linux mechanism), #416 (merged: the cache-file rule, #1474's second change, not here), #1339, #789, #902, #737, #801 (open: no shared lines found; #737 moves cache-file storage, so the remake's record check needs a look if it lands), #966 (a fixture line in
tests/test_linux_pressure.py: take both edits).Issues
Refs #1474.
Checklist
Everyone
type(scope): description) of the status line's type.c3239a09aran in the game on Linux, five windowless runs beside main's; Windows has not run it.)RX_VK_DROP_MODULES=1, as the rule's test shows; no Windows PC has run it. Linux's rule is unchanged: the Linux runs let go of the same modules as main (50,196 and 50,190, the 6 being 3 more programs in this PR's precompile), made 3 programs' modules again with 0 failing, exited 0 and showed no kernel lines. What the switch could cost on Windows is in Risks and untested.)main(main @310e7c9df, where the game runs were made; it merges with main @4b68c42bewithout a conflict).python -I -B tests/run_all.pypasses (any failure that also fails onmainis named). (Strict, 6 at once, clean worktrees of the same layout: this head 707 passed, 44 failed, 17 skipped; main @310e7c9df705 passed, 45 failed, 17 skipped. All 44 of this head's failing names fail on main too: test_bug_report_defaults, test_compute_warm_apart, test_cpu_report, test_crash_record, test_crt_options, test_damage_debug_menu, test_dev_packs, test_display_startup_failure, test_dlss_feature_size, test_draw_stream_visibility, test_failed_compile_keeps_objects, test_fsr_image_retirement, test_fsr_uniform_ownership, test_guest_imported, test_hud_layout_row, test_import_reach, test_invalidate_quick, test_invalidate_vcore, test_libc_hooks, test_linux_preflight, test_linux_pressure, test_linux_update, test_log_open_failure, test_mirror_budget, test_missing_nup, test_mods_size_table, test_nonuniform_image_arrays, test_parallel_init_order, test_pending_guest_import, test_pipeline_play_cache, test_present_thread, test_profiling_mode, test_psychov35_fsr3_fg, test_readback_timeout_source, test_replay_write_order, test_run_all_changed, test_slow_frames, test_staging_burst, test_switch_table, test_target_image_pool, test_upscaler_rows, test_vcore_escape, test_vk_occlusion_queries, test_walk_key. Main's 45th, test_prepare_stall, is a load-sensitive timing test: it failed there in the whole run (itsbusy-compile-intelcase, load average 20 to 36) and, run alone at a load average of 80 to 110, it fails on main (busy-compile-intel) and on this head (busy-compile) alike. test_crash_record fails in both whole runs because their launcher left SIGHUP ignored; it passes alone on both. test_linux_pressure fails on both at main's stale needlepool_pressed = true;before reaching any drop check, so its fixture and the source needles this PR updates were run on their own on this head: both pass. test_switch_table fails on both with the same eight lines, none about this PR's switches.)third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
Assisted-by:/Co-Authored-By:trailers.mainand passing here.tests/that reads changed source updated in this PR, not weakened.c3239a09aand main310e7c9dfeach link the renderer DLL and the executable, 66 of 66 host units compiled, 0 warnings (main 521 units, 274 new; head 521 units, 106 new); never run on Windows. The Linux copies of both built and ran windowless, below. The paths code is not changed: the remake reuses the program cache's own file name and opens.)New on this forge; not opened on GitHub.
Verdict: Request changes. The shared policy and Intel owed-build guard look sound, but enabling module release by default on Windows still has no Windows measurement of memory saved or the reconstruction cost. Keep the stated performance gate open until that tradeoff is established; the Linux observations cannot establish it for Windows drivers.
This targets private-commit exhaustion on smaller Windows PCs by destroying shader modules after their startup pipelines have been built. The benefit is plausible, but Windows may retain the driver's allocation, while a later pipeline state must read and recreate modules and can wait or omit draws. No new concrete lifetime defect was found in the changed code.
Reviewed:
e3628fd319against merge basee9da93b6f8. Read every changed production hunk in the 11 renderer/header/switch files, all six changed/new test files where changed (the new policy header and both new fixtures in full), and the development-guide change. Traced precompile publication/join and abandoned-worker handling, both startup call sites, graphics remake callers including GPL/synchronous paths, compute_optimize and its first-dispatch handoff, the existing drop/remake implementation and locks, Windows RAM/commit readers, and private-memory reporting. Compared relevant drift against current main310e7c9dfa. Read the description and available review/comment/check records; no earlier review was present. Nothing run: no tests, builds, generators or game launches.Fixed in this review: nothing.
Checked and fine: Linux switch precedence and the 20 GiB/shortfall policy are preserved; preparation and abandoned precompile workers prevent release even with the force switch. Windows uses the existing commit-headroom/growth reader and reserve rather than a second budget definition, and reserve zero contributes no shortfall. Program::optimize_owed prevents dropping the compute module needed by Intel's later optimized build. Built graphics variants are now noted on Windows; unnoted variants and unreconstructible stages retain their modules. The remake table distinguishes program identity as well as key/variant, and existing shader_mu -> light_mu -> remake-mu ordering is preserved. Counter additions are atomic and do not change Program/Stage layout, cache format, translator stamp or renderer ABI. Existing options retain a keep/off escape hatch. Tests cover decision boundaries, switches, preparation guards, shortfall arithmetic, successful/failed remakes and owed-compute retention.
Blocking
gpu/vk/module_drop.h:69(fed on Windows by pipeline_cache_play): establish the new Windows default's gain and cost before marking this ready. A <=20 GiB Windows startup using the full-load/precompile path will destroy modules without any Windows evidence that private commit falls, or that later reconstruction does not introduce unacceptable waits or omitted draws. The author correctly leaves the no-regression box unticked and explicitly lists these unknowns. Run the planned controlled Windows keep/drop comparison on this head with pinned caches/settings/route and interleaved repeats; report private commit/working set and commit headroom, release duration, remake failures/time, first-use waits/omitted draws, frame-time medians/tails and visual integrity. Include the natural default on a 16 GiB PC and the Intel owed-optimized-build case. A larger-RAM PC forcing the switch is useful mechanism coverage but does not validate the small-RAM default. If that evidence cannot be obtained yet, retain the old Windows default and keep the Windows release opt-in until it can. This is an evidence/default-policy blocker, not an assertion that a regression has been observed.Suggestions
Testing: Author reports the new policy test failing on main and passing here with 19 mutations caught; the same full-suite failing-name set on Linux (686 passed/42 failed/17 skipped versus main 685/42/17), Windows-target syntax checks with explicitly inherited failures/unjudged cases, and full Windows cross-build/link with no warnings. Five Linux runs beside another game include the same 50,190 dropped modules as main, four of 22,506 programs reconstructed, and no reconstruction failures. Four runs ended cleanly; one was killed at its wall. The loaded-machine runs are honestly labelled observations, not speed or memory comparisons: the 295.1 ms versus 7.6 ms first-use-wait totals do not establish causation or a reliable delta. Windows execution, reclaimed commit, frame pacing and Intel's optimized compute path remain untested. I ran nothing. Cached checks show a failed Guide screenshots status, pending description check and skipped Python source jobs, so no green merge gate is claimed. The WIP state is appropriate while the Windows cost gate is unresolved.
Overlaps and merge order: 1474 tracks the Windows memory proposal. This extends the Linux mechanism from 223, rather than duplicating it; the pipeline-cache-file rule in 416 is separate. 737 moves cache-file storage, so preserve the remake's record validation and verify reconstruction against the combined cache lifecycle if it lands. The author identifies 966 as a fixture-overlap follow-up; it was not independently trial-merged in this review. No independent competing module-release PR was found in the current search.
@ -0,0 +66,4 @@if (in.workers_left) return {false, Why::kWorkersLeft};if (in.keep_env && *in.keep_env && !off_word(in.keep_env)) return {false, Why::kKeepSwitch};if (in.drop_env && *in.drop_env) return off_word(in.drop_env) ? Decision{false, Why::kDropOff} : Decision{true, Why::kDropSwitch};if (small_ram(in.ram_bytes)) return {true, Why::kSmallRam};Establish the new Windows default's memory/reconstruction tradeoff before marking ready. This now drops modules on <=20 GiB Windows PCs, but no Windows run establishes reclaimed private commit or the cost of later remakes/waits/omitted draws. Please complete the controlled keep/drop Windows comparison with pinned caches/route/settings and interleaved repeats, including natural 16 GiB default and Intel owed-compute coverage. Otherwise keep Windows opt-in until measured. The description correctly leaves its no-regression box open; Linux loaded-machine observations cannot close this Windows gate. No regression is asserted as observed.
e3628fd319c3239a09a7WIP: perf(vk): on Windows, the shader modules of ready programs are let go after the start on PCs with 20 GB of RAM or lessto perf(vk): let go of the shader modules of ready programs after the start on Windows too, on request (#1474)Pushed
c3239a09a(rebased onto main at310e7c9df; it merges with today's main at4b68c42bewithout a conflict). Windows now keeps every shader module by default;RX_VK_DROP_MODULES=1is the opt-in, as the review suggested. Linux is unchanged.gpu/vk/module_drop.h) has a Windows input: with no switch set it keeps and says why (on Windows the release is opt-in until it is measured there).RX_VK_DROP_MODULES=1lets the modules go;RX_VK_KEEP_MODULES=1,RX_VK_DROP_MODULES=0, the preparation process and the left-over precompile workers keep them, as before.device_policy.h's field follows the same function (module_drop::by_default), so no Windows PC gets the release by default.switches.defrows and the development guide say Windows is opt-in, and that a remake can run on the replay thread withRX_VK_SYNC_PIPELINES=1and before the optional GPL link.RX_VK_LOAD=startwithRX_VK_DROP_MODULES=1): this PR lets go of the same modules as main (50,196 against 50,190; its precompile read 3 more programs), 3 of 22,509 let-go programs were made again in 3.8 ms and none could not be made again, exit 0, no kernel lines; the table and picture are in the description. The whole suite fails 44 names on this head, all also failing on main (45 there). Both trees cross-build for Windows (they link, 0 warnings); nothing has run on Windows yet, the Intel Arc laptop case is staged for tonight.Windows default-on is a follow-up after the controlled Windows keep/drop comparison.
Thank you for the careful review, and for reading the Windows paths this closely.
I took the opt-in route from your review. On Windows nothing is let go after the precompile unless
RX_VK_DROP_MODULES=1is set; the RAM line and the commit-headroom shortfall no longer decide anything there. Linux behaves exactly as on main.RX_VK_KEEP_MODULES=1and the shader preparation's own guards still win over the switch, and the Intel owed-build guard, the shared rule and the counters stay as they were. The new log reason on Windows says that the release is opt-in until it is measured there.I also put your suggestion into the development guide and the description: reconstruction is usually on a worker, but
get_pipelinecallsprogram_cache_complete_graphicson the replay thread withRX_VK_SYNC_PIPELINES=1and before the optional graphics-pipeline-library link, so the file read andvkCreateShaderModulecan then be replay-thread work.Making the release the Windows default becomes a follow-up PR, after the controlled Windows keep/drop comparison you describe: pinned caches, settings and route, interleaved repeats, private commit, working set and commit headroom, release time, remake failures and time, first-use waits and omitted draws, frame-time medians and tails, and pictures, including a natural 16 GiB PC and an Intel owed-compute run. The Intel Arc laptop will run that plan from the prepared case. Until then this PR only makes the switch work on Windows.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.