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