2026-03-11 16:49:29 +01:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
2026-01-18 12:33:00 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-04-05 16:04:25 -04:00
|
|
|
|
2015-12-30 08:52:01 -05:00
|
|
|
#include <memory>
|
2020-06-11 00:58:57 -03:00
|
|
|
|
2026-03-12 18:29:15 +01:00
|
|
|
#include "common/logging.h"
|
2021-04-14 16:07:40 -07:00
|
|
|
#include "common/settings.h"
|
2018-08-31 14:16:16 +08:00
|
|
|
#include "core/core.h"
|
2026-03-11 16:49:29 +01:00
|
|
|
#include "core/frontend/emu_window.h"
|
|
|
|
|
#include "core/frontend/graphics_context.h"
|
2023-12-25 07:32:16 +01:00
|
|
|
#include "video_core/host1x/gpu_device_memory_manager.h"
|
|
|
|
|
#include "video_core/host1x/host1x.h"
|
2015-09-11 07:20:02 -04:00
|
|
|
#include "video_core/renderer_base.h"
|
2022-11-27 20:37:37 -05:00
|
|
|
#include "video_core/renderer_null/renderer_null.h"
|
2026-03-11 16:49:29 +01:00
|
|
|
#ifdef HAS_OPENGL
|
2015-09-11 07:20:02 -04:00
|
|
|
#include "video_core/renderer_opengl/renderer_opengl.h"
|
2026-03-11 16:49:29 +01:00
|
|
|
#endif
|
2020-01-21 16:40:53 -03:00
|
|
|
#include "video_core/renderer_vulkan/renderer_vulkan.h"
|
2016-09-20 23:52:38 -07:00
|
|
|
#include "video_core/video_core.h"
|
2014-04-05 16:04:25 -04:00
|
|
|
|
2020-03-24 20:58:49 -06:00
|
|
|
namespace {
|
2020-06-11 00:58:57 -03:00
|
|
|
|
2026-03-11 16:49:29 +01:00
|
|
|
std::unique_ptr<VideoCore::RendererBase> CreateRenderer(Core::System& system, Core::Frontend::EmuWindow& emu_window, Tegra::GPU& gpu, std::unique_ptr<Core::Frontend::GraphicsContext> context) {
|
|
|
|
|
[[maybe_unused]] auto& device_memory = system.Host1x().MemoryManager();
|
2020-07-09 22:42:09 -04:00
|
|
|
switch (Settings::values.renderer_backend.GetValue()) {
|
2026-03-11 16:49:29 +01:00
|
|
|
#ifdef HAS_OPENGL
|
2026-01-18 12:33:00 +01:00
|
|
|
case Settings::RendererBackend::OpenGL_GLSL:
|
|
|
|
|
case Settings::RendererBackend::OpenGL_GLASM:
|
|
|
|
|
case Settings::RendererBackend::OpenGL_SPIRV:
|
|
|
|
|
return std::make_unique<OpenGL::RendererOpenGL>(emu_window, device_memory, gpu, std::move(context));
|
2026-03-11 16:49:29 +01:00
|
|
|
#endif
|
2020-01-21 16:40:53 -03:00
|
|
|
case Settings::RendererBackend::Vulkan:
|
2026-01-18 12:33:00 +01:00
|
|
|
return std::make_unique<Vulkan::RendererVulkan>(emu_window, device_memory, gpu, std::move(context));
|
2022-11-27 20:37:37 -05:00
|
|
|
case Settings::RendererBackend::Null:
|
2023-12-25 07:32:16 +01:00
|
|
|
return std::make_unique<Null::RendererNull>(emu_window, gpu, std::move(context));
|
2020-01-21 16:40:53 -03:00
|
|
|
default:
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2014-04-05 16:04:25 -04:00
|
|
|
}
|
2020-06-11 00:58:57 -03:00
|
|
|
|
2020-03-24 22:57:36 -06:00
|
|
|
} // Anonymous namespace
|
2014-04-05 16:04:25 -04:00
|
|
|
|
2020-03-24 20:58:49 -06:00
|
|
|
namespace VideoCore {
|
|
|
|
|
|
2026-06-23 06:31:25 +02:00
|
|
|
/// @brief Creates an emulated GPU instance using the given system context.
|
|
|
|
|
void CreateGPU(std::optional<Tegra::GPU>& gpu, Core::Frontend::EmuWindow& emu_window, Core::System& system) {
|
2021-10-08 20:47:14 -04:00
|
|
|
Settings::UpdateRescalingInfo();
|
|
|
|
|
|
2021-08-08 16:56:40 -04:00
|
|
|
const auto nvdec_value = Settings::values.nvdec_emulation.GetValue();
|
|
|
|
|
const bool use_nvdec = nvdec_value != Settings::NvdecEmulation::Off;
|
2021-01-05 04:09:39 -03:00
|
|
|
const bool use_async = Settings::values.use_asynchronous_gpu_emulation.GetValue();
|
2026-06-23 06:31:25 +02:00
|
|
|
gpu.emplace(system, use_async, use_nvdec);
|
2020-03-24 20:58:49 -06:00
|
|
|
auto context = emu_window.CreateSharedContext();
|
2021-01-05 04:09:39 -03:00
|
|
|
auto scope = context->Acquire();
|
|
|
|
|
try {
|
|
|
|
|
auto renderer = CreateRenderer(system, emu_window, *gpu, std::move(context));
|
|
|
|
|
gpu->BindRenderer(std::move(renderer));
|
|
|
|
|
} catch (const std::runtime_error& exception) {
|
2022-03-07 03:37:54 -05:00
|
|
|
scope.Cancel();
|
2021-01-05 04:09:39 -03:00
|
|
|
LOG_ERROR(HW_GPU, "Failed to initialize GPU: {}", exception.what());
|
2026-06-23 06:31:25 +02:00
|
|
|
gpu.reset();
|
2019-04-09 14:02:00 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-20 00:48:02 -07:00
|
|
|
} // namespace VideoCore
|