diff --git a/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs b/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs index 9d58f23..ad59ada 100644 --- a/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs +++ b/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs @@ -335,7 +335,7 @@ public sealed class CpuTileConvolverTests } [Fact] - public void OnlyTheThreadsThatComputeKeepAWorkingAreaOfTheCurrentSize() + public void OnlyTheThreadsThatComputeKeepAWorkingArea() { static long PerThread(int size) => ((long)size * size * 4 + size * 4 * 2) * sizeof(float); static void Convolve(CpuTileConvolver convolver, int size, int radius, int regionSide) @@ -355,9 +355,6 @@ public sealed class CpuTileConvolverTests Convolve(convolver, 512, 24, 2000); Assert.Equal(16 * PerThread(512), convolver.WorkingBytes); - - Convolve(convolver, 128, 3, 610); - Assert.Equal(24 * PerThread(128), convolver.WorkingBytes); } static (byte[] Output, float[] Convolved) RunLight(ConvolutionScene scene, int threads, float gain) diff --git a/SpectralConvolution/SpectralConvolution/CpuTileConvolver.cs b/SpectralConvolution/SpectralConvolution/CpuTileConvolver.cs index 540e52f..89e4b45 100644 --- a/SpectralConvolution/SpectralConvolution/CpuTileConvolver.cs +++ b/SpectralConvolution/SpectralConvolution/CpuTileConvolver.cs @@ -15,13 +15,12 @@ internal sealed class CpuTileConvolver : IDisposable readonly Worker[] workers; readonly WorkerPool pool; - readonly bool sharesEngine; + readonly bool ownsEngine; readonly ConvolveJob convolveJob; readonly RenderJob renderJob; bool disposed; int[] reversal = []; int reversalSize; - int workingSize; byte[] source = []; int sourceX; int sourceY; @@ -47,20 +46,20 @@ internal sealed class CpuTileConvolver : IDisposable } public CpuTileConvolver(int threadCount) - : this(new Engine(threadCount), false) + : this(new Engine(threadCount), true) { } - CpuTileConvolver(Engine engine, bool sharesEngine) + CpuTileConvolver(Engine engine, bool ownsEngine) { workers = engine.Workers; pool = engine.Pool; - this.sharesEngine = sharesEngine; + this.ownsEngine = ownsEngine; convolveJob = new ConvolveJob(this); renderJob = new RenderJob(this); } - public static CpuTileConvolver CreateShared() => new(SharedEngine.Value, true); + public static CpuTileConvolver CreateShared() => new(SharedEngine.Value, false); public int Threads => workers.Length; @@ -147,7 +146,6 @@ internal sealed class CpuTileConvolver : IDisposable ObjectDisposedException.ThrowIf(disposed, this); EnsureReversal(tilePlan.Size, tilePlan.Log2Size); - EnsureWorkingSize(tilePlan.Size); source = sourcePixels; sourceX = sourceLeft; @@ -228,7 +226,7 @@ internal sealed class CpuTileConvolver : IDisposable if (disposed) return; disposed = true; - if (!sharesEngine) + if (ownsEngine) pool.Dispose(); } @@ -242,15 +240,6 @@ internal sealed class CpuTileConvolver : IDisposable reversalSize = size; } - void EnsureWorkingSize(int size) - { - if (sharesEngine || workingSize == size) - return; - foreach (var worker in workers) - worker.Release(); - workingSize = size; - } - void ConvolveTile(int tile, Worker worker) { var size = plan.Size; @@ -528,14 +517,5 @@ internal sealed class CpuTileConvolver : IDisposable BlueAlphaSpare = new float[rowLength]; } } - - public void Release() - { - Tile = []; - Line = []; - Spare = []; - BlueAlphaLine = []; - BlueAlphaSpare = []; - } } }