2015-05-23 22:55:12 -06:00
|
|
|
// Copyright 2008 Dolphin Emulator Project
|
2021-07-04 19:22:19 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2021-12-09 19:22:16 -07:00
|
|
|
#include "VideoBackends/D3D/VideoBackend.h"
|
|
|
|
|
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-02-17 03:18:15 -07:00
|
|
|
#include "VideoBackends/D3D/D3DBase.h"
|
2020-09-15 06:50:34 -06:00
|
|
|
#include "VideoBackends/D3D/D3DBoundingBox.h"
|
2023-01-29 03:58:32 -07:00
|
|
|
#include "VideoBackends/D3D/D3DGfx.h"
|
2023-01-30 21:29:16 -07:00
|
|
|
#include "VideoBackends/D3D/D3DPerfQuery.h"
|
2020-09-15 06:50:34 -06:00
|
|
|
#include "VideoBackends/D3D/D3DSwapChain.h"
|
|
|
|
#include "VideoBackends/D3D/D3DVertexManager.h"
|
2020-09-15 07:07:22 -06:00
|
|
|
#include "VideoBackends/D3DCommon/D3DCommon.h"
|
2011-01-25 09:43:08 -07:00
|
|
|
|
2023-01-29 03:58:32 -07:00
|
|
|
#include "VideoCommon/AbstractGfx.h"
|
2019-02-14 18:59:50 -07:00
|
|
|
#include "VideoCommon/FramebufferManager.h"
|
2018-02-24 08:15:35 -07:00
|
|
|
#include "VideoCommon/ShaderCache.h"
|
2019-02-14 18:59:50 -07:00
|
|
|
#include "VideoCommon/TextureCacheBase.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
|
|
|
{
|
2020-09-06 04:56:45 -06:00
|
|
|
return NAME;
|
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
|
|
|
}
|
|
|
|
|
2019-07-21 09:29:08 -06:00
|
|
|
std::optional<std::string> VideoBackend::GetWarningMessage() const
|
|
|
|
{
|
|
|
|
std::optional<std::string> result;
|
|
|
|
|
2023-07-11 14:41:51 -06:00
|
|
|
// If relevant, show a warning about partial DX11.1 support
|
2019-07-21 09:29:08 -06:00
|
|
|
// 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)
|
|
|
|
{
|
2023-07-11 14:41:51 -06:00
|
|
|
result = _trans("The Direct3D 11 renderer requires support for features not supported by your "
|
|
|
|
"system configuration. You may still use this backend, but you will encounter "
|
|
|
|
"graphical artifacts in certain games.\n"
|
|
|
|
"\n"
|
|
|
|
"Do you really want to switch to Direct3D 11? If unsure, select 'No'.");
|
2019-07-21 09:29:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-25 18:16:53 -06:00
|
|
|
void VideoBackend::InitBackendInfo(const WindowSystemInfo& wsi)
|
2010-11-22 15:17:35 -07:00
|
|
|
{
|
2019-03-09 06:31:36 -07:00
|
|
|
if (!D3DCommon::LoadLibraries())
|
2010-11-23 12:58:02 -07:00
|
|
|
return;
|
2016-06-24 02:43:46 -06:00
|
|
|
|
2019-03-09 06:31:36 -07:00
|
|
|
FillBackendInfo();
|
|
|
|
D3DCommon::UnloadLibraries();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::FillBackendInfo()
|
|
|
|
{
|
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;
|
2019-02-14 18:59:50 -07:00
|
|
|
g_Config.backend_info.bUsesLowerLeftOrigin = false;
|
2014-07-19 12:18:03 -06:00
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
|
2011-05-31 14:16:59 -06:00
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
2013-04-08 08:34:47 -06:00
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
2014-12-16 16:26:03 -07:00
|
|
|
g_Config.backend_info.bSupportsGeometryShaders = true;
|
2016-11-27 01:14:55 -07:00
|
|
|
g_Config.backend_info.bSupportsComputeShaders = false;
|
2014-11-13 16:24:53 -07:00
|
|
|
g_Config.backend_info.bSupports3DVision = true;
|
2019-02-14 18:59:50 -07:00
|
|
|
g_Config.backend_info.bSupportsPostProcessing = true;
|
2015-01-26 16:33:23 -07:00
|
|
|
g_Config.backend_info.bSupportsPaletteConversion = true;
|
2015-06-24 15:16:53 -06:00
|
|
|
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;
|
2016-08-13 06:08:46 -06:00
|
|
|
g_Config.backend_info.bSupportsMultithreading = false;
|
2019-02-14 18:59:50 -07:00
|
|
|
g_Config.backend_info.bSupportsGPUTextureDecoding = true;
|
2017-05-29 16:02:09 -06:00
|
|
|
g_Config.backend_info.bSupportsCopyToVram = true;
|
2019-02-14 18:59:50 -07:00
|
|
|
g_Config.backend_info.bSupportsLargePoints = false;
|
2020-05-24 00:11:10 -06:00
|
|
|
g_Config.backend_info.bSupportsDepthReadback = true;
|
2019-03-01 22:03:49 -07:00
|
|
|
g_Config.backend_info.bSupportsPartialDepthCopies = false;
|
2017-07-19 23:25:24 -06:00
|
|
|
g_Config.backend_info.bSupportsBitfield = false;
|
|
|
|
g_Config.backend_info.bSupportsDynamicSamplerIndexing = 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;
|
2019-03-09 06:31:36 -07: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 05:55:26 -06:00
|
|
|
g_Config.backend_info.bSupportsShaderBinaries = true;
|
|
|
|
g_Config.backend_info.bSupportsPipelineCacheData = false;
|
2021-11-13 21:10:20 -07:00
|
|
|
g_Config.backend_info.bSupportsCoarseDerivatives = true;
|
2021-11-13 21:10:55 -07:00
|
|
|
g_Config.backend_info.bSupportsTextureQueryLevels = true;
|
2021-08-06 21:26:51 -06:00
|
|
|
g_Config.backend_info.bSupportsLodBiasInSampler = true;
|
2019-07-21 09:10:51 -06:00
|
|
|
g_Config.backend_info.bSupportsLogicOp = D3D::SupportsLogicOp(g_Config.iAdapter);
|
2022-01-30 20:18:59 -07:00
|
|
|
g_Config.backend_info.bSupportsSettingObjectNames = true;
|
2022-06-21 01:07:35 -06:00
|
|
|
g_Config.backend_info.bSupportsPartialMultisampleResolve = true;
|
2022-06-18 00:09:35 -06:00
|
|
|
g_Config.backend_info.bSupportsDynamicVertexLoader = false;
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 02:48:05 -06:00
|
|
|
g_Config.backend_info.bSupportsHDROutput = true;
|
2019-03-09 06:31:36 -07:00
|
|
|
|
|
|
|
g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
|
|
|
|
g_Config.backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter);
|
2019-04-27 23:26:46 -06: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 14:16:59 -06:00
|
|
|
}
|
|
|
|
|
2018-10-03 07:03:22 -06:00
|
|
|
bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
|
2010-06-13 13:50:06 -06:00
|
|
|
{
|
2019-03-09 06:31:36 -07:00
|
|
|
if (!D3D::Create(g_Config.iAdapter, g_Config.bEnableValidationLayer))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FillBackendInfo();
|
2023-01-29 03:58:32 -07:00
|
|
|
UpdateActiveConfig();
|
2010-06-13 13:50:06 -06:00
|
|
|
|
2019-03-09 06:31:36 -07:00
|
|
|
std::unique_ptr<SwapChain> swap_chain;
|
|
|
|
if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
|
2018-01-25 22:09:07 -07:00
|
|
|
{
|
2020-12-02 11:17:27 -07:00
|
|
|
PanicAlertFmtT("Failed to create D3D swap chain");
|
2019-03-09 06:31:36 -07:00
|
|
|
ShutdownShared();
|
|
|
|
D3D::Destroy();
|
2018-01-25 22:09:07 -07:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-03 23:40:08 -07:00
|
|
|
|
2023-01-29 03:58:32 -07:00
|
|
|
auto gfx = std::make_unique<DX11::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
|
|
|
|
auto vertex_manager = std::make_unique<VertexManager>();
|
|
|
|
auto perf_query = std::make_unique<PerfQuery>();
|
|
|
|
auto bounding_box = std::make_unique<D3DBoundingBox>();
|
2018-02-24 08:15:35 -07:00
|
|
|
|
2023-01-29 03:58:32 -07:00
|
|
|
return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
|
2023-01-30 21:29:16 -07:00
|
|
|
std::move(bounding_box));
|
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
|
|
|
{
|
2016-01-13 13:14:20 -07:00
|
|
|
ShutdownShared();
|
2019-03-09 06:31:36 -07:00
|
|
|
D3D::Destroy();
|
2013-02-26 08:42:32 -07:00
|
|
|
}
|
2018-10-03 07:03:13 -06:00
|
|
|
} // namespace DX11
|