From 887e3830bac95b0418201af337756564c89963d0 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 9 Feb 2018 21:41:31 +1000 Subject: [PATCH] VideoBackends: Restore the framebuffer as part of the API state It's not often we switch out to draw to the EFB anyway. --- Source/Core/VideoBackends/D3D/DXTexture.cpp | 1 - Source/Core/VideoBackends/D3D/FramebufferManager.cpp | 2 -- Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp | 2 -- Source/Core/VideoBackends/D3D/Render.cpp | 9 ++------- Source/Core/VideoBackends/D3D/TextureCache.cpp | 2 -- Source/Core/VideoBackends/OGL/OGLTexture.cpp | 1 - Source/Core/VideoBackends/OGL/Render.cpp | 5 ++--- Source/Core/VideoBackends/OGL/TextureCache.cpp | 2 -- Source/Core/VideoBackends/OGL/TextureConverter.cpp | 3 --- Source/Core/VideoBackends/Vulkan/Renderer.cpp | 3 +++ 10 files changed, 7 insertions(+), 23 deletions(-) diff --git a/Source/Core/VideoBackends/D3D/DXTexture.cpp b/Source/Core/VideoBackends/D3D/DXTexture.cpp index 7be3264a74..ac21d3041c 100644 --- a/Source/Core/VideoBackends/D3D/DXTexture.cpp +++ b/Source/Core/VideoBackends/D3D/DXTexture.cpp @@ -144,7 +144,6 @@ void DXTexture::ScaleRectangleFromTexture(const AbstractTexture* source, VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader(), 1.0, 0); - FramebufferManager::BindEFBRenderTarget(); g_renderer->RestoreAPIState(); } diff --git a/Source/Core/VideoBackends/D3D/FramebufferManager.cpp b/Source/Core/VideoBackends/D3D/FramebufferManager.cpp index 30fbde261e..e7e8fa9ddc 100644 --- a/Source/Core/VideoBackends/D3D/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/D3D/FramebufferManager.cpp @@ -87,9 +87,7 @@ D3DTexture2D*& FramebufferManager::GetResolvedEFBDepthTexture() PixelShaderCache::GetDepthResolveProgram(), VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader()); - BindEFBRenderTarget(); g_renderer->RestoreAPIState(); - return m_efb.resolved_depth_tex; } else diff --git a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp index b1ccefd8f0..e4d981bcc4 100644 --- a/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp +++ b/Source/Core/VideoBackends/D3D/PSTextureEncoder.cpp @@ -131,8 +131,6 @@ void PSTextureEncoder::Encode(u8* dst, const EFBCopyParams& params, u32 native_w } } - // Restore API - FramebufferManager::BindEFBRenderTarget(); g_renderer->RestoreAPIState(); } diff --git a/Source/Core/VideoBackends/D3D/Render.cpp b/Source/Core/VideoBackends/D3D/Render.cpp index f1751e44f2..5cc4832c56 100644 --- a/Source/Core/VideoBackends/D3D/Render.cpp +++ b/Source/Core/VideoBackends/D3D/Render.cpp @@ -450,7 +450,6 @@ u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) VertexShaderCache::GetSimpleInputLayout()); // Restore expected game state. - FramebufferManager::BindEFBRenderTarget(); RestoreAPIState(); // Copy the pixel from the renderable to cpu-readable buffer. @@ -525,7 +524,6 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num D3D11_VIEWPORT vp = CD3D11_VIEWPORT(0.0f, 0.0f, (float)GetTargetWidth(), (float)GetTargetHeight()); D3D::context->RSSetViewports(1, &vp); - FramebufferManager::BindEFBRenderTarget(false); } else // if (type == EFBAccessType::PokeZ) { @@ -536,7 +534,6 @@ void Renderer::PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num CD3D11_VIEWPORT(0.0f, 0.0f, (float)GetTargetWidth(), (float)GetTargetHeight()); D3D::context->RSSetViewports(1, &vp); - FramebufferManager::BindEFBRenderTarget(); } D3D::DrawEFBPokeQuads(type, points, num_points); @@ -627,10 +624,8 @@ void Renderer::ReinterpretPixelData(unsigned int convtype) GetTargetHeight(), pixel_shader, VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader()); - RestoreAPIState(); - FramebufferManager::SwapReinterpretTexture(); - FramebufferManager::BindEFBRenderTarget(); + RestoreAPIState(); } void Renderer::SetBlendingState(const BlendingState& state) @@ -707,7 +702,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region // begin next frame RestoreAPIState(); - FramebufferManager::BindEFBRenderTarget(); } void Renderer::CheckForSurfaceChange() @@ -769,6 +763,7 @@ void Renderer::ResetAPIState() void Renderer::RestoreAPIState() { // Gets us back into a more game-like state. + FramebufferManager::BindEFBRenderTarget(); BPFunctions::SetViewport(); BPFunctions::SetScissor(); } diff --git a/Source/Core/VideoBackends/D3D/TextureCache.cpp b/Source/Core/VideoBackends/D3D/TextureCache.cpp index e9ad781dcf..b0974f3cc3 100644 --- a/Source/Core/VideoBackends/D3D/TextureCache.cpp +++ b/Source/Core/VideoBackends/D3D/TextureCache.cpp @@ -160,7 +160,6 @@ void TextureCache::ConvertTexture(TCacheEntry* destination, TCacheEntry* source, VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader()); - FramebufferManager::BindEFBRenderTarget(); g_renderer->RestoreAPIState(); } @@ -275,7 +274,6 @@ void TextureCache::CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, pixel_shader, VertexShaderCache::GetSimpleVertexShader(), VertexShaderCache::GetSimpleInputLayout(), GeometryShaderCache::GetCopyGeometryShader()); - FramebufferManager::BindEFBRenderTarget(); g_renderer->RestoreAPIState(); } diff --git a/Source/Core/VideoBackends/OGL/OGLTexture.cpp b/Source/Core/VideoBackends/OGL/OGLTexture.cpp index 680e1aceae..db0ffd8e5a 100644 --- a/Source/Core/VideoBackends/OGL/OGLTexture.cpp +++ b/Source/Core/VideoBackends/OGL/OGLTexture.cpp @@ -219,7 +219,6 @@ void OGLTexture::ScaleRectangleFromTexture(const AbstractTexture* source, glUniform4f(TextureCache::GetInstance()->GetColorCopyPositionUniform(), float(srcrect.left), float(srcrect.top), float(srcrect.GetWidth()), float(srcrect.GetHeight())); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - FramebufferManager::SetFramebuffer(0); g_renderer->RestoreAPIState(); } diff --git a/Source/Core/VideoBackends/OGL/Render.cpp b/Source/Core/VideoBackends/OGL/Render.cpp index 99666ed531..fab642e71b 100644 --- a/Source/Core/VideoBackends/OGL/Render.cpp +++ b/Source/Core/VideoBackends/OGL/Render.cpp @@ -1416,9 +1416,6 @@ void Renderer::SwapImpl(AbstractTexture* texture, const EFBRectangle& xfb_region g_texture_cache->Cleanup(frameCount); ProgramShaderCache::RetrieveAsyncShaders(); - // Render to the framebuffer. - FramebufferManager::SetFramebuffer(0); - RestoreAPIState(); g_Config.iSaveTargetId = 0; @@ -1499,6 +1496,8 @@ void Renderer::ResetAPIState() void Renderer::RestoreAPIState() { + FramebufferManager::SetFramebuffer(0); + // Gets us back into a more game-like state. glEnable(GL_SCISSOR_TEST); if (g_ActiveConfig.backend_info.bSupportsDepthClamp) diff --git a/Source/Core/VideoBackends/OGL/TextureCache.cpp b/Source/Core/VideoBackends/OGL/TextureCache.cpp index 65324c608b..bd2e1cfcd1 100644 --- a/Source/Core/VideoBackends/OGL/TextureCache.cpp +++ b/Source/Core/VideoBackends/OGL/TextureCache.cpp @@ -323,7 +323,6 @@ void TextureCache::ConvertTexture(TCacheEntry* destination, TCacheEntry* source, ProgramShaderCache::BindVertexFormat(nullptr); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - FramebufferManager::SetFramebuffer(0); g_renderer->RestoreAPIState(); } @@ -540,7 +539,6 @@ void TextureCache::CopyEFBToCacheEntry(TCacheEntry* entry, bool is_depth_copy, ProgramShaderCache::BindVertexFormat(nullptr); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - FramebufferManager::SetFramebuffer(0); g_renderer->RestoreAPIState(); } } diff --git a/Source/Core/VideoBackends/OGL/TextureConverter.cpp b/Source/Core/VideoBackends/OGL/TextureConverter.cpp index e7fa050e3f..a1b12db772 100644 --- a/Source/Core/VideoBackends/OGL/TextureConverter.cpp +++ b/Source/Core/VideoBackends/OGL/TextureConverter.cpp @@ -133,8 +133,6 @@ static void EncodeToRamUsingShader(GLuint srcTexture, u8* destAddr, u32 dst_line s_encoding_readback_texture->CopyFromTexture(s_encoding_render_texture.get(), copy_rect, 0, 0, copy_rect); s_encoding_readback_texture->ReadTexels(copy_rect, destAddr, writeStride); - - FramebufferManager::SetFramebuffer(0); } void EncodeToRamFromTexture(u8* dest_ptr, const EFBCopyParams& params, u32 native_width, @@ -157,7 +155,6 @@ void EncodeToRamFromTexture(u8* dest_ptr, const EFBCopyParams& params, u32 nativ EncodeToRamUsingShader(read_texture, dest_ptr, bytes_per_row, num_blocks_y, memory_stride, scale_by_half && !params.depth, params.y_scale); - FramebufferManager::SetFramebuffer(0); g_renderer->RestoreAPIState(); } diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index e4a7401c54..12de136162 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -1036,6 +1036,9 @@ void Renderer::ResetAPIState() void Renderer::RestoreAPIState() { + StateTracker::GetInstance()->EndRenderPass(); + BindEFBToStateTracker(); + // Instruct the state tracker to re-bind everything before the next draw StateTracker::GetInstance()->SetPendingRebind(); }