From b888820e39e7fdb1dc8c4be4d3837b63d50fd68b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 5 Sep 2022 00:25:21 +0200 Subject: [PATCH] Switch bokeh blur shader to built-in transform mappers --- .../Effects/BokehBlurEffect.cs | 74 ++----------------- 1 file changed, 8 insertions(+), 66 deletions(-) diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs index adbb3816..c19876d7 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs @@ -303,8 +303,8 @@ public sealed partial class BokehBlurEffect d2D1DeviceContext.Get()->SetRenderingControls(&d2D1RenderingControls); // Register all necessary effects - D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), new VerticalConvolution(), out _); - D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), new HorizontalConvolutionAndAccumulatePartials(), out _); + D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), VerticalConvolution.Transform, out _); + D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), HorizontalConvolutionAndAccumulatePartials.Transform, out _); D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), out _); D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), out _); @@ -477,41 +477,12 @@ public sealed partial class BokehBlurEffect /// /// The vertical convolution shader and transform. /// - private sealed partial class VerticalConvolution : ID2D1TransformMapperFactory, ID2D1TransformMapper + private sealed partial class VerticalConvolution { /// - /// The length of the convolution kernel. + /// The for the shader. /// - private int kernelLength; - - /// - public ID2D1TransformMapper Create() - { - return new VerticalConvolution(); - } - - /// - public void MapInputsToOutput(in Shader shader, ReadOnlySpan inputs, ReadOnlySpan opaqueInputs, out Rectangle output, out Rectangle opaqueOutput) - { - this.kernelLength = shader.kernelLength; - - output = inputs[0]; - opaqueOutput = Rectangle.Empty; - } - - /// - public void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput) - { - invalidOutput = invalidInput; - } - - /// - public void MapOutputToInputs(in Rectangle output, Span inputs) - { - Rectangle input = Rectangle.Inflate(output, 0, this.kernelLength); - - inputs.Fill(input); - } + public static ID2D1TransformMapperFactory Transform { get; } = D2D1TransformMapperFactory.Inflate(static (in Shader shader) => (0, shader.kernelLength, 0, shader.kernelLength)); /// /// Kernel for the vertical convolution pass for real or imaginary components. @@ -553,41 +524,12 @@ public sealed partial class BokehBlurEffect /// /// The horizontal convolutin and partial accumulation effect and transform. /// - private sealed partial class HorizontalConvolutionAndAccumulatePartials : ID2D1TransformMapperFactory, ID2D1TransformMapper + private sealed partial class HorizontalConvolutionAndAccumulatePartials { /// - /// The length of the convolution kernel. + /// The for the shader. /// - private int kernelLength; - - /// - public ID2D1TransformMapper Create() - { - return new HorizontalConvolutionAndAccumulatePartials(); - } - - /// - public void MapInputsToOutput(in Shader shader, ReadOnlySpan inputs, ReadOnlySpan opaqueInputs, out Rectangle output, out Rectangle opaqueOutput) - { - this.kernelLength = shader.kernelLength; - - output = inputs[0]; - opaqueOutput = Rectangle.Empty; - } - - /// - public void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput) - { - invalidOutput = invalidInput; - } - - /// - public void MapOutputToInputs(in Rectangle output, Span inputs) - { - Rectangle input = Rectangle.Inflate(output, this.kernelLength, 0); - - inputs.Fill(input); - } + public static ID2D1TransformMapperFactory Transform { get; } = D2D1TransformMapperFactory.Inflate(static (in Shader shader) => (shader.kernelLength, 0, shader.kernelLength, 0)); /// /// Kernel for the horizontal convolution pass.