2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
#include <string>
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
|
|
|
#include "Common/IniFile.h"
|
2014-03-12 19:33:41 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-06-05 23:29:54 +00:00
|
|
|
#include "Common/Logging/LogManager.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
#include "Core/Host.h"
|
2010-07-18 10:11:34 +00:00
|
|
|
|
2014-12-05 02:01:20 +00:00
|
|
|
#include "VideoBackends/D3D/BoundingBox.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/D3DUtil.h"
|
2014-12-03 21:17:56 +00:00
|
|
|
#include "VideoBackends/D3D/GeometryShaderCache.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoBackends/D3D/Globals.h"
|
|
|
|
#include "VideoBackends/D3D/PerfQuery.h"
|
|
|
|
#include "VideoBackends/D3D/PixelShaderCache.h"
|
|
|
|
#include "VideoBackends/D3D/TextureCache.h"
|
|
|
|
#include "VideoBackends/D3D/VertexManager.h"
|
|
|
|
#include "VideoBackends/D3D/VertexShaderCache.h"
|
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/BPStructs.h"
|
|
|
|
#include "VideoCommon/CommandProcessor.h"
|
|
|
|
#include "VideoCommon/Fifo.h"
|
2014-12-14 20:23:13 +00:00
|
|
|
#include "VideoCommon/GeometryShaderManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/IndexGenerator.h"
|
|
|
|
#include "VideoCommon/OnScreenDisplay.h"
|
|
|
|
#include "VideoCommon/OpcodeDecoding.h"
|
|
|
|
#include "VideoCommon/PixelEngine.h"
|
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
|
|
|
#include "VideoCommon/VertexLoaderManager.h"
|
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
namespace DX11
|
2011-01-14 15:09:30 +00:00
|
|
|
{
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
unsigned int VideoBackend::PeekMessages()
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
if (msg.message == WM_QUIT)
|
|
|
|
return FALSE;
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-12 23:39:55 +00:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 13:51:43 +00:00
|
|
|
{
|
2013-09-22 15:48:48 +00:00
|
|
|
return "D3D";
|
2013-05-01 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
2014-03-12 23:39:55 +00:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2013-09-22 15:48:48 +00:00
|
|
|
return "Direct3D";
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
void InitBackendInfo()
|
|
|
|
{
|
2011-01-29 20:16:51 +00:00
|
|
|
HRESULT hr = DX11::D3D::LoadDXGI();
|
|
|
|
if (SUCCEEDED(hr)) hr = DX11::D3D::LoadD3D();
|
2010-11-23 19:58:02 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-01-29 20:16:51 +00:00
|
|
|
DX11::D3D::UnloadDXGI();
|
2010-11-23 19:58:02 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-11-21 15:34:04 +00:00
|
|
|
|
2013-09-22 16:07:21 +00:00
|
|
|
g_Config.backend_info.APIType = API_D3D;
|
2014-07-19 18:18:03 +00:00
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
|
2011-05-31 20:16:59 +00:00
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
2013-04-08 14:34:47 +00:00
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
2014-12-06 02:54:34 +00:00
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = false;
|
2014-12-16 23:26:03 +00:00
|
|
|
g_Config.backend_info.bSupportsGeometryShaders = true;
|
2014-11-13 23:24:53 +00:00
|
|
|
g_Config.backend_info.bSupports3DVision = true;
|
2015-01-03 00:33:30 +00:00
|
|
|
g_Config.backend_info.bSupportsPostProcessing = false;
|
2015-01-26 23:33:23 +00:00
|
|
|
g_Config.backend_info.bSupportsPaletteConversion = true;
|
2015-06-24 21:16:53 +00:00
|
|
|
g_Config.backend_info.bSupportsClipControl = true;
|
2015-09-01 05:17:24 +00:00
|
|
|
g_Config.backend_info.bSupportsSSAA = false;
|
2011-05-31 20:16:59 +00:00
|
|
|
|
2010-11-15 09:54:07 +00:00
|
|
|
IDXGIFactory* factory;
|
|
|
|
IDXGIAdapter* ad;
|
2011-01-29 20:16:51 +00:00
|
|
|
hr = DX11::PCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
|
2010-11-15 09:54:07 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
PanicAlert("Failed to create IDXGIFactory object");
|
|
|
|
|
2010-11-22 22:17:35 +00:00
|
|
|
// adapters
|
|
|
|
g_Config.backend_info.Adapters.clear();
|
2010-11-23 19:58:02 +00:00
|
|
|
g_Config.backend_info.AAModes.clear();
|
2010-11-21 14:47:28 +00:00
|
|
|
while (factory->EnumAdapters((UINT)g_Config.backend_info.Adapters.size(), &ad) != DXGI_ERROR_NOT_FOUND)
|
2010-11-15 09:54:07 +00:00
|
|
|
{
|
2013-07-22 12:38:09 +00:00
|
|
|
const size_t adapter_index = g_Config.backend_info.Adapters.size();
|
|
|
|
|
2013-02-28 00:01:48 +00:00
|
|
|
DXGI_ADAPTER_DESC desc;
|
2010-11-15 09:54:07 +00:00
|
|
|
ad->GetDesc(&desc);
|
2010-11-23 19:58:02 +00:00
|
|
|
|
|
|
|
// TODO: These don't get updated on adapter change, yet
|
2013-07-22 12:38:09 +00:00
|
|
|
if (adapter_index == g_Config.iAdapter)
|
2010-11-23 19:58:02 +00:00
|
|
|
{
|
2014-06-03 05:08:54 +00:00
|
|
|
std::string samples;
|
|
|
|
std::vector<DXGI_SAMPLE_DESC> modes = DX11::D3D::EnumAAModes(ad);
|
2011-06-11 19:37:21 +00:00
|
|
|
for (unsigned int i = 0; i < modes.size(); ++i)
|
2010-11-23 19:58:02 +00:00
|
|
|
{
|
2014-06-03 05:08:54 +00:00
|
|
|
if (i == 0)
|
|
|
|
samples = _trans("None");
|
|
|
|
else if (modes[i].Quality)
|
|
|
|
samples = StringFromFormat(_trans("%d samples (quality level %d)"), modes[i].Count, modes[i].Quality);
|
|
|
|
else
|
|
|
|
samples = StringFromFormat(_trans("%d samples"), modes[i].Count);
|
|
|
|
|
|
|
|
g_Config.backend_info.AAModes.push_back(samples);
|
2010-11-23 19:58:02 +00:00
|
|
|
}
|
2014-11-14 11:39:25 +00:00
|
|
|
|
2014-12-05 21:51:23 +00:00
|
|
|
bool shader_model_5_supported = (DX11::D3D::GetFeatureLevel(ad) >= D3D_FEATURE_LEVEL_11_0);
|
2014-11-14 11:39:25 +00:00
|
|
|
|
2013-07-22 12:38:09 +00:00
|
|
|
// Requires the earlydepthstencil attribute (only available in shader model 5)
|
2014-12-05 21:51:23 +00:00
|
|
|
g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported;
|
2014-11-14 11:39:25 +00:00
|
|
|
|
2014-12-05 21:51:23 +00:00
|
|
|
// Requires full UAV functionality (only available in shader model 5)
|
|
|
|
g_Config.backend_info.bSupportsBBox = shader_model_5_supported;
|
2014-11-14 11:39:25 +00:00
|
|
|
|
|
|
|
// Requires the instance attribute (only available in shader model 5)
|
|
|
|
g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported;
|
2010-11-23 19:58:02 +00:00
|
|
|
}
|
2013-02-28 00:01:48 +00:00
|
|
|
g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description));
|
2010-11-21 14:47:28 +00:00
|
|
|
ad->Release();
|
2010-11-15 09:54:07 +00:00
|
|
|
}
|
2010-11-22 22:17:35 +00:00
|
|
|
factory->Release();
|
2010-11-21 14:47:28 +00:00
|
|
|
|
2011-02-05 02:13:33 +00:00
|
|
|
// Clear ppshaders string vector
|
|
|
|
g_Config.backend_info.PPShaders.clear();
|
2015-01-03 00:33:30 +00:00
|
|
|
g_Config.backend_info.AnaglyphShaders.clear();
|
2011-02-05 02:13:33 +00:00
|
|
|
|
2011-01-29 20:16:51 +00:00
|
|
|
DX11::D3D::UnloadDXGI();
|
|
|
|
DX11::D3D::UnloadD3D();
|
2011-05-31 20:16:59 +00:00
|
|
|
}
|
|
|
|
|
2014-08-04 00:07:27 +00:00
|
|
|
void VideoBackend::ShowConfig(void *hParent)
|
2011-05-31 20:16:59 +00:00
|
|
|
{
|
|
|
|
InitBackendInfo();
|
2014-08-04 00:07:27 +00:00
|
|
|
Host_ShowVideoConfig(hParent, GetDisplayName(), "gfx_dx11");
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2014-08-06 04:44:21 +00:00
|
|
|
bool VideoBackend::Initialize(void *window_handle)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2014-06-14 22:23:43 +00:00
|
|
|
if (window_handle == nullptr)
|
|
|
|
return false;
|
|
|
|
|
2012-01-02 10:20:22 +00:00
|
|
|
InitializeShared();
|
2010-11-22 22:17:35 +00:00
|
|
|
InitBackendInfo();
|
|
|
|
|
2010-06-13 19:50:06 +00:00
|
|
|
frameCount = 0;
|
|
|
|
|
2014-03-12 19:33:41 +00:00
|
|
|
g_Config.Load(File::GetUserPath(D_CONFIG_IDX) + "gfx_dx11.ini");
|
2013-09-23 06:39:14 +00:00
|
|
|
g_Config.GameIniLoad();
|
2011-05-31 20:16:59 +00:00
|
|
|
g_Config.UpdateProjectionHack();
|
|
|
|
g_Config.VerifyValidity();
|
2010-06-13 19:50:06 +00:00
|
|
|
UpdateActiveConfig();
|
|
|
|
|
2014-06-14 22:23:43 +00:00
|
|
|
m_window_handle = window_handle;
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2011-02-14 02:18:03 +00:00
|
|
|
s_BackendInitialized = true;
|
2011-02-25 21:14:13 +00:00
|
|
|
|
2011-03-02 15:13:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::Video_Prepare()
|
|
|
|
{
|
2010-07-18 10:11:34 +00:00
|
|
|
// internal interfaces
|
2014-06-14 22:23:43 +00:00
|
|
|
g_renderer = new Renderer(m_window_handle);
|
2011-01-31 01:28:32 +00:00
|
|
|
g_texture_cache = new TextureCache;
|
|
|
|
g_vertex_manager = new VertexManager;
|
2013-03-01 18:30:37 +00:00
|
|
|
g_perf_query = new PerfQuery;
|
2011-01-31 01:28:32 +00:00
|
|
|
VertexShaderCache::Init();
|
|
|
|
PixelShaderCache::Init();
|
2014-12-03 21:17:56 +00:00
|
|
|
GeometryShaderCache::Init();
|
2011-01-31 01:28:32 +00:00
|
|
|
D3D::InitUtils();
|
2010-07-18 10:11:34 +00:00
|
|
|
|
|
|
|
// VideoCommon
|
|
|
|
BPInit();
|
2010-06-13 19:50:06 +00:00
|
|
|
Fifo_Init();
|
2013-04-08 17:39:43 +00:00
|
|
|
IndexGenerator::Init();
|
2010-06-13 19:50:06 +00:00
|
|
|
VertexLoaderManager::Init();
|
|
|
|
OpcodeDecoder_Init();
|
|
|
|
VertexShaderManager::Init();
|
|
|
|
PixelShaderManager::Init();
|
2014-12-14 20:23:13 +00:00
|
|
|
GeometryShaderManager::Init();
|
2010-07-06 13:14:51 +00:00
|
|
|
CommandProcessor::Init();
|
|
|
|
PixelEngine::Init();
|
2014-12-05 02:01:20 +00:00
|
|
|
BBox::Init();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2010-09-28 02:15:02 +00:00
|
|
|
// Tell the host that the window is ready
|
2011-03-15 23:09:12 +00:00
|
|
|
Host_Message(WM_USER_CREATE);
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
void VideoBackend::Shutdown()
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2011-02-14 02:18:03 +00:00
|
|
|
s_BackendInitialized = false;
|
2010-09-28 02:15:02 +00:00
|
|
|
|
2013-02-26 15:42:32 +00:00
|
|
|
// TODO: should be in Video_Cleanup
|
2011-03-02 15:13:13 +00:00
|
|
|
if (g_renderer)
|
|
|
|
{
|
|
|
|
// VideoCommon
|
|
|
|
Fifo_Shutdown();
|
|
|
|
CommandProcessor::Shutdown();
|
2014-12-14 20:23:13 +00:00
|
|
|
GeometryShaderManager::Shutdown();
|
2011-03-02 15:13:13 +00:00
|
|
|
PixelShaderManager::Shutdown();
|
|
|
|
VertexShaderManager::Shutdown();
|
|
|
|
OpcodeDecoder_Shutdown();
|
|
|
|
VertexLoaderManager::Shutdown();
|
|
|
|
|
|
|
|
// internal interfaces
|
|
|
|
D3D::ShutdownUtils();
|
|
|
|
PixelShaderCache::Shutdown();
|
|
|
|
VertexShaderCache::Shutdown();
|
2014-12-03 21:17:56 +00:00
|
|
|
GeometryShaderCache::Shutdown();
|
2014-12-05 02:01:20 +00:00
|
|
|
BBox::Shutdown();
|
|
|
|
|
2013-03-01 18:30:37 +00:00
|
|
|
delete g_perf_query;
|
2011-03-02 15:13:13 +00:00
|
|
|
delete g_vertex_manager;
|
|
|
|
delete g_texture_cache;
|
|
|
|
delete g_renderer;
|
2014-03-09 20:14:26 +00:00
|
|
|
g_renderer = nullptr;
|
|
|
|
g_texture_cache = nullptr;
|
2011-03-02 15:13:13 +00:00
|
|
|
}
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
2011-01-31 01:28:32 +00:00
|
|
|
|
2014-08-30 20:54:18 +00:00
|
|
|
void VideoBackend::Video_Cleanup()
|
|
|
|
{
|
2013-02-26 15:42:32 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 01:28:32 +00:00
|
|
|
}
|