VideoBackendBase: Do save state logic on the GPU thread

This commit is contained in:
Stenzek
2019-06-29 18:35:12 +10:00
parent a25a4e0708
commit b26bb0605b
7 changed files with 40 additions and 30 deletions

View File

@ -40,6 +40,7 @@
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/TextureCacheBase.h"
#include "VideoCommon/VertexLoaderManager.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VertexShaderManager.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
@ -236,8 +237,25 @@ void VideoBackendBase::PopulateBackendInfo()
g_Config.Refresh();
}
// Run from the CPU thread
void VideoBackendBase::DoState(PointerWrap& p)
{
if (!SConfig::GetInstance().bCPUThread)
{
DoStateGPUThread(p);
return;
}
AsyncRequests::Event ev = {};
ev.do_save_state.p = &p;
ev.type = AsyncRequests::Event::DO_SAVE_STATE;
AsyncRequests::GetInstance()->PushEvent(ev, true);
// Let the GPU thread sleep after loading the state, so we're not spinning if paused after loading
// a state. The next GP burst will wake it up again.
Fifo::GpuMaySleep();
}
void VideoBackendBase::DoStateGPUThread(PointerWrap& p)
{
bool software = false;
p.Do(software);
@ -254,7 +272,10 @@ void VideoBackendBase::DoState(PointerWrap& p)
// Refresh state.
if (p.GetMode() == PointerWrap::MODE_READ)
{
m_invalid = true;
// Inform backend of new state from registers.
g_vertex_manager->Flush();
g_texture_cache->Invalidate();
BPReload();
// Clear all caches that touch RAM
// (? these don't appear to touch any emulation state that gets saved. moved to on load only.)
@ -262,17 +283,6 @@ void VideoBackendBase::DoState(PointerWrap& p)
}
}
void VideoBackendBase::CheckInvalidState()
{
if (m_invalid)
{
m_invalid = false;
BPReload();
g_texture_cache->Invalidate();
}
}
void VideoBackendBase::InitializeShared()
{
memset(&g_main_cp_state, 0, sizeof(g_main_cp_state));
@ -282,8 +292,6 @@ void VideoBackendBase::InitializeShared()
// do not initialize again for the config window
m_initialized = true;
m_invalid = false;
CommandProcessor::Init();
Fifo::Init();
OpcodeDecoder::Init();