Debian Codegraph @

Source/Core/VideoBackends/D3D12/VideoBackend.cpp

raw symbols SCIP
1 // Copyright 2016 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "VideoBackends/D3D12/VideoBackend.h"
5
6 #include <string>
7
8 #include "Common/CommonTypes.h"
9 #include "Common/StringUtil.h"
10
11 #include "Core/ConfigManager.h"
12
13 #include "VideoBackends/D3D12/Common.h"
14 #include "VideoBackends/D3D12/D3D12BoundingBox.h"
15 #include "VideoBackends/D3D12/D3D12Gfx.h"
16 #include "VideoBackends/D3D12/D3D12PerfQuery.h"
17 #include "VideoBackends/D3D12/D3D12SwapChain.h"
18 #include "VideoBackends/D3D12/D3D12VertexManager.h"
19 #include "VideoBackends/D3D12/DX12Context.h"
20
21 #include "VideoCommon/FramebufferManager.h"
22 #include "VideoCommon/ShaderCache.h"
23 #include "VideoCommon/TextureCacheBase.h"
24 #include "VideoCommon/VideoCommon.h"
25 #include "VideoCommon/VideoConfig.h"
26
27 namespace DX12
28 {
29 std::string VideoBackend::GetConfigName() const
30 {
31 return CONFIG_NAME;
32 }
33
34 std::string VideoBackend::GetDisplayName() const
35 {
36 return "Direct3D 12";
37 }
38
39 void VideoBackend::InitBackendInfo(const WindowSystemInfo& wsi)
40 {
41 if (!D3DCommon::LoadLibraries())
42 return;
43
44 FillBackendInfo();
45 D3DCommon::UnloadLibraries();
46 }
47
48 void VideoBackend::FillBackendInfo()
49 {
50 g_backend_info.api_type = APIType::D3D;
51 g_backend_info.bUsesLowerLeftOrigin = false;
52 g_backend_info.bSupportsExclusiveFullscreen = true;
53 g_backend_info.bSupportsDualSourceBlend = true;
54 g_backend_info.bSupportsPrimitiveRestart = true;
55 g_backend_info.bSupportsGeometryShaders = true;
56 g_backend_info.bSupports3DVision = false;
57 g_backend_info.bSupportsEarlyZ = true;
58 g_backend_info.bSupportsBindingLayout = false;
59 g_backend_info.bSupportsBBox = true;
60 g_backend_info.bSupportsGSInstancing = true;
61 g_backend_info.bSupportsPaletteConversion = true;
62 g_backend_info.bSupportsPostProcessing = true;
63 g_backend_info.bSupportsClipControl = true;
64 g_backend_info.bSupportsSSAA = true;
65 g_backend_info.bSupportsFragmentStoresAndAtomics = true;
66 g_backend_info.bSupportsDepthClamp = true;
67 g_backend_info.bSupportsReversedDepthRange = false;
68 g_backend_info.bSupportsComputeShaders = true;
69 g_backend_info.bSupportsLogicOp = true;
70 g_backend_info.bSupportsMultithreading = false;
71 g_backend_info.bSupportsGPUTextureDecoding = true;
72 g_backend_info.bSupportsST3CTextures = false;
73 g_backend_info.bSupportsCopyToVram = true;
74 g_backend_info.bSupportsBitfield = false;
75 g_backend_info.bSupportsDynamicSamplerIndexing = false;
76 g_backend_info.bSupportsBPTCTextures = false;
77 g_backend_info.bSupportsFramebufferFetch = false;
78 g_backend_info.bSupportsBackgroundCompiling = true;
79 g_backend_info.bSupportsLargePoints = false;
80 g_backend_info.bSupportsDepthReadback = true;
81 g_backend_info.bSupportsPartialDepthCopies = false;
82 g_backend_info.Adapters = D3DCommon::GetAdapterNames();
83 g_backend_info.AAModes = DXContext::GetAAModes(g_Config.iAdapter);
84 g_backend_info.bSupportsShaderBinaries = true;
85 g_backend_info.bSupportsPipelineCacheData = true;
86 g_backend_info.bSupportsCoarseDerivatives = true;
87 g_backend_info.bSupportsTextureQueryLevels = true;
88 g_backend_info.bSupportsLodBiasInSampler = true;
89 g_backend_info.bSupportsSettingObjectNames = true;
90 g_backend_info.bSupportsPartialMultisampleResolve = true;
91 g_backend_info.bSupportsDynamicVertexLoader = true;
92 g_backend_info.bSupportsVSLinePointExpand = true;
93 g_backend_info.bSupportsHDROutput = true;
94
95 // We can only check texture support once we have a device.
96 if (g_dx_context)
97 {
98 g_backend_info.bSupportsST3CTextures =
99 g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC1_UNORM) &&
100 g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC2_UNORM) &&
101 g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC3_UNORM);
102 g_backend_info.bSupportsBPTCTextures =
103 g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC7_UNORM);
104 }
105 }
106
107 bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
108 {
109 if (!DXContext::Create(g_Config.iAdapter, g_Config.bEnableValidationLayer))
110 {
111 PanicAlertFmtT("Failed to create D3D12 context");
112 return false;
113 }
114
115 FillBackendInfo();
116 UpdateActiveConfig();
117
118 if (!g_dx_context->CreateGlobalResources())
119 {
120 PanicAlertFmtT("Failed to create D3D12 global resources");
121 DXContext::Destroy();
122 ShutdownShared();
123 return false;
124 }
125
126 std::unique_ptr<SwapChain> swap_chain;
127 if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
128 {
129 PanicAlertFmtT("Failed to create D3D swap chain");
130 DXContext::Destroy();
131 ShutdownShared();
132 return false;
133 }
134
135 // Create main wrapper instances.
136 auto gfx = std::make_unique<DX12::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
137 auto vertex_manager = std::make_unique<DX12::VertexManager>();
138 auto perf_query = std::make_unique<DX12::PerfQuery>();
139 auto bounding_box = std::make_unique<DX12::D3D12BoundingBox>();
140
141 return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
142 std::move(bounding_box));
143 }
144
145 void VideoBackend::Shutdown()
146 {
147 // Keep the debug runtime happy...
148 if (g_gfx)
149 Gfx::GetInstance()->ExecuteCommandList(true);
150
151 ShutdownShared();
152 DXContext::Destroy();
153 }
154 } // namespace DX12