2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2015-12-20 21:49:49 -05:00
|
|
|
#include <memory>
|
2014-03-12 15:33:41 -04:00
|
|
|
#include <string>
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2018-06-30 04:53:24 -04:00
|
|
|
#include "Common/Common.h"
|
2016-01-02 15:01:12 -05:00
|
|
|
#include "Common/CommonTypes.h"
|
2017-03-04 16:40:08 +10:00
|
|
|
#include "Common/MsgHandler.h"
|
2014-03-12 15:33:41 -04:00
|
|
|
#include "Common/StringUtil.h"
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
2020-09-15 05:50:34 -07:00
|
|
|
#include "VideoBackends/D3D/D3DBoundingBox.h"
|
|
|
|
#include "VideoBackends/D3D/D3DPerfQuery.h"
|
|
|
|
#include "VideoBackends/D3D/D3DRender.h"
|
|
|
|
#include "VideoBackends/D3D/D3DSwapChain.h"
|
|
|
|
#include "VideoBackends/D3D/D3DVertexManager.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
2020-09-15 06:07:22 -07:00
|
|
|
#include "VideoBackends/D3DCommon/D3DCommon.h"
|
2011-01-25 16:43:08 +00:00
|
|
|
|
2019-02-15 11:59:50 +10:00
|
|
|
#include "VideoCommon/FramebufferManager.h"
|
2018-02-25 01:15:35 +10:00
|
|
|
#include "VideoCommon/ShaderCache.h"
|
2019-02-15 11:59:50 +10:00
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
2016-07-21 19:04:57 -04:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2014-02-17 05:18:15 -05:00
|
|
|
#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
|
|
|
{
|
2014-03-13 00:39:55 +01:00
|
|
|
std::string VideoBackend::GetName() const
|
2013-05-01 23:51:43 +10:00
|
|
|
{
|
2020-09-06 12:56:45 +02:00
|
|
|
return NAME;
|
2013-05-01 23:51:43 +10:00
|
|
|
}
|
|
|
|
|
2014-03-13 00:39:55 +01:00
|
|
|
std::string VideoBackend::GetDisplayName() const
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2018-06-30 04:53:24 -04:00
|
|
|
return _trans("Direct3D 11");
|
2010-06-13 19:50:06 +00:00
|
|
|
}
|
|
|
|
|
2019-07-21 17:29:08 +02:00
|
|
|
std::optional<std::string> VideoBackend::GetWarningMessage() const
|
|
|
|
{
|
|
|
|
std::optional<std::string> result;
|
|
|
|
|
|
|
|
// If user is on Win7, show a warning about partial DX11.1 support
|
|
|
|
// This is being called BEFORE FillBackendInfo is called for this backend,
|
|
|
|
// so query for logic op support manually
|
|
|
|
bool supportsLogicOp = false;
|
|
|
|
if (D3DCommon::LoadLibraries())
|
|
|
|
{
|
|
|
|
supportsLogicOp = D3D::SupportsLogicOp(g_Config.iAdapter);
|
|
|
|
D3DCommon::UnloadLibraries();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!supportsLogicOp)
|
|
|
|
{
|
|
|
|
result = _trans("Direct3D 11 renderer requires support for features not supported by your "
|
|
|
|
"system configuration. This is most likely because you are using Windows 7. "
|
|
|
|
"You may still use this backend, but you might encounter graphical artifacts."
|
|
|
|
"\n\nDo you really want to switch to Direct3D 11? If unsure, select 'No'.");
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-01-13 21:38:11 +01:00
|
|
|
void VideoBackend::InitBackendInfo()
|
2010-11-22 22:17:35 +00:00
|
|
|
{
|
2019-03-09 23:31:36 +10:00
|
|
|
if (!D3DCommon::LoadLibraries())
|
2010-11-23 19:58:02 +00:00
|
|
|
return;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2019-03-09 23:31:36 +10:00
|
|
|
FillBackendInfo();
|
|
|
|
D3DCommon::UnloadLibraries();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::FillBackendInfo()
|
|
|
|
{
|
2016-07-21 19:04:57 -04:00
|
|
|
g_Config.backend_info.api_type = APIType::D3D;
|
2017-03-10 23:40:52 +10:00
|
|
|
g_Config.backend_info.MaxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
|
2019-02-15 11:59:50 +10:00
|
|
|
g_Config.backend_info.bUsesLowerLeftOrigin = false;
|
2014-07-19 20:18:03 +02:00
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
|
2011-05-31 20:16:59 +00:00
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
2013-04-08 16:34:47 +02:00
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
2014-12-05 23:54:34 -03:00
|
|
|
g_Config.backend_info.bSupportsOversizedViewports = false;
|
2014-12-17 00:26:03 +01:00
|
|
|
g_Config.backend_info.bSupportsGeometryShaders = true;
|
2016-11-27 18:14:55 +10:00
|
|
|
g_Config.backend_info.bSupportsComputeShaders = false;
|
2014-11-14 00:24:53 +01:00
|
|
|
g_Config.backend_info.bSupports3DVision = true;
|
2019-02-15 11:59:50 +10:00
|
|
|
g_Config.backend_info.bSupportsPostProcessing = true;
|
2015-01-26 15:33:23 -08:00
|
|
|
g_Config.backend_info.bSupportsPaletteConversion = true;
|
2015-06-24 23:16:53 +02:00
|
|
|
g_Config.backend_info.bSupportsClipControl = true;
|
2016-08-05 22:31:34 +02:00
|
|
|
g_Config.backend_info.bSupportsDepthClamp = true;
|
2016-08-21 17:47:24 +02:00
|
|
|
g_Config.backend_info.bSupportsReversedDepthRange = false;
|
2016-08-13 22:08:46 +10:00
|
|
|
g_Config.backend_info.bSupportsMultithreading = false;
|
2019-02-15 11:59:50 +10:00
|
|
|
g_Config.backend_info.bSupportsGPUTextureDecoding = true;
|
2017-05-29 17:02:09 -05:00
|
|
|
g_Config.backend_info.bSupportsCopyToVram = true;
|
2019-02-15 11:59:50 +10:00
|
|
|
g_Config.backend_info.bSupportsLargePoints = false;
|
2020-05-24 16:11:10 +10:00
|
|
|
g_Config.backend_info.bSupportsDepthReadback = true;
|
2019-03-02 15:03:49 +10:00
|
|
|
g_Config.backend_info.bSupportsPartialDepthCopies = false;
|
2017-07-20 15:25:24 +10:00
|
|
|
g_Config.backend_info.bSupportsBitfield = false;
|
|
|
|
g_Config.backend_info.bSupportsDynamicSamplerIndexing = false;
|
2017-10-25 22:44:39 -07:00
|
|
|
g_Config.backend_info.bSupportsFramebufferFetch = false;
|
2018-02-25 17:56:09 +10:00
|
|
|
g_Config.backend_info.bSupportsBackgroundCompiling = true;
|
2019-03-09 23:31:36 +10:00
|
|
|
g_Config.backend_info.bSupportsST3CTextures = true;
|
|
|
|
g_Config.backend_info.bSupportsBPTCTextures = true;
|
|
|
|
g_Config.backend_info.bSupportsEarlyZ = true;
|
|
|
|
g_Config.backend_info.bSupportsBBox = true;
|
|
|
|
g_Config.backend_info.bSupportsFragmentStoresAndAtomics = true;
|
|
|
|
g_Config.backend_info.bSupportsGSInstancing = true;
|
|
|
|
g_Config.backend_info.bSupportsSSAA = true;
|
2019-04-15 21:55:26 +10:00
|
|
|
g_Config.backend_info.bSupportsShaderBinaries = true;
|
|
|
|
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
2021-11-13 20:10:20 -08:00
|
|
|
g_Config.backend_info.bSupportsCoarseDerivatives = true;
|
2021-11-13 20:10:55 -08:00
|
|
|
g_Config.backend_info.bSupportsTextureQueryLevels = true;
|
2019-07-21 17:10:51 +02:00
|
|
|
g_Config.backend_info.bSupportsLogicOp = D3D::SupportsLogicOp(g_Config.iAdapter);
|
2019-03-09 23:31:36 +10:00
|
|
|
|
|
|
|
g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
|
|
|
|
g_Config.backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter);
|
2019-04-28 15:26:46 +10:00
|
|
|
|
|
|
|
// Override optional features if we are actually booting.
|
|
|
|
if (D3D::device)
|
|
|
|
{
|
|
|
|
g_Config.backend_info.bSupportsST3CTextures =
|
|
|
|
D3D::SupportsTextureFormat(DXGI_FORMAT_BC1_UNORM) &&
|
|
|
|
D3D::SupportsTextureFormat(DXGI_FORMAT_BC2_UNORM) &&
|
|
|
|
D3D::SupportsTextureFormat(DXGI_FORMAT_BC3_UNORM);
|
|
|
|
g_Config.backend_info.bSupportsBPTCTextures = D3D::SupportsTextureFormat(DXGI_FORMAT_BC7_UNORM);
|
|
|
|
|
|
|
|
// Features only supported with a FL11.0+ device.
|
|
|
|
const bool shader_model_5_supported = D3D::feature_level >= D3D_FEATURE_LEVEL_11_0;
|
|
|
|
g_Config.backend_info.bSupportsEarlyZ = shader_model_5_supported;
|
|
|
|
g_Config.backend_info.bSupportsBBox = shader_model_5_supported;
|
|
|
|
g_Config.backend_info.bSupportsFragmentStoresAndAtomics = shader_model_5_supported;
|
|
|
|
g_Config.backend_info.bSupportsGSInstancing = shader_model_5_supported;
|
|
|
|
g_Config.backend_info.bSupportsSSAA = shader_model_5_supported;
|
|
|
|
g_Config.backend_info.bSupportsGPUTextureDecoding = shader_model_5_supported;
|
|
|
|
}
|
2011-05-31 20:16:59 +00:00
|
|
|
}
|
|
|
|
|
2018-10-03 23:03:22 +10:00
|
|
|
bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
|
2010-06-13 19:50:06 +00:00
|
|
|
{
|
2019-03-09 23:31:36 +10:00
|
|
|
if (!D3D::Create(g_Config.iAdapter, g_Config.bEnableValidationLayer))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FillBackendInfo();
|
2016-01-13 21:14:20 +01:00
|
|
|
InitializeShared();
|
2010-06-13 19:50:06 +00:00
|
|
|
|
2019-03-09 23:31:36 +10:00
|
|
|
std::unique_ptr<SwapChain> swap_chain;
|
|
|
|
if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
|
2018-01-26 15:09:07 +10:00
|
|
|
{
|
2020-12-02 13:17:27 -05:00
|
|
|
PanicAlertFmtT("Failed to create D3D swap chain");
|
2019-03-09 23:31:36 +10:00
|
|
|
ShutdownShared();
|
|
|
|
D3D::Destroy();
|
2018-01-26 15:09:07 +10:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-04 16:40:08 +10:00
|
|
|
|
2019-03-09 23:31:36 +10:00
|
|
|
g_renderer = std::make_unique<Renderer>(std::move(swap_chain), wsi.render_surface_scale);
|
2015-12-20 21:49:49 -05:00
|
|
|
g_vertex_manager = std::make_unique<VertexManager>();
|
2019-02-15 11:59:50 +10:00
|
|
|
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
|
|
|
|
g_framebuffer_manager = std::make_unique<FramebufferManager>();
|
|
|
|
g_texture_cache = std::make_unique<TextureCacheBase>();
|
2015-12-20 21:49:49 -05:00
|
|
|
g_perf_query = std::make_unique<PerfQuery>();
|
2019-10-02 11:50:09 +10:00
|
|
|
if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
|
|
|
|
!g_renderer->Initialize() || !g_framebuffer_manager->Initialize() ||
|
2019-02-15 11:59:50 +10:00
|
|
|
!g_texture_cache->Initialize())
|
|
|
|
{
|
2019-03-09 23:31:36 +10:00
|
|
|
Shutdown();
|
2018-02-25 01:15:35 +10:00
|
|
|
return false;
|
2019-02-15 11:59:50 +10:00
|
|
|
}
|
2018-02-25 01:15:35 +10:00
|
|
|
|
2019-02-15 11:59:50 +10:00
|
|
|
g_shader_cache->InitializeShaderCache();
|
2018-11-28 14:30:47 +10:00
|
|
|
return true;
|
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
|
|
|
{
|
2018-02-25 01:15:35 +10:00
|
|
|
g_shader_cache->Shutdown();
|
2018-01-26 15:09:07 +10:00
|
|
|
g_renderer->Shutdown();
|
|
|
|
|
2016-01-13 21:14:20 +01:00
|
|
|
g_perf_query.reset();
|
|
|
|
g_texture_cache.reset();
|
2019-02-15 11:59:50 +10:00
|
|
|
g_framebuffer_manager.reset();
|
2018-02-25 01:15:35 +10:00
|
|
|
g_shader_cache.reset();
|
2019-02-15 11:59:50 +10:00
|
|
|
g_vertex_manager.reset();
|
2016-01-13 21:14:20 +01:00
|
|
|
g_renderer.reset();
|
|
|
|
|
|
|
|
ShutdownShared();
|
2019-03-09 23:31:36 +10:00
|
|
|
D3D::Destroy();
|
2013-02-26 16:42:32 +01:00
|
|
|
}
|
2018-10-03 23:03:13 +10:00
|
|
|
} // namespace DX11
|