メモリの共有と参照の釣り合いを試験で固める
このコミットが含まれているのは:
6ファイル変更
+114
-5
検索条件に一致するファイルはありません
@@ -59,6 +59,18 @@ public sealed class ChromaticGpuConvolverTests
|
||||
static ChromaticConvolutionScene Scene(int size, int radius, int width, int height, int margin, int seed, LightOptions light = default)
|
||||
=> ChromaticConvolutionScene.Create(ConvolutionScene.RandomSource(width, height, seed, 0.45), width, height, margin, radius, size, light);
|
||||
|
||||
[Fact]
|
||||
public void AWarmChromaticUploadAllocatesNoManagedMemory()
|
||||
{
|
||||
var device = HardwareOrDefault();
|
||||
var scene = Scene(128, 23, 140, 90, 24, 5);
|
||||
using var convolver = new GpuTileConvolver(device);
|
||||
convolver.Upload(scene.Spectrum);
|
||||
convolver.Upload(scene.Spectrum);
|
||||
|
||||
Assert.Equal(0L, AllocationProbe.MinimumAllocatedBytes(() => convolver.Upload(scene.Spectrum), 16));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(64, 5, 150, 97, 11)]
|
||||
[InlineData(128, 23, 140, 90, 24)]
|
||||
|
||||
@@ -276,6 +276,8 @@ public sealed class CpuTileConvolverTests
|
||||
|
||||
Convolve(first);
|
||||
var bytes = first.WorkingBytes;
|
||||
Assert.Equal(Environment.ProcessorCount, first.Threads);
|
||||
Assert.True(second.WorkingBytes >= bytes);
|
||||
Convolve(second);
|
||||
|
||||
var active = CpuTileConvolver.ActiveThreads(first.Threads, 512);
|
||||
|
||||
@@ -144,4 +144,19 @@ public sealed class FraunhoferKernelSamplerTests
|
||||
|
||||
Assert.Equal(0, AllocationProbe.MinimumAllocatedBytes(SampleEveryDefocusStep, 16));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ASamplerHoldsOnlyTheRowsTheApertureReaches()
|
||||
{
|
||||
const int GridSize = 512;
|
||||
var specification = PsfSpecification.Of(Descriptor(gridSize: GridSize, diameter: 16));
|
||||
Assert.True(new FraunhoferKernelSampler().TrySample(in specification, kernel.AsSpan(0, 31 * 31)));
|
||||
var fresh = new FraunhoferKernelSampler();
|
||||
|
||||
var before = GC.GetAllocatedBytesForCurrentThread();
|
||||
Assert.True(fresh.TrySample(in specification, kernel.AsSpan(0, 31 * 31)));
|
||||
var allocated = GC.GetAllocatedBytesForCurrentThread() - before;
|
||||
|
||||
Assert.True(allocated < (long)GridSize * GridSize * sizeof(double) * 2, allocated.ToString());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using SpectralConvolution;
|
||||
using WaveOptics.Effects;
|
||||
using WaveOptics.Rendering;
|
||||
|
||||
@@ -34,6 +36,25 @@ public sealed class WaveOpticsCpuPipelineTests
|
||||
return pipeline.RenderVisible(rect, in parameters).ToArray();
|
||||
}
|
||||
|
||||
static CpuTileConvolver Convolver(WaveOpticsCpuPipeline pipeline)
|
||||
=> (CpuTileConvolver)typeof(WaveOpticsCpuPipeline).GetField("_convolver", BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(pipeline)!;
|
||||
|
||||
[Fact]
|
||||
public void PipelinesShareTheThreadsAndTheWorkingArea()
|
||||
{
|
||||
using var first = new WaveOpticsCpuPipeline();
|
||||
using var second = new WaveOpticsCpuPipeline();
|
||||
var source = Bytes(Square(150, 120, 30, 20, 70));
|
||||
var parameters = Parameters(gain: 1.5f, defocus: 1f);
|
||||
|
||||
RenderFrame(first, source, 150, 120, 16, in parameters, out _);
|
||||
var bytes = Convolver(first).WorkingBytes;
|
||||
|
||||
Assert.True(bytes > 0);
|
||||
Assert.Equal(Environment.ProcessorCount, Convolver(second).Threads);
|
||||
Assert.True(Convolver(second).WorkingBytes >= bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheCpuAndTheGpuDrawTheSameImageWithinTwoLevels()
|
||||
{
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace WaveOptics.Tests;
|
||||
[Collection("Direct2D")]
|
||||
public sealed class WaveOpticsEffectProcessorAllocationTests
|
||||
{
|
||||
const int Size = 128;
|
||||
const int Length = 60;
|
||||
internal const int Size = 128;
|
||||
internal 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;
|
||||
internal 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)
|
||||
internal static void RequireInterop(IGraphicsDevicesAndContext devices)
|
||||
{
|
||||
using var scheduler = ComputeExternalQueueScheduler.Create();
|
||||
using var provider = WaveOpticsInteropProvider.TryCreate(devices, scheduler, out var device);
|
||||
@@ -24,7 +24,7 @@ public sealed class WaveOpticsEffectProcessorAllocationTests
|
||||
Assert.Skip("Direct3D 11 and Direct3D 12 sharing is unavailable.");
|
||||
}
|
||||
|
||||
static WaveOpticsEffectProcessor Processor(IGraphicsDevicesAndContext devices, WaveOpticsEffect effect, bool allowGpu)
|
||||
internal 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<WaveOpticsEffect> configure)
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Vortice.Direct2D1;
|
||||
using WaveOptics.Effects;
|
||||
using WaveOptics.Rendering;
|
||||
using YukkuriMovieMaker.Commons;
|
||||
using YukkuriMovieMaker.Player.Video;
|
||||
|
||||
namespace WaveOptics.Tests;
|
||||
|
||||
[Collection("Direct2D")]
|
||||
public sealed class WaveOpticsEffectProcessorBitmapTests
|
||||
{
|
||||
static object Field(WaveOpticsEffectProcessor processor, string name)
|
||||
=> typeof(WaveOpticsEffectProcessor).GetField(name, BindingFlags.Instance | BindingFlags.NonPublic)!.GetValue(processor)!;
|
||||
|
||||
static int SourceBitmapReferences(WaveOpticsEffectProcessor processor)
|
||||
{
|
||||
var resources = (WaveOpticsResourceSet)Field(processor, "_resourceSet");
|
||||
using var borrow = resources.BeginSourceExternalOperation();
|
||||
return Marshal.Release(borrow.DangerousGetView().AddRefBitmap());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EveryFrameLeavesTheReferencesOfTheSourceBitmapBalanced()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
WaveOpticsEffectProcessorAllocationTests.RequireInterop(context);
|
||||
using var source = new SourceImage(context, WaveOpticsEffectProcessorAllocationTests.Size, WaveOpticsEffectProcessorAllocationTests.Size, WaveOpticsEffectProcessorAllocationTests.Shape);
|
||||
using var processor = WaveOpticsEffectProcessorAllocationTests.Processor(context, new WaveOpticsEffect(), true);
|
||||
processor.SetInput(source.Bitmap);
|
||||
var description = EffectDescriptions.At(7, WaveOpticsEffectProcessorAllocationTests.Length);
|
||||
processor.Update(description);
|
||||
var baseline = SourceBitmapReferences(processor);
|
||||
|
||||
for (var frame = 0; frame < 10; frame++)
|
||||
processor.Update(description);
|
||||
|
||||
Assert.Equal(baseline, SourceBitmapReferences(processor));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheSourceBitmapWrapperHoldsNoPointerBetweenFrames()
|
||||
{
|
||||
using var devices = new GraphicsDevices();
|
||||
using var context = devices.CreateContext();
|
||||
WaveOpticsEffectProcessorAllocationTests.RequireInterop(context);
|
||||
using var source = new SourceImage(context, WaveOpticsEffectProcessorAllocationTests.Size, WaveOpticsEffectProcessorAllocationTests.Size, WaveOpticsEffectProcessorAllocationTests.Shape);
|
||||
using var processor = WaveOpticsEffectProcessorAllocationTests.Processor(context, new WaveOpticsEffect(), true);
|
||||
processor.SetInput(source.Bitmap);
|
||||
var description = EffectDescriptions.At(7, WaveOpticsEffectProcessorAllocationTests.Length);
|
||||
|
||||
processor.Update(description);
|
||||
processor.Update(description);
|
||||
|
||||
Assert.Equal(IntPtr.Zero, ((ID2D1Bitmap1)Field(processor, "_sourceBitmap")).NativePointer);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする