From 4dcdf283aa78ae7992434454edef5d96ad7dc701 Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 6 Oct 2026 18:32:24 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A4=89=E7=95=B0=E8=A9=A6=E9=A8=93=E3=81=A7?= =?UTF-8?q?=E8=A6=8B=E3=81=A4=E3=81=91=E3=81=9F=E5=B9=85=E3=81=A8=E5=8C=BA?= =?UTF-8?q?=E7=94=BB=E3=81=AE=E7=B6=99=E3=81=8E=E7=9B=AE=E3=81=A8=E8=A8=B1?= =?UTF-8?q?=E5=AE=B9=E5=80=A4=E3=81=AE=E8=A9=A6=E9=A8=93=E3=81=AE=E6=BC=8F?= =?UTF-8?q?=E3=82=8C=E3=82=92=E8=A3=9C=E3=81=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CpuTileConvolverTests.cs | 25 +++++++++++ .../GpuTileConvolverTests.cs | 43 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs b/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs index 6c4bcde..eb1a194 100644 --- a/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs +++ b/SpectralConvolution/SpectralConvolution.Tests/CpuTileConvolverTests.cs @@ -465,10 +465,14 @@ public sealed class CpuTileConvolverTests var actual = (float[])expected.Clone(); + var narrow = (float[])expected.Clone(); + CpuTileConvolver.ButterfliesScalar(expected, log2, twiddles, direction); CpuTileConvolver.Butterflies(actual, log2, twiddles, direction); + CpuTileConvolver.Butterflies(narrow, log2, twiddles, direction, allowWide: false); Assert.Equal(expected.Select(BitConverter.SingleToInt32Bits), actual.Select(BitConverter.SingleToInt32Bits)); + Assert.Equal(expected.Select(BitConverter.SingleToInt32Bits), narrow.Select(BitConverter.SingleToInt32Bits)); } } @@ -583,4 +587,25 @@ public sealed class CpuTileConvolverTests } } } + + [Theory] + [InlineData(true)] + [InlineData(false)] + public void RenderingASeveralChunkStoreAwayFromTheOriginKeepsEveryPosition(bool linear) + { + var light = new LightOptions(linear, true, 0.85f, linear ? 12f : 0f); + var source = ConvolutionScene.RandomSource(100, 60, 80, 0.5); + var scene = ConvolutionScene.CreateShifted(source, 103, 59, 100, 60, 97, 53, 313, 207, 4, 64, light); + var plan = scene.Plan; + Assert.True(plan.RegionWidth * plan.RegionHeight > CpuTileConvolver.StoredChunkPixels * 3); + Assert.NotEqual(0, CpuTileConvolver.StoredChunkPixels % plan.RegionWidth); + var (expected, _) = RunLight(scene, 3, 1.2f); + var (_, stored) = RunLight(scene, 3, 1f); + var output = new byte[scene.RegionLength]; + using var convolver = new CpuTileConvolver(4); + + convolver.RenderStored(stored, plan.RegionWidth * plan.RegionHeight, 1.2f, output, light, plan.RegionWidth, plan.RegionX, plan.RegionY); + + Assert.Equal(expected, output); + } } diff --git a/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs b/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs index d56eb4c..b4421a6 100644 --- a/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs +++ b/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs @@ -694,4 +694,47 @@ public sealed class GpuTileConvolverTests Assert.InRange(scene.WorstRatio(run.Store, ConvolutionBound.GpuOperationError + GpuTileCheck.LightTransformError), 0d, 1d); AssertOutputIsTheTransformOfTheStore(scene, run, 1f, light); } + + [Fact] + public void PreparingInvalidLightOptionsIsRejected() + { + var scene = ConvolutionScene.Create(ConvolutionScene.RandomSource(100, 60, 3, 0.5), 100, 60, 8, 4, 64); + var plan = scene.Plan; + using var convolver = new GpuTileConvolver(HardwareOrDefault()); + convolver.Upload(scene.Spectrum); + + Assert.Throws(() => convolver.Prepare(plan, 8, 8, 100, 60, 1f, [], false, new LightOptions(true, false, 1.5f, 5f))); + Assert.Throws(() => convolver.Prepare(plan, 8, 8, 100, 60, 1f, [], false, new LightOptions(true, false, 0.5f, 2000f))); + convolver.Prepare(plan, 8, 8, 100, 60, 1f, [], false, new LightOptions(true, false, 0.5f, 5f)); + } + + [Fact] + public void TheLinearLightToleranceExceedsTheOtherOneByTheTransformError() + { + var scene = ConvolutionScene.Create(ConvolutionScene.RandomSource(150, 97, 31, 0.45), 150, 97, 11, 5, 64, new LightOptions(true, false, 0f, 0f)); + var run = Run(HardwareOrDefault(), scene); + var plan = scene.Plan; + var sampleCount = run.Samples.Length; + var linear = new ConvolutionMeasurement[GpuTileCheck.MeasurementCount(sampleCount)]; + var plain = new ConvolutionMeasurement[linear.Length]; + var linearJob = run.Job with { Light = new LightOptions(true, true, 0f, 0f) }; + var plainJob = run.Job with { Light = new LightOptions(false, true, 0f, 0f) }; + + GpuTileCheck.Evaluate(run.Report, linearJob, run.Samples, scene.Spectrum.Kernel, linear); + GpuTileCheck.Evaluate(run.Report, plainJob, run.Samples, scene.Spectrum.Kernel, plain); + + for (var sample = 0; sample < sampleCount; sample++) + { + var tile = plan.TileAt(plan.RegionX + run.Samples[sample].X, plan.RegionY + run.Samples[sample].Y); + var (redGreen, blueAlpha) = GpuTileCheck.Norms(run.Report, plan, tile, true); + for (var channel = 0; channel < 4; channel++) + { + var index = 1 + 4 + sample * 4 + channel; + var norm = channel < 2 ? redGreen : blueAlpha; + Assert.Equal(GpuTileCheck.LightTransformError * norm, linear[index].Tolerance - plain[index].Tolerance, norm * 1e-12); + } + } + + Assert.Equal(Math.ScaleB(1d, -16), GpuTileCheck.LightTransformError); + } }