Skip to content

Commit

Permalink
Savestate/IDM: Do not save unsavable containers
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Jun 24, 2023
1 parent 72fa51a commit 63b125b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 5 additions & 0 deletions rpcs3/Emu/Cell/lv2/sys_sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ struct lv2_obj
public:
SAVESTATE_INIT_POS(4); // Dependency on PPUs

lv2_obj() noexcept = default;
lv2_obj(u32 i) noexcept : exists{ i } {}
lv2_obj(utils::serial&) noexcept {}
void save(utils::serial&) {}

// Existence validation (workaround for shared-ptr ref-counting)
atomic_t<u32> exists = 0;

Expand Down
13 changes: 8 additions & 5 deletions rpcs3/Emu/IdManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,18 @@ namespace id_manager
std::vector<std::pair<id_key, std::shared_ptr<void>>> vec{}, private_copy{};
shared_mutex mutex{}; // TODO: Use this instead of global mutex

id_map()
id_map() noexcept
{
// Preallocate memory
vec.reserve(T::id_count);
}

// Order it directly before the source type's position
static constexpr double savestate_init_pos = std::bit_cast<double>(std::bit_cast<u64>(T::savestate_init_pos) - 1);
static constexpr double savestate_init_pos_original = T::savestate_init_pos;
static constexpr double savestate_init_pos = std::bit_cast<double>(std::bit_cast<u64>(savestate_init_pos_original) - 1);

id_map(utils::serial& ar)
template <bool Dummy = false> requires (savestate_init_pos_original != 0 && std::is_constructible_v<T, stx::exact_t<utils::serial&>>)
id_map(utils::serial& ar) noexcept
{
vec.resize(T::id_count);

Expand Down Expand Up @@ -297,6 +299,7 @@ namespace id_manager
}
}

template <bool Dummy = false> requires (savestate_init_pos_original != 0 && std::is_constructible_v<T, stx::exact_t<utils::serial&>>)
void save(utils::serial& ar)
{
u32 obj_count = 0;
Expand Down Expand Up @@ -334,8 +337,8 @@ namespace id_manager
std::memcpy(ar.data.data() + obj_count_offs, &obj_count, sizeof(obj_count));
}

template <bool dummy = false> requires (std::is_assignable_v<T&, thread_state>)
id_map& operator=(thread_state state)
template <bool Dummy = false> requires (std::is_assignable_v<T&, thread_state>)
id_map& operator=(thread_state state) noexcept
{
if (private_copy.empty())
{
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/util/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,4 +1353,4 @@ extern bool serialize(utils::serial& ar, T& obj);
}()

#define ENABLE_BITWISE_SERIALIZATION using enable_bitcopy = std::true_type;
#define SAVESTATE_INIT_POS(x) static constexpr double savestate_init_pos = (x)
#define SAVESTATE_INIT_POS(...) static constexpr double savestate_init_pos = (__VA_ARGS__)

0 comments on commit 63b125b

Please sign in to comment.