The shader cache key includes the size of the program struct, so adding any member to it makes every player prepare all shaders again #1510
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#1510
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: correctness · Area: renderer, shader caches · Part of: #1493
TL;DR
The key of the shader caches (
translator_stamp()) hashessizeof(Program), although aProgramis never written to the cache as it lies in memory. Adding any member toProgramtherefore changes the key, and the first start after the update prepares all 38,809 programs again: 251.6 s on a Steam Deck in a tester's run of #223, caught in review before it merged. The cache already has a format number (kProgramCacheFormat) and compile-time layout checks for what it really writes. I propose to takesizeof(Program)out of the key and add a test that fails if a struct size enters it again.Breakdown
Program, and anyone who adds a member to it without knowing the key moves. Slow PCs and the Steam Deck pay the most.vk_shader.cpp:1291-1300).Programis written member by member, never as one block. The few small types written as they lie have size and offset checks, andShader::Infois covered by the recompiler's files and its own size. So the size of the whole struct only measures members nobody stores.sizeof(Program)from the key. Keep the format number and the existing checks as the only way a cache layout change invalidates it. Add a test that reads the key's inputs and fails on a struct size that is not written as it lies. Add a library version for libstdc++, which the key has none for (:1297).Programmember (the log line that drops caches appears today, not after), and the one re-prepare this change itself costs, shipped with a release that already re-prepares.Evidence
Code, on main (
310e7c9df):gpu/vk/vk_shader.cpp:1289-1300:abi[]=sizeof(Shader::Info),sizeof(Program),sizeof(std::vector<uint32_t>), then the C++ library (libc++ and Microsoft's by version;3u, 0ufor libstdc++, no version). The comment says the records keepShader::Infoas it lies and another library crashed at start.gpu/vk/vk_progcache.cpp:284-295, 368-388: a record isput_head(members one by one), then per stage its two stage words, the SPIR-V,c1, andput_info(Shader::Infobysizeof, plus its lists). Nothing writes aProgramas one block.vk_progcache.cpp:46-74:kProgramCacheFormat = 1, static_asserts for each type written as it lies (Program::Answer,answers,questions,Stage::c1, the head's words), andprogram_cache_stamp()=translator_stamp()mixed with the format.tests/test_program_cache_format.py:97-113fails if a memberput_headwrites has no assert.vk_progcache.cpp:157), the pipeline cache files (vk_draw.cpp:1034), the pipeline notes and state lists (:1753, 1798, 10688-10803), the prepare marker (:9391-9593) and the module ids (vk_programs.cpp:156). One changed input drops all of it.vk_progcache.cpp:874-879), side tables invk_progcache.cpp(namespace module_remake) and a test that forbids five member names (tests/test_linux_pressure.py:120-126). A new member with another name passes.What happened (the 251.6 s):
4 files made for another translator dropped (306 MB),0 program keys kept, thenprepared 38809 shader programs (46597 new, 70 failed, 9687 compute pipelines; ...) in 251.6 s. Going back to the build without it did the same.LONGSHOT_SHADER_STAMPandkProgramCacheFormathad not moved;sizeof(Program)had, because the PR added four members. The same comment gives the cause. The members were moved out ofProgramin review (comment of 14 Nov), and #223 merged withProgramunchanged (f1b17d59d).sizeof(Program)entered the key (40c3f851b, 7 Nov), two merged commits grewProgramand touched no file the translator stamp hashes: #41 (13 Nov,desc_counts) and #404 (14 Nov,compute_optimized,optimize_owed). Whether each movedsizeofwas not measured, and a release may have changed the translator anyway. [INFERENCE]What is already done, so this issue is only the rest:
2ed98c468(11 Nov) gave the cache a format number apart from the translator stamp. #370 (merged 17 Nov) tookvk_api.hout of the stamp. #1418 (merged) keeps the pipeline marker across an update that changes no shader. #1390 (merged 17 Nov) deleted 15 switches the translation read and says its merge re-prepares every player once.Proposed change
(uint32_t)sizeof(Program)fromabi[]. Keepsizeof(Shader::Info),sizeof(std::vector<uint32_t>)and the library words: they describe bytes written as they lie.tests/test_linux_pressure.pywith a test of the rule itself (below). The side tables can stay; they are not required any more.How we would test it
translator_stamp()contains nosizeofof a struct thatprogram_cache_savedoes not write as one block. On main it findssizeof(Program).tests/test_program_cache_format.py. Add a fingerprint of the static_assert block next to the format number in the test, so changing a written layout without raisingkProgramCacheFormatfails the test and names both.Program; this change with the same member added. The second drops the caches at its first start (made for another translator dropped,0 program keys kept); the third keeps them. A yes or no in the log, not a timing. No speed claim is made.Related
2ed98c468: the format number. #370, #1418, #1390: the stamp's other inputs, listed above.sizeof(Program)once cost Steam Deck players 251.6 s" is a tester's run in review, not a shipped release.New on this forge; not opened on GitHub.
Possibly related, for context: