diff options
| author | 2021-07-18 21:07:12 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:40 -0400 | |
| commit | 258f35515d61d01049d2e433146cab808837bb7d (patch) | |
| tree | d7259d17dbbba65229a9473f1efef18149769a3b | |
| 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.
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_cache.cpp | 10 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | 9 | ||||
| -rw-r--r-- | src/video_core/shader_environment.cpp | 11 | ||||
| -rw-r--r-- | src/video_core/shader_environment.h | 9 |
4 files changed, 23 insertions, 16 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp index 7ecafc862..8d6cc074c 100644 --- a/src/video_core/renderer_opengl/gl_shader_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp | |||
| @@ -48,9 +48,12 @@ using VideoCommon::ComputeEnvironment; | |||
| 48 | using VideoCommon::FileEnvironment; | 48 | using VideoCommon::FileEnvironment; |
| 49 | using VideoCommon::GenericEnvironment; | 49 | using VideoCommon::GenericEnvironment; |
| 50 | using VideoCommon::GraphicsEnvironment; | 50 | using VideoCommon::GraphicsEnvironment; |
| 51 | using VideoCommon::LoadPipelines; | ||
| 51 | using VideoCommon::SerializePipeline; | 52 | using VideoCommon::SerializePipeline; |
| 52 | using Context = ShaderContext::Context; | 53 | using Context = ShaderContext::Context; |
| 53 | 54 | ||
| 55 | constexpr u32 CACHE_VERSION = 5; | ||
| 56 | |||
| 54 | template <typename Container> | 57 | template <typename Container> |
| 55 | auto MakeSpan(Container& container) { | 58 | auto MakeSpan(Container& container) { |
| 56 | return std::span(container.data(), container.size()); | 59 | return std::span(container.data(), container.size()); |
| @@ -287,7 +290,7 @@ void ShaderCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading, | |||
| 287 | }); | 290 | }); |
| 288 | ++state.total; | 291 | ++state.total; |
| 289 | }}; | 292 | }}; |
| 290 | VideoCommon::LoadPipelines(stop_loading, shader_cache_filename, load_compute, load_graphics); | 293 | LoadPipelines(stop_loading, shader_cache_filename, CACHE_VERSION, load_compute, load_graphics); |
| 291 | 294 | ||
| 292 | std::unique_lock lock{state.mutex}; | 295 | std::unique_lock lock{state.mutex}; |
| 293 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); | 296 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); |
| @@ -394,7 +397,7 @@ std::unique_ptr<GraphicsPipeline> ShaderCache::CreateGraphicsPipeline() { | |||
| 394 | env_ptrs.push_back(&environments.envs[index]); | 397 | env_ptrs.push_back(&environments.envs[index]); |
| 395 | } | 398 | } |
| 396 | } | 399 | } |
| 397 | SerializePipeline(graphics_key, env_ptrs, shader_cache_filename); | 400 | SerializePipeline(graphics_key, env_ptrs, shader_cache_filename, CACHE_VERSION); |
| 398 | return pipeline; | 401 | return pipeline; |
| 399 | } | 402 | } |
| 400 | 403 | ||
| @@ -492,7 +495,8 @@ std::unique_ptr<ComputePipeline> ShaderCache::CreateComputePipeline( | |||
| 492 | if (!pipeline || shader_cache_filename.empty()) { | 495 | if (!pipeline || shader_cache_filename.empty()) { |
| 493 | return pipeline; | 496 | return pipeline; |
| 494 | } | 497 | } |
| 495 | SerializePipeline(key, std::array<const GenericEnvironment*, 1>{&env}, shader_cache_filename); | 498 | SerializePipeline(key, std::array<const GenericEnvironment*, 1>{&env}, shader_cache_filename, |
| 499 | CACHE_VERSION); | ||
| 496 | return pipeline; | 500 | return pipeline; |
| 497 | } | 501 | } |
| 498 | 502 | ||
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index 39db35175..2ce8b4156 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp | |||
| @@ -54,6 +54,8 @@ using VideoCommon::FileEnvironment; | |||
| 54 | using VideoCommon::GenericEnvironment; | 54 | using VideoCommon::GenericEnvironment; |
| 55 | using VideoCommon::GraphicsEnvironment; | 55 | using VideoCommon::GraphicsEnvironment; |
| 56 | 56 | ||
| 57 | constexpr u32 CACHE_VERSION = 5; | ||
| 58 | |||
| 57 | template <typename Container> | 59 | template <typename Container> |
| 58 | auto MakeSpan(Container& container) { | 60 | auto MakeSpan(Container& container) { |
| 59 | return std::span(container.data(), container.size()); | 61 | return std::span(container.data(), container.size()); |
| @@ -434,7 +436,8 @@ void PipelineCache::LoadDiskResources(u64 title_id, std::stop_token stop_loading | |||
| 434 | }); | 436 | }); |
| 435 | ++state.total; | 437 | ++state.total; |
| 436 | }}; | 438 | }}; |
| 437 | VideoCommon::LoadPipelines(stop_loading, pipeline_cache_filename, load_compute, load_graphics); | 439 | VideoCommon::LoadPipelines(stop_loading, pipeline_cache_filename, CACHE_VERSION, load_compute, |
| 440 | load_graphics); | ||
| 438 | 441 | ||
| 439 | std::unique_lock lock{state.mutex}; | 442 | std::unique_lock lock{state.mutex}; |
| 440 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); | 443 | callback(VideoCore::LoadCallbackStage::Build, 0, state.total); |
| @@ -562,7 +565,7 @@ std::unique_ptr<GraphicsPipeline> PipelineCache::CreateGraphicsPipeline() { | |||
| 562 | env_ptrs.push_back(&envs[index]); | 565 | env_ptrs.push_back(&envs[index]); |
| 563 | } | 566 | } |
| 564 | } | 567 | } |
| 565 | SerializePipeline(key, env_ptrs, pipeline_cache_filename); | 568 | SerializePipeline(key, env_ptrs, pipeline_cache_filename, CACHE_VERSION); |
| 566 | }); | 569 | }); |
| 567 | return pipeline; | 570 | return pipeline; |
| 568 | } | 571 | } |
| @@ -581,7 +584,7 @@ std::unique_ptr<ComputePipeline> PipelineCache::CreateComputePipeline( | |||
| 581 | } | 584 | } |
| 582 | serialization_thread.QueueWork([this, key, env = std::move(env)] { | 585 | serialization_thread.QueueWork([this, key, env = std::move(env)] { |
| 583 | SerializePipeline(key, std::array<const GenericEnvironment*, 1>{&env}, | 586 | SerializePipeline(key, std::array<const GenericEnvironment*, 1>{&env}, |
| 584 | pipeline_cache_filename); | 587 | pipeline_cache_filename, CACHE_VERSION); |
| 585 | }); | 588 | }); |
| 586 | return pipeline; | 589 | return pipeline; |
| 587 | } | 590 | } |
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 { |
diff --git a/src/video_core/shader_environment.h b/src/video_core/shader_environment.h index d26dbfaab..2079979db 100644 --- a/src/video_core/shader_environment.h +++ b/src/video_core/shader_environment.h | |||
| @@ -164,18 +164,19 @@ private: | |||
| 164 | }; | 164 | }; |
| 165 | 165 | ||
| 166 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, | 166 | void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, |
| 167 | const std::filesystem::path& filename); | 167 | const std::filesystem::path& filename, u32 cache_version); |
| 168 | 168 | ||
| 169 | template <typename Key, typename Envs> | 169 | template <typename Key, typename Envs> |
| 170 | void SerializePipeline(const Key& key, const Envs& envs, const std::filesystem::path& filename) { | 170 | void SerializePipeline(const Key& key, const Envs& envs, const std::filesystem::path& filename, |
| 171 | u32 cache_version) { | ||
| 171 | static_assert(std::is_trivially_copyable_v<Key>); | 172 | static_assert(std::is_trivially_copyable_v<Key>); |
| 172 | static_assert(std::has_unique_object_representations_v<Key>); | 173 | static_assert(std::has_unique_object_representations_v<Key>); |
| 173 | SerializePipeline(std::span(reinterpret_cast<const char*>(&key), sizeof(key)), | 174 | SerializePipeline(std::span(reinterpret_cast<const char*>(&key), sizeof(key)), |
| 174 | std::span(envs.data(), envs.size()), filename); | 175 | std::span(envs.data(), envs.size()), filename, cache_version); |
| 175 | } | 176 | } |
| 176 | 177 | ||
| 177 | void LoadPipelines( | 178 | void LoadPipelines( |
| 178 | std::stop_token stop_loading, const std::filesystem::path& filename, | 179 | std::stop_token stop_loading, const std::filesystem::path& filename, u32 expected_cache_version, |
| 179 | Common::UniqueFunction<void, std::ifstream&, FileEnvironment> load_compute, | 180 | Common::UniqueFunction<void, std::ifstream&, FileEnvironment> load_compute, |
| 180 | Common::UniqueFunction<void, std::ifstream&, std::vector<FileEnvironment>> load_graphics); | 181 | Common::UniqueFunction<void, std::ifstream&, std::vector<FileEnvironment>> load_graphics); |
| 181 | 182 | ||