From aa8f1da3d2a68b0909bd81fcefdb7f7f913b6c3a Mon Sep 17 00:00:00 2001 From: routersys Date: Fri, 9 Oct 2026 21:35:12 +0900 Subject: [PATCH] =?UTF-8?q?=E5=87=A6=E7=90=86=E5=99=A8=E3=81=AE=E3=83=95?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=83=A0=E3=81=8C=E7=A2=BA=E4=BF=9D=E3=81=97?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=93=E3=81=A8=E3=82=92=E8=A9=A6=E9=A8=93?= =?UTF-8?q?=E3=81=A7=E5=9B=BA=E3=82=81=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...aveOpticsEffectProcessorAllocationTests.cs | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 WaveOptics.Tests/WaveOpticsEffectProcessorAllocationTests.cs diff --git a/WaveOptics.Tests/WaveOpticsEffectProcessorAllocationTests.cs b/WaveOptics.Tests/WaveOpticsEffectProcessorAllocationTests.cs new file mode 100644 index 0000000..c0fdc75 --- /dev/null +++ b/WaveOptics.Tests/WaveOpticsEffectProcessorAllocationTests.cs @@ -0,0 +1,76 @@ +using ComputeGuard; +using ComputeWeave; +using WaveOptics.Effects; +using WaveOptics.Rendering; +using YukkuriMovieMaker.Commons; +using YukkuriMovieMaker.Player.Video; + +namespace WaveOptics.Tests; + +[Collection("Direct2D")] +public sealed class WaveOpticsEffectProcessorAllocationTests +{ + const int Size = 128; + const int Length = 60; + const int Rounds = 24; + + static Bgra Shape(int x, int y) => x is >= 32 and < 96 && y is >= 32 and < 96 && (x + 2 * y) % 9 != 0 ? Bgra.Opaque(220, 160, 90) : Bgra.Transparent; + + static void RequireInterop(IGraphicsDevicesAndContext devices) + { + using var scheduler = ComputeExternalQueueScheduler.Create(); + using var provider = WaveOpticsInteropProvider.TryCreate(devices, scheduler, out var device); + if (provider is null || device is null) + Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable."); + } + + static WaveOpticsEffectProcessor Processor(IGraphicsDevicesAndContext devices, WaveOpticsEffect effect, bool allowGpu) + => new(devices, effect, new ComputeGuardian(new ComputeGuardianOptions { Report = _ => { } }), null, allowGpu); + + static long MinimumAllocatedPerUpdate(bool allowGpu, Action configure) + { + using var devices = new GraphicsDevices(); + using var context = devices.CreateContext(); + if (allowGpu) + RequireInterop(context); + using var source = new SourceImage(context, Size, Size, Shape); + var effect = new WaveOpticsEffect(); + configure(effect); + using var processor = Processor(context, effect, allowGpu); + processor.SetInput(source.Bitmap); + var description = EffectDescriptions.At(7, Length); + for (var warmUp = 0; warmUp < 8; warmUp++) + processor.Update(description); + AllocationProbe.Settle(); + + return AllocationProbe.MinimumAllocatedBytes(() => processor.Update(description), Rounds); + } + + [Fact] + public void AnUnchangedFrameOnTheGpuRouteAllocatesNothing() + => Assert.Equal(0L, MinimumAllocatedPerUpdate(true, _ => { })); + + [Fact] + public void AnUnchangedFrameOnTheCpuRouteAllocatesNothing() + => Assert.Equal(0L, MinimumAllocatedPerUpdate(false, _ => { })); + + [Fact] + public void AFrameWithoutAmountOnTheGpuRouteAllocatesNothing() + => Assert.Equal(0L, MinimumAllocatedPerUpdate(true, effect => effect.Amount.Values[0].Value = 0d)); + + [Fact] + public void AFrameWithoutAmountOnTheCpuRouteAllocatesNothing() + => Assert.Equal(0L, MinimumAllocatedPerUpdate(false, effect => effect.Amount.Values[0].Value = 0d)); + + [Fact] + public void AnUnchangedFrameWithDepthOnTheGpuRouteAllocatesNothing() + => Assert.Equal(0L, MinimumAllocatedPerUpdate(true, effect => + { + effect.UseDepth = true; + effect.FocusDistance.Values[0].Value = 800d; + })); + + [Fact] + public void AnUnchangedChromaticFrameOnTheGpuRouteAllocatesNothing() + => Assert.Equal(0L, MinimumAllocatedPerUpdate(true, effect => effect.ColorMode = WaveOpticsColorMode.Broadband)); +}