System: Move restore/reset graphics API state to System

Fixes frame stepping.
This commit is contained in:
Connor McLaughlin 2020-08-01 16:45:06 +10:00
parent 3532ab8d72
commit e9882a10aa
5 changed files with 34 additions and 25 deletions

View File

@ -249,18 +249,18 @@ void AndroidHostInterface::EmulationThreadEntryPoint(ANativeWindow* initial_surf
{ {
DrawImGuiWindows(); DrawImGuiWindows();
g_gpu->ResetGraphicsAPIState();
m_display->Render(); m_display->Render();
ImGui::NewFrame(); ImGui::NewFrame();
g_gpu->RestoreGraphicsAPIState(); if (System::IsRunning())
{
System::UpdatePerformanceCounters(); System::UpdatePerformanceCounters();
if (m_speed_limiter_enabled) if (m_speed_limiter_enabled)
System::Throttle(); System::Throttle();
} }
} }
}
DestroySystem(); DestroySystem();
DestroyImGuiContext(); DestroyImGuiContext();

View File

@ -586,6 +586,11 @@ bool DoState(StateWrapper& sw)
void Reset() void Reset()
{ {
if (IsShutdown())
return;
g_gpu->RestoreGraphicsAPIState();
CPU::Reset(); CPU::Reset();
CPU::CodeCache::Flush(); CPU::CodeCache::Flush();
Bus::Reset(); Bus::Reset();
@ -602,6 +607,8 @@ void Reset()
s_internal_frame_number = 0; s_internal_frame_number = 0;
TimingEvents::Reset(); TimingEvents::Reset();
ResetPerformanceCounters(); ResetPerformanceCounters();
g_gpu->ResetGraphicsAPIState();
} }
bool LoadState(ByteStream* state) bool LoadState(ByteStream* state)
@ -609,7 +616,13 @@ bool LoadState(ByteStream* state)
if (IsShutdown()) if (IsShutdown())
return false; return false;
return DoLoadState(state, false); g_gpu->RestoreGraphicsAPIState();
const bool result = DoLoadState(state, false);
g_gpu->ResetGraphicsAPIState();
return result;
} }
bool DoLoadState(ByteStream* state, bool force_software_renderer) bool DoLoadState(ByteStream* state, bool force_software_renderer)
@ -732,11 +745,9 @@ bool SaveState(ByteStream* state, u32 screenshot_size /* = 128 */)
if (screenshot_size > 0) if (screenshot_size > 0)
{ {
std::vector<u32> screenshot_buffer; std::vector<u32> screenshot_buffer;
g_gpu->ResetGraphicsAPIState(); if (g_host_interface->GetDisplay()->WriteDisplayTextureToBuffer(&screenshot_buffer, screenshot_size,
const bool screenshot_saved = screenshot_size) &&
g_host_interface->GetDisplay()->WriteDisplayTextureToBuffer(&screenshot_buffer, screenshot_size, screenshot_size); !screenshot_buffer.empty())
g_gpu->RestoreGraphicsAPIState();
if (screenshot_saved && !screenshot_buffer.empty())
{ {
header.offset_to_screenshot = static_cast<u32>(state->GetPosition()); header.offset_to_screenshot = static_cast<u32>(state->GetPosition());
header.screenshot_width = screenshot_size; header.screenshot_width = screenshot_size;
@ -751,8 +762,14 @@ bool SaveState(ByteStream* state, u32 screenshot_size /* = 128 */)
{ {
header.offset_to_data = static_cast<u32>(state->GetPosition()); header.offset_to_data = static_cast<u32>(state->GetPosition());
g_gpu->RestoreGraphicsAPIState();
StateWrapper sw(state, StateWrapper::Mode::Write); StateWrapper sw(state, StateWrapper::Mode::Write);
if (!DoState(sw)) const bool result = DoState(sw);
g_gpu->ResetGraphicsAPIState();
if (!result)
return false; return false;
header.data_compression_type = 0; header.data_compression_type = 0;
@ -774,6 +791,8 @@ void RunFrame()
{ {
s_frame_timer.Reset(); s_frame_timer.Reset();
g_gpu->RestoreGraphicsAPIState();
if (g_settings.cpu_execution_mode == CPUExecutionMode::Interpreter) if (g_settings.cpu_execution_mode == CPUExecutionMode::Interpreter)
CPU::Execute(); CPU::Execute();
else else
@ -781,6 +800,8 @@ void RunFrame()
// Generate any pending samples from the SPU before sleeping, this way we reduce the chances of underruns. // Generate any pending samples from the SPU before sleeping, this way we reduce the chances of underruns.
g_spu.GeneratePendingSamples(); g_spu.GeneratePendingSamples();
g_gpu->ResetGraphicsAPIState();
} }
void SetThrottleFrequency(float frequency) void SetThrottleFrequency(float frequency)

View File

@ -259,12 +259,8 @@ void LibretroHostInterface::retro_run_frame()
UpdateControllers(); UpdateControllers();
g_gpu->RestoreGraphicsAPIState();
System::RunFrame(); System::RunFrame();
g_gpu->ResetGraphicsAPIState();
m_display->Render(); m_display->Render();
} }

View File

@ -1094,14 +1094,10 @@ void QtHostInterface::threadEntryPoint()
void QtHostInterface::renderDisplay() void QtHostInterface::renderDisplay()
{ {
g_gpu->ResetGraphicsAPIState();
DrawImGuiWindows(); DrawImGuiWindows();
m_display->Render(); m_display->Render();
ImGui::NewFrame(); ImGui::NewFrame();
g_gpu->RestoreGraphicsAPIState();
} }
void QtHostInterface::wakeThread() void QtHostInterface::wakeThread()

View File

@ -1505,16 +1505,12 @@ void SDLHostInterface::Run()
{ {
DrawImGuiWindows(); DrawImGuiWindows();
if (System::IsRunning())
g_gpu->ResetGraphicsAPIState();
m_display->Render(); m_display->Render();
ImGui_ImplSDL2_NewFrame(m_window); ImGui_ImplSDL2_NewFrame(m_window);
ImGui::NewFrame(); ImGui::NewFrame();
if (System::IsRunning()) if (System::IsRunning())
{ {
g_gpu->RestoreGraphicsAPIState();
System::UpdatePerformanceCounters(); System::UpdatePerformanceCounters();
if (m_speed_limiter_enabled) if (m_speed_limiter_enabled)