diff --git a/src/video_core/renderer_vulkan/shader_cache.cpp b/src/video_core/renderer_vulkan/shader_cache.cpp index 63db08b03..cce789b45 100644 --- a/src/video_core/renderer_vulkan/shader_cache.cpp +++ b/src/video_core/renderer_vulkan/shader_cache.cpp @@ -13,11 +13,11 @@ namespace ShaderCache { const auto shader_cache_dir = Common::FS::GetUserPath(Common::FS::PathType::ShaderDir) / "cache"; -std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_dump, std::ostream& profile_dump) { +std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_serialized, std::ostream& profile_serialized) { std::ostringstream info_stream, profile_stream; info_stream << pgm_hash << perm_idx; - info_stream << info_dump.rdbuf(); - profile_stream << profile_dump.rdbuf(); + info_stream << info_serialized.rdbuf(); + profile_stream << profile_serialized.rdbuf(); std::string combined_data = info_stream.str() + profile_stream.str(); @@ -26,12 +26,20 @@ std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_dum return std::to_string(shader_id); } -void DumpInfo(std::ostream& info_dump, Shader::Info info) { - writeBin(info_dump, info.mrt_mask); +void SerializeInfo(std::ostream& info_serialized, Shader::Info info) { + writeBin(info_serialized, info.mrt_mask); } -void DumpProfile(std::ostream& profile_dump, Shader::Profile profile) { - writeBin(profile_dump, profile.has_broken_spirv_clamp); +void DeserializeInfo(std::istream& info_serialized, Shader::Info& info) { + readBin(info_serialized, info.mrt_mask); +} + +void SerializeProfile(std::ostream& profile_serialized, Shader::Profile profile) { + writeBin(profile_serialized, profile.has_broken_spirv_clamp); +} + +void DeserializeProfile(std::istream& profile_serialized, Shader::Profile& profile) { + readBin(profile_serialized, profile.has_broken_spirv_clamp); } bool CheckShaderCache(std::string shader_id) { @@ -48,7 +56,7 @@ bool GetShader(std::string shader_id) { spirv_cache_file.Read(spv); } -void AddShader(std::string shader_id, std::vector spv, std::ostream& info_dump, std::ostream& profile_dump) { +void AddShader(std::string shader_id, std::vector spv, std::ostream& info_serialized, std::ostream& profile_serialized) { std::string spirv_cache_filename = shader_id + ".spv "; std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename; Common::FS::IOFile shader_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Write); @@ -58,8 +66,8 @@ void AddShader(std::string shader_id, std::vector spv, std::ostream& info_d Common::FS::IOFile resources_dump_file(resources_dump_file_path, Common::FS::FileAccessMode::Write); // Schreibe beide Streams nacheinander in die Ressourcen-Datei std::ostringstream info_stream, profile_stream; - info_stream << info_dump.rdbuf(); - profile_stream << profile_dump.rdbuf(); + info_stream << info_serialized.rdbuf(); + profile_stream << profile_serialized.rdbuf(); // Schreibe zuerst die Größe des info-Dumps, dann die Daten u32 info_size = static_cast(info_stream.str().size()); @@ -69,8 +77,6 @@ void AddShader(std::string shader_id, std::vector spv, std::ostream& info_d u32 profile_size = static_cast(profile_stream.str().size()); resources_dump_file.WriteString( std::span(profile_stream.str().data(), profile_size)); - - } } // namespace ShaderCache \ No newline at end of file diff --git a/src/video_core/renderer_vulkan/shader_cache.h b/src/video_core/renderer_vulkan/shader_cache.h index 0ae35ed2c..c789eb855 100644 --- a/src/video_core/renderer_vulkan/shader_cache.h +++ b/src/video_core/renderer_vulkan/shader_cache.h @@ -10,8 +10,8 @@ namespace ShaderCache { std::string CreateShaderID(u64 pgm_hash, size_t perm_idx, std::ostream& info_dump, std::ostream& profile_dump); -void DumpInfo(std::ostream& info_dump, Shader::Info info); -void DumpProfile(std::ostream& profile_dump, Shader::Profile profile); +void SerializeInfo(std::ostream& info_dump, Shader::Info info); +void SerializeProfile(std::ostream& profile_dump, Shader::Profile profile); bool CheckShaderCache(std::string shader_id); bool GetShader(std::string shader_id); void AddShader(std::string shader_id, std::vector spv, std::ostream& info_dump, diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp index ab0f9f3f8..ca6b19c91 100644 --- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp @@ -493,11 +493,11 @@ vk::ShaderModule PipelineCache::CompileModule(Shader::Info& info, Shader::Runtim perm_idx != 0 ? "(permutation)" : ""); DumpShader(code, info.pgm_hash, info.stage, perm_idx, "bin"); - std::ostringstream info_dump, profile_dump; - ::ShaderCache::DumpInfo(info_dump, info); - ::ShaderCache::DumpProfile(profile_dump, profile); - std::string shader_id = ::ShaderCache::CreateShaderID(info.pgm_hash, perm_idx, info_dump, profile_dump); - ::ShaderCache::AddShader(shader_id, std::vector{}, info_dump, profile_dump); + std::ostringstream info_serialized, profile_serialized; + ::ShaderCache::SerializeInfo(info_serialized, info); + ::ShaderCache::SerializeProfile(profile_serialized, profile); + std::string shader_id = ::ShaderCache::CreateShaderID(info.pgm_hash, perm_idx, info_serialized, profile_serialized); + ::ShaderCache::AddShader(shader_id, std::vector{}, info_serialized, profile_serialized); LOG_INFO(Render_Vulkan, "Shader ID: {}", shader_id); const auto ir_program = Shader::TranslateProgram(code, pools, info, runtime_info, profile);