Debian Codegraph @

Source/Core/VideoBackends/D3D/D3DMain.cpp

raw symbols SCIP
1 // Copyright 2008 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoBackends/D3D/VideoBackend.h"
5
6 #include <memory>
7 #include <string>
8
9 #include "Common/Common.h"
10 #include "Common/CommonTypes.h"
11 #include "Common/MsgHandler.h"
12 #include "Common/StringUtil.h"
13
14 #include "VideoBackends/D3D/D3DBase.h"
15 #include "VideoBackends/D3D/D3DBoundingBox.h"
16 #include "VideoBackends/D3D/D3DGfx.h"
17 #include "VideoBackends/D3D/D3DPerfQuery.h"
18 #include "VideoBackends/D3D/D3DSwapChain.h"
19 #include "VideoBackends/D3D/D3DVertexManager.h"
20 #include "VideoBackends/D3DCommon/D3DCommon.h"
21
22 #include "VideoCommon/AbstractGfx.h"
23 #include "VideoCommon/FramebufferManager.h"
24 #include "VideoCommon/ShaderCache.h"
25 #include "VideoCommon/TextureCacheBase.h"
26 #include "VideoCommon/VideoCommon.h"
27 #include "VideoCommon/VideoConfig.h"
28
29 namespace DX11
30 {
31 std::string VideoBackend::GetConfigName() const
32 {
33 return CONFIG_NAME;
34 }
35
36 std::string VideoBackend::GetDisplayName() const
37 {
38 return _trans("Direct3D 11");
39 }
40
41 std::optional<std::string> VideoBackend::GetWarningMessage() const
42 {
43 std::optional<std::string> result;
44
45 // If relevant, show a warning about partial DX11.1 support
46 // This is being called BEFORE FillBackendInfo is called for this backend,
47 // so query for logic op support manually
48 bool supportsLogicOp = false;
49 if (D3DCommon::LoadLibraries())
50 {
51 supportsLogicOp = D3D::SupportsLogicOp(g_Config.iAdapter);
52 D3DCommon::UnloadLibraries();
53 }
54
55 if (!supportsLogicOp)
56 {
57 result = _trans("The Direct3D 11 renderer requires support for features not supported by your "
58 "system configuration. You may still use this backend, but you will encounter "
59 "graphical artifacts in certain games.\n"
60 "\n"
61 "Do you really want to switch to Direct3D 11? If unsure, select 'No'.");
62 }
63
64 return result;
65 }
66
67 void VideoBackend::InitBackendInfo(const WindowSystemInfo& wsi)
68 {
69 if (!D3DCommon::LoadLibraries())
70 return;
71
72 FillBackendInfo();
73 D3DCommon::UnloadLibraries();
74 }
75
76 void VideoBackend::FillBackendInfo()
77 {
78 g_backend_info.api_type = APIType::D3D;
79 g_backend_info.MaxTextureSize = D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION;
80 g_backend_info.bUsesLowerLeftOrigin = false;
81 g_backend_info.bSupportsExclusiveFullscreen = true;
82 g_backend_info.bSupportsDualSourceBlend = true;
83 g_backend_info.bSupportsPrimitiveRestart = true;
84 g_backend_info.bSupportsGeometryShaders = true;
85 g_backend_info.bSupportsComputeShaders = false;
86 g_backend_info.bSupports3DVision = true;
87 g_backend_info.bSupportsPostProcessing = true;
88 g_backend_info.bSupportsPaletteConversion = true;
89 g_backend_info.bSupportsClipControl = true;
90 g_backend_info.bSupportsDepthClamp = true;
91 g_backend_info.bSupportsReversedDepthRange = false;
92 g_backend_info.bSupportsMultithreading = false;
93 g_backend_info.bSupportsGPUTextureDecoding = true;
94 g_backend_info.bSupportsCopyToVram = true;
95 g_backend_info.bSupportsLargePoints = false;
96 g_backend_info.bSupportsDepthReadback = true;
97 g_backend_info.bSupportsPartialDepthCopies = false;
98 g_backend_info.bSupportsBitfield = false;
99 g_backend_info.bSupportsDynamicSamplerIndexing = false;
100 g_backend_info.bSupportsFramebufferFetch = false;
101 g_backend_info.bSupportsBackgroundCompiling = true;
102 g_backend_info.bSupportsST3CTextures = true;
103 g_backend_info.bSupportsBPTCTextures = true;
104 g_backend_info.bSupportsEarlyZ = true;
105 g_backend_info.bSupportsBBox = true;
106 g_backend_info.bSupportsFragmentStoresAndAtomics = true;
107 g_backend_info.bSupportsGSInstancing = true;
108 g_backend_info.bSupportsSSAA = true;
109 g_backend_info.bSupportsShaderBinaries = true;
110 g_backend_info.bSupportsPipelineCacheData = false;
111 g_backend_info.bSupportsCoarseDerivatives = true;
112 g_backend_info.bSupportsTextureQueryLevels = true;
113 g_backend_info.bSupportsLodBiasInSampler = true;
114 g_backend_info.bSupportsLogicOp = D3D::SupportsLogicOp(g_Config.iAdapter);
115 g_backend_info.bSupportsSettingObjectNames = true;
116 g_backend_info.bSupportsPartialMultisampleResolve = true;
117 g_backend_info.bSupportsDynamicVertexLoader = false;
118 g_backend_info.bSupportsHDROutput = true;
119
120 g_backend_info.Adapters = D3DCommon::GetAdapterNames();
121 g_backend_info.AAModes = D3D::GetAAModes(g_Config.iAdapter);
122
123 // Override optional features if we are actually booting.
124 if (D3D::device)
125 {
126 g_backend_info.bSupportsST3CTextures = D3D::SupportsTextureFormat(DXGI_FORMAT_BC1_UNORM) &&
127 D3D::SupportsTextureFormat(DXGI_FORMAT_BC2_UNORM) &&
128 D3D::SupportsTextureFormat(DXGI_FORMAT_BC3_UNORM);
129 g_backend_info.bSupportsBPTCTextures = D3D::SupportsTextureFormat(DXGI_FORMAT_BC7_UNORM);
130
131 // Features only supported with a FL11.0+ device.
132 const bool shader_model_5_supported = D3D::feature_level >= D3D_FEATURE_LEVEL_11_0;
133 g_backend_info.bSupportsEarlyZ = shader_model_5_supported;
134 g_backend_info.bSupportsBBox = shader_model_5_supported;
135 g_backend_info.bSupportsFragmentStoresAndAtomics = shader_model_5_supported;
136 g_backend_info.bSupportsGSInstancing = shader_model_5_supported;
137 g_backend_info.bSupportsSSAA = shader_model_5_supported;
138 g_backend_info.bSupportsGPUTextureDecoding = shader_model_5_supported;
139 }
140 }
141
142 bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
143 {
144 if (!D3D::Create(g_Config.iAdapter, g_Config.bEnableValidationLayer))
145 return false;
146
147 FillBackendInfo();
148 UpdateActiveConfig();
149
150 std::unique_ptr<SwapChain> swap_chain;
151 if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
152 {
153 PanicAlertFmtT("Failed to create D3D swap chain");
154 ShutdownShared();
155 D3D::Destroy();
156 return false;
157 }
158
159 auto gfx = std::make_unique<DX11::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
160 auto vertex_manager = std::make_unique<VertexManager>();
161 auto perf_query = std::make_unique<PerfQuery>();
162 auto bounding_box = std::make_unique<D3DBoundingBox>();
163
164 return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
165 std::move(bounding_box));
166 }
167
168 void VideoBackend::Shutdown()
169 {
170 ShutdownShared();
171 D3D::Destroy();
172 }
173 } // namespace DX11