From 625f5fb88ab992a0778f86c8acb95b1789c503a8 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sat, 25 Jun 2022 11:52:38 -0300
Subject: [PATCH] Account for pool change on texture bindings cache (#3420)

* Account for pool change on texture bindings cache

* Reduce the number of checks needed
---
 .../Image/TextureBindingsManager.cs                | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs
index a990528ed4..18f5a74a0a 100644
--- a/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs
+++ b/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs
@@ -32,6 +32,9 @@ namespace Ryujinx.Graphics.Gpu.Image
         private readonly GpuChannel _channel;
         private readonly TexturePoolCache _texturePoolCache;
 
+        private TexturePool _cachedTexturePool;
+        private SamplerPool _cachedSamplerPool;
+
         private readonly TextureBindingInfo[][] _textureBindings;
         private readonly TextureBindingInfo[][] _imageBindings;
 
@@ -343,9 +346,14 @@ namespace Ryujinx.Graphics.Gpu.Image
                 ? _texturePoolCache.FindOrCreate(_channel, texturePoolAddress, _texturePoolMaximumId)
                 : null;
 
+            SamplerPool samplerPool = _samplerPool;
+
             // Check if the texture pool has been modified since bindings were last committed.
             // If it wasn't, then it's possible to avoid looking up textures again when the handle remains the same.
-            bool poolModified = false;
+            bool poolModified = _cachedTexturePool != texturePool || _cachedSamplerPool != samplerPool;
+
+            _cachedTexturePool = texturePool;
+            _cachedSamplerPool = samplerPool;
 
             if (texturePool != null)
             {
@@ -358,9 +366,9 @@ namespace Ryujinx.Graphics.Gpu.Image
                 }
             }
 
-            if (_samplerPool != null)
+            if (samplerPool != null)
             {
-                int samplerPoolSequence = _samplerPool.CheckModified();
+                int samplerPoolSequence = samplerPool.CheckModified();
 
                 if (_samplerPoolSequence != samplerPoolSequence)
                 {