From 550fd4a7338eded794bf961ef6fd0c38643471c8 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Mon, 14 Aug 2023 13:57:39 -0300 Subject: [PATCH] Simplify resolution scale updates (#5541) --- .../Image/TextureBindingsManager.cs | 21 ++--------- .../Image/TextureManager.cs | 7 ++-- .../Memory/SupportBufferUpdater.cs | 35 +++++++++---------- .../DescriptorSetUpdater.cs | 2 +- 4 files changed, 21 insertions(+), 44 deletions(-) diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs index d1454fc9a..8eca18b48 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureBindingsManager.cs @@ -61,8 +61,6 @@ namespace Ryujinx.Graphics.Gpu.Image private int _textureBufferIndex; - private readonly float[] _scales; - private bool _scaleChanged; private int _lastFragmentTotal; /// @@ -72,14 +70,12 @@ namespace Ryujinx.Graphics.Gpu.Image /// The GPU channel that the texture bindings manager belongs to /// Texture pools cache used to get texture pools from /// Sampler pools cache used to get sampler pools from - /// Array where the scales for the currently bound textures are stored /// True if the bindings manager is used for the compute engine public TextureBindingsManager( GpuContext context, GpuChannel channel, TexturePoolCache texturePoolCache, SamplerPoolCache samplerPoolCache, - float[] scales, bool isCompute) { _context = context; @@ -87,7 +83,6 @@ namespace Ryujinx.Graphics.Gpu.Image _texturePoolCache = texturePoolCache; _samplerPoolCache = samplerPoolCache; - _scales = scales; _isCompute = isCompute; int stages = isCompute ? 1 : Constants.ShaderStages; @@ -239,12 +234,7 @@ namespace Ryujinx.Graphics.Gpu.Image } } - if (result != _scales[index]) - { - _scaleChanged = true; - - _scales[index] = result; - } + _context.SupportBufferUpdater.UpdateRenderScale(index, result); return changed; } @@ -290,11 +280,6 @@ namespace Ryujinx.Graphics.Gpu.Image // - Vertex stage has bindings that require scale. // - Fragment stage binding count has been updated since last render scale update. - _scaleChanged = true; - } - - if (_scaleChanged) - { if (!_isCompute) { total += fragmentTotal; // Add the fragment bindings to the total. @@ -302,9 +287,7 @@ namespace Ryujinx.Graphics.Gpu.Image _lastFragmentTotal = fragmentTotal; - _context.SupportBufferUpdater.UpdateRenderScale(_scales, total, fragmentTotal); - - _scaleChanged = false; + _context.SupportBufferUpdater.UpdateRenderScaleFragmentCount(total, fragmentTotal); } } diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index 63b9b47c3..ed181640a 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -44,11 +44,8 @@ namespace Ryujinx.Graphics.Gpu.Image TexturePoolCache texturePoolCache = new(context); SamplerPoolCache samplerPoolCache = new(context); - float[] scales = new float[64]; - new Span(scales).Fill(1f); - - _cpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, scales, isCompute: true); - _gpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, scales, isCompute: false); + _cpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, isCompute: true); + _gpBindingsManager = new TextureBindingsManager(context, channel, texturePoolCache, samplerPoolCache, isCompute: false); _texturePoolCache = texturePoolCache; _samplerPoolCache = samplerPoolCache; diff --git a/src/Ryujinx.Graphics.Gpu/Memory/SupportBufferUpdater.cs b/src/Ryujinx.Graphics.Gpu/Memory/SupportBufferUpdater.cs index b236476e0..409c7a786 100644 --- a/src/Ryujinx.Graphics.Gpu/Memory/SupportBufferUpdater.cs +++ b/src/Ryujinx.Graphics.Gpu/Memory/SupportBufferUpdater.cs @@ -136,33 +136,30 @@ namespace Ryujinx.Graphics.Gpu.Memory /// /// Updates the render scales for shader input textures or images. /// - /// Scale values + /// Index of the scale + /// Scale value + public void UpdateRenderScale(int index, float scale) + { + if (_data.RenderScale[1 + index].X != scale) + { + _data.RenderScale[1 + index].X = scale; + DirtyRenderScale(1 + index, 1); + } + } + + /// + /// Updates the render scales for shader input textures or images. + /// /// Total number of scales across all stages /// Total number of scales on the fragment shader stage - public void UpdateRenderScale(ReadOnlySpan scales, int totalCount, int fragmentCount) + public void UpdateRenderScaleFragmentCount(int totalCount, int fragmentCount) { - bool changed = false; - - for (int index = 0; index < totalCount; index++) - { - if (_data.RenderScale[1 + index].X != scales[index]) - { - _data.RenderScale[1 + index].X = scales[index]; - changed = true; - } - } - // Only update fragment count if there are scales after it for the vertex stage. if (fragmentCount != totalCount && fragmentCount != _data.FragmentRenderScaleCount.X) { _data.FragmentRenderScaleCount.X = fragmentCount; DirtyFragmentRenderScaleCount(); } - - if (changed) - { - DirtyRenderScale(0, 1 + totalCount); - } } /// @@ -172,7 +169,7 @@ namespace Ryujinx.Graphics.Gpu.Memory /// True if the format is BGRA< false otherwise public void SetRenderTargetIsBgra(int index, bool isBgra) { - bool isBgraChanged = (_data.FragmentIsBgra[index].X != 0) != isBgra; + bool isBgraChanged = _data.FragmentIsBgra[index].X != 0 != isBgra; if (isBgraChanged) { diff --git a/src/Ryujinx.Graphics.Vulkan/DescriptorSetUpdater.cs b/src/Ryujinx.Graphics.Vulkan/DescriptorSetUpdater.cs index 894710911..45392b642 100644 --- a/src/Ryujinx.Graphics.Vulkan/DescriptorSetUpdater.cs +++ b/src/Ryujinx.Graphics.Vulkan/DescriptorSetUpdater.cs @@ -376,7 +376,7 @@ namespace Ryujinx.Graphics.Vulkan var program = _program; var bindingSegments = program.BindingSegments[setIndex]; - if (bindingSegments.Length == 0 && setIndex != PipelineBase.UniformSetIndex) + if (bindingSegments.Length == 0) { return; }