diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs
index dd4ecb24..25e9dfc9 100644
--- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs
+++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor.cs
@@ -26,7 +26,7 @@ namespace ComputeSharp.BokehBlur.Processors
/// Initializes a new instance of the class.
///
public HlslBokehBlurProcessor()
- : this(DefaultRadius, DefaultComponents)
+ : this(Gpu.Default, DefaultRadius, DefaultComponents)
{
}
@@ -36,11 +36,28 @@ namespace ComputeSharp.BokehBlur.Processors
/// The size of the area to sample.
/// The number of components to use to approximate the original 2D bokeh blur convolution kernel.
public HlslBokehBlurProcessor(int radius, int components)
+ : this(Gpu.Default, radius, components)
{
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The associated with the current instance.
+ /// The size of the area to sample.
+ /// The number of components to use to approximate the original 2D bokeh blur convolution kernel.
+ public HlslBokehBlurProcessor(GraphicsDevice device, int radius, int components)
+ {
+ GraphicsDevice = device;
Radius = radius;
Components = components;
}
+ ///
+ /// Gets the associated with the current instance.
+ ///
+ public GraphicsDevice GraphicsDevice { get; }
+
///
/// Gets the radius.
///
diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs
index 5b609cc0..eddd54af 100644
--- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs
+++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs
@@ -20,6 +20,11 @@ namespace ComputeSharp.BokehBlur.Processors
/// This processor is based on the code from Mike Pound, see github.com/mikepound/convolve.
public sealed partial class Implementation : ImageProcessor
{
+ ///
+ /// The instance in use.
+ ///
+ private readonly GraphicsDevice GraphicsDevice;
+
///
/// The kernel radius.
///
@@ -65,6 +70,7 @@ namespace ComputeSharp.BokehBlur.Processors
public Implementation(HlslBokehBlurProcessor definition, Configuration configuration, Image source, Rectangle sourceRectangle)
: base(configuration, source, sourceRectangle)
{
+ GraphicsDevice = definition.GraphicsDevice;
Radius = definition.Radius;
KernelSize = Radius * 2 + 1;
ComponentsCount = definition.Components;
@@ -256,14 +262,14 @@ namespace ComputeSharp.BokehBlur.Processors
Span span = MemoryMarshal.Cast(pixelSpan);
- using ReadWriteTexture2D texture = Gpu.Default.AllocateReadWriteTexture2D(span, source.Width, source.Height);
- using ReadWriteTexture2D temporary = Gpu.Default.AllocateReadWriteTexture2D(source.Width, source.Height, AllocationMode.Clear);
- using ReadWriteTexture2D reals = Gpu.Default.AllocateReadWriteTexture2D(source.Width, source.Height);
- using ReadWriteTexture2D imaginaries = Gpu.Default.AllocateReadWriteTexture2D(source.Width, source.Height);
- using ReadOnlyBuffer kernel = Gpu.Default.AllocateReadOnlyBuffer(KernelSize);
+ using ReadWriteTexture2D texture = GraphicsDevice.AllocateReadWriteTexture2D(span, source.Width, source.Height);
+ using ReadWriteTexture2D temporary = GraphicsDevice.AllocateReadWriteTexture2D(source.Width, source.Height, AllocationMode.Clear);
+ using ReadWriteTexture2D reals = GraphicsDevice.AllocateReadWriteTexture2D(source.Width, source.Height);
+ using ReadWriteTexture2D imaginaries = GraphicsDevice.AllocateReadWriteTexture2D(source.Width, source.Height);
+ using ReadOnlyBuffer kernel = GraphicsDevice.AllocateReadOnlyBuffer(KernelSize);
// Preliminary gamma highlight pass
- Gpu.Default.For(source.Height, new(texture));
+ GraphicsDevice.For(source.Height, new(texture));
// Perform two 1D convolutions for each component in the current instance
for (int j = 0; j < Kernels.Length; j++)
@@ -272,19 +278,19 @@ namespace ComputeSharp.BokehBlur.Processors
kernel.CopyFrom(Kernels[j]);
- Gpu.Default.For(
+ GraphicsDevice.For(
source.Width,
source.Height,
new(texture, reals, imaginaries, kernel));
- Gpu.Default.For(
+ GraphicsDevice.For(
source.Width,
source.Height,
new(parameters.Z, parameters.W, reals, imaginaries, temporary, kernel));
}
// Apply the inverse gamma exposure pass
- Gpu.Default.For(source.Height, new(temporary, texture));
+ GraphicsDevice.For(source.Height, new(temporary, texture));
// Write the final pixel data
texture.CopyTo(span);
diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs
index 962db9cf..159e1965 100644
--- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs
+++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor.cs
@@ -20,25 +20,48 @@ namespace ComputeSharp.BokehBlur.Processors
///
/// Initializes a new instance of the class.
///
- public HlslGaussianBlurProcessor() : this(DefaultSigma, 9) { }
+ public HlslGaussianBlurProcessor()
+ : this(Gpu.Default, DefaultSigma, 9)
+ {
+ }
///
/// Initializes a new instance of the class.
///
/// The radius value representing the size of the area to sample.
- public HlslGaussianBlurProcessor(int radius) : this(radius / 3F, radius) { }
+ public HlslGaussianBlurProcessor(int radius)
+ : this(Gpu.Default, radius / 3F, radius)
+ {
+ }
///
/// Initializes a new instance of the class.
///
+ /// The associated with the current instance.
+ /// The radius value representing the size of the area to sample.
+ public HlslGaussianBlurProcessor(GraphicsDevice device, int radius)
+ : this(device, radius / 3F, radius)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The associated with the current instance.
/// The sigma value representing the weight of the blur.
/// The radius value representing the size of the area to sample (this should be at least twice the sigma value)
- public HlslGaussianBlurProcessor(float sigma, int radius)
+ public HlslGaussianBlurProcessor(GraphicsDevice device, float sigma, int radius)
{
+ GraphicsDevice = device;
Sigma = sigma;
Radius = radius;
}
+ ///
+ /// The instance in use.
+ ///
+ private readonly GraphicsDevice GraphicsDevice;
+
///
/// Gets the sigma value representing the weight of the blur.
///
diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs
index dcb932bd..e3b5a7c4 100644
--- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs
+++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs
@@ -17,6 +17,11 @@ namespace ComputeSharp.BokehBlur.Processors
///
internal sealed partial class Implementation : ImageProcessor
{
+ ///
+ /// The instance in use.
+ ///
+ private readonly GraphicsDevice GraphicsDevice;
+
///
/// The 1D kernel to apply.
///
@@ -33,6 +38,8 @@ namespace ComputeSharp.BokehBlur.Processors
: base(configuration, source, sourceRectangle)
{
int kernelSize = definition.Radius * 2 + 1;
+
+ GraphicsDevice = definition.GraphicsDevice;
Kernel = CreateGaussianBlurKernel(kernelSize, definition.Sigma);
}
@@ -94,12 +101,12 @@ namespace ComputeSharp.BokehBlur.Processors
Span span = MemoryMarshal.Cast(pixelSpan);
- using ReadWriteTexture2D sourceTexture = Gpu.Default.AllocateReadWriteTexture2D(span, source.Width, source.Height);
- using ReadWriteTexture2D firstPassTexture = Gpu.Default.AllocateReadWriteTexture2D(source.Width, source.Height);
- using ReadOnlyBuffer kernelBuffer = Gpu.Default.AllocateReadOnlyBuffer(Kernel);
+ using ReadWriteTexture2D sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D(span, source.Width, source.Height);
+ using ReadWriteTexture2D firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D(source.Width, source.Height);
+ using ReadOnlyBuffer kernelBuffer = GraphicsDevice.AllocateReadOnlyBuffer(Kernel);
- Gpu.Default.For(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
- Gpu.Default.For(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
+ GraphicsDevice.For(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
+ GraphicsDevice.For(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
sourceTexture.CopyTo(span);
}
diff --git a/tests/ComputeSharp.Tests/ImagingTests.cs b/tests/ComputeSharp.Tests/ImagingTests.cs
index b9519a19..887c7cbe 100644
--- a/tests/ComputeSharp.Tests/ImagingTests.cs
+++ b/tests/ComputeSharp.Tests/ImagingTests.cs
@@ -5,6 +5,8 @@ using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using ComputeSharp.BokehBlur.Processors;
+using ComputeSharp.Tests.Attributes;
+using ComputeSharp.Tests.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Processing;
@@ -16,14 +18,15 @@ namespace ComputeSharp.Tests
[TestCategory("Imaging")]
public class ImagingTests
{
- [TestMethod]
- public void BokehBlur()
+ [CombinatorialTestMethod]
+ [AllDevices]
+ public void BokehBlur(Device device)
{
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
using var original = Image.Load(Path.Combine(path, "city.jpg"));
using var cpu = original.Clone(c => c.BokehBlur(80, 2, 3));
- using var gpu = original.Clone(c => c.ApplyProcessor(new HlslBokehBlurProcessor(80, 2)));
+ using var gpu = original.Clone(c => c.ApplyProcessor(new HlslBokehBlurProcessor(device.Get(), 80, 2)));
string
expectedPath = Path.Combine(path, "city_bokeh_cpu.jpg"),
@@ -35,14 +38,15 @@ namespace ComputeSharp.Tests
TolerantImageComparer.AssertEqual(expectedPath, actualPath, 0.000009f);
}
- [TestMethod]
- public void GaussianBlur()
+ [CombinatorialTestMethod]
+ [AllDevices]
+ public void GaussianBlur(Device device)
{
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging");
using var original = Image.Load(Path.Combine(path, "city.jpg"));
using var cpu = original.Clone(c => c.GaussianBlur(30f));
- using var gpu = original.Clone(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(90)));
+ using var gpu = original.Clone(c => c.ApplyProcessor(new HlslGaussianBlurProcessor(device.Get(), 90)));
string
expectedPath = Path.Combine(path, "city_gaussian_cpu.jpg"),