using System; using ComputeSharp.D2D1.Interop; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace ComputeSharp.D2D1.Tests; [TestClass] public partial class D2D1EffectRegistrationDataTests { [TestMethod] public unsafe void EffectRegistrationData_Validate() { ReadOnlyMemory blob = D2D1PixelShaderEffect.GetRegistrationBlob(out Guid effectId); D2D1EffectRegistrationData.V1 data = D2D1EffectRegistrationData.V1.Load(blob); Assert.AreEqual(Guid.Parse("8AA3BDF3-5EC8-34D9-CFBC-97A2B4068FFD"), effectId); Assert.AreEqual(effectId, data.ClassId); Assert.AreEqual(2, data.NumberOfInputs); Assert.IsTrue(data.EffectFactory is not null); Assert.AreEqual(2, data.PropertyBindings.Length); Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.ConstantBuffer), data.PropertyBindings.Span[0].PropertyName); Assert.AreEqual(nameof(D2D1PixelShaderEffectProperty.TransformMapper), data.PropertyBindings.Span[1].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(""" """, data.PropertyXml); } [D2DInputCount(2)] [D2DRequiresScenePosition] [D2DGeneratedPixelShaderDescriptor] [AutoConstructor] internal readonly partial struct TestRegistrationBlobShader : ID2D1PixelShader { private readonly float a; public float4 Execute() { return this.a; } } [TestMethod] public unsafe void EffectRegistrationData_WithCustomMetadata_Validate() { ReadOnlyMemory blob = D2D1PixelShaderEffect.GetRegistrationBlob(out Guid effectId); D2D1EffectRegistrationData.V1 data = D2D1EffectRegistrationData.V1.Load(blob); Assert.AreEqual(Guid.Parse("ABF58390-91D2-4F58-AA2B-22D0F6AC069C"), effectId); Assert.AreEqual(""" """, 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")] [D2DGeneratedPixelShaderDescriptor] [AutoConstructor] internal 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(""" """, data.PropertyXml); } [D2DInputCount(0)] [D2DGeneratedPixelShaderDescriptor] [AutoConstructor] internal readonly partial struct TestRegistrationBlobWithResourceTextures : ID2D1PixelShader { [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 0; } } }