From 3c3bcd82fe6dfa8bdc2c9a9f33724ebfacd7dd40 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 27 Jul 2022 21:07:48 -0300 Subject: Add a sampler pool cache and improve texture pool cache (#3487) * Add a sampler pool cache and improve texture pool cache * Increase disposal timestamp delta more to be on the safe side * Nits * Use abstract class for PoolCache, remove factory callback --- Ryujinx.Graphics.Gpu/Image/TextureManager.cs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Image/TextureManager.cs') diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index 628c3159..fe0175a6 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -16,6 +16,7 @@ namespace Ryujinx.Graphics.Gpu.Image private readonly TextureBindingsManager _cpBindingsManager; private readonly TextureBindingsManager _gpBindingsManager; private readonly TexturePoolCache _texturePoolCache; + private readonly SamplerPoolCache _samplerPoolCache; private readonly Texture[] _rtColors; private readonly ITexture[] _rtHostColors; @@ -41,13 +42,15 @@ namespace Ryujinx.Graphics.Gpu.Image _channel = channel; TexturePoolCache texturePoolCache = new TexturePoolCache(context); + SamplerPoolCache samplerPoolCache = new SamplerPoolCache(context); float[] scales = new float[64]; new Span(scales).Fill(1f); - _cpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, scales, isCompute: true); - _gpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, scales, isCompute: false); + _cpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, scales, isCompute: true); + _gpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, scales, isCompute: false); _texturePoolCache = texturePoolCache; + _samplerPoolCache = samplerPoolCache; _rtColors = new Texture[Constants.TotalRenderTargets]; _rtHostColors = new ITexture[Constants.TotalRenderTargets]; @@ -368,6 +371,10 @@ namespace Ryujinx.Graphics.Gpu.Image // we must rebind everything. // Since compute work happens less often, we always do that // before and after the compute dispatch. + + _texturePoolCache.Tick(); + _samplerPoolCache.Tick(); + _cpBindingsManager.Rebind(); bool result = _cpBindingsManager.CommitBindings(specState); _gpBindingsManager.Rebind(); @@ -382,6 +389,9 @@ namespace Ryujinx.Graphics.Gpu.Image /// True if all bound textures match the current shader specialization state, false otherwise public bool CommitGraphicsBindings(ShaderSpecializationState specState) { + _texturePoolCache.Tick(); + _samplerPoolCache.Tick(); + bool result = _gpBindingsManager.CommitBindings(specState); UpdateRenderTargets(); @@ -501,6 +511,15 @@ namespace Ryujinx.Graphics.Gpu.Image _context.Renderer.Pipeline.SetRenderTargets(_rtHostColors, _rtHostDs); } + /// + /// Forces the texture and sampler pools to be re-loaded from the cache on next use. + /// + public void ReloadPools() + { + _cpBindingsManager.ReloadPools(); + _gpBindingsManager.ReloadPools(); + } + /// /// Forces all textures, samplers, images and render targets to be rebound the next time /// CommitGraphicsBindings is called. @@ -523,8 +542,8 @@ namespace Ryujinx.Graphics.Gpu.Image /// public void Dispose() { - _cpBindingsManager.Dispose(); - _gpBindingsManager.Dispose(); + // Textures are owned by the texture cache, so we shouldn't dispose the texture pool cache. + _samplerPoolCache.Dispose(); for (int i = 0; i < _rtColors.Length; i++) { -- cgit v1.2.3