From 37a5e8d30f0702fd8e17ca67069b587e8bb8468d Mon Sep 17 00:00:00 2001 From: routersys Date: Sat, 18 Jul 2026 14:07:08 +0900 Subject: [PATCH] =?UTF-8?q?=E7=8B=AD=E3=81=84=E8=BC=9D=E5=BA=A6=E5=9F=9F?= =?UTF-8?q?=E3=81=A7Simulate=E7=B5=8C=E8=B7=AF=E3=81=A8=E4=B8=80=E6=8B=AC?= =?UTF-8?q?=E7=B5=8C=E8=B7=AF=E3=81=8C=E5=85=A8=E7=94=BB=E7=B4=A0=E4=B8=80?= =?UTF-8?q?=E8=87=B4=E3=81=99=E3=82=8B=E3=81=8B=E6=A4=9C=E8=A8=BC=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LaplacianRemapping.Harness/Program.cs | 25 ++++++++++ .../LaplacianRemappingEffectTests.cs | 49 +++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/LaplacianRemapping.Harness/Program.cs b/LaplacianRemapping.Harness/Program.cs index c787336..89f6ddb 100644 --- a/LaplacianRemapping.Harness/Program.cs +++ b/LaplacianRemapping.Harness/Program.cs @@ -69,6 +69,31 @@ foreach (var quality in new[] { LaplacianRemappingQuality.Balanced, LaplacianRem stopwatch.Stop(); Console.WriteLine($"structure recompute: {stopwatch.Elapsed.TotalMilliseconds:F2} ms"); + var darkPixels = new Bgra32[source.Length]; + for (var index = 0; index < source.Length; index++) + { + var pixel = source[index]; + var r = ((pixel >> 16) & 255) / 4; + var g = ((pixel >> 8) & 255) / 4; + var b = (pixel & 255) / 4; + darkPixels[index].PackedValue = (uint)(pixel & unchecked((int)0xFF000000)) | (uint)(r << 16 | g << 8 | b); + } + using var darkTexture = device.AllocateReadWriteTexture2D(width, height); + darkTexture.CopyFrom(darkPixels); + pipeline.Simulate(darkTexture, width, height, in parameters); + stopwatch.Restart(); + pipeline.Simulate(darkTexture, width, height, parameters with { Detail = 0.6f }); + stopwatch.Stop(); + Console.WriteLine($"dark structure recompute: {stopwatch.Elapsed.TotalMilliseconds:F2} ms"); + pipeline.Simulate(sourceTexture, width, height, parameters with { Detail = 0.6f }); + + stopwatch.Restart(); + const int hitFrames = 200; + for (var frame = 0; frame < hitFrames; frame++) + pipeline.Simulate(sourceTexture, width, height, parameters with { Detail = 0.6f }); + stopwatch.Stop(); + Console.WriteLine($"cache-hit simulate: {stopwatch.Elapsed.TotalMilliseconds / hitFrames:F3} ms/frame"); + if (pipeline.TryGetVisibleBounds(width, height, out var rect)) { using var rectOutput = device.AllocateReadWriteTexture2D(rect.Width, rect.Height); diff --git a/LaplacianRemapping.Tests/LaplacianRemappingEffectTests.cs b/LaplacianRemapping.Tests/LaplacianRemappingEffectTests.cs index cc953e6..ce3faa9 100644 --- a/LaplacianRemapping.Tests/LaplacianRemappingEffectTests.cs +++ b/LaplacianRemapping.Tests/LaplacianRemappingEffectTests.cs @@ -419,6 +419,55 @@ public sealed class LaplacianRemappingEffectTests } } + [Fact] + public void SimulatePathMatchesFullRenderOnNarrowLuminanceRange() + { + using var pipeline = LaplacianRemappingPipeline.TryCreate(); + if (pipeline is null) + { + Assert.Skip("Direct3D 12 is unavailable."); + return; + } + + const int width = 128; + const int height = 128; + var source = new int[width * height]; + for (var y = 8; y < height - 8; y++) + { + for (var x = 8; x < width - 8; x++) + { + var value = 24 + (((x / 4 + y / 4) & 1) == 0 ? 24 : 0) + 16 * x / width; + source[y * width + x] = unchecked((int)0xFF000000) | value << 16 | value << 8 | value; + } + } + var full = new int[source.Length]; + var parameters = CreateParameters(detail: 1f, tone: -0.5f, threshold: 0.1f); + pipeline.Process(source, full, width, height, in parameters); + + var device = GraphicsDevice.GetDefault(); + using var sourceTexture = device.AllocateReadWriteTexture2D(width, height); + var sourcePixels = new Bgra32[source.Length]; + for (var index = 0; index < source.Length; index++) + sourcePixels[index].PackedValue = unchecked((uint)source[index]); + sourceTexture.CopyFrom(sourcePixels); + + pipeline.Simulate(sourceTexture, width, height, in parameters); + Assert.True(pipeline.TryGetVisibleBounds(width, height, out var rect)); + using var outputTexture = device.AllocateReadWriteTexture2D(rect.Width, rect.Height); + pipeline.RenderVisible(sourceTexture, outputTexture, width, height, rect); + var result = new Bgra32[rect.Width * rect.Height]; + outputTexture.CopyTo(result); + + for (var y = 0; y < rect.Height; y++) + { + for (var x = 0; x < rect.Width; x++) + { + var expected = unchecked((uint)full[(rect.Y + y) * width + rect.X + x]); + Assert.Equal(expected, result[y * rect.Width + x].PackedValue); + } + } + } + [Fact] public void SimulateCachesStructureUntilInputsChange() {