From f9d44b421889126b20100a08da47aa03ad1b49d4 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 14 Aug 2018 16:47:53 -0300 Subject: [PATCH] Only try uploading const buffers that are really used --- Ryujinx.Graphics/Gal/IGalShader.cs | 1 + Ryujinx.Graphics/Gal/OpenGL/OGLPipeline.cs | 2 +- Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs | 16 +++++++++++--- .../Gal/OpenGL/OGLShaderProgram.cs | 21 ++++++++++--------- Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs | 19 ++++++++++------- 5 files changed, 38 insertions(+), 21 deletions(-) diff --git a/Ryujinx.Graphics/Gal/IGalShader.cs b/Ryujinx.Graphics/Gal/IGalShader.cs index a9bd13811f..5174c03931 100644 --- a/Ryujinx.Graphics/Gal/IGalShader.cs +++ b/Ryujinx.Graphics/Gal/IGalShader.cs @@ -9,6 +9,7 @@ namespace Ryujinx.Graphics.Gal void Create(IGalMemory Memory, long VpAPos, long Key, GalShaderType Type); + IEnumerable GetConstBufferUsage(long Key); IEnumerable GetTextureUsage(long Key); void EnsureTextureBinding(string UniformName, int Value); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLPipeline.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLPipeline.cs index 54f984cd67..c9e7f6c3ac 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLPipeline.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLPipeline.cs @@ -279,7 +279,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL { if (Stage != null) { - foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage) + foreach (ShaderDeclInfo DeclInfo in Stage.ConstBufferUsage) { long Key = New.ConstBufferKeys[(int)Stage.Type][DeclInfo.Cbuf]; diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs index 4792bc5e8a..9c7b8668fe 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLShader.cs @@ -72,8 +72,18 @@ namespace Ryujinx.Graphics.Gal.OpenGL return new OGLShaderStage( Type, Program.Code, - Program.Textures, - Program.Uniforms); + Program.Uniforms, + Program.Textures); + } + + public IEnumerable GetConstBufferUsage(long Key) + { + if (Stages.TryGetValue(Key, out OGLShaderStage Stage)) + { + return Stage.ConstBufferUsage; + } + + return Enumerable.Empty(); } public IEnumerable GetTextureUsage(long Key) @@ -224,7 +234,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL { if (Stage != null) { - foreach (ShaderDeclInfo DeclInfo in Stage.UniformUsage) + foreach (ShaderDeclInfo DeclInfo in Stage.ConstBufferUsage) { int BlockIndex = GL.GetUniformBlockIndex(ProgramHandle, DeclInfo.Name); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLShaderProgram.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLShaderProgram.cs index 731994cec7..c4e6a881f8 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLShaderProgram.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLShaderProgram.cs @@ -1,6 +1,7 @@ using OpenTK.Graphics.OpenGL; using System; using System.Collections.Generic; +using System.Linq; namespace Ryujinx.Graphics.Gal.OpenGL { @@ -23,19 +24,19 @@ namespace Ryujinx.Graphics.Gal.OpenGL public string Code { get; private set; } - public IEnumerable TextureUsage { get; private set; } - public IEnumerable UniformUsage { get; private set; } + public IEnumerable ConstBufferUsage { get; private set; } + public IEnumerable TextureUsage { get; private set; } public OGLShaderStage( - GalShaderType Type, - string Code, - IEnumerable TextureUsage, - IEnumerable UniformUsage) + GalShaderType Type, + string Code, + IEnumerable ConstBufferUsage, + IEnumerable TextureUsage) { - this.Type = Type; - this.Code = Code; - this.TextureUsage = TextureUsage; - this.UniformUsage = UniformUsage; + this.Type = Type; + this.Code = Code; + this.ConstBufferUsage = ConstBufferUsage; + this.TextureUsage = TextureUsage; } public void Compile() diff --git a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs index 089e3fa4e2..3c1a1f79a5 100644 --- a/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs +++ b/Ryujinx.HLE/Gpu/Engines/NvGpuEngine3d.cs @@ -101,7 +101,7 @@ namespace Ryujinx.HLE.Gpu.Engines Gpu.Renderer.Shader.BindProgram(); UploadTextures(Vmm, State, Keys); - UploadConstBuffers(Vmm, State); + UploadConstBuffers(Vmm, State, Keys); UploadVertexArrays(Vmm, State); DispatchRender(Vmm, State); @@ -463,24 +463,29 @@ namespace Ryujinx.HLE.Gpu.Engines Gpu.Renderer.Texture.SetSampler(Sampler); } - private void UploadConstBuffers(NvGpuVmm Vmm, GalPipelineState State) + private void UploadConstBuffers(NvGpuVmm Vmm, GalPipelineState State, long[] Keys) { - for (int Stage = 0; Stage < State.ConstBufferKeys.Length; Stage++) + for (int Stage = 0; Stage < Keys.Length; Stage++) { - for (int Index = 0; Index < State.ConstBufferKeys[Stage].Length; Index++) + foreach (ShaderDeclInfo DeclInfo in Gpu.Renderer.Shader.GetConstBufferUsage(Keys[Stage])) { - ConstBuffer Cb = ConstBuffers[Stage][Index]; + ConstBuffer Cb = ConstBuffers[Stage][DeclInfo.Cbuf]; + + if (!Cb.Enabled) + { + continue; + } long Key = Vmm.GetPhysicalAddress(Cb.Position); - if (Cb.Enabled && QueryKeyUpload(Vmm, Key, Cb.Size, NvGpuBufferType.ConstBuffer)) + if (QueryKeyUpload(Vmm, Key, Cb.Size, NvGpuBufferType.ConstBuffer)) { IntPtr Source = Vmm.GetHostAddress(Cb.Position, Cb.Size); Gpu.Renderer.Buffer.SetData(Key, Cb.Size, Source); } - State.ConstBufferKeys[Stage][Index] = Key; + State.ConstBufferKeys[Stage][DeclInfo.Cbuf] = Key; } } }