From f0e27a23a5a4c834cc846e415c9cce0597e8d6c5 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Tue, 17 Jan 2023 03:39:46 +0000 Subject: Add short duration texture cache (#3754) * Add short duration texture cache This texture cache takes textures that lose their last pool reference and keeps them alive until the next frame, or until an incompatible overlap removes it. This is done since under certain circumstances, a texture's reference can be wiped from a pool despite it still being in use - though typically the reference will return when rendering the next frame. While this may slightly increase texture memory usage when quickly going through a bunch of temporary textures, it's still bounded due to the overlap removal rule. This greatly increases performance in Hyrule Warriors: Age of Calamity. It may positively affect some UE4 games which dip framerate severely under certain circumstances. * Small optimization * Don't forget this. * Add short cache dictionary * Address feedback * Address some feedback --- Ryujinx.Graphics.Gpu/Image/Texture.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'Ryujinx.Graphics.Gpu/Image/Texture.cs') diff --git a/Ryujinx.Graphics.Gpu/Image/Texture.cs b/Ryujinx.Graphics.Gpu/Image/Texture.cs index f0c31be6..cfe57756 100644 --- a/Ryujinx.Graphics.Gpu/Image/Texture.cs +++ b/Ryujinx.Graphics.Gpu/Image/Texture.cs @@ -138,6 +138,10 @@ namespace Ryujinx.Graphics.Gpu.Image public LinkedListNode CacheNode { get; set; } /// + /// Entry for this texture in the short duration cache, if present. + /// + public ShortTextureCacheEntry ShortCacheEntry { get; set; } + /// Physical memory ranges where the texture data is located. /// public MultiRange Range { get; private set; } @@ -1555,6 +1559,20 @@ namespace Ryujinx.Graphics.Gpu.Image _poolOwners.Add(new TexturePoolOwner { Pool = pool, ID = id }); } _referenceCount++; + + if (ShortCacheEntry != null) + { + _physicalMemory.TextureCache.RemoveShortCache(this); + } + } + + /// + /// Indicates that the texture has one reference left, and will delete on reference decrement. + /// + /// True if there is one reference remaining, false otherwise + public bool HasOneReference() + { + return _referenceCount == 1; } /// @@ -1624,6 +1642,14 @@ namespace Ryujinx.Graphics.Gpu.Image _poolOwners.Clear(); } + if (ShortCacheEntry != null && _context.IsGpuThread()) + { + // If this is called from another thread (unmapped), the short cache will + // have to remove this texture on a future tick. + + _physicalMemory.TextureCache.RemoveShortCache(this); + } + InvalidatedSequence++; } -- cgit v1.2.3