diff --git a/Ryujinx.Graphics.Gpu/Image/Texture.cs b/Ryujinx.Graphics.Gpu/Image/Texture.cs index 5a00ddd95b..7511bdfad3 100644 --- a/Ryujinx.Graphics.Gpu/Image/Texture.cs +++ b/Ryujinx.Graphics.Gpu/Image/Texture.cs @@ -54,10 +54,15 @@ namespace Ryujinx.Graphics.Gpu.Image public LinkedListNode CacheNode { get; set; } /// - /// Event to fire when texture data modified by the GPU. + /// Event to fire when texture data is modified by the GPU. /// public event Action Modified; + /// + /// Event to fire when texture data is disposed. + /// + public event Action Disposed; + /// /// Start address of the texture in guest memory. /// @@ -1020,6 +1025,8 @@ namespace Ryujinx.Graphics.Gpu.Image _arrayViewTexture?.Dispose(); _arrayViewTexture = null; + + Disposed?.Invoke(this); } /// diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index 10f4f5e30c..13de1b1006 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -585,6 +585,7 @@ namespace Ryujinx.Graphics.Gpu.Image { _cache.Add(texture); texture.Modified += CacheTextureModified; + texture.Disposed += CacheTextureDisposed; } _textures.Add(texture); @@ -603,6 +604,15 @@ namespace Ryujinx.Graphics.Gpu.Image _modified.Add(texture); } + /// + /// Signaled when a cache texture is disposed, so it can be removed from the set of modified textures if present. + /// + /// The texture that was diosposed. + private void CacheTextureDisposed(Texture texture) + { + _modified.Remove(texture); + } + /// /// Resizes the temporary buffer used for range list intersection results, if it has grown too much. /// @@ -785,6 +795,7 @@ namespace Ryujinx.Graphics.Gpu.Image { foreach (Texture texture in _textures) { + _modified.Remove(texture); texture.Dispose(); } }