GPUThread: Fix setting change crash with thread off

This commit is contained in:
Stenzek 2025-01-30 13:32:32 +10:00
parent 369879e685
commit 44a75d6586
No known key found for this signature in database

View File

@ -83,7 +83,7 @@ static bool CreateGPUBackendOnThread(GPURenderer renderer, bool upload_vram, Err
static void DestroyGPUBackendOnThread(); static void DestroyGPUBackendOnThread();
static void DestroyGPUPresenterOnThread(); static void DestroyGPUPresenterOnThread();
static void UpdateSettingsOnThread(GPUThreadUpdateSettingsCommand* cmd); static void UpdateSettingsOnThread(GPUSettings&& new_settings);
static void UpdateRunIdle(); static void UpdateRunIdle();
@ -511,7 +511,7 @@ void GPUThread::Internal::GPUThreadEntryPoint()
case GPUBackendCommandType::UpdateSettings: case GPUBackendCommandType::UpdateSettings:
{ {
GPUThreadUpdateSettingsCommand* ccmd = static_cast<GPUThreadUpdateSettingsCommand*>(cmd); GPUThreadUpdateSettingsCommand* ccmd = static_cast<GPUThreadUpdateSettingsCommand*>(cmd);
UpdateSettingsOnThread(ccmd); UpdateSettingsOnThread(std::move(ccmd->settings));
ccmd->~GPUThreadUpdateSettingsCommand(); ccmd->~GPUThreadUpdateSettingsCommand();
} }
break; break;
@ -984,12 +984,12 @@ bool GPUThread::Internal::PresentFrameAndRestoreContext()
return true; return true;
} }
void GPUThread::UpdateSettingsOnThread(GPUThreadUpdateSettingsCommand* cmd) void GPUThread::UpdateSettingsOnThread(GPUSettings&& new_settings)
{ {
VERBOSE_LOG("Updating GPU settings on thread..."); VERBOSE_LOG("Updating GPU settings on thread...");
GPUSettings old_settings = std::move(g_gpu_settings); GPUSettings old_settings = std::move(g_gpu_settings);
g_gpu_settings = std::move(cmd->settings); g_gpu_settings = std::move(new_settings);
if (g_gpu_device) if (g_gpu_device)
{ {
@ -1090,9 +1090,16 @@ void GPUThread::UpdateSettings(bool gpu_settings_changed, bool device_settings_c
} }
else if (gpu_settings_changed) else if (gpu_settings_changed)
{ {
GPUThreadUpdateSettingsCommand* cmd = if (s_state.use_gpu_thread) [[likely]]
AllocateCommand<GPUThreadUpdateSettingsCommand>(GPUBackendCommandType::UpdateSettings, g_settings); {
PushCommandAndWakeThread(cmd); GPUThreadUpdateSettingsCommand* cmd =
AllocateCommand<GPUThreadUpdateSettingsCommand>(GPUBackendCommandType::UpdateSettings, g_settings);
PushCommandAndWakeThread(cmd);
}
else
{
UpdateSettingsOnThread(GPUSettings(g_settings));
}
} }
else else
{ {
@ -1377,7 +1384,7 @@ const std::string& GPUThread::GetGameSerial()
void GPUThread::SetGameSerial(std::string serial) void GPUThread::SetGameSerial(std::string serial)
{ {
DebugAssert(!IsOnThread()); DebugAssert(!IsOnThread() || !s_state.use_gpu_thread);
RunOnThread([serial = std::move(serial)]() mutable { RunOnThread([serial = std::move(serial)]() mutable {
const bool changed = (s_state.game_serial != serial); const bool changed = (s_state.game_serial != serial);
s_state.game_serial = std::move(serial); s_state.game_serial = std::move(serial);