WIP: feat(vk): a disk cache of decoded ASTC textures (RX_VK_TEX_CACHE, off by default) #2292
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2292
Loading…
Reference in a new issue
No description provided.
Delete branch "TrashPanda/Longshot:feat/tex-disk-cache"
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?
Summary
No longer stacked: #2307 and #2314 have merged, and this now sits directly on
main(three commits, head679e25d90on94cd0a204). It was rebuilt on #2314 because the cache keeps what the GPU ASTC decoder produces (and, for big textures, what the BC re-encoder makes of it) in files; #2314 defines what the correct output is (bit-exact to astcenc, sRGB formats in the sRGB decode mode), so the cache has to sit on it. Only the three commits under #2314 are this pull request; it can be rebased ontomainonce #2307 and #2314 land.What the first version got wrong, and what this one drops. The first version was pushed from a private development branch: its 35 commits sat on an old
main(141 commits behind) and only the top five were the cache. Underneath they carried a temporary texel read-back harness (RX_VK_TEXDECODE_CHECK,texdecode_use.*, adlsymhook that logged texel values), three experimental switches (RX_VK_ASTC_GPU_PORT,RX_VK_UNSWIZZLE_GPU_PORT,RX_VK_ASTC_BC3_OWN), a ported GPU ASTC decoder, a GPU deswizzle and a BC3 encoder that were later measured to be slower on integrated GPUs and are not offered, and a commit pair (0d9325aa9and its revert) that held another project's file. That was a mistake in how the first version was pushed, not something to review. None of it is here: the branch is three commits, the cache and its tests only, andgit grepfor those names finds nothing. Also dropped: the two commits that fixed Eden's decoder reading uninitialised colour bits;mainalready zeroescolor_endpoint_data(the line at the top of the block's colour decode, from #2194 and #2314's follow-ups), and the in-game check below finds no difference on either GPU.What it does. The first whole upload of a decoded ASTC texture is looked up by the hash of its blocks (
reuse_uploadalready makes it), the texture's shape and a producer stamp. A file is copied into the image with onevkCmdCopyBufferToImagewhen a small cost model says the read takes under half the decode's time; otherwise the texture is decoded as before and its final image read back and written by a background thread at idle I/O priority, for the next run. Textures decoded on the CPU are never read or written. Files live undercache/textures/<stamp>/, made from the player's game files like the rest ofcache/: they never leave the PC.The default is now off (the title used to say "on for integrated GPUs"). On this PC's integrated GPU (Raphael, RADV), on top of #2194's fast decoder and #2314, a warm cache gains no more than the run-to-run spread (Measurements).
RX_VK_TEX_CACHE=1turns it on with the cost model;=2for every texture the cache takes, for checks. Reviewer data on a Steam Deck (42% fewer hitches, 51% fewer slow-frame seconds, an hour of play with no failure) says it wins there; that is the number to confirm on this head, and it decides whether the default goes back on.Changes in answer to omgitsgela's review (thank you for the Deck run and for feeding old files to the new decoder, which is how the gap was found):
tex_cache::make_stamp) folds the cache's format version, the generated SPIR-V the renderer embeds for the ASTC decoder and for the BC encoder (BC7's too when BC7 is on), and the rule that picks the decode mode (astc_nvn_srgb, evaluated over every NVN format), so a shader change invalidates by itself with nothing to remember to bump. The decoder's error colour is a constant in its SPIR-V, so it is covered. Each texture's shape carries its own decode mode and format (RGBA8, BC1/BC3/BC7), which are in the key and the header. The stamp is in the key (a file of another stamp is at another name, so a lookup cannot reach it), in the header (refused if a file is moved or renamed) and in the folder name (so the start-up can tell what is stale without opening files). The CPU decoder's version is not in the stamp because nothing the CPU route makes is cached (tex_cache::refused: "decoded on the CPU"); a route that fills the cache from the CPU must add it.tuneswitchRX_VK_TEX_CACHE_MB, 4096 MB by default, never more than a tenth of the disk's free space (the cache's own files counted as free), at least 1 GB. A write that would pass it is refused. 4 GB is chosen from the measured sizes: a route through Link's house, Kokiri Forest and Hyrule Field is 1.5 to 2 GB on this PC (1.1 GB for one of the areas), and the reviewer's day of play was about 1 GB, so the cap holds several routes' worth and about four times a day. It was 8192 MB.mainwith no conflicts (same three commits; the measurements below were taken atceb46c513, whose tree differs from the current head only by what merged beneath it).Read first:
gpu/vk/tex_cache.h(key, stamp, header, regions, eviction, cost model), thentex_cache_fill,tex_cache_capture,tex_cache_frameandtc_stampingpu/vk/vk_texture.cpp, thengpu/vk/tex_cache.cpp(index and writer threads). Where the hooks sit:upload_innertakes the memory generation before the blocks are hashed,tex_cache_fillruns afterreuse_uploadand beforeupload_astc_gpu,tex_cache_captureruns afterupload_astc_gpusucceeds on a first whole upload;texture_framecallstex_cache_frame,mkwvk_close_askedstops the writer. The copies use whole-block row lengths (#2015's rule) and one region a layer for a multi-layer BC level whose extent is not a multiple of 4 (#2228's AMD Windows finding, applied on every driver).Written with AI agents under the project owner's direction.
Testing
Tested: (head
ceb46c513; Linux, this PC: RTX 4070 Ti, and the integrated GPU of the Ryzen 7 9800X3D on RADV; lavapipe):tests/test_tex_cache.pypasses with g++ and clang++ (every field of the shape and every stamp component changes the key or the stamp; a header with another stamp is refused; the eviction rule; the store on a temporary folder).tests/test_tex_cache_gpu.py(six shapes: BC3 and RGBA8, 1 and 3 layers, 11-level chains to 1 x 1, linear and sRGB decode modes; the renderer's own decoder and encoder SPIR-V; capture, file, fill, every byte compared) passes on lavapipe with the validation layer, on the RTX 4070 Ti and on the RADV iGPU.suite.py compareagainst #2314's head511dd4049: 936 passed, 3 failed, 26 skipped, against 934, 3, 26 on the base; failing only here: 0; failing only on the base: 0 (test_dev_packs,test_pipeline_state_computes,test_thinlto_tlsfail on both); the two new checks pass. The translator stamp is unchanged (9a7560c9042d2783 on both).RX_VK_TEX_CACHE=2, one fill pass then one reading pass on the same folder; every run alone on the GPU in the queue's timing mode; Link's house, Kokiri Forest and Hyrule Field one scene a run): RTX 4070 Ti reading pass 232, 340 and 313 textures (1474, 1930 and 1816 MB) compared, 0 differ, and the copies read back from the files 0 differ; RADV iGPU (RX_VK_DEVICE=1, 1280x720,RX_VK_AUTO_TUNE=0) 250, 383 and 373 textures (924, 1234 and 1102 MB), 0 differ. All runs stopped cleanly.RX_VK_TEX_CACHE=2, Kokiri Forest): a folder filled by main's decoder from before #2314 (its SPIR-V loaded withRX_VK_SHADER_DIR, stamp a437...: 168 files, 950 MB), then this build on the same folder (stamp f086...): the log says "0 MB of this build's stamp and 950 MB of other stamps found ... 168 files (950 MB) deleted ... 0 files listed", 0 files read, 408 "not there", then its own fill of 173 files; a third run lists those 173 files and reads 103 of them.gamerun, the three scenes (house, Kokiri Forest, Hyrule Field) on the RTX, cache off against on and warm: all clean stops, 0 warning lines,logdifffinds no new, gone or changed warning or error kind in any scene; the screenshots read the same (only the animation pose differs).Still to test:
_wfopen,_wgetenv,THREAD_MODE_BACKGROUND_BEGIN,MoveFileExW):@Beanstalkbuild and a run withRX_VK_TEX_CACHE=1.@Beanstalkon an RX 6000, forced on withRX_VK_TEX_CACHE=2).@Beanstalk).Measurements
Verdict: On this PC's integrated GPU the cache no longer pays, on top of #2194 and #2314: no gain beyond the run-to-run spread, so it ships off. On the RTX forcing it on is worse (the cost model declines every file by default, as designed). The first version's gain (frames over 100 ms 12.1 s to 7.5 s on this GPU) was measured against the old decoder, and the integrated cost model's decode seed (150 MB/s) comes from it: the decode now runs at about 500 MB/s here against a file read of about 380 MB/s. The reviewer's Deck numbers (42% fewer hitches, 51% fewer slow-frame seconds) do not carry over to this GPU; the Deck's rerun on this head is the open question.
Setup: Linux, this PC, queue timing mode (each run alone on the GPU, checked with
qoverlap), headceb46c513(the runs were made at c64f28250; the later commits change only the default),RX_VK_FRAME_LOG, worst frames from the whole-run log, 2 interleaved rounds, median (range). A:RX_VK_TEX_CACHE=0(what main does), B: an empty folder (cold: the fill's cost), C: the same folder straight after (warm). iGPU: Raphael, RADV,RX_VK_DEVICE=1, 1280x720,RX_VK_AUTO_TUNE=0, house 20 s then 45 s in Kokiri Forest (F) or in Hyrule Field (H), two separate runs (the three-stop route loses the device here on every build). RTX 4070 Ti: the three-stop route,RX_VK_TEX_CACHE=2(forced). Switches added and their defaults:RX_VK_TEX_CACHEoff (above),RX_VK_TEX_CACHE_MB4096 (the size of a route and a day, above),RX_VK_TEX_CACHE_VERIFYon (a file's checksum is checked as it is read, about 0.05 ms a MB; off only for measurements) andRX_VK_TEX_CACHE_DIRthe game folder'scache/textures(a folder for tests; no measurement chose it). Logs:Longshot/work/texcache2/logs/summary_igpu.txt,summary_rtx.txt(not published: they hold game-derived names).511dd4049(#2314's head; cache off, A)ceb46c513, cold (B)ceb46c513, warm (C)Every run reached its teleport, with 0 warning lines. House load time (launch to map) is 21 to 23 s in every arm after the first run. Disk used by a filled cache: 0.5 GB per iGPU route, 2.2 GB on the RTX (forced). The old branch's numbers (iGPU, three-stop route, same GPU, before #2194): off 12.1 s of frames over 100 ms and a 2.7 s worst frame, warm 7.5 s and 1.3 s. Against them: here A's worst frame is already 1.0 to 2.0 s and its frames over 100 ms 4.5 to 6.3 s without the cache, so there is less left for it to remove, and the reads cost about what the decodes do.
Risks
RX_VK_TEX_CACHE=0forces it off, deletingcache/textures/is always safe. A revert is enough.RX_VK_TEX_CACHE_MB(4096 MB) in the game folder'scache/, when it is on. Memory: read-backs waiting to be written hold at most 512 MB (256 below 16 GB of RAM).cache/textures/appears. A build whose shaders differ deletes the previous build's files at its first start (two builds sharing one game folder would delete each other's).Checklist
Ready for review
main; the title is a Conventional Commit. (On currentmainsince #2307 and #2314 merged.)mise run testpasses (any failure that also fails onmainis named). (The suite's three failures also fail on the base, named above.)main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
mainand passes here. (Not a fix: a feature, off by default; its tests are game-free and in Testing.)gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.MKWVK_API_VERSIONbumped (MkwVkHostorMkwVkRendereringpu/vk/vk_api.hchanged). (Not needed:vk_api.his untouched.)mainand here, for a change that shows on screen. (Nothing shows on screen; the cache-off and cache-warm screenshots read the same.)Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Linux 7.0, AMD Raphael iGPU (RADV, Mesa 26.0.8, 1280x720) and RTX 4070 Ti (NVIDIA 595.99.02): with RX_VK_TEX_CACHE_CHECK=1 every cache hit decoded again and compared: iGPU at
0fec7986a, Kokiri Forest and Hyrule Field two passes, 0 differences (374 and 454 decodes in pass 2); RTX atc184bc28e, Link's house, Kokiri Forest, Hyrule Field two passes, 0 differences. Measurements still running. Stacked on the unopened texture decoding series.Deck LCD data for this idea, from an independent implementation, plus an offer to run this branch itself once it's rebased.
Context: this is the Deck LCD bench from the emulation campaign. Last week we built our own minimal version of the same cache before finding this PR: the finished converted image, keyed by the
reuse_uploadXXH64 plus shape, written tocache/bc3by a writer thread, read back with onevkCmdCopyBufferToImagewhen in-session reuse misses (RX_VK_BC3_DISK=1, ~230 lines, one file). Readingtex_cache.hafterwards: your design matches ours where it counts and is stricter everywhere ours is thin. The stamp especially — see finding 2.Deck LCD numbers. Hardware: Steam Deck LCD (Vangogh, 16 GB LPDDR5, stock carve-out). Scene: Castle Town, scripted walk-and-turn from a save at Castle Market, 20 cycles,
RX_VK_FRAME_LOGper arm, hitch = a frame over 60 ms. Against v3.1.1 stock, warm cache: hitches >60 ms −38%, >150 ms −83%, slow-frame seconds −62%, staged MB −51%, 1% low +29%; cold run no worse than stock.The number the repo still needs, and which decides how this ships: does the disk cache still pay after #2194's 5.3x decode speedup? Your RTX arms show the cost model correctly going inert there. We put #2194's merged commit on the same base and re-ran:
On Vangogh the cache still wins clearly after the fast decoder: −42% hitches, −51% slow-frame seconds, −61% bytes staged. The biggest single hitches improved less than pre-#2194 (the fast decode eats part of it), but count, seconds and bytes hold. I'd expect your learned read rate to sit well above the 500 MB/s seed on this hardware, for the reason in finding 1.
A human minute too: 62 minutes of normal free play, warm cache, 94k frames — 1.37% of frames over 60 ms, 0.067% over 150 ms, 5,057 uploads (2.9 GB) served from file, zero failures.
Two findings that bear on the design.
On Deck, the "disk" cache is already a RAM cache: warm hits read through the Linux page cache and cost about a memcpy. On Linux integrated GPUs an explicit second RAM tier mostly re-stores the same bytes in the same LPDDR5 with a double copy. Where a RAM tier earns its keep is #2273's case — bytes the VRAM budget evicted mid-session, before anything reached a file. Different bug class; worth keeping out of this cache's path.
The producer stamp is not paranoia; we proved the scenario and our un-stamped key passed it only by luck of the check. The upgrade arm fed pre-#2194 files to the post-#2194 decoder: 1,600+ hits, zero header failures, screenshots clean — but that only shows the checks passed, not that shader-changed bytes were right. Please keep the stamp through the rebase; we're adding one to our branch before it ships anywhere.
Eviction. Our pilot has none, and its folder reached 996 MB after one day of test runs plus an hour of play, untrimmed, so take this from the "it's needed" side. One observation before anyone reaches for least-frequently-used: on the Castle route, every file the cache held was read at least once by the next session — frequency only starts to separate from recency on big caches with long-tail areas. Your stamp-first, then least-recently-read order is a reasonable default; if you want the hit-distribution data that actually decides LRU vs LFU, we can instrument the bench to log per-file counts across normal play.
Offer. When this rebases onto main (once the series beneath settles), we'll run it on this Deck LCD: the Castle arms cold/warm/upgrade, with traces. The description lists Deck among the untested hardware, and the Deck is where the on-by-default-for-integrated claim actually lives.
0fec7986a3ceb46c5138Thank you, omgitsgela: the Deck run, the "an hour of play with zero failures", and above all feeding files from the old decoder to the new one. That test is what found the gap. Here is what changed in answer to each point.
Rebased, and where. The branch is rebuilt, not rebased: the first version was pushed from a private development branch, so most of its 35 commits were not the cache at all (a texel read-back harness, three experimental switches, a ported decoder and encoder that are not offered, and a file of another project). That was a mistake in how I pushed it. The branch is now three commits (the cache's rules and store, the wiring, a GPU test) on top of #2314's head (
fix/astc-gpu-exact,511dd4049, which is on #2307). It is stacked there on purpose: the cache stores what the decoder produces, and #2314 defines the correct output (it moves about 18% of texels by a step and decodes sRGB formats in the sRGB mode), so files made before it are stale by definition.Producer stamp. Done. The stamp folds the cache format, the generated SPIR-V of the ASTC decoder and of the BC encoder (BC7's when on) and the rule that picks the decode mode, so any shader change invalidates by itself. It is in the key (a stale file is unreachable, not just detected), in the header, and in the folder name. A game-free test changes each component and checks the stamp moves. I ran your upgrade scenario for real on the RTX: a folder filled with main's decoder from before #2314, then the new build on it: 168 files (950 MB) of the other stamp deleted at start, 0 read, then its own fill.
Eviction. The stale files go at start-up, whatever the size; this stamp's files go least recently read first when over a cap, down to 90% of it, also only at start-up, never on the upload path. The cap is
RX_VK_TEX_CACHE_MB, now 4096 MB (it was 8192): a three-area route is 1.5 to 2 GB on my PC and your day was about 1 GB. Since every file was read at least once on your route, the cap is what bounds it; an LRU alone could not.RAM tier. None, following your finding about the page cache on Linux integrated GPUs. I left Windows as an open question in the description.
Default. The title no longer says "on by default". On my Raphael iGPU, on top of #2194's decoder and #2314, a warm cache gains no more than the run-to-run spread (frames over 100 ms 6.3 s off against 5.3 s warm in Kokiri Forest, 4.5 s against 5.0 s in Hyrule Field; file reads about 380 MB/s against a decode of about 500 MB/s), so it ships off. That is the opposite of what you saw on the Deck, so your numbers are the ones that matter. Checked in the game, both GPUs, every texture served from a file against a fresh decode, byte for byte: 0 differences (about 250 to 380 textures a scene).
Ask. Could you rerun your Deck test on this branch (head
ceb46c513, on top of #2314), withRX_VK_TEX_CACHE=1? If it still shows the 42% and 51%, the default goes back on for integrated GPUs and the cost model's decode seed gets re-measured on your numbers. The full write-up is in the updated description.WIP: feat(vk): a disk cache of decoded ASTC textures, on by default for integrated GPUs (RX_VK_TEX_CACHE)to WIP: feat(vk): a disk cache of decoded ASTC textures (RX_VK_TEX_CACHE, off by default)ceb46c5138679e25d900Rebased straight onto
mainnow that #2307 and #2314 have merged: the same three commits, no conflicts, head679e25d90. The pull request is no longer stacked and shows only its own 16 files. The game-free cache test and the switch table check were rerun after the rebase and pass; the in-game measurements in the description were taken at the previous head.@review
@Beanstalk
Beanstalk test farm · ❌ failed on nvidia, linux+radv, steamdeck and 1 more
Commit
679e25d· approved by HumanBean (reviewed) · dashboard⚠️ Note: Two starts per side fit the time budget but provide less resilience to noisy results than three; cache files and actual hits are not guaranteed, so this cannot establish a controlled warm-cache improvement.
⚠️ Note: The farm cannot reproduce the prior 60 ms hitch threshold, slow-frame seconds, byte-for-byte texture verification, stale-file upgrade or eviction tests with this plan.
Done (started 05:48 UTC, last report 16:05 UTC). Comment
@Beanstalkto run it again.nvidiawindows+amdlinux+radvintelsteamdeckigpumarket-and-kokiri· frame time p99 (ms)RX_VK_TEX_CACHE=(reference)RX_VK_TEX_CACHE=1nvidiawindows+amdlinux+radvintelsteamdeckigpuWhy it failed
nvidia:market-and-kokiri · RX_VK_TEX_CACHE= (PR only)screenshot.max_diff:0.1 → 0.8; limit 0.2nvidia:market-and-kokiri · RX_VK_TEX_CACHE= (PR only)load_time_max_s.max_delta_pct:7.7 → 11.2 (+46.1%); limit 30.0nvidia:market-and-kokiri · RX_VK_TEX_CACHE= (PR only)run_frametime_max_ms.max_delta_pct:2,671 → 6,279 (+135.1%); limit 50.0linux+radv:market-and-kokiri · RX_VK_TEX_CACHE=1 (PR only)market.frametime_p99_ms: RX_VK_TEX_CACHE=1 vs RX_VK_TEX_CACHE= (PR):43.2 → 60.2 (+39.3%); limit 20.0; the PR's own cells: RX_VK_TEX_CACHE=1 against RX_VK_TEX_CACHE= (RX_VK_TEX_CACHE= (PR only))linux+radv:market-and-kokiri · RX_VK_TEX_CACHE=1 (PR only)kokiri.frametime_p99_ms: RX_VK_TEX_CACHE=1 vs RX_VK_TEX_CACHE= (PR):48.0 → 57.8 (+20.5%); limit 20.0; the PR's own cells: RX_VK_TEX_CACHE=1 against RX_VK_TEX_CACHE= (RX_VK_TEX_CACHE= (PR only))steamdeck:market-and-kokiri · RX_VK_TEX_CACHE= (PR only)screenshot.max_diff:0.8 → 0.3; limit 0.2igpu:market-and-kokiri · RX_VK_TEX_CACHE=1 (PR only)screenshot.max_diff:0.1 → 0.8; limit 0.2Couldn't be judged: the tester's PC could not finish the test. The farm tries another PC, or the same one after a fix; it says nothing about the PR on its own.
windows+amd, report 2:Insufficient frame-time evidence for 12 required comparison(s). See rule results.intel, report 1:the main base failed (exit 1): Windows doesn't let programs look inside C:\, a folder above the builder's own compiler, so it can't start. Move Longshot's folder out of it (for example to C:\Longshot) and start Longshot from there.intel, report 2:Insufficient frame-time evidence for 12 required comparison(s). See rule results.What was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares main with the pull request in Castle Town Market and Kokiri Forest, using two starts per side for each cache setting and about 50 minutes per tester. The cache axis tests both the shipped default and the cost-model-enabled mode across GPU makers, AMD drivers, integrated GPUs and Steam Deck. It measures frame-time tails, hitches and worst frames, and compares stationary screenshots. Crashes, substantial performance regressions or significant picture differences fail the plan; the enabled mode is also compared with the pull request's default.
1(PR only).market-entrance, then teleport to Market, take the picture market to compare with main, move the stick, measure market for 20 s (after 5 s warm-up), teleport to Kokiri Forest, take the picture kokiri to compare with main, measure kokiri for 20 s (after 5 s warm-up); 2 runs on each side for each of 2 cells (2 game starts a run).Measurements on `nvidia`, for the PR description
Verdict: fail on nvidia (2 reports):
market-and-kokiri screenshot.max_diff;market-and-kokiri load_time_max_s.max_delta_pct (+46.1%);market-and-kokiri run_frametime_max_ms.max_delta_pct (+135.1%)failed.Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 3080 Ti, 621.24.0AMD Ryzen 9 5900X 12-Core Processor, 64 GB RAM; 2: linux+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce GTX 1660 Ti, 620.73.4Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz, 16 GB RAMScene: market-and-kokiri, from the repository's save market-entrance; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-kokiri: 2 game starts a side, market 20 s after 5 s warm-up, kokiri 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)94cd0a2679e25dRX_VK_TEX_CACHE= (PR only)· longest load (s)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· longest load (s)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (worst 1%) (ms)Flags and settings
RX_VK_TEX_CACHE1As Markdown for the PR description:
Measurements on `windows+amd`, for the PR description
Verdict: pass on windows+amd (2 reports): no rule failed and no PR run crashed.
Hardware: 1: windows+amd+amd-proprietary+dgpu
AMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAM; 2: windows+amd+amd-proprietary+igpuAMD Radeon Graphics, 2.0.388AMD Ryzen Z1 Extreme, 16 GB RAMScene: market-and-kokiri, from the repository's save market-entrance; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-kokiri: 2 game starts a side, market 20 s after 5 s warm-up, kokiri 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)94cd0a2679e25dRX_VK_TEX_CACHE= (PR only)· longest load (s)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· longest load (s)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (worst 1%) (ms)Flags and settings
RX_VK_TEX_CACHE1As Markdown for the PR description:
Measurements on `linux+radv`, for the PR description
Verdict: fail on linux+radv (2 reports):
market-and-kokiri market.frametime_p99_ms: RX_VK_TEX_CACHE=1 vs RX_VK_TEX_CACHE= (PR) (+39.3%);market-and-kokiri kokiri.frametime_p99_ms: RX_VK_TEX_CACHE=1 vs RX_VK_TEX_CACHE= (PR) (+20.5%)failed.Hardware: 1: linux+amd+radv+dgpu
AMD Radeon RX 580 Series (RADV POLARIS10), 26.2.7AMD Ryzen 5 5500F 6-Core Processor, 32 GB RAM; 2: linux+amd+radv+dgpuAMD Radeon RX 7900 XTX (RADV NAVI31), 26.3.1AMD Ryzen 7 7800X3D 8-Core Processor, 32 GB RAMScene: market-and-kokiri, from the repository's save market-entrance; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-kokiri: 2 game starts a side, market 20 s after 5 s warm-up, kokiri 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)94cd0a2679e25dRX_VK_TEX_CACHE= (PR only)· longest load (s)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· longest load (s)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (worst 1%) (ms)Flags and settings
RX_VK_TEX_CACHE1As Markdown for the PR description:
Measurements on `intel`, for the PR description
Verdict: could not be judged on intel (2 reports): required frame-time comparison inconclusive (fewer than two usable starts per side).
Hardware: 1: windows+intel+intel-proprietary+dgpu
Intel(R) Arc(TM) B580 Graphics, 0.406.983AMD Ryzen 5 9600X 6-Core Processor, 16 GB RAM; 2: windows+intel+intel-proprietary+dgpu+xessIntel(R) Arc(TM) B580 Graphics, 0.406.983AMD Ryzen 5 9600X 6-Core Processor, 16 GB RAMScene: market-and-kokiri, from the repository's save market-entrance; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-kokiri: 2 game starts a side, market 20 s after 5 s warm-up, kokiri 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)94cd0a2679e25dRX_VK_TEX_CACHE= (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE=1 (PR only)· worst frame time in the whole run (ms)Flags and settings
RX_VK_TEX_CACHE1As Markdown for the PR description:
Measurements on `steamdeck`, for the PR description
Verdict: fail on steamdeck (2 reports):
market-and-kokiri screenshot.max_difffailed.Hardware: 1: linux+amd+radv+igpu+handheld
AMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAM; 2: linux+amd+radv+igpu+handheldAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMScene: market-and-kokiri, from the repository's save market-entrance; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-kokiri: 2 game starts a side, market 20 s after 5 s warm-up, kokiri 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)94cd0a2679e25dRX_VK_TEX_CACHE= (PR only)· longest load (s)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· longest load (s)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (worst 1%) (ms)Flags and settings
RX_VK_TEX_CACHE1As Markdown for the PR description:
Measurements on `igpu`, for the PR description
Verdict: fail on igpu (2 reports):
market-and-kokiri screenshot.max_difffailed.Hardware: 1: linux+amd+radv+igpu
AMD Radeon 890M Graphics (RADV STRIX1), 26.1.99AMD Ryzen Z2 Extreme, 32 GB RAM; 2: linux+amd+radv+igpuAMD Radeon 8060S Graphics (RADV STRIX_HALO), 26.99.99AMD RYZEN AI MAX+ 395 w/ Radeon 8060S, 64 GB RAMScene: market-and-kokiri, from the repository's save market-entrance; each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); market-and-kokiri: 2 game starts a side, market 20 s after 5 s warm-up, kokiri 20 s after 5 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)94cd0a2679e25dRX_VK_TEX_CACHE= (PR only)· longest load (s)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE= (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE= (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE= (PR only)· market · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· longest load (s)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (p99) (ms)RX_VK_TEX_CACHE=1 (PR only)· worst frame time in the whole run (ms)RX_VK_TEX_CACHE=1 (PR only)· kokiri · frame time (worst 1%) (ms)RX_VK_TEX_CACHE=1 (PR only)· market · frame time (worst 1%) (ms)Flags and settings
RX_VK_TEX_CACHE1As Markdown for the PR description:
The testers' hardware
nvidiaNVIDIA GeForce RTX 3080 Ti, 621.24.0AMD Ryzen 9 5900X 12-Core Processor, 64 GB RAMnvidiaNVIDIA GeForce GTX 1660 Ti, 620.73.4Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz, 16 GB RAMwindows+amdAMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAMwindows+amdAMD Radeon Graphics, 2.0.388AMD Ryzen Z1 Extreme, 16 GB RAMlinux+radvAMD Radeon RX 580 Series (RADV POLARIS10), 26.2.7AMD Ryzen 5 5500F 6-Core Processor, 32 GB RAMlinux+radvAMD Radeon RX 7900 XTX (RADV NAVI31), 26.3.1AMD Ryzen 7 7800X3D 8-Core Processor, 32 GB RAMintelIntel(R) Arc(TM) B580 Graphics, 0.406.983AMD Ryzen 5 9600X 6-Core Processor, 16 GB RAMintelIntel(R) Arc(TM) B580 Graphics, 0.406.983AMD Ryzen 5 9600X 6-Core Processor, 16 GB RAMsteamdeckAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMsteamdeckAMD Custom GPU 0405 (RADV VANGOGH), 26.1.99AMD Custom APU 0405, 12 GB RAMigpuAMD Radeon 890M Graphics (RADV STRIX1), 26.1.99AMD Ryzen Z2 Extreme, 32 GB RAMigpuAMD Radeon 8060S Graphics (RADV STRIX_HALO), 26.99.99AMD RYZEN AI MAX+ 395 w/ Radeon 8060S, 64 GB RAMRecommendation: Request changes. An inaccessible cache directory can terminate the game, and the enabled cost model uses a decoder rate the PR identifies as obsolete. The reported Raphael runs show substantially more slow-upload time with the warm cache; a gain for this implementation remains unproven.
The change optionally stores GPU-decoded ASTC textures on disk and reloads them on later runs. It adds a bounded store, validation and GPU copy tests, but also adds synchronous file reads, background I/O and read-back memory; the cache is off by default.
Blocking (2): must change before merging.
gpu/vk/tex_cache.cpp:123: The recovery path uses the throwing filesystem overload after directory creation fails, so a cache setup error can terminate the process. (more on the line) Do: Use the error-code overload of is_directory and treat any status error as an unavailable cache; add a store test for an inaccessible or otherwise failing directory.gpu/vk/tex_cache.h:348: The integrated-GPU cost model still seeds decode speed from the old decoder, causing it to select file reads that are slower than the current decode. (more on the line) Do: Seed the model conservatively for the current decoder, or defer cache reads until representative decode and read rates have been learned; update the cost-model test for that behavior.Should fix (1): not blocking, but worth doing before merging.
tests/tex_cache_store_test.cpp:73: The store test constructs its Windows temporary path from narrow argv, so it does not reliably preserve Unicode paths. (more on the line) Do: Accept the Windows arguments as wide strings and construct the filesystem path from them; apply the same treatment to the GPU fixture's vector and cache paths.Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)
gpu/vk/tex_cache.h:373: The intended performance benefit has not been demonstrated for this implementation on the system where it is expected to help. (more on the line) Do: Run interleaved cache-off, cold and warm comparisons of this head on Steam Deck in the same scene and settings, including frame times, slow-frame counts, load time, cache size and RAM.gpu/vk/vk_texture.cpp:2285: The new image read-back and fill copies have not been exercised on Windows or the AMD Windows driver affected by uneven BC layers. (more on the line) Do: Build and run the enabled cache on Windows, including a warm Hyrule Field pass on an AMD RX 6000 or newer, checking the far ground and validation output.@fixcan do L1, L2 and L3.Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven. On Raphael, the PR reports warm versus cache-off slow-upload time of 2850 ms versus 2125 ms in Kokiri Forest and 2848 ms versus 2573 ms in Hyrule Field. Its Deck gains of 42% fewer hitches and 51% fewer slow-frame seconds came from a separate implementation, not this head.
Other systems: The enabled path changes GPU copies, upload timing, host memory and disk I/O on Windows and Linux. Linux NVIDIA and RADV runs are reported; Steam Deck, Windows, AMD Windows uneven BC copies and slow storage remain untested on this head. Saves, audio and input are not directly changed.
Switches: RX_VK_TEX_CACHE defaults to off; its cost-model mode needs a current decoder rate before it is a safe enabled choice. RX_VK_TEX_CACHE_MB defaults to 4096 MB, subject to the disk-space cap; RX_VK_TEX_CACHE_VERIFY defaults on; RX_VK_TEX_CACHE_DIR defaults to cache/textures. All four have switch-table rows. The size and verification defaults are reasonable provisional choices, but the gain and costs of enabling the cache still need validation.
Reviewed:
679e25d900against94cd0a2042: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the PR template, the commits, the full cache store and header, the cache wiring and adjacent upload and memory code, and the new cache tests. Reviewed the remaining diffs and skimmed the larger surrounding renderer and fixture-runner files; did not read all of vk_texture.cpp in full. Tooling's adjacent AGENTS.md and docs/review-checklist.md were absent.; nothing run (a code review).Checked and fine:
Testing: Read-only review; no builds, tests or project scripts were run. The supplied CI checks are still running.
Overlaps and merge order: No overlapping pull request was established from the supplied material; the described prerequisite PRs are reported merged.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -0,0 +120,4 @@const auto t0 = std::chrono::steady_clock::now();std::error_code ec;fs::create_directories(cfg.dir / hex16(cfg.stamp), ec);if (ec && !fs::is_directory(cfg.dir / hex16(cfg.stamp))) {L1 (blocking): The recovery path uses the throwing filesystem overload after directory creation fails, so a cache setup error can terminate the process.
When: With the cache enabled and a parent of the cache directory inaccessible, create_directories returns a permission error; is_directory can throw for the same error on the index thread, and the uncaught exception invokes std::terminate instead of disabling the cache.
Do: Use the error-code overload of is_directory and treat any status error as an unavailable cache; add a store test for an inaccessible or otherwise failing directory.
@ -0,0 +345,4 @@/// microSD card's 90-160 MB a second excepted; the page cache gives several GB)inline Rates seed(bool integrated) {Rates r;r.decode_bps[0] = r.decode_bps[1] = integrated ? 150e6 : 3e9;L2 (blocking): The integrated-GPU cost model still seeds decode speed from the old decoder, causing it to select file reads that are slower than the current decode.
When: With RX_VK_TEX_CACHE=1 on the measured Raphael, the model starts at 150 MB/s for decode and 500 MB/s for reads, while the PR reports about 500 MB/s decode and 380 MB/s reads. Its warm Kokiri Forest slow-upload time rises from 2125 ms to 2850 ms, about 34%, and Hyrule Field rises about 11%.
Do: Seed the model conservatively for the current decoder, or defer cache reads until representative decode and read rates have been learned; update the cost-model test for that behavior.
@ -0,0 +370,4 @@/// a warm cache gains no more than the run-to-run spread (Kokiri Forest's worst frame 1.2 s against 2.0 s, but its slow-upload time/// 2.8 s against 2.1 s; Hyrule Field's the other way), as a file reads at 380 MB/s and the decode runs at about 500 MB/s. The integrated/// seed below (150 MB/s) was measured before those two and is staleinline bool default_on() { return false; }L4 (should fix): The intended performance benefit has not been demonstrated for this implementation on the system where it is expected to help.
When: The Deck results exercise a separate cache implementation, while this head adds its own cost model, capture, checksum and writer behavior; the reported Raphael runs do not show a gain beyond their spread.
Do: Run interleaved cache-off, cold and warm comparisons of this head on Steam Deck in the same scene and settings, including frame times, slow-frame counts, load time, cache size and RAM.
@ -2125,0 +2282,4 @@VkCommandBuffer cmd = upload_cmd();full_barrier(cmd);const std::vector<VkBufferImageCopy> c = tc_copies(s, 0);vkCmdCopyImageToBuffer(cmd, tex.image, VK_IMAGE_LAYOUT_GENERAL, p.buf, (uint32_t)c.size(), c.data());L5 (should fix): The new image read-back and fill copies have not been exercised on Windows or the AMD Windows driver affected by uneven BC layers.
When: A warm cached multi-layer BC texture with an uneven mip extent takes the new per-layer capture and fill regions; the reported GPU and in-game runs are Linux-only.
Do: Build and run the enabled cache on Windows, including a warm Hyrule Field pass on an AMD RX 6000 or newer, checking the far ground and validation output.
@ -0,0 +70,4 @@std::fprintf(stderr, "usage: %s <empty folder>\n", argv[0]);return 2;}const fs::path dir = fs::path(argv[1]) / "textures";L3 (should fix): The store test constructs its Windows temporary path from narrow argv, so it does not reliably preserve Unicode paths.
When: On Windows with a temporary directory containing characters outside the active ANSI code page, the CRT's narrow arguments can lose those characters and the test opens a different or nonexistent directory.
Do: Accept the Windows arguments as wide strings and construct the filesystem path from them; apply the same treatment to the GPU fixture's vector and cache paths.
@HumanBean — on BeanBot's note that the Deck numbers in this thread come from "a separate implementation": correct, and since those numbers are the largest gain quoted on this PR, it's worth spelling out exactly what they do and don't establish.
What was measured, where. The −42% (hitches >60 ms), −60% (>150 ms), −51% (slow-frame seconds) and −61% (staged texture MB) are paired interleaved boots on a Steam Deck LCD (Vangogh, 16 GB unified), our pilot implementation, post-#2194 code on both sides, cache-off control built from the same base. TrashPanda's Raphael table measures his head on a desktop iGPU. Different machines, different implementations — the two tables don't contradict each other, and neither is "faster" than the other on shared hardware, because none has been run head to head. What they show together is that this mechanism's value is hardware-dependent, and this PR's own description says where it matters: the integrated-GPU default.
Why the Deck gains big and Raphael gains nothing. The cache pays when a file read beats an ASTC decode. On TrashPanda's Raphael that's close to true even with the new decoder: ~500 MB/s decode against ~380 MB/s disk reads, so the cost model should (and does) mostly decline — BeanBot's L2 is right that the 150 MB/s seed is stale, and with a correct seed a well-behaved model declines nearly everything there. On the Deck the balance is different in two ways: file reads land in the page cache of the same 16 GB unified pool the game runs in, so after first touch they run at RAM speed rather than NVMe speed, and the decode we're skipping is the Vangogh decode. Direct evidence of the crossover on Deck hardware: when #2194 made the decoder 5.3× faster, our biggest-hitch margin shrank from −83% to −60% while the count/seconds/MB margins held — the win tracks the decode-vs-read race exactly. A 62-minute real-play run on Deck: 5,057 uploads served from file, zero failures, hitch density 1.37% over 60 ms; the folder sat near 1 GB after a day, inside this PR's 4 GB cap.
What our numbers actually support. On the hardware class this feature's default claims (16 GB iGPU handhelds), the disk-cache mechanism removes roughly half the slow-frame load. On desktop iGPU it removes nothing, which is precisely what TrashPanda measured and shipped as off. Both results are right; the default decision lives on the Deck, so BeanBot's L4 (Deck arms at this head) is the correct blocker, not a reason to discount the Deck data.
Offer, standing. This head (
679e25d90) on our Deck LCD: cache-off / cold / warm interleaved Castle arms with the frame log — hitch thresholds, slow-frame seconds, staged MB, load time, cache size and RAM, per L4's wording. The Beanstalk farm can't run a Deck (its own notes say the hitch thresholds and warm-cache control are out of reach there), so this arm is ours. Running it needs the Deck back in desktop mode at my end; when it's posted here the table lands. If it holds at this head, the cost model should learn Deck rates at runtime rather than seed from Raphael's 380 MB/s — on Deck those reads are page-cache reads.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.