perf(vk): let go of the shader modules of ready programs after the start on Windows too, on request (#1474) #1488

Open
mooki wants to merge 4 commits from mooki/Longshot:perf/windows-drop-modules into main
Member

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=1 is 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

  • Who it helps: Windows testers and players who opt in with RX_VK_DROP_MODULES=1 (private commit ends long sessions on 16 GB PCs, #1474), and the follow-up that measures it.
  • What was wrong: the release sat inside #ifdef __linux__, driven by /proc/meminfo, and the call that notes which programs' pipelines the precompile built was Linux's too, so RX_VK_DROP_MODULES=1 did nothing on Windows.
  • What changes: one rule (gpu/vk/module_drop.h) for both systems. On Windows it keeps every module unless RX_VK_DROP_MODULES=1 forces 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.
  • What does not change: Linux's rule and defaults; Windows' default; the program cache's format and the translator stamp; the default RX_VK_LOAD=create start, where few modules exist at the start to let go.
  • How it was checked: game-free tests that fail on the previous head and pass here; the whole suite on this head and on main (every failing name of this head also fails on main); Windows cross-builds of this head and of main (both link, 0 warnings; nothing has run on Windows); and five windowless Linux runs of the game beside another game: this PR and main let go of the same modules (50,196 and 50,190, the 6 being 3 more programs in this PR's precompile), 3 programs' modules were made again and none could not be, every run exited 0 with no kernel lines. No Windows PC has run it.
  • What is still open: what Windows frees (private commit, working set, commit headroom), the cost of remakes, first-use waits and omitted draws for new states of let-go programs, on a real Windows PC. Making the release the Windows default is a follow-up.
  • Risk: low. Nothing changes unless a Windows tester sets 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=1 is 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() and say() 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_MODULES keeps, RX_VK_DROP_MODULES forces.
  • gpu/vk/vk_draw.cpp: pipeline_cache_play asks the rule on both systems and logs the reason, the unchanged N shader modules let go line, and the release time with the process's private memory across it; precompile_run notes built programs on Windows too; malloc_trim stays glibc-only (Windows runs nothing: the modules live in the driver's heap, which HeapCompact would 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 follows module_drop::by_default (Linux with 20 GB or less; never on Windows). gpu/vk/switches.def and docs/development.md: rows say Windows is opt-in.
  • tests: tests/module_drop_test.cpp and tests/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_default edges), linux_pressure_test.cpp, test_commit_room.cpp and test_linux_pressure.py updated, none weakened.
  • Where a remake runs: usually on a worker, in the job a new pipeline state queues. get_pipeline also calls program_cache_complete_graphics on the replay thread with RX_VK_SYNC_PIPELINES=1 and before the optional graphics-pipeline-library link (RX_VK_GPL=1), and the file read and vkCreateShaderModule are 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, observations
Scene: 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=1 on this PR and on main

RX_VK_LOAD=start, RX_VK_DROP_MODULES=1 Before: main @ 310e7c9df After: this PR @ c3239a09a
programs the precompile built; graphics and compute pipelines 27,115; 32,441 and 3,656 27,118; 32,448 and 3,656
modules let go (the existing line) 50,190 50,196
the decision line none (main has none) shader modules let go after the precompile: RX_VK_DROP_MODULES=1 lets them go
the release took; private memory across it (includes glibc's malloc_trim on Linux) no line 161.0 ms; 10,455 -> 6,236 MB
programs let go / made again by play / could not be made again (at close) no line 22,509 / 3 (3.8 ms) / 0
draws and dispatches left out; first-use waits (at close) 4,944; 1 (5.0 ms) 1,089; 0 (0.0 ms)
private memory at the first and last 600-present line (MB) 6,867 -> 7,600 6,865 -> 7,599
run health exit 0; fatal, crash, device lost, nocore, kernel, NVRM 0 the same

Other runs of this head (observations beside another game; one run each):

this PR @ c3239a09a decision line modules let go private memory at the first and last 600-present line (MB) draws left out; waits (at close)
RX_VK_DROP_MODULES=1, default load (create) RX_VK_DROP_MODULES=1 lets them go none printed (no precompile at the start in this mode) 2,916 -> 5,097 6; 1 (217.7 ms)
unset, default load kept: 96233 MB of RAM, more than 20480 MB, and nothing short none 2,914 -> 5,128 0; 0 (0.0 ms)
RX_VK_LOAD=start, RX_VK_KEEP_MODULES=1 kept: RX_VK_KEEP_MODULES=1 keeps them none 11,064 -> 9,656 4; 2 (14.6 ms)

What 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_trim included: 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 2 vcores: ... ran without a core after 2000 ms lines (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. The kernel.txt of all five runs is empty and their summaries say kernel=0 and nvrm=0 with the journal window complete.

vk: programs: shader modules let go after the precompile: RX_VK_DROP_MODULES=1 lets them go
vk: programs: 50196 shader modules let go after the precompile (RX_VK_KEEP_MODULES=1 keeps them)
vk: programs: the release took 161.0 ms, and the process's private memory went 10455 -> 6236 MB across it (glibc's malloc_trim included; Windows has none)
vk: shader modules let go after the precompile (close): 22509 programs' graphics modules were let go, 3 made again by play (3.8 ms reading and making them), 0 could not be made again (their new pipeline states are left out)
vk: programs: shader modules kept after the precompile: 96233 MB of RAM, more than 20480 MB, and nothing short (RX_VK_DROP_MODULES=1 lets them go)
vk: programs: shader modules kept after the precompile: RX_VK_KEEP_MODULES=1 keeps them

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:

win1474-head-drop-start-194444 exit=0 wall=122.8s span=113.1s from=0s frames=7412(headless-renderer) mean=65.5 low1=9.9 over16.7=2956 over20=749 over25=300 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 8.19 20.06 27.54 -> 9.59 16.81 25.42 journal=complete
win1474-base-drop-start-194749 exit=0 wall=120.1s span=110.0s from=0s frames=7013(headless-renderer) mean=63.8 low1=9.1 over16.7=2917 over20=934 over25=424 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 9.59 16.81 25.42 -> 11.56 15.61 23.95 journal=complete
win1474-head-drop-create-194949 exit=0 wall=116.5s span=110.1s from=0s frames=7129(headless-renderer) mean=64.8 low1=9.2 over16.7=2883 over20=632 over25=245 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 11.56 15.61 23.95 -> 13.60 14.67 22.61 journal=complete
win1474-head-unset-create-195147 exit=0 wall=117.4s span=110.5s from=0s frames=7095(headless-renderer) mean=64.2 low1=9.0 over16.7=2962 over20=759 over25=288 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 13.60 14.67 22.61 -> 12.31 13.47 21.18 journal=complete
win1474-head-keep-start-195345 exit=0 wall=126.2s span=116.2s from=0s frames=5446(headless-renderer) mean=46.9 low1=3.9 over16.7=3017 over20=1155 over25=579 shots=0 - 0.0MB fatal=0 crash=0 devlost=0 nocore=2 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 12.31 13.47 21.18 -> 22.84 19.36 22.56 journal=complete

The end of laps 1 and 2 of three Linux runs beside another game (side lane), the same dark place after the route: 1 and 4 this PR with RX_VK_DROP_MODULES=1 and every program loaded at the start; 2 and 5 main with the same switches; 3 and 6 this PR with RX_VK_KEEP_MODULES=1 (the camera is closer to Link in 6). No black patches, stripes or missing tiles in any.

Flags and settings

RX_VK_DROP_MODULES and RX_VK_KEEP_MODULES change meaning on Windows (no new switch).

Flag What it is Before this PR After this PR Effect Helps / doesn't help / untested Recommendation
RX_VK_DROP_MODULES=0/1 forces the release (1) or keeps (0) Linux only Linux; Windows too, and there it is the only way to let them go the modules of programs whose pipelines the precompile built are destroyed after the start untested on Windows unset: Linux's rule decides; Windows keeps
RX_VK_KEEP_MODULES=1 keeps every module Linux only Linux and Windows none let go untested on Windows for an A/B only

Testing

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 @ 310e7c9df 705 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 new tests/module_drop_test.cpp passes it, test_commit_room's fixture (9 errors, the CRT's deprecated memcpy) and test_device_policy's (2 errors, deprecated getenv in gpu/vk/compat/longshot_env.h) fail it the same way on main, and test_linux_pressure's driver stops at the stale needle pool_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 with RX_VK_DROP_MODULES=1 at RX_VK_LOAD=start, this PR with RX_VK_KEEP_MODULES=1 at RX_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=1 against RX_VK_KEEP_MODULES=1 on 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:

  • Windows 11, Intel Arc (64 GB): the laptop case's plan, RX_VK_DROP_MODULES=1 against RX_VK_KEEP_MODULES=1 on this head and main once, expecting a log line that names the reason, N modules let go with RX_VK_LOAD=start, private memory before and after the release, and no could not be made again (by hand: the owner runs the case and reads those lines)
  • Windows 11, a natural 16 GB PC with any GPU (and one Intel Arc run with owed optimized compute builds): play several areas with and without RX_VK_DROP_MODULES=1, expecting private commit lower with it, no left-out draws beyond main's and no could 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=1 on 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 with RX_VK_SYNC_PIPELINES=1 or RX_VK_GPL=1); the drop holds the program table's locks while it destroys the modules (a start-up pause, shown by the release took line); 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_MODULES unset (the Windows default), or RX_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

  • One topic.
  • The title is a Conventional Commit (type(scope): description) of the status line's type.
  • Why gives the reason plainly and links the issues that fit (the tracker searched).
  • Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand. (The final head c3239a09a ran in the game on Linux, five windowless runs beside main's; Windows has not run it.)
  • Measurements has a verdict, or one line saying why there is nothing to measure.
  • Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. (The Windows default is unchanged: the rule keeps every module unless 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.)
  • Testing names what was tested, what wasn't, and what must still be tested, where and how.
  • Rebased on current main (main @ 310e7c9df, where the game runs were made; it merges with main @ 4b68c42be without a conflict).
  • python -I -B tests/run_all.py passes (any failure that also fails on main is named). (Strict, 6 at once, clean worktrees of the same layout: this head 707 passed, 44 failed, 17 skipped; main @ 310e7c9df 705 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 (its busy-compile-intel case, 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 needle pool_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.)
  • No game files, dumps, build output or generated files.
  • third_party/ untouched (a new folder with a PROVENANCE.md instead).
  • The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.
  • Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value.
  • A game-free test added for the fix, failing on main and passing here.
  • A check under tests/ that reads changed source updated in this PR, not weakened.
  • Docs updated.
  • Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (llvm-mingw clang 23.1.5, a fresh Windows lift of each tree, lift identity equal: this head c3239a09a and main 310e7c9df each 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.

**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=1` is 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 - **Who it helps:** Windows testers and players who opt in with `RX_VK_DROP_MODULES=1` (private commit ends long sessions on 16 GB PCs, #1474), and the follow-up that measures it. - **What was wrong:** the release sat inside `#ifdef __linux__`, driven by `/proc/meminfo`, and the call that notes which programs' pipelines the precompile built was Linux's too, so `RX_VK_DROP_MODULES=1` did nothing on Windows. - **What changes:** one rule (`gpu/vk/module_drop.h`) for both systems. On Windows it keeps every module unless `RX_VK_DROP_MODULES=1` forces 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. - **What does not change:** Linux's rule and defaults; Windows' default; the program cache's format and the translator stamp; the default `RX_VK_LOAD=create` start, where few modules exist at the start to let go. - **How it was checked:** game-free tests that fail on the previous head and pass here; the whole suite on this head and on main (every failing name of this head also fails on main); Windows cross-builds of this head and of main (both link, 0 warnings; nothing has run on Windows); and five windowless Linux runs of the game beside another game: this PR and main let go of the same modules (50,196 and 50,190, the 6 being 3 more programs in this PR's precompile), 3 programs' modules were made again and none could not be, every run exited 0 with no kernel lines. No Windows PC has run it. - **What is still open:** what Windows frees (private commit, working set, commit headroom), the cost of remakes, first-use waits and omitted draws for new states of let-go programs, on a real Windows PC. Making the release the Windows default is a follow-up. - **Risk:** low. Nothing changes unless a Windows tester sets `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=1` is 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()` and `say()` 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_MODULES` keeps, `RX_VK_DROP_MODULES` forces. - `gpu/vk/vk_draw.cpp`: `pipeline_cache_play` asks the rule on both systems and logs the reason, the unchanged `N shader modules let go` line, and the release time with the process's private memory across it; `precompile_run` notes built programs on Windows too; `malloc_trim` stays glibc-only (Windows runs nothing: the modules live in the driver's heap, which `HeapCompact` would 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 follows `module_drop::by_default` (Linux with 20 GB or less; never on Windows). `gpu/vk/switches.def` and `docs/development.md`: rows say Windows is opt-in. - tests: `tests/module_drop_test.cpp` and `tests/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_default` edges), `linux_pressure_test.cpp`, `test_commit_room.cpp` and `test_linux_pressure.py` updated, none weakened. - Where a remake runs: usually on a worker, in the job a new pipeline state queues. `get_pipeline` also calls `program_cache_complete_graphics` on the replay thread with `RX_VK_SYNC_PIPELINES=1` and before the optional graphics-pipeline-library link (`RX_VK_GPL=1`), and the file read and `vkCreateShaderModule` are 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, observations Scene: 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=1` on this PR and on main | `RX_VK_LOAD=start`, `RX_VK_DROP_MODULES=1` | Before: main @ 310e7c9df | After: this PR @ c3239a09a | |---|---|---| | programs the precompile built; graphics and compute pipelines | 27,115; 32,441 and 3,656 | 27,118; 32,448 and 3,656 | | modules let go (the existing line) | 50,190 | 50,196 | | the decision line | none (main has none) | `shader modules let go after the precompile: RX_VK_DROP_MODULES=1 lets them go` | | the release took; private memory across it (includes glibc's `malloc_trim` on Linux) | no line | 161.0 ms; 10,455 -> 6,236 MB | | programs let go / made again by play / could not be made again (at close) | no line | 22,509 / 3 (3.8 ms) / 0 | | draws and dispatches left out; first-use waits (at close) | 4,944; 1 (5.0 ms) | 1,089; 0 (0.0 ms) | | private memory at the first and last 600-present line (MB) | 6,867 -> 7,600 | 6,865 -> 7,599 | | run health | exit 0; fatal, crash, device lost, nocore, kernel, NVRM 0 | the same | Other runs of this head (observations beside another game; one run each): | this PR @ c3239a09a | decision line | modules let go | private memory at the first and last 600-present line (MB) | draws left out; waits (at close) | |---|---|---|---|---| | `RX_VK_DROP_MODULES=1`, default load (create) | `RX_VK_DROP_MODULES=1 lets them go` | none printed (no precompile at the start in this mode) | 2,916 -> 5,097 | 6; 1 (217.7 ms) | | unset, default load | `kept: 96233 MB of RAM, more than 20480 MB, and nothing short` | none | 2,914 -> 5,128 | 0; 0 (0.0 ms) | | `RX_VK_LOAD=start`, `RX_VK_KEEP_MODULES=1` | `kept: RX_VK_KEEP_MODULES=1 keeps them` | none | 11,064 -> 9,656 | 4; 2 (14.6 ms) | What 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_trim` included: 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 2 `vcores: ... ran without a core after 2000 ms` lines (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. The `kernel.txt` of all five runs is empty and their summaries say kernel=0 and nvrm=0 with the journal window complete. ``` vk: programs: shader modules let go after the precompile: RX_VK_DROP_MODULES=1 lets them go vk: programs: 50196 shader modules let go after the precompile (RX_VK_KEEP_MODULES=1 keeps them) vk: programs: the release took 161.0 ms, and the process's private memory went 10455 -> 6236 MB across it (glibc's malloc_trim included; Windows has none) vk: shader modules let go after the precompile (close): 22509 programs' graphics modules were let go, 3 made again by play (3.8 ms reading and making them), 0 could not be made again (their new pipeline states are left out) vk: programs: shader modules kept after the precompile: 96233 MB of RAM, more than 20480 MB, and nothing short (RX_VK_DROP_MODULES=1 lets them go) vk: programs: shader modules kept after the precompile: RX_VK_KEEP_MODULES=1 keeps them ``` 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: ``` win1474-head-drop-start-194444 exit=0 wall=122.8s span=113.1s from=0s frames=7412(headless-renderer) mean=65.5 low1=9.9 over16.7=2956 over20=749 over25=300 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 8.19 20.06 27.54 -> 9.59 16.81 25.42 journal=complete win1474-base-drop-start-194749 exit=0 wall=120.1s span=110.0s from=0s frames=7013(headless-renderer) mean=63.8 low1=9.1 over16.7=2917 over20=934 over25=424 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 9.59 16.81 25.42 -> 11.56 15.61 23.95 journal=complete win1474-head-drop-create-194949 exit=0 wall=116.5s span=110.1s from=0s frames=7129(headless-renderer) mean=64.8 low1=9.2 over16.7=2883 over20=632 over25=245 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 11.56 15.61 23.95 -> 13.60 14.67 22.61 journal=complete win1474-head-unset-create-195147 exit=0 wall=117.4s span=110.5s from=0s frames=7095(headless-renderer) mean=64.2 low1=9.0 over16.7=2962 over20=759 over25=288 shots=1 1280x720 2.8MB fatal=0 crash=0 devlost=0 nocore=0 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 13.60 14.67 22.61 -> 12.31 13.47 21.18 journal=complete win1474-head-keep-start-195345 exit=0 wall=126.2s span=116.2s from=0s frames=5446(headless-renderer) mean=46.9 low1=3.9 over16.7=3017 over20=1155 over25=579 shots=0 - 0.0MB fatal=0 crash=0 devlost=0 nocore=2 kernel=0 nvrm=0 dev=0:NVIDIA_GeForce_RTX_4090 load 12.31 13.47 21.18 -> 22.84 19.36 22.56 journal=complete ``` ![The end of laps 1 and 2 of three Linux runs beside another game (side lane), the same dark place after the route: 1 and 4 this PR with RX_VK_DROP_MODULES=1 and every program loaded at the start; 2 and 5 main with the same switches; 3 and 6 this PR with RX_VK_KEEP_MODULES=1 (the camera is closer to Link in 6). No black patches, stripes or missing tiles in any.](https://git.magicbean.dev/attachments/e9a89aa7-63b1-46a1-b568-5cf8fcc16ba2) ### Flags and settings `RX_VK_DROP_MODULES` and `RX_VK_KEEP_MODULES` change meaning on Windows (no new switch). | Flag | What it is | Before this PR | After this PR | Effect | Helps / doesn't help / untested | Recommendation | |---|---|---|---|---|---|---| | `RX_VK_DROP_MODULES=0/1` | forces the release (1) or keeps (0) | Linux only | Linux; Windows too, and there it is the only way to let them go | the modules of programs whose pipelines the precompile built are destroyed after the start | untested on Windows | unset: Linux's rule decides; Windows keeps | | `RX_VK_KEEP_MODULES=1` | keeps every module | Linux only | Linux and Windows | none let go | untested on Windows | for an A/B only | ## Testing **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 @ 310e7c9df 705 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 new `tests/module_drop_test.cpp` passes it, `test_commit_room`'s fixture (9 errors, the CRT's deprecated `memcpy`) and `test_device_policy`'s (2 errors, deprecated `getenv` in `gpu/vk/compat/longshot_env.h`) fail it the same way on main, and `test_linux_pressure`'s driver stops at the stale needle `pool_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 with `RX_VK_DROP_MODULES=1` at `RX_VK_LOAD=start`, this PR with `RX_VK_KEEP_MODULES=1` at `RX_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](https://github.com/mooki000/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=1` against `RX_VK_KEEP_MODULES=1` on 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:** - Windows 11, Intel Arc (64 GB): the laptop case's plan, `RX_VK_DROP_MODULES=1` against `RX_VK_KEEP_MODULES=1` on this head and main once, expecting a log line that names the reason, N modules let go with `RX_VK_LOAD=start`, private memory before and after the release, and no `could not be made again` (by hand: the owner runs the case and reads those lines) - Windows 11, a natural 16 GB PC with any GPU (and one Intel Arc run with owed optimized compute builds): play several areas with and without `RX_VK_DROP_MODULES=1`, expecting private commit lower with it, no left-out draws beyond main's and no `could 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=1` on 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 with `RX_VK_SYNC_PIPELINES=1` or `RX_VK_GPL=1`); the drop holds the program table's locks while it destroys the modules (a start-up pause, shown by the `release took` line); 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_MODULES` unset (the Windows default), or `RX_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 - [x] One topic. - [x] The title is a Conventional Commit (`type(scope): description`) of the status line's type. - [x] Why gives the reason plainly and links the issues that fit (the tracker searched). - [x] Tested on my own PC where it runs (in the game, for a change the game runs), as Testing's Tested says; what can't be run by hand is in Testing's Not testable by hand. (The final head c3239a09a ran in the game on Linux, five windowless runs beside main's; Windows has not run it.) - [x] Measurements has a verdict, or one line saying why there is nothing to measure. - [x] Nothing gets worse that I know of: any cost (speed, latency, memory, a setup that worked before) is measured and in Risks. (The Windows default is unchanged: the rule keeps every module unless `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.) - [x] Testing names what was tested, what wasn't, and what must still be tested, where and how. - [x] Rebased on current `main` (main @ 310e7c9df, where the game runs were made; it merges with main @ 4b68c42be without a conflict). - [x] `python -I -B tests/run_all.py` passes (any failure that also fails on `main` is named). (Strict, 6 at once, clean worktrees of the same layout: this head 707 passed, 44 failed, 17 skipped; main @ 310e7c9df 705 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 (its `busy-compile-intel` case, 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 needle `pool_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.) - [x] No game files, dumps, build output or generated files. - [x] `third_party/` untouched (a new folder with a `PROVENANCE.md` instead). - [x] The license is OK: GPL-3.0-or-later, nothing incompatible and nothing decompiled. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. - [x] Switches documented (docs/development.md; the README for a menu row) and shipped at their recommended value. - [x] A game-free test added for the fix, failing on `main` and passing here. - [x] A check under `tests/` that reads changed source updated in this PR, not weakened. - [x] Docs updated. - [x] Host code builds on both Windows (llvm-mingw) and Linux, with UTF-8 paths. (llvm-mingw clang 23.1.5, a fresh Windows lift of each tree, lift identity equal: this head c3239a09a and main 310e7c9df each 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.
Tests for #1474's first change, written before it and failing on main:

- tests/module_drop_test.cpp, run by tests/test_module_drop.py: the rule as a pure
  function (module_drop.h): the RAM line at 20 GB, a shortfall of any size (Windows'
  is how far the commit headroom is under the commit rule's reserve, commit_room.h
  short_by), RX_VK_DROP_MODULES and RX_VK_KEEP_MODULES with their off words and empty
  values, the shader preparation's guards, and the reason in words. The same file
  checks that pipeline_cache_play reads each OS's numbers, that precompile_run notes
  the programs it built on Windows too, and that the switch table and the docs say
  Windows.
- tests/linux_pressure_test.cpp: should_drop_modules' checks move to the new fixture;
  a compute module whose optimized build is still owed (Intel's quick compute builds,
  Windows) is kept by the drop. On main the drop destroys it.
- tests/test_device_policy.py: drop_modules_small_ram is on for the Windows PCs with
  20 GB of RAM or less, and the RAM line has its edges.
- tests/test_commit_room.cpp: short_by.

Assisted-by: Claude Sonnet 5.5
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
perf(vk): let go of the shader modules of ready programs after the start on Windows too (#1474)
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 9s
PR description / Description follows the template (pull_request_target) Successful in 14s
Website / Website on Cloudflare (pull_request_target) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
CI / Workflow lint (actionlint) (pull_request) Successful in 19s
Third-party parts / As their notes say (pull_request) Successful in 29s
e3628fd319
Windows kept every VkShaderModule the start-up precompile made: pipeline_cache_play
called program_cache_drop_modules only under #ifdef __linux__, with /proc/meminfo's
numbers, and program_cache_note_built, which says which programs' pipelines the
precompile built, was Linux's too, so RX_VK_DROP_MODULES=1 did nothing there.

- gpu/vk/module_drop.h: the rule, one pure function for both OSes (20 GB of RAM or
  less, or free memory already short at the start, RX_VK_DROP_MODULES forcing it,
  RX_VK_KEEP_MODULES keeping all, the shader preparation and builds left in the
  driver keeping all), and its reason in words. It replaces linux_pressure.h's
  should_drop_modules; device_policy.h's drop_modules_small_ram follows it.
- Windows' numbers are the textures' own: ullTotalPhys, and the commit headroom
  under RX_VK_COMMIT_RESERVE_MB (commit_headroom, now through commit_now and
  commit_room::short_by), so the release and the commit rule agree on "short".
- pipeline_cache_play asks the rule on both OSes, logs the reason, and says what the
  process's private memory did across the release. malloc_trim stays glibc's;
  Windows runs nothing in its place.
- precompile_run notes the programs it built on Windows too.
- program_cache_drop_modules keeps the module of a compute program whose optimized
  build is still owed (Intel's quick compute builds, Windows only: compute_optimize
  makes it from that module; Linux never owes one).
- The census says how many programs were let go and made again, and the time the
  remakes took.
- switches.def and docs/development.md: the three switches are not Linux's only.

Refs #1474

Assisted-by: Claude Sonnet 5.5
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
futondestroyer left a comment

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: e3628fd319 against merge base e9da93b6f8. 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 main 310e7c9dfa. 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

  1. 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

  • The description says reconstruction runs on a worker. That is the usual asynchronous path, but get_pipeline also calls program_cache_complete_graphics synchronously with RX_VK_SYNC_PIPELINES and before the optional GPL link. State that qualification and include the GPL path if it is in the supported configuration under test; disk reads and vkCreateShaderModule can then be replay-thread work. The current aggregate remake timing does not identify that placement or a worst frame, and excludes failed/unpublished competing remakes.

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.

**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:** e3628fd3198a193c403fa5f1a8208c1a70c97b0b against merge base e9da93b6f8bf5812346a7eddf92c7cb615528c13. 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 main 310e7c9dfa152ecf7ff165b22a86c62bd444451f. 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** 1. `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** - The description says reconstruction runs on a worker. That is the usual asynchronous path, but get_pipeline also calls program_cache_complete_graphics synchronously with RX_VK_SYNC_PIPELINES and before the optional GPL link. State that qualification and include the GPL path if it is in the supported configuration under test; disk reads and vkCreateShaderModule can then be replay-thread work. The current aggregate remake timing does not identify that placement or a worst frame, and excludes failed/unpublished competing remakes. **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](https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1474) tracks the Windows memory proposal. This extends the Linux mechanism from [223](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/223), rather than duplicating it; the pipeline-cache-file rule in [416](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/416) is separate. [737](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/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](https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/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};
Member

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.

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.
mooki force-pushed perf/windows-drop-modules from e3628fd319
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 9s
PR description / Description follows the template (pull_request_target) Successful in 14s
Website / Website on Cloudflare (pull_request_target) Has been skipped
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 19s
CI / Workflow lint (actionlint) (pull_request) Successful in 19s
Third-party parts / As their notes say (pull_request) Successful in 29s
to c3239a09a7
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 11s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
PR description / Description follows the template (pull_request_target) Successful in 12s
Third-party parts / As their notes say (pull_request) Successful in 14s
2026-11-18 02:06:07 +00:00
Compare
mooki changed title from WIP: perf(vk): on Windows, the shader modules of ready programs are let go after the start on PCs with 20 GB of RAM or less to perf(vk): let go of the shader modules of ready programs after the start on Windows too, on request (#1474) 2026-11-18 02:06:07 +00:00
Author
Member

Pushed c3239a09a (rebased onto main at 310e7c9df; it merges with today's main at 4b68c42be without a conflict). Windows now keeps every shader module by default; RX_VK_DROP_MODULES=1 is the opt-in, as the review suggested. Linux is unchanged.

  • The shared rule (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=1 lets 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.
  • The Intel owed-build guard, the remake and the counters are unchanged. switches.def rows and the development guide say Windows is opt-in, and that a remake can run on the replay thread with RX_VK_SYNC_PIPELINES=1 and before the optional GPL link.
  • Tests first: the Windows cases fail on the previous head and pass here.
  • Linux, one run each beside another game (RX_VK_LOAD=start with RX_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.

Pushed c3239a09a (rebased onto main at 310e7c9df; it merges with today's main at 4b68c42be without a conflict). Windows now keeps every shader module by default; `RX_VK_DROP_MODULES=1` is the opt-in, as the review suggested. Linux is unchanged. - The shared rule (`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=1` lets 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. - The Intel owed-build guard, the remake and the counters are unchanged. `switches.def` rows and the development guide say Windows is opt-in, and that a remake can run on the replay thread with `RX_VK_SYNC_PIPELINES=1` and before the optional GPL link. - Tests first: the Windows cases fail on the previous head and pass here. - Linux, one run each beside another game (`RX_VK_LOAD=start` with `RX_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.
Author
Member

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=1 is set; the RAM line and the commit-headroom shortfall no longer decide anything there. Linux behaves exactly as on main. RX_VK_KEEP_MODULES=1 and 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_pipeline calls program_cache_complete_graphics on the replay thread with RX_VK_SYNC_PIPELINES=1 and before the optional graphics-pipeline-library link, so the file read and vkCreateShaderModule can 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.

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=1` is set; the RAM line and the commit-headroom shortfall no longer decide anything there. Linux behaves exactly as on main. `RX_VK_KEEP_MODULES=1` and 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_pipeline` calls `program_cache_complete_graphics` on the replay thread with `RX_VK_SYNC_PIPELINES=1` and before the optional graphics-pipeline-library link, so the file read and `vkCreateShaderModule` can 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.
Some checks failed
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Has been skipped
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Has been skipped
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Has been skipped
Third-party parts / The same as upstream (pull_request) Has been skipped
Website / Website on Cloudflare (pull_request) Has been skipped
CI / Conventional Commit title (pull_request) Successful in 11s
Guide screenshots / Guide images and local UI source review (pull_request) Failing after 13s
CI / Workflow lint (actionlint) (pull_request) Successful in 14s
PR description / Description follows the template (pull_request_target) Successful in 12s
Third-party parts / As their notes say (pull_request) Successful in 14s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/windows-drop-modules:mooki-perf/windows-drop-modules'
git switch 'mooki-perf/windows-drop-modules'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!1488
No description provided.