Browse Source

Revert some convolution processors

pull/3113/head
James Jackson-South 1 month ago
parent
commit
03670ab032
  1. 26
      src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs
  2. 15
      src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs
  3. 12
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs

26
src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs

@ -123,15 +123,10 @@ internal class Convolution2PassProcessor<TPixel> : ImageProcessor<TPixel>
this.Configuration,
this.PreserveAlpha);
using (IMemoryOwner<Vector4> hBuffer = allocator.Allocate<Vector4>(horizontalOperation.GetRequiredBufferLength(interest)))
{
Span<Vector4> hSpan = hBuffer.Memory.Span;
for (int y = interest.Top; y < interest.Bottom; y++)
{
horizontalOperation.Invoke(y, hSpan);
}
}
ParallelRowIterator.IterateRows<HorizontalConvolutionRowOperation, Vector4>(
this.Configuration,
interest,
in horizontalOperation);
// Vertical convolution
VerticalConvolutionRowOperation verticalOperation = new(
@ -143,15 +138,10 @@ internal class Convolution2PassProcessor<TPixel> : ImageProcessor<TPixel>
this.Configuration,
this.PreserveAlpha);
using (IMemoryOwner<Vector4> vBuffer = allocator.Allocate<Vector4>(verticalOperation.GetRequiredBufferLength(interest)))
{
Span<Vector4> vSpan = vBuffer.Memory.Span;
for (int y = interest.Top; y < interest.Bottom; y++)
{
verticalOperation.Invoke(y, vSpan);
}
}
ParallelRowIterator.IterateRows<VerticalConvolutionRowOperation, Vector4>(
this.Configuration,
interest,
in verticalOperation);
}
/// <summary>

15
src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs

@ -97,17 +97,10 @@ internal class ConvolutionProcessor<TPixel> : ImageProcessor<TPixel>
map.BuildSamplingOffsetMap(this.KernelXY.Rows, this.KernelXY.Columns, interest, this.BorderWrapModeX, this.BorderWrapModeY);
RowOperation operation = new(interest, targetPixels, source.PixelBuffer, map, this.KernelXY, this.Configuration, this.PreserveAlpha);
// Convolution is memory-bandwidth-bound with low arithmetic intensity.
// Parallelization degrades performance due to cache line contention from
// overlapping source row reads. See #3111.
using IMemoryOwner<Vector4> buffer = allocator.Allocate<Vector4>(operation.GetRequiredBufferLength(interest));
Span<Vector4> span = buffer.Memory.Span;
for (int y = interest.Top; y < interest.Bottom; y++)
{
operation.Invoke(y, span);
}
ParallelRowIterator.IterateRows<RowOperation, Vector4>(
this.Configuration,
interest,
in operation);
}
Buffer2D<TPixel>.SwapOrCopyContent(source.PixelBuffer, targetPixels);

12
src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs

@ -83,15 +83,11 @@ internal class EdgeDetectorCompassProcessor<TPixel> : ImageProcessor<TPixel>
processor.Apply(pass);
}
// Convolution is memory-bandwidth-bound with low arithmetic intensity.
// Parallelization degrades performance due to cache line contention from
// overlapping source row reads. See #3111.
RowOperation operation = new(source.PixelBuffer, pass.PixelBuffer, interest);
for (int y = interest.Top; y < interest.Bottom; y++)
{
operation.Invoke(y);
}
ParallelRowIterator.IterateRows(
this.Configuration,
interest,
in operation);
}
}

Loading…
Cancel
Save