Repository navigation
feat(agc): persistent shader disk cache and Vulkan pipeline cache - #129
Conversation
|
A useful feature, especially since there is no recompilation of shaders at the relinker stage. The only thing I don't like is the location of the cache in the system paths. After all, with the current architecture of the project, before your changes, the final working result is an independent folder that does not depend on anything from the outside, and does not change anything outside, and this is important. Can you make the cache folder be created next to the executable file (not in the working directory, because the file can be launched from anywhere, namely next to the executable file)? |
8a270f5 to
7bab67d
Compare
|
Good point, done. The cache now lives in a |
Every run recompiled every shader: the recompiler's variant cache and the device's VkPipelineCache only lived in memory, and the first frames of a title spent hundreds of milliseconds per large program in the front end, the emitter and the optimizer. Compiled variants (the SPIR-V plus the compiled shader info and binding allocation that per-snapshot binding population needs) are now stored on disk, one file per key, written atomically by a background thread, and a later run loads them instead of compiling. The key holds every input the in-memory variant cache matches on: the in-memory recompile key (stage, code hash, stage registers, user data count, target), every code word, the host subgroup size, the binding layout, the resource specialization, and the values of the APS5_* switches the recompiler sources read (found at build time; switches that only report are left out). Entries live under a directory per source version, a build-time hash of the recompiler and AGC driver sources and the build configuration, and carry their key and checksums: an entry whose format, version, key, size or checksum does not match, or whose payload does not decode exactly, is ignored and recompiled. Directories no build used for two weeks and stale temporary files are removed. Requests under the debug probe bypass the disk cache. The device's VkPipelineCache is loaded at creation when the file's checksum and Vulkan header match the device (vendor, device and pipelineCacheUUID; the driver version is in the file name), saved every 10 s while it grew, and saved at teardown. Location: a shader_cache folder beside the running executable (not the working directory), so the relinked game stays a self-contained folder; ANYPS5_SHADER_CACHE_DIR overrides it. ANYPS5_NO_SHADER_CACHE=1 turns both caches off; the AGC tests run with it set so they never write to the user's cache. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ButHENCbXXt8h4EZuWUabJ
7bab67d to
bb60336
Compare
…, boykopovar#129) into astrobot Conflicts resolved: - Shader disk cache (boykopovar#129 as merged upstream): upstream's version, plus astrobot's imageDepthCompare and waveLayout fields (format 3). - Shader fusion: upstream's fd4700b replaces astrobot's boykopovar#124 version. - -KRzWekV120: upstream's export replaces astrobot's; its test now calls sceAgcUnknown__MKRzWekV120. - Misaligned buffer views: upstream's push-constant adjustment (3dec6ce) replaces astrobot's view aliases; GuestBufferMemory is the rebased boykopovar#121 version (write watch on shared direct memory). - DirectMemory: rebased boykopovar#121 (re-register after the shared-backing remap, aliased pages leave the watch) plus boykopovar#164's per-piece unmap. - Depth: astrobot's DepthTarget model is kept for attachments; upstream's DepthSurface module is dropped (it would duplicate it). Upstream's mip-chain colour targets, CB_COLOR_VIEW MIP_LEVEL at bits 26-29 and export formats are taken into DecodeColorBuffer. - GPU-selected V#s: upstream's gpuDescriptor replaces astrobot's opt-in runtimeDescriptor; image_bvh_intersect_ray is upstream's. - Occlusion counter dumps: upstream's Vulkan occlusion queries replace astrobot's always-visible PIXEL_PIPE_STAT dump. - AudioOut2 DualSense ports: rebased boykopovar#180 on upstream's 16-bit ports. - Pixel stage decode: rebased boykopovar#136; mesh push constants: rebased boykopovar#133. - Label waits (boykopovar#178): noteHeldAtSubmit moved into reserveOutputs.
What
The recompiler's variant cache and the device's
VkPipelineCacheonly lived in memory, so every run recompiled every shader. A title's first frames spent hundreds of milliseconds per large program in the front end, emitter and optimizer, and titles that time their queues against each other could miss their deadlines.Shader disk cache (
core/shader/recompiler/ShaderDiskCache.*):APS5_*switches that the recompiler sources read. These are collected at build time; switches that only report are excluded.static_asserts on the stored structures' sizes (Linux/x86-64/libstdc++) force the encoder to be updated when a field is added. Other open PRs that add fields toRecompileResult,CompiledShaderInfoor the binding structures will have to extend the encoder. Fields added only to the request are covered by the in-memory key and the source version. The disk cache has its ownFormatVersion(1) and doesn't useRequestSerializer, so no serializer version change is needed here.Pipeline cache: the device's
VkPipelineCacheis loaded at creation if the file's checksum and Vulkan header match the device. Vendor, device andpipelineCacheUUIDare checked, and the driver version is part of the file name. The cache is saved every 10 s while it grew, and again at teardown.Settings:
shader_cachefolder beside the running executable (found through/proc/self/exeorGetModuleFileNameW, not the working directory), so the relinked game stays a self-contained folder that changes nothing outside itself.ANYPS5_SHADER_CACHE_DIRoverrides it.ANYPS5_NO_SHADER_CACHE=1turns both caches off. The AGC ctest entries run with it set, so tests never write to the user's cache.Tested
agc_shader_disk_cachetest (in ctest) covers:agc_driver_graphics_testspasses with test(agc): link agc_driver_graphics_tests again, run it under ctest and bring its stale expectations up to date #113 merged in on a throwaway branch. That merge has a one-line conflict in theforeach(agcTest ...)list oflibSceAgcDriver/CMakeLists.txt: keep both test names.shader_cachebeside the test executable, and thatANYPS5_NO_SHADER_CACHE=1disables it.main.ctest: 62/62 pass.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository