From 05f3bbfa4d22bf50e803dfb1c75657e1a9f953a7 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Fri, 7 Oct 2022 11:52:44 -0700 Subject: [PATCH 1/2] Include tangent/binormal cache in savestates This theoretically matters for RS2/RS3, although in practice these games reconfigure it each frame so it shouldn't matter for savestates. --- Source/Core/Core/State.cpp | 2 +- Source/Core/VideoCommon/VertexManagerBase.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/Core/Core/State.cpp b/Source/Core/Core/State.cpp index 1f38fe1e17..7e81035b2a 100644 --- a/Source/Core/Core/State.cpp +++ b/Source/Core/Core/State.cpp @@ -94,7 +94,7 @@ static size_t s_state_writes_in_queue; static std::condition_variable s_state_write_queue_is_empty; // Don't forget to increase this after doing changes on the savestate system -constexpr u32 STATE_VERSION = 151; // Last changed in PR 11125 +constexpr u32 STATE_VERSION = 152; // Last changed in PR 11131 // Maps savestate versions to Dolphin versions. // Versions after 42 don't need to be added to this list, diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index e77e6e4525..c208f81097 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -564,6 +564,8 @@ void VertexManagerBase::DoState(PointerWrap& p) } p.Do(m_zslope); + p.Do(VertexLoaderManager::tangent_cache); + p.Do(VertexLoaderManager::binormal_cache); } void VertexManagerBase::CalculateZSlope(NativeVertexFormat* format) From ffed23c059f52dfbe1dbd089d6861c68b8960035 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Fri, 7 Oct 2022 12:25:04 -0700 Subject: [PATCH 2/2] Simplify saving CP state Rather than makring some parts of VertexLoaderManager dirty in some places and some in others, do it all in VideoState. Also, since CPState no longer contains pointers/non-CP data after d039b1bc0dfaba2a88036468b6d971bb1d7e463d, we can just use p.Do on it instead of manually saving each field. --- Source/Core/VideoCommon/CPMemory.cpp | 18 ------------------ Source/Core/VideoCommon/CPMemory.h | 2 -- .../Core/VideoCommon/VertexLoaderManager.cpp | 1 + Source/Core/VideoCommon/VertexManagerBase.cpp | 4 ---- Source/Core/VideoCommon/VideoState.cpp | 9 ++++++++- 5 files changed, 9 insertions(+), 25 deletions(-) diff --git a/Source/Core/VideoCommon/CPMemory.cpp b/Source/Core/VideoCommon/CPMemory.cpp index 401c37bc00..c9a5a57b51 100644 --- a/Source/Core/VideoCommon/CPMemory.cpp +++ b/Source/Core/VideoCommon/CPMemory.cpp @@ -15,24 +15,6 @@ CPState g_main_cp_state; CPState g_preprocess_cp_state; -void DoCPState(PointerWrap& p) -{ - // We don't save g_preprocess_cp_state separately because the GPU should be - // synced around state save/load. - p.DoArray(g_main_cp_state.array_bases); - p.DoArray(g_main_cp_state.array_strides); - p.Do(g_main_cp_state.matrix_index_a); - p.Do(g_main_cp_state.matrix_index_b); - p.Do(g_main_cp_state.vtx_desc); - p.DoArray(g_main_cp_state.vtx_attr); - p.DoMarker("CP Memory"); - if (p.IsReadMode()) - { - CopyPreprocessCPStateFromMain(); - VertexLoaderManager::g_bases_dirty = true; - } -} - void CopyPreprocessCPStateFromMain() { std::memcpy(&g_preprocess_cp_state, &g_main_cp_state, sizeof(CPState)); diff --git a/Source/Core/VideoCommon/CPMemory.h b/Source/Core/VideoCommon/CPMemory.h index 7ce56c05cd..098cf1f288 100644 --- a/Source/Core/VideoCommon/CPMemory.h +++ b/Source/Core/VideoCommon/CPMemory.h @@ -658,8 +658,6 @@ class PointerWrap; extern CPState g_main_cp_state; extern CPState g_preprocess_cp_state; -void DoCPState(PointerWrap& p); - void CopyPreprocessCPStateFromMain(); std::pair GetCPRegInfo(u8 cmd, u32 value); diff --git a/Source/Core/VideoCommon/VertexLoaderManager.cpp b/Source/Core/VideoCommon/VertexLoaderManager.cpp index bb843a6120..08dbe8a4d5 100644 --- a/Source/Core/VideoCommon/VertexLoaderManager.cpp +++ b/Source/Core/VideoCommon/VertexLoaderManager.cpp @@ -123,6 +123,7 @@ struct entry void MarkAllDirty() { + g_bases_dirty = true; g_main_vat_dirty = BitSet8::AllTrue(8); g_preprocess_vat_dirty = BitSet8::AllTrue(8); } diff --git a/Source/Core/VideoCommon/VertexManagerBase.cpp b/Source/Core/VideoCommon/VertexManagerBase.cpp index c208f81097..41b3968b2b 100644 --- a/Source/Core/VideoCommon/VertexManagerBase.cpp +++ b/Source/Core/VideoCommon/VertexManagerBase.cpp @@ -557,10 +557,6 @@ void VertexManagerBase::DoState(PointerWrap& p) { // Flush old vertex data before loading state. Flush(); - - // Clear all caches that touch RAM - // (? these don't appear to touch any emulation state that gets saved. moved to on load only.) - VertexLoaderManager::MarkAllDirty(); } p.Do(m_zslope); diff --git a/Source/Core/VideoCommon/VideoState.cpp b/Source/Core/VideoCommon/VideoState.cpp index 538c3d0904..b56c931b48 100644 --- a/Source/Core/VideoCommon/VideoState.cpp +++ b/Source/Core/VideoCommon/VideoState.cpp @@ -18,6 +18,7 @@ #include "VideoCommon/TMEM.h" #include "VideoCommon/TextureCacheBase.h" #include "VideoCommon/TextureDecoder.h" +#include "VideoCommon/VertexLoaderManager.h" #include "VideoCommon/VertexManagerBase.h" #include "VideoCommon/VertexShaderManager.h" #include "VideoCommon/XFMemory.h" @@ -38,7 +39,12 @@ void VideoCommon_DoState(PointerWrap& p) p.DoMarker("BP Memory"); // CP Memory - DoCPState(p); + // We don't save g_preprocess_cp_state separately because the GPU should be + // synced around state save/load. + p.Do(g_main_cp_state); + p.DoMarker("CP Memory"); + if (p.IsReadMode()) + CopyPreprocessCPStateFromMain(); // XF Memory p.Do(xfmem); @@ -90,5 +96,6 @@ void VideoCommon_DoState(PointerWrap& p) { // Inform backend of new state from registers. BPReload(); + VertexLoaderManager::MarkAllDirty(); } }