2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2011 Dolphin Emulator Project
|
2015-05-18 01:08:10 +02:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 05:09:55 +02:00
|
|
|
// Refer to the license.txt file included.
|
2011-01-31 02:28:32 +01:00
|
|
|
|
2016-02-16 03:29:24 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
2016-01-17 22:54:31 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2011-01-31 02:28:32 +01:00
|
|
|
// TODO: ugly
|
|
|
|
#ifdef _WIN32
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
2016-01-08 04:40:35 +01:00
|
|
|
#include "VideoBackends/D3D12/VideoBackend.h"
|
2011-01-31 02:28:32 +01:00
|
|
|
#endif
|
2014-02-03 14:02:17 +01:00
|
|
|
#include "VideoBackends/Null/VideoBackend.h"
|
2014-02-17 11:18:15 +01:00
|
|
|
#include "VideoBackends/OGL/VideoBackend.h"
|
|
|
|
#include "VideoBackends/Software/VideoBackend.h"
|
2016-10-07 01:47:03 +02:00
|
|
|
#ifndef __APPLE__
|
2016-08-13 14:57:50 +02:00
|
|
|
#include "VideoBackends/Vulkan/VideoBackend.h"
|
2016-10-07 01:47:03 +02:00
|
|
|
#endif
|
2011-03-16 23:48:17 +01:00
|
|
|
|
2014-02-19 02:27:20 +01:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
|
|
|
|
2016-02-16 03:29:24 +01:00
|
|
|
std::vector<std::unique_ptr<VideoBackendBase>> g_available_video_backends;
|
2016-01-12 09:35:24 +01:00
|
|
|
VideoBackendBase* g_video_backend = nullptr;
|
|
|
|
static VideoBackendBase* s_default_backend = nullptr;
|
2011-01-31 02:28:32 +01:00
|
|
|
|
2011-03-19 13:58:55 +01:00
|
|
|
#ifdef _WIN32
|
2013-08-11 16:30:19 +02:00
|
|
|
#include <windows.h>
|
|
|
|
|
2014-10-04 21:12:15 +02:00
|
|
|
// Nvidia drivers >= v302 will check if the application exports a global
|
|
|
|
// variable named NvOptimusEnablement to know if it should run the app in high
|
|
|
|
// performance graphics mode or using the IGP.
|
|
|
|
extern "C" {
|
|
|
|
__declspec(dllexport) DWORD NvOptimusEnablement = 1;
|
|
|
|
}
|
2011-03-19 13:58:55 +01:00
|
|
|
#endif
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::PopulateList()
|
2011-01-31 02:28:32 +01:00
|
|
|
{
|
2016-08-13 14:57:50 +02:00
|
|
|
// OGL > D3D11 > D3D12 > Vulkan > SW > Null
|
2016-06-24 10:43:46 +02:00
|
|
|
g_available_video_backends.push_back(std::make_unique<OGL::VideoBackend>());
|
2011-01-31 02:28:32 +01:00
|
|
|
#ifdef _WIN32
|
2016-06-24 10:43:46 +02:00
|
|
|
g_available_video_backends.push_back(std::make_unique<DX11::VideoBackend>());
|
|
|
|
|
|
|
|
// More robust way to check for D3D12 support than (unreliable) OS version checks.
|
|
|
|
HMODULE d3d12_module = LoadLibraryA("d3d12.dll");
|
|
|
|
if (d3d12_module != nullptr)
|
|
|
|
{
|
|
|
|
FreeLibrary(d3d12_module);
|
|
|
|
g_available_video_backends.push_back(std::make_unique<DX12::VideoBackend>());
|
|
|
|
}
|
2012-12-17 21:54:20 +01:00
|
|
|
#endif
|
2016-10-07 01:47:03 +02:00
|
|
|
#ifndef __APPLE__
|
2016-08-13 14:57:50 +02:00
|
|
|
g_available_video_backends.push_back(std::make_unique<Vulkan::VideoBackend>());
|
2016-10-07 01:47:03 +02:00
|
|
|
#endif
|
2016-06-24 10:43:46 +02:00
|
|
|
g_available_video_backends.push_back(std::make_unique<SW::VideoSoftware>());
|
2014-02-03 14:02:17 +01:00
|
|
|
g_available_video_backends.push_back(std::make_unique<Null::VideoBackend>());
|
2011-02-08 15:51:53 +01:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
const auto iter =
|
|
|
|
std::find_if(g_available_video_backends.begin(), g_available_video_backends.end(),
|
|
|
|
[](const auto& backend) { return backend != nullptr; });
|
2016-02-16 03:29:24 +01:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
if (iter == g_available_video_backends.end())
|
|
|
|
return;
|
2016-02-16 03:29:24 +01:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
s_default_backend = iter->get();
|
|
|
|
g_video_backend = iter->get();
|
2011-01-31 02:28:32 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::ClearList()
|
2011-01-31 02:28:32 +01:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
g_available_video_backends.clear();
|
2011-01-31 02:28:32 +01:00
|
|
|
}
|
|
|
|
|
2016-01-12 09:35:24 +01:00
|
|
|
void VideoBackendBase::ActivateBackend(const std::string& name)
|
2011-01-31 02:28:32 +01:00
|
|
|
{
|
2016-06-24 10:43:46 +02:00
|
|
|
// If empty, set it to the default backend (expected behavior)
|
|
|
|
if (name.empty())
|
|
|
|
g_video_backend = s_default_backend;
|
2012-09-25 02:47:37 +02:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
const auto iter =
|
|
|
|
std::find_if(g_available_video_backends.begin(), g_available_video_backends.end(),
|
|
|
|
[&name](const auto& backend) { return name == backend->GetName(); });
|
2016-02-16 03:29:24 +01:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
if (iter == g_available_video_backends.end())
|
|
|
|
return;
|
2016-02-16 03:29:24 +01:00
|
|
|
|
2016-06-24 10:43:46 +02:00
|
|
|
g_video_backend = iter->get();
|
2011-01-31 02:28:32 +01:00
|
|
|
}
|