aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.OpenGL/Image
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Graphics.OpenGL/Image')
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs5
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs33
-rw-r--r--Ryujinx.Graphics.OpenGL/Image/TextureView.cs32
3 files changed, 66 insertions, 4 deletions
diff --git a/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs
index 2c69571c..6df2b630 100644
--- a/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs
@@ -67,5 +67,10 @@ namespace Ryujinx.Graphics.OpenGL.Image
Handle = 0;
}
}
+
+ public void Release()
+ {
+ Dispose();
+ }
}
}
diff --git a/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs b/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs
index ed258aee..635b6c2c 100644
--- a/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs
@@ -16,6 +16,8 @@ namespace Ryujinx.Graphics.OpenGL.Image
private int _viewsCount;
+ internal ITexture DefaultView { get; private set; }
+
public TextureStorage(Renderer renderer, TextureCreateInfo info, float scaleFactor)
{
_renderer = renderer;
@@ -147,7 +149,9 @@ namespace Ryujinx.Graphics.OpenGL.Image
public ITexture CreateDefaultView()
{
- return CreateView(Info, 0, 0);
+ DefaultView = CreateView(Info, 0, 0);
+
+ return DefaultView;
}
public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel)
@@ -167,12 +171,37 @@ namespace Ryujinx.Graphics.OpenGL.Image
// If we don't have any views, then the storage is now useless, delete it.
if (--_viewsCount == 0)
{
- Dispose();
+ if (DefaultView == null)
+ {
+ Dispose();
+ }
+ else
+ {
+ // If the default view still exists, we can put it into the resource pool.
+ Release();
+ }
}
}
+ /// <summary>
+ /// Release the TextureStorage to the resource pool without disposing its handle.
+ /// </summary>
+ public void Release()
+ {
+ _viewsCount = 1; // When we are used again, we will have the default view.
+
+ _renderer.ResourcePool.AddTexture((TextureView)DefaultView);
+ }
+
+ public void DeleteDefault()
+ {
+ DefaultView = null;
+ }
+
public void Dispose()
{
+ DefaultView = null;
+
if (Handle != 0)
{
GL.DeleteTexture(Handle);
diff --git a/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
index 2d50eba5..04cadae7 100644
--- a/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
@@ -434,7 +434,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
throw new NotSupportedException();
}
- public void Dispose()
+ private void DisposeHandles()
{
if (_incompatibleFormatView != null)
{
@@ -447,10 +447,38 @@ namespace Ryujinx.Graphics.OpenGL.Image
{
GL.DeleteTexture(Handle);
+ Handle = 0;
+ }
+ }
+
+ /// <summary>
+ /// Release the view without necessarily disposing the parent if we are the default view.
+ /// This allows it to be added to the resource pool and reused later.
+ /// </summary>
+ public void Release()
+ {
+ bool hadHandle = Handle != 0;
+
+ if (_parent.DefaultView != this)
+ {
+ DisposeHandles();
+ }
+
+ if (hadHandle)
+ {
_parent.DecrementViewsCount();
+ }
+ }
- Handle = 0;
+ public void Dispose()
+ {
+ if (_parent.DefaultView == this)
+ {
+ // Remove the default view (us), so that the texture cannot be released to the cache.
+ _parent.DeleteDefault();
}
+
+ Release();
}
}
}