2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2011 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:09:55 +00:00
|
|
|
// Refer to the license.txt file included.
|
2011-01-31 01:28:32 +00:00
|
|
|
|
2016-02-16 02:29:24 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <memory>
|
2016-01-17 21:54:31 +00:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
// TODO: ugly
|
|
|
|
#ifdef _WIN32
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
2016-01-08 03:40:35 +00:00
|
|
|
#include "VideoBackends/D3D12/VideoBackend.h"
|
2011-01-31 01:28:32 +00:00
|
|
|
#endif
|
2014-02-03 13:02:17 +00:00
|
|
|
#include "VideoBackends/Null/VideoBackend.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/OGL/VideoBackend.h"
|
|
|
|
#include "VideoBackends/Software/VideoBackend.h"
|
2016-10-06 23:47:03 +00:00
|
|
|
#ifndef __APPLE__
|
2016-08-13 12:57:50 +00:00
|
|
|
#include "VideoBackends/Vulkan/VideoBackend.h"
|
2016-10-06 23:47:03 +00:00
|
|
|
#endif
|
2011-03-16 22:48:17 +00:00
|
|
|
|
2014-02-19 01:27:20 +00:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
|
|
|
|
2016-02-16 02:29:24 +00:00
|
|
|
std::vector<std::unique_ptr<VideoBackendBase>> g_available_video_backends;
|
2016-01-12 08:35:24 +00:00
|
|
|
VideoBackendBase* g_video_backend = nullptr;
|
|
|
|
static VideoBackendBase* s_default_backend = nullptr;
|
2011-01-31 01:28:32 +00:00
|
|
|
|
2011-03-19 12:58:55 +00:00
|
|
|
#ifdef _WIN32
|
2013-08-11 14:30:19 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
2014-10-04 19:12:15 +00: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 12:58:55 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-12 08:35:24 +00:00
|
|
|
void VideoBackendBase::PopulateList()
|
2011-01-31 01:28:32 +00:00
|
|
|
{
|
2016-08-13 12:57:50 +00:00
|
|
|
// OGL > D3D11 > D3D12 > Vulkan > SW > Null
|
2016-06-24 08:43:46 +00:00
|
|
|
g_available_video_backends.push_back(std::make_unique<OGL::VideoBackend>());
|
2011-01-31 01:28:32 +00:00
|
|
|
#ifdef _WIN32
|
2016-06-24 08:43:46 +00: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 20:54:20 +00:00
|
|
|
#endif
|
2016-10-06 23:47:03 +00:00
|
|
|
#ifndef __APPLE__
|
2016-08-13 12:57:50 +00:00
|
|
|
g_available_video_backends.push_back(std::make_unique<Vulkan::VideoBackend>());
|
2016-10-06 23:47:03 +00:00
|
|
|
#endif
|
2016-06-24 08:43:46 +00:00
|
|
|
g_available_video_backends.push_back(std::make_unique<SW::VideoSoftware>());
|
2014-02-03 13:02:17 +00:00
|
|
|
g_available_video_backends.push_back(std::make_unique<Null::VideoBackend>());
|
2011-02-08 14:51:53 +00:00
|
|
|
|
2016-06-24 08:43:46 +00: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 02:29:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (iter == g_available_video_backends.end())
|
|
|
|
return;
|
2016-02-16 02:29:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
s_default_backend = iter->get();
|
|
|
|
g_video_backend = iter->get();
|
2011-01-31 01:28:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:35:24 +00:00
|
|
|
void VideoBackendBase::ClearList()
|
2011-01-31 01:28:32 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
g_available_video_backends.clear();
|
2011-01-31 01:28:32 +00:00
|
|
|
}
|
|
|
|
|
2016-01-12 08:35:24 +00:00
|
|
|
void VideoBackendBase::ActivateBackend(const std::string& name)
|
2011-01-31 01:28:32 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// If empty, set it to the default backend (expected behavior)
|
|
|
|
if (name.empty())
|
|
|
|
g_video_backend = s_default_backend;
|
2012-09-25 00:47:37 +00:00
|
|
|
|
2016-06-24 08:43:46 +00: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 02:29:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
if (iter == g_available_video_backends.end())
|
|
|
|
return;
|
2016-02-16 02:29:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
g_video_backend = iter->get();
|
2011-01-31 01:28:32 +00:00
|
|
|
}
|