video_core.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "core/core.h"
  7. #include "core/settings.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. const bool use_nvdec = Settings::values.use_nvdec_emulation.GetValue();
  33. std::unique_ptr<Tegra::GPU> gpu = std::make_unique<Tegra::GPU>(
  34. system, Settings::values.use_asynchronous_gpu_emulation.GetValue(), use_nvdec);
  35. auto context = emu_window.CreateSharedContext();
  36. const auto scope = context->Acquire();
  37. auto renderer = CreateRenderer(system, emu_window, *gpu, std::move(context));
  38. if (!renderer->Init()) {
  39. return nullptr;
  40. }
  41. gpu->BindRenderer(std::move(renderer));
  42. return gpu;
  43. }
  44. u16 GetResolutionScaleFactor(const RendererBase& renderer) {
  45. return static_cast<u16>(
  46. Settings::values.resolution_factor.GetValue() != 0
  47. ? Settings::values.resolution_factor.GetValue()
  48. : renderer.GetRenderWindow().GetFramebufferLayout().GetScalingRatio());
  49. }
  50. } // namespace VideoCore