mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-18 16:50:05 +00:00
Added shader state serialization
This commit is contained in:
parent
6f00976ab5
commit
45788b9c82
@ -32,6 +32,7 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
#include <boost/serialization/access.hpp>
|
||||
|
||||
namespace Common {
|
||||
|
||||
@ -44,6 +45,14 @@ class Vec4;
|
||||
|
||||
template <typename T>
|
||||
class Vec2 {
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
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<float>::Normalize() {
|
||||
|
||||
template <typename T>
|
||||
class Vec3 {
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
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<float>;
|
||||
|
||||
template <typename T>
|
||||
class Vec4 {
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int file_version)
|
||||
{
|
||||
ar & x;
|
||||
ar & y;
|
||||
ar & z;
|
||||
ar & w;
|
||||
}
|
||||
|
||||
public:
|
||||
T x;
|
||||
T y;
|
||||
|
@ -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<typename Value, size_t Size>
|
||||
struct UnionArray : public std::array<Value, Size> { };
|
||||
|
||||
namespace boost::serialization {
|
||||
|
||||
template<class Archive, typename Value, size_t Size>
|
||||
void serialize(Archive & ar, std::array<Value, Size> &array, const unsigned int version)
|
||||
void serialize(Archive& ar, UnionArray<Value, Size>& array, const unsigned int version)
|
||||
{
|
||||
static_assert(sizeof(Value) == sizeof(u32));
|
||||
ar & *static_cast<u32 (*)[Size]>(static_cast<void *>(array.data()));
|
||||
@ -87,11 +91,11 @@ struct State {
|
||||
}
|
||||
};
|
||||
|
||||
std::array<ValueEntry, 128> noise_table;
|
||||
std::array<ValueEntry, 128> color_map_table;
|
||||
std::array<ValueEntry, 128> alpha_map_table;
|
||||
std::array<ColorEntry, 256> color_table;
|
||||
std::array<ColorDifferenceEntry, 256> color_diff_table;
|
||||
UnionArray<ValueEntry, 128> noise_table;
|
||||
UnionArray<ValueEntry, 128> color_map_table;
|
||||
UnionArray<ValueEntry, 128> alpha_map_table;
|
||||
UnionArray<ColorEntry, 256> color_table;
|
||||
UnionArray<ColorDifferenceEntry, 256> color_diff_table;
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
@ -134,7 +138,7 @@ struct State {
|
||||
}
|
||||
};
|
||||
|
||||
std::array<std::array<LutEntry, 256>, 24> luts;
|
||||
std::array<UnionArray<LutEntry, 256>, 24> luts;
|
||||
} lighting;
|
||||
|
||||
struct {
|
||||
@ -154,7 +158,7 @@ struct State {
|
||||
}
|
||||
};
|
||||
|
||||
std::array<LutEntry, 128> lut;
|
||||
UnionArray<LutEntry, 128> 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;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <boost/serialization/access.hpp>
|
||||
#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<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int file_version)
|
||||
{
|
||||
ar & value;
|
||||
}
|
||||
};
|
||||
|
||||
using float24 = Float<16, 7>;
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <nihstro/shader_bytecode.h>
|
||||
#include <boost/serialization/array.hpp>
|
||||
#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<u8>);
|
||||
}
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
template<class Archive>
|
||||
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<class Archive>
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user