Update unit tests for new API shapes

このコミットが含まれているのは:
Sergio Pedri committed 2022-11-29 22:34:06 +01:00
1 親 6658a21477
コミット 8fa29edf19
4ファイル変更
+43 -61

検索条件に一致するファイルはありません

+3 -35
ファイルの表示
@@ -1,6 +1,5 @@
using System;
using System.ComponentModel;
using System.Drawing;
using ComputeSharp.D2D1.Interop;
using ComputeSharp.D2D1.Tests.Effects;
using ComputeSharp.D2D1.Tests.Helpers;
@@ -23,42 +22,11 @@ public partial class D2D1PixelShaderEffectTests
D2D1PixelShaderEffect.RegisterForD2D1Factory1<InvertEffect>(null, out _);
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public unsafe void RegisterForD2D1Factory1_WithTransformMapper_NullD2D1Factory1()
{
D2D1PixelShaderEffect.RegisterForD2D1Factory1<DummyTransformMapper.Shader, DummyTransformMapper>(null, out _);
}
public sealed partial class DummyTransformMapper : ID2D1TransformMapper<DummyTransformMapper.Shader>
{
public void MapInputsToOutput(in Shader shader, ReadOnlySpan<Rectangle> inputs, ReadOnlySpan<Rectangle> opaqueInputs, out Rectangle output, out Rectangle opaqueOutput)
{
output = default;
opaqueOutput = default;
}
public void MapInvalidOutput(int inputIndex, Rectangle invalidInput, out Rectangle invalidOutput)
{
invalidOutput = default;
}
public void MapOutputToInputs(in Rectangle output, Span<Rectangle> inputs)
{
}
[D2DInputCount(0)]
public partial struct Shader : ID2D1PixelShader
{
public float4 Execute() => default;
}
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException), AllowDerivedTypes = false)]
public unsafe void RegisterForD2D1Factory1_WithTransformMapperFactory_NullD2D1Factory1()
{
D2D1PixelShaderEffect.RegisterForD2D1Factory1<PixelateEffect>(null, null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<PixelateEffect>(null, out _);
}
[TestMethod]
@@ -125,7 +93,7 @@ public partial class D2D1PixelShaderEffectTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<NullConstantBufferShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<NullConstantBufferShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -156,7 +124,7 @@ public partial class D2D1PixelShaderEffectTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<ConstantBufferSizeTestShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<ConstantBufferSizeTestShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
+11 -11
ファイルの表示
@@ -108,7 +108,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<DummyShaderWithResourceTexture>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<DummyShaderWithResourceTexture>(d2D1Factory2.Get(), out _);
using ComPtr<IUnknown> resourceTextureManager = default;
@@ -152,7 +152,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<DummyShaderWithResourceTexture>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<DummyShaderWithResourceTexture>(d2D1Factory2.Get(), out _);
D2D1ResourceTextureManager resourceTextureManager = new(
extents: stackalloc uint[] { 128, 128 },
@@ -192,7 +192,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -251,7 +251,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -315,7 +315,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -373,7 +373,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom2DResourceTextureShader>(d2D1Factory2.Get(), out _);
string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
string wallpaper0Path = Path.Combine(assemblyPath, "Assets", "Wallpaper0.png");
@@ -480,7 +480,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom3DResourceTextureShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<IndexFrom3DResourceTextureShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -567,7 +567,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture1DShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture1DShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -655,7 +655,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture2DShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture2DShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -758,7 +758,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture3DShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<CopyFromResourceTexture3DShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -854,7 +854,7 @@ public partial class D2D1ResourceTextureManagerTests
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1<NullResourceTextureShader>(d2D1Factory2.Get(), null, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<NullResourceTextureShader>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
+10 -6
ファイルの表示
@@ -317,8 +317,8 @@ public sealed partial class BokehBlurEffect
d2D1DeviceContext.Get()->SetRenderingControls(&d2D1RenderingControls);
// Register all necessary effects
D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), VerticalConvolution.Transform, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), HorizontalConvolutionAndAccumulatePartials.Transform, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<VerticalConvolution.Shader>(d2D1Factory2.Get(), out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<HorizontalConvolutionAndAccumulatePartials.Shader>(d2D1Factory2.Get(), out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<GammaHighlight>(d2D1Factory2.Get(), out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<InverseGammaHighlight>(d2D1Factory2.Get(), out _);
@@ -344,6 +344,10 @@ public sealed partial class BokehBlurEffect
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<VerticalConvolution.Shader>(d2D1DeviceContext.Get(), (void**)verticalConvolutionEffectsForReals[i].GetAddressOf());
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<VerticalConvolution.Shader>(d2D1DeviceContext.Get(), (void**)verticalConvolutionEffectsForImaginaries[i].GetAddressOf());
D2D1PixelShaderEffect.CreateFromD2D1DeviceContext<HorizontalConvolutionAndAccumulatePartials.Shader>(d2D1DeviceContext.Get(), (void**)horizontalConvolutionEffects[i].GetAddressOf());
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(verticalConvolutionEffectsForReals[i].Get(), VerticalConvolution.Transform);
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(verticalConvolutionEffectsForImaginaries[i].Get(), VerticalConvolution.Transform);
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(horizontalConvolutionEffects[i].Get(), HorizontalConvolutionAndAccumulatePartials.Transform);
}
// Create the border effect to clamp the input image
@@ -494,9 +498,9 @@ public sealed partial class BokehBlurEffect
private sealed partial class VerticalConvolution
{
/// <summary>
/// The <see cref="ID2D1TransformMapperFactory{T}"/> for the shader.
/// The <see cref="D2D1TransformMapper{T}"/> for the shader.
/// </summary>
public static ID2D1TransformMapperFactory<Shader> Transform { get; } = D2D1TransformMapperFactory<Shader>.Inflate(static (in Shader shader) => (0, shader.kernelLength, 0, shader.kernelLength));
public static D2D1TransformMapper<Shader> Transform { get; } = D2D1TransformMapperFactory<Shader>.Inflate(static (in Shader shader) => (0, shader.kernelLength, 0, shader.kernelLength));
/// <summary>
/// Kernel for the vertical convolution pass for real or imaginary components.
@@ -541,9 +545,9 @@ public sealed partial class BokehBlurEffect
private sealed partial class HorizontalConvolutionAndAccumulatePartials
{
/// <summary>
/// The <see cref="ID2D1TransformMapperFactory{T}"/> for the shader.
/// The <see cref="D2D1TransformMapper{T}"/> for the shader.
/// </summary>
public static ID2D1TransformMapperFactory<Shader> Transform { get; } = D2D1TransformMapperFactory<Shader>.Inflate(static (in Shader shader) => (shader.kernelLength, 0, shader.kernelLength, 0));
public static D2D1TransformMapper<Shader> Transform { get; } = D2D1TransformMapperFactory<Shader>.Inflate(static (in Shader shader) => (shader.kernelLength, 0, shader.kernelLength, 0));
/// <summary>
/// Kernel for the horizontal convolution pass.
+19 -9
ファイルの表示
@@ -22,7 +22,7 @@ internal static class D2D1TestRunner
/// Executes a pixel shader and compares the expected results.
/// </summary>
/// <typeparam name="T">The type of pixel shader to run.</typeparam>
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
/// <param name="transformMapper">A custom <see cref="D2D1TransformMapper{T}"/> instance for the effect.</param>
/// <param name="originalFileName">The name of the source image.</param>
/// <param name="expectedFileName">The name of the expected result image.</param>
/// <param name="destinationFileName">The name of the destination image to save results to.</param>
@@ -30,7 +30,7 @@ internal static class D2D1TestRunner
/// <param name="threshold">The allowed difference threshold for the normalized delta.</param>
public static void RunAndCompareShader<T>(
in T shader,
ID2D1TransformMapperFactory<T>? transformMapperFactory,
D2D1TransformMapper<T>? transformMapper,
string originalFileName,
string expectedFileName,
[CallerMemberName] string destinationFileName = "",
@@ -49,7 +49,7 @@ internal static class D2D1TestRunner
// Run the shader
ExecutePixelShaderAndSaveToFile(
in shader,
transformMapperFactory,
transformMapper,
originalPath,
destinationPath);
@@ -104,12 +104,12 @@ internal static class D2D1TestRunner
/// </summary>
/// <typeparam name="T">The shader type to execute.</typeparam>
/// <param name="shader">The shader to run.</param>
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
/// <param name="transformMapper">A custom <see cref="D2D1TransformMapper{T}"/> instance for the effect.</param>
/// <param name="sourcePath">The source path for the image to run the shader on.</param>
/// <param name="destinationPath">The destination path for the result.</param>
private static unsafe void ExecutePixelShaderAndSaveToFile<T>(
in T shader,
ID2D1TransformMapperFactory<T>? transformMapperFactory,
D2D1TransformMapper<T>? transformMapper,
string sourcePath,
string destinationPath)
where T : unmanaged, ID2D1PixelShader
@@ -118,7 +118,7 @@ internal static class D2D1TestRunner
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), transformMapperFactory, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<T>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -126,6 +126,11 @@ internal static class D2D1TestRunner
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
if (transformMapper is not null)
{
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(d2D1Effect.Get(), transformMapper);
}
ReadOnlyMemory<byte> pixels = ImageHelper.LoadBitmapFromFile(sourcePath, out uint width, out uint height);
using ComPtr<ID2D1Bitmap> d2D1BitmapSource = D2D1Helper.CreateD2D1BitmapAndSetAsSource(d2D1DeviceContext.Get(), pixels, width, height, d2D1Effect.Get());
@@ -146,12 +151,12 @@ internal static class D2D1TestRunner
/// <param name="shader">The shader to run.</param>
/// <param name="width">The resulting width.</param>
/// <param name="height">The resulting height.</param>
/// <param name="transformMapperFactory">A custom <see cref="ID2D1TransformMapper{T}"/> factory for the effect.</param>
/// <param name="transformMapper">A custom <see cref="D2D1TransformMapper{T}"/> instance for the effect.</param>
/// <param name="destinationPath">The destination path for the result.</param>
/// <param name="resourceTextures">The additional resource textures to use to run the shader.</param>
private static unsafe void ExecutePixelShaderAndSaveToFile<T>(
in T shader,
ID2D1TransformMapperFactory<T>? transformMapperFactory,
D2D1TransformMapper<T>? transformMapper,
int width,
int height,
string destinationPath,
@@ -162,7 +167,7 @@ internal static class D2D1TestRunner
using ComPtr<ID2D1Device> d2D1Device = D2D1Helper.CreateD2D1Device(d2D1Factory2.Get());
using ComPtr<ID2D1DeviceContext> d2D1DeviceContext = D2D1Helper.CreateD2D1DeviceContext(d2D1Device.Get());
D2D1PixelShaderEffect.RegisterForD2D1Factory1(d2D1Factory2.Get(), transformMapperFactory, out _);
D2D1PixelShaderEffect.RegisterForD2D1Factory1<T>(d2D1Factory2.Get(), out _);
using ComPtr<ID2D1Effect> d2D1Effect = default;
@@ -170,6 +175,11 @@ internal static class D2D1TestRunner
D2D1PixelShaderEffect.SetConstantBufferForD2D1Effect(in shader, d2D1Effect.Get());
if (transformMapper is not null)
{
D2D1PixelShaderEffect.SetTransformMapperForD2D1Effect(d2D1Effect.Get(), transformMapper);
}
foreach ((int index, D2D1ResourceTextureManager resourceTextureManager) in resourceTextures)
{
D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(d2D1Effect.Get(), resourceTextureManager, index);