From 2e461aa2e4750911b0bee57d204e38e024eacab3 Mon Sep 17 00:00:00 2001 From: fdfawef324 <287205748+fdfawef324@users.noreply.github.com> Date: Mon, 12 Oct 2026 14:48:55 -0400 Subject: [PATCH] build(recompiler): generate the shader cache version as a source file ShaderCacheVersion.cmake wrote the 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 that header and recompiled ShaderDiskCache.cpp next to the file actually edited. The script now writes ShaderCacheVersion.cpp, which defines Generated::SourceVersion and Generated::RecompilerSwitches (a span over the same sorted switch list) with constinit. They are declared in the new ShaderCacheSourceVersion.hpp in the source tree, which ShaderDiskCache.cpp includes; the generated directory is no longer an include directory. The header has a different name from the old generated one so that a build directory that still holds the stale ShaderCacheVersion.hpp next to the generated .cpp cannot pick it up. What is hashed is unchanged: the same manifest (recompiler sources, HostThreadLocal.hpp, submodule commits, compiler, build type, architecture and flags), the same checks and the same rewrite-only- when-different step, so the version still changes exactly when it did. Running the upstream/main script and this one with the same arguments over this tree gives the same version (0x7907101dc4d8c62e) and the same 26 switches, and a second ninja run has no work to do. The value differs from the one main 682ef0c17 generates (0xdce3a0ce03bf030a) only because this commit edits hashed files, as any recompiler change does. Tested with ninja -d explain -j 4 shader_recompiler_agc_driver, CCACHE_DISABLE=1, after appending a line to IntermediateRepresentation/src/IrType.cpp, three runs on main and then three runs on this commit back to back, with the machine at 100% CPU from other builds. On main ShaderCacheVersion.hpp and ShaderDiskCache.cpp.obj are dirty and the rebuild takes 22.0/23.9/22.2 s. With this change only ShaderCacheVersion.cpp.obj and IrType.cpp.obj are compiled, ShaderDiskCache.cpp is absent from the explain output, and the rebuild takes 12.2/14.7/15.0 s. The shader and recompiler ctest set (26 tests) passes. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex --- core/shader/recompiler/CMakeLists.txt | 9 ++++----- .../recompiler/ShaderCacheSourceVersion.hpp | 15 +++++++++++++++ core/shader/recompiler/ShaderCacheVersion.cmake | 17 ++++++++--------- core/shader/recompiler/ShaderDiskCache.cpp | 2 +- 4 files changed, 28 insertions(+), 15 deletions(-) create mode 100644 core/shader/recompiler/ShaderCacheSourceVersion.hpp diff --git a/core/shader/recompiler/CMakeLists.txt b/core/shader/recompiler/CMakeLists.txt index d4ff8cefaa..6b11c97a3d 100644 --- a/core/shader/recompiler/CMakeLists.txt +++ b/core/shader/recompiler/CMakeLists.txt @@ -165,7 +165,7 @@ function(add_shader_recompiler target runtimeTarget) target_compile_features(${target} PUBLIC cxx_std_20) set(shaderCacheGeneratedDir "${CMAKE_CURRENT_BINARY_DIR}/${target}_generated") - set(shaderCacheVersionHeader "${shaderCacheGeneratedDir}/ShaderCacheVersion.hpp") + set(shaderCacheVersionSource "${shaderCacheGeneratedDir}/ShaderCacheVersion.cpp") file(GLOB_RECURSE shaderCacheRecompilerSources CONFIGURE_DEPENDS "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/*.cpp" "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/*.hpp" @@ -274,21 +274,20 @@ function(add_shader_recompiler target runtimeTarget) set(shaderCacheListFile "${shaderCacheGeneratedDir}/sources.txt") file(CONFIGURE OUTPUT "${shaderCacheListFile}" CONTENT "${shaderCacheManifest}" @ONLY) add_custom_command( - OUTPUT "${shaderCacheVersionHeader}" + OUTPUT "${shaderCacheVersionSource}" COMMAND ${CMAKE_COMMAND} "-DROOT=${PROJECT_SOURCE_DIR}" "-DLIST_FILE=${shaderCacheListFile}" "-DRECOMPILER_DIR=${CMAKE_CURRENT_FUNCTION_LIST_DIR}" "-DGIT=${GIT_EXECUTABLE}" "-DEXTRA=${shaderCacheExtra}" - "-DOUTPUT=${shaderCacheVersionHeader}" + "-DOUTPUT=${shaderCacheVersionSource}" -P "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ShaderCacheVersion.cmake" DEPENDS ${shaderCacheRecompilerSources} ${shaderCacheGuardSources} ${shaderCacheSubmoduleStamps} "${shaderCacheListFile}" "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/ShaderCacheVersion.cmake" COMMENT "Hashing the shader recompiler sources for the shader disk cache" VERBATIM ) - target_sources(${target} PRIVATE "${shaderCacheVersionHeader}") - target_include_directories(${target} PRIVATE "${shaderCacheGeneratedDir}") + target_sources(${target} PRIVATE "${shaderCacheVersionSource}") set_target_properties(${target} PROPERTIES POSITION_INDEPENDENT_CODE ON diff --git a/core/shader/recompiler/ShaderCacheSourceVersion.hpp b/core/shader/recompiler/ShaderCacheSourceVersion.hpp new file mode 100644 index 0000000000..d73de7db7f --- /dev/null +++ b/core/shader/recompiler/ShaderCacheSourceVersion.hpp @@ -0,0 +1,15 @@ +#ifndef CORE_SHADER_RECOMPILER_SHADERCACHESOURCEVERSION_HPP +#define CORE_SHADER_RECOMPILER_SHADERCACHESOURCEVERSION_HPP + +#include +#include +#include + +namespace ShaderRecompiler::ShaderDiskCache::Generated { + +extern const std::uint64_t SourceVersion; +extern const std::span RecompilerSwitches; + +} + +#endif diff --git a/core/shader/recompiler/ShaderCacheVersion.cmake b/core/shader/recompiler/ShaderCacheVersion.cmake index e952236aef..fe033d0a1f 100644 --- a/core/shader/recompiler/ShaderCacheVersion.cmake +++ b/core/shader/recompiler/ShaderCacheVersion.cmake @@ -140,23 +140,22 @@ list(REMOVE_DUPLICATES switches) list(SORT switches) list(JOIN switches ",\n " switchList) -set(content "#ifndef CORE_SHADER_RECOMPILER_SHADERCACHEVERSION_HPP -#define CORE_SHADER_RECOMPILER_SHADERCACHEVERSION_HPP - -#include -#include - +set(content "#include \"ShaderCacheSourceVersion.hpp\"\n") +string(APPEND content " namespace ShaderRecompiler::ShaderDiskCache::Generated { -inline constexpr std::uint64_t SourceVersion = 0x${version}ull; +namespace { -inline constexpr std::string_view RecompilerSwitches[] = { +constexpr std::string_view recompilerSwitches[] = { ${switchList} }; } -#endif +constinit const std::uint64_t SourceVersion = 0x${version}ull; +constinit const std::span RecompilerSwitches = recompilerSwitches; + +} ") if(EXISTS "${OUTPUT}") diff --git a/core/shader/recompiler/ShaderDiskCache.cpp b/core/shader/recompiler/ShaderDiskCache.cpp index c650f519c2..d18c6bb6ba 100644 --- a/core/shader/recompiler/ShaderDiskCache.cpp +++ b/core/shader/recompiler/ShaderDiskCache.cpp @@ -20,7 +20,7 @@ #include #include #endif -#include "ShaderCacheVersion.hpp" +#include "ShaderCacheSourceVersion.hpp" #include #include #include