diff --git a/samples/ComputeSharp.BokehBlur/Processor/HlslBokehBlurProcessor{TPixel}.cs b/samples/ComputeSharp.BokehBlur/Processor/HlslBokehBlurProcessor{TPixel}.cs index 5f23c843..63fb9d1d 100644 --- a/samples/ComputeSharp.BokehBlur/Processor/HlslBokehBlurProcessor{TPixel}.cs +++ b/samples/ComputeSharp.BokehBlur/Processor/HlslBokehBlurProcessor{TPixel}.cs @@ -11,6 +11,7 @@ using SixLabors.ImageSharp; using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing.Processors; +using SixLabors.Memory; using SixLabors.Primitives; namespace ComputeSharp.BokehBlur.Processor @@ -256,44 +257,43 @@ namespace ComputeSharp.BokehBlur.Processor // Preliminary gamma highlight pass using IMemoryOwner source4 = GetExposedVector4Buffer(source); - using ReadOnlyBuffer source4_gpu = Gpu.Default.AllocateReadOnlyBuffer(source4.Memory.Span); - using ReadWriteBuffer processing_gpu = Gpu.Default.AllocateReadWriteBuffer(source4.Memory.Length); - using ReadWriteBuffer firstPassValues_gpu = Gpu.Default.AllocateReadWriteBuffer(source4.Memory.Length * 2); - using ReadWriteBuffer secondPassBuffer_gpu = Gpu.Default.AllocateReadWriteBuffer(source4.Memory.Length * 2); + using IMemoryOwner processingBuffer = source.GetConfiguration().MemoryAllocator.Allocate(source4.Memory.Length, AllocationOptions.Clean); + using IMemoryOwner firstPassBuffer = source.GetConfiguration().MemoryAllocator.Allocate(source4.Memory.Length * 2); + using IMemoryOwner secondPassBuffer = source.GetConfiguration().MemoryAllocator.Allocate(source4.Memory.Length * 2); // Perform two 1D convolutions for each component in the current instance for (int i = 0; i < Kernels.Length; i++) { // Compute the resulting complex buffer for the current component - using ReadOnlyBuffer kernel_gpu = Gpu.Default.AllocateReadOnlyBuffer(Kernels[i]); - ApplyVerticalConvolution(source4_gpu, firstPassValues_gpu, kernel_gpu, source.Width, source.Height); - ApplyHorizontalConvolution(firstPassValues_gpu, secondPassBuffer_gpu, kernel_gpu, source.Width, source.Height); + using IMemoryOwner kernel = source.GetConfiguration().MemoryAllocator.Allocate(Kernels[i].Length); + Kernels[i].AsSpan().CopyTo(kernel.Memory.Span); + ApplyVerticalConvolution(source4, firstPassBuffer, kernel, source.Width, source.Height); + ApplyHorizontalConvolution(firstPassBuffer, secondPassBuffer, kernel, source.Width, source.Height); // Add the results of the convolution with the current kernel Vector4 parameters = KernelParameters[i]; - SumProcessingPartials(secondPassBuffer_gpu, processing_gpu, parameters.Z, parameters.W, source.Width, source.Height); + SumProcessingPartials(secondPassBuffer, processingBuffer, parameters.Z, parameters.W, source.Width, source.Height); } // Apply the inverse gamma exposure pass, and write the final pixel data - processing_gpu.GetData(source4.Memory.Span); - ApplyInverseGammaExposure(source4, source); + ApplyInverseGammaExposure(processingBuffer, source); } /// /// Performs a vertical 1D complex convolution with the specified parameters /// - /// The source to read data from - /// The target to write the results to - /// The with the values for the current complex kernel + /// The source to read data from + /// The target to write the results to + /// The with the values for the current complex kernel /// The width of the image being processed /// The height of the image being processed private void ApplyVerticalConvolution( - ReadOnlyBuffer source, - ReadWriteBuffer target, - ReadOnlyBuffer kernel, + IMemoryOwner source, + IMemoryOwner target, + IMemoryOwner kernel, int width, int height) { - int kernelLength = kernel.Size; + int kernelLength = kernel.Memory.Length; int radiusY = kernelLength >> 1; int maxRow = height - 1; @@ -303,18 +303,18 @@ namespace ComputeSharp.BokehBlur.Processor /// /// Performs an horizontal 1D complex convolution with the specified parameters /// - /// The source to read data from - /// The target to write the results to - /// The with the values for the current complex kernel + /// The source to read data from + /// The target to write the results to + /// The with the values for the current complex kernel /// The width of the image being processed /// The height of the image being processed private void ApplyHorizontalConvolution( - ReadWriteBuffer source, - ReadWriteBuffer target, - ReadOnlyBuffer kernel, + IMemoryOwner source, + IMemoryOwner target, + IMemoryOwner kernel, int width, int height) { - int kernelLength = kernel.Size; + int kernelLength = kernel.Memory.Length; int radiusX = kernelLength >> 1; int maxRow = height - 1; int maxColumn = width - 1; @@ -385,15 +385,15 @@ namespace ComputeSharp.BokehBlur.Processor /// /// Sums the partial results for a complex convolution pass over a single kernel component /// - /// The source to read data from - /// The target to write the results to + /// The source to read data from + /// The target to write the results to /// The weight factor for the real component of the complex pixel values /// The weight factor for the imaginary component of the complex pixel values /// The width of the image being processed /// The height of the image being processed private void SumProcessingPartials( - ReadWriteBuffer source, - ReadWriteBuffer target, + IMemoryOwner source, + IMemoryOwner target, float z, float w, int width, int height)