From d941f4c07099bd365f6b0e8efb1cd727ae422009 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Sun, 24 May 2020 14:44:12 +0100 Subject: [PATCH] Remember bound framebuffer to avoid glGetInteger use. (#1273) glGetInteger seems to sync with GPU which is less than ideal, and slowing down texture copies. --- Ryujinx.Graphics.OpenGL/Framebuffer.cs | 3 ++- Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs | 3 +-- Ryujinx.Graphics.OpenGL/Pipeline.cs | 11 ++++++++++- Ryujinx.Graphics.OpenGL/Window.cs | 3 +-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/Ryujinx.Graphics.OpenGL/Framebuffer.cs index e66dcaca..aececbe8 100644 --- a/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -20,9 +20,10 @@ namespace Ryujinx.Graphics.OpenGL _colors = new TextureView[8]; } - public void Bind() + public int Bind() { GL.BindFramebuffer(FramebufferTarget.Framebuffer, Handle); + return Handle; } public void AttachColor(int index, TextureView color) diff --git a/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 1cef61a9..db9ff41c 100644 --- a/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -23,8 +23,7 @@ namespace Ryujinx.Graphics.OpenGL.Image Extents2D dstRegion, bool linearFilter) { - int oldReadFramebufferHandle = GL.GetInteger(GetPName.ReadFramebufferBinding); - int oldDrawFramebufferHandle = GL.GetInteger(GetPName.DrawFramebufferBinding); + (int oldDrawFramebufferHandle, int oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers(); GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, GetSrcFramebufferLazy()); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, GetDstFramebufferLazy()); diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index 05383f5d..affb4efc 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -28,6 +28,9 @@ namespace Ryujinx.Graphics.OpenGL private bool _depthTest; private bool _hasDepthBuffer; + private int _boundDrawFramebuffer; + private int _boundReadFramebuffer; + private TextureBase _unit0Texture; private ClipOrigin _clipOrigin; @@ -956,12 +959,18 @@ namespace Ryujinx.Graphics.OpenGL { _framebuffer = new Framebuffer(); - _framebuffer.Bind(); + int boundHandle = _framebuffer.Bind(); + _boundDrawFramebuffer = _boundReadFramebuffer = boundHandle; GL.Enable(EnableCap.FramebufferSrgb); } } + internal (int drawHandle, int readHandle) GetBoundFramebuffers() + { + return (_boundDrawFramebuffer, _boundReadFramebuffer); + } + private void UpdateDepthTest() { // Enabling depth operations is only valid when we have diff --git a/Ryujinx.Graphics.OpenGL/Window.cs b/Ryujinx.Graphics.OpenGL/Window.cs index 6e7ddbac..6da9e715 100644 --- a/Ryujinx.Graphics.OpenGL/Window.cs +++ b/Ryujinx.Graphics.OpenGL/Window.cs @@ -44,8 +44,7 @@ namespace Ryujinx.Graphics.OpenGL { bool[] oldFramebufferColorWritemask = new bool[4]; - int oldReadFramebufferHandle = GL.GetInteger(GetPName.ReadFramebufferBinding); - int oldDrawFramebufferHandle = GL.GetInteger(GetPName.DrawFramebufferBinding); + (int oldDrawFramebufferHandle, int oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers(); GL.GetBoolean(GetIndexedPName.ColorWritemask, drawFramebuffer, oldFramebufferColorWritemask);