Shader programs, modules and pipelines are never released while the game runs, and the rule that would release a program has no caller #1509
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#1509
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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: performance · Area: renderer, shaders, RAM · Part of: #1493
TL;DR
Everything the renderer loads for shaders (programs, shader modules, pipelines) stays in memory until the game exits, and the rule that would let a whole program unit go has no caller on main. In today's default start, on a 16 GB PC, private memory grows from 2.9 GB at the save load to 5.1 GB after eight areas (#388). Letting programs go at the game's free call was tried for that change and dropped (at most 8.5% of loaded units, for over 2,000 reloads). I propose to count what a release would give back first, then release only under memory pressure.
Breakdown
Evidence
Code, on main (
310e7c9df):gpu/vk/program_life.h:91-111:release_candidates(keep)(units that are Ready, have no live program, and were drawn; only the excess abovekeep, longest freed first) andreleased(unit). The header comment at:16-18calls this "phase C".git grepfinds callers only intests/program_life_test.cpp.:96; "the game made it for something it has not shown"). In #388's tour only 3,859 of 10,686 built pipelines were taken by draws, so part of the stock is outside the rule by design. How much, the count in step 1 below says.gpu/vk/vk_programs.cpp:595-615: the game's free call reachestable.free()(:601), which only lowers a count and stamps an order (program_life.h:84-90, 125-129). Nothing is erased.vk_programs.cpp:285-297: a finished load is appended toprograms. The only other places that add to it arevk_shader.cpp:1819, 2085, 2537andvk_progcache.cpp:832. No code removes a loaded program.vk_shader.cpp:2622-2626: the program-released call erases a small code record and nothing else.vk_draw.cpp:11529-11540keeps a pipeline made at a create call inkept_ready; an entry leaves only when a draw takes it (:2636-2643), never by destroy. The pipeline map's entries "live as long as the cache" and per-thread maps hold raw pointers to them (:2628). A release pass must handle those, so this is not a one-line change.vk_draw.cpp:11422-11456callsprogram_cache_drop_modules()(vk_progcache.cpp:985) once, on Linux, with 20 GB of RAM or less or under pressure. #388 measured 1.39 GB of module code "never let go" in the default mode.gpu/vk/load_default.h:23-32loads at create calls, except with the compressed program cache, after a safety-net marker, or withRX_VK_LOAD=start.Measurements (each from the source named):
bdfe09c(11 Nov), every listed program loaded before the title. 14,354 MB resident: 7,096 MB the game's window, 6,845 MB the port, of which 5,242 MB was shader stock: pipeline cache 1,015 MB, 23,641 modules 2,197 MB, 16,574 pipelines 2,030 MB. Allocator checkpoints in a diagnostic build.RX_VK_PRECOMPILE=0took the process from 14,312 to 10,457 MB. This was before load-at-create became the default (86a9cda23, 12 Nov), so it is not what a default start holds today.0caf0618, 8-area tour of about 7 minutes. Private memory 2.9 GB at the save load, 5.1 to 5.2 GB after eight areas. At the end 7,391 programs were loaded, 10,686 graphics pipelines built, 3,859 taken by draws, plus a 1.2 GB pipeline-cache copy.86a9cda23), 11-minute tour of five area visits, programs a list names only. Heap in use about 3.6 GB a minute in and 4.3 to 4.4 GB at the end, against 7.9 and 8.1 GB in start mode.Not measured: a default start's memory on a PC with 24 GB or more at today's main; what each part is worth on Windows.
Proposed change
release_candidates(keep)underlife_mu(it isconst), add an "unused for N presents" count beside it, and log units and bytes (186 KB a program and 125 KB a pipeline were measured in one run; use the allocator's own sizes if they are at hand). No behaviour change.vk_programs.cpp: erase the unit's programs and pipelines from the lists, retire them by the GPU's timeline as the other dead lists do, bump a generation that the per-thread pipeline maps check, then callreleased().MemAvailableand swap rules, Windows commit headroom), and register it in the arbiter of #1339 so that one place decides who gives memory back first.How we would test it
tests/program_load_wait_test.cpp(it already runs the loader on stand-in lists) with a release pass. It must remove a freed unit's programs from the stand-in list, leave a unit whose program is alive, and load the unit again on a new create call. The test cannot be written against main, because no such pass exists.Related
bdfe09c; the default has loaded at create since 12 Nov.New on this forge; not opened on GitHub.
Possibly related, for context: