@@ -0,0 +1,166 @@
// Copyright 2016 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include <string>

#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"

#include "Core/ConfigManager.h"

#include "VideoBackends/D3D12/Common.h"
#include "VideoBackends/D3D12/DXContext.h"
#include "VideoBackends/D3D12/PerfQuery.h"
#include "VideoBackends/D3D12/Renderer.h"
#include "VideoBackends/D3D12/SwapChain.h"
#include "VideoBackends/D3D12/VertexManager.h"
#include "VideoBackends/D3D12/VideoBackend.h"

#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
{
return "D3D12";
}

std::string VideoBackend::GetDisplayName() const
{
return "Direct3D 12";
}

void VideoBackend::InitBackendInfo()
{
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.bSupportsOversizedViewports = false;
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;
g_Config.backend_info.bSupportsMultithreading = true;
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;
g_Config.backend_info.bSupportsPartialDepthCopies = false;
g_Config.backend_info.Adapters = D3DCommon::GetAdapterNames();
g_Config.backend_info.AAModes = DXContext::GetAAModes(g_Config.iAdapter);

// 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))
{
PanicAlert("Failed to create D3D12 context");
return false;
}

FillBackendInfo();
InitializeShared();

if (!g_dx_context->CreateGlobalResources())
{
PanicAlert("Failed to create D3D12 global resources");
DXContext::Destroy();
ShutdownShared();
return false;
}

std::unique_ptr<SwapChain> swap_chain;
if (wsi.render_surface && !(swap_chain = SwapChain::Create(wsi)))
{
PanicAlertT("Failed to create D3D swap chain");
DXContext::Destroy();
ShutdownShared();
return false;
}

// Create main wrapper instances.
g_renderer = std::make_unique<Renderer>(std::move(swap_chain), wsi.render_surface_scale);
g_vertex_manager = std::make_unique<VertexManager>();
g_shader_cache = std::make_unique<VideoCommon::ShaderCache>();
g_framebuffer_manager = std::make_unique<FramebufferManager>();
g_texture_cache = std::make_unique<TextureCacheBase>();
g_perf_query = std::make_unique<PerfQuery>();

if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() ||
!g_renderer->Initialize() || !g_framebuffer_manager->Initialize() ||
!g_texture_cache->Initialize() || !PerfQuery::GetInstance()->Initialize())
{
PanicAlert("Failed to initialize renderer classes");
Shutdown();
return false;
}

g_shader_cache->InitializeShaderCache();
return true;
}

void VideoBackend::Shutdown()
{
// Keep the debug runtime happy...
if (g_renderer)
Renderer::GetInstance()->ExecuteCommandList(true);

if (g_shader_cache)
g_shader_cache->Shutdown();

if (g_renderer)
g_renderer->Shutdown();

g_perf_query.reset();
g_texture_cache.reset();
g_framebuffer_manager.reset();
g_shader_cache.reset();
g_vertex_manager.reset();
g_renderer.reset();
DXContext::Destroy();
ShutdownShared();
}
} // namespace DX12
@@ -0,0 +1,25 @@
// Copyright 2019 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <string>
#include "VideoCommon/VideoBackendBase.h"

namespace DX12
{
class VideoBackend final : public VideoBackendBase
{
public:
bool Initialize(const WindowSystemInfo& wsi) override;
void Shutdown() override;

std::string GetName() const override;
std::string GetDisplayName() const override;
void InitBackendInfo() override;

private:
void FillBackendInfo();
};
}
@@ -21,6 +21,7 @@
// TODO: ugly
#ifdef _WIN32
#include "VideoBackends/D3D/VideoBackend.h"
#include "VideoBackends/D3D12/VideoBackend.h"
#endif
#include "VideoBackends/Null/VideoBackend.h"
#include "VideoBackends/OGL/VideoBackend.h"
@@ -184,6 +185,7 @@ void VideoBackendBase::PopulateList()
g_available_video_backends.push_back(std::make_unique<OGL::VideoBackend>());
#ifdef _WIN32
g_available_video_backends.push_back(std::make_unique<DX11::VideoBackend>());
g_available_video_backends.push_back(std::make_unique<DX12::VideoBackend>());
#endif
g_available_video_backends.push_back(std::make_unique<Vulkan::VideoBackend>());
g_available_video_backends.push_back(std::make_unique<SW::VideoSoftware>());
@@ -84,6 +84,9 @@
<ProjectReference Include="$(CoreDir)UICommon\UICommon.vcxproj">
<Project>{604c8368-f34a-4d55-82c8-cc92a0c13254}</Project>
</ProjectReference>
<ProjectReference Include="..\Core\VideoBackends\D3D12\D3D12.vcxproj">
<Project>{570215b7-e32f-4438-95ae-c8d955f9fca3}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -93,6 +93,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "imgui", "..\Externals\imgui
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UpdaterCommon", "Core\UpdaterCommon\UpdaterCommon.vcxproj", "{B001D13E-7EAB-4689-842D-801E5ACFFAC5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D3D12", "Core\VideoBackends\D3D12\D3D12.vcxproj", "{570215B7-E32F-4438-95AE-C8D955F9FCA3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D3DCommon", "Core\VideoBackends\D3DCommon\D3DCommon.vcxproj", "{DEA96CF2-F237-4A1A-B32F-C916769EFB50}"
EndProject
Global
@@ -355,6 +357,12 @@ Global
{B001D13E-7EAB-4689-842D-801E5ACFFAC5}.Release|x64.ActiveCfg = Release|x64
{B001D13E-7EAB-4689-842D-801E5ACFFAC5}.Release|x64.Build.0 = Release|x64
{B001D13E-7EAB-4689-842D-801E5ACFFAC5}.Release|x86.ActiveCfg = Release|x64
{570215B7-E32F-4438-95AE-C8D955F9FCA3}.Debug|x64.ActiveCfg = Debug|x64
{570215B7-E32F-4438-95AE-C8D955F9FCA3}.Debug|x64.Build.0 = Debug|x64
{570215B7-E32F-4438-95AE-C8D955F9FCA3}.Debug|x86.ActiveCfg = Debug|x64
{570215B7-E32F-4438-95AE-C8D955F9FCA3}.Release|x64.ActiveCfg = Release|x64
{570215B7-E32F-4438-95AE-C8D955F9FCA3}.Release|x64.Build.0 = Release|x64
{570215B7-E32F-4438-95AE-C8D955F9FCA3}.Release|x86.ActiveCfg = Release|x64
{DEA96CF2-F237-4A1A-B32F-C916769EFB50}.Debug|x64.ActiveCfg = Debug|x64
{DEA96CF2-F237-4A1A-B32F-C916769EFB50}.Debug|x64.Build.0 = Debug|x64
{DEA96CF2-F237-4A1A-B32F-C916769EFB50}.Debug|x86.ActiveCfg = Debug|x64
@@ -402,6 +410,7 @@ Global
{4482FD2A-EC43-3FFB-AC20-2E5C54B05EAD} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{23114507-079A-4418-9707-CFA81A03CA99} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{4C3B2264-EA73-4A7B-9CFE-65B0FD635EBB} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}
{570215B7-E32F-4438-95AE-C8D955F9FCA3} = {AAD1BCD6-9804-44A5-A5FC-4782EA00E9D4}
{DEA96CF2-F237-4A1A-B32F-C916769EFB50} = {AAD1BCD6-9804-44A5-A5FC-4782EA00E9D4}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution