GS/Vulkan: Fix clear order in Merge/Interlace

Fixes blank frame when changing resolutions.
This commit is contained in:
Stenzek 2023-03-05 16:22:41 +10:00 committed by refractionpcsx2
parent ac02bcbe33
commit 5b88e637d8
2 changed files with 11 additions and 22 deletions

View File

@ -657,12 +657,6 @@ void GSDevice12::DoStretchRect(GSTexture12* sTex, const GSVector4& sRect, GSText
BeginRenderPassForStretchRect(dTex, dtex_rc, dst_rc); BeginRenderPassForStretchRect(dTex, dtex_rc, dst_rc);
DrawStretchRect(sRect, dRect, size); DrawStretchRect(sRect, dRect, size);
if (!drawing_to_current_rt)
{
EndRenderPass();
static_cast<GSTexture12*>(dTex)->TransitionToState(D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
}
} }
void GSDevice12::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds) void GSDevice12::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds)
@ -772,6 +766,7 @@ void GSDevice12::DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex,
BeginRenderPass(D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE, BeginRenderPass(D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE,
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS,
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS, c); D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS, c);
dTex->SetState(GSTexture::State::Dirty);
} }
else if (!InRenderPass()) else if (!InRenderPass())
{ {
@ -828,15 +823,13 @@ void GSDevice12::DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool
OMSetRenderTargets(dTex, nullptr, rc); OMSetRenderTargets(dTex, nullptr, rc);
SetUtilityRootSignature(); SetUtilityRootSignature();
SetUtilityTexture(sTex, linear ? m_linear_sampler_cpu : m_point_sampler_cpu); SetUtilityTexture(sTex, linear ? m_linear_sampler_cpu : m_point_sampler_cpu);
BeginRenderPass(D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_PRESERVE, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE, BeginRenderPassForStretchRect(static_cast<GSTexture12*>(dTex), rc, rc, false);
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS);
SetPipeline(m_interlace[shader].get()); SetPipeline(m_interlace[shader].get());
SetUtilityPushConstants(&cb, sizeof(cb)); SetUtilityPushConstants(&cb, sizeof(cb));
DrawStretchRect(sRect, dRect, dTex->GetSize()); DrawStretchRect(sRect, dRect, dTex->GetSize());
EndRenderPass(); EndRenderPass();
// this texture is going to get used as an input, so make sure we don't read undefined data // this texture is going to get used as an input, so make sure we don't read undefined data
static_cast<GSTexture12*>(dTex)->CommitClear();
static_cast<GSTexture12*>(dTex)->TransitionToState(D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE); static_cast<GSTexture12*>(dTex)->TransitionToState(D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
} }
@ -850,6 +843,7 @@ void GSDevice12::DoShadeBoost(GSTexture* sTex, GSTexture* dTex, const float para
SetUtilityTexture(sTex, m_point_sampler_cpu); SetUtilityTexture(sTex, m_point_sampler_cpu);
BeginRenderPass(D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_DISCARD, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE, BeginRenderPass(D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_DISCARD, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE,
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS); D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS);
dTex->SetState(GSTexture::State::Dirty);
SetPipeline(m_shadeboost_pipeline.get()); SetPipeline(m_shadeboost_pipeline.get());
SetUtilityPushConstants(params, sizeof(float) * 4); SetUtilityPushConstants(params, sizeof(float) * 4);
DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize()); DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize());
@ -868,6 +862,7 @@ void GSDevice12::DoFXAA(GSTexture* sTex, GSTexture* dTex)
SetUtilityTexture(sTex, m_linear_sampler_cpu); SetUtilityTexture(sTex, m_linear_sampler_cpu);
BeginRenderPass(D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_DISCARD, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE, BeginRenderPass(D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_DISCARD, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE,
D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS); D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_NO_ACCESS, D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_NO_ACCESS);
dTex->SetState(GSTexture::State::Dirty);
SetPipeline(m_fxaa_pipeline.get()); SetPipeline(m_fxaa_pipeline.get());
DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize()); DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize());
EndRenderPass(); EndRenderPass();

View File

@ -730,7 +730,7 @@ void GSDeviceVK::DoStretchRect(GSTextureVK* sTex, const GSVector4& sRect, GSText
if (!is_present) if (!is_present)
{ {
OMSetRenderTargets(depth ? nullptr : dTex, depth ? dTex : nullptr, dst_rc, false); OMSetRenderTargets(depth ? nullptr : dTex, depth ? dTex : nullptr, dst_rc, false);
if (InRenderPass() && !CheckRenderPassArea(dst_rc)) if (InRenderPass() && (!CheckRenderPassArea(dst_rc) || dTex->GetState() == GSTexture::State::Cleared))
EndRenderPass(); EndRenderPass();
} }
else else
@ -739,17 +739,10 @@ void GSDeviceVK::DoStretchRect(GSTextureVK* sTex, const GSVector4& sRect, GSText
m_dirty_flags &= ~(DIRTY_FLAG_VIEWPORT | DIRTY_FLAG_SCISSOR); m_dirty_flags &= ~(DIRTY_FLAG_VIEWPORT | DIRTY_FLAG_SCISSOR);
} }
const bool drawing_to_current_rt = (is_present || InRenderPass()); if (!is_present && !InRenderPass())
if (!drawing_to_current_rt)
BeginRenderPassForStretchRect(dTex, dtex_rc, dst_rc); BeginRenderPassForStretchRect(dTex, dtex_rc, dst_rc);
DrawStretchRect(sRect, dRect, size); DrawStretchRect(sRect, dRect, size);
if (!drawing_to_current_rt)
{
EndRenderPass();
static_cast<GSTextureVK*>(dTex)->TransitionToLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
} }
void GSDeviceVK::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds) void GSDeviceVK::DrawStretchRect(const GSVector4& sRect, const GSVector4& dRect, const GSVector2i& ds)
@ -889,6 +882,7 @@ void GSDeviceVK::DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex,
EndRenderPass(); EndRenderPass();
OMSetRenderTargets(dTex, nullptr, darea, false); OMSetRenderTargets(dTex, nullptr, darea, false);
BeginClearRenderPass(m_utility_color_render_pass_clear, darea, c); BeginClearRenderPass(m_utility_color_render_pass_clear, darea, c);
dTex->SetState(GSTexture::State::Dirty);
} }
else if (!InRenderPass()) else if (!InRenderPass())
{ {
@ -944,14 +938,12 @@ void GSDeviceVK::DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool
EndRenderPass(); EndRenderPass();
OMSetRenderTargets(dTex, nullptr, rc, false); OMSetRenderTargets(dTex, nullptr, rc, false);
SetUtilityTexture(sTex, linear ? m_linear_sampler : m_point_sampler); SetUtilityTexture(sTex, linear ? m_linear_sampler : m_point_sampler);
BeginRenderPass(m_utility_color_render_pass_load, rc); BeginRenderPassForStretchRect(static_cast<GSTextureVK*>(dTex), rc, rc, false);
SetPipeline(m_interlace[shader]); SetPipeline(m_interlace[shader]);
SetUtilityPushConstants(&cb, sizeof(cb)); SetUtilityPushConstants(&cb, sizeof(cb));
DrawStretchRect(sRect, dRect, dTex->GetSize()); DrawStretchRect(sRect, dRect, dTex->GetSize());
EndRenderPass(); EndRenderPass();
// this texture is going to get used as an input, so make sure we don't read undefined data
static_cast<GSTextureVK*>(dTex)->CommitClear();
static_cast<GSTextureVK*>(dTex)->TransitionToLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); static_cast<GSTextureVK*>(dTex)->TransitionToLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
} }
@ -963,6 +955,7 @@ void GSDeviceVK::DoShadeBoost(GSTexture* sTex, GSTexture* dTex, const float para
OMSetRenderTargets(dTex, nullptr, dRect, false); OMSetRenderTargets(dTex, nullptr, dRect, false);
SetUtilityTexture(sTex, m_point_sampler); SetUtilityTexture(sTex, m_point_sampler);
BeginRenderPass(m_utility_color_render_pass_discard, dRect); BeginRenderPass(m_utility_color_render_pass_discard, dRect);
dTex->SetState(GSTexture::State::Dirty);
SetPipeline(m_shadeboost_pipeline); SetPipeline(m_shadeboost_pipeline);
SetUtilityPushConstants(params, sizeof(float) * 4); SetUtilityPushConstants(params, sizeof(float) * 4);
DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize()); DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize());
@ -979,6 +972,7 @@ void GSDeviceVK::DoFXAA(GSTexture* sTex, GSTexture* dTex)
OMSetRenderTargets(dTex, nullptr, dRect, false); OMSetRenderTargets(dTex, nullptr, dRect, false);
SetUtilityTexture(sTex, m_linear_sampler); SetUtilityTexture(sTex, m_linear_sampler);
BeginRenderPass(m_utility_color_render_pass_discard, dRect); BeginRenderPass(m_utility_color_render_pass_discard, dRect);
dTex->SetState(GSTexture::State::Dirty);
SetPipeline(m_fxaa_pipeline); SetPipeline(m_fxaa_pipeline);
DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize()); DrawStretchRect(sRect, GSVector4(dRect), dTex->GetSize());
EndRenderPass(); EndRenderPass();
@ -2434,7 +2428,7 @@ void GSDeviceVK::PSSetShaderResource(int i, GSTexture* sr, bool check_state)
{ {
if (vkTex->GetTexture().GetLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL && InRenderPass()) if (vkTex->GetTexture().GetLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL && InRenderPass())
{ {
// Console.Warning("Ending render pass due to resource transition"); GL_INS("Ending render pass due to resource transition");
EndRenderPass(); EndRenderPass();
} }