From 2b06c4ac5483bb301ac94597e83017f66c40fe99 Mon Sep 17 00:00:00 2001 From: routersys Date: Sat, 10 Oct 2026 09:48:14 +0900 Subject: [PATCH] =?UTF-8?q?CPU=E3=81=AE=E7=95=B3=E3=81=BF=E8=BE=BC?= =?UTF-8?q?=E3=81=BF=E3=81=AE=E4=BD=9C=E6=A5=AD=E9=A0=98=E5=9F=9F=E3=81=AE?= =?UTF-8?q?=E5=A4=A7=E3=81=8D=E3=81=95=E5=A4=89=E6=9B=B4=E3=81=AE=E8=A7=A3?= =?UTF-8?q?=E6=94=BE=E3=82=92=E5=8F=96=E3=82=8A=E9=99=A4=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CpuTileConvolverTests.cs | 5 +-- .../SpectralConvolution/CpuTileConvolver.cs | 32 ++++--------------- 2 files changed, 7 insertions(+), 30 deletions(-) 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 = []; - } } }