From 4ec30767cefb8aabe4ee802c092ffacaf0579f9f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 2 Dec 2023 22:20:31 +0100 Subject: [PATCH] Add D2D1 shader to test custom constructors --- ...InvertWithUserTypeWithConstructorEffect.cs | 33 +++++++++++++++++++ tests/ComputeSharp.D2D1.Tests/EffectsTests.cs | 6 ++++ .../UserDefinedTypeConstructorTests.cs | 1 + 3 files changed, 40 insertions(+) create mode 100644 tests/ComputeSharp.D2D1.Tests/Effects/InvertWithUserTypeWithConstructorEffect.cs diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/InvertWithUserTypeWithConstructorEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/InvertWithUserTypeWithConstructorEffect.cs new file mode 100644 index 00000000..7ef7edfb --- /dev/null +++ b/tests/ComputeSharp.D2D1.Tests/Effects/InvertWithUserTypeWithConstructorEffect.cs @@ -0,0 +1,33 @@ +#pragma warning disable IDE0290 + +namespace ComputeSharp.D2D1.Tests.Effects; + +public struct ColorWrapper +{ + private float4 value; + + public ColorWrapper(float4 color) + { + this.value = color; + } + + public float4 Invert() + { + return new(Hlsl.Saturate(1.0f - this.value.RGB), 1); + } +} + +[D2DInputCount(1)] +[D2DInputSimple(0)] +[D2DShaderProfile(D2D1ShaderProfile.PixelShader50)] +[D2DGeneratedPixelShaderDescriptor] +public partial struct InvertWithUserTypeWithConstructorEffect : ID2D1PixelShader +{ + /// + public float4 Execute() + { + ColorWrapper wrapper = new(D2D.GetInput(0)); + + return wrapper.Invert(); + } +} \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests/EffectsTests.cs b/tests/ComputeSharp.D2D1.Tests/EffectsTests.cs index 6782a7f5..b454bb65 100644 --- a/tests/ComputeSharp.D2D1.Tests/EffectsTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/EffectsTests.cs @@ -33,6 +33,12 @@ public class EffectsTests D2D1TestRunner.RunAndCompareShader(new InvertWithThresholdEffect(1), null, "Landscape.png", "Landscape_Inverted.png"); } + [TestMethod] + public void InvertWithUserTypeWithConstructor() + { + D2D1TestRunner.RunAndCompareShader(new InvertWithUserTypeWithConstructorEffect(), null, "Landscape.png", "Landscape_Inverted.png"); + } + [TestMethod] public void Pixelate() { diff --git a/tests/ComputeSharp.Tests/UserDefinedTypeConstructorTests.cs b/tests/ComputeSharp.Tests/UserDefinedTypeConstructorTests.cs index c1303361..50912566 100644 --- a/tests/ComputeSharp.Tests/UserDefinedTypeConstructorTests.cs +++ b/tests/ComputeSharp.Tests/UserDefinedTypeConstructorTests.cs @@ -79,6 +79,7 @@ public partial class UserDefinedTypeConstructorTests } } + // See https://github.com/Sergio0694/ComputeSharp/issues/481 [CombinatorialTestMethod] [Device(Device.Warp)] public void ConstructorWithParameters(Device device)