perf(vk): drop another driver's pipeline cache by its header, before reading it #2488
No reviewers
Labels
No labels
accessibility
autorelease: pending
autorelease: tagged
bug
dependencies
documentation
duplicate
enhancement
github_actions
good first issue
help wanted
invalid
question
testing wanted
wontfix
No milestone
No assignees
1 participant
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Hookshot!2488
Loading…
Reference in a new issue
No description provided.
Delete branch "perf/vk-cache-header-evict-set-mirror-skip"
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?
After a driver update, or with a cache copied from another GPU, every start read the whole
mkw_vk_pipelines.bin(hundreds of MB) into memory only to throw it away on the header check. This reads and checks the 32-byte header first. It also takes out two CPU costs on hot paths. None of the three changes what the game does.These come from King Kuranes' Hookshot 2.1.0 performance package, shared in Discord (he said GitHub is not his thing). This PR keeps only the parts that are self-contained and keep behavior the same; see "Not included" below.
What changed
gpu/vk/vk_draw.cpppcache_file_read: checks the header (size, version, vendor, device, pipeline cache UUID) before it seeks to the end and reads the rest. A cache from this device and driver reachesvkCreatePipelineCachebyte for byte as before; a short, truncated or mismatched file is still dropped.gpu/vk/vk_texture.cpp, the texture budget pass: the evicted textures go in anunordered_set. Before, the cache walk ranstd::findover a vector of them for every live texture. The same textures are removed.gpu/vk/vk_memory.cppmirror_sync: skips a clean 2 MB region (region_gen <= synced_gen) from any page in it, not only from its first page. A pool that starts mid-region used to check up to 511 clean pages one by one.region_genis updated whenever a page in its region is written, and copy runs already handle gaps, so the copies recorded are the same.Tests
tests/test_pcache_header_read.py: extractspcache_file_readfromvk_draw.cppand checks that a matching cache comes back unchanged; that another vendor, device or UUID, or a bad header size, is rejected after reading only 32 bytes; and that a truncated, empty or missing file returns nothing. Againstmain's version the 32-byte check fails, because the whole 1 MB file is read.tests/run_all.pyon Linux: 410 passed, 11 skipped (Windows, GPU or game only).clang++ -fsyntax-onlywith the back end's flags on the three files.Not included (could be follow-ups, each needing an in-game test)
RX_VK_BC4_STUDIO_SLICES).mainalready does this withprogram_cache_keys.Thanks, this is a tidy cut of the package: three changes that don't alter behavior, and the risky parts left out.
I checked each one against the code at
b489c38:pcache_file_read: it accepts and drops the same files as before.sz > 32andhead_size <= szstill hold, and a short first read leaveshead_size = 0, so the check fails beforeheadis compared. A file that matches gets the 32 bytes it already read copied back in front, sovkCreatePipelineCachegets the same bytes._fseeki64still maps tofseekothroughhost/posix/windows.hon Linux.mirror_sync: skipping from a page in the middle of a region is safe. Every place that writes a page generation (stamp_page, and the whole-regionregion_fullpath) also setsregion_genfor that region, and generations only go up, soregion_genis never below any page's generation in its region. A clean page did nothing in the old loop (every side effect is behinddirty), andmemory_written_since/memory_written_runsalready skip partial regions the same way. Clamping toend_pagekeeps the loop bound as it was.<unordered_set>is already included invk_texture.cpp, each pointer is taken out ofgonebeforetextures.erasefrees the texture, and the set is only used for lookups, so its order doesn't matter.The new test uses the
{cxx}/{vulkan_headers}arguments thatrun_all.pyon main supports. Countingfreadbytes is a good way to pin the early drop. No existing test cuts out the changed code:test_capture_copy_runs.pyonly checks thatmirror_syncstill callsappend_capture_copy, which it does.The PR is 32 commits behind main and merges cleanly. No CI checks have run on the branch yet. Approving.
github-sync referenced this pull request2026-11-12 06:22:54 +00:00