From c30504e3b3bb64c44d993d6339f15ec6703a3c55 Mon Sep 17 00:00:00 2001
From: riperiperi <rhy3756547@hotmail.com>
Date: Fri, 29 Jan 2021 03:19:06 +0000
Subject: Use a descriptor cache for faster pool invalidation. (#1977)

* Use a descriptor cache for faster pool invalidation.

* Speed up comparison by casting to Vector256

Now we never need to worry about this ever again
---
 Ryujinx.Graphics.Gpu/Image/SamplerPool.cs | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

(limited to 'Ryujinx.Graphics.Gpu/Image/SamplerPool.cs')

diff --git a/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs b/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs
index ca13a7d6..1395aea2 100644
--- a/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs
+++ b/Ryujinx.Graphics.Gpu/Image/SamplerPool.cs
@@ -3,7 +3,7 @@ namespace Ryujinx.Graphics.Gpu.Image
     /// <summary>
     /// Sampler pool.
     /// </summary>
-    class SamplerPool : Pool<Sampler>
+    class SamplerPool : Pool<Sampler, SamplerDescriptor>
     {
         private int _sequenceNumber;
 
@@ -38,11 +38,13 @@ namespace Ryujinx.Graphics.Gpu.Image
 
             if (sampler == null)
             {
-                SamplerDescriptor descriptor = Context.PhysicalMemory.Read<SamplerDescriptor>(Address + (ulong)id * DescriptorSize);
+                SamplerDescriptor descriptor = GetDescriptor(id);
 
                 sampler = new Sampler(Context, descriptor);
 
                 Items[id] = sampler;
+
+                DescriptorCache[id] = descriptor;
             }
 
             return sampler;
@@ -65,6 +67,14 @@ namespace Ryujinx.Graphics.Gpu.Image
 
                 if (sampler != null)
                 {
+                    SamplerDescriptor descriptor = GetDescriptor(id);
+
+                    // If the descriptors are the same, the sampler is still valid.
+                    if (descriptor.Equals(ref DescriptorCache[id]))
+                    {
+                        continue;
+                    }
+
                     sampler.Dispose();
 
                     Items[id] = null;
-- 
cgit v1.2.3-70-g09d2