2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:29:41 -06:00
|
|
|
// Refer to the license.txt file included.
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2015-12-20 19:49:49 -07:00
|
|
|
#include <memory>
|
2014-03-12 13:33:41 -06:00
|
|
|
#include <string>
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2018-06-30 02:53:24 -06:00
|
|
|
#include "Common/Common.h"
|
2016-01-02 13:01:12 -07:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-03-03 23:40:08 -07:00
|
|
|
#include "Common/MsgHandler.h"
|
2014-03-12 13:33:41 -06:00
|
|
|
#include "Common/StringUtil.h"
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2014-12-04 19:01:20 -07:00
|
|
|
#include "VideoBackends/D3D/BoundingBox.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
|
|
|
#include "VideoBackends/D3D/D3DUtil.h"
|
2014-12-03 14:17:56 -07:00
|
|
|
#include "VideoBackends/D3D/GeometryShaderCache.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/D3D/PerfQuery.h"
|
|
|
|
#include "VideoBackends/D3D/PixelShaderCache.h"
|
2016-01-02 13:01:12 -07:00
|
|
|
#include "VideoBackends/D3D/Render.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/D3D/TextureCache.h"
|
|
|
|
#include "VideoBackends/D3D/VertexManager.h"
|
|
|
|
#include "VideoBackends/D3D/VertexShaderCache.h"
|
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
2011-01-25 09:43:08 -07:00
|
|
|
|
2018-02-24 08:15:35 -07:00
|
|
|
#include "VideoCommon/ShaderCache.h"
|
2016-07-21 17:04:57 -06:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
namespace DX11
|
2011-01-14 08:09:30 -07:00
|
|
|
{
|
2014-03-12 17:39:55 -06:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 07:51:43 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
return "D3D";
|
2013-05-01 07:51:43 -06:00
|
|
|
}
|
|
|
|
|
2014-03-12 17:39:55 -06:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2018-06-30 02:53:24 -06:00
|
|
|
return _trans("Direct3D 11");
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2016-01-13 13:38:11 -07:00
|
|
|
void VideoBackend::InitBackendInfo()
|
2010-11-22 15:17:35 -07:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
HRESULT hr = DX11::D3D::LoadDXGI();
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = DX11::D3D::LoadD3D();
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
DX11::D3D::UnloadDXGI();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-21 17:04:57 -06:00
|
|
|
g_Config.backend_info.api_type = APIType::D3D;
|
2017-03-10 06:40:52 -07:00
|
|
|
g_Config.backend_info.MaxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
2016-06-24 02:43:46 -06:00
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
|
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = false;
|
|
|
|
g_Config.backend_info.bSupportsGeometryShaders = true;
|
2016-11-27 01:14:55 -07:00
|
|
|
g_Config.backend_info.bSupportsComputeShaders = false;
|
2016-06-24 02:43:46 -06:00
|
|
|
g_Config.backend_info.bSupports3DVision = true;
|
|
|
|
g_Config.backend_info.bSupportsPostProcessing = false;
|
|
|
|
g_Config.backend_info.bSupportsPaletteConversion = true;
|
|
|
|
g_Config.backend_info.bSupportsClipControl = true;
|
2016-08-05 14:31:34 -06:00
|
|
|
g_Config.backend_info.bSupportsDepthClamp = true;
|
2016-08-21 09:47:24 -06:00
|
|
|
g_Config.backend_info.bSupportsReversedDepthRange = false;
|
2018-05-25 08:04:18 -06:00
|
|
|
g_Config.backend_info.bSupportsLogicOp = true;
|
2016-08-13 06:08:46 -06:00
|
|
|
g_Config.backend_info.bSupportsMultithreading = false;
|
2016-11-27 01:14:57 -07:00
|
|
|
g_Config.backend_info.bSupportsGPUTextureDecoding = false;
|
2017-04-16 03:30:11 -06:00
|
|
|
g_Config.backend_info.bSupportsST3CTextures = false;
|
2017-05-29 16:02:09 -06:00
|
|
|
g_Config.backend_info.bSupportsCopyToVram = true;
|
2017-07-19 23:25:24 -06:00
|
|
|
g_Config.backend_info.bSupportsBitfield = false;
|
|
|
|
g_Config.backend_info.bSupportsDynamicSamplerIndexing = false;
|
2017-07-27 06:00:04 -06:00
|
|
|
g_Config.backend_info.bSupportsBPTCTextures = false;
|
2017-10-25 23:44:39 -06:00
|
|
|
g_Config.backend_info.bSupportsFramebufferFetch = false;
|
2018-02-25 00:56:09 -07:00
|
|
|
g_Config.backend_info.bSupportsBackgroundCompiling = true;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2017-09-03 05:55:07 -06:00
|
|
|
IDXGIFactory2* factory;
|
2016-06-24 02:43:46 -06:00
|
|
|
IDXGIAdapter* ad;
|
2017-09-03 05:55:07 -06:00
|
|
|
hr = DX11::PCreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)&factory);
|
2016-06-24 02:43:46 -06:00
|
|
|
if (FAILED(hr))
|
|
|
|
PanicAlert("Failed to create IDXGIFactory object");
|
|
|
|
|
|
|
|
// adapters
|
|
|
|
g_Config.backend_info.Adapters.clear();
|
|
|
|
g_Config.backend_info.AAModes.clear();
|
|
|
|
while (factory->EnumAdapters((UINT)g_Config.backend_info.Adapters.size(), &ad) !=
|
|
|
|
DXGI_ERROR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
const size_t adapter_index = g_Config.backend_info.Adapters.size();
|
|
|
|
|
|
|
|
DXGI_ADAPTER_DESC desc;
|
|
|
|
ad->GetDesc(&desc);
|
|
|
|
|
|
|
|
// TODO: These don't get updated on adapter change, yet
|
|
|
|
if (adapter_index == g_Config.iAdapter)
|
|
|
|
{
|
|
|
|
std::vector<DXGI_SAMPLE_DESC> modes = DX11::D3D::EnumAAModes(ad);
|
|
|
|
// First iteration will be 1. This equals no AA.
|
|
|
|
for (unsigned int i = 0; i < modes.size(); ++i)
|
|
|
|
{
|
|
|
|
g_Config.backend_info.AAModes.push_back(modes[i].Count);
|
|
|
|
}
|
|
|
|
|
2017-03-10 06:40:52 -07:00
|
|
|
D3D_FEATURE_LEVEL feature_level = D3D::GetFeatureLevel(ad);
|
|
|
|
bool shader_model_5_supported = feature_level >= D3D_FEATURE_LEVEL_11_0;
|
|
|
|
g_Config.backend_info.MaxTextureSize = D3D::GetMaxTextureSize(feature_level);
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Requires the earlydepthstencil attribute (only available in shader model 5)
|
|
|
|
g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported;
|
|
|
|
|
|
|
|
// Requires full UAV functionality (only available in shader model 5)
|
2017-03-05 16:17:54 -07:00
|
|
|
g_Config.backend_info.bSupportsBBox =
|
|
|
|
g_Config.backend_info.bSupportsFragmentStoresAndAtomics = shader_model_5_supported;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
|
|
|
// Requires the instance attribute (only available in shader model 5)
|
|
|
|
g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported;
|
|
|
|
|
|
|
|
// Sample shading requires shader model 5
|
|
|
|
g_Config.backend_info.bSupportsSSAA = shader_model_5_supported;
|
|
|
|
}
|
|
|
|
g_Config.backend_info.Adapters.push_back(UTF16ToUTF8(desc.Description));
|
|
|
|
ad->Release();
|
|
|
|
}
|
|
|
|
factory->Release();
|
|
|
|
|
|
|
|
DX11::D3D::UnloadDXGI();
|
|
|
|
DX11::D3D::UnloadD3D();
|
2011-05-31 14:16:59 -06:00
|
|
|
}
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
bool VideoBackend::Initialize(void* window_handle)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2016-06-24 02:43:46 -06:00
|
|
|
if (window_handle == nullptr)
|
|
|
|
return false;
|
2014-06-14 16:23:43 -06:00
|
|
|
|
2016-01-13 13:14:20 -07:00
|
|
|
InitializeShared();
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2018-01-25 22:09:07 -07:00
|
|
|
if (FAILED(D3D::Create(reinterpret_cast<HWND>(window_handle))))
|
|
|
|
{
|
2017-03-03 23:40:08 -07:00
|
|
|
PanicAlert("Failed to create D3D device.");
|
2018-01-25 22:09:07 -07:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-03 23:40:08 -07:00
|
|
|
|
2018-01-25 23:23:24 -07:00
|
|
|
int backbuffer_width = 1, backbuffer_height = 1;
|
|
|
|
if (D3D::swapchain)
|
|
|
|
{
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 desc = {};
|
|
|
|
D3D::swapchain->GetDesc1(&desc);
|
|
|
|
backbuffer_width = std::max(desc.Width, 1u);
|
|
|
|
backbuffer_height = std::max(desc.Height, 1u);
|
|
|
|
}
|
|
|
|
|
|
|
|
// internal interfaces
|
|
|
|
g_renderer = std::make_unique<Renderer>(backbuffer_width, backbuffer_height);
|
2018-02-24 08:15:35 -07:00
|
|
|
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
|
2016-06-24 02:43:46 -06:00
|
|
|
g_texture_cache = std::make_unique<TextureCache>();
|
|
|
|
g_vertex_manager = std::make_unique<VertexManager>();
|
|
|
|
g_perf_query = std::make_unique<PerfQuery>();
|
2018-01-25 22:09:07 -07:00
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
VertexShaderCache::Init();
|
|
|
|
PixelShaderCache::Init();
|
|
|
|
GeometryShaderCache::Init();
|
2018-02-24 08:15:35 -07:00
|
|
|
if (!g_shader_cache->Initialize())
|
|
|
|
return false;
|
|
|
|
|
2016-06-24 02:43:46 -06:00
|
|
|
D3D::InitUtils();
|
2016-06-27 04:45:00 -06:00
|
|
|
BBox::Init();
|
2018-01-25 22:09:07 -07:00
|
|
|
return true;
|
2010-06-13 13:50:06 -06:00
|
|
|
}
|
|
|
|
|
2011-01-30 18:28:32 -07:00
|
|
|
void VideoBackend::Shutdown()
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2018-02-24 08:15:35 -07:00
|
|
|
g_shader_cache->Shutdown();
|
2018-01-25 22:09:07 -07:00
|
|
|
g_renderer->Shutdown();
|
|
|
|
|
2016-01-13 13:14:20 -07:00
|
|
|
D3D::ShutdownUtils();
|
|
|
|
PixelShaderCache::Shutdown();
|
|
|
|
VertexShaderCache::Shutdown();
|
|
|
|
GeometryShaderCache::Shutdown();
|
|
|
|
BBox::Shutdown();
|
|
|
|
|
|
|
|
g_perf_query.reset();
|
|
|
|
g_vertex_manager.reset();
|
|
|
|
g_texture_cache.reset();
|
2018-02-24 08:15:35 -07:00
|
|
|
g_shader_cache.reset();
|
2016-01-13 13:14:20 -07:00
|
|
|
g_renderer.reset();
|
|
|
|
|
|
|
|
ShutdownShared();
|
2011-01-30 18:28:32 -07:00
|
|
|
|
2018-01-25 22:09:07 -07:00
|
|
|
D3D::Close();
|
2013-02-26 08:42:32 -07:00
|
|
|
}
|
2011-01-30 18:28:32 -07:00
|
|
|
}
|