From 0da10ee0916f6e6ffd352888c6525fe120ee22a5 Mon Sep 17 00:00:00 2001 From: Fire Cube Date: Tue, 15 Jul 2025 22:12:43 +0200 Subject: [PATCH] clang + deserialize + flattened_udbuf + fs_interpolation --- src/common/serialization.h | 8 +-- src/shader_recompiler/info.h | 2 + .../renderer_vulkan/shader_cache.cpp | 27 ++++++-- .../shader_cache_serialization.h | 63 ++++++++----------- 4 files changed, 55 insertions(+), 45 deletions(-) diff --git a/src/common/serialization.h b/src/common/serialization.h index 63c112021..a05a1acab 100644 --- a/src/common/serialization.h +++ b/src/common/serialization.h @@ -3,21 +3,21 @@ #pragma once -#include #include +#include #include namespace cereal { // boost::small_vector -template +template void save(Archive& ar, boost::container::small_vector const& smallVector) { ar(make_size_tag(static_cast(smallVector.size()))); for (auto const& element : smallVector) ar(element); } -template +template void load(Archive& ar, boost::container::small_vector& smallVector) { u32 elementCount; ar(make_size_tag(elementCount)); @@ -26,4 +26,4 @@ void load(Archive& ar, boost::container::small_vector& smallVector) ar(element); } -} \ No newline at end of file +} // namespace cereal \ No newline at end of file diff --git a/src/shader_recompiler/info.h b/src/shader_recompiler/info.h index bb5c88584..6942368e5 100644 --- a/src/shader_recompiler/info.h +++ b/src/shader_recompiler/info.h @@ -93,6 +93,8 @@ struct ImageResource { using ImageResourceList = boost::container::small_vector; struct SamplerResource { + SamplerResource() = default; + std::variant sampler; u32 associated_image : 4; u32 disable_aniso : 1; diff --git a/src/video_core/renderer_vulkan/shader_cache.cpp b/src/video_core/renderer_vulkan/shader_cache.cpp index e4f14d699..903b5dc33 100644 --- a/src/video_core/renderer_vulkan/shader_cache.cpp +++ b/src/video_core/renderer_vulkan/shader_cache.cpp @@ -29,7 +29,6 @@ using u32 = uint32_t; namespace ShaderCache { - u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec) { u64 hash = 0; @@ -244,9 +243,11 @@ u64 CalculateSpecializationHash(const Shader::StageSpecialization& spec) { } bool CheckShaderCache(std::string shader_id) { - std::filesystem::path spirv_cache_file_path = SHADER_CACHE_DIR / static_cast(shader_id + ".spv"); - std::filesystem::path resources_file_path = SHADER_CACHE_DIR / static_cast(shader_id + ".resources"); -; + std::filesystem::path spirv_cache_file_path = + SHADER_CACHE_DIR / static_cast(shader_id + ".spv"); + std::filesystem::path resources_file_path = + SHADER_CACHE_DIR / static_cast(shader_id + ".resources"); + ; if (!std::filesystem::exists(spirv_cache_file_path)) { return false; @@ -324,7 +325,7 @@ 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; @@ -333,7 +334,23 @@ void SerializeInfo(std::ostream& info_serialized, Shader::Info &info) { ar << info.images; ar << info.samplers; ar << info.fmasks; + // srt info + ar << info.flattened_ud_buf; + ar << info.fs_interpolation; +} +void DeserializeInfo(std::istream& info_serialized, Shader::Info& info) { + cereal::BinaryInputArchive ar(info_serialized); + ar >> info.ud_mask; + ar >> info.gs_copy_data; + ar >> info.uses_patches; + ar >> info.buffers; + ar >> info.images; + ar >> info.samplers; + ar >> info.fmasks; + // srt info + ar >> info.flattened_ud_buf; + ar >> info.fs_interpolation; } } // namespace ShaderCache \ No newline at end of file diff --git a/src/video_core/renderer_vulkan/shader_cache_serialization.h b/src/video_core/renderer_vulkan/shader_cache_serialization.h index b4ee48d2f..b1a5aaf5c 100644 --- a/src/video_core/renderer_vulkan/shader_cache_serialization.h +++ b/src/video_core/renderer_vulkan/shader_cache_serialization.h @@ -2,82 +2,73 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once +#include #include -#include #include - +#include +#include #include "common/serialization.h" #include "shader_recompiler/info.h" +#include "shader_recompiler/info.h" + namespace cereal { // Shader::Info::UserDataMask -template +template void serialize(Archive& ar, Shader::Info::UserDataMask& mask) { ar(mask.mask); } // Shader::CopyShaderData -template +template void serialize(Archive& ar, Shader::CopyShaderData& data) { - ar( - data.attr_map, - data.num_attrs, - data.output_vertices); + ar(data.attr_map, data.num_attrs, data.output_vertices); } // AmdGPU::Buffer -template +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); +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& image) -{ - ar( - image.sharp_idx, - image.is_depth, - image.is_atomic, - image.is_array, - image.is_written, - image.is_r128); +template +void serialize(Archive& ar, Shader::ImageResource& image) { + ar(image.sharp_idx, image.is_depth, image.is_atomic, image.is_array, image.is_written, + image.is_r128); } // AmdGpu::Sampler -template +template void serialize(Archive& ar, AmdGpu::Sampler& sampler) { ar(cereal::binary_data(reinterpret_cast(&sampler), sizeof(sampler))); } // Shader::SamplerResource -template +template void serialize(Archive& ar, Shader::SamplerResource& sampler) { ar(sampler.sampler); - ar(static_cast(sampler.associated_image), - static_cast(sampler.disable_aniso)); + ar(static_cast(sampler.associated_image), static_cast(sampler.disable_aniso)); } // Shader::FMaskResource -template +template void serialize(Archive& ar, Shader::FMaskResource& fmask) { cereal::binary_data(reinterpret_cast(&fmask), sizeof(fmask)); } -} \ No newline at end of file +// Shader::Info::Interpolation +template +void serialize(Archive& ar, Shader::Info::Interpolation& interpolation) { + ar(interpolation.primary, interpolation.auxiliary); +} +} // namespace cereal \ No newline at end of file