Enabled imaging tests on WARP device
このコミットが含まれているのは:
1 親
4b23773873
コミット
c5ccaa0237
5ファイル変更
+81
-24
検索条件に一致するファイルはありません
@@ -26,7 +26,7 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
public HlslBokehBlurProcessor()
|
||||
: this(DefaultRadius, DefaultComponents)
|
||||
: this(Gpu.Default, DefaultRadius, DefaultComponents)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -36,11 +36,28 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
/// <param name="radius">The size of the area to sample.</param>
|
||||
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
|
||||
public HlslBokehBlurProcessor(int radius, int components)
|
||||
: this(Gpu.Default, radius, components)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslBokehBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="radius">The size of the area to sample.</param>
|
||||
/// <param name="components">The number of components to use to approximate the original 2D bokeh blur convolution kernel.</param>
|
||||
public HlslBokehBlurProcessor(GraphicsDevice device, int radius, int components)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
Radius = radius;
|
||||
Components = components;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.
|
||||
/// </summary>
|
||||
public GraphicsDevice GraphicsDevice { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the radius.
|
||||
/// </summary>
|
||||
|
||||
@@ -20,6 +20,11 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
/// <remarks>This processor is based on the code from Mike Pound, see <a href="https://github.com/mikepound/convolve">github.com/mikepound/convolve</a>.</remarks>
|
||||
public sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The kernel radius.
|
||||
/// </summary>
|
||||
@@ -65,6 +70,7 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
public Implementation(HlslBokehBlurProcessor definition, Configuration configuration, Image<ImageSharpRgba32> 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<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> texture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> temporary = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
|
||||
using ReadWriteTexture2D<Vector4> reals = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> imaginaries = Gpu.Default.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<Complex64> kernel = Gpu.Default.AllocateReadOnlyBuffer<Complex64>(KernelSize);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> texture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> temporary = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height, AllocationMode.Clear);
|
||||
using ReadWriteTexture2D<Vector4> reals = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Vector4> imaginaries = GraphicsDevice.AllocateReadWriteTexture2D<Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<Complex64> kernel = GraphicsDevice.AllocateReadOnlyBuffer<Complex64>(KernelSize);
|
||||
|
||||
// Preliminary gamma highlight pass
|
||||
Gpu.Default.For<GammaHighlightProcessor>(source.Height, new(texture));
|
||||
GraphicsDevice.For<GammaHighlightProcessor>(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<VerticalConvolutionProcessor>(
|
||||
GraphicsDevice.For<VerticalConvolutionProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(texture, reals, imaginaries, kernel));
|
||||
|
||||
Gpu.Default.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
|
||||
GraphicsDevice.For<HorizontalConvolutionAndAccumulatePartialsProcessor>(
|
||||
source.Width,
|
||||
source.Height,
|
||||
new(parameters.Z, parameters.W, reals, imaginaries, temporary, kernel));
|
||||
}
|
||||
|
||||
// Apply the inverse gamma exposure pass
|
||||
Gpu.Default.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
|
||||
GraphicsDevice.For<InverseGammaHighlightProcessor>(source.Height, new(temporary, texture));
|
||||
|
||||
// Write the final pixel data
|
||||
texture.CopyTo(span);
|
||||
|
||||
@@ -20,25 +20,48 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
public HlslGaussianBlurProcessor() : this(DefaultSigma, 9) { }
|
||||
public HlslGaussianBlurProcessor()
|
||||
: this(Gpu.Default, DefaultSigma, 9)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample.</param>
|
||||
public HlslGaussianBlurProcessor(int radius) : this(radius / 3F, radius) { }
|
||||
public HlslGaussianBlurProcessor(int radius)
|
||||
: this(Gpu.Default, radius / 3F, radius)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample.</param>
|
||||
public HlslGaussianBlurProcessor(GraphicsDevice device, int radius)
|
||||
: this(device, radius / 3F, radius)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HlslGaussianBlurProcessor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The <see cref="GraphicsDevice"/> associated with the current instance.</param>
|
||||
/// <param name="sigma"> The sigma value representing the weight of the blur. </param>
|
||||
/// <param name="radius">The radius value representing the size of the area to sample (this should be at least twice the sigma value)</param>
|
||||
public HlslGaussianBlurProcessor(float sigma, int radius)
|
||||
public HlslGaussianBlurProcessor(GraphicsDevice device, float sigma, int radius)
|
||||
{
|
||||
GraphicsDevice = device;
|
||||
Sigma = sigma;
|
||||
Radius = radius;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the sigma value representing the weight of the blur.
|
||||
/// </summary>
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace ComputeSharp.BokehBlur.Processors
|
||||
/// </summary>
|
||||
internal sealed partial class Implementation : ImageProcessor<ImageSharpRgba32>
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="ComputeSharp.GraphicsDevice"/> instance in use.
|
||||
/// </summary>
|
||||
private readonly GraphicsDevice GraphicsDevice;
|
||||
|
||||
/// <summary>
|
||||
/// The 1D kernel to apply.
|
||||
/// </summary>
|
||||
@@ -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<Rgba32> span = MemoryMarshal.Cast<ImageSharpRgba32, Rgba32>(pixelSpan);
|
||||
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = Gpu.Default.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<float> kernelBuffer = Gpu.Default.AllocateReadOnlyBuffer(Kernel);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(span, source.Width, source.Height);
|
||||
using ReadWriteTexture2D<Rgba32, Vector4> firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D<Rgba32, Vector4>(source.Width, source.Height);
|
||||
using ReadOnlyBuffer<float> kernelBuffer = GraphicsDevice.AllocateReadOnlyBuffer(Kernel);
|
||||
|
||||
Gpu.Default.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
|
||||
Gpu.Default.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
|
||||
GraphicsDevice.For<VerticalConvolutionProcessor>(source.Width, source.Height, new(sourceTexture, firstPassTexture, kernelBuffer));
|
||||
GraphicsDevice.For<HorizontalConvolutionProcessor>(source.Width, source.Height, new(firstPassTexture, sourceTexture, kernelBuffer));
|
||||
|
||||
sourceTexture.CopyTo(span);
|
||||
}
|
||||
|
||||
@@ -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<ImageSharpRgba32>(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<ImageSharpRgba32>(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"),
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする