mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-07 12:05:52 +00:00
GPUThread: Push settings through FIFO
Saves the std::function heap allocation.
This commit is contained in:
parent
f045a1742d
commit
89504b0184
@ -82,7 +82,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(const GPUSettings& old_settings);
|
static void UpdateSettingsOnThread(GPUThreadUpdateSettingsCommand* cmd);
|
||||||
|
|
||||||
static void UpdateRunIdle();
|
static void UpdateRunIdle();
|
||||||
|
|
||||||
@ -507,6 +507,14 @@ void GPUThread::Internal::GPUThreadEntryPoint()
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GPUBackendCommandType::UpdateSettings:
|
||||||
|
{
|
||||||
|
GPUThreadUpdateSettingsCommand* ccmd = static_cast<GPUThreadUpdateSettingsCommand*>(cmd);
|
||||||
|
UpdateSettingsOnThread(ccmd);
|
||||||
|
ccmd->~GPUThreadUpdateSettingsCommand();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case GPUBackendCommandType::Shutdown:
|
case GPUBackendCommandType::Shutdown:
|
||||||
{
|
{
|
||||||
// Should have consumed everything, and be shutdown.
|
// Should have consumed everything, and be shutdown.
|
||||||
@ -553,6 +561,7 @@ bool GPUThread::Reconfigure(std::string serial, std::optional<GPURenderer> rende
|
|||||||
cmd->upload_vram = upload_vram;
|
cmd->upload_vram = upload_vram;
|
||||||
cmd->error_ptr = error;
|
cmd->error_ptr = error;
|
||||||
cmd->out_result = &result;
|
cmd->out_result = &result;
|
||||||
|
cmd->settings = g_settings;
|
||||||
|
|
||||||
if (!s_state.use_gpu_thread) [[unlikely]]
|
if (!s_state.use_gpu_thread) [[unlikely]]
|
||||||
ReconfigureOnThread(cmd);
|
ReconfigureOnThread(cmd);
|
||||||
@ -819,7 +828,7 @@ void GPUThread::ReconfigureOnThread(GPUThreadReconfigureCommand* cmd)
|
|||||||
s_state.requested_allow_present_throttle = cmd->allow_present_throttle;
|
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.requested_fullscreen_ui = cmd->start_fullscreen_ui.value_or(s_state.requested_fullscreen_ui);
|
||||||
s_state.game_serial = std::move(cmd->game_serial);
|
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.
|
// Readback old VRAM for hardware renderers.
|
||||||
const bool had_renderer = static_cast<bool>(s_state.gpu_backend);
|
const bool had_renderer = static_cast<bool>(s_state.gpu_backend);
|
||||||
@ -966,8 +975,13 @@ bool GPUThread::Internal::PresentFrameAndRestoreContext()
|
|||||||
return true;
|
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_device)
|
||||||
{
|
{
|
||||||
if (g_gpu_settings.display_osd_scale != old_settings.display_osd_scale)
|
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)
|
else if (gpu_settings_changed)
|
||||||
{
|
{
|
||||||
RunOnThread([settings = g_settings]() {
|
GPUThreadUpdateSettingsCommand* cmd =
|
||||||
VERBOSE_LOG("Updating GPU settings on thread...");
|
AllocateCommand<GPUThreadUpdateSettingsCommand>(GPUBackendCommandType::UpdateSettings, g_settings);
|
||||||
|
PushCommandAndWakeThread(cmd);
|
||||||
GPUSettings old_settings = std::move(g_gpu_settings);
|
|
||||||
g_gpu_settings = std::move(settings);
|
|
||||||
|
|
||||||
UpdateSettingsOnThread(old_settings);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <stenzek@gmail.com>
|
||||||
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "gpu_types.h"
|
#include "gpu_types.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
#include "common/align.h"
|
#include "common/align.h"
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ enum class GPUBackendCommandType : u8
|
|||||||
AsyncCall,
|
AsyncCall,
|
||||||
AsyncBackendCall,
|
AsyncBackendCall,
|
||||||
Reconfigure,
|
Reconfigure,
|
||||||
|
UpdateSettings,
|
||||||
Shutdown,
|
Shutdown,
|
||||||
ClearVRAM,
|
ClearVRAM,
|
||||||
ClearDisplay,
|
ClearDisplay,
|
||||||
@ -78,6 +80,14 @@ struct GPUThreadReconfigureCommand : public GPUThreadCommand
|
|||||||
bool allow_present_throttle;
|
bool allow_present_throttle;
|
||||||
bool force_recreate_device;
|
bool force_recreate_device;
|
||||||
bool upload_vram;
|
bool upload_vram;
|
||||||
|
GPUSettings settings;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GPUThreadUpdateSettingsCommand : public GPUThreadCommand
|
||||||
|
{
|
||||||
|
GPUThreadUpdateSettingsCommand(const GPUSettings& settings_) : settings(settings_) {}
|
||||||
|
|
||||||
|
GPUSettings settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GPUThreadAsyncCallCommand : public GPUThreadCommand
|
struct GPUThreadAsyncCallCommand : public GPUThreadCommand
|
||||||
|
Loading…
x
Reference in New Issue
Block a user