diff options
| author | 2019-01-14 01:58:46 -0300 | |
|---|---|---|
| committer | 2019-02-06 22:20:57 -0300 | |
| commit | be4641c43f0c6c68d183549a9a8715ba6fde9c50 (patch) | |
| tree | c923d382f2e9c27e4d92090c4c331fd99e0c7c47 /src | |
| parent | gl_shader_cache: Refactor to support disk shader cache (diff) | |
| download | yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar.gz yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.tar.xz yuzu-be4641c43f0c6c68d183549a9a8715ba6fde9c50.zip | |
gl_shader_disk_cache: Invalidate shader cache changes with CMake hash
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/CMakeLists.txt | 92 | ||||
| -rw-r--r-- | src/common/scm_rev.cpp.in | 2 | ||||
| -rw-r--r-- | src/common/scm_rev.h | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | 23 |
4 files changed, 72 insertions, 46 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 845626fc5..f38c0fee9 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt | |||
| @@ -1,42 +1,56 @@ | |||
| 1 | # Generate cpp with Git revision from template | 1 | # Add a custom command to generate a new shader_cache_version hash when any of the following files change |
| 2 | # Also if this is a CI build, add the build name (ie: Nightly, Canary) to the scm_rev file as well | 2 | # NOTE: This is an approximation of what files affect shader generation, its possible something else |
| 3 | set(REPO_NAME "") | 3 | # could affect the result, but much more unlikely than the following files. Keeping a list of files |
| 4 | set(BUILD_VERSION "0") | 4 | # like this allows for much better caching since it doesn't force the user to recompile binary shaders every update |
| 5 | if ($ENV{CI}) | 5 | set(VIDEO_CORE "${CMAKE_SOURCE_DIR}/src/video_core") |
| 6 | if ($ENV{TRAVIS}) | 6 | add_custom_command(OUTPUT scm_rev.cpp |
| 7 | set(BUILD_REPOSITORY $ENV{TRAVIS_REPO_SLUG}) | 7 | COMMAND cmake -DSRC_DIR="${CMAKE_SOURCE_DIR}" -P "${CMAKE_SOURCE_DIR}/CMakeModules/GenerateSCMRev.cmake" |
| 8 | set(BUILD_TAG $ENV{TRAVIS_TAG}) | 8 | DEPENDS |
| 9 | elseif($ENV{APPVEYOR}) | 9 | # WARNING! It was too much work to try and make a common location for this list, |
| 10 | set(BUILD_REPOSITORY $ENV{APPVEYOR_REPO_NAME}) | 10 | # so if you need to change it, please update CMakeModules/GenerateSCMRev.cmake as well |
| 11 | set(BUILD_TAG $ENV{APPVEYOR_REPO_TAG_NAME}) | 11 | "${VIDEO_CORE}/renderer_opengl/gl_shader_cache.cpp" |
| 12 | endif() | 12 | "${VIDEO_CORE}/renderer_opengl/gl_shader_cache.h" |
| 13 | # regex capture the string nightly or canary into CMAKE_MATCH_1 | 13 | "${VIDEO_CORE}/renderer_opengl/gl_shader_decompiler.cpp" |
| 14 | string(REGEX MATCH "yuzu-emu/yuzu-?(.*)" OUTVAR ${BUILD_REPOSITORY}) | 14 | "${VIDEO_CORE}/renderer_opengl/gl_shader_decompiler.h" |
| 15 | if (${CMAKE_MATCH_COUNT} GREATER 0) | 15 | "${VIDEO_CORE}/renderer_opengl/gl_shader_disk_cache.cpp" |
| 16 | # capitalize the first letter of each word in the repo name. | 16 | "${VIDEO_CORE}/renderer_opengl/gl_shader_disk_cache.h" |
| 17 | string(REPLACE "-" ";" REPO_NAME_LIST ${CMAKE_MATCH_1}) | 17 | "${VIDEO_CORE}/renderer_opengl/gl_shader_gen.cpp" |
| 18 | foreach(WORD ${REPO_NAME_LIST}) | 18 | "${VIDEO_CORE}/renderer_opengl/gl_shader_gen.h" |
| 19 | string(SUBSTRING ${WORD} 0 1 FIRST_LETTER) | 19 | "${VIDEO_CORE}/shader/decode/arithmetic.cpp" |
| 20 | string(SUBSTRING ${WORD} 1 -1 REMAINDER) | 20 | "${VIDEO_CORE}/shader/decode/arithmetic_half.cpp" |
| 21 | string(TOUPPER ${FIRST_LETTER} FIRST_LETTER) | 21 | "${VIDEO_CORE}/shader/decode/arithmetic_half_immediate.cpp" |
| 22 | set(REPO_NAME "${REPO_NAME}${FIRST_LETTER}${REMAINDER}") | 22 | "${VIDEO_CORE}/shader/decode/arithmetic_immediate.cpp" |
| 23 | endforeach() | 23 | "${VIDEO_CORE}/shader/decode/arithmetic_integer.cpp" |
| 24 | if (BUILD_TAG) | 24 | "${VIDEO_CORE}/shader/decode/arithmetic_integer_immediate.cpp" |
| 25 | string(REGEX MATCH "${CMAKE_MATCH_1}-([0-9]+)" OUTVAR ${BUILD_TAG}) | 25 | "${VIDEO_CORE}/shader/decode/bfe.cpp" |
| 26 | if (${CMAKE_MATCH_COUNT} GREATER 0) | 26 | "${VIDEO_CORE}/shader/decode/bfi.cpp" |
| 27 | set(BUILD_VERSION ${CMAKE_MATCH_1}) | 27 | "${VIDEO_CORE}/shader/decode/conversion.cpp" |
| 28 | endif() | 28 | "${VIDEO_CORE}/shader/decode/ffma.cpp" |
| 29 | if (BUILD_VERSION) | 29 | "${VIDEO_CORE}/shader/decode/float_set.cpp" |
| 30 | # This leaves a trailing space on the last word, but we actually want that | 30 | "${VIDEO_CORE}/shader/decode/float_set_predicate.cpp" |
| 31 | # because of how it's styled in the title bar. | 31 | "${VIDEO_CORE}/shader/decode/half_set.cpp" |
| 32 | set(BUILD_FULLNAME "${REPO_NAME} ${BUILD_VERSION} ") | 32 | "${VIDEO_CORE}/shader/decode/half_set_predicate.cpp" |
| 33 | else() | 33 | "${VIDEO_CORE}/shader/decode/hfma2.cpp" |
| 34 | set(BUILD_FULLNAME "") | 34 | "${VIDEO_CORE}/shader/decode/integer_set.cpp" |
| 35 | endif() | 35 | "${VIDEO_CORE}/shader/decode/integer_set_predicate.cpp" |
| 36 | endif() | 36 | "${VIDEO_CORE}/shader/decode/memory.cpp" |
| 37 | endif() | 37 | "${VIDEO_CORE}/shader/decode/other.cpp" |
| 38 | endif() | 38 | "${VIDEO_CORE}/shader/decode/predicate_set_predicate.cpp" |
| 39 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp" @ONLY) | 39 | "${VIDEO_CORE}/shader/decode/predicate_set_register.cpp" |
| 40 | "${VIDEO_CORE}/shader/decode/register_set_predicate.cpp" | ||
| 41 | "${VIDEO_CORE}/shader/decode/shift.cpp" | ||
| 42 | "${VIDEO_CORE}/shader/decode/video.cpp" | ||
| 43 | "${VIDEO_CORE}/shader/decode/xmad.cpp" | ||
| 44 | "${VIDEO_CORE}/shader/decode.cpp" | ||
| 45 | "${VIDEO_CORE}/shader/shader_ir.cpp" | ||
| 46 | "${VIDEO_CORE}/shader/shader_ir.h" | ||
| 47 | "${VIDEO_CORE}/shader/track.cpp" | ||
| 48 | # and also check that the scm_rev files haven't changed | ||
| 49 | "${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.cpp.in" | ||
| 50 | "${CMAKE_CURRENT_SOURCE_DIR}/scm_rev.h" | ||
| 51 | # technically we should regenerate if the git version changed, but its not worth the effort imo | ||
| 52 | "${CMAKE_SOURCE_DIR}/CMakeModules/GenerateSCMRev.cmake" | ||
| 53 | ) | ||
| 40 | 54 | ||
| 41 | add_library(common STATIC | 55 | add_library(common STATIC |
| 42 | alignment.h | 56 | alignment.h |
diff --git a/src/common/scm_rev.cpp.in b/src/common/scm_rev.cpp.in index 2b1727769..d69038f65 100644 --- a/src/common/scm_rev.cpp.in +++ b/src/common/scm_rev.cpp.in | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | #define BUILD_DATE "@BUILD_DATE@" | 11 | #define BUILD_DATE "@BUILD_DATE@" |
| 12 | #define BUILD_FULLNAME "@BUILD_FULLNAME@" | 12 | #define BUILD_FULLNAME "@BUILD_FULLNAME@" |
| 13 | #define BUILD_VERSION "@BUILD_VERSION@" | 13 | #define BUILD_VERSION "@BUILD_VERSION@" |
| 14 | #define SHADER_CACHE_VERSION "@SHADER_CACHE_VERSION@" | ||
| 14 | 15 | ||
| 15 | namespace Common { | 16 | namespace Common { |
| 16 | 17 | ||
| @@ -21,6 +22,7 @@ const char g_build_name[] = BUILD_NAME; | |||
| 21 | const char g_build_date[] = BUILD_DATE; | 22 | const char g_build_date[] = BUILD_DATE; |
| 22 | const char g_build_fullname[] = BUILD_FULLNAME; | 23 | const char g_build_fullname[] = BUILD_FULLNAME; |
| 23 | const char g_build_version[] = BUILD_VERSION; | 24 | const char g_build_version[] = BUILD_VERSION; |
| 25 | const char g_shader_cache_version[] = SHADER_CACHE_VERSION; | ||
| 24 | 26 | ||
| 25 | } // namespace | 27 | } // namespace |
| 26 | 28 | ||
diff --git a/src/common/scm_rev.h b/src/common/scm_rev.h index af9a9daed..666bf0367 100644 --- a/src/common/scm_rev.h +++ b/src/common/scm_rev.h | |||
| @@ -13,5 +13,6 @@ extern const char g_build_name[]; | |||
| 13 | extern const char g_build_date[]; | 13 | extern const char g_build_date[]; |
| 14 | extern const char g_build_fullname[]; | 14 | extern const char g_build_fullname[]; |
| 15 | extern const char g_build_version[]; | 15 | extern const char g_build_version[]; |
| 16 | extern const char g_shader_cache_version[]; | ||
| 16 | 17 | ||
| 17 | } // namespace Common | 18 | } // namespace Common |
diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 4d02a800d..4b0e50b90 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <cstring> | ||
| 8 | |||
| 7 | #include <fmt/format.h> | 9 | #include <fmt/format.h> |
| 8 | 10 | ||
| 9 | #include "common/assert.h" | 11 | #include "common/assert.h" |
| @@ -11,6 +13,7 @@ | |||
| 11 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 12 | #include "common/file_util.h" | 14 | #include "common/file_util.h" |
| 13 | #include "common/logging/log.h" | 15 | #include "common/logging/log.h" |
| 16 | #include "common/scm_rev.h" | ||
| 14 | 17 | ||
| 15 | #include "core/core.h" | 18 | #include "core/core.h" |
| 16 | #include "core/hle/kernel/process.h" | 19 | #include "core/hle/kernel/process.h" |
| @@ -26,9 +29,7 @@ enum class EntryKind : u32 { | |||
| 26 | }; | 29 | }; |
| 27 | 30 | ||
| 28 | constexpr u32 NativeVersion = 1; | 31 | constexpr u32 NativeVersion = 1; |
| 29 | 32 | constexpr u32 ShaderHashSize = 64; | |
| 30 | // TODO(Rodrigo): Hash files | ||
| 31 | constexpr u64 PrecompiledHash = 0xdeadbeefdeadbeef; | ||
| 32 | 33 | ||
| 33 | // Making sure sizes doesn't change by accident | 34 | // Making sure sizes doesn't change by accident |
| 34 | static_assert(sizeof(BaseBindings) == 12); | 35 | static_assert(sizeof(BaseBindings) == 12); |
| @@ -38,6 +39,12 @@ namespace { | |||
| 38 | std::string GetTitleID() { | 39 | std::string GetTitleID() { |
| 39 | return fmt::format("{:016X}", Core::CurrentProcess()->GetTitleID()); | 40 | return fmt::format("{:016X}", Core::CurrentProcess()->GetTitleID()); |
| 40 | } | 41 | } |
| 42 | |||
| 43 | std::string GetShaderHash() { | ||
| 44 | std::array<char, ShaderHashSize> hash{}; | ||
| 45 | std::strncpy(hash.data(), Common::g_shader_cache_version, ShaderHashSize); | ||
| 46 | return std::string(hash.data()); | ||
| 47 | } | ||
| 41 | } // namespace | 48 | } // namespace |
| 42 | 49 | ||
| 43 | ShaderDiskCacheRaw::ShaderDiskCacheRaw(FileUtil::IOFile& file) { | 50 | ShaderDiskCacheRaw::ShaderDiskCacheRaw(FileUtil::IOFile& file) { |
| @@ -130,9 +137,9 @@ std::vector<ShaderDiskCachePrecompiledEntry> ShaderDiskCacheOpenGL::LoadPrecompi | |||
| 130 | } | 137 | } |
| 131 | const u64 file_size = file.GetSize(); | 138 | const u64 file_size = file.GetSize(); |
| 132 | 139 | ||
| 133 | u64 precompiled_hash{}; | 140 | char precompiled_hash[ShaderHashSize]; |
| 134 | file.ReadBytes(&precompiled_hash, sizeof(precompiled_hash)); | 141 | file.ReadBytes(&precompiled_hash, ShaderHashSize); |
| 135 | if (precompiled_hash != PrecompiledHash) { | 142 | if (std::string(precompiled_hash) != GetShaderHash()) { |
| 136 | LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing"); | 143 | LOG_INFO(Render_OpenGL, "Precompiled cache is from another version of yuzu - removing"); |
| 137 | file.Close(); | 144 | file.Close(); |
| 138 | InvalidatePrecompiled(); | 145 | InvalidatePrecompiled(); |
| @@ -255,7 +262,9 @@ FileUtil::IOFile ShaderDiskCacheOpenGL::AppendPrecompiledFile() const { | |||
| 255 | } | 262 | } |
| 256 | 263 | ||
| 257 | if (!existed || file.GetSize() == 0) { | 264 | if (!existed || file.GetSize() == 0) { |
| 258 | file.WriteObject(PrecompiledHash); | 265 | std::array<char, ShaderHashSize> hash{}; |
| 266 | std::strcpy(hash.data(), GetShaderHash().c_str()); | ||
| 267 | file.WriteArray(hash.data(), hash.size()); | ||
| 259 | } | 268 | } |
| 260 | return file; | 269 | return file; |
| 261 | } | 270 | } |