From b944941733befdfbae802c29c496fe5125f045e2 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Mon, 31 Jan 2022 00:11:43 -0300
Subject: [PATCH] Fix bug that could cause depth buffer to be missing after
 clear (#3067)

---
 .../Engine/Threed/StateUpdater.cs                | 16 ++++++++--------
 Ryujinx.Graphics.Gpu/Image/TextureManager.cs     |  1 +
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
index 1a9aeb4426..a65fc9085f 100644
--- a/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
+++ b/Ryujinx.Graphics.Gpu/Engine/Threed/StateUpdater.cs
@@ -369,14 +369,14 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
 
                 if (color != null)
                 {
-                    if (clipRegionWidth > color.Width)
+                    if (clipRegionWidth > color.Width / samplesInX)
                     {
-                        clipRegionWidth = color.Width;
+                        clipRegionWidth = color.Width / samplesInX;
                     }
 
-                    if (clipRegionHeight > color.Height)
+                    if (clipRegionHeight > color.Height / samplesInY)
                     {
-                        clipRegionHeight = color.Height;
+                        clipRegionHeight = color.Height / samplesInY;
                     }
                 }
             }
@@ -400,14 +400,14 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
 
                 if (depthStencil != null)
                 {
-                    if (clipRegionWidth > depthStencil.Width)
+                    if (clipRegionWidth > depthStencil.Width / samplesInX)
                     {
-                        clipRegionWidth = depthStencil.Width;
+                        clipRegionWidth = depthStencil.Width / samplesInX;
                     }
 
-                    if (clipRegionHeight > depthStencil.Height)
+                    if (clipRegionHeight > depthStencil.Height / samplesInY)
                     {
-                        clipRegionHeight = depthStencil.Height;
+                        clipRegionHeight = depthStencil.Height / samplesInY;
                     }
                 }
             }
diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs
index 90e26442ba..a1c292912d 100644
--- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs
+++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs
@@ -434,6 +434,7 @@ namespace Ryujinx.Graphics.Gpu.Image
         {
             new Span<ITexture>(_rtHostColors).Fill(null);
             _rtHostColors[index] = _rtColors[index]?.HostTexture;
+            _rtHostDs = null;
 
             _context.Renderer.Pipeline.SetRenderTargets(_rtHostColors, null);
         }