diff --git a/src/common/vector_math.h b/src/common/vector_math.h index ba36744fc..171d4ebfd 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -32,6 +32,7 @@ #include #include +#include namespace Common { @@ -44,6 +45,14 @@ class Vec4; template class Vec2 { + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & x; + ar & y; + } + public: T x; T y; @@ -191,6 +200,15 @@ inline float Vec2::Normalize() { template class Vec3 { + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & x; + ar & y; + ar & z; + } + public: T x; T y; @@ -399,6 +417,16 @@ using Vec3f = Vec3; template class Vec4 { + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & x; + ar & y; + ar & z; + ar & w; + } + public: T x; T y; diff --git a/src/video_core/pica_state.h b/src/video_core/pica_state.h index 1e5b1ecd2..10d1e637b 100644 --- a/src/video_core/pica_state.h +++ b/src/video_core/pica_state.h @@ -14,11 +14,15 @@ #include "video_core/regs.h" #include "video_core/shader/shader.h" -// NB, by defining this we can't use the built-in std::array serializer in this file +// Boost::serialization doesn't like union types for some reason, +// so we need to mark arrays of union values with a special serialization method +template +struct UnionArray : public std::array { }; + namespace boost::serialization { template -void serialize(Archive & ar, std::array &array, const unsigned int version) +void serialize(Archive& ar, UnionArray& array, const unsigned int version) { static_assert(sizeof(Value) == sizeof(u32)); ar & *static_cast(static_cast(array.data())); @@ -87,11 +91,11 @@ struct State { } }; - std::array noise_table; - std::array color_map_table; - std::array alpha_map_table; - std::array color_table; - std::array color_diff_table; + UnionArray noise_table; + UnionArray color_map_table; + UnionArray alpha_map_table; + UnionArray color_table; + UnionArray color_diff_table; private: friend class boost::serialization::access; @@ -134,7 +138,7 @@ struct State { } }; - std::array, 24> luts; + std::array, 24> luts; } lighting; struct { @@ -154,7 +158,7 @@ struct State { } }; - std::array lut; + UnionArray lut; } fog; #undef SERIALIZE_RAW @@ -214,13 +218,11 @@ private: void serialize(Archive & ar, const unsigned int file_version) { ar & regs.reg_array; - // ar & vs; - // ar & gs; + ar & vs; + ar & gs; // ar & input_default_attributes; ar & proctex; - for (auto i = 0; i < lighting.luts.size(); i++) { - ar & lighting.luts[i]; - } + ar & lighting.luts; ar & fog.lut; ar & cmd_list.addr; ar & cmd_list.length; diff --git a/src/video_core/pica_types.h b/src/video_core/pica_types.h index 5aca37b69..bef256e13 100644 --- a/src/video_core/pica_types.h +++ b/src/video_core/pica_types.h @@ -6,6 +6,7 @@ #include #include +#include #include "common/common_types.h" namespace Pica { @@ -140,6 +141,13 @@ private: // Stored as a regular float, merely for convenience // TODO: Perform proper arithmetic on this! float value; + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & value; + } }; using float24 = Float<16, 7>; diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index bb6a5fae7..3f55d3064 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "common/assert.h" #include "common/common_funcs.h" #include "common/common_types.h" @@ -193,6 +194,16 @@ struct Uniforms { static std::size_t GetIntUniformOffset(unsigned index) { return offsetof(Uniforms, i) + index * sizeof(Common::Vec4); } + +private: + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & f; + ar & b; + ar & i; + } }; struct ShaderSetup { @@ -237,6 +248,19 @@ private: bool swizzle_data_hash_dirty = true; u64 program_code_hash = 0xDEADC0DE; u64 swizzle_data_hash = 0xDEADC0DE; + + friend class boost::serialization::access; + template + void serialize(Archive & ar, const unsigned int file_version) + { + ar & uniforms; + ar & program_code; + ar & swizzle_data; + ar & program_code_hash_dirty; + ar & swizzle_data_hash_dirty; + ar & program_code_hash; + ar & swizzle_data_hash; + } }; class ShaderEngine {