D3D12HostDisplay: Implement post processing

This commit is contained in:
Connor McLaughlin
2022-10-13 19:56:57 +10:00
parent cc3fadba14
commit adf41b9bbd
3 changed files with 315 additions and 70 deletions

View File

@@ -1,12 +1,13 @@
#pragma once
#pragma once
#include "common/d3d12/descriptor_heap_manager.h"
#include "common/d3d12/staging_texture.h"
#include "common/d3d12/stream_buffer.h"
#include "common/d3d12/texture.h"
#include "common/timer.h"
#include "common/window_info.h"
#include "common/windows_headers.h"
#include "core/host_display.h"
#include "postprocessing_chain.h"
#include <d3d12.h>
#include <dxgi.h>
#include <memory>
@@ -73,10 +74,15 @@ public:
static AdapterAndModeList StaticGetAdapterAndModeList();
protected:
enum : u32
struct PostProcessingStage
{
DISPLAY_UNIFORM_BUFFER_SIZE = 65536,
TEXTURE_STREAMING_BUFFER_SIZE = 4 * 1024 * 1024
PostProcessingStage() = default;
PostProcessingStage(PostProcessingStage&& move);
~PostProcessingStage();
ComPtr<ID3D12PipelineState> pipeline;
D3D12::Texture output_texture;
u32 uniforms_size = 0;
};
static AdapterAndModeList GetAdapterAndModeList(IDXGIFactory* dxgi_factory);
@@ -92,7 +98,7 @@ protected:
bool CreateSwapChainRTV();
void DestroySwapChainRTVs();
void RenderDisplay(ID3D12GraphicsCommandList* cmdlist);
void RenderDisplay(ID3D12GraphicsCommandList* cmdlist, D3D12::Texture* swap_chain_buf);
void RenderSoftwareCursor(ID3D12GraphicsCommandList* cmdlist);
void RenderImGui(ID3D12GraphicsCommandList* cmdlist);
@@ -102,6 +108,12 @@ protected:
void RenderSoftwareCursor(ID3D12GraphicsCommandList* cmdlist, s32 left, s32 top, s32 width, s32 height,
GPUTexture* texture_handle);
bool CheckPostProcessingRenderTargets(u32 target_width, u32 target_height);
void ApplyPostProcessingChain(ID3D12GraphicsCommandList* cmdlist, D3D12::Texture* final_target, s32 final_left,
s32 final_top, s32 final_width, s32 final_height, D3D12::Texture* texture,
s32 texture_view_x, s32 texture_view_y, s32 texture_view_width, s32 texture_view_height,
u32 target_width, u32 target_height);
ComPtr<IDXGIFactory> m_dxgi_factory;
ComPtr<IDXGISwapChain> m_swap_chain;
std::vector<D3D12::Texture> m_swap_chain_buffers;
@@ -114,9 +126,16 @@ protected:
D3D12::DescriptorHandle m_linear_sampler;
D3D12::Texture m_display_pixels_texture;
D3D12::StreamBuffer m_display_uniform_buffer;
D3D12::StagingTexture m_readback_staging_texture;
ComPtr<ID3D12RootSignature> m_post_processing_root_signature;
ComPtr<ID3D12RootSignature> m_post_processing_cb_root_signature;
FrontendCommon::PostProcessingChain m_post_processing_chain;
D3D12::StreamBuffer m_post_processing_cbuffer;
D3D12::Texture m_post_processing_input_texture;
std::vector<PostProcessingStage> m_post_processing_stages;
Common::Timer m_post_processing_timer;
bool m_allow_tearing_supported = false;
bool m_using_allow_tearing = false;
bool m_vsync = true;