From 3e68a87d63707e53c4b439a80c4c54538de02e4b Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 16 Apr 2023 14:26:22 -0300 Subject: [PATCH] Change SMAA filter texture clear method (#4685) * Change SMAA filter texture clear method * Alpha should be 1 * Delete more unnecessary code --- .../Effects/FsrScalingFilter.cs | 29 --------- .../Effects/FxaaPostProcessingEffect.cs | 16 ----- .../Effects/SmaaPostProcessingEffect.cs | 63 ++++++------------- 3 files changed, 19 insertions(+), 89 deletions(-) diff --git a/Ryujinx.Graphics.Vulkan/Effects/FsrScalingFilter.cs b/Ryujinx.Graphics.Vulkan/Effects/FsrScalingFilter.cs index a871679b..5f15f15f 100644 --- a/Ryujinx.Graphics.Vulkan/Effects/FsrScalingFilter.cs +++ b/Ryujinx.Graphics.Vulkan/Effects/FsrScalingFilter.cs @@ -118,20 +118,6 @@ namespace Ryujinx.Graphics.Vulkan.Effects _intermediaryTexture = _renderer.CreateTexture(info, view.ScaleFactor) as TextureView; } - Span viewports = stackalloc GAL.Viewport[1]; - Span> scissors = stackalloc Rectangle[1]; - - viewports[0] = new GAL.Viewport( - new Rectangle(0, 0, view.Width, view.Height), - ViewportSwizzle.PositiveX, - ViewportSwizzle.PositiveY, - ViewportSwizzle.PositiveZ, - ViewportSwizzle.PositiveW, - 0f, - 1f); - - scissors[0] = new Rectangle(0, 0, view.Width, view.Height); - _pipeline.SetCommandBuffer(cbs); _pipeline.SetProgram(_scalingProgram); _pipeline.SetTextureAndSampler(ShaderStage.Compute, 1, view, _sampler); @@ -169,23 +155,10 @@ namespace Ryujinx.Graphics.Vulkan.Effects var bufferRanges = new BufferRange(bufferHandle, 0, rangeSize); _pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) }); - _pipeline.SetScissors(scissors); - _pipeline.SetViewports(viewports, false); _pipeline.SetImage(0, _intermediaryTexture, GAL.Format.R8G8B8A8Unorm); _pipeline.DispatchCompute(dispatchX, dispatchY, 1); _pipeline.ComputeBarrier(); - viewports[0] = new GAL.Viewport( - new Rectangle(0, 0, width, height), - ViewportSwizzle.PositiveX, - ViewportSwizzle.PositiveY, - ViewportSwizzle.PositiveZ, - ViewportSwizzle.PositiveW, - 0f, - 1f); - - scissors[0] = new Rectangle(0, 0, width, height); - // Sharpening pass _pipeline.SetCommandBuffer(cbs); _pipeline.SetProgram(_sharpeningProgram); @@ -193,8 +166,6 @@ namespace Ryujinx.Graphics.Vulkan.Effects _pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) }); var sharpeningRange = new BufferRange(sharpeningBufferHandle, 0, sizeof(float)); _pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(4, sharpeningRange) }); - _pipeline.SetScissors(scissors); - _pipeline.SetViewports(viewports, false); _pipeline.SetImage(0, destinationTexture); _pipeline.DispatchCompute(dispatchX, dispatchY, 1); _pipeline.ComputeBarrier(); diff --git a/Ryujinx.Graphics.Vulkan/Effects/FxaaPostProcessingEffect.cs b/Ryujinx.Graphics.Vulkan/Effects/FxaaPostProcessingEffect.cs index 9e73e1b8..b7316d85 100644 --- a/Ryujinx.Graphics.Vulkan/Effects/FxaaPostProcessingEffect.cs +++ b/Ryujinx.Graphics.Vulkan/Effects/FxaaPostProcessingEffect.cs @@ -94,25 +94,9 @@ namespace Ryujinx.Graphics.Vulkan.Effects var bufferRanges = new BufferRange(bufferHandle, 0, rangeSize); _pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) }); - Span viewports = stackalloc GAL.Viewport[1]; - - viewports[0] = new GAL.Viewport( - new Rectangle(0, 0, view.Width, view.Height), - ViewportSwizzle.PositiveX, - ViewportSwizzle.PositiveY, - ViewportSwizzle.PositiveZ, - ViewportSwizzle.PositiveW, - 0f, - 1f); - - Span> scissors = stackalloc Rectangle[1]; - var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); - _pipeline.SetScissors(stackalloc[] { new Rectangle(0, 0, view.Width, view.Height) }); - _pipeline.SetViewports(viewports, false); - _pipeline.SetImage(0, _texture, GAL.Format.R8G8B8A8Unorm); _pipeline.DispatchCompute(dispatchX, dispatchY, 1); diff --git a/Ryujinx.Graphics.Vulkan/Effects/SmaaPostProcessingEffect.cs b/Ryujinx.Graphics.Vulkan/Effects/SmaaPostProcessingEffect.cs index bf698ade..38f86bae 100644 --- a/Ryujinx.Graphics.Vulkan/Effects/SmaaPostProcessingEffect.cs +++ b/Ryujinx.Graphics.Vulkan/Effects/SmaaPostProcessingEffect.cs @@ -218,40 +218,10 @@ namespace Ryujinx.Graphics.Vulkan.Effects _blendOutputTexture = _renderer.CreateTexture(info, view.ScaleFactor) as TextureView; } - Span viewports = stackalloc GAL.Viewport[1]; + _pipeline.SetCommandBuffer(cbs); - viewports[0] = new GAL.Viewport( - new Rectangle(0, 0, view.Width, view.Height), - ViewportSwizzle.PositiveX, - ViewportSwizzle.PositiveY, - ViewportSwizzle.PositiveZ, - ViewportSwizzle.PositiveW, - 0f, - 1f); - - Span> scissors = stackalloc Rectangle[1]; - - scissors[0] = new Rectangle(0, 0, view.Width, view.Height); - - _renderer.HelperShader.Clear(_renderer, - _edgeOutputTexture.GetImageView(), - new float[] { 0, 0, 0, 1 }, - (uint)(ColorComponentFlags.RBit | ColorComponentFlags.GBit | ColorComponentFlags.BBit | ColorComponentFlags.ABit), - view.Width, - view.Height, - _edgeOutputTexture.VkFormat, - ComponentType.UnsignedInteger, - scissors[0]); - - _renderer.HelperShader.Clear(_renderer, - _blendOutputTexture.GetImageView(), - new float[] { 0, 0, 0, 1 }, - (uint)(ColorComponentFlags.RBit | ColorComponentFlags.GBit | ColorComponentFlags.BBit | ColorComponentFlags.ABit), - view.Width, - view.Height, - _blendOutputTexture.VkFormat, - ComponentType.UnsignedInteger, - scissors[0]); + Clear(_edgeOutputTexture); + Clear(_blendOutputTexture); _renderer.Pipeline.TextureBarrier(); @@ -259,7 +229,6 @@ namespace Ryujinx.Graphics.Vulkan.Effects var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); // Edge pass - _pipeline.SetCommandBuffer(cbs); _pipeline.SetProgram(_edgeProgram); _pipeline.SetTextureAndSampler(ShaderStage.Compute, 1, view, _samplerLinear); _pipeline.Specialize(_specConstants); @@ -271,35 +240,25 @@ namespace Ryujinx.Graphics.Vulkan.Effects _renderer.BufferManager.SetData(bufferHandle, 0, resolutionBuffer); var bufferRanges = new BufferRange(bufferHandle, 0, rangeSize); _pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) }); - _pipeline.SetScissors(scissors); - _pipeline.SetViewports(viewports, false); _pipeline.SetImage(0, _edgeOutputTexture, GAL.Format.R8G8B8A8Unorm); _pipeline.DispatchCompute(dispatchX, dispatchY, 1); _pipeline.ComputeBarrier(); // Blend pass - _pipeline.SetCommandBuffer(cbs); _pipeline.SetProgram(_blendProgram); _pipeline.Specialize(_specConstants); _pipeline.SetTextureAndSampler(ShaderStage.Compute, 1, _edgeOutputTexture, _samplerLinear); _pipeline.SetTextureAndSampler(ShaderStage.Compute, 3, _areaTexture, _samplerLinear); _pipeline.SetTextureAndSampler(ShaderStage.Compute, 4, _searchTexture, _samplerLinear); - _pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) }); - _pipeline.SetScissors(scissors); - _pipeline.SetViewports(viewports, false); _pipeline.SetImage(0, _blendOutputTexture, GAL.Format.R8G8B8A8Unorm); _pipeline.DispatchCompute(dispatchX, dispatchY, 1); _pipeline.ComputeBarrier(); // Neighbour pass - _pipeline.SetCommandBuffer(cbs); _pipeline.SetProgram(_neighbourProgram); _pipeline.Specialize(_specConstants); _pipeline.SetTextureAndSampler(ShaderStage.Compute, 3, _blendOutputTexture, _samplerLinear); _pipeline.SetTextureAndSampler(ShaderStage.Compute, 1, view, _samplerLinear); - _pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) }); - _pipeline.SetScissors(scissors); - _pipeline.SetViewports(viewports, false); _pipeline.SetImage(0, _outputTexture, GAL.Format.R8G8B8A8Unorm); _pipeline.DispatchCompute(dispatchX, dispatchY, 1); _pipeline.ComputeBarrier(); @@ -310,5 +269,21 @@ namespace Ryujinx.Graphics.Vulkan.Effects return _outputTexture; } + + private void Clear(TextureView texture) + { + Span colorMasks = stackalloc uint[1]; + + colorMasks[0] = 0xf; + + Span> scissors = stackalloc Rectangle[1]; + + scissors[0] = new Rectangle(0, 0, texture.Width, texture.Height); + + _pipeline.SetRenderTarget(texture.GetImageViewForAttachment(), (uint)texture.Width, (uint)texture.Height, false, texture.VkFormat); + _pipeline.SetRenderTargetColorMasks(colorMasks); + _pipeline.SetScissors(scissors); + _pipeline.ClearRenderTargetColor(0, 0, 1, new ColorF(0f, 0f, 0f, 1f)); + } } } \ No newline at end of file