diff options
| author | 2021-07-18 21:07:12 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:40 -0400 | |
| commit | 258f35515d61d01049d2e433146cab808837bb7d (patch) | |
| tree | d7259d17dbbba65229a9473f1efef18149769a3b /src/video_core/shader_environment.cpp | |
| parent | cmake: Remove shader cache version (diff) | |
| download | yuzu-258f35515d61d01049d2e433146cab808837bb7d.tar.gz yuzu-258f35515d61d01049d2e433146cab808837bb7d.tar.xz yuzu-258f35515d61d01049d2e433146cab808837bb7d.zip | |
shader_environment: Receive cache version from outside
This allows us invalidating OpenGL and Vulkan separately in the future.
Diffstat (limited to 'src/video_core/shader_environment.cpp')
| -rw-r--r-- | src/video_core/shader_environment.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/video_core/shader_environment.cpp b/src/video_core/shader_environment.cpp index 429cab30d..8a4581c19 100644 --- a/src/video_core/shader_environment.cpp +++ b/src/video_core/shader_environment.cpp | |||
| @@ -22,7 +22,6 @@ | |||
| 22 | namespace VideoCommon { | 22 | namespace VideoCommon { |
| 23 | 23 | ||
| 24 | constexpr std::array<char, 8> MAGIC_NUMBER{'y', 'u', 'z', 'u', 'c', 'a', 'c', 'h'}; | 24 | constexpr std::array<char, 8> MAGIC_NUMBER{'y', 'u', 'z', 'u', 'c', 'a', 'c', 'h'}; |
| 25 | constexpr u32 CACHE_VERSION = 5; | ||
| 26 | 25 | ||
| 27 | constexpr size_t INST_SIZE = sizeof(u64); | 26 | constexpr size_t INST_SIZE = sizeof(u64); |
| 28 | 27 | ||
| @@ -370,7 +369,7 @@ std::array<u32, 3> FileEnvironment::WorkgroupSize() const { | |||
| 370 | } | 369 | } |
| 371 | 370 | ||
| 372 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, | 371 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, |
| 373 | const std::filesystem::path& filename) try { | 372 | const std::filesystem::path& filename, u32 cache_version) try { |
| 374 | std::ofstream file(filename, std::ios::binary | std::ios::ate | std::ios::app); | 373 | std::ofstream file(filename, std::ios::binary | std::ios::ate | std::ios::app); |
| 375 | file.exceptions(std::ifstream::failbit); | 374 | file.exceptions(std::ifstream::failbit); |
| 376 | if (!file.is_open()) { | 375 | if (!file.is_open()) { |
| @@ -381,7 +380,7 @@ void SerializePipeline(std::span<const char> key, std::span<const GenericEnviron | |||
| 381 | if (file.tellp() == 0) { | 380 | if (file.tellp() == 0) { |
| 382 | // Write header | 381 | // Write header |
| 383 | file.write(MAGIC_NUMBER.data(), MAGIC_NUMBER.size()) | 382 | file.write(MAGIC_NUMBER.data(), MAGIC_NUMBER.size()) |
| 384 | .write(reinterpret_cast<const char*>(&CACHE_VERSION), sizeof(CACHE_VERSION)); | 383 | .write(reinterpret_cast<const char*>(&cache_version), sizeof(cache_version)); |
| 385 | } | 384 | } |
| 386 | if (!std::ranges::all_of(envs, &GenericEnvironment::CanBeSerialized)) { | 385 | if (!std::ranges::all_of(envs, &GenericEnvironment::CanBeSerialized)) { |
| 387 | return; | 386 | return; |
| @@ -402,7 +401,7 @@ void SerializePipeline(std::span<const char> key, std::span<const GenericEnviron | |||
| 402 | } | 401 | } |
| 403 | 402 | ||
| 404 | void LoadPipelines( | 403 | void LoadPipelines( |
| 405 | std::stop_token stop_loading, const std::filesystem::path& filename, | 404 | std::stop_token stop_loading, const std::filesystem::path& filename, u32 expected_cache_version, |
| 406 | Common::UniqueFunction<void, std::ifstream&, FileEnvironment> load_compute, | 405 | Common::UniqueFunction<void, std::ifstream&, FileEnvironment> load_compute, |
| 407 | Common::UniqueFunction<void, std::ifstream&, std::vector<FileEnvironment>> load_graphics) try { | 406 | Common::UniqueFunction<void, std::ifstream&, std::vector<FileEnvironment>> load_graphics) try { |
| 408 | std::ifstream file(filename, std::ios::binary | std::ios::ate); | 407 | std::ifstream file(filename, std::ios::binary | std::ios::ate); |
| @@ -417,13 +416,13 @@ void LoadPipelines( | |||
| 417 | u32 cache_version; | 416 | u32 cache_version; |
| 418 | file.read(magic_number.data(), magic_number.size()) | 417 | file.read(magic_number.data(), magic_number.size()) |
| 419 | .read(reinterpret_cast<char*>(&cache_version), sizeof(cache_version)); | 418 | .read(reinterpret_cast<char*>(&cache_version), sizeof(cache_version)); |
| 420 | if (magic_number != MAGIC_NUMBER || cache_version != CACHE_VERSION) { | 419 | if (magic_number != MAGIC_NUMBER || cache_version != expected_cache_version) { |
| 421 | file.close(); | 420 | file.close(); |
| 422 | if (Common::FS::RemoveFile(filename)) { | 421 | if (Common::FS::RemoveFile(filename)) { |
| 423 | if (magic_number != MAGIC_NUMBER) { | 422 | if (magic_number != MAGIC_NUMBER) { |
| 424 | LOG_ERROR(Common_Filesystem, "Invalid pipeline cache file"); | 423 | LOG_ERROR(Common_Filesystem, "Invalid pipeline cache file"); |
| 425 | } | 424 | } |
| 426 | if (cache_version != CACHE_VERSION) { | 425 | if (cache_version != expected_cache_version) { |
| 427 | LOG_INFO(Common_Filesystem, "Deleting old pipeline cache"); | 426 | LOG_INFO(Common_Filesystem, "Deleting old pipeline cache"); |
| 428 | } | 427 | } |
| 429 | } else { | 428 | } else { |