diff options
author | riperiperi <rhy3756547@hotmail.com> | 2023-01-17 03:39:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-17 04:39:46 +0100 |
commit | f0e27a23a5a4c834cc846e415c9cce0597e8d6c5 (patch) | |
tree | e7ec2acf2838b5306cee3803a5d31ff0e302e402 /Ryujinx.Graphics.Gpu/Image/TexturePool.cs | |
parent | e68650237db2d5fd0fb78d9e21378d139338246f (diff) |
Add short duration texture cache (#3754)1.1.566
* 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
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Image/TexturePool.cs')
-rw-r--r-- | Ryujinx.Graphics.Gpu/Image/TexturePool.cs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs index 4d2544e2..fc99fc99 100644 --- a/Ryujinx.Graphics.Gpu/Image/TexturePool.cs +++ b/Ryujinx.Graphics.Gpu/Image/TexturePool.cs @@ -52,16 +52,21 @@ namespace Ryujinx.Graphics.Gpu.Image if (texture == null) { - TextureInfo info = GetInfo(descriptor, out int layerSize); + texture = PhysicalMemory.TextureCache.FindShortCache(descriptor); - ProcessDereferenceQueue(); - - texture = PhysicalMemory.TextureCache.FindOrCreateTexture(_channel.MemoryManager, TextureSearchFlags.ForSampler, info, layerSize); - - // If this happens, then the texture address is invalid, we can't add it to the cache. if (texture == null) { - return ref descriptor; + TextureInfo info = GetInfo(descriptor, out int layerSize); + + ProcessDereferenceQueue(); + + texture = PhysicalMemory.TextureCache.FindOrCreateTexture(_channel.MemoryManager, TextureSearchFlags.ForSampler, info, layerSize); + + // If this happens, then the texture address is invalid, we can't add it to the cache. + if (texture == null) + { + return ref descriptor; + } } texture.IncrementReferenceCount(this, id); @@ -208,15 +213,21 @@ namespace Ryujinx.Graphics.Gpu.Image if (texture != null) { - TextureDescriptor descriptor = PhysicalMemory.Read<TextureDescriptor>(address); + ref TextureDescriptor cachedDescriptor = ref DescriptorCache[id]; + ref readonly TextureDescriptor descriptor = ref GetDescriptorRefAddress(address); // If the descriptors are the same, the texture is the same, // we don't need to remove as it was not modified. Just continue. - if (descriptor.Equals(ref DescriptorCache[id])) + if (descriptor.Equals(ref cachedDescriptor)) { continue; } + if (texture.HasOneReference()) + { + _channel.MemoryManager.Physical.TextureCache.AddShortCache(texture, ref cachedDescriptor); + } + texture.DecrementReferenceCount(this, id); Items[id] = null; |