mirror of
				https://github.com/RetroDECK/Duckstation.git
				synced 2025-04-10 19:15:14 +00:00 
			
		
		
		
	System: Move restore/reset graphics API state to System
Fixes frame stepping.
This commit is contained in:
		
							parent
							
								
									3532ab8d72
								
							
						
					
					
						commit
						e9882a10aa
					
				|  | @ -249,16 +249,16 @@ void AndroidHostInterface::EmulationThreadEntryPoint(ANativeWindow* initial_surf | |||
|     { | ||||
|       DrawImGuiWindows(); | ||||
| 
 | ||||
|       g_gpu->ResetGraphicsAPIState(); | ||||
| 
 | ||||
|       m_display->Render(); | ||||
|       ImGui::NewFrame(); | ||||
| 
 | ||||
|       g_gpu->RestoreGraphicsAPIState(); | ||||
|       System::UpdatePerformanceCounters(); | ||||
|       if (System::IsRunning()) | ||||
|       { | ||||
|         System::UpdatePerformanceCounters(); | ||||
| 
 | ||||
|       if (m_speed_limiter_enabled) | ||||
|         System::Throttle(); | ||||
|         if (m_speed_limiter_enabled) | ||||
|           System::Throttle(); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -586,6 +586,11 @@ bool DoState(StateWrapper& sw) | |||
| 
 | ||||
| void Reset() | ||||
| { | ||||
|   if (IsShutdown()) | ||||
|     return; | ||||
| 
 | ||||
|   g_gpu->RestoreGraphicsAPIState(); | ||||
| 
 | ||||
|   CPU::Reset(); | ||||
|   CPU::CodeCache::Flush(); | ||||
|   Bus::Reset(); | ||||
|  | @ -602,6 +607,8 @@ void Reset() | |||
|   s_internal_frame_number = 0; | ||||
|   TimingEvents::Reset(); | ||||
|   ResetPerformanceCounters(); | ||||
| 
 | ||||
|   g_gpu->ResetGraphicsAPIState(); | ||||
| } | ||||
| 
 | ||||
| bool LoadState(ByteStream* state) | ||||
|  | @ -609,7 +616,13 @@ bool LoadState(ByteStream* state) | |||
|   if (IsShutdown()) | ||||
|     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) | ||||
|  | @ -732,11 +745,9 @@ bool SaveState(ByteStream* state, u32 screenshot_size /* = 128 */) | |||
|   if (screenshot_size > 0) | ||||
|   { | ||||
|     std::vector<u32> screenshot_buffer; | ||||
|     g_gpu->ResetGraphicsAPIState(); | ||||
|     const bool screenshot_saved = | ||||
|       g_host_interface->GetDisplay()->WriteDisplayTextureToBuffer(&screenshot_buffer, screenshot_size, screenshot_size); | ||||
|     g_gpu->RestoreGraphicsAPIState(); | ||||
|     if (screenshot_saved && !screenshot_buffer.empty()) | ||||
|     if (g_host_interface->GetDisplay()->WriteDisplayTextureToBuffer(&screenshot_buffer, screenshot_size, | ||||
|                                                                     screenshot_size) && | ||||
|         !screenshot_buffer.empty()) | ||||
|     { | ||||
|       header.offset_to_screenshot = static_cast<u32>(state->GetPosition()); | ||||
|       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()); | ||||
| 
 | ||||
|     g_gpu->RestoreGraphicsAPIState(); | ||||
| 
 | ||||
|     StateWrapper sw(state, StateWrapper::Mode::Write); | ||||
|     if (!DoState(sw)) | ||||
|     const bool result = DoState(sw); | ||||
| 
 | ||||
|     g_gpu->ResetGraphicsAPIState(); | ||||
| 
 | ||||
|     if (!result) | ||||
|       return false; | ||||
| 
 | ||||
|     header.data_compression_type = 0; | ||||
|  | @ -774,6 +791,8 @@ void RunFrame() | |||
| { | ||||
|   s_frame_timer.Reset(); | ||||
| 
 | ||||
|   g_gpu->RestoreGraphicsAPIState(); | ||||
| 
 | ||||
|   if (g_settings.cpu_execution_mode == CPUExecutionMode::Interpreter) | ||||
|     CPU::Execute(); | ||||
|   else | ||||
|  | @ -781,6 +800,8 @@ void RunFrame() | |||
| 
 | ||||
|   // Generate any pending samples from the SPU before sleeping, this way we reduce the chances of underruns.
 | ||||
|   g_spu.GeneratePendingSamples(); | ||||
| 
 | ||||
|   g_gpu->ResetGraphicsAPIState(); | ||||
| } | ||||
| 
 | ||||
| void SetThrottleFrequency(float frequency) | ||||
|  |  | |||
|  | @ -259,12 +259,8 @@ void LibretroHostInterface::retro_run_frame() | |||
| 
 | ||||
|   UpdateControllers(); | ||||
| 
 | ||||
|   g_gpu->RestoreGraphicsAPIState(); | ||||
| 
 | ||||
|   System::RunFrame(); | ||||
| 
 | ||||
|   g_gpu->ResetGraphicsAPIState(); | ||||
| 
 | ||||
|   m_display->Render(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1094,14 +1094,10 @@ void QtHostInterface::threadEntryPoint() | |||
| 
 | ||||
| void QtHostInterface::renderDisplay() | ||||
| { | ||||
|   g_gpu->ResetGraphicsAPIState(); | ||||
| 
 | ||||
|   DrawImGuiWindows(); | ||||
| 
 | ||||
|   m_display->Render(); | ||||
|   ImGui::NewFrame(); | ||||
| 
 | ||||
|   g_gpu->RestoreGraphicsAPIState(); | ||||
| } | ||||
| 
 | ||||
| void QtHostInterface::wakeThread() | ||||
|  |  | |||
|  | @ -1505,16 +1505,12 @@ void SDLHostInterface::Run() | |||
|     { | ||||
|       DrawImGuiWindows(); | ||||
| 
 | ||||
|       if (System::IsRunning()) | ||||
|         g_gpu->ResetGraphicsAPIState(); | ||||
| 
 | ||||
|       m_display->Render(); | ||||
|       ImGui_ImplSDL2_NewFrame(m_window); | ||||
|       ImGui::NewFrame(); | ||||
| 
 | ||||
|       if (System::IsRunning()) | ||||
|       { | ||||
|         g_gpu->RestoreGraphicsAPIState(); | ||||
|         System::UpdatePerformanceCounters(); | ||||
| 
 | ||||
|         if (m_speed_limiter_enabled) | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Connor McLaughlin
						Connor McLaughlin