From be17050d5e28264ff6d9f04de8bfe55803baeec2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 1 Oct 2023 12:27:10 +0200 Subject: [PATCH] Update unit tests for new effect XML behavior --- .../D2D1EffectRegistrationDataTests.cs | 198 ++++++++++-------- .../Effects/BokehBlurEffect.cs | 8 +- 2 files changed, 112 insertions(+), 94 deletions(-) diff --git a/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs b/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs index ef833251..176e03f1 100644 --- a/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs +++ b/tests/ComputeSharp.D2D1.Tests/D2D1EffectRegistrationDataTests.cs @@ -18,25 +18,9 @@ public partial class D2D1EffectRegistrationDataTests Assert.AreEqual(effectId, data.ClassId); Assert.AreEqual(2, data.NumberOfInputs); Assert.IsTrue(data.EffectFactory is not null); - Assert.AreEqual(18, data.PropertyBindings.Length); + Assert.AreEqual(2, data.PropertyBindings.Length); Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ConstantBuffer), data.PropertyBindings.Span[0].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager0), data.PropertyBindings.Span[1].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager1), data.PropertyBindings.Span[2].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager2), data.PropertyBindings.Span[3].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager3), data.PropertyBindings.Span[4].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager4), data.PropertyBindings.Span[5].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager5), data.PropertyBindings.Span[6].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager6), data.PropertyBindings.Span[7].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager7), data.PropertyBindings.Span[8].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager8), data.PropertyBindings.Span[9].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager9), data.PropertyBindings.Span[10].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager10), data.PropertyBindings.Span[11].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager11), data.PropertyBindings.Span[12].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager12), data.PropertyBindings.Span[13].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager13), data.PropertyBindings.Span[14].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager14), data.PropertyBindings.Span[15].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager15), data.PropertyBindings.Span[16].PropertyName); - Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.TransformMapper), data.PropertyBindings.Span[17].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.TransformMapper), data.PropertyBindings.Span[1].PropertyName); foreach (ref readonly D2D1PropertyBinding propertyBinding in data.PropertyBindings.Span) { @@ -58,54 +42,6 @@ public partial class D2D1EffectRegistrationDataTests - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -147,6 +83,74 @@ public partial class D2D1EffectRegistrationDataTests + + + + + """, data.PropertyXml); + } + + [D2DInputCount(2)] + [D2DEffectId("ABF58390-91D2-4F58-AA2B-22D0F6AC069C")] + [D2DEffectDisplayName("EffectWithCustomMetadata")] + [D2DEffectDescription("A test effect with some custom metadata")] + [D2DEffectCategory("Test effects")] + [D2DEffectAuthor("Bob Ross")] + [AutoConstructor] + private readonly partial struct TestRegistrationBlobWithCustomMetadataShader : ID2D1PixelShader + { + private readonly float a; + + public float4 Execute() + { + return this.a; + } + } + + [TestMethod] + public unsafe void EffectRegistrationData_WithResourceTextures_Validate() + { + ReadOnlyMemory blob = D2D1PixelShaderEffect.GetRegistrationBlob(out _); + D2D1EffectRegistrationData.V1 data = D2D1EffectRegistrationData.V1.Load(blob); + + Assert.IsTrue(data.EffectFactory is not null); + Assert.AreEqual(14, data.PropertyBindings.Length); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ConstantBuffer), data.PropertyBindings.Span[0].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.TransformMapper), data.PropertyBindings.Span[1].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager0), data.PropertyBindings.Span[2].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager1), data.PropertyBindings.Span[3].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager2), data.PropertyBindings.Span[4].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager3), data.PropertyBindings.Span[5].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager4), data.PropertyBindings.Span[6].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager5), data.PropertyBindings.Span[7].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager6), data.PropertyBindings.Span[8].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager7), data.PropertyBindings.Span[9].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager8), data.PropertyBindings.Span[10].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager9), data.PropertyBindings.Span[11].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager10), data.PropertyBindings.Span[12].PropertyName); + Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager11), data.PropertyBindings.Span[13].PropertyName); + + foreach (ref readonly D2D1PropertyBinding propertyBinding in data.PropertyBindings.Span) + { + Assert.IsTrue(propertyBinding.SetFunction is not null); + Assert.IsTrue(propertyBinding.GetFunction is not null); + } + + Assert.AreEqual(""" + + + + + + + + + + + + + + @@ -183,39 +187,53 @@ public partial class D2D1EffectRegistrationDataTests - - - - - - - - - - - - - - - """, data.PropertyXml); } - [D2DInputCount(2)] - [D2DEffectId("ABF58390-91D2-4F58-AA2B-22D0F6AC069C")] - [D2DEffectDisplayName("EffectWithCustomMetadata")] - [D2DEffectDescription("A test effect with some custom metadata")] - [D2DEffectCategory("Test effects")] - [D2DEffectAuthor("Bob Ross")] + [D2DInputCount(0)] [AutoConstructor] - private readonly partial struct TestRegistrationBlobWithCustomMetadataShader : ID2D1PixelShader + private readonly partial struct TestRegistrationBlobWithResourceTextures : ID2D1PixelShader { - private readonly float a; + [D2DResourceTextureIndex(0)] + public readonly D2D1ResourceTexture1D t0; + + [D2DResourceTextureIndex(1)] + public readonly D2D1ResourceTexture1D t1; + + [D2DResourceTextureIndex(2)] + public readonly D2D1ResourceTexture1D t2; + + [D2DResourceTextureIndex(3)] + public readonly D2D1ResourceTexture1D t3; + + [D2DResourceTextureIndex(4)] + public readonly D2D1ResourceTexture1D t4; + + [D2DResourceTextureIndex(5)] + public readonly D2D1ResourceTexture1D t5; + + [D2DResourceTextureIndex(6)] + public readonly D2D1ResourceTexture1D t6; + + [D2DResourceTextureIndex(7)] + public readonly D2D1ResourceTexture1D t7; + + [D2DResourceTextureIndex(8)] + public readonly D2D1ResourceTexture1D t8; + + [D2DResourceTextureIndex(9)] + public readonly D2D1ResourceTexture1D t9; + + [D2DResourceTextureIndex(10)] + public readonly D2D1ResourceTexture1D t10; + + [D2DResourceTextureIndex(11)] + public readonly D2D1ResourceTexture1D t11; public float4 Execute() { - return this.a; + return 0; } } } \ No newline at end of file diff --git a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs index ef09dc4d..7e7dfc0d 100644 --- a/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs +++ b/tests/ComputeSharp.D2D1.Tests/Effects/BokehBlurEffect.cs @@ -414,10 +414,10 @@ public sealed partial class BokehBlurEffect // Assign the resource textures for (int i = 0; i < numberOfComponents; i++) { - D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(verticalConvolutionEffectsForReals[i].Get(), kernels[i].Reals, 1); - D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(verticalConvolutionEffectsForImaginaries[i].Get(), kernels[i].Imaginaries, 1); - D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(horizontalConvolutionEffects[i].Get(), kernels[i].Reals, 2); - D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(horizontalConvolutionEffects[i].Get(), kernels[i].Imaginaries, 3); + D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(verticalConvolutionEffectsForReals[i].Get(), kernels[i].Reals, 0); + D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(verticalConvolutionEffectsForImaginaries[i].Get(), kernels[i].Imaginaries, 0); + D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(horizontalConvolutionEffects[i].Get(), kernels[i].Reals, 0); + D2D1PixelShaderEffect.SetResourceTextureManagerForD2D1Effect(horizontalConvolutionEffects[i].Get(), kernels[i].Imaginaries, 1); } // Set the constant buffers