perf(recompiler): keep the front-end resource plan in the shader disk cache #4883

Merged
nikowolf123 merged 9 commits from upstream-pr/4883 into main 2026-10-14 00:33:02 +00:00
nikowolf123 commented 2026-10-13 01:47:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T01:47:52Z.


What

With a warm shader cache, every launch still runs the whole recompiler front end once for every shader. getSource builds ResourceProgram (decode, CFG, structurizer, translation, SSA, the fold passes, SrtWalker, ResourceTracker, then ExtractPlan) before findOrCompileVariant looks in the disk cache, because the disk cache keeps compiled variants but not the resource plan. Only SPIR-V emission is skipped. #2292 measured 0.3 to 0.8 s per registration with 0 cache misses and lists this fix as its option 4. #2774 (about 1,950 hits, no misses) found the plan "is built before ShaderDiskCache::Load is consulted". #3504 hit its slow pass "with a warm shader cache", and #4404 reports hundreds of queued preparation jobs on a warm run with zero misses.

This PR stores the plan in the disk cache and loads it before the front end:

  • Since #471 the plan owns its values (ownPlanValues), so it can be written out. EncodePlan writes the value graph in storage order as LEB128 integers (opcode, type, id, flags, register, immediate, each argument as the zigzag distance to the value's own index, phi predecessor blocks), the roots as value indices, and the plain data. ShaderInfo uses the variant's encoder, now split out of encodeInfo. DecodePlan rebuilds the graph the way ownPlanValues does. It rejects an unknown opcode, an overlong integer, and a value, block, descriptor source or image index past the end, including an image table's heap and material sources and the targets of control-flow edges.
  • A plan entry uses the variant entry's header, key and payload hashes, directory and background writer. Its key is the in-memory source key (RecompileCacheKey::Build and the host subgroup size), every code word and the switch key, under a plan tag. The binding layout is not in it, so all layouts of a shader share one plan. FormatVersion 30. Size asserts and field counts cover the plan structures (below).
  • getSource tries LoadPlan first. On a hit the program stays null: findOrCompileVariant already rebuilds it when no stored variant fits a layout. On a miss it builds the plan as before and stores it. A plan the front end refuses is not stored. The disk is not used when the cache is off, under the debug probe, with APS5_DUMP_IR, or with APS5_NO_PERF_DISK_PLANS=1, a cache-neutral switch for comparisons.
  • The 10 s cache report counts plan hits, misses, writes and load failures. FrontEndBuilds() counts PrepareResourceProgram calls, for the tests.

Field counts: the plan and ShaderInfo encoders write their structures field by field, and until now the size asserts were the only reminder to update them. A field that fits in existing padding does not change the size. main's #5097 added ShaderInfo::layerExported and sizeof(ShaderInfo) stayed 232. The three bools #5089 adds to DescriptorSource::IndirectImage keep it at 28. A size assert catches neither, so a missed encoder update would go unnoticed and a warm cache would hand back entries without the new field. Next to the size asserts, a static_assert now pins the field count of every aggregate the plan codec reaches: IrResourcePlan, GuestRegister, MemoryInfo, DescriptorSource, IndirectImage, ResourceBlock, SrtRead, UniformFill, UniformFillPlan, and ShaderInfo with its buffer, image, sampler, sampled-pair and stage input and output records. The count is found by brace-initializing the aggregate with more and more values of a type that converts to anything, until that stops compiling. This is plain C++20 and does not depend on the ABI, so unlike the size asserts it is checked on MinGW too. IrValue is a class with private state, so it keeps only its size assert.

This adds no new correctness assumption. A warm run on main already pairs a variant compiled by an earlier process with a plan rebuilt by the current one, and both come from the same front end under the same SourceVersion. Specialized modules are still built in each process. Storing them would be a separate change.

Bytes per plan entry: 1.4 to 7.1 KB for the 15 in-tree fixtures in the test (4.3 KB on average). Control-flow conditions can pull most of a program into the plan, so the worst case is large. A synthetic compute shader with a branch every 20 dwords has plans of 518 KB, 2.07 MB and 8.25 MB at 2,038, 8,038 and 32,038 dwords. Its variant entries are 935 KB, 3.70 MB and 14.7 MB. Fixed-width fields would have made those plans 2.5 MB at 2,038 dwords, which is why values are LEB128.

Overlap, all textual: #4806 changes Words() to Read() next to these hunks in Recompiler.cpp and ShaderDiskCache.cpp. #4732 generates the cache version, and #4475 and other open PRs also bump FormatVersion. #4271 and #4757 edit Recompiler.cpp near getSource. #1341 adds an execution plan to IrResourcePlan, which would be rebuilt after DecodePlan. #5089 adds three fields to IndirectImage. Whichever of #5089 and this PR lands second must add them to the plan encoder, and the field count turns a missed update into a build error. No open or closed PR stores the plan.

Tested

WSL Ubuntu, i9-14900KF, GCC 15, the CI configuration (Release, SPIRV-Tools on, lavapipe), with the series on main d1fd9372b. Also native Windows 11 (WinLibs GCC 15.2.0, Release with tests) on an RTX 5080 (NVIDIA 616.92), same head: full ctest with ANYPS5_REQUIRE_VULKAN=1, 1021 tests, 0 failed, 7 skipped as tools/check_skips.py --job windows expects; agc_shader_disk_cache, including its two-process runs, passes there. Not tested with a title.

  • Full ctest: 1004 tests, 0 failures. 41 tests skipped themselves because lavapipe lacks a feature or there is no display. The WSL distro restarted several times during the session, so the final run went in chunks of 100 tests.
  • agc_shader_disk_cache (1.2 s) gains these tests:
    • Round trips of 15 in-tree shader fixtures and a hand-built plan. The fixtures come from agc_shader_memory, except "descriptor invariant phi", which is its "descriptor phi image" with both branches loading the same descriptor. They cover SRT reads, guarded and chained pointers, control-flow conditions, an indirect image table, a loop phi, an invariant descriptor phi and a fragment shader. The hand-built plan gives every plan-level field, every MemoryInfo and image table field, the uniform fill and a 64-bit immediate a value other than the default.
    • Every decoded plan must equal its original field by field, compared without the codec: the value graph by storage index (opcode, type, id, flags, register, immediate, arguments, phi blocks), the block ids, the roots and the plain data.
    • Each fixture's original and decoded plan is also materialized over 1000 random user-data and memory runtimes, and the snapshot, poison, null-root count and read trace (or the error) must match. The hand-built plan is not a walkable SRT, so it is covered by the field comparison only.
    • Truncated, bit-flipped, previous-format and other-source-version entries are rejected, and malformed plans do not decode.
    • The plan key follows the code, the target and the host subgroup size, but not the layout, the addresses or the user data.
    • Two processes share one cache directory and prepare, capture and materialize all 15 fixtures. The second process must run the front end 0 times, hit 15 plans and 15 variants, and produce byte-identical SPIR-V, bindings, push constants, snapshots, read traces and plans. It then builds each fixture's plan with its own front end, and that plan must equal the stored one field by field.
    • With APS5_NO_PERF_DISK_PLANS=1, a process on the same cache runs the front end for all 15 fixtures, loads and stores no plan, still hits the 15 stored variants, and produces the same output.
    • A damaged plan entry is rejected, rebuilt alone with the same output, and stored again. A changed code word and another switch value miss, and a refused plan is not stored.
  • Fails before, passes after (run before the invariant phi fixture was added, so with 14 fixtures): with only the getSource hunk reverted, the second process reports front end builds 14, plan hits 0, plan misses 0, plan load failures 0, variant hits 14, variant misses 0 and the test fails. With the change it passes.
  • Field coverage: for each of 51 plan fields and value parts in turn, I made EncodePlan write the default value instead, which is the same as leaving the field out of both the encoder and the decoder. The test fails for every one of them.
  • Whole suite on the earlier base 43e3a70f8, with local instrumentation that is not part of the PR: every ResourceMaterializer::Materialize call also encoded, decoded and re-encoded its plan, materialized the decoded copy with the same runtime, and aborted on any difference. All 1002 tests passed. Across 266 test executables besides the disk-cache test, more than 3,700 materializations matched (snapshots, read traces and error messages), with no mismatch.

Performance: there is no title or Performance report summary line here, only a synthetic harness. It is a compute shader with 16 V#s loaded from an SRT and a buffer load, an ALU chain and a divergent branch every 20 dwords. It calls PrepareShader in one process with an empty cache (cold) and then in a new process with the same cache (warm), with APS5_SPIRV_OPT=none. main 43e3a70f8 and this series on the same base were built from one tree and run interleaved on the same machine. Since then main has gained one front-end pass and one ShaderInfo field (#4031's ancillary word), which these runs do not include. Load average was 7 to 20 from other jobs. Medians of 7 runs (5 at 32k):

  • 2,038 dwords: warm PrepareShader 395 ms on main, 25 ms with this PR (15.7x).
  • 8,038 dwords: 711 ms on main, 39 ms with this PR (18.1x).
  • 32,038 dwords: 6.7 s on main, 0.27 s with this PR (25x). This size is the noisiest: main's warm runs ranged from 3.2 to 12.1 s and this PR's from 0.19 to 0.37 s.
  • With APS5_NO_PERF_DISK_PLANS=1, the branch's warm runs match main: 420 ms, 698 ms and 5.2 s.
  • Cold runs did not change measurably at 2k and 8k (702 and 1,337 ms on main, 672 and 1,281 ms with this PR). At 32k both builds ranged from 7 to 19 s under that load. The plan is encoded on the writer thread, and that encode took 6, 41 and 83 ms at the three sizes. Decoding took 10, 68 and 135 ms.

I can attach the JSON lines of every run, the harness source and the instrumentation patch. A warm-start comparison on a title would show the real gain: start-up time with and without APS5_NO_PERF_DISK_PLANS=1 against the same cache, from the reporters of #2292, #2774 or #4404.

  • Rebased onto main 0c3dc9ca2 for this pull request: it builds in the CI configuration and the 32 shader, pipeline-library, structurizer and control-flow tests (ctest -R 'agc_shader|agc_driver_prepared|agc_pipeline_library|agc_structurizer|control_flow') pass on lavapipe.

Rebased onto main 60fb61870. main had added a reclaim argument to getSource and ResourceProgram (57b2dc858), which conflicted with the disk-plan path in getSource. The plan loaded from the disk cache is used as before; when there is none, ResourceProgram is built with main's reclaim argument. PrepareShader still passes reclaim = false, and on a disk-plan hit its program is rebuilt by the existing fallback in findOrCompileVariant when a variant must be compiled. The per-file diff is unchanged. WSL2 Ubuntu 26.04, lavapipe (Mesa 26.0.8), CI configuration: the disk cache, structurizer and control-flow tests 16 of 16, full ctest 1067 of 1067.

Phi coverage with #5181: the new fixture "descriptor invariant phi" loads one image descriptor from the same SRT offset on both sides of a branch. Its plan keeps eight invariant phis as descriptor dwords, and the CPU walk evaluates them, from the built and from the stored plan, to the image descriptor in the SRT. The only other planned phi is the loop counter of "bindless sample in a loop latch", in a latch condition the walk cannot evaluate. With #5181 16bd6505e merged locally (the plan codec moved to its value arena), the phi check passes with or without the new fixture, because #5181 counts CompositeExtractU32x2 as evaluable on its own and keeps that latch condition. With extracts checked through their source instead, it fails with no fixture plans a phi without the fixture and passes with it. On the branch, ctest -R 'disk_cache|shader_cache|agc_shader|recompiler|structurizer': 16 of 16.

Rebased onto main 0214069e3. main's #5097 added layerExported to the ShaderInfo encoder, which this PR splits into encodeShaderInfo and decodeShaderInfo. The flag is now written last in both, right after rasterPrimitive, as on main. A variant entry's payload therefore has the same bytes as on main, and plans store the flag too. The entry round trip now sets layerExported, as it does the other ShaderInfo flags, so an encoder and decoder that both skip it fail with entry round trip: shader info differs. #5097 also took FormatVersion 29, so this PR moves to 30. Against main, the series changes the same lines as before the rebase except the FormatVersion line, plus the field-count asserts. Nothing else main changed after 60fb61870 touches a structure the codecs write, apart from the new StageInputKind::LayerExported, which the stage-input encoder writes as its integer value. WSL2 Ubuntu 26.04, lavapipe (Mesa 26.0.8), CI configuration: ctest -R 'disk_cache|shader_cache|agc_shader|recompiler|structurizer' 16 of 16, full ctest 1077 of 1077 (43 skipped themselves: lavapipe features, and the WSLg display has no 120 Hz mode). The field-count asserts compile in that build (GCC 15.2), with Clang 21, and in a native Windows compile of ShaderDiskCache.cpp with MinGW GCC 15.2.0 (WinLibs r7). With #5089's three bools added to IndirectImage, every size assert still holds and the build stops at static assertion failed: IndirectImage changed: update the plan encoder (the comparison reduces to '(10 == 7)') with each of those compilers. A bool added in the padding of ShaderInfo, MemoryInfo, IrResourcePlan, StageInput or SamplerResource also keeps its size and stops the build at that structure's field count.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: lavapipe (Mesa 26.0.8, llvmpipe) on WSL2 Ubuntu 26.04; NVIDIA GeForce RTX 5080, driver 616.92, Windows 11
  • AI-assisted: yes. Written with Claude Code; I reviewed every line and ran the tests above.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4837198527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4883). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-13T01:47:52Z. --- ### What With a warm shader cache, every launch still runs the whole recompiler front end once for every shader. `getSource` builds `ResourceProgram` (decode, CFG, structurizer, translation, SSA, the fold passes, SrtWalker, ResourceTracker, then `ExtractPlan`) before `findOrCompileVariant` looks in the disk cache, because the disk cache keeps compiled variants but not the resource plan. Only SPIR-V emission is skipped. #2292 measured 0.3 to 0.8 s per registration with 0 cache misses and lists this fix as its option 4. #2774 (about 1,950 hits, no misses) found the plan "is built before `ShaderDiskCache::Load` is consulted". #3504 hit its slow pass "with a warm shader cache", and #4404 reports hundreds of queued preparation jobs on a warm run with zero misses. This PR stores the plan in the disk cache and loads it before the front end: - Since #471 the plan owns its values (`ownPlanValues`), so it can be written out. `EncodePlan` writes the value graph in storage order as LEB128 integers (opcode, type, id, flags, register, immediate, each argument as the zigzag distance to the value's own index, phi predecessor blocks), the roots as value indices, and the plain data. ShaderInfo uses the variant's encoder, now split out of `encodeInfo`. `DecodePlan` rebuilds the graph the way `ownPlanValues` does. It rejects an unknown opcode, an overlong integer, and a value, block, descriptor source or image index past the end, including an image table's heap and material sources and the targets of control-flow edges. - A plan entry uses the variant entry's header, key and payload hashes, directory and background writer. Its key is the in-memory source key (`RecompileCacheKey::Build` and the host subgroup size), every code word and the switch key, under a plan tag. The binding layout is not in it, so all layouts of a shader share one plan. FormatVersion 30. Size asserts and field counts cover the plan structures (below). - `getSource` tries `LoadPlan` first. On a hit the program stays null: `findOrCompileVariant` already rebuilds it when no stored variant fits a layout. On a miss it builds the plan as before and stores it. A plan the front end refuses is not stored. The disk is not used when the cache is off, under the debug probe, with `APS5_DUMP_IR`, or with `APS5_NO_PERF_DISK_PLANS=1`, a cache-neutral switch for comparisons. - The 10 s cache report counts plan hits, misses, writes and load failures. `FrontEndBuilds()` counts `PrepareResourceProgram` calls, for the tests. Field counts: the plan and ShaderInfo encoders write their structures field by field, and until now the size asserts were the only reminder to update them. A field that fits in existing padding does not change the size. `main`'s #5097 added `ShaderInfo::layerExported` and `sizeof(ShaderInfo)` stayed 232. The three bools #5089 adds to `DescriptorSource::IndirectImage` keep it at 28. A size assert catches neither, so a missed encoder update would go unnoticed and a warm cache would hand back entries without the new field. Next to the size asserts, a `static_assert` now pins the field count of every aggregate the plan codec reaches: `IrResourcePlan`, `GuestRegister`, `MemoryInfo`, `DescriptorSource`, `IndirectImage`, `ResourceBlock`, `SrtRead`, `UniformFill`, `UniformFillPlan`, and `ShaderInfo` with its buffer, image, sampler, sampled-pair and stage input and output records. The count is found by brace-initializing the aggregate with more and more values of a type that converts to anything, until that stops compiling. This is plain C++20 and does not depend on the ABI, so unlike the size asserts it is checked on MinGW too. `IrValue` is a class with private state, so it keeps only its size assert. This adds no new correctness assumption. A warm run on `main` already pairs a variant compiled by an earlier process with a plan rebuilt by the current one, and both come from the same front end under the same SourceVersion. Specialized modules are still built in each process. Storing them would be a separate change. Bytes per plan entry: 1.4 to 7.1 KB for the 15 in-tree fixtures in the test (4.3 KB on average). Control-flow conditions can pull most of a program into the plan, so the worst case is large. A synthetic compute shader with a branch every 20 dwords has plans of 518 KB, 2.07 MB and 8.25 MB at 2,038, 8,038 and 32,038 dwords. Its variant entries are 935 KB, 3.70 MB and 14.7 MB. Fixed-width fields would have made those plans 2.5 MB at 2,038 dwords, which is why values are LEB128. Overlap, all textual: #4806 changes `Words()` to `Read()` next to these hunks in Recompiler.cpp and ShaderDiskCache.cpp. #4732 generates the cache version, and #4475 and other open PRs also bump FormatVersion. #4271 and #4757 edit Recompiler.cpp near `getSource`. #1341 adds an execution plan to `IrResourcePlan`, which would be rebuilt after `DecodePlan`. #5089 adds three fields to `IndirectImage`. Whichever of #5089 and this PR lands second must add them to the plan encoder, and the field count turns a missed update into a build error. No open or closed PR stores the plan. ### Tested WSL Ubuntu, i9-14900KF, GCC 15, the CI configuration (Release, SPIRV-Tools on, lavapipe), with the series on `main` d1fd9372b. Also native Windows 11 (WinLibs GCC 15.2.0, Release with tests) on an RTX 5080 (NVIDIA 616.92), same head: full `ctest` with `ANYPS5_REQUIRE_VULKAN=1`, 1021 tests, 0 failed, 7 skipped as `tools/check_skips.py --job windows` expects; `agc_shader_disk_cache`, including its two-process runs, passes there. Not tested with a title. - Full ctest: 1004 tests, 0 failures. 41 tests skipped themselves because lavapipe lacks a feature or there is no display. The WSL distro restarted several times during the session, so the final run went in chunks of 100 tests. - `agc_shader_disk_cache` (1.2 s) gains these tests: - Round trips of 15 in-tree shader fixtures and a hand-built plan. The fixtures come from `agc_shader_memory`, except "descriptor invariant phi", which is its "descriptor phi image" with both branches loading the same descriptor. They cover SRT reads, guarded and chained pointers, control-flow conditions, an indirect image table, a loop phi, an invariant descriptor phi and a fragment shader. The hand-built plan gives every plan-level field, every `MemoryInfo` and image table field, the uniform fill and a 64-bit immediate a value other than the default. - Every decoded plan must equal its original field by field, compared without the codec: the value graph by storage index (opcode, type, id, flags, register, immediate, arguments, phi blocks), the block ids, the roots and the plain data. - Each fixture's original and decoded plan is also materialized over 1000 random user-data and memory runtimes, and the snapshot, poison, null-root count and read trace (or the error) must match. The hand-built plan is not a walkable SRT, so it is covered by the field comparison only. - Truncated, bit-flipped, previous-format and other-source-version entries are rejected, and malformed plans do not decode. - The plan key follows the code, the target and the host subgroup size, but not the layout, the addresses or the user data. - Two processes share one cache directory and prepare, capture and materialize all 15 fixtures. The second process must run the front end 0 times, hit 15 plans and 15 variants, and produce byte-identical SPIR-V, bindings, push constants, snapshots, read traces and plans. It then builds each fixture's plan with its own front end, and that plan must equal the stored one field by field. - With `APS5_NO_PERF_DISK_PLANS=1`, a process on the same cache runs the front end for all 15 fixtures, loads and stores no plan, still hits the 15 stored variants, and produces the same output. - A damaged plan entry is rejected, rebuilt alone with the same output, and stored again. A changed code word and another switch value miss, and a refused plan is not stored. - Fails before, passes after (run before the invariant phi fixture was added, so with 14 fixtures): with only the `getSource` hunk reverted, the second process reports `front end builds 14, plan hits 0, plan misses 0, plan load failures 0, variant hits 14, variant misses 0` and the test fails. With the change it passes. - Field coverage: for each of 51 plan fields and value parts in turn, I made `EncodePlan` write the default value instead, which is the same as leaving the field out of both the encoder and the decoder. The test fails for every one of them. - Whole suite on the earlier base 43e3a70f8, with local instrumentation that is not part of the PR: every `ResourceMaterializer::Materialize` call also encoded, decoded and re-encoded its plan, materialized the decoded copy with the same runtime, and aborted on any difference. All 1002 tests passed. Across 266 test executables besides the disk-cache test, more than 3,700 materializations matched (snapshots, read traces and error messages), with no mismatch. Performance: there is no title or Performance report summary line here, only a synthetic harness. It is a compute shader with 16 V#s loaded from an SRT and a buffer load, an ALU chain and a divergent branch every 20 dwords. It calls `PrepareShader` in one process with an empty cache (cold) and then in a new process with the same cache (warm), with `APS5_SPIRV_OPT=none`. `main` 43e3a70f8 and this series on the same base were built from one tree and run interleaved on the same machine. Since then `main` has gained one front-end pass and one ShaderInfo field (#4031's ancillary word), which these runs do not include. Load average was 7 to 20 from other jobs. Medians of 7 runs (5 at 32k): - 2,038 dwords: warm `PrepareShader` 395 ms on main, 25 ms with this PR (15.7x). - 8,038 dwords: 711 ms on main, 39 ms with this PR (18.1x). - 32,038 dwords: 6.7 s on main, 0.27 s with this PR (25x). This size is the noisiest: main's warm runs ranged from 3.2 to 12.1 s and this PR's from 0.19 to 0.37 s. - With `APS5_NO_PERF_DISK_PLANS=1`, the branch's warm runs match main: 420 ms, 698 ms and 5.2 s. - Cold runs did not change measurably at 2k and 8k (702 and 1,337 ms on main, 672 and 1,281 ms with this PR). At 32k both builds ranged from 7 to 19 s under that load. The plan is encoded on the writer thread, and that encode took 6, 41 and 83 ms at the three sizes. Decoding took 10, 68 and 135 ms. I can attach the JSON lines of every run, the harness source and the instrumentation patch. A warm-start comparison on a title would show the real gain: start-up time with and without `APS5_NO_PERF_DISK_PLANS=1` against the same cache, from the reporters of #2292, #2774 or #4404. - Rebased onto `main` 0c3dc9ca2 for this pull request: it builds in the CI configuration and the 32 shader, pipeline-library, structurizer and control-flow tests (`ctest -R 'agc_shader|agc_driver_prepared|agc_pipeline_library|agc_structurizer|control_flow'`) pass on lavapipe. Rebased onto `main` 60fb61870. `main` had added a `reclaim` argument to `getSource` and `ResourceProgram` (57b2dc858), which conflicted with the disk-plan path in `getSource`. The plan loaded from the disk cache is used as before; when there is none, `ResourceProgram` is built with `main`'s `reclaim` argument. `PrepareShader` still passes `reclaim = false`, and on a disk-plan hit its program is rebuilt by the existing fallback in `findOrCompileVariant` when a variant must be compiled. The per-file diff is unchanged. WSL2 Ubuntu 26.04, lavapipe (Mesa 26.0.8), CI configuration: the disk cache, structurizer and control-flow tests 16 of 16, full `ctest` 1067 of 1067. Phi coverage with #5181: the new fixture "descriptor invariant phi" loads one image descriptor from the same SRT offset on both sides of a branch. Its plan keeps eight invariant phis as descriptor dwords, and the CPU walk evaluates them, from the built and from the stored plan, to the image descriptor in the SRT. The only other planned phi is the loop counter of "bindless sample in a loop latch", in a latch condition the walk cannot evaluate. With #5181 16bd6505e merged locally (the plan codec moved to its value arena), the phi check passes with or without the new fixture, because #5181 counts `CompositeExtractU32x2` as evaluable on its own and keeps that latch condition. With extracts checked through their source instead, it fails with `no fixture plans a phi` without the fixture and passes with it. On the branch, `ctest -R 'disk_cache|shader_cache|agc_shader|recompiler|structurizer'`: 16 of 16. Rebased onto `main` 0214069e3. `main`'s #5097 added `layerExported` to the ShaderInfo encoder, which this PR splits into `encodeShaderInfo` and `decodeShaderInfo`. The flag is now written last in both, right after `rasterPrimitive`, as on `main`. A variant entry's payload therefore has the same bytes as on `main`, and plans store the flag too. The entry round trip now sets `layerExported`, as it does the other ShaderInfo flags, so an encoder and decoder that both skip it fail with `entry round trip: shader info differs`. #5097 also took FormatVersion 29, so this PR moves to 30. Against `main`, the series changes the same lines as before the rebase except the FormatVersion line, plus the field-count asserts. Nothing else `main` changed after 60fb61870 touches a structure the codecs write, apart from the new `StageInputKind::LayerExported`, which the stage-input encoder writes as its integer value. WSL2 Ubuntu 26.04, lavapipe (Mesa 26.0.8), CI configuration: `ctest -R 'disk_cache|shader_cache|agc_shader|recompiler|structurizer'` 16 of 16, full `ctest` 1077 of 1077 (43 skipped themselves: lavapipe features, and the WSLg display has no 120 Hz mode). The field-count asserts compile in that build (GCC 15.2), with Clang 21, and in a native Windows compile of `ShaderDiskCache.cpp` with MinGW GCC 15.2.0 (WinLibs r7). With #5089's three bools added to `IndirectImage`, every size assert still holds and the build stops at `static assertion failed: IndirectImage changed: update the plan encoder` (`the comparison reduces to '(10 == 7)'`) with each of those compilers. A bool added in the padding of `ShaderInfo`, `MemoryInfo`, `IrResourcePlan`, `StageInput` or `SamplerResource` also keeps its size and stops the build at that structure's field count. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: lavapipe (Mesa 26.0.8, llvmpipe) on WSL2 Ubuntu 26.04; NVIDIA GeForce RTX 5080, driver 616.92, Windows 11 - [x] AI-assisted: yes. Written with Claude Code; I reviewed every line and ran the tests above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
EagleBearerYS commented 2026-10-13 15:13:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-13T15:13:29Z.


A title measurement: Resident Evil Village (PPSA01556, 01.210.000) on Windows 11, RTX 3070 Laptop, WinLibs GCC 15.2.0 r7, Release. It registers its whole PSO cache at boot behind a black screen, about 6,000 shaders, so the boot measures shader preparation directly.

The build is main b478fbbb1 plus #4949's register change (so it gets past its first frame) and this PR. Merging this PR needed one conflict resolved in Recompiler.cpp: #4271 added a reclaim parameter to getSource and ResourceProgram, which I kept. I filled the cache with one cold run, then ran warm runs on the same cache, alternating APS5_NO_PERF_DISK_PLANS=1 and the default. Shaders back are the [shader-disk-cache] totals:

Run Plans from the cache Shaders back at 32 s at 64 s at 80 s
1 off 1,380 1,994 2,182
2 on 2,851 (all cached)
3 off 1,463 2,007 2,233
4 on 2,961 (all cached)

The cold run took about 240 s to reach 2,800 shaders. The front end is the bottleneck of this boot, and with this PR a warm boot skips most of it.

A heads-up on the tests: #5181 leaves branch conditions the CPU walk can never evaluate out of resource plans. I had the same idea locally. With it, agc_shader_disk_cache's coverage check failed on top of this PR with "no fixture plans a phi": the only fixture phis are the loop counter of the "descriptor phi loop" fixture (not invariant, so never evaluable) and the branch on it. Each PR passed on its own. #5181 is likely to hit the same check. A fixture whose plan keeps an evaluable phi would cover both, for example an invariant phi that feeds a descriptor dword.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148776870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4883#issuecomment-6148776870). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-13T15:13:29Z. --- A title measurement: Resident Evil Village (PPSA01556, 01.210.000) on Windows 11, RTX 3070 Laptop, WinLibs GCC 15.2.0 r7, Release. It registers its whole PSO cache at boot behind a black screen, about 6,000 shaders, so the boot measures shader preparation directly. The build is `main` b478fbbb1 plus #4949's register change (so it gets past its first frame) and this PR. Merging this PR needed one conflict resolved in `Recompiler.cpp`: #4271 added a `reclaim` parameter to `getSource` and `ResourceProgram`, which I kept. I filled the cache with one cold run, then ran warm runs on the same cache, alternating `APS5_NO_PERF_DISK_PLANS=1` and the default. Shaders back are the `[shader-disk-cache]` totals: | Run | Plans from the cache | Shaders back at 32 s | at 64 s | at 80 s | |---|---|---|---|---| | 1 | off | 1,380 | 1,994 | 2,182 | | 2 | on | 2,851 (all cached) | | | | 3 | off | 1,463 | 2,007 | 2,233 | | 4 | on | 2,961 (all cached) | | | The cold run took about 240 s to reach 2,800 shaders. The front end is the bottleneck of this boot, and with this PR a warm boot skips most of it. A heads-up on the tests: #5181 leaves branch conditions the CPU walk can never evaluate out of resource plans. I had the same idea locally. With it, `agc_shader_disk_cache`'s coverage check failed on top of this PR with "no fixture plans a phi": the only fixture phis are the loop counter of the "descriptor phi loop" fixture (not invariant, so never evaluable) and the branch on it. Each PR passed on its own. #5181 is likely to hit the same check. A fixture whose plan keeps an evaluable phi would cover both, for example an invariant phi that feeds a descriptor dword.
nikowolf123 commented 2026-10-13 15:38:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T15:38:52Z.


Thank you, that's the title measurement this PR needed. On a warm cache, Resident Evil Village gets all of its roughly 2,900 shaders back by 32 s with plans from the disk cache, against about 1,400 without them.

The reclaim conflict you resolved is the one I resolved in today's rebase (3d86335b9), the same way: the disk-plan path stays, and ResourceProgram gets main's reclaim argument when there is no stored plan.

Thanks also for the #5181 heads-up. I'm adding a fixture whose plan keeps an evaluable phi, so the coverage check holds in whichever order the two PRs land. I'll post here when it's pushed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6149280934 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4883#issuecomment-6149280934). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-13T15:38:52Z. --- Thank you, that's the title measurement this PR needed. On a warm cache, Resident Evil Village gets all of its roughly 2,900 shaders back by 32 s with plans from the disk cache, against about 1,400 without them. The `reclaim` conflict you resolved is the one I resolved in today's rebase (3d86335b9), the same way: the disk-plan path stays, and `ResourceProgram` gets `main`'s `reclaim` argument when there is no stored plan. Thanks also for the #5181 heads-up. I'm adding a fixture whose plan keeps an evaluable phi, so the coverage check holds in whichever order the two PRs land. I'll post here when it's pushed.
nikowolf123 commented 2026-10-13 17:34:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nikowolf123 on 2026-10-13T17:34:15Z.


@EagleBearerYS the fixture is pushed in ce8944f85. "descriptor invariant phi" loads one image descriptor from the same SRT offset on both sides of a branch. Its plan keeps eight invariant phis as descriptor dwords, and the CPU walk evaluates them from both the built plan and the stored one.

As it turns out, with #5181's current head (16bd6505e) the phi check would pass even without it. #5181's MayEvaluate counts CompositeExtractU32x2 as evaluable without looking at its source. So the loop-latch condition of "bindless sample in a loop latch" stays in the plan, and so does its counter phi, even though the walk can never evaluate that condition. If extracts were checked through their source, that condition and its phi would be dropped, and the check would fail with no fixture plans a phi. The new fixture keeps phis covered in either case, whichever PR lands first.

The same push rebases onto main (format 30, with main's layerExported carried into the split ShaderInfo codec) and adds 664ad7703, which pins the field count of every structure the plan codec writes, so a field added inside padding (as in #5089) breaks the build until the codec writes it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151418329 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4883#issuecomment-6151418329). Originally posted by [nikowolf123](https://github.com/nikowolf123) on 2026-10-13T17:34:15Z. --- @EagleBearerYS the fixture is pushed in ce8944f85. "descriptor invariant phi" loads one image descriptor from the same SRT offset on both sides of a branch. Its plan keeps eight invariant phis as descriptor dwords, and the CPU walk evaluates them from both the built plan and the stored one. As it turns out, with #5181's current head (16bd6505e) the phi check would pass even without it. #5181's `MayEvaluate` counts `CompositeExtractU32x2` as evaluable without looking at its source. So the loop-latch condition of "bindless sample in a loop latch" stays in the plan, and so does its counter phi, even though the walk can never evaluate that condition. If extracts were checked through their source, that condition and its phi would be dropped, and the check would fail with `no fixture plans a phi`. The new fixture keeps phis covered in either case, whichever PR lands first. The same push rebases onto `main` (format 30, with `main`'s `layerExported` carried into the split ShaderInfo codec) and adds 664ad7703, which pins the field count of every structure the plan codec writes, so a field added inside padding (as in #5089) breaks the build until the codec writes it.
github-actions[bot] commented 2026-10-13 17:45:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T17:45:57Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5315 core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp L20-21, L1084
#5500 core/shader/recompiler/ShaderDiskCache.cpp L560-561, L671
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6151624304 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4883#issuecomment-6151624304). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T17:45:57Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5315 | `core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp` [L20-21](https://github.com/boykopovar/AnyPS5/blob/7cc6cd86335d23b120a08eb5680324977a9eaf8c/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp#L20-L21), [L1084](https://github.com/boykopovar/AnyPS5/blob/7cc6cd86335d23b120a08eb5680324977a9eaf8c/core/libs/prx/libSceAgcDriver/tests/ShaderDiskCache.cpp#L1084) | | | | #5500 | `core/shader/recompiler/ShaderDiskCache.cpp` [L560-561](https://github.com/boykopovar/AnyPS5/blob/7cc6cd86335d23b120a08eb5680324977a9eaf8c/core/shader/recompiler/ShaderDiskCache.cpp#L560-L561), [L671](https://github.com/boykopovar/AnyPS5/blob/7cc6cd86335d23b120a08eb5680324977a9eaf8c/core/shader/recompiler/ShaderDiskCache.cpp#L671) | | |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4883
No description provided.