2019-03-28 10:35:46 +00:00
|
|
|
// Copyright 2016 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-03-28 10:35:46 +00:00
|
|
|
|
2021-12-10 02:22:16 +00:00
|
|
|
#include "VideoBackends/D3D12/VideoBackend.h"
|
|
|
|
|
2019-03-28 10:35:46 +00:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "Common/CommonTypes.h"
|
|
|
|
#include "Common/StringUtil.h"
|
|
|
|
|
|
|
|
#include "Core/ConfigManager.h"
|
|
|
|
|
|
|
|
#include "VideoBackends/D3D12/Common.h"
|
2023-01-29 10:58:54 +00:00
|
|
|
#include "VideoBackends/D3D12/D3D12BoundingBox.h"
|
|
|
|
#include "VideoBackends/D3D12/D3D12Gfx.h"
|
2023-01-31 04:29:16 +00:00
|
|
|
#include "VideoBackends/D3D12/D3D12PerfQuery.h"
|
2020-09-15 13:01:29 +00:00
|
|
|
#include "VideoBackends/D3D12/D3D12SwapChain.h"
|
|
|
|
#include "VideoBackends/D3D12/D3D12VertexManager.h"
|
|
|
|
#include "VideoBackends/D3D12/DX12Context.h"
|
2019-03-28 10:35:46 +00:00
|
|
|
|
|
|
|
#include "VideoCommon/FramebufferManager.h"
|
|
|
|
#include "VideoCommon/ShaderCache.h"
|
|
|
|
#include "VideoCommon/TextureCacheBase.h"
|
|
|
|
#include "VideoCommon/VideoCommon.h"
|
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
|
|
|
|
namespace DX12
|
|
|
|
{
|
|
|
|
std::string VideoBackend::GetName() const
|
|
|
|
{
|
2020-09-06 10:56:45 +00:00
|
|
|
return NAME;
|
2019-03-28 10:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string VideoBackend::GetDisplayName() const
|
|
|
|
{
|
|
|
|
return "Direct3D 12";
|
|
|
|
}
|
|
|
|
|
2023-03-26 00:16:53 +00:00
|
|
|
void VideoBackend::InitBackendInfo(const WindowSystemInfo& wsi)
|
2019-03-28 10:35:46 +00:00
|
|
|
{
|
|
|
|
if (!D3DCommon::LoadLibraries())
|
|
|
|
return;
|
|
|
|
|
|
|
|
FillBackendInfo();
|
|
|
|
D3DCommon::UnloadLibraries();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::FillBackendInfo()
|
|
|
|
{
|
|
|
|
g_Config.backend_info.api_type = APIType::D3D;
|
|
|
|
g_Config.backend_info.bUsesLowerLeftOrigin = false;
|
|
|
|
g_Config.backend_info.bSupportsExclusiveFullscreen = true;
|
|
|
|
g_Config.backend_info.bSupportsDualSourceBlend = true;
|
|
|
|
g_Config.backend_info.bSupportsPrimitiveRestart = true;
|
|
|
|
g_Config.backend_info.bSupportsGeometryShaders = true;
|
|
|
|
g_Config.backend_info.bSupports3DVision = false;
|
|
|
|
g_Config.backend_info.bSupportsEarlyZ = true;
|
|
|
|
g_Config.backend_info.bSupportsBindingLayout = false;
|
|
|
|
g_Config.backend_info.bSupportsBBox = true;
|
|
|
|
g_Config.backend_info.bSupportsGSInstancing = true;
|
|
|
|
g_Config.backend_info.bSupportsPaletteConversion = true;
|
|
|
|
g_Config.backend_info.bSupportsPostProcessing = true;
|
|
|
|
g_Config.backend_info.bSupportsClipControl = true;
|
|
|
|
g_Config.backend_info.bSupportsSSAA = true;
|
|
|
|
g_Config.backend_info.bSupportsFragmentStoresAndAtomics = true;
|
|
|
|
g_Config.backend_info.bSupportsDepthClamp = true;
|
|
|
|
g_Config.backend_info.bSupportsReversedDepthRange = false;
|
|
|
|
g_Config.backend_info.bSupportsComputeShaders = true;
|
|
|
|
g_Config.backend_info.bSupportsLogicOp = true;
|
2022-09-27 02:24:52 +00:00
|
|
|
g_Config.backend_info.bSupportsMultithreading = false;
|
2019-03-28 10:35:46 +00:00
|
|
|
g_Config.backend_info.bSupportsGPUTextureDecoding = true;
|
|
|
|
g_Config.backend_info.bSupportsST3CTextures = false;
|
|
|
|
g_Config.backend_info.bSupportsCopyToVram = true;
|
|
|
|
g_Config.backend_info.bSupportsBitfield = false;
|
|
|
|
g_Config.backend_info.bSupportsDynamicSamplerIndexing = false;
|
|
|
|
g_Config.backend_info.bSupportsBPTCTextures = false;
|
|
|
|
g_Config.backend_info.bSupportsFramebufferFetch = false;
|
|
|
|
g_Config.backend_info.bSupportsBackgroundCompiling = true;
|
|
|
|
g_Config.backend_info.bSupportsLargePoints = false;
|
2020-05-24 06:11:10 +00:00
|
|
|
g_Config.backend_info.bSupportsDepthReadback = true;
|
2019-03-28 10:35:46 +00:00
|
|
|
g_Config.backend_info.bSupportsPartialDepthCopies = false;
|
|
|
|
g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
|
|
|
|
g_Config.backend_info.AAModes = DXContext::GetAAModes(g_Config.iAdapter);
|
2019-04-15 11:55:26 +00:00
|
|
|
g_Config.backend_info.bSupportsShaderBinaries = true;
|
|
|
|
g_Config.backend_info.bSupportsPipelineCacheData = true;
|
2021-11-14 04:10:20 +00:00
|
|
|
g_Config.backend_info.bSupportsCoarseDerivatives = true;
|
2021-11-14 04:10:55 +00:00
|
|
|
g_Config.backend_info.bSupportsTextureQueryLevels = true;
|
2021-08-07 03:26:51 +00:00
|
|
|
g_Config.backend_info.bSupportsLodBiasInSampler = true;
|
2022-01-31 06:16:05 +00:00
|
|
|
g_Config.backend_info.bSupportsSettingObjectNames = true;
|
2022-06-21 07:07:35 +00:00
|
|
|
g_Config.backend_info.bSupportsPartialMultisampleResolve = true;
|
2022-06-20 07:55:49 +00:00
|
|
|
g_Config.backend_info.bSupportsDynamicVertexLoader = true;
|
2022-10-01 03:12:08 +00:00
|
|
|
g_Config.backend_info.bSupportsVSLinePointExpand = true;
|
2019-03-28 10:35:46 +00:00
|
|
|
|
|
|
|
// We can only check texture support once we have a device.
|
|
|
|
if (g_dx_context)
|
|
|
|
{
|
|
|
|
g_Config.backend_info.bSupportsST3CTextures =
|
|
|
|
g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC1_UNORM) &&
|
|
|
|
g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC2_UNORM) &&
|
|
|
|
g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC3_UNORM);
|
|
|
|
g_Config.backend_info.bSupportsBPTCTextures =
|
|
|
|
g_dx_context->SupportsTextureFormat(DXGI_FORMAT_BC7_UNORM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
|
|
|
|
{
|
|
|
|
if (!DXContext::Create(g_Config.iAdapter, g_Config.bEnableValidationLayer))
|
|
|
|
{
|
2020-12-02 18:17:27 +00:00
|
|
|
PanicAlertFmtT("Failed to create D3D12 context");
|
2019-03-28 10:35:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FillBackendInfo();
|
2023-01-29 10:58:54 +00:00
|
|
|
UpdateActiveConfig();
|
2019-03-28 10:35:46 +00:00
|
|
|
|
|
|
|
if (!g_dx_context->CreateGlobalResources())
|
|
|
|
{
|
2020-12-02 18:17:27 +00:00
|
|
|
PanicAlertFmtT("Failed to create D3D12 global resources");
|
2019-03-28 10:35:46 +00:00
|
|
|
DXContext::Destroy();
|
|
|
|
ShutdownShared();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<SwapChain> swap_chain;
|
|
|
|
if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
|
|
|
|
{
|
2020-12-02 18:17:27 +00:00
|
|
|
PanicAlertFmtT("Failed to create D3D swap chain");
|
2019-03-28 10:35:46 +00:00
|
|
|
DXContext::Destroy();
|
|
|
|
ShutdownShared();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create main wrapper instances.
|
2023-01-29 10:58:54 +00:00
|
|
|
auto gfx = std::make_unique<DX12::Gfx>(std::move(swap_chain), wsi.render_surface_scale);
|
|
|
|
auto vertex_manager = std::make_unique<DX12::VertexManager>();
|
|
|
|
auto perf_query = std::make_unique<DX12::PerfQuery>();
|
|
|
|
auto bounding_box = std::make_unique<DX12::D3D12BoundingBox>();
|
2019-03-28 10:35:46 +00:00
|
|
|
|
2023-01-29 10:58:54 +00:00
|
|
|
return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
|
|
|
|
std::move(bounding_box));
|
2019-03-28 10:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VideoBackend::Shutdown()
|
|
|
|
{
|
|
|
|
// Keep the debug runtime happy...
|
2023-01-29 10:58:54 +00:00
|
|
|
if (g_gfx)
|
|
|
|
Gfx::GetInstance()->ExecuteCommandList(true);
|
2019-03-28 10:35:46 +00:00
|
|
|
|
|
|
|
ShutdownShared();
|
2022-07-25 05:20:33 +00:00
|
|
|
DXContext::Destroy();
|
2019-03-28 10:35:46 +00:00
|
|
|
}
|
|
|
|
} // namespace DX12
|