From 36faac26d295db2e17745f18f37a576103d48b17 Mon Sep 17 00:00:00 2001 From: routersys Date: Sat, 3 Oct 2026 09:44:42 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E5=AD=98=E3=81=97=E3=81=9F=E7=95=B3?= =?UTF-8?q?=E3=81=BF=E8=BE=BC=E3=81=BF=E3=81=AE=E5=80=A4=E3=81=AB=E3=82=B2?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=82=92=E6=8E=9B=E3=81=91=E3=81=A6=E6=8F=8F?= =?UTF-8?q?=E3=81=8F=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GpuTileConvolverTests.cs | 23 ++++++++++++++++++ .../SpectralConvolution/GpuTileConvolver.cs | 9 +++++++ .../SpectralConvolution/GpuTileShaders.cs | 24 +++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs b/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs index 1bd60f0..b91b578 100644 --- a/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs +++ b/SpectralConvolution/SpectralConvolution.Tests/GpuTileConvolverTests.cs @@ -146,6 +146,29 @@ public sealed class GpuTileConvolverTests } } + [Theory] + [InlineData(1f)] + [InlineData(2.75f)] + [InlineData(0.3f)] + public void RenderingTheStoreMatchesTheConvolutionBitForBit(float gain) + { + var scene = Scene(64, 5, 150, 97, 11, 47); + var device = HardwareOrDefault(); + var fused = Run(device, scene, gain); + using var convolver = new GpuTileConvolver(device); + var stored = Run(device, convolver, scene, 1f); + var width = scene.Plan.RegionWidth; + var height = scene.Plan.RegionHeight; + using var output = device.AllocateReadWriteTexture2D(width, height); + + using (var context = device.CreateComputeContext()) + GpuTileConvolver.RecordStored(in context, convolver.StoreFor(stored.Job), output, width, height, gain); + + var pixels = new Bgra32[width * height]; + output.CopyTo(pixels); + Assert.Equal(fused.Output, MemoryMarshal.Cast(pixels).ToArray()); + } + [Fact] public void TheStatisticsDescribeTheSource() { diff --git a/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs b/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs index 2818342..1267e2b 100644 --- a/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs +++ b/SpectralConvolution/SpectralConvolution/GpuTileConvolver.cs @@ -226,6 +226,15 @@ internal sealed class GpuTileConvolver : IDisposable context.Barrier(report); } + public static void RecordStored( + in ComputeContext context, + ReadWriteBuffer store, + ReadWriteTexture2D output, + int width, + int height, + float gain) + => context.For(width, height, new StoredRenderShader(store, output, width, height, gain)); + public void Dispose() { tiles?.Dispose(); diff --git a/SpectralConvolution/SpectralConvolution/GpuTileShaders.cs b/SpectralConvolution/SpectralConvolution/GpuTileShaders.cs index f755bd9..01f2028 100644 --- a/SpectralConvolution/SpectralConvolution/GpuTileShaders.cs +++ b/SpectralConvolution/SpectralConvolution/GpuTileShaders.cs @@ -16,6 +16,30 @@ internal readonly partial struct ReportResetShader( } } +[ThreadGroupSize(DefaultThreadGroupSizes.XY)] +[GeneratedComputeShaderDescriptor] +[CompileOptions(CompileOptions.Default | CompileOptions.IeeeStrictness)] +internal readonly partial struct StoredRenderShader( + ReadWriteBuffer store, + ReadWriteTexture2D output, + int width, + int height, + float gain) : IComputeShader +{ + private readonly ReadWriteBuffer store = store; + private readonly ReadWriteTexture2D output = output; + private readonly int width = width; + private readonly int height = height; + private readonly float gain = gain; + + public void Execute() + { + if (ThreadIds.X >= width || ThreadIds.Y >= height) + return; + output[ThreadIds.XY] = store[ThreadIds.Y * width + ThreadIds.X] * gain; + } +} + [ThreadGroupSize(DefaultThreadGroupSizes.XY)] [GeneratedComputeShaderDescriptor] [CompileOptions(CompileOptions.Default | CompileOptions.IeeeStrictness)]