From 0ff34c6275bb93cc2fa3441cbcbd226c679c869b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 1 Oct 2023 12:27:00 +0200 Subject: [PATCH] Remove invalid properties from effect XML text --- .../Shaders/Interop/D2D1PixelShaderEffect.cs | 300 ++++++++++-------- .../Interop/D2D1PixelShaderEffectProperty.cs | 207 ++++++------ ...ixelShaderEffect.ID2D1EffectImplMethods.cs | 6 +- .../Effects/PixelShaderEffect.Properties.cs | 41 +-- .../Interop/Effects/PixelShaderEffect.cs | 7 +- .../Interop/Helpers/D2D1EffectXmlFactory.cs | 66 +--- 6 files changed, 313 insertions(+), 314 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs index a248c778..46941807 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs @@ -107,6 +107,7 @@ public static unsafe class D2D1PixelShaderEffect fixed (char* pXml = effectXml.GetBuffer()) fixed (char* pBufferPropertyName = nameof(D2D1PixelShaderEffectProperty.ConstantBuffer)) + fixed (char* pTransformMapperPropertyName = nameof(D2D1PixelShaderEffectProperty.TransformMapper)) fixed (char* pResourceTextureManager0PropertyName = nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager0)) fixed (char* pResourceTextureManager1PropertyName = nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager1)) fixed (char* pResourceTextureManager2PropertyName = nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager2)) @@ -123,70 +124,69 @@ public static unsafe class D2D1PixelShaderEffect fixed (char* pResourceTextureManager13PropertyName = nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager13)) fixed (char* pResourceTextureManager14PropertyName = nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager14)) fixed (char* pResourceTextureManager15PropertyName = nameof(D2D1PixelShaderEffectProperty.ResourceTextureManager15)) - fixed (char* pTransformMapperPropertyName = nameof(D2D1PixelShaderEffectProperty.TransformMapper)) { // Prepare the effect binding functions - D2D1_PROPERTY_BINDING* d2D1PropertyBinding = stackalloc D2D1_PROPERTY_BINDING[(int)D2D1PixelShaderEffectProperty.NumberOfProperties]; + D2D1_PROPERTY_BINDING* d2D1PropertyBinding = stackalloc D2D1_PROPERTY_BINDING[D2D1PixelShaderEffectProperty.MaximumNumberOfAvailableProperties]; // Property names - d2D1PropertyBinding[0].propertyName = (ushort*)pBufferPropertyName; - d2D1PropertyBinding[1].propertyName = (ushort*)pResourceTextureManager0PropertyName; - d2D1PropertyBinding[2].propertyName = (ushort*)pResourceTextureManager1PropertyName; - d2D1PropertyBinding[3].propertyName = (ushort*)pResourceTextureManager2PropertyName; - d2D1PropertyBinding[4].propertyName = (ushort*)pResourceTextureManager3PropertyName; - d2D1PropertyBinding[5].propertyName = (ushort*)pResourceTextureManager4PropertyName; - d2D1PropertyBinding[6].propertyName = (ushort*)pResourceTextureManager5PropertyName; - d2D1PropertyBinding[7].propertyName = (ushort*)pResourceTextureManager6PropertyName; - d2D1PropertyBinding[8].propertyName = (ushort*)pResourceTextureManager7PropertyName; - d2D1PropertyBinding[9].propertyName = (ushort*)pResourceTextureManager8PropertyName; - d2D1PropertyBinding[10].propertyName = (ushort*)pResourceTextureManager9PropertyName; - d2D1PropertyBinding[11].propertyName = (ushort*)pResourceTextureManager10PropertyName; - d2D1PropertyBinding[12].propertyName = (ushort*)pResourceTextureManager11PropertyName; - d2D1PropertyBinding[13].propertyName = (ushort*)pResourceTextureManager12PropertyName; - d2D1PropertyBinding[14].propertyName = (ushort*)pResourceTextureManager13PropertyName; - d2D1PropertyBinding[15].propertyName = (ushort*)pResourceTextureManager14PropertyName; - d2D1PropertyBinding[16].propertyName = (ushort*)pResourceTextureManager15PropertyName; - d2D1PropertyBinding[17].propertyName = (ushort*)pTransformMapperPropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ConstantBuffer].propertyName = (ushort*)pBufferPropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.TransformMapper].propertyName = (ushort*)pTransformMapperPropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager0].propertyName = (ushort*)pResourceTextureManager0PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager1].propertyName = (ushort*)pResourceTextureManager1PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager2].propertyName = (ushort*)pResourceTextureManager2PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager3].propertyName = (ushort*)pResourceTextureManager3PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager4].propertyName = (ushort*)pResourceTextureManager4PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager5].propertyName = (ushort*)pResourceTextureManager5PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager6].propertyName = (ushort*)pResourceTextureManager6PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager7].propertyName = (ushort*)pResourceTextureManager7PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager8].propertyName = (ushort*)pResourceTextureManager8PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager9].propertyName = (ushort*)pResourceTextureManager9PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager10].propertyName = (ushort*)pResourceTextureManager10PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager11].propertyName = (ushort*)pResourceTextureManager11PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager12].propertyName = (ushort*)pResourceTextureManager12PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager13].propertyName = (ushort*)pResourceTextureManager13PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager14].propertyName = (ushort*)pResourceTextureManager14PropertyName; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager15].propertyName = (ushort*)pResourceTextureManager15PropertyName; // Property getters - d2D1PropertyBinding[0].getFunction = PixelShaderEffect.GetConstantBuffer; - d2D1PropertyBinding[1].getFunction = PixelShaderEffect.GetResourceTextureManager0; - d2D1PropertyBinding[2].getFunction = PixelShaderEffect.GetResourceTextureManager1; - d2D1PropertyBinding[3].getFunction = PixelShaderEffect.GetResourceTextureManager2; - d2D1PropertyBinding[4].getFunction = PixelShaderEffect.GetResourceTextureManager3; - d2D1PropertyBinding[5].getFunction = PixelShaderEffect.GetResourceTextureManager4; - d2D1PropertyBinding[6].getFunction = PixelShaderEffect.GetResourceTextureManager5; - d2D1PropertyBinding[7].getFunction = PixelShaderEffect.GetResourceTextureManager6; - d2D1PropertyBinding[8].getFunction = PixelShaderEffect.GetResourceTextureManager7; - d2D1PropertyBinding[9].getFunction = PixelShaderEffect.GetResourceTextureManager8; - d2D1PropertyBinding[10].getFunction = PixelShaderEffect.GetResourceTextureManager9; - d2D1PropertyBinding[11].getFunction = PixelShaderEffect.GetResourceTextureManager10; - d2D1PropertyBinding[12].getFunction = PixelShaderEffect.GetResourceTextureManager11; - d2D1PropertyBinding[13].getFunction = PixelShaderEffect.GetResourceTextureManager12; - d2D1PropertyBinding[14].getFunction = PixelShaderEffect.GetResourceTextureManager13; - d2D1PropertyBinding[15].getFunction = PixelShaderEffect.GetResourceTextureManager14; - d2D1PropertyBinding[16].getFunction = PixelShaderEffect.GetResourceTextureManager15; - d2D1PropertyBinding[17].getFunction = PixelShaderEffect.GetTransformMapper; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ConstantBuffer].getFunction = PixelShaderEffect.GetConstantBuffer; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.TransformMapper].getFunction = PixelShaderEffect.GetTransformMapper; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager0].getFunction = PixelShaderEffect.GetResourceTextureManager0; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager1].getFunction = PixelShaderEffect.GetResourceTextureManager1; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager2].getFunction = PixelShaderEffect.GetResourceTextureManager2; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager3].getFunction = PixelShaderEffect.GetResourceTextureManager3; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager4].getFunction = PixelShaderEffect.GetResourceTextureManager4; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager5].getFunction = PixelShaderEffect.GetResourceTextureManager5; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager6].getFunction = PixelShaderEffect.GetResourceTextureManager6; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager7].getFunction = PixelShaderEffect.GetResourceTextureManager7; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager8].getFunction = PixelShaderEffect.GetResourceTextureManager8; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager9].getFunction = PixelShaderEffect.GetResourceTextureManager9; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager10].getFunction = PixelShaderEffect.GetResourceTextureManager10; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager11].getFunction = PixelShaderEffect.GetResourceTextureManager11; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager12].getFunction = PixelShaderEffect.GetResourceTextureManager12; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager13].getFunction = PixelShaderEffect.GetResourceTextureManager13; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager14].getFunction = PixelShaderEffect.GetResourceTextureManager14; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager15].getFunction = PixelShaderEffect.GetResourceTextureManager15; // Property setters - d2D1PropertyBinding[0].setFunction = PixelShaderEffect.SetConstantBuffer; - d2D1PropertyBinding[1].setFunction = PixelShaderEffect.SetResourceTextureManager0; - d2D1PropertyBinding[2].setFunction = PixelShaderEffect.SetResourceTextureManager1; - d2D1PropertyBinding[3].setFunction = PixelShaderEffect.SetResourceTextureManager2; - d2D1PropertyBinding[4].setFunction = PixelShaderEffect.SetResourceTextureManager3; - d2D1PropertyBinding[5].setFunction = PixelShaderEffect.SetResourceTextureManager4; - d2D1PropertyBinding[6].setFunction = PixelShaderEffect.SetResourceTextureManager5; - d2D1PropertyBinding[7].setFunction = PixelShaderEffect.SetResourceTextureManager6; - d2D1PropertyBinding[8].setFunction = PixelShaderEffect.SetResourceTextureManager7; - d2D1PropertyBinding[9].setFunction = PixelShaderEffect.SetResourceTextureManager8; - d2D1PropertyBinding[10].setFunction = PixelShaderEffect.SetResourceTextureManager9; - d2D1PropertyBinding[11].setFunction = PixelShaderEffect.SetResourceTextureManager10; - d2D1PropertyBinding[12].setFunction = PixelShaderEffect.SetResourceTextureManager11; - d2D1PropertyBinding[13].setFunction = PixelShaderEffect.SetResourceTextureManager12; - d2D1PropertyBinding[14].setFunction = PixelShaderEffect.SetResourceTextureManager13; - d2D1PropertyBinding[15].setFunction = PixelShaderEffect.SetResourceTextureManager14; - d2D1PropertyBinding[16].setFunction = PixelShaderEffect.SetResourceTextureManager15; - d2D1PropertyBinding[17].setFunction = PixelShaderEffect.SetTransformMapper; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ConstantBuffer].setFunction = PixelShaderEffect.SetConstantBuffer; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.TransformMapper].setFunction = PixelShaderEffect.SetTransformMapper; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager0].setFunction = PixelShaderEffect.SetResourceTextureManager0; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager1].setFunction = PixelShaderEffect.SetResourceTextureManager1; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager2].setFunction = PixelShaderEffect.SetResourceTextureManager2; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager3].setFunction = PixelShaderEffect.SetResourceTextureManager3; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager4].setFunction = PixelShaderEffect.SetResourceTextureManager4; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager5].setFunction = PixelShaderEffect.SetResourceTextureManager5; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager6].setFunction = PixelShaderEffect.SetResourceTextureManager6; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager7].setFunction = PixelShaderEffect.SetResourceTextureManager7; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager8].setFunction = PixelShaderEffect.SetResourceTextureManager8; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager9].setFunction = PixelShaderEffect.SetResourceTextureManager9; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager10].setFunction = PixelShaderEffect.SetResourceTextureManager10; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager11].setFunction = PixelShaderEffect.SetResourceTextureManager11; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager12].setFunction = PixelShaderEffect.SetResourceTextureManager12; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager13].setFunction = PixelShaderEffect.SetResourceTextureManager13; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager14].setFunction = PixelShaderEffect.SetResourceTextureManager14; + d2D1PropertyBinding[D2D1PixelShaderEffectProperty.ResourceTextureManager15].setFunction = PixelShaderEffect.SetResourceTextureManager15; fixed (Guid* pGuid = &PixelShaderEffect.For.Instance.Id) { @@ -195,7 +195,7 @@ public static unsafe class D2D1PixelShaderEffect classId: pGuid, propertyXml: (ushort*)pXml, bindings: d2D1PropertyBinding, - bindingsCount: D2D1PixelShaderEffectProperty.NumberOfProperties, + bindingsCount: (uint)(D2D1PixelShaderEffectProperty.NumberOfAlwaysAvailableProperties + D2D1PixelShader.GetResourceTextureCount()), effectFactory: PixelShaderEffect.For.Instance.Factory).Assert(); } @@ -273,80 +273,120 @@ public static unsafe class D2D1PixelShaderEffect } // Bindings - writer.Write(D2D1PixelShaderEffectProperty.NumberOfProperties); + writer.Write(D2D1PixelShaderEffectProperty.NumberOfAlwaysAvailableProperties + D2D1PixelShader.GetResourceTextureCount()); writer.Write("ConstantBuffer"u8); writer.Write((byte)'\0'); writer.Write((nint)PixelShaderEffect.GetConstantBuffer); writer.Write((nint)PixelShaderEffect.SetConstantBuffer); - writer.Write("ResourceTextureManager0"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager0); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager0); - writer.Write("ResourceTextureManager1"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager1); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager1); - writer.Write("ResourceTextureManager2"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager2); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager2); - writer.Write("ResourceTextureManager3"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager3); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager3); - writer.Write("ResourceTextureManager4"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager4); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager4); - writer.Write("ResourceTextureManager5"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager5); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager5); - writer.Write("ResourceTextureManager6"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager6); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager6); - writer.Write("ResourceTextureManager7"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager7); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager7); - writer.Write("ResourceTextureManager8"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager8); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager8); - writer.Write("ResourceTextureManager9"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager9); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager9); - writer.Write("ResourceTextureManager10"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager10); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager10); - writer.Write("ResourceTextureManager11"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager11); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager11); - writer.Write("ResourceTextureManager12"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager12); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager12); - writer.Write("ResourceTextureManager13"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager13); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager13); - writer.Write("ResourceTextureManager14"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager14); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager14); - writer.Write("ResourceTextureManager15"u8); - writer.Write((byte)'\0'); - writer.Write((nint)PixelShaderEffect.GetResourceTextureManager15); - writer.Write((nint)PixelShaderEffect.SetResourceTextureManager15); writer.Write("TransformMapper"u8); writer.Write((byte)'\0'); writer.Write((nint)PixelShaderEffect.GetTransformMapper); writer.Write((nint)PixelShaderEffect.SetTransformMapper); + // Add all resource texture manager property bindings + for (int i = 0; i < D2D1PixelShader.GetResourceTextureCount(); i++) + { + switch (i) + { + case 0: + writer.Write("ResourceTextureManager0"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager0); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager0); + break; + case 1: + writer.Write("ResourceTextureManager1"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager1); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager1); + break; + case 2: + writer.Write("ResourceTextureManager2"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager2); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager2); + break; + case 3: + writer.Write("ResourceTextureManager3"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager3); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager3); + break; + case 4: + writer.Write("ResourceTextureManager4"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager4); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager4); + break; + case 5: + writer.Write("ResourceTextureManager5"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager5); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager5); + break; + case 6: + writer.Write("ResourceTextureManager6"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager6); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager6); + break; + case 7: + writer.Write("ResourceTextureManager7"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager7); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager7); + break; + case 8: + writer.Write("ResourceTextureManager8"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager8); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager8); + break; + case 9: + writer.Write("ResourceTextureManager9"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager9); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager9); + break; + case 10: + writer.Write("ResourceTextureManager10"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager10); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager10); + break; + case 11: + writer.Write("ResourceTextureManager11"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager11); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager11); + break; + case 12: + writer.Write("ResourceTextureManager12"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager12); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager12); + break; + case 13: + writer.Write("ResourceTextureManager13"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager13); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager13); + break; + case 14: + writer.Write("ResourceTextureManager14"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager14); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager14); + break; + case 15: + writer.Write("ResourceTextureManager15"u8); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager15); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager15); + break; + } + } + // Effect factory writer.Write((nint)PixelShaderEffect.For.Instance.Factory); @@ -410,16 +450,18 @@ public static unsafe class D2D1PixelShaderEffect /// /// A pointer to the ID2D1Effect instance to use. /// The input ID2D1ResourceTextureManager object (see ). - /// The index of the resource texture to assign the resource texture manager to. + /// The index of the resource texture manager to assign the resource texture manager to (note: this might not match the resource texture index). /// Thrown if or are . + /// Thrown if is outside of the allowed range (ie. [0, 16]). /// For more info, see . - public static void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, void* resourceTextureManager, int resourceTextureIndex) + public static void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, void* resourceTextureManager, int index) { default(ArgumentNullException).ThrowIfNull(d2D1Effect); default(ArgumentNullException).ThrowIfNull(resourceTextureManager); + default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16); ((ID2D1Effect*)d2D1Effect)->SetValue( - index: D2D1PixelShaderEffectProperty.ResourceTextureManager0 + (uint)resourceTextureIndex, + index: D2D1PixelShaderEffectProperty.ResourceTextureManager0 + (uint)index, type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_IUNKNOWN, data: (byte*)&resourceTextureManager, dataSize: (uint)sizeof(void*)).Assert(); @@ -430,20 +472,22 @@ public static unsafe class D2D1PixelShaderEffect /// /// A pointer to the ID2D1Effect instance to use. /// The input instance. - /// The index of the resource texture to assign the resource texture manager to. + /// The index of the resource texture manager to assign the resource texture manager to (note: this might not match the resource texture index) /// Thrown if or are . + /// Thrown if is outside of the allowed range (ie. [0, 16]). /// For more info, see . - public static void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, D2D1ResourceTextureManager resourceTextureManager, int resourceTextureIndex) + public static void SetResourceTextureManagerForD2D1Effect(void* d2D1Effect, D2D1ResourceTextureManager resourceTextureManager, int index) { default(ArgumentNullException).ThrowIfNull(d2D1Effect); default(ArgumentNullException).ThrowIfNull(resourceTextureManager); + default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16); using ComPtr resourceTextureManager2 = default; resourceTextureManager.GetD2D1ResourceTextureManager(resourceTextureManager2.GetAddressOf()); ((ID2D1Effect*)d2D1Effect)->SetValue( - index: D2D1PixelShaderEffectProperty.ResourceTextureManager0 + (uint)resourceTextureIndex, + index: D2D1PixelShaderEffectProperty.ResourceTextureManager0 + (uint)index, type: D2D1_PROPERTY_TYPE.D2D1_PROPERTY_TYPE_IUNKNOWN, data: (byte*)resourceTextureManager2.GetAddressOf(), dataSize: (uint)sizeof(void*)).Assert(); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffectProperty.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffectProperty.cs index 440b0951..eaa7ad43 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffectProperty.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffectProperty.cs @@ -17,102 +17,6 @@ public static class D2D1PixelShaderEffectProperty /// public const uint ConstantBuffer = 0; - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 0. - /// - /// For more info, see . - public const uint ResourceTextureManager0 = 1; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 1. - /// - /// For more info, see . - public const uint ResourceTextureManager1 = 2; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 2. - /// - /// For more info, see . - public const uint ResourceTextureManager2 = 3; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 3. - /// - /// For more info, see . - public const uint ResourceTextureManager3 = 4; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 4. - /// - /// For more info, see . - public const uint ResourceTextureManager4 = 5; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 5. - /// - /// For more info, see . - public const uint ResourceTextureManager5 = 6; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 6. - /// - /// For more info, see . - public const uint ResourceTextureManager6 = 7; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 7. - /// - /// For more info, see . - public const uint ResourceTextureManager7 = 8; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 8. - /// - /// For more info, see . - public const uint ResourceTextureManager8 = 9; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 9. - /// - /// For more info, see . - public const uint ResourceTextureManager9 = 10; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 10. - /// - /// For more info, see . - public const uint ResourceTextureManager10 = 11; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 11. - /// - /// For more info, see . - public const uint ResourceTextureManager11 = 12; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 12. - /// - /// For more info, see . - public const uint ResourceTextureManager12 = 13; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 13. - /// - /// For more info, see . - public const uint ResourceTextureManager13 = 14; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 14. - /// - /// For more info, see . - public const uint ResourceTextureManager14 = 15; - - /// - /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 15. - /// - /// For more info, see . - public const uint ResourceTextureManager15 = 16; - /// /// The index for the ID2D1TransformMapper property of a object. /// @@ -121,11 +25,116 @@ public static class D2D1PixelShaderEffectProperty /// This value can be passed when calling ID2D1Effect::SetValue. /// For more info, see . /// - public const uint TransformMapper = 17; + public const uint TransformMapper = 1; /// - /// The total number of properties. + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 0. + /// + /// + /// For more info, see . + /// This property is only available if a shader declares at least N + 1 resource textures. + /// + public const uint ResourceTextureManager0 = 2; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 1. + /// + /// + public const uint ResourceTextureManager1 = 3; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 2. + /// + /// + public const uint ResourceTextureManager2 = 4; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 3. + /// + /// + public const uint ResourceTextureManager3 = 5; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 4. + /// + /// + public const uint ResourceTextureManager4 = 6; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 5. + /// + /// + public const uint ResourceTextureManager5 = 7; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 6. + /// + /// + public const uint ResourceTextureManager6 = 8; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 7. + /// + /// + public const uint ResourceTextureManager7 = 9; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 8. + /// + /// + public const uint ResourceTextureManager8 = 10; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 9. + /// + /// + public const uint ResourceTextureManager9 = 11; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 10. + /// + /// + public const uint ResourceTextureManager10 = 12; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 11. + /// + /// + public const uint ResourceTextureManager11 = 13; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 12. + /// + /// + public const uint ResourceTextureManager12 = 14; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 13. + /// + /// + public const uint ResourceTextureManager13 = 15; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 14. + /// + /// + public const uint ResourceTextureManager14 = 16; + + /// + /// The index for the ID2D1ResourceTextureManager instance for the resource texture at index 15. + /// + /// + public const uint ResourceTextureManager15 = 17; + + /// + /// The maximum total number of properties. /// /// This should always be the value of the last property above, plus 1. - internal const uint NumberOfProperties = 18; + internal const int MaximumNumberOfAvailableProperties = 18; + + /// + /// The number of always available properties. + /// + /// These are and . + internal const int NumberOfAlwaysAvailableProperties = 2; } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs index 1affe1a6..2450925e 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs @@ -146,9 +146,9 @@ internal unsafe partial struct PixelShaderEffect if (Windows.SUCCEEDED(hresult)) { - foreach (ref readonly D2D1ResourceTextureDescription resourceTextureDescription in new ReadOnlySpan(@this->resourceTextureDescriptions, @this->resourceTextureDescriptionCount)) + for (int i = 0; i < @this->resourceTextureDescriptionCount; i++) { - using ComPtr resourceTextureManager = @this->resourceTextureManagerBuffer[resourceTextureDescription.Index]; + using ComPtr resourceTextureManager = @this->resourceTextureManagerBuffer[i]; // If the current resource texture manager is not set, we cannot render, as there's an unbound resource texture if (resourceTextureManager.Get() is null) @@ -180,6 +180,8 @@ internal unsafe partial struct PixelShaderEffect break; } + ref readonly D2D1ResourceTextureDescription resourceTextureDescription = ref @this->resourceTextureDescriptions[i]; + // Set the ID2D1ResourceTexture object to the current index in the ID2D1DrawInfo object in use hresult = @this->d2D1DrawInfo->SetResourceTexture( textureIndex: (uint)resourceTextureDescription.Index, diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs index 335c4d19..3eff1fa7 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs @@ -277,14 +277,14 @@ unsafe partial struct PixelShaderEffect /// /// Gets the resource texture manager for a given index. /// - /// The index of the resource texture to get the manager for. + /// The index of the resource texture manager to assign the resource texture manager to (this might not match the resource texture index). /// A pointer to a variable that stores the data that this function retrieves on the property. /// The number of bytes in the property to retrieve. /// A optional pointer to a variable that stores the actual number of bytes retrieved on the property. /// The for the operation. - private int GetResourceTextureManagerAtIndex(int resourceTextureIndex, byte* data, uint dataSize, uint* actualSize) + private int GetResourceTextureManagerAtIndex(int index, byte* data, uint dataSize, uint* actualSize) { - if (!IsResourceTextureManagerIndexValid(resourceTextureIndex, out _)) + if (index >= this.resourceTextureDescriptionCount) { return E.E_INVALIDARG; } @@ -299,7 +299,7 @@ unsafe partial struct PixelShaderEffect return E.E_INVALIDARG; } - using ComPtr resourceTextureManager = this.resourceTextureManagerBuffer[resourceTextureIndex]; + using ComPtr resourceTextureManager = this.resourceTextureManagerBuffer[index]; HRESULT hresult = resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data); @@ -319,13 +319,13 @@ unsafe partial struct PixelShaderEffect /// /// Sets the resource texture manager for a given index. /// - /// The index of the resource texture to set the manager for. + /// The index of the resource texture manager to assign the resource texture manager to (this might not match the resource texture index). /// A pointer to the data to be set on the property. /// The number of bytes in the property set by the function. /// The for the operation. - private int SetResourceTextureManagerAtIndex(int resourceTextureIndex, byte* data, uint dataSize) + private int SetResourceTextureManagerAtIndex(int index, byte* data, uint dataSize) { - if (!IsResourceTextureManagerIndexValid(resourceTextureIndex, out uint dimensions)) + if (index >= this.resourceTextureDescriptionCount) { return E.E_INVALIDARG; } @@ -371,6 +371,8 @@ unsafe partial struct PixelShaderEffect // Initialize the resource texture manager, if an effect context is available if (this.d2D1EffectContext is not null) { + uint dimensions = (uint)this.resourceTextureDescriptions[index].Dimensions; + result = resourceTextureManagerInternal.Get()->Initialize(this.d2D1EffectContext, &dimensions); // ID2D1ResourceTextureManager::Initialize should generally return either S_OK for first @@ -384,7 +386,7 @@ unsafe partial struct PixelShaderEffect } } - ref ID2D1ResourceTextureManager* currentResourceTextureManager = ref this.resourceTextureManagerBuffer[resourceTextureIndex]; + ref ID2D1ResourceTextureManager* currentResourceTextureManager = ref this.resourceTextureManagerBuffer[index]; // If there's already an existing manager at this index, release it if (currentResourceTextureManager is not null) @@ -397,27 +399,4 @@ unsafe partial struct PixelShaderEffect return S.S_OK; } - - /// - /// Checks whether a given index for a resource texture manager is valid for the current effect. - /// - /// The index of the resource texture to validate. - /// The number of dimensions for the resource texture at the gven index. - /// Whether or not is valid for the current effect. - private readonly bool IsResourceTextureManagerIndexValid(int resourceTextureIndex, out uint dimensions) - { - foreach (ref readonly D2D1ResourceTextureDescription resourceTextureDescription in new ReadOnlySpan(this.resourceTextureDescriptions, this.resourceTextureDescriptionCount)) - { - if (resourceTextureDescription.Index == resourceTextureIndex) - { - dimensions = (uint)resourceTextureDescription.Dimensions; - - return true; - } - } - - dimensions = 0; - - return false; - } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index a898f11b..3106e5df 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -351,11 +351,10 @@ internal unsafe partial struct PixelShaderEffect _ = this.d2D1EffectContext->Release(); } - // Use the list of resource texture descriptions to see the indices that might have accepted a resource texture manager. - // Then, retrieve all of them and release the ones that had been assigned (from one of the property bindings). - foreach (ref readonly D2D1ResourceTextureDescription resourceTextureDescription in new ReadOnlySpan(this.resourceTextureDescriptions, this.resourceTextureDescriptionCount)) + // Retrieve all possible resource texture managers in use and release the ones that had been assigned (from one of the property bindings) + for (int i = 0; i < this.resourceTextureDescriptionCount; i++) { - ID2D1ResourceTextureManager* resourceTextureManager = this.resourceTextureManagerBuffer[resourceTextureDescription.Index]; + ID2D1ResourceTextureManager* resourceTextureManager = this.resourceTextureManagerBuffer[i]; if (resourceTextureManager is not null) { diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs index 36f6bc56..a879b4d9 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Helpers/D2D1EffectXmlFactory.cs @@ -53,67 +53,33 @@ internal static unsafe class D2D1EffectXmlFactory _ = builder.Append($" "); } - // Close the inputs tag and add all effect properties + // Close the inputs tag and add the always available properties _ = builder.Append('\n'); _ = builder.Append(""" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - """); + // Add the resource texture manager nodes, if any + for (int i = 0; i < D2D1PixelShader.GetResourceTextureCount(); i++) + { + _ = builder.Append('\n'); + _ = builder.Append($""" + + + + """); + } + + // Close the effect tag + _ = builder.Append('\n'); + _ = builder.Append(""); + // Null terminator for the text _ = builder.Append('\0');