From 7527c5b906b386eedaf285a0b0923174e37bb6d4 Mon Sep 17 00:00:00 2001 From: Mary Date: Tue, 1 Jun 2021 09:29:01 +0200 Subject: [PATCH] Avoid clearing alpha channel by handle when presenting (#2323) * Avoid clearning alpha channel by handle when presenting Previous code was binding then blitting while the framebuffer was bound and then clearing the alpha channel by its handle. This ended up triggering a bug since AMD driver 21.4.1 ending up clearing the whole framebuffer as a result. New code fix this weird logic by applying the clear on the bound framebuffer. Close #2236. * Address rip's comments * Fix AMD being broken once again --- Ryujinx.Graphics.OpenGL/Pipeline.cs | 2 +- Ryujinx.Graphics.OpenGL/Window.cs | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index fcb0fdf1b..ed3507a3d 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -1232,7 +1232,7 @@ namespace Ryujinx.Graphics.OpenGL } } - private void RestoreComponentMask(int index) + public void RestoreComponentMask(int index) { // If the bound render target is bgra, swap the red and blue masks. uint redMask = _fpIsBgra[index] == 0 ? 1u : 4u; diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs index 5de2a6453..b7525ae51 100644 --- a/Ryujinx.Graphics.OpenGL/Window.cs +++ b/Ryujinx.Graphics.OpenGL/Window.cs @@ -1,4 +1,3 @@ -using OpenTK.Graphics; using OpenTK.Graphics.OpenGL; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; @@ -39,12 +38,8 @@ namespace Ryujinx.Graphics.OpenGL private void CopyTextureToFrameBufferRGB(int drawFramebuffer, int readFramebuffer, TextureView view, ImageCrop crop) { - bool[] oldFramebufferColorWritemask = new bool[4]; - (int oldDrawFramebufferHandle, int oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers(); - GL.GetBoolean(GetIndexedPName.ColorWritemask, drawFramebuffer, oldFramebufferColorWritemask); - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, drawFramebuffer); GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, readFramebuffer); @@ -124,13 +119,14 @@ namespace Ryujinx.Graphics.OpenGL BlitFramebufferFilter.Linear); // Remove Alpha channel - GL.ColorMask(drawFramebuffer, false, false, false, true); - GL.ClearBuffer(ClearBuffer.Color, drawFramebuffer, new float[] { 0.0f, 0.0f, 0.0f, 1.0f }); - GL.ColorMask(drawFramebuffer, - oldFramebufferColorWritemask[0], - oldFramebufferColorWritemask[1], - oldFramebufferColorWritemask[2], - oldFramebufferColorWritemask[3]); + GL.ColorMask(false, false, false, true); + GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); + GL.Clear(ClearBufferMask.ColorBufferBit); + + for (int i = 0; i < Constants.MaxRenderTargets; i++) + { + ((Pipeline)_renderer.Pipeline).RestoreComponentMask(i); + } GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle);