video_core.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // SPDX-FileCopyrightText: 2014 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <memory>
  4. #include "common/logging/log.h"
  5. #include "common/settings.h"
  6. #include "core/core.h"
  7. #include "video_core/host1x/gpu_device_memory_manager.h"
  8. #include "video_core/host1x/host1x.h"
  9. #include "video_core/renderer_base.h"
  10. #include "video_core/renderer_null/renderer_null.h"
  11. #include "video_core/renderer_opengl/renderer_opengl.h"
  12. #include "video_core/renderer_vulkan/renderer_vulkan.h"
  13. #include "video_core/video_core.h"
  14. namespace {
  15. std::unique_ptr<VideoCore::RendererBase> CreateRenderer(
  16. Core::System& system, Core::Frontend::EmuWindow& emu_window, Tegra::GPU& gpu,
  17. std::unique_ptr<Core::Frontend::GraphicsContext> context) {
  18. auto& telemetry_session = system.TelemetrySession();
  19. auto& device_memory = system.Host1x().MemoryManager();
  20. switch (Settings::values.renderer_backend.GetValue()) {
  21. case Settings::RendererBackend::OpenGL:
  22. return std::make_unique<OpenGL::RendererOpenGL>(telemetry_session, emu_window,
  23. device_memory, gpu, std::move(context));
  24. case Settings::RendererBackend::Vulkan:
  25. return std::make_unique<Vulkan::RendererVulkan>(telemetry_session, emu_window,
  26. device_memory, gpu, std::move(context));
  27. case Settings::RendererBackend::Null:
  28. return std::make_unique<Null::RendererNull>(emu_window, gpu, std::move(context));
  29. default:
  30. return nullptr;
  31. }
  32. }
  33. } // Anonymous namespace
  34. namespace VideoCore {
  35. std::unique_ptr<Tegra::GPU> CreateGPU(Core::Frontend::EmuWindow& emu_window, Core::System& system) {
  36. Settings::UpdateRescalingInfo();
  37. const auto nvdec_value = Settings::values.nvdec_emulation.GetValue();
  38. const bool use_nvdec = nvdec_value != Settings::NvdecEmulation::Off;
  39. const bool use_async = Settings::values.use_asynchronous_gpu_emulation.GetValue();
  40. auto gpu = std::make_unique<Tegra::GPU>(system, use_async, use_nvdec);
  41. auto context = emu_window.CreateSharedContext();
  42. auto scope = context->Acquire();
  43. try {
  44. auto renderer = CreateRenderer(system, emu_window, *gpu, std::move(context));
  45. gpu->BindRenderer(std::move(renderer));
  46. return gpu;
  47. } catch (const std::runtime_error& exception) {
  48. scope.Cancel();
  49. LOG_ERROR(HW_GPU, "Failed to initialize GPU: {}", exception.what());
  50. return nullptr;
  51. }
  52. }
  53. } // namespace VideoCore