From f0ed5c46cfd69631a0540d495369b2120d531ce3 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 4 Jun 2022 17:11:02 +0200 Subject: [PATCH] Update ImageSharp to 2.1.2 --- .../ComputeSharp.Benchmark.csproj | 2 +- .../Imaging/ImagingBenchmark.cs | 2 ++ .../ComputeSharp.ImageProcessing.csproj | 2 +- .../Processors/HlslBokehBlurProcessor{TPixel}.cs | 4 ++-- .../HlslGaussianBlurProcessor{TPixel}.cs | 4 ++-- samples/ComputeSharp.ImageProcessing/Program.cs | 2 ++ .../ComputeSharp.D2D1.Tests.csproj | 2 +- tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs | 7 +++++++ ...uteSharp.Tests.DisableDynamicCompilation.csproj | 2 +- tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj | 2 +- .../Extensions/ImagingExtensions.cs | 8 ++++---- .../Helpers/TolerantImageComparer.cs | 14 +++++++------- tests/ComputeSharp.Tests/ImagingTests.cs | 8 +++++++- tests/ComputeSharp.Tests/ShadersTests.cs | 8 ++++---- 14 files changed, 42 insertions(+), 25 deletions(-) diff --git a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj index 002e1078..678e0982 100644 --- a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj +++ b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj @@ -19,7 +19,7 @@ - + diff --git a/samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs b/samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs index 72f57439..12ecc013 100644 --- a/samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs +++ b/samples/ComputeSharp.Benchmark/Imaging/ImagingBenchmark.cs @@ -31,6 +31,8 @@ public class ImagingBenchmark : IDisposable [GlobalSetup] public void Setup() { + Configuration.Default.PreferContiguousImageBuffers = true; + string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Imaging", "city.jpg"); this.image = Image.Load(path); diff --git a/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj b/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj index 59564f49..76b697a3 100644 --- a/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj +++ b/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj @@ -11,7 +11,7 @@ - + diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs index 4d3e7888..b9187cf0 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslBokehBlurProcessor{TPixel}.cs @@ -263,12 +263,12 @@ public sealed partial class HlslBokehBlurProcessor /// protected override void OnFrameApply(ImageFrame source) { - if (!source.TryGetSinglePixelSpan(out Span pixelSpan)) + if (!source.DangerousTryGetSinglePixelMemory(out Memory pixelMemory)) { ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory."); } - Span span = MemoryMarshal.Cast(pixelSpan); + Span span = MemoryMarshal.Cast(pixelMemory.Span); using ReadWriteTexture2D texture = GraphicsDevice.AllocateReadWriteTexture2D(span, source.Width, source.Height); using ReadWriteTexture2D temporary = GraphicsDevice.AllocateReadWriteTexture2D(source.Width, source.Height, AllocationMode.Clear); diff --git a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs index 33aa5541..d6edd6e6 100644 --- a/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.ImageProcessing/Processors/HlslGaussianBlurProcessor{TPixel}.cs @@ -93,12 +93,12 @@ public sealed partial class HlslGaussianBlurProcessor /// protected override void OnFrameApply(ImageFrame source) { - if (!source.TryGetSinglePixelSpan(out Span pixelSpan)) + if (!source.DangerousTryGetSinglePixelMemory(out Memory pixelMemory)) { ThrowHelper.ThrowInvalidOperationException("Cannot process image frames wrapping discontiguous memory."); } - Span span = MemoryMarshal.Cast(pixelSpan); + Span span = MemoryMarshal.Cast(pixelMemory.Span); using ReadWriteTexture2D sourceTexture = GraphicsDevice.AllocateReadWriteTexture2D(span, source.Width, source.Height); using ReadWriteTexture2D firstPassTexture = GraphicsDevice.AllocateReadWriteTexture2D(source.Width, source.Height); diff --git a/samples/ComputeSharp.ImageProcessing/Program.cs b/samples/ComputeSharp.ImageProcessing/Program.cs index 0318a63e..0886c24b 100644 --- a/samples/ComputeSharp.ImageProcessing/Program.cs +++ b/samples/ComputeSharp.ImageProcessing/Program.cs @@ -13,6 +13,8 @@ class Program { static void Main() { + Configuration.Default.PreferContiguousImageBuffers = true; + Console.WriteLine(">> Loading image"); string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "city.jpg"); using Image image = Image.Load(path); diff --git a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj index 16fd9b98..4ea5b499 100644 --- a/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj +++ b/tests/ComputeSharp.D2D1.Tests/ComputeSharp.D2D1.Tests.csproj @@ -16,7 +16,7 @@ - + diff --git a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs index a8e2fc4d..c44fb1c0 100644 --- a/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/EndToEndTests.cs @@ -6,6 +6,7 @@ using ComputeSharp.D2D1.Tests.Effects; using ComputeSharp.D2D1.Tests.Helpers; using ComputeSharp.Tests.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; +using SixLabors.ImageSharp; namespace ComputeSharp.D2D1.Tests; @@ -13,6 +14,12 @@ namespace ComputeSharp.D2D1.Tests; [TestCategory("EndToEnd")] public class EndToEndTests { + [AssemblyInitialize] + public static void ConfigureImageSharp() + { + Configuration.Default.PreferContiguousImageBuffers = true; + } + [TestMethod] public unsafe void Invert() { diff --git a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj index ea6ed60b..7f7bae0f 100644 --- a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj +++ b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj @@ -11,7 +11,7 @@ - + diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj index fb26bd84..1365ca64 100644 --- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj +++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj @@ -11,7 +11,7 @@ - + diff --git a/tests/ComputeSharp.Tests/Extensions/ImagingExtensions.cs b/tests/ComputeSharp.Tests/Extensions/ImagingExtensions.cs index bf4a3ddc..8470ebb3 100644 --- a/tests/ComputeSharp.Tests/Extensions/ImagingExtensions.cs +++ b/tests/ComputeSharp.Tests/Extensions/ImagingExtensions.cs @@ -28,9 +28,9 @@ public static class ImagingExtensions Image image = new(texture.Width, texture.Height); - Assert.IsTrue(image.TryGetSinglePixelSpan(out Span span)); + Assert.IsTrue(image.DangerousTryGetSinglePixelMemory(out Memory memory)); - Span pixels = MemoryMarshal.Cast(span); + Span pixels = MemoryMarshal.Cast(memory.Span); texture.CopyTo(pixels); @@ -53,9 +53,9 @@ public static class ImagingExtensions Image image = new(texture.Width, texture.Height); - Assert.IsTrue(image.TryGetSinglePixelSpan(out Span span)); + Assert.IsTrue(image.DangerousTryGetSinglePixelMemory(out Memory memory)); - Span pixels = MemoryMarshal.Cast(span); + Span pixels = MemoryMarshal.Cast(memory.Span); texture.CopyTo(pixels, 0, 0, depth, texture.Width, texture.Height, 1); diff --git a/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs b/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs index 1c7c16ef..4f3594c3 100644 --- a/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs +++ b/tests/ComputeSharp.Tests/Helpers/TolerantImageComparer.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; using System.Text; -using SixLabors.ImageSharp; -using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32; +using System.Runtime.CompilerServices; using Microsoft.VisualStudio.TestTools.UnitTesting; +using SixLabors.ImageSharp; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Advanced; -using System.Runtime.CompilerServices; +using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32; namespace ComputeSharp.Tests.Helpers; @@ -61,11 +61,11 @@ internal static class TolerantImageComparer for (int y = 0; y < actual.Height; y++) { - Span aSpan = expected.GetPixelRowSpan(y); - Span bSpan = actual.GetPixelRowSpan(y); + Memory aMemory = expected.DangerousGetPixelRowMemory(y); + Memory bMemory = actual.DangerousGetPixelRowMemory(y); - PixelOperations.Instance.ToRgba32(actual.GetConfiguration(), aSpan, aBuffer); - PixelOperations.Instance.ToRgba32(actual.GetConfiguration(), bSpan, bBuffer); + PixelOperations.Instance.ToRgba32(actual.GetConfiguration(), aMemory.Span, aBuffer); + PixelOperations.Instance.ToRgba32(actual.GetConfiguration(), bMemory.Span, bBuffer); for (int x = 0; x < width; x++) { diff --git a/tests/ComputeSharp.Tests/ImagingTests.cs b/tests/ComputeSharp.Tests/ImagingTests.cs index 75849c9a..2ef5ba13 100644 --- a/tests/ComputeSharp.Tests/ImagingTests.cs +++ b/tests/ComputeSharp.Tests/ImagingTests.cs @@ -6,12 +6,12 @@ using CommunityToolkit.HighPerformance.Buffers; using ComputeSharp.Resources; using ComputeSharp.Tests.Attributes; using ComputeSharp.Tests.Extensions; +using ComputeSharp.Tests.Helpers; using Microsoft.VisualStudio.TestTools.UnitTesting; using SixLabors.ImageSharp; using ImageSharpRgba32 = SixLabors.ImageSharp.PixelFormats.Rgba32; using ImageSharpBgra32 = SixLabors.ImageSharp.PixelFormats.Bgra32; using ImageSharpL8 = SixLabors.ImageSharp.PixelFormats.L8; -using ComputeSharp.Tests.Helpers; namespace ComputeSharp.Tests; @@ -19,6 +19,12 @@ namespace ComputeSharp.Tests; [TestCategory("Imaging")] public class ImagingTests { + [AssemblyInitialize] + public static void ConfigureImageSharp() + { + Configuration.Default.PreferContiguousImageBuffers = true; + } + [CombinatorialTestMethod] [AllDevices] [Resource(typeof(ReadOnlyTexture2D<,>))] diff --git a/tests/ComputeSharp.Tests/ShadersTests.cs b/tests/ComputeSharp.Tests/ShadersTests.cs index bc04c844..515a829d 100644 --- a/tests/ComputeSharp.Tests/ShadersTests.cs +++ b/tests/ComputeSharp.Tests/ShadersTests.cs @@ -186,9 +186,9 @@ public class ShadersTests action.Method.GetGenericMethodDefinition().MakeGenericMethod(shaderType).Invoke(null, new[] { texture }); } - _ = image.TryGetSinglePixelSpan(out Span span); + _ = image.DangerousTryGetSinglePixelMemory(out Memory memory); - texture.CopyTo(MemoryMarshal.Cast(span)); + texture.CopyTo(MemoryMarshal.Cast(memory.Span)); } string actualPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Shaders", $"{shaderType.Name}.png"); @@ -246,9 +246,9 @@ public class ShadersTests texture.GraphicsDevice.ForEach(texture, pixelFactory(texture)); } - _ = image.TryGetSinglePixelSpan(out Span span); + _ = image.DangerousTryGetSinglePixelMemory(out Memory memory); - texture.CopyTo(MemoryMarshal.Cast(span)); + texture.CopyTo(MemoryMarshal.Cast(memory.Span)); } string actualPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "Shaders", $"{shaderType.Name}.png");