diff --git a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj
index 9261ae98..3a0fde04 100644
--- a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj
+++ b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj
@@ -7,6 +7,7 @@
+
diff --git a/samples/ComputeSharp.ImageProcessing/Primitives/ComplexVector4.cs b/samples/ComputeSharp.ImageProcessing/Primitives/ComplexVector4.cs
new file mode 100644
index 00000000..3d3431f4
--- /dev/null
+++ b/samples/ComputeSharp.ImageProcessing/Primitives/ComplexVector4.cs
@@ -0,0 +1,32 @@
+// Copyright (c) Six Labors.
+// Licensed under the Apache License, Version 2.0.
+
+using System.Numerics;
+using System.Runtime.CompilerServices;
+
+namespace SixLabors.ImageSharp;
+
+///
+/// A vector with 4 values of type .
+///
+internal struct ComplexVector4
+{
+ ///
+ /// The real part of the complex vector
+ ///
+ public Vector4 Real;
+
+ ///
+ /// The imaginary part of the complex number
+ ///
+ public Vector4 Imaginary;
+
+ ///
+ /// Performs a weighted sum on the current instance according to the given parameters
+ ///
+ /// The 'a' parameter, for the real component
+ /// The 'b' parameter, for the imaginary component
+ /// The resulting value
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public Vector4 WeightedSum(float a, float b) => (this.Real * a) + (this.Imaginary * b);
+}
\ No newline at end of file
diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs
index b9187cf0..2677d2a2 100644
--- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs
+++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs
@@ -363,13 +363,12 @@ public sealed partial class HlslBokehBlurProcessor
///
public void Execute()
{
- float4 real = float4.Zero;
- float4 imaginary = float4.Zero;
int maxY = target.Height;
int maxX = target.Width;
int kernelLength = kernel.Length;
int radiusX = kernelLength >> 1;
int offsetY = Hlsl.Clamp(ThreadIds.Y, 0, maxY);
+ ComplexVector4 result = default;
for (int i = 0; i < kernelLength; i++)
{
@@ -378,11 +377,11 @@ public sealed partial class HlslBokehBlurProcessor
float4 sourceImaginary = imaginaries[offsetX, offsetY];
Complex64 factors = kernel[i];
- real += factors.Real * sourceReal - factors.Imaginary * sourceImaginary;
- imaginary += factors.Real * sourceImaginary + factors.Imaginary * sourceReal;
+ result.Real += (Vector4)(factors.Real * sourceReal - factors.Imaginary * sourceImaginary);
+ result.Imaginary += (Vector4)(factors.Real * sourceImaginary + factors.Imaginary * sourceReal);
}
- target[ThreadIds.XY] += real * z + imaginary * w;
+ target[ThreadIds.XY] += (float4)result.WeightedSum(z, w);
}
}
diff --git a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj
index c6b0d625..de70d87b 100644
--- a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj
+++ b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj
@@ -25,6 +25,11 @@
+
+
+
+
+
PreserveNewest
diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs
index 462281f4..f657c94c 100644
--- a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs
+++ b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs
@@ -9,6 +9,7 @@ using ComputeSharp.D2D1;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Extensions;
using ComputeSharp.D2D1.Tests.Helpers;
+using SixLabors.ImageSharp;
using Win32;
using Win32.Graphics.Direct2D;
@@ -568,10 +569,9 @@ public sealed partial class BokehBlurEffect
///
public float4 Execute()
{
- float4 real = float4.Zero;
- float4 imaginary = float4.Zero;
int length = this.kernelLength;
int radiusX = length >> 1;
+ ComplexVector4 result = default;
for (int i = 0; i < length; i++)
{
@@ -580,11 +580,11 @@ public sealed partial class BokehBlurEffect
float realFactor = kernelReals[i];
float imaginaryFactor = kernelImaginaries[i];
- real += realFactor * sourceReal - imaginaryFactor * sourceImaginary;
- imaginary += realFactor * sourceImaginary + imaginaryFactor * sourceReal;
+ result.Real += (Vector4)(realFactor * sourceReal - imaginaryFactor * sourceImaginary);
+ result.Imaginary += (Vector4)(realFactor * sourceImaginary + imaginaryFactor * sourceReal);
}
- return real * z + imaginary * w;
+ return result.WeightedSum(z, w);
}
}
}
@@ -633,40 +633,4 @@ public sealed partial class BokehBlurEffect
return pixel;
}
}
-
- ///
- /// Represents a complex number, where the real and imaginary parts are stored as values.
- ///
- private readonly struct Complex64
- {
- ///
- /// The real part of the complex number.
- ///
- public readonly float Real;
-
- ///
- /// The imaginary part of the complex number.
- ///
- public readonly float Imaginary;
-
- ///
- /// Initializes a new instance of the struct.
- ///
- /// The real part in the complex number.
- /// The imaginary part in the complex number.
- public Complex64(float real, float imaginary)
- {
- this.Real = real;
- this.Imaginary = imaginary;
- }
-
- ///
- /// Performs the multiplication operation between a instance and a scalar.
- ///
- /// The value to multiply.
- /// The scalar to use to multiply the value.
- /// The result.
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static Complex64 operator *(Complex64 value, float scalar) => new(value.Real * scalar, value.Imaginary * scalar);
- }
}
diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj
index c14ba3ee..d92c7e29 100644
--- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj
+++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj
@@ -36,6 +36,7 @@
+