GPU: Add D3D12 renderer

This commit is contained in:
Connor McLaughlin
2021-07-10 21:37:08 +10:00
parent 5da9edceb9
commit 14e7f8fd13
37 changed files with 5838 additions and 2 deletions

View File

@ -122,6 +122,8 @@ target_compile_definitions(core PUBLIC "-DWITH_IMGUI=1")
if(WIN32)
target_sources(core PRIVATE
gpu_hw_d3d12.cpp
gpu_hw_d3d12.h
gpu_hw_d3d11.cpp
gpu_hw_d3d11.h
)

View File

@ -36,6 +36,7 @@
<ClCompile Include="gpu_backend.cpp" />
<ClCompile Include="gpu_commands.cpp" />
<ClCompile Include="gpu_hw_d3d11.cpp" />
<ClCompile Include="gpu_hw_d3d12.cpp" />
<ClCompile Include="gpu_hw_shadergen.cpp" />
<ClCompile Include="gpu_hw_vulkan.cpp" />
<ClCompile Include="gpu_sw.cpp" />
@ -99,6 +100,7 @@
<ClInclude Include="digital_controller.h" />
<ClInclude Include="gpu_backend.h" />
<ClInclude Include="gpu_hw_d3d11.h" />
<ClInclude Include="gpu_hw_d3d12.h" />
<ClInclude Include="gpu_hw_shadergen.h" />
<ClInclude Include="gpu_hw_vulkan.h" />
<ClInclude Include="gpu_sw.h" />

View File

@ -58,6 +58,7 @@
<ClCompile Include="texture_replacements.cpp" />
<ClCompile Include="gdb_protocol.h" />
<ClCompile Include="multitap.cpp" />
<ClCompile Include="gpu_hw_d3d12.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="types.h" />
@ -118,5 +119,6 @@
<ClInclude Include="texture_replacements.h" />
<ClInclude Include="shader_cache_version.h" />
<ClInclude Include="multitap.h" />
<ClInclude Include="gpu_hw_d3d12.h" />
</ItemGroup>
</Project>
</Project>

View File

@ -146,6 +146,9 @@ public:
// gpu_hw_d3d11.cpp
static std::unique_ptr<GPU> CreateHardwareD3D11Renderer();
// gpu_hw_d3d12.cpp
static std::unique_ptr<GPU> CreateHardwareD3D12Renderer();
// gpu_hw_opengl.cpp
static std::unique_ptr<GPU> CreateHardwareOpenGLRenderer();

1097
src/core/gpu_hw_d3d12.cpp Normal file

File diff suppressed because it is too large Load Diff

102
src/core/gpu_hw_d3d12.h Normal file
View File

@ -0,0 +1,102 @@
#pragma once
#include "common/dimensional_array.h"
#include "common/d3d12/staging_texture.h"
#include "common/d3d12/stream_buffer.h"
#include "common/d3d12/texture.h"
#include "gpu_hw.h"
#include <array>
#include <memory>
#include <tuple>
class GPU_HW_D3D12 : public GPU_HW
{
public:
template<typename T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
GPU_HW_D3D12();
~GPU_HW_D3D12() override;
GPURenderer GetRendererType() const override;
bool Initialize(HostDisplay* host_display) override;
void Reset(bool clear_vram) override;
void ResetGraphicsAPIState() override;
void RestoreGraphicsAPIState() override;
void UpdateSettings() override;
protected:
void ClearDisplay() override;
void UpdateDisplay() override;
void ReadVRAM(u32 x, u32 y, u32 width, u32 height) override;
void FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color) override;
void UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data, bool set_mask, bool check_mask) override;
void CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) override;
void UpdateVRAMReadTexture() override;
void UpdateDepthBufferFromMaskBit() override;
void ClearDepthBuffer() override;
void SetScissorFromDrawingArea() override;
void MapBatchVertexPointer(u32 required_vertices) override;
void UnmapBatchVertexPointer(u32 used_vertices) override;
void UploadUniformBuffer(const void* data, u32 data_size) override;
void DrawBatchVertices(BatchRenderMode render_mode, u32 base_vertex, u32 num_vertices) override;
private:
enum : u32
{
MAX_PUSH_CONSTANTS_SIZE = 64,
};
void SetCapabilities();
void DestroyResources();
bool CreateRootSignatures();
bool CreateSamplers();
bool CreateFramebuffer();
void ClearFramebuffer();
void DestroyFramebuffer();
bool CreateVertexBuffer();
bool CreateUniformBuffer();
bool CreateTextureBuffer();
bool CompilePipelines();
void DestroyPipelines();
ComPtr<ID3D12RootSignature> m_batch_root_signature;
ComPtr<ID3D12RootSignature> m_single_sampler_root_signature;
D3D12::Texture m_vram_texture;
D3D12::Texture m_vram_depth_texture;
D3D12::Texture m_vram_read_texture;
D3D12::Texture m_vram_readback_texture;
D3D12::StagingTexture m_vram_readback_staging_texture;
D3D12::Texture m_display_texture;
D3D12::DescriptorHandle m_point_sampler;
D3D12::DescriptorHandle m_linear_sampler;
D3D12::StreamBuffer m_vertex_stream_buffer;
D3D12::StreamBuffer m_uniform_stream_buffer;
D3D12::StreamBuffer m_texture_stream_buffer;
D3D12::DescriptorHandle m_texture_stream_buffer_srv;
u32 m_current_uniform_buffer_offset = 0;
// [depth_test][render_mode][texture_mode][transparency_mode][dithering][interlacing]
DimensionalArray<ComPtr<ID3D12PipelineState>, 2, 2, 5, 9, 4, 2> m_batch_pipelines;
// [interlaced]
std::array<ComPtr<ID3D12PipelineState>, 2> m_vram_fill_pipelines;
// [depth_test]
std::array<ComPtr<ID3D12PipelineState>, 2> m_vram_write_pipelines;
std::array<ComPtr<ID3D12PipelineState>, 2> m_vram_copy_pipelines;
ComPtr<ID3D12PipelineState> m_vram_readback_pipeline;
ComPtr<ID3D12PipelineState> m_vram_update_depth_pipeline;
// [depth_24][interlace_mode]
DimensionalArray<ComPtr<ID3D12PipelineState>, 3, 2> m_display_pipelines;
};

View File

@ -41,6 +41,7 @@ public:
{
None,
D3D11,
D3D12,
Vulkan,
OpenGL,
OpenGLES

View File

@ -652,11 +652,13 @@ const char* Settings::GetCPUFastmemModeDisplayName(CPUFastmemMode mode)
static constexpr auto s_gpu_renderer_names = make_array(
#ifdef _WIN32
"D3D11",
"D3D12",
#endif
"Vulkan", "OpenGL", "Software");
static constexpr auto s_gpu_renderer_display_names = make_array(
#ifdef _WIN32
TRANSLATABLE("GPURenderer", "Hardware (D3D11)"),
TRANSLATABLE("GPURenderer", "Hardware (D3D12)"),
#endif
TRANSLATABLE("GPURenderer", "Hardware (Vulkan)"), TRANSLATABLE("GPURenderer", "Hardware (OpenGL)"),
TRANSLATABLE("GPURenderer", "Software"));

View File

@ -7,7 +7,7 @@
Log_SetChannel(ShaderGen);
ShaderGen::ShaderGen(HostDisplay::RenderAPI render_api, bool supports_dual_source_blend)
: m_render_api(render_api), m_glsl(render_api != HostDisplay::RenderAPI::D3D11),
: m_render_api(render_api), m_glsl(render_api != HostDisplay::RenderAPI::D3D11 && render_api != HostDisplay::RenderAPI::D3D12),
m_supports_dual_source_blend(supports_dual_source_blend), m_use_glsl_interface_blocks(false)
{
if (m_glsl)
@ -133,6 +133,7 @@ void ShaderGen::WriteHeader(std::stringstream& ss)
DefineMacro(ss, "API_OPENGL", m_render_api == HostDisplay::RenderAPI::OpenGL);
DefineMacro(ss, "API_OPENGL_ES", m_render_api == HostDisplay::RenderAPI::OpenGLES);
DefineMacro(ss, "API_D3D11", m_render_api == HostDisplay::RenderAPI::D3D11);
DefineMacro(ss, "API_D3D12", m_render_api == HostDisplay::RenderAPI::D3D12);
DefineMacro(ss, "API_VULKAN", m_render_api == HostDisplay::RenderAPI::Vulkan);
if (m_render_api == HostDisplay::RenderAPI::OpenGLES)

View File

@ -1012,6 +1012,9 @@ bool CreateGPU(GPURenderer renderer)
case GPURenderer::HardwareD3D11:
g_gpu = GPU::CreateHardwareD3D11Renderer();
break;
case GPURenderer::HardwareD3D12:
g_gpu = GPU::CreateHardwareD3D12Renderer();
break;
#endif
case GPURenderer::Software:

View File

@ -56,6 +56,7 @@ enum class GPURenderer : u8
{
#ifdef _WIN32
HardwareD3D11,
HardwareD3D12,
#endif
HardwareVulkan,
HardwareOpenGL,