mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-03-12 06:39:14 +01:00
D3D12: Simplify and fix MSAA EFB depth copy path
This commit is contained in:
parent
649b94338e
commit
6bbf836ea9
@ -599,8 +599,7 @@ void DrawShadedTexQuad(D3DTexture2D* texture,
|
||||
u32 slice,
|
||||
DXGI_FORMAT rt_format,
|
||||
bool inherit_srv_binding,
|
||||
bool rt_multisampled,
|
||||
D3D12_DEPTH_STENCIL_DESC* depth_stencil_desc_override
|
||||
bool rt_multisampled
|
||||
)
|
||||
{
|
||||
float sw = 1.0f / static_cast<float>(source_width);
|
||||
@ -663,8 +662,6 @@ void DrawShadedTexQuad(D3DTexture2D* texture,
|
||||
Renderer::GetResetBlendDesc(), // D3D12_BLEND_DESC BlendState;
|
||||
UINT_MAX, // UINT SampleMask;
|
||||
Renderer::GetResetRasterizerDesc(), // D3D12_RASTERIZER_DESC RasterizerState
|
||||
depth_stencil_desc_override ?
|
||||
*depth_stencil_desc_override :
|
||||
Renderer::GetResetDepthStencilDesc(), // D3D12_DEPTH_STENCIL_DESC DepthStencilState
|
||||
layout12, // D3D12_INPUT_LAYOUT_DESC InputLayout
|
||||
D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFF, // D3D12_INDEX_BUFFER_PROPERTIES IndexBufferProperties
|
||||
|
@ -86,8 +86,7 @@ void DrawShadedTexQuad(D3DTexture2D* texture,
|
||||
u32 slice = 0,
|
||||
DXGI_FORMAT rt_format = DXGI_FORMAT_R8G8B8A8_UNORM,
|
||||
bool inherit_srv_binding = false,
|
||||
bool rt_multisampled = false,
|
||||
D3D12_DEPTH_STENCIL_DESC* depth_stencil_desc_override = nullptr
|
||||
bool rt_multisampled = false
|
||||
);
|
||||
|
||||
void DrawClearQuad(u32 Color, float z, D3D12_BLEND_DESC* blend_desc, D3D12_DEPTH_STENCIL_DESC* depth_stencil_desc, bool rt_multisampled);
|
||||
|
@ -21,8 +21,6 @@ FramebufferManager::Efb FramebufferManager::m_efb;
|
||||
unsigned int FramebufferManager::m_target_width;
|
||||
unsigned int FramebufferManager::m_target_height;
|
||||
|
||||
D3D12_DEPTH_STENCIL_DESC FramebufferManager::m_depth_resolve_depth_stencil_desc;
|
||||
|
||||
D3DTexture2D*& FramebufferManager::GetEFBColorTexture() { return m_efb.color_tex; }
|
||||
ID3D12Resource*& FramebufferManager::GetEFBColorStagingBuffer() { return m_efb.color_staging_buf; }
|
||||
|
||||
@ -148,18 +146,12 @@ FramebufferManager::FramebufferManager()
|
||||
SAFE_RELEASE(buf12);
|
||||
D3D::SetDebugObjectName12(m_efb.resolved_color_tex->GetTex12(), "EFB color resolve texture shader resource view");
|
||||
|
||||
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_TYPELESS, m_target_width, m_target_height, m_efb.slices, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);
|
||||
texdesc12 = CD3DX12_RESOURCE_DESC::Tex2D(DXGI_FORMAT_R32_FLOAT, m_target_width, m_target_height, m_efb.slices, 1, 1, 0, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET);
|
||||
hr = D3D::device12->CreateCommittedResource(&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT), D3D12_HEAP_FLAG_NONE, &texdesc12, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(&buf12));
|
||||
CHECK(hr == S_OK, "create EFB depth resolve texture (size: %dx%d; hr=%#x)", m_target_width, m_target_height, hr);
|
||||
m_efb.resolved_depth_tex = new D3DTexture2D(buf12, (D3D11_BIND_FLAG)(D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE), DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_UNKNOWN, false, D3D12_RESOURCE_STATE_COMMON);
|
||||
m_efb.resolved_depth_tex = new D3DTexture2D(buf12, (D3D11_BIND_FLAG)(D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE), DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, false, D3D12_RESOURCE_STATE_COMMON);
|
||||
SAFE_RELEASE(buf12);
|
||||
D3D::SetDebugObjectName12(m_efb.resolved_depth_tex->GetTex12(), "EFB depth resolve texture shader resource view");
|
||||
|
||||
m_depth_resolve_depth_stencil_desc = {};
|
||||
m_depth_resolve_depth_stencil_desc.StencilEnable = FALSE;
|
||||
m_depth_resolve_depth_stencil_desc.DepthEnable = TRUE;
|
||||
m_depth_resolve_depth_stencil_desc.DepthFunc = D3D12_COMPARISON_FUNC_ALWAYS;
|
||||
m_depth_resolve_depth_stencil_desc.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ALL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -215,21 +207,18 @@ void FramebufferManager::ResolveDepthTexture()
|
||||
const D3D12_VIEWPORT vp12 = { 0.f, 0.f, static_cast<float>(m_target_width), static_cast<float>(m_target_height), D3D12_MIN_DEPTH, D3D12_MAX_DEPTH };
|
||||
D3D::current_command_list->RSSetViewports(1, &vp12);
|
||||
|
||||
m_efb.resolved_depth_tex->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_DEPTH_WRITE);
|
||||
m_efb.resolved_depth_tex->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_RENDER_TARGET);
|
||||
D3D::current_command_list->OMSetRenderTargets(0, nullptr, FALSE, &m_efb.resolved_depth_tex->GetDSV12());
|
||||
|
||||
FramebufferManager::GetEFBDepthTexture()->TransitionToResourceState(D3D::current_command_list, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
|
||||
|
||||
D3D::SetLinearCopySampler();
|
||||
|
||||
// Render a quad covering the entire target, writing SV_Depth.
|
||||
const D3D12_RECT source_rect = CD3DX12_RECT(0, 0, m_target_width, m_target_height);
|
||||
D3D::DrawShadedTexQuad(
|
||||
FramebufferManager::GetEFBDepthTexture(),
|
||||
&source_rect,
|
||||
m_target_width,
|
||||
m_target_height,
|
||||
StaticShaderCache::GetDepthCopyPixelShader(true),
|
||||
StaticShaderCache::GetDepthResolveToColorPixelShader(),
|
||||
StaticShaderCache::GetSimpleVertexShader(),
|
||||
StaticShaderCache::GetSimpleVertexShaderInputLayout(),
|
||||
StaticShaderCache::GetCopyGeometryShader(),
|
||||
|
@ -100,8 +100,6 @@ private:
|
||||
|
||||
static unsigned int m_target_width;
|
||||
static unsigned int m_target_height;
|
||||
|
||||
static D3D12_DEPTH_STENCIL_DESC m_depth_resolve_depth_stencil_desc;
|
||||
};
|
||||
|
||||
} // namespace DX12
|
||||
|
@ -15,7 +15,7 @@ namespace DX12
|
||||
static ID3DBlob* s_color_matrix_program_blob[2] = {};
|
||||
static ID3DBlob* s_color_copy_program_blob[2] = {};
|
||||
static ID3DBlob* s_depth_matrix_program_blob[2] = {};
|
||||
static ID3DBlob* s_depth_copy_program_blob[2] = {};
|
||||
static ID3DBlob* s_depth_resolve_to_color_program_blob = {};
|
||||
static ID3DBlob* s_clear_program_blob = {};
|
||||
static ID3DBlob* s_anaglyph_program_blob = {};
|
||||
static ID3DBlob* s_rgba6_to_rgb8_program_blob[2] = {};
|
||||
@ -73,17 +73,6 @@ static constexpr const char s_color_copy_program_hlsl[] = {
|
||||
"}\n"
|
||||
};
|
||||
|
||||
static constexpr const char s_depth_copy_program_hlsl[] = {
|
||||
"sampler samp0 : register(s0);\n"
|
||||
"Texture2DArray Tex0 : register(t0);\n"
|
||||
"void main(\n"
|
||||
"out float odepth : SV_Depth,\n"
|
||||
"in float4 pos : SV_Position,\n"
|
||||
"in float3 uv0 : TEXCOORD0){\n"
|
||||
"odepth = Tex0.Sample(samp0,uv0);\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
// Anaglyph Red-Cyan shader based on Dubois algorithm
|
||||
// Constants taken from the paper:
|
||||
// "Conversion of a Stereo Pair to Anaglyph with
|
||||
@ -126,19 +115,19 @@ static constexpr const char s_color_copy_program_msaa_hlsl[] = {
|
||||
"}\n"
|
||||
};
|
||||
|
||||
static constexpr const char s_depth_copy_program_msaa_hlsl[] = {
|
||||
static constexpr const char s_depth_resolve_to_color_program_hlsl[] = {
|
||||
"#define SAMPLES %d\n"
|
||||
"Texture2DMSArray<float4, SAMPLES> Tex0 : register(t0);\n"
|
||||
"void main(\n"
|
||||
" out float depth : SV_Depth,\n"
|
||||
" out float ocol0 : SV_Target,\n"
|
||||
" in float4 pos : SV_Position,\n"
|
||||
" in float3 uv0 : TEXCOORD0)\n"
|
||||
"{\n"
|
||||
" int width, height, slices, samples;\n"
|
||||
" Tex0.GetDimensions(width, height, slices, samples);\n"
|
||||
" depth = Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), 0).x;\n"
|
||||
" ocol0 = Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), 0).x;\n"
|
||||
" for(int i = 1; i < SAMPLES; ++i)\n"
|
||||
" depth = min(depth, Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i).x);\n"
|
||||
" ocol0 = min(ocol0, Tex0.Load(int3(uv0.x*(width), uv0.y*(height), uv0.z), i).x);\n"
|
||||
"}\n"
|
||||
};
|
||||
|
||||
@ -497,25 +486,21 @@ D3D12_SHADER_BYTECODE StaticShaderCache::GetColorCopyPixelShader(bool multisampl
|
||||
return bytecode;
|
||||
}
|
||||
|
||||
D3D12_SHADER_BYTECODE StaticShaderCache::GetDepthCopyPixelShader(bool multisampled)
|
||||
D3D12_SHADER_BYTECODE StaticShaderCache::GetDepthResolveToColorPixelShader()
|
||||
{
|
||||
D3D12_SHADER_BYTECODE bytecode = {};
|
||||
|
||||
if (!multisampled || g_ActiveConfig.iMultisamples == 1)
|
||||
if (s_depth_resolve_to_color_program_blob)
|
||||
{
|
||||
bytecode = { s_depth_copy_program_blob[0]->GetBufferPointer(), s_depth_copy_program_blob[0]->GetBufferSize() };
|
||||
}
|
||||
else if (s_depth_copy_program_blob[1])
|
||||
{
|
||||
bytecode = { s_depth_copy_program_blob[1]->GetBufferPointer(), s_depth_copy_program_blob[1]->GetBufferSize() };
|
||||
bytecode = { s_depth_resolve_to_color_program_blob->GetBufferPointer(), s_depth_resolve_to_color_program_blob->GetBufferSize() };
|
||||
}
|
||||
else
|
||||
{
|
||||
// create MSAA shader for current AA mode
|
||||
std::string buf = StringFromFormat(s_depth_copy_program_msaa_hlsl, g_ActiveConfig.iMultisamples);
|
||||
std::string buf = StringFromFormat(s_depth_resolve_to_color_program_hlsl, g_ActiveConfig.iMultisamples);
|
||||
|
||||
D3D::CompilePixelShader(buf, &s_depth_copy_program_blob[1]);
|
||||
bytecode = { s_depth_copy_program_blob[1]->GetBufferPointer(), s_depth_copy_program_blob[1]->GetBufferSize() };
|
||||
D3D::CompilePixelShader(buf, &s_depth_resolve_to_color_program_blob);
|
||||
bytecode = { s_depth_resolve_to_color_program_blob->GetBufferPointer(), s_depth_resolve_to_color_program_blob->GetBufferSize() };
|
||||
}
|
||||
|
||||
return bytecode;
|
||||
@ -646,7 +631,6 @@ void StaticShaderCache::Init()
|
||||
D3D::CompilePixelShader(s_clear_program_hlsl, &s_clear_program_blob);
|
||||
D3D::CompilePixelShader(s_anaglyph_program_hlsl, &s_anaglyph_program_blob);
|
||||
D3D::CompilePixelShader(s_color_copy_program_hlsl, &s_color_copy_program_blob[0]);
|
||||
D3D::CompilePixelShader(s_depth_copy_program_hlsl, &s_depth_copy_program_blob[0]);
|
||||
D3D::CompilePixelShader(s_color_matrix_program_hlsl, &s_color_matrix_program_blob[0]);
|
||||
D3D::CompilePixelShader(s_depth_matrix_program_hlsl, &s_depth_matrix_program_blob[0]);
|
||||
|
||||
@ -667,6 +651,7 @@ void StaticShaderCache::InvalidateMSAAShaders()
|
||||
SAFE_RELEASE(s_depth_matrix_program_blob[1]);
|
||||
SAFE_RELEASE(s_rgb8_to_rgba6_program_blob[1]);
|
||||
SAFE_RELEASE(s_rgba6_to_rgb8_program_blob[1]);
|
||||
SAFE_RELEASE(s_depth_resolve_to_color_program_blob);
|
||||
}
|
||||
|
||||
void StaticShaderCache::Shutdown()
|
||||
@ -675,6 +660,7 @@ void StaticShaderCache::Shutdown()
|
||||
|
||||
SAFE_RELEASE(s_clear_program_blob);
|
||||
SAFE_RELEASE(s_anaglyph_program_blob);
|
||||
SAFE_RELEASE(s_depth_resolve_to_color_program_blob);
|
||||
|
||||
for (unsigned int i = 0; i < 2; ++i)
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public:
|
||||
static D3D12_SHADER_BYTECODE GetColorMatrixPixelShader(bool multisampled);
|
||||
static D3D12_SHADER_BYTECODE GetColorCopyPixelShader(bool multisampled);
|
||||
static D3D12_SHADER_BYTECODE GetDepthMatrixPixelShader(bool multisampled);
|
||||
static D3D12_SHADER_BYTECODE GetDepthCopyPixelShader(bool multisampled);
|
||||
static D3D12_SHADER_BYTECODE GetDepthResolveToColorPixelShader();
|
||||
static D3D12_SHADER_BYTECODE GetClearPixelShader();
|
||||
static D3D12_SHADER_BYTECODE GetAnaglyphPixelShader();
|
||||
static D3D12_SHADER_BYTECODE GetReinterpRGBA6ToRGB8PixelShader(bool multisampled);
|
||||
|
Loading…
x
Reference in New Issue
Block a user