build(recompiler): generate the shader cache version as a source file #4732

Merged
fdfawef324 merged 1 commit from upstream-pr/4732 into main 2026-10-14 17:31:28 +00:00
fdfawef324 commented 2026-10-12 19:59:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-12T19:59:42Z.


What

core/shader/recompiler/ShaderCacheVersion.cmake wrote the shader disk cache source version and the APS5_* switch list into a generated ShaderCacheVersion.hpp that ShaderDiskCache.cpp included. The version hashes every recompiler source, so any content change under core/shader/recompiler rewrote the header and recompiled ShaderDiskCache.cpp on top of the file actually edited.

The script now generates ShaderCacheVersion.cpp, which defines ShaderDiskCache::Generated::SourceVersion and Generated::RecompilerSwitches (a std::span over the same sorted switch list), both constinit. They are declared in the new core/shader/recompiler/ShaderCacheSourceVersion.hpp, which ShaderDiskCache.cpp includes. The generated directory is no longer an include directory. The new header has a different name from the old generated header, so in an existing build directory the stale ShaderCacheVersion.hpp sitting next to the generated .cpp is never included.

The hashed inputs are unchanged: the same manifest (recompiler sources, HostThreadLocal.hpp, submodule commits, compiler, build type, architecture, flags), the same include and guard checks, and the same step that skips the write when the content is unchanged (with Ninja's restat). So the version still changes exactly when it changed before.

Tested

Windows Server 2025, RTX 3060, GCC 15.2 (winlibs), Ninja Release -O3. Branch rebased on main 682ef0c17.

  • Cache key: I ran the main ShaderCacheVersion.cmake and this branch's script with the same arguments (taken from build.ninja) over this branch's tree. Both give 0x7907101dc4d8c62e and the same 26 switches. A second ninja run after the build has no work to do, so the value is stable on an unchanged tree. main itself generates 0xdce3a0ce03bf030a; the value differs only because this change edits hashed files, as any recompiler change does.
  • Rebuild: I appended a line to core/shader/recompiler/IntermediateRepresentation/src/IrType.cpp, then ran ninja -d explain -j 4 shader_recompiler_agc_driver with CCACHE_DISABLE=1. Three runs on main 682ef0c17, then three runs on this branch, back to back. The machine was at 100% CPU from other builds during all six runs, so the absolute times are high; both sides saw the same load.
    • main: the explain output marks ShaderCacheVersion.hpp and ShaderDiskCache.cpp.obj dirty, and both are rebuilt. Wall time 22.0 / 23.9 / 22.2 s.
    • This branch: only ShaderCacheVersion.cpp.obj and IrType.cpp.obj are compiled, and ShaderDiskCache.cpp does not appear in the explain output. Wall time 12.2 / 14.7 / 15.0 s.
    • Both sides also run the hashing step, which took several seconds per run under this load.
  • ctest -R "shader|recompiler" -j 4: all 26 tests pass, including agc_shader_disk_cache, shader_cache_file_read and the agc_driver_prepared_shaders* tests. No test was added: this is a build-graph change, and the red-on-main evidence is the ninja -d explain output above.
  • Built only on Windows with GCC. The Linux GCC and Clang builds were not run locally; CI is the first place they compile the new extern const declarations with their constinit definitions.
  • Not tested with a title.

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: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4834361663 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4732). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-12T19:59:42Z. --- ### What `core/shader/recompiler/ShaderCacheVersion.cmake` wrote the shader disk cache source version and the `APS5_*` switch list into a generated `ShaderCacheVersion.hpp` that `ShaderDiskCache.cpp` included. The version hashes every recompiler source, so any content change under `core/shader/recompiler` rewrote the header and recompiled `ShaderDiskCache.cpp` on top of the file actually edited. The script now generates `ShaderCacheVersion.cpp`, which defines `ShaderDiskCache::Generated::SourceVersion` and `Generated::RecompilerSwitches` (a `std::span` over the same sorted switch list), both `constinit`. They are declared in the new `core/shader/recompiler/ShaderCacheSourceVersion.hpp`, which `ShaderDiskCache.cpp` includes. The generated directory is no longer an include directory. The new header has a different name from the old generated header, so in an existing build directory the stale `ShaderCacheVersion.hpp` sitting next to the generated `.cpp` is never included. The hashed inputs are unchanged: the same manifest (recompiler sources, `HostThreadLocal.hpp`, submodule commits, compiler, build type, architecture, flags), the same include and guard checks, and the same step that skips the write when the content is unchanged (with Ninja's `restat`). So the version still changes exactly when it changed before. ### Tested Windows Server 2025, RTX 3060, GCC 15.2 (winlibs), Ninja Release -O3. Branch rebased on `main` 682ef0c17. - Cache key: I ran the `main` `ShaderCacheVersion.cmake` and this branch's script with the same arguments (taken from `build.ninja`) over this branch's tree. Both give `0x7907101dc4d8c62e` and the same 26 switches. A second `ninja` run after the build has no work to do, so the value is stable on an unchanged tree. `main` itself generates `0xdce3a0ce03bf030a`; the value differs only because this change edits hashed files, as any recompiler change does. - Rebuild: I appended a line to `core/shader/recompiler/IntermediateRepresentation/src/IrType.cpp`, then ran `ninja -d explain -j 4 shader_recompiler_agc_driver` with `CCACHE_DISABLE=1`. Three runs on `main` 682ef0c17, then three runs on this branch, back to back. The machine was at 100% CPU from other builds during all six runs, so the absolute times are high; both sides saw the same load. - `main`: the explain output marks `ShaderCacheVersion.hpp` and `ShaderDiskCache.cpp.obj` dirty, and both are rebuilt. Wall time 22.0 / 23.9 / 22.2 s. - This branch: only `ShaderCacheVersion.cpp.obj` and `IrType.cpp.obj` are compiled, and `ShaderDiskCache.cpp` does not appear in the explain output. Wall time 12.2 / 14.7 / 15.0 s. - Both sides also run the hashing step, which took several seconds per run under this load. - `ctest -R "shader|recompiler" -j 4`: all 26 tests pass, including `agc_shader_disk_cache`, `shader_cache_file_read` and the `agc_driver_prepared_shaders*` tests. No test was added: this is a build-graph change, and the red-on-main evidence is the `ninja -d explain` output above. - Built only on Windows with GCC. The Linux GCC and Clang builds were not run locally; CI is the first place they compile the new `extern const` declarations with their `constinit` definitions. - Not tested with a title. ### 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: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-14 17:05:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T17:05:17Z.


Checked the generated ShaderCacheVersion.cpp (version and the 26 switches are emitted, ShaderDiskCache.cpp only includes the static header), local build and the agc ctest scope pass on Linux GCC; merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6173853505 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4732#issuecomment-6173853505). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T17:05:17Z. --- Checked the generated `ShaderCacheVersion.cpp` (version and the 26 switches are emitted, `ShaderDiskCache.cpp` only includes the static header), local build and the agc ctest scope pass on Linux GCC; merging once the full Build is green.
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!4732
No description provided.