GPU resource disposal

This commit is contained in:
gdkchan
2019-12-31 19:09:49 -03:00
committed by Thog
parent f7bcc884e4
commit 59fdaa744b
20 changed files with 195 additions and 46 deletions

View File

@ -6,7 +6,7 @@ using System;
namespace Ryujinx.Graphics.OpenGL
{
class Pipeline : IPipeline
class Pipeline : IPipeline, IDisposable
{
private Program _program;
@ -863,5 +863,11 @@ namespace Ryujinx.Graphics.OpenGL
(_componentMasks[index] & 8u) != 0);
}
}
public void Dispose()
{
_framebuffer?.Dispose();
_vertexArray?.Dispose();
}
}
}

View File

@ -66,6 +66,13 @@ namespace Ryujinx.Graphics.OpenGL
GL.LinkProgram(Handle);
for (int index = 0; index < shaders.Length; index++)
{
int shaderHandle = ((Shader)shaders[index]).Handle;
GL.DetachShader(Handle, shaderHandle);
}
CheckProgramLink();
Bind();

View File

@ -4,9 +4,11 @@ using Ryujinx.Graphics.Shader;
namespace Ryujinx.Graphics.OpenGL
{
public class Renderer : IRenderer
public sealed class Renderer : IRenderer
{
public IPipeline Pipeline { get; }
private Pipeline _pipeline;
public IPipeline Pipeline => _pipeline;
private readonly Counters _counters;
@ -18,7 +20,7 @@ namespace Ryujinx.Graphics.OpenGL
public Renderer()
{
Pipeline = new Pipeline();
_pipeline = new Pipeline();
_counters = new Counters();
@ -81,5 +83,12 @@ namespace Ryujinx.Graphics.OpenGL
{
_counters.ResetCounter(type);
}
public void Dispose()
{
TextureCopy.Dispose();
_pipeline.Dispose();
_window.Dispose();
}
}
}

View File

@ -1,9 +1,10 @@
using Ryujinx.Graphics.GAL;
using OpenTK.Graphics.OpenGL;
using System;
namespace Ryujinx.Graphics.OpenGL
{
class TextureCopy
class TextureCopy : IDisposable
{
private int _srcFramebuffer;
private int _dstFramebuffer;
@ -53,11 +54,6 @@ namespace Ryujinx.Graphics.OpenGL
GL.Enable(EnableCap.FramebufferSrgb);
}
private static void Detach(FramebufferTarget target, Format format)
{
Attach(target, format, 0);
}
private static void Attach(FramebufferTarget target, Format format, int handle)
{
if (format == Format.D24UnormS8Uint || format == Format.D32FloatS8Uint)
@ -124,5 +120,22 @@ namespace Ryujinx.Graphics.OpenGL
return _dstFramebuffer;
}
public void Dispose()
{
if (_srcFramebuffer != 0)
{
GL.DeleteFramebuffer(_srcFramebuffer);
_srcFramebuffer = 0;
}
if (_dstFramebuffer != 0)
{
GL.DeleteFramebuffer(_dstFramebuffer);
_dstFramebuffer = 0;
}
}
}
}

View File

@ -6,7 +6,7 @@ namespace Ryujinx.Graphics.OpenGL
{
class VertexArray : IDisposable
{
public int Handle { get; }
public int Handle { get; private set; }
private bool _needsAttribsUpdate;
@ -128,7 +128,12 @@ namespace Ryujinx.Graphics.OpenGL
public void Dispose()
{
GL.DeleteVertexArray(Handle);
if (Handle != 0)
{
GL.DeleteVertexArray(Handle);
Handle = 0;
}
}
}
}

View File

@ -4,7 +4,7 @@ using System;
namespace Ryujinx.Graphics.OpenGL
{
class Window : IWindow
class Window : IWindow, IDisposable
{
private const int NativeWidth = 1280;
private const int NativeHeight = 720;
@ -118,5 +118,15 @@ namespace Ryujinx.Graphics.OpenGL
return handle;
}
public void Dispose()
{
if (_copyFramebufferHandle != 0)
{
GL.DeleteFramebuffer(_copyFramebufferHandle);
_copyFramebufferHandle = 0;
}
}
}
}