diff options
| author | gdkchan <gab.dark.100@gmail.com> | 2019-12-31 19:09:49 -0300 |
|---|---|---|
| committer | Thog <thog@protonmail.com> | 2020-01-09 02:13:00 +0100 |
| commit | 59fdaa744b20f91928ee3fcaf5fabfcb7b409451 (patch) | |
| tree | f01e21d930e456398411317784c5063c532a7215 /Ryujinx.Graphics.OpenGL | |
| parent | f7bcc884e46805f4dcda4fc7d7e7bccb2a3ac316 (diff) | |
GPU resource disposal
Diffstat (limited to 'Ryujinx.Graphics.OpenGL')
| -rw-r--r-- | Ryujinx.Graphics.OpenGL/Pipeline.cs | 8 | ||||
| -rw-r--r-- | Ryujinx.Graphics.OpenGL/Program.cs | 7 | ||||
| -rw-r--r-- | Ryujinx.Graphics.OpenGL/Renderer.cs | 15 | ||||
| -rw-r--r-- | Ryujinx.Graphics.OpenGL/TextureCopy.cs | 25 | ||||
| -rw-r--r-- | Ryujinx.Graphics.OpenGL/VertexArray.cs | 9 | ||||
| -rw-r--r-- | Ryujinx.Graphics.OpenGL/Window.cs | 12 |
6 files changed, 63 insertions, 13 deletions
diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index 7ca19c9d..0ef21d7d 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -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(); + } } } diff --git a/Ryujinx.Graphics.OpenGL/Program.cs b/Ryujinx.Graphics.OpenGL/Program.cs index 48ec69d1..a8ee7ae8 100644 --- a/Ryujinx.Graphics.OpenGL/Program.cs +++ b/Ryujinx.Graphics.OpenGL/Program.cs @@ -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(); diff --git a/Ryujinx.Graphics.OpenGL/Renderer.cs b/Ryujinx.Graphics.OpenGL/Renderer.cs index 7cb69a78..e6021f51 100644 --- a/Ryujinx.Graphics.OpenGL/Renderer.cs +++ b/Ryujinx.Graphics.OpenGL/Renderer.cs @@ -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(); + } } } diff --git a/Ryujinx.Graphics.OpenGL/TextureCopy.cs b/Ryujinx.Graphics.OpenGL/TextureCopy.cs index 75ef07c1..244ace8a 100644 --- a/Ryujinx.Graphics.OpenGL/TextureCopy.cs +++ b/Ryujinx.Graphics.OpenGL/TextureCopy.cs @@ -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; + } + } } } diff --git a/Ryujinx.Graphics.OpenGL/VertexArray.cs b/Ryujinx.Graphics.OpenGL/VertexArray.cs index 26e63364..721a90f0 100644 --- a/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -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; + } } } } diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs index cf520ed4..26fc6a64 100644 --- a/Ryujinx.Graphics.OpenGL/Window.cs +++ b/Ryujinx.Graphics.OpenGL/Window.cs @@ -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; + } + } } } |
