diff --git a/src/core/gpu_thread.cpp b/src/core/gpu_thread.cpp index 1c8ae3d676..3afb803031 100644 --- a/src/core/gpu_thread.cpp +++ b/src/core/gpu_thread.cpp @@ -82,7 +82,7 @@ static bool CreateGPUBackendOnThread(GPURenderer renderer, bool upload_vram, Err static void DestroyGPUBackendOnThread(); static void DestroyGPUPresenterOnThread(); -static void UpdateSettingsOnThread(const GPUSettings& old_settings); +static void UpdateSettingsOnThread(GPUThreadUpdateSettingsCommand* cmd); static void UpdateRunIdle(); @@ -507,6 +507,14 @@ void GPUThread::Internal::GPUThreadEntryPoint() } break; + case GPUBackendCommandType::UpdateSettings: + { + GPUThreadUpdateSettingsCommand* ccmd = static_cast(cmd); + UpdateSettingsOnThread(ccmd); + ccmd->~GPUThreadUpdateSettingsCommand(); + } + break; + case GPUBackendCommandType::Shutdown: { // Should have consumed everything, and be shutdown. @@ -553,6 +561,7 @@ bool GPUThread::Reconfigure(std::string serial, std::optional rende cmd->upload_vram = upload_vram; cmd->error_ptr = error; cmd->out_result = &result; + cmd->settings = g_settings; if (!s_state.use_gpu_thread) [[unlikely]] ReconfigureOnThread(cmd); @@ -819,7 +828,7 @@ void GPUThread::ReconfigureOnThread(GPUThreadReconfigureCommand* cmd) s_state.requested_allow_present_throttle = cmd->allow_present_throttle; s_state.requested_fullscreen_ui = cmd->start_fullscreen_ui.value_or(s_state.requested_fullscreen_ui); s_state.game_serial = std::move(cmd->game_serial); - g_gpu_settings = g_settings; + g_gpu_settings = std::move(cmd->settings); // Readback old VRAM for hardware renderers. const bool had_renderer = static_cast(s_state.gpu_backend); @@ -966,8 +975,13 @@ bool GPUThread::Internal::PresentFrameAndRestoreContext() return true; } -void GPUThread::UpdateSettingsOnThread(const GPUSettings& old_settings) +void GPUThread::UpdateSettingsOnThread(GPUThreadUpdateSettingsCommand* cmd) { + VERBOSE_LOG("Updating GPU settings on thread..."); + + GPUSettings old_settings = std::move(g_gpu_settings); + g_gpu_settings = std::move(cmd->settings); + if (g_gpu_device) { if (g_gpu_settings.display_osd_scale != old_settings.display_osd_scale) @@ -1067,14 +1081,9 @@ void GPUThread::UpdateSettings(bool gpu_settings_changed, bool device_settings_c } else if (gpu_settings_changed) { - RunOnThread([settings = g_settings]() { - VERBOSE_LOG("Updating GPU settings on thread..."); - - GPUSettings old_settings = std::move(g_gpu_settings); - g_gpu_settings = std::move(settings); - - UpdateSettingsOnThread(old_settings); - }); + GPUThreadUpdateSettingsCommand* cmd = + AllocateCommand(GPUBackendCommandType::UpdateSettings, g_settings); + PushCommandAndWakeThread(cmd); } else { diff --git a/src/core/gpu_thread_commands.h b/src/core/gpu_thread_commands.h index 7b289fda5a..5135c60063 100644 --- a/src/core/gpu_thread_commands.h +++ b/src/core/gpu_thread_commands.h @@ -1,9 +1,10 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #pragma once #include "gpu_types.h" +#include "settings.h" #include "common/align.h" @@ -29,6 +30,7 @@ enum class GPUBackendCommandType : u8 AsyncCall, AsyncBackendCall, Reconfigure, + UpdateSettings, Shutdown, ClearVRAM, ClearDisplay, @@ -78,6 +80,14 @@ struct GPUThreadReconfigureCommand : public GPUThreadCommand bool allow_present_throttle; bool force_recreate_device; bool upload_vram; + GPUSettings settings; +}; + +struct GPUThreadUpdateSettingsCommand : public GPUThreadCommand +{ + GPUThreadUpdateSettingsCommand(const GPUSettings& settings_) : settings(settings_) {} + + GPUSettings settings; }; struct GPUThreadAsyncCallCommand : public GPUThreadCommand