GPUDevice: Use Error class for initialization errors

This commit is contained in:
Stenzek
2024-01-20 23:21:35 +10:00
parent 24cb489a32
commit f66866ed73
32 changed files with 323 additions and 228 deletions

View File

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "host.h"
@ -14,6 +14,7 @@
#include "util/imgui_manager.h"
#include "common/assert.h"
#include "common/error.h"
#include "common/layered_settings_interface.h"
#include "common/log.h"
#include "common/string_util.h"
@ -259,29 +260,30 @@ bool Host::CreateGPUDevice(RenderAPI api)
disabled_features |= GPUDevice::FEATURE_MASK_TEXTURE_COPY_TO_SELF;
// TODO: FSUI should always use vsync..
Error error;
const bool vsync = System::IsValid() ? System::ShouldUseVSync() : g_settings.video_sync_enabled;
if (!g_gpu_device || !g_gpu_device->Create(g_settings.gpu_adapter,
g_settings.gpu_disable_shader_cache ? std::string_view() :
std::string_view(EmuFolders::Cache),
SHADER_CACHE_VERSION, g_settings.gpu_use_debug_device, vsync,
g_settings.gpu_threaded_presentation, exclusive_fullscreen_control,
static_cast<GPUDevice::FeatureMask>(disabled_features)))
static_cast<GPUDevice::FeatureMask>(disabled_features), &error))
{
Log_ErrorPrintf("Failed to create GPU device.");
if (g_gpu_device)
g_gpu_device->Destroy();
g_gpu_device.reset();
Host::ReportErrorAsync("Error",
fmt::format("Failed to create render device. This may be due to your GPU not supporting the "
"chosen renderer ({}), or because your graphics drivers need to be updated.",
GPUDevice::RenderAPIToString(api)));
Host::ReportErrorAsync(
"Error", fmt::format("Failed to create render device:\n\n{}\n\nThis may be due to your GPU not supporting the "
"chosen renderer ({}), or because your graphics drivers need to be updated.",
error.GetDescription(), GPUDevice::RenderAPIToString(api)));
return false;
}
if (!ImGuiManager::Initialize(g_settings.display_osd_scale / 100.0f, g_settings.display_show_osd_messages))
if (!ImGuiManager::Initialize(g_settings.display_osd_scale / 100.0f, g_settings.display_show_osd_messages, &error))
{
Log_ErrorPrintf("Failed to initialize ImGuiManager.");
Host::ReportErrorAsync("Error", fmt::format("Failed to initialize ImGuiManager: {}", error.GetDescription()));
g_gpu_device->Destroy();
g_gpu_device.reset();
return false;