This commit is contained in:
Fire Cube 2025-07-14 20:44:10 +02:00
parent f9e199e1a0
commit e418249f75
4 changed files with 81 additions and 41 deletions

View File

@ -5,10 +5,10 @@
#include "common/types.h" #include "common/types.h"
[[nodiscard]] inline u64 HashCombine(const u64 seed, const u64 hash) { template <typename T1, typename T2>
return seed ^ (hash + 0x9e3779b9 + (seed << 12) + (seed >> 4)); [[nodiscard]] constexpr u64 HashCombine(T1 seed, T2 hash) noexcept {
} u64 s = static_cast<u64>(seed);
u64 h = static_cast<u64>(hash);
[[nodiscard]] inline u32 HashCombine(const u32 seed, const u32 hash) { return s ^ (h + 0x9e3779b9 + (s << 12) + (s >> 4));
return seed ^ (hash + 0x9e3779b9 + (seed << 6) + (seed >> 2)); }
}

View File

@ -2,26 +2,25 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <iostream> #include <iostream>
#include <vector>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <vector>
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
#else #else
#include <sys/mman.h> #include <sys/mman.h>
#include <unistd.h> #include <unistd.h>
#endif #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 <cereal/archives/binary.hpp>
#include "common/logging/log.h"
#include "shader_recompiler/ir/type.h"
#include "shader_recompiler/info.h"
#include "shader_recompiler/specialization.h"
#include <fstream> #include <fstream>
#include <iostream> #include <cereal/archives/binary.hpp>
#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" #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<u32>& spv) { void GetShader(std::string shader_id, Shader::Info& info, std::vector<u32>& spv) {
std::string spirv_cache_filename = shader_id + ".spv"; std::string spirv_cache_filename = shader_id + ".spv";
std::filesystem::path spirv_cache_file_path = shader_cache_dir / spirv_cache_filename; 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::IOFile spirv_cache_file(spirv_cache_file_path, Common::FS::FileAccessMode::Read);
Common::FS::FileAccessMode::Read);
spv.resize(spirv_cache_file.GetSize() / sizeof(u32)); spv.resize(spirv_cache_file.GetSize() / sizeof(u32));
spirv_cache_file.Read(spv); spirv_cache_file.Read(spv);
spirv_cache_file.Close(); spirv_cache_file.Close();
@ -306,8 +304,6 @@ void GetShader(std::string shader_id, Shader::Info& info, std::vector<u32>& spv)
std::istringstream info_stream; std::istringstream info_stream;
info_stream.str(std::string(resources_data.begin(), resources_data.end())); info_stream.str(std::string(resources_data.begin(), resources_data.end()));
} }
void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_serialized) { void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_serialized) {
@ -329,10 +325,14 @@ void AddShader(std::string shader_id, std::vector<u32> spv, std::ostream& info_s
resources_dump_file.Close(); resources_dump_file.Close();
} }
void SerializeInfo( void SerializeInfo(std::ostream& info_serialized, Shader::Info &info) {
std::ostream& info_serialized, Shader::Info info) {
cereal::BinaryOutputArchive ar(info_serialized); cereal::BinaryOutputArchive ar(info_serialized);
ar << info.ud_mask;
ar << info.gs_copy_data;
ar << info.uses_patches;
ar << info.buffers;
ar << info.images; ar << info.images;
} }
} // namespace ShaderCache } // namespace ShaderCache

View File

@ -13,7 +13,7 @@ namespace ShaderCache {
u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec); u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec);
void SerializeInfo( 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); void DeserializeInfo(std::istream& info_serialized, Shader::Info& info);
bool CheckShaderCache(std::string shader_id); bool CheckShaderCache(std::string shader_id);

View File

@ -2,36 +2,76 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#pragma once #pragma once
#include <cereal/types/map.hpp>
#include <cereal/types/utility.hpp>
#include "shader_recompiler/info.h" #include "shader_recompiler/info.h"
namespace cereal { namespace cereal {
// boost::small_vector // boost::small_vector
template<class Archive, class T, std::size_t N, class Alloc> template<class Archive, class T, std::size_t N, class Alloc>
void save(Archive& ar, boost::container::small_vector<T, N, Alloc> const& v) { void save(Archive& ar, boost::container::small_vector<T, N, Alloc> const& smallVector) {
ar(static_cast<std::uint32_t>(v.size())); ar(static_cast<std::uint32_t>(smallVector.size()));
for (auto const& e : v) for (auto const& element : smallVector)
ar(e); ar(element);
} }
template<class Archive, class T, std::size_t N, class Alloc> template<class Archive, class T, std::size_t N, class Alloc>
void load(Archive& ar, boost::container::small_vector<T, N, Alloc>& v) { void load(Archive& ar, boost::container::small_vector<T, N, Alloc>& smallVector) {
std::uint32_t n; std::uint32_t elementCount;
ar(n); ar(elementCount);
v.resize(n); smallVector.resize(elementCount);
for (auto& e : v) for (auto& element : smallVector)
ar(e); ar(element);
}
// Shader::Info::UserDataMask
template<class Archive>
void serialize(Archive& ar, Shader::Info::UserDataMask& mask) {
ar(mask.mask);
}
// Shader::CopyShaderData
template<class Archive>
void serialize(Archive& ar, Shader::CopyShaderData& data) {
ar(
data.attr_map,
data.num_attrs,
data.output_vertices);
}
// AmdGPU::Buffer
template<class Archive>
void serialize(Archive& ar, AmdGpu::Buffer& buffer) {
ar(cereal::binary_data(reinterpret_cast<uint8_t*>(&buffer), sizeof(buffer)));
// is base_adress cacheable?
}
// Shader::BufferResource
template<class Archive>
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 // Shader::ImageResource
template<class Archive> template<class Archive>
void serialize(Archive& ar, Shader::ImageResource& img) void serialize(Archive& ar, Shader::ImageResource& image)
{ {
ar(img.sharp_idx, ar(
img.is_depth, image.sharp_idx,
img.is_atomic, image.is_depth,
img.is_array, image.is_atomic,
img.is_written, image.is_array,
img.is_r128); image.is_written,
image.is_r128);
} }
} }