From 5328c4b39cf0e6c61b996a37757ccc8759a8edd4 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 11 Aug 2022 15:42:22 +0200 Subject: [PATCH] Update ID2D1Effect registration with new properties --- .../Shaders/Interop/D2D1PixelShaderEffect.cs | 269 ++++++++++++++++-- .../d2d1effectauthor/D2D1_PROPERTY_BINDING.cs | 4 +- 2 files changed, 242 insertions(+), 31 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs index fd9c236f..969aa1c4 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1PixelShaderEffect.cs @@ -91,26 +91,134 @@ public static unsafe class D2D1PixelShaderEffect + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; fixed (char* pXml = xml) - fixed (char* pPropertyName = "Buffer") + fixed (char* pBufferPropertyName = "Buffer") + fixed (char* pResourceTextureManager0PropertyName = "ResourceTextureManager0") + fixed (char* pResourceTextureManager1PropertyName = "ResourceTextureManager1") + fixed (char* pResourceTextureManager2PropertyName = "ResourceTextureManager2") + fixed (char* pResourceTextureManager3PropertyName = "ResourceTextureManager3") + fixed (char* pResourceTextureManager4PropertyName = "ResourceTextureManager4") + fixed (char* pResourceTextureManager5PropertyName = "ResourceTextureManager5") + fixed (char* pResourceTextureManager6PropertyName = "ResourceTextureManager6") + fixed (char* pResourceTextureManager7PropertyName = "ResourceTextureManager7") + fixed (char* pResourceTextureManager8PropertyName = "ResourceTextureManager8") + fixed (char* pResourceTextureManager9PropertyName = "ResourceTextureManager9") + fixed (char* pResourceTextureManager10PropertyName = "ResourceTextureManager10") + fixed (char* pResourceTextureManager11PropertyName = "ResourceTextureManager11") + fixed (char* pResourceTextureManager12PropertyName = "ResourceTextureManager12") + fixed (char* pResourceTextureManager13PropertyName = "ResourceTextureManager13") + fixed (char* pResourceTextureManager14PropertyName = "ResourceTextureManager14") + fixed (char* pResourceTextureManager15PropertyName = "ResourceTextureManager15") { // Prepare the effect binding functions - D2D1_PROPERTY_BINDING d2D1PropertyBinding; - d2D1PropertyBinding.propertyName = (ushort*)pPropertyName; - d2D1PropertyBinding.getFunction = -#if NET6_0_OR_GREATER - &PixelShaderEffect.GetConstantBuffer; -#else - (void*)Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.GetConstantBufferWrapper); -#endif - d2D1PropertyBinding.setFunction = -#if NET6_0_OR_GREATER - &PixelShaderEffect.SetConstantBuffer; -#else - (void*)Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.SetConstantBufferWrapper); -#endif + D2D1_PROPERTY_BINDING* d2D1PropertyBinding = stackalloc D2D1_PROPERTY_BINDING[17]; + + // 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; + + // 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; + + // 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; fixed (Guid* pGuid = &PixelShaderEffect.For.Id) { @@ -118,8 +226,8 @@ public static unsafe class D2D1PixelShaderEffect ((ID2D1Factory1*)d2D1Factory1)->RegisterEffectFromString( classId: pGuid, propertyXml: (ushort*)pXml, - bindings: &d2D1PropertyBinding, - bindingsCount: 1, + bindings: d2D1PropertyBinding, + bindingsCount: 17, effectFactory: PixelShaderEffect.For.Factory).Assert(); } @@ -239,26 +347,129 @@ public static unsafe class D2D1PixelShaderEffect + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "); // Null terminator for the text writer.Write((byte)'\0'); - // Property accessors -#if NET6_0_OR_GREATER - nint getBufferPointer = (nint)(delegate* unmanaged)&PixelShaderEffect.GetConstantBuffer; - nint setBufferPointer = (nint)(delegate* unmanaged)&PixelShaderEffect.SetConstantBuffer; -#else - nint getBufferPointer = Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.GetConstantBufferWrapper); - nint setBufferPointer = Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.SetConstantBufferWrapper); -#endif - // Bindings - writer.Write(1); + writer.Write(17); writer.WriteAsUtf8("Buffer"); writer.Write((byte)'\0'); - writer.Write(getBufferPointer); - writer.Write(setBufferPointer); + writer.Write((nint)PixelShaderEffect.GetConstantBuffer); + writer.Write((nint)PixelShaderEffect.SetConstantBuffer); + writer.WriteAsUtf8("ResourceTextureManager0"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager0); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager0); + writer.WriteAsUtf8("ResourceTextureManager1"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager1); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager1); + writer.WriteAsUtf8("ResourceTextureManager2"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager2); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager2); + writer.WriteAsUtf8("ResourceTextureManager3"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager3); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager3); + writer.WriteAsUtf8("ResourceTextureManager4"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager4); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager4); + writer.WriteAsUtf8("ResourceTextureManager5"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager5); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager5); + writer.WriteAsUtf8("ResourceTextureManager6"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager6); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager6); + writer.WriteAsUtf8("ResourceTextureManager7"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager7); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager7); + writer.WriteAsUtf8("ResourceTextureManager8"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager8); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager8); + writer.WriteAsUtf8("ResourceTextureManager9"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager9); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager9); + writer.WriteAsUtf8("ResourceTextureManager10"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager10); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager10); + writer.WriteAsUtf8("ResourceTextureManager11"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager11); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager11); + writer.WriteAsUtf8("ResourceTextureManager12"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager12); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager12); + writer.WriteAsUtf8("ResourceTextureManager13"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager13); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager13); + writer.WriteAsUtf8("ResourceTextureManager14"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager14); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager14); + writer.WriteAsUtf8("ResourceTextureManager15"); + writer.Write((byte)'\0'); + writer.Write((nint)PixelShaderEffect.GetResourceTextureManager15); + writer.Write((nint)PixelShaderEffect.SetResourceTextureManager15); // Effect factory writer.Write((nint)PixelShaderEffect.For.Factory); diff --git a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_PROPERTY_BINDING.cs b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_PROPERTY_BINDING.cs index 96bdd363..fdd86e4a 100644 --- a/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_PROPERTY_BINDING.cs +++ b/src/TerraFX.Interop.Windows.D2D1/DirectX/um/d2d1effectauthor/D2D1_PROPERTY_BINDING.cs @@ -18,14 +18,14 @@ namespace TerraFX.Interop.DirectX [NativeTypeName("PD2D1_PROPERTY_SET_FUNCTION")] #if NET6_0_OR_GREATER - public delegate* unmanaged setFunction; + public delegate* unmanaged[Stdcall] setFunction; #else public void* setFunction; #endif [NativeTypeName("PD2D1_PROPERTY_GET_FUNCTION")] #if NET6_0_OR_GREATER - public delegate* unmanaged getFunction; + public delegate* unmanaged[Stdcall] getFunction; #else public void* getFunction; #endif