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"
[[nodiscard]] inline u64 HashCombine(const u64 seed, const u64 hash) {
return seed ^ (hash + 0x9e3779b9 + (seed << 12) + (seed >> 4));
}
template <typename T1, typename T2>
[[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 seed ^ (hash + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
return s ^ (h + 0x9e3779b9 + (s << 12) + (s >> 4));
}

View File

@ -2,26 +2,25 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <vector>
#ifdef _WIN32
#include <Windows.h>
#else
#include <sys/mman.h>
#include <unistd.h>
#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 <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"
@ -287,8 +286,7 @@ bool CheckShaderCache(std::string shader_id) {
void GetShader(std::string shader_id, Shader::Info& info, std::vector<u32>& 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<u32>& spv)
std::istringstream info_stream;
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) {
@ -329,10 +325,14 @@ void AddShader(std::string shader_id, std::vector<u32> 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

View File

@ -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);

View File

@ -2,36 +2,76 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <cereal/types/map.hpp>
#include <cereal/types/utility.hpp>
#include "shader_recompiler/info.h"
namespace cereal {
// boost::small_vector
template<class Archive, class T, std::size_t N, class Alloc>
void save(Archive& ar, boost::container::small_vector<T, N, Alloc> const& v) {
ar(static_cast<std::uint32_t>(v.size()));
for (auto const& e : v)
ar(e);
void save(Archive& ar, boost::container::small_vector<T, N, Alloc> const& smallVector) {
ar(static_cast<std::uint32_t>(smallVector.size()));
for (auto const& element : smallVector)
ar(element);
}
template<class Archive, class T, std::size_t N, class Alloc>
void load(Archive& ar, boost::container::small_vector<T, N, Alloc>& v) {
std::uint32_t n;
ar(n);
v.resize(n);
for (auto& e : v)
ar(e);
void load(Archive& ar, boost::container::small_vector<T, N, Alloc>& smallVector) {
std::uint32_t elementCount;
ar(elementCount);
smallVector.resize(elementCount);
for (auto& element : smallVector)
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
template<class Archive>
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);
}
}