From 0ba4ade8f1fa64e2bda5c4b1e0c5b37e10d51c80 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 11 Aug 2021 19:44:41 -0300 Subject: [PATCH] Ensure render scale is initialized to 1 on the backend (#2543) --- Ryujinx.Graphics.OpenGL/Pipeline.cs | 19 +++++++++++-------- Ryujinx.Graphics.OpenGL/Renderer.cs | 1 + Ryujinx.Graphics.Shader/SupportBuffer.cs | 2 +- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Ryujinx.Graphics.OpenGL/Pipeline.cs b/Ryujinx.Graphics.OpenGL/Pipeline.cs index 9c39f719c1..7c626f54a0 100644 --- a/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -76,13 +76,22 @@ namespace Ryujinx.Graphics.OpenGL _componentMasks[index] = 0xf; } - var v4Zero = new Vector4 { X = 0f, Y = 0f, Z = 0f, W = 0f }; - new Span>(_renderScale).Fill(v4Zero); + var defaultScale = new Vector4 { X = 1f, Y = 0f, Z = 0f, W = 0f }; + new Span>(_renderScale).Fill(defaultScale); _tfbs = new BufferHandle[Constants.MaxTransformFeedbackBuffers]; _tfbTargets = new BufferRange[Constants.MaxTransformFeedbackBuffers]; } + public void Initialize() + { + _supportBuffer = Buffer.Create(SupportBuffer.RequiredSize); + GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, Unsafe.As(ref _supportBuffer)); + + SetSupportBufferData>(SupportBuffer.FragmentIsBgraOffset, _fpIsBgra, SupportBuffer.FragmentIsBgraCount); + SetSupportBufferData>(SupportBuffer.FragmentRenderScaleOffset, _renderScale, SupportBuffer.RenderScaleMaxCount); + } + public void Barrier() { GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); @@ -1207,12 +1216,6 @@ namespace Ryujinx.Graphics.OpenGL private void SetSupportBufferData(int offset, ReadOnlySpan data, int count) where T : unmanaged { - if (_supportBuffer == BufferHandle.Null) - { - _supportBuffer = Buffer.Create(SupportBuffer.RequiredSize); - GL.BindBufferBase(BufferRangeTarget.UniformBuffer, 0, Unsafe.As(ref _supportBuffer)); - } - Buffer.SetData(_supportBuffer, offset, MemoryMarshal.Cast(data.Slice(0, count))); } diff --git a/Ryujinx.Graphics.OpenGL/Renderer.cs b/Ryujinx.Graphics.OpenGL/Renderer.cs index 22648fd131..01072176ec 100644 --- a/Ryujinx.Graphics.OpenGL/Renderer.cs +++ b/Ryujinx.Graphics.OpenGL/Renderer.cs @@ -144,6 +144,7 @@ namespace Ryujinx.Graphics.OpenGL GL.Arb.MaxShaderCompilerThreads(Math.Min(Environment.ProcessorCount, 8)); } + _pipeline.Initialize(); _counters.Initialize(); } diff --git a/Ryujinx.Graphics.Shader/SupportBuffer.cs b/Ryujinx.Graphics.Shader/SupportBuffer.cs index 78f2440113..f76d2c922a 100644 --- a/Ryujinx.Graphics.Shader/SupportBuffer.cs +++ b/Ryujinx.Graphics.Shader/SupportBuffer.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.Shader public const int ComputeRenderScaleOffset = FragmentRenderScaleOffset + FieldSize; // Skip first scale that is used for the render target // One for the render target, 32 for the textures, and 8 for the images. - private const int RenderScaleMaxCount = 1 + 32 + 8; + public const int RenderScaleMaxCount = 1 + 32 + 8; public const int RequiredSize = FragmentRenderScaleOffset + RenderScaleMaxCount * FieldSize; }