Idea: on Windows, hold less memory for pipelines after the start: the cache file rule (#416) and the module release (#223) Linux has, once measured #1474

Open
opened 2026-11-17 22:03:52 +00:00 by mooki · 1 comment
Member

The idea

TL;DR. On a 16 GB Windows PC the game's private memory is what ends long sessions (the commit-limit crashes below), and part of it is pipeline knowledge kept resident: the pipeline cache file the driver holds, and the shader modules of programs whose pipelines are already built. Linux already has two ways to give some of that back (#416 leaves the cache file unread on small Linux NVIDIA PCs, #223 lets the modules go after the precompile); Windows has neither, by code, not by choice. I propose extending both to Windows, one at a time, each behind its own measurement, and not adopting a lean "no cache at all" mode. This is from reading the code and the related issues and pull requests; I ran nothing for this issue, and no number below is a Windows saving.

Why it matters (leads, not measurements)

  • The project's crash reports over the last 90 days have 48 with the commit-limit exception 0x20474343 (all builds; 36 of them on rc.6). rc.7 added the wait at the commit limit (#1291), so since then the same situation ends with "Your PC ran out of memory" instead (#1364, after 21 minutes). #1280 and #333 are the two allocation paths that ended the game there.
  • Of the 20 reports in the issues with logs of 27 minutes or more, 9 ended with that commit-limit exception (28 to 218 minutes). Part of that is the render-target retention fixed by #1462 (#1443 collects those reports); pipelines are a separate part that #1339's accounting leaves out by its own description.
  • #805 measured the size of this on Windows: on an RX 5600 XT with 24 GB, loading every program before the title held 23 to 26 GB of private memory against 18 to 20 GB with programs loaded at their create calls. #975 has since made create the default on the compute fallback, so that gap is closed for that case; it shows how much the kept pipeline objects weigh, not what is left to save today.

What the code does on Windows today (forge main 6112edb61, line numbers from there)

  • pcache_load_off() (gpu/vk/vk_draw.cpp:1106) is #416's rule. On Windows it sets linux_nvidia = false and ram_mb = 0 (:1111-1113), so the automatic "do not read the file" choice can never be made there. Only RX_VK_PCACHE_LOAD=0 skips the file.
  • pcache_init() (:1165) always creates a VkPipelineCache, empty when the file is skipped (:1178), and keeps it for the session. The file's mapping is released once the cache is made, so the file's size on disk is not the game's RAM: what costs RAM is the driver's copy inside the cache object.
  • play_cache_begin() (:966) treats the two kinds of skip differently, as #415 and #416 intended: the automatic skip keeps play generations and lets each go at a save without writing it; the explicit RX_VK_PCACHE_LOAD=0 starts none, so play's pipelines go into the one base cache, which grows for the whole session. So RX_VK_PCACHE_LOAD=0 on Windows is an A/B of the file, not a model of a lean mode.
  • pipeline_cache_play() (:11489) calls program_cache_drop_modules() (gpu/vk/vk_progcache.cpp:985) inside #ifdef __linux__ only, driven by linux_pressure (/proc/meminfo). On Windows RX_VK_DROP_MODULES=1 does nothing.

The two changes I would try, in this order

  1. Release the modules after the start on Windows (#223's mechanism, a Windows trigger). The drop and the remake from longshot_programs.bin exist; what is missing is a Windows condition. Windows has the numbers it needs (GlobalMemoryStatusEx: physical RAM and commit headroom; the texture budget already reads the headroom this way in commit_headroom, gpu/vk/vk_texture.cpp:340), so the condition could mirror Linux's: 20 GB of RAM or less, or commit already near its limit. Its limits, as #223 says: with programs loaded at their create calls few modules exist at the start to let go, so this helps most after a full precompile or a cold-cache recovery (#1188), not modules made later in play; and a new state variant in play must remake its module on a worker, never on the replay thread. Expected cost: none measured; possible first-use waits for new variants.
  2. #416's rule on Windows, for Windows NVIDIA on 16 GB first, with programs loaded at their create calls. Windows has no folder size to trust (NVIDIA's cache folder is shared with every other game, and #1289 asks for a distinct identity), so the evidence that the driver's cache answers should be #1188's probe of this game's own pipeline keys, not a size heuristic. A cold driver cache must still take #1188's path, and precompile_warm fills the base cache even when the file was not read, so a recovered session's peak is not bounded by this rule. One caution from Linux: on #388 HumanBean's reproduction (RTX 3090, the game held to 13 GB) saw no change in swap from #416 (5.0 and 6.3 GB against main's 5.7 and 5.9), so even the Linux saving needs a second look before it is carried over.

A third option, replacing the big cache with a smaller one after a full precompile once no builder is running, would free the cache object's storage but nothing the pipelines themselves hold, does not lower the startup peak, and needs a reader-lifetime protocol for every cache call; I would leave it until the first two are measured.

What I would not do

  • A null application cache by default, deleting old cache files, or dropping the cold-cache and first-use safety nets (#1188, #903, the load-wait strike in vk_programs.cpp).
  • Caps or eviction of pipelines themselves: recorded commands and shared programs need a lifetime design of their own.
  • Counting a cache file's bytes, the working set, private commit and VRAM as one number: Windows reports private commit and working set separately, and only commit headroom decides the crash above.

How to measure it (one change at a time, interleaved runs, the same folder prepared the normal way)

  • Windows, 16 GB, three separate cases: discrete NVIDIA, an AMD card on the compute fallback, and an integrated GPU with shared memory.
  • At the title and after a route with several area changes and revisits: the start's peak private commit, private working set, commit headroom, hard faults, pipeline and module counts, play generation sizes, load-worker waits and first-use waits, missing or omitted draws, and the pictures (content intact, not only lower memory).
  • Warm driver cache, a cleared one (on a test account, never a player's), and after a driver update answer different questions; keep them apart.

Anything else

Existing work this builds on, not around: #416 and #415 (the two skip paths), #223 (module release and remake), #975 (programs at their create calls on the compute fallback), #1188 (the driver-cache probe), #903 (the cache saved before the title), #563 (more prepared pipelines: coverage stays), #190 (Intel's fetch lock), #1291 (the commit-limit wait). Open and related: #789 and #902 (driver-cache detection and diagnostics), #737 (one shader cache store across game folders: disk, not RAM), #801 (dynamic vertex input: fewer pipelines), #1339 (memory accounting, which leaves pipelines and modules out), #805, #388, #1443.

Another port, Project ReLink, takes the lean route further: no application cache by default, and a big cache swapped for a smaller one after its full precompile. I read its approach as an idea only; nothing of its code is proposed here, and its private-memory numbers are against its own earlier configuration, not against Longshot today.

What I can add: Linux with NVIDIA here, and a Windows 11 laptop with Intel Arc integrated graphics (shared memory, 64 GB), which can give the integrated case's private commit and working set with the file read and not read, and with modules kept and released, once a build with a Windows trigger exists. A 16 GB Windows NVIDIA tester would be the most useful second data point.

### The idea **TL;DR.** On a 16 GB Windows PC the game's private memory is what ends long sessions (the commit-limit crashes below), and part of it is pipeline knowledge kept resident: the pipeline cache file the driver holds, and the shader modules of programs whose pipelines are already built. Linux already has two ways to give some of that back (#416 leaves the cache file unread on small Linux NVIDIA PCs, #223 lets the modules go after the precompile); Windows has neither, by code, not by choice. I propose extending both to Windows, one at a time, each behind its own measurement, and not adopting a lean "no cache at all" mode. This is from reading the code and the related issues and pull requests; I ran nothing for this issue, and no number below is a Windows saving. **Why it matters (leads, not measurements)** - The project's crash reports over the last 90 days have 48 with the commit-limit exception `0x20474343` (all builds; 36 of them on rc.6). rc.7 added the wait at the commit limit (#1291), so since then the same situation ends with "Your PC ran out of memory" instead (#1364, after 21 minutes). #1280 and #333 are the two allocation paths that ended the game there. - Of the 20 reports in the issues with logs of 27 minutes or more, 9 ended with that commit-limit exception (28 to 218 minutes). Part of that is the render-target retention fixed by #1462 (#1443 collects those reports); pipelines are a separate part that #1339's accounting leaves out by its own description. - #805 measured the size of this on Windows: on an RX 5600 XT with 24 GB, loading every program before the title held 23 to 26 GB of private memory against 18 to 20 GB with programs loaded at their create calls. #975 has since made create the default on the compute fallback, so that gap is closed for that case; it shows how much the kept pipeline objects weigh, not what is left to save today. **What the code does on Windows today** (forge main `6112edb61`, line numbers from there) - `pcache_load_off()` (`gpu/vk/vk_draw.cpp:1106`) is #416's rule. On Windows it sets `linux_nvidia = false` and `ram_mb = 0` (`:1111-1113`), so the automatic "do not read the file" choice can never be made there. Only `RX_VK_PCACHE_LOAD=0` skips the file. - `pcache_init()` (`:1165`) always creates a `VkPipelineCache`, empty when the file is skipped (`:1178`), and keeps it for the session. The file's mapping is released once the cache is made, so the file's size on disk is not the game's RAM: what costs RAM is the driver's copy inside the cache object. - `play_cache_begin()` (`:966`) treats the two kinds of skip differently, as #415 and #416 intended: the automatic skip keeps play generations and lets each go at a save without writing it; the explicit `RX_VK_PCACHE_LOAD=0` starts none, so play's pipelines go into the one base cache, which grows for the whole session. So `RX_VK_PCACHE_LOAD=0` on Windows is an A/B of the file, not a model of a lean mode. - `pipeline_cache_play()` (`:11489`) calls `program_cache_drop_modules()` (`gpu/vk/vk_progcache.cpp:985`) inside `#ifdef __linux__` only, driven by `linux_pressure` (`/proc/meminfo`). On Windows `RX_VK_DROP_MODULES=1` does nothing. **The two changes I would try, in this order** 1. **Release the modules after the start on Windows** (#223's mechanism, a Windows trigger). The drop and the remake from `longshot_programs.bin` exist; what is missing is a Windows condition. Windows has the numbers it needs (`GlobalMemoryStatusEx`: physical RAM and commit headroom; the texture budget already reads the headroom this way in `commit_headroom`, `gpu/vk/vk_texture.cpp:340`), so the condition could mirror Linux's: 20 GB of RAM or less, or commit already near its limit. Its limits, as #223 says: with programs loaded at their create calls few modules exist at the start to let go, so this helps most after a full precompile or a cold-cache recovery (#1188), not modules made later in play; and a new state variant in play must remake its module on a worker, never on the replay thread. Expected cost: none measured; possible first-use waits for new variants. 2. **#416's rule on Windows**, for Windows NVIDIA on 16 GB first, with programs loaded at their create calls. Windows has no folder size to trust (NVIDIA's cache folder is shared with every other game, and #1289 asks for a distinct identity), so the evidence that the driver's cache answers should be #1188's probe of this game's own pipeline keys, not a size heuristic. A cold driver cache must still take #1188's path, and `precompile_warm` fills the base cache even when the file was not read, so a recovered session's peak is not bounded by this rule. One caution from Linux: on #388 HumanBean's reproduction (RTX 3090, the game held to 13 GB) saw no change in swap from #416 (5.0 and 6.3 GB against main's 5.7 and 5.9), so even the Linux saving needs a second look before it is carried over. A third option, replacing the big cache with a smaller one after a full precompile once no builder is running, would free the cache object's storage but nothing the pipelines themselves hold, does not lower the startup peak, and needs a reader-lifetime protocol for every cache call; I would leave it until the first two are measured. **What I would not do** - A null application cache by default, deleting old cache files, or dropping the cold-cache and first-use safety nets (#1188, #903, the load-wait strike in `vk_programs.cpp`). - Caps or eviction of pipelines themselves: recorded commands and shared programs need a lifetime design of their own. - Counting a cache file's bytes, the working set, private commit and VRAM as one number: Windows reports private commit and working set separately, and only commit headroom decides the crash above. **How to measure it** (one change at a time, interleaved runs, the same folder prepared the normal way) - Windows, 16 GB, three separate cases: discrete NVIDIA, an AMD card on the compute fallback, and an integrated GPU with shared memory. - At the title and after a route with several area changes and revisits: the start's peak private commit, private working set, commit headroom, hard faults, pipeline and module counts, play generation sizes, load-worker waits and first-use waits, missing or omitted draws, and the pictures (content intact, not only lower memory). - Warm driver cache, a cleared one (on a test account, never a player's), and after a driver update answer different questions; keep them apart. ### Anything else Existing work this builds on, not around: #416 and #415 (the two skip paths), #223 (module release and remake), #975 (programs at their create calls on the compute fallback), #1188 (the driver-cache probe), #903 (the cache saved before the title), #563 (more prepared pipelines: coverage stays), #190 (Intel's fetch lock), #1291 (the commit-limit wait). Open and related: #789 and #902 (driver-cache detection and diagnostics), #737 (one shader cache store across game folders: disk, not RAM), #801 (dynamic vertex input: fewer pipelines), #1339 (memory accounting, which leaves pipelines and modules out), #805, #388, #1443. Another port, Project ReLink, takes the lean route further: no application cache by default, and a big cache swapped for a smaller one after its full precompile. I read its approach as an idea only; nothing of its code is proposed here, and its private-memory numbers are against its own earlier configuration, not against Longshot today. What I can add: Linux with NVIDIA here, and a Windows 11 laptop with Intel Arc integrated graphics (shared memory, 64 GB), which can give the integrated case's private commit and working set with the file read and not read, and with modules kept and released, once a build with a Windows trigger exists. A 16 GB Windows NVIDIA tester would be the most useful second data point.
Collaborator

Possibly related, for context:

  • issue #805 Idea: on the compute fallback, loading every program before the title costs 5 GB and puts a 24 GB PC at its commit limit; RX_VK_LOAD=create measured on a second such card (RX 5600 XT): same fps or better, loads of 50 ms at worst — Windows pipeline-related private-memory cost, though focused on loading policy.
  • issue #388 Game: on 16 GB of RAM the game's memory outgrows RAM within a minute of loading a save, then swap fills on area changes until RAM is at 0 — Linux NVIDIA memory-pressure report relevant to the cache rule's existing behavior.
  • PR #223 fix(vk): give memory back under Linux memory pressure and after the precompile — Merged Linux module-release implementation the proposal would extend.
  • issue #1156 Game: Deleting NVIDIA shader cache causes pipelines to load every boot and excess RAM usage — Windows NVIDIA cache-read behavior and memory use.
Possibly related, for context: - issue #805 Idea: on the compute fallback, loading every program before the title costs 5 GB and puts a 24 GB PC at its commit limit; `RX_VK_LOAD=create` measured on a second such card (RX 5600 XT): same fps or better, loads of 50 ms at worst — Windows pipeline-related private-memory cost, though focused on loading policy. - issue #388 Game: on 16 GB of RAM the game's memory outgrows RAM within a minute of loading a save, then swap fills on area changes until RAM is at 0 — Linux NVIDIA memory-pressure report relevant to the cache rule's existing behavior. - PR #223 fix(vk): give memory back under Linux memory pressure and after the precompile — Merged Linux module-release implementation the proposal would extend. - issue #1156 Game: Deleting NVIDIA shader cache causes pipelines to load every boot and excess RAM usage — Windows NVIDIA cache-read behavior and memory use.
mooki self-assigned this 2026-11-17 22:11:27 +00:00
Sign in to join this conversation.
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#1474
No description provided.