diff --git a/src/common/hash.h b/src/common/hash.h index d5cacedd7..7f819fd4b 100644 --- a/src/common/hash.h +++ b/src/common/hash.h @@ -5,10 +5,10 @@ #include "common/types.h" -[[nodiscard]] inline u64 HashCombine(const u64 seed, const u64 hash) { - return seed ^ (hash + 0x9e3779b9 + (seed << 12) + (seed >> 4)); -} +template +[[nodiscard]] constexpr u64 HashCombine(T1 seed, T2 hash) noexcept { + u64 s = static_cast(seed); + u64 h = static_cast(hash); -[[nodiscard]] inline u32 HashCombine(const u32 seed, const u32 hash) { - return seed ^ (hash + 0x9e3779b9 + (seed << 6) + (seed >> 2)); -} \ No newline at end of file + return s ^ (h + 0x9e3779b9 + (s << 12) + (s >> 4)); +} diff --git a/src/video_core/renderer_vulkan/shader_cache.cpp b/src/video_core/renderer_vulkan/shader_cache.cpp index f65332c9e..d6643a4df 100644 --- a/src/video_core/renderer_vulkan/shader_cache.cpp +++ b/src/video_core/renderer_vulkan/shader_cache.cpp @@ -2,26 +2,25 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include -#include #include #include +#include #ifdef _WIN32 #include #else #include #include #endif -#include "common/hash.h" -#include "common/path_util.h" -#include "common/io_file.h" -#include "video_core/renderer_vulkan/shader_cache_serialization.h" -#include -#include "common/logging/log.h" -#include "shader_recompiler/ir/type.h" -#include "shader_recompiler/info.h" -#include "shader_recompiler/specialization.h" #include -#include +#include +#include "common/hash.h" +#include "common/io_file.h" +#include "common/logging/log.h" +#include "common/path_util.h" +#include "shader_recompiler/info.h" +#include "shader_recompiler/ir/type.h" +#include "shader_recompiler/specialization.h" +#include "video_core/renderer_vulkan/shader_cache_serialization.h" #include "shader_cache.h" @@ -287,8 +286,7 @@ bool CheckShaderCache(std::string shader_id) { void GetShader(std::string shader_id, Shader::Info& info, std::vector& spv) { std::string spirv_cache_filename = shader_id + ".spv"; std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename; - Common::FS::IOFile spirv_cache_file(spirv_cache_file_path, - Common::FS::FileAccessMode::Read); + Common::FS::IOFile spirv_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Read); spv.resize(spirv_cache_file.GetSize() / sizeof(u32)); spirv_cache_file.Read(spv); spirv_cache_file.Close(); @@ -306,8 +304,6 @@ void GetShader(std::string shader_id, Shader::Info& info, std::vector& spv) std::istringstream info_stream; info_stream.str(std::string(resources_data.begin(), resources_data.end())); - - } void AddShader(std::string shader_id, std::vector spv, std::ostream& info_serialized) { @@ -329,10 +325,14 @@ void AddShader(std::string shader_id, std::vector spv, std::ostream& info_s resources_dump_file.Close(); } -void SerializeInfo( - std::ostream& info_serialized, Shader::Info info) { +void SerializeInfo(std::ostream& info_serialized, Shader::Info &info) { cereal::BinaryOutputArchive ar(info_serialized); + ar << info.ud_mask; + ar << info.gs_copy_data; + ar << info.uses_patches; + ar << info.buffers; ar << info.images; + } } // 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 c9518e918..4df74e115 100644 --- a/src/video_core/renderer_vulkan/shader_cache.h +++ b/src/video_core/renderer_vulkan/shader_cache.h @@ -13,7 +13,7 @@ namespace ShaderCache { u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec); void SerializeInfo( - std::ostream& info_serialized, Shader::Info info); + std::ostream& info_serialized, Shader::Info& info); void DeserializeInfo(std::istream& info_serialized, Shader::Info& info); bool CheckShaderCache(std::string shader_id); diff --git a/src/video_core/renderer_vulkan/shader_cache_serialization.h b/src/video_core/renderer_vulkan/shader_cache_serialization.h index 98b996066..ba48ae7be 100644 --- a/src/video_core/renderer_vulkan/shader_cache_serialization.h +++ b/src/video_core/renderer_vulkan/shader_cache_serialization.h @@ -2,36 +2,76 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once +#include +#include #include "shader_recompiler/info.h" namespace cereal { // boost::small_vector template -void save(Archive& ar, boost::container::small_vector const& v) { - ar(static_cast(v.size())); - for (auto const& e : v) - ar(e); +void save(Archive& ar, boost::container::small_vector const& smallVector) { + ar(static_cast(smallVector.size())); + for (auto const& element : smallVector) + ar(element); } template -void load(Archive& ar, boost::container::small_vector& v) { - std::uint32_t n; - ar(n); - v.resize(n); - for (auto& e : v) - ar(e); +void load(Archive& ar, boost::container::small_vector& smallVector) { + std::uint32_t elementCount; + ar(elementCount); + smallVector.resize(elementCount); + for (auto& element : smallVector) + ar(element); +} + +// Shader::Info::UserDataMask +template +void serialize(Archive& ar, Shader::Info::UserDataMask& mask) { + ar(mask.mask); +} + +// Shader::CopyShaderData +template +void serialize(Archive& ar, Shader::CopyShaderData& data) { + ar( + data.attr_map, + data.num_attrs, + data.output_vertices); +} + +// AmdGPU::Buffer +template +void serialize(Archive& ar, AmdGpu::Buffer& buffer) { + ar(cereal::binary_data(reinterpret_cast(&buffer), sizeof(buffer))); + // is base_adress cacheable? +} + +// Shader::BufferResource +template +void serialize(Archive& ar, Shader::BufferResource& buffer) +{ + ar( + buffer.sharp_idx, + buffer.used_types, + buffer.inline_cbuf, + buffer.buffer_type, + buffer.instance_attrib, + buffer.is_written, + buffer.is_formatted); } // Shader::ImageResource template -void serialize(Archive& ar, Shader::ImageResource& img) +void serialize(Archive& ar, Shader::ImageResource& image) { - ar(img.sharp_idx, - img.is_depth, - img.is_atomic, - img.is_array, - img.is_written, - img.is_r128); + ar( + image.sharp_idx, + image.is_depth, + image.is_atomic, + image.is_array, + image.is_written, + image.is_r128); } + } \ No newline at end of file