From b18ef8e3a00980595f45c7fe184dcb160dcc3cb9 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sun, 29 Mar 2020 09:48:39 -0300
Subject: Workaround for AMD and Intel view format bug (#1050)

* Workaround for Intel view format bug

* Dispose of the intermmediate texture aswell

* Apply workaround on AMD aswell
---
 Ryujinx.Graphics.OpenGL/Framebuffer.cs | 37 +++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)

(limited to 'Ryujinx.Graphics.OpenGL/Framebuffer.cs')

diff --git a/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/Ryujinx.Graphics.OpenGL/Framebuffer.cs
index d416bd03..23f015b1 100644
--- a/Ryujinx.Graphics.OpenGL/Framebuffer.cs
+++ b/Ryujinx.Graphics.OpenGL/Framebuffer.cs
@@ -10,9 +10,13 @@ namespace Ryujinx.Graphics.OpenGL
 
         private FramebufferAttachment _lastDsAttachment;
 
+        private readonly TextureView[] _colors;
+
         public Framebuffer()
         {
             Handle = GL.GenFramebuffer();
+
+            _colors = new TextureView[8];
         }
 
         public void Bind()
@@ -22,11 +26,19 @@ namespace Ryujinx.Graphics.OpenGL
 
         public void AttachColor(int index, TextureView color)
         {
-            GL.FramebufferTexture(
-                FramebufferTarget.Framebuffer,
-                FramebufferAttachment.ColorAttachment0 + index,
-                color?.Handle ?? 0,
-                0);
+            FramebufferAttachment attachment = FramebufferAttachment.ColorAttachment0 + index;
+
+            if (HwCapabilities.Vendor == HwCapabilities.GpuVendor.Amd ||
+                HwCapabilities.Vendor == HwCapabilities.GpuVendor.Intel)
+            {
+                GL.FramebufferTexture(FramebufferTarget.Framebuffer, attachment, color?.GetIncompatibleFormatViewHandle() ?? 0, 0);
+
+                _colors[index] = color;
+            }
+            else
+            {
+                GL.FramebufferTexture(FramebufferTarget.Framebuffer, attachment, color?.Handle ?? 0, 0);
+            }
         }
 
         public void AttachDepthStencil(TextureView depthStencil)
@@ -68,6 +80,21 @@ namespace Ryujinx.Graphics.OpenGL
             }
         }
 
+        public void SignalModified()
+        {
+            if (HwCapabilities.Vendor == HwCapabilities.GpuVendor.Amd ||
+                HwCapabilities.Vendor == HwCapabilities.GpuVendor.Intel)
+            {
+                for (int i = 0; i < 8; i++)
+                {
+                    if (_colors[i] != null)
+                    {
+                        _colors[i].SignalModified();
+                    }
+                }
+            }
+        }
+
         public void SetDrawBuffers(int colorsCount)
         {
             DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorsCount];
-- 
cgit v1.2.3-70-g09d2