Skip to content

Commit

Permalink
System: Use recreation logic for toggling GPU threading
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jan 31, 2025
1 parent f7d7eec commit 96058f5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/core/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ static void ClearRunningGame();
static void DestroySystem();

static void RecreateGPU(GPURenderer new_renderer);
static void SetGPUThreadEnabled(bool enabled);
static std::string GetScreenshotPath(const char* extension);
static bool StartMediaCapture(std::string path, bool capture_video, bool capture_audio, u32 video_width,
u32 video_height);
Expand Down Expand Up @@ -1203,6 +1204,27 @@ void System::RecreateGPU(GPURenderer renderer)
GPUThread::PresentCurrentFrame();
}

void System::SetGPUThreadEnabled(bool enabled)
{
// can be called without valid system
if (!IsValid())
{
GPUThread::Internal::SetThreadEnabled(g_settings.gpu_use_thread);
return;
}

FreeMemoryStateStorage(false, true, false);
StopMediaCapture();

GPUThread::Internal::SetThreadEnabled(g_settings.gpu_use_thread);

ClearMemorySaveStates(true, false);

g_gpu.UpdateDisplay(false);
if (IsPaused())
GPUThread::PresentCurrentFrame();
}

void System::LoadSettings(bool display_osd_messages)
{
std::unique_lock<std::mutex> lock = Host::GetSettingsLock();
Expand Down Expand Up @@ -4676,7 +4698,7 @@ void System::CheckForSettingsChanges(const Settings& old_settings)

if (g_settings.gpu_use_thread != old_settings.gpu_use_thread) [[unlikely]]
{
GPUThread::Internal::SetThreadEnabled(g_settings.gpu_use_thread);
SetGPUThreadEnabled(g_settings.gpu_use_thread);
}
else if (g_settings.gpu_use_thread && g_settings.gpu_max_queued_frames != old_settings.gpu_max_queued_frames)
[[unlikely]]
Expand Down

0 comments on commit 96058f5

Please sign in to comment.