mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 13:55:38 +00:00
HostDisplay: Blit before post processing, not after
Should be a tiny performance boost on tilers.
This commit is contained in:
parent
adf41b9bbd
commit
2c867bc3df
|
@ -21,6 +21,8 @@ Log_SetChannel(D3D11HostDisplay);
|
|||
#pragma comment(lib, "d3d11.lib")
|
||||
#pragma comment(lib, "dxgi.lib")
|
||||
|
||||
static constexpr std::array<float, 4> s_clear_color = {};
|
||||
|
||||
D3D11HostDisplay::D3D11HostDisplay() = default;
|
||||
|
||||
D3D11HostDisplay::~D3D11HostDisplay()
|
||||
|
@ -706,10 +708,6 @@ bool D3D11HostDisplay::Render(bool skip_present)
|
|||
if (m_vsync && m_gpu_timing_enabled)
|
||||
PopTimestampQuery();
|
||||
|
||||
static constexpr std::array<float, 4> clear_color = {};
|
||||
m_context->ClearRenderTargetView(m_swap_chain_rtv.Get(), clear_color.data());
|
||||
m_context->OMSetRenderTargets(1, m_swap_chain_rtv.GetAddressOf(), nullptr);
|
||||
|
||||
RenderDisplay();
|
||||
|
||||
if (ImGui::GetCurrentContext())
|
||||
|
@ -746,7 +744,7 @@ bool D3D11HostDisplay::RenderScreenshot(u32 width, u32 height, std::vector<u32>*
|
|||
|
||||
if (HasDisplayTexture())
|
||||
{
|
||||
const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height, 0);
|
||||
const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height);
|
||||
|
||||
if (!m_post_processing_chain.IsEmpty())
|
||||
{
|
||||
|
@ -783,12 +781,9 @@ void D3D11HostDisplay::RenderImGui()
|
|||
|
||||
void D3D11HostDisplay::RenderDisplay()
|
||||
{
|
||||
if (!HasDisplayTexture())
|
||||
return;
|
||||
|
||||
const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight());
|
||||
|
||||
if (!m_post_processing_chain.IsEmpty())
|
||||
if (HasDisplayTexture() && !m_post_processing_chain.IsEmpty())
|
||||
{
|
||||
ApplyPostProcessingChain(m_swap_chain_rtv.Get(), left, top, width, height,
|
||||
static_cast<D3D11::Texture*>(m_display_texture), m_display_texture_view_x,
|
||||
|
@ -797,6 +792,12 @@ void D3D11HostDisplay::RenderDisplay()
|
|||
return;
|
||||
}
|
||||
|
||||
m_context->ClearRenderTargetView(m_swap_chain_rtv.Get(), s_clear_color.data());
|
||||
m_context->OMSetRenderTargets(1, m_swap_chain_rtv.GetAddressOf(), nullptr);
|
||||
|
||||
if (!HasDisplayTexture())
|
||||
return;
|
||||
|
||||
RenderDisplay(left, top, width, height, static_cast<D3D11::Texture*>(m_display_texture), m_display_texture_view_x,
|
||||
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height,
|
||||
IsUsingLinearFiltering());
|
||||
|
@ -1048,8 +1049,6 @@ void D3D11HostDisplay::ApplyPostProcessingChain(ID3D11RenderTargetView* final_ta
|
|||
s32 texture_view_x, s32 texture_view_y, s32 texture_view_width,
|
||||
s32 texture_view_height, u32 target_width, u32 target_height)
|
||||
{
|
||||
static constexpr std::array<float, 4> clear_color = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
|
||||
if (!CheckPostProcessingRenderTargets(target_width, target_height))
|
||||
{
|
||||
RenderDisplay(final_left, final_top, final_width, final_height, texture, texture_view_x, texture_view_y,
|
||||
|
@ -1058,7 +1057,7 @@ void D3D11HostDisplay::ApplyPostProcessingChain(ID3D11RenderTargetView* final_ta
|
|||
}
|
||||
|
||||
// downsample/upsample - use same viewport for remainder
|
||||
m_context->ClearRenderTargetView(m_post_processing_input_texture.GetD3DRTV(), clear_color.data());
|
||||
m_context->ClearRenderTargetView(m_post_processing_input_texture.GetD3DRTV(), s_clear_color.data());
|
||||
m_context->OMSetRenderTargets(1, m_post_processing_input_texture.GetD3DRTVArray(), nullptr);
|
||||
RenderDisplay(final_left, final_top, final_width, final_height, texture, texture_view_x, texture_view_y,
|
||||
texture_view_width, texture_view_height, IsUsingLinearFiltering());
|
||||
|
@ -1075,15 +1074,9 @@ void D3D11HostDisplay::ApplyPostProcessingChain(ID3D11RenderTargetView* final_ta
|
|||
for (u32 i = 0; i < static_cast<u32>(m_post_processing_stages.size()); i++)
|
||||
{
|
||||
PostProcessingStage& pps = m_post_processing_stages[i];
|
||||
if (i == final_stage)
|
||||
{
|
||||
m_context->OMSetRenderTargets(1, &final_target, nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_context->ClearRenderTargetView(pps.output_texture.GetD3DRTV(), clear_color.data());
|
||||
m_context->OMSetRenderTargets(1, pps.output_texture.GetD3DRTVArray(), nullptr);
|
||||
}
|
||||
ID3D11RenderTargetView* rtv = (i == final_stage) ? final_target : pps.output_texture.GetD3DRTV();
|
||||
m_context->ClearRenderTargetView(rtv, s_clear_color.data());
|
||||
m_context->OMSetRenderTargets(1, &rtv, nullptr);
|
||||
|
||||
m_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
|
||||
m_context->VSSetShader(pps.vertex_shader.Get(), nullptr, 0);
|
||||
|
|
|
@ -620,9 +620,7 @@ bool OpenGLHostDisplay::Render(bool skip_present)
|
|||
}
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
RenderDisplay();
|
||||
|
||||
|
@ -652,22 +650,23 @@ bool OpenGLHostDisplay::RenderScreenshot(u32 width, u32 height, std::vector<u32>
|
|||
}
|
||||
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
texture.BindFramebuffer(GL_FRAMEBUFFER);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (HasDisplayTexture())
|
||||
const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height);
|
||||
|
||||
if (HasDisplayTexture() && !m_post_processing_chain.IsEmpty())
|
||||
{
|
||||
const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height, 0);
|
||||
ApplyPostProcessingChain(texture.GetGLFramebufferID(), left, height - top - draw_height, draw_width, draw_height,
|
||||
static_cast<GL::Texture*>(m_display_texture), m_display_texture_view_x,
|
||||
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height,
|
||||
width, height);
|
||||
}
|
||||
else
|
||||
{
|
||||
texture.BindFramebuffer(GL_FRAMEBUFFER);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (!m_post_processing_chain.IsEmpty())
|
||||
{
|
||||
ApplyPostProcessingChain(texture.GetGLFramebufferID(), left, height - top - draw_height, draw_width, draw_height,
|
||||
static_cast<GL::Texture*>(m_display_texture), m_display_texture_view_x,
|
||||
m_display_texture_view_y, m_display_texture_view_width, m_display_texture_view_height,
|
||||
width, height);
|
||||
}
|
||||
else
|
||||
if (HasDisplayTexture())
|
||||
{
|
||||
RenderDisplay(left, height - top - draw_height, draw_width, draw_height,
|
||||
static_cast<GL::Texture*>(m_display_texture), m_display_texture_view_x, m_display_texture_view_y,
|
||||
|
@ -693,12 +692,9 @@ void OpenGLHostDisplay::RenderImGui()
|
|||
|
||||
void OpenGLHostDisplay::RenderDisplay()
|
||||
{
|
||||
if (!HasDisplayTexture())
|
||||
return;
|
||||
|
||||
const auto [left, top, width, height] = CalculateDrawRect(GetWindowWidth(), GetWindowHeight());
|
||||
|
||||
if (!m_post_processing_chain.IsEmpty())
|
||||
if (HasDisplayTexture() && !m_post_processing_chain.IsEmpty())
|
||||
{
|
||||
ApplyPostProcessingChain(0, left, GetWindowHeight() - top - height, width, height,
|
||||
static_cast<GL::Texture*>(m_display_texture), m_display_texture_view_x,
|
||||
|
@ -707,6 +703,12 @@ void OpenGLHostDisplay::RenderDisplay()
|
|||
return;
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
if (!HasDisplayTexture())
|
||||
return;
|
||||
|
||||
RenderDisplay(left, GetWindowHeight() - top - height, width, height, static_cast<GL::Texture*>(m_display_texture),
|
||||
m_display_texture_view_x, m_display_texture_view_y, m_display_texture_view_width,
|
||||
m_display_texture_view_height, IsUsingLinearFiltering());
|
||||
|
@ -877,6 +879,7 @@ bool OpenGLHostDisplay::SetPostProcessingChain(const std::string_view& config)
|
|||
m_post_processing_ubo->Unbind();
|
||||
}
|
||||
|
||||
m_post_processing_timer.Reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -924,7 +927,7 @@ void OpenGLHostDisplay::ApplyPostProcessingChain(GLuint final_target, s32 final_
|
|||
}
|
||||
|
||||
// downsample/upsample - use same viewport for remainder
|
||||
m_post_processing_input_texture.BindFramebuffer(GL_DRAW_FRAMEBUFFER);
|
||||
m_post_processing_input_texture.BindFramebuffer(GL_FRAMEBUFFER);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
RenderDisplay(final_left, target_height - final_top - final_height, final_width, final_height, texture,
|
||||
texture_view_x, texture_view_y, texture_view_width, texture_view_height, IsUsingLinearFiltering());
|
||||
|
@ -943,15 +946,8 @@ void OpenGLHostDisplay::ApplyPostProcessingChain(GLuint final_target, s32 final_
|
|||
for (u32 i = 0; i < static_cast<u32>(m_post_processing_stages.size()); i++)
|
||||
{
|
||||
PostProcessingStage& pps = m_post_processing_stages[i];
|
||||
if (i == final_stage)
|
||||
{
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, final_target);
|
||||
}
|
||||
else
|
||||
{
|
||||
pps.output_texture.BindFramebuffer(GL_DRAW_FRAMEBUFFER);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, (i == final_stage) ? final_target : pps.output_texture.GetGLFramebufferID());
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
pps.program.Bind();
|
||||
|
||||
|
|
|
@ -713,7 +713,7 @@ bool VulkanHostDisplay::RenderScreenshot(u32 width, u32 height, std::vector<u32>
|
|||
"VulkanHostDisplay::RenderScreenshot: %ux%u", width, height);
|
||||
tex.TransitionToLayout(g_vulkan_context->GetCurrentCommandBuffer(), VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
|
||||
const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height, 0);
|
||||
const auto [left, top, draw_width, draw_height] = CalculateDrawRect(width, height);
|
||||
|
||||
if (!m_post_processing_chain.IsEmpty())
|
||||
{
|
||||
|
@ -1025,6 +1025,7 @@ bool VulkanHostDisplay::SetPostProcessingChain(const std::string_view& config)
|
|||
}
|
||||
Vulkan::Util::SetObjectName(g_vulkan_context->GetDevice(), m_post_processing_ubo.GetBuffer(),
|
||||
"Post Processing Uniform Buffer");
|
||||
m_post_processing_timer.Reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue