video_core: Initialize renderer with a GPU

Add an extra step in GPU initialization to be able to initialize render
backends with a valid GPU instance.
This commit is contained in:
ReinUsesLisp
2020-06-11 00:58:57 -03:00
parent ada9b7fb77
commit da53bcee60
22 changed files with 172 additions and 119 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <memory>
#include "common/logging/log.h"
#include "core/core.h"
#include "core/settings.h"
@ -16,37 +17,46 @@
#include "video_core/video_core.h"
namespace {
std::unique_ptr<VideoCore::RendererBase> CreateRenderer(Core::Frontend::EmuWindow& emu_window,
Core::System& system,
Core::Frontend::GraphicsContext& context) {
std::unique_ptr<VideoCore::RendererBase> CreateRenderer(
Core::System& system, Core::Frontend::EmuWindow& emu_window, Tegra::GPU& gpu,
std::unique_ptr<Core::Frontend::GraphicsContext> context) {
switch (Settings::values.renderer_backend.GetValue()) {
case Settings::RendererBackend::OpenGL:
return std::make_unique<OpenGL::RendererOpenGL>(emu_window, system, context);
return std::make_unique<OpenGL::RendererOpenGL>(system, emu_window, gpu,
std::move(context));
#ifdef HAS_VULKAN
case Settings::RendererBackend::Vulkan:
return std::make_unique<Vulkan::RendererVulkan>(emu_window, system);
return std::make_unique<Vulkan::RendererVulkan>(system, emu_window, gpu,
std::move(context));
#endif
default:
return nullptr;
}
}
} // Anonymous namespace
namespace VideoCore {
std::unique_ptr<Tegra::GPU> CreateGPU(Core::Frontend::EmuWindow& emu_window, Core::System& system) {
std::unique_ptr<Tegra::GPU> gpu;
if (Settings::values.use_asynchronous_gpu_emulation.GetValue()) {
gpu = std::make_unique<VideoCommon::GPUAsynch>(system);
} else {
gpu = std::make_unique<VideoCommon::GPUSynch>(system);
}
auto context = emu_window.CreateSharedContext();
const auto scope = context->Acquire();
auto renderer = CreateRenderer(emu_window, system, *context);
auto renderer = CreateRenderer(system, emu_window, *gpu, std::move(context));
if (!renderer->Init()) {
return nullptr;
}
if (Settings::values.use_asynchronous_gpu_emulation.GetValue()) {
return std::make_unique<VideoCommon::GPUAsynch>(system, std::move(renderer),
std::move(context));
}
return std::make_unique<VideoCommon::GPUSynch>(system, std::move(renderer), std::move(context));
gpu->BindRenderer(std::move(renderer));
return gpu;
}
u16 GetResolutionScaleFactor(const RendererBase& renderer) {