summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-07-18 21:07:12 -0300
committerGravatar ameerj2021-07-22 21:51:40 -0400
commit258f35515d61d01049d2e433146cab808837bb7d (patch)
treed7259d17dbbba65229a9473f1efef18149769a3b /src
parentcmake: Remove shader cache version (diff)
downloadyuzu-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')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp10
-rw-r--r--src/video_core/renderer_vulkan/vk_pipeline_cache.cpp9
-rw-r--r--src/video_core/shader_environment.cpp11
-rw-r--r--src/video_core/shader_environment.h9
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;
48using VideoCommon::FileEnvironment; 48using VideoCommon::FileEnvironment;
49using VideoCommon::GenericEnvironment; 49using VideoCommon::GenericEnvironment;
50using VideoCommon::GraphicsEnvironment; 50using VideoCommon::GraphicsEnvironment;
51using VideoCommon::LoadPipelines;
51using VideoCommon::SerializePipeline; 52using VideoCommon::SerializePipeline;
52using Context = ShaderContext::Context; 53using Context = ShaderContext::Context;
53 54
55constexpr u32 CACHE_VERSION = 5;
56
54template <typename Container> 57template <typename Container>
55auto MakeSpan(Container& container) { 58auto 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;
54using VideoCommon::GenericEnvironment; 54using VideoCommon::GenericEnvironment;
55using VideoCommon::GraphicsEnvironment; 55using VideoCommon::GraphicsEnvironment;
56 56
57constexpr u32 CACHE_VERSION = 5;
58
57template <typename Container> 59template <typename Container>
58auto MakeSpan(Container& container) { 60auto 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 @@
22namespace VideoCommon { 22namespace VideoCommon {
23 23
24constexpr std::array<char, 8> MAGIC_NUMBER{'y', 'u', 'z', 'u', 'c', 'a', 'c', 'h'}; 24constexpr std::array<char, 8> MAGIC_NUMBER{'y', 'u', 'z', 'u', 'c', 'a', 'c', 'h'};
25constexpr u32 CACHE_VERSION = 5;
26 25
27constexpr size_t INST_SIZE = sizeof(u64); 26constexpr size_t INST_SIZE = sizeof(u64);
28 27
@@ -370,7 +369,7 @@ std::array<u32, 3> FileEnvironment::WorkgroupSize() const {
370} 369}
371 370
372void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, 371void 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
404void LoadPipelines( 403void 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
166void SerializePipeline(std::span<const char> key, std::span<const GenericEnvironment* const> envs, 166void 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
169template <typename Key, typename Envs> 169template <typename Key, typename Envs>
170void SerializePipeline(const Key& key, const Envs& envs, const std::filesystem::path& filename) { 170void 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
177void LoadPipelines( 178void 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