video_core.cpp 2.2 KB

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