diff --git a/ComputeSharp.sln b/ComputeSharp.sln index 3a191376..945e4d6c 100644 --- a/ComputeSharp.sln +++ b/ComputeSharp.sln @@ -109,6 +109,7 @@ Global src\ComputeSharp.NetStandard\ComputeSharp.NetStandard.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{314eb353-e7e3-4146-8111-685cc83ec1de}*SharedItemsImports = 5 src\ComputeSharp.Core.NetStandard\ComputeSharp.Core.NetStandard.projitems*{3acacf03-6b20-40ba-b8ec-11ac1624d2c9}*SharedItemsImports = 13 + src\ComputeSharp.D2D1Interop.NetStandard\ComputeSharp.D2D1Interop.NetStandard.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5 src\TerraFX.Interop.Windows.D2D1Interop\TerraFX.Interop.Windows.D2D1Interop.projitems*{4d7d9ba8-a821-4b1c-9ee2-cbcf5849906e}*SharedItemsImports = 5 src\TerraFX.Interop.Windows\TerraFX.Interop.Windows.projitems*{514ff00e-bbf0-4d55-a47c-eeeb6208adce}*SharedItemsImports = 13 src\ComputeSharp.SourceGeneration\ComputeSharp.SourceGeneration.projitems*{51d5a422-d3a5-4c4d-8a6d-a048940bf279}*SharedItemsImports = 13 diff --git a/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj b/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj index a2eea4a2..14ab14ea 100644 --- a/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj +++ b/src/ComputeSharp.D2D1Interop/ComputeSharp.D2D1Interop.csproj @@ -1,9 +1,8 @@  - net6.0 + netstandard2.0;net6.0 bin\Release ComputeSharp.D2D1Interop.xml - AnyCPU;x64;ARM64 diff --git a/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1InteropServices.Effects.cs b/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1InteropServices.Effects.cs index 2ffb12bd..4062f71f 100644 --- a/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1InteropServices.Effects.cs +++ b/src/ComputeSharp.D2D1Interop/Shaders/Interop/D2D1InteropServices.Effects.cs @@ -1,7 +1,10 @@ using System; +#if !NET6_0_OR_GREATER +using System.Runtime.InteropServices; +#endif using System.Text; using ComputeSharp.D2D1Interop.Extensions; -using ComputeSharp.D2D1Interop.Tests.Helpers; +using ComputeSharp.D2D1Interop.Interop.Effects; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -56,12 +59,20 @@ unsafe partial class D2D1InteropServices d2D1PropertyBinding.propertyName = (ushort*)pPropertyName; d2D1PropertyBinding.getFunction = (delegate* unmanaged[Stdcall]) - (delegate* unmanaged[Stdcall]) +#if NET6_0_OR_GREATER + (delegate* unmanaged) &PixelShaderEffect.GetConstantBuffer; +#else + (void*)Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.GetConstantBufferWrapper); +#endif d2D1PropertyBinding.setFunction = (delegate* unmanaged[Stdcall]) - (delegate* unmanaged[Stdcall]) +#if NET6_0_OR_GREATER + (delegate* unmanaged) &PixelShaderEffect.SetConstantBuffer; +#else + (void*)Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.SetConstantBufferWrapper); +#endif Guid shaderId = typeof(T).GUID; diff --git a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs index 99b64e9d..4b623e0d 100644 --- a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs +++ b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1DrawTransformMethods.cs @@ -2,8 +2,11 @@ using System.Runtime.InteropServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if !NET6_0_OR_GREATER +using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute; +#endif -namespace ComputeSharp.D2D1Interop.Tests.Helpers; +namespace ComputeSharp.D2D1Interop.Interop.Effects; /// partial struct PixelShaderEffect @@ -13,6 +16,68 @@ partial struct PixelShaderEffect /// private unsafe static class ID2D1DrawTransformMethods { +#if !NET6_0_OR_GREATER + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate uint GetInputCountDelegate(PixelShaderEffect* @this); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int MapOutputRectToInputRectsDelegate(PixelShaderEffect* @this, RECT* outputRect, RECT* inputRects, uint inputRectsCount); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int MapInputRectsToOutputRectDelegate(PixelShaderEffect* @this, RECT* inputRects, RECT* inputOpaqueSubRects, uint inputRectCount, RECT* outputRect, RECT* outputOpaqueSubRect); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int MapInvalidRectDelegate(PixelShaderEffect* @this, uint inputIndex, RECT invalidInputRect, RECT* invalidOutputRect); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int SetDrawInfoDelegate(PixelShaderEffect* @this, ID2D1DrawInfo* drawInfo); + + /// + /// A cached instance wrapping . + /// + public static readonly QueryInterfaceDelegate QueryInterfaceWrapper = QueryInterface; + + /// + /// A cached instance wrapping . + /// + public static readonly AddRefDelegate AddRefWrapper = AddRef; + + /// + /// A cached instance wrapping . + /// + public static readonly ReleaseDelegate ReleaseWrapper = Release; + + /// + /// A cached instance wrapping . + /// + public static readonly GetInputCountDelegate GetInputCountWrapper = GetInputCount; + + /// + /// A cached instance wrapping . + /// + public static readonly MapOutputRectToInputRectsDelegate MapOutputRectToInputRectsWrapper = MapOutputRectToInputRects; + + /// + /// A cached instance wrapping . + /// + public static readonly MapInputRectsToOutputRectDelegate MapInputRectsToOutputRectWrapper = MapInputRectsToOutputRect; + + /// + /// A cached instance wrapping . + /// + public static readonly MapInvalidRectDelegate MapInvalidRectWrapper = MapInvalidRect; + + /// + /// A cached instance wrapping . + /// + public static readonly SetDrawInfoDelegate SetDrawInfoWrapper = SetDrawInfo; +#endif + /// [UnmanagedCallersOnly] public static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject) diff --git a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs index 0ff6cb33..e8d6181a 100644 --- a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs +++ b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs @@ -2,8 +2,11 @@ using System.Runtime.InteropServices; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if !NET6_0_OR_GREATER +using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute; +#endif -namespace ComputeSharp.D2D1Interop.Tests.Helpers; +namespace ComputeSharp.D2D1Interop.Interop.Effects; /// /// A simple and implementation for a given pixel shader. @@ -15,6 +18,50 @@ internal unsafe partial struct PixelShaderEffect /// private static class ID2D1EffectImplMethods { +#if !NET6_0_OR_GREATER + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int InitializeDelegate(PixelShaderEffect* @this, ID2D1EffectContext* effectContext, ID2D1TransformGraph* transformGraph); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int PrepareForRenderDelegate(PixelShaderEffect* @this, D2D1_CHANGE_TYPE changeType); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int SetGraphDelegate(PixelShaderEffect* @this, ID2D1TransformGraph* transformGraph); + + /// + /// A cached instance wrapping . + /// + public static readonly QueryInterfaceDelegate QueryInterfaceWrapper = QueryInterface; + + /// + /// A cached instance wrapping . + /// + public static readonly AddRefDelegate AddRefWrapper = AddRef; + + /// + /// A cached instance wrapping . + /// + public static readonly ReleaseDelegate ReleaseWrapper = Release; + + /// + /// A cached instance wrapping . + /// + public static readonly InitializeDelegate InitializeWrapper = Initialize; + + /// + /// A cached instance wrapping . + /// + public static readonly PrepareForRenderDelegate PrepareForRenderWrapper = PrepareForRender; + + /// + /// A cached instance wrapping . + /// + public static readonly SetGraphDelegate SetGraphWrapper = SetGraph; +#endif + /// [UnmanagedCallersOnly] public static int QueryInterface(PixelShaderEffect* @this, Guid* riid, void** ppvObject) diff --git a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.cs index cec6e777..23c3e056 100644 --- a/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1Interop/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -4,8 +4,14 @@ using System.Runtime.InteropServices; using System.Threading; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; +#if NET6_0_OR_GREATER +using RuntimeHelpers = System.Runtime.CompilerServices.RuntimeHelpers; +#else +using RuntimeHelpers = ComputeSharp.D2D1Interop.NetStandard.System.Runtime.CompilerServices.RuntimeHelpers; +using UnmanagedCallersOnlyAttribute = ComputeSharp.NetStandard.System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute; +#endif -namespace ComputeSharp.D2D1Interop.Tests.Helpers; +namespace ComputeSharp.D2D1Interop.Interop.Effects; /// /// A simple and implementation for a given pixel shader. @@ -20,6 +26,38 @@ internal unsafe partial struct PixelShaderEffect [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate int FactoryDelegate(IUnknown** effectImpl); +#if !NET6_0_OR_GREATER + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate int QueryInterfaceDelegate(PixelShaderEffect* @this, Guid* riid, void** ppvObject); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate uint AddRefDelegate(PixelShaderEffect* @this); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + private delegate uint ReleaseDelegate(PixelShaderEffect* @this); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int GetConstantBufferDelegate(IUnknown* effect, byte* data, uint dataSize, uint* actualSize); + + /// + [UnmanagedFunctionPointer(CallingConvention.StdCall)] + public delegate int SetConstantBufferDelegate(IUnknown* effect, byte* data, uint dataSize); + + /// + /// A cached instance wrapping . + /// + public static readonly GetConstantBufferDelegate GetConstantBufferWrapper = GetConstantBuffer; + + /// + /// A cached instance wrapping . + /// + public static readonly SetConstantBufferDelegate SetConstantBufferWrapper = SetConstantBuffer; +#endif + /// /// A generic pixel shader implementation. /// @@ -108,14 +146,24 @@ internal unsafe partial struct PixelShaderEffect void** lpVtbl = (void**)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(PixelShaderEffect), sizeof(void*) * 14); // ID2D1EffectImpl +#if NET6_0_OR_GREATER lpVtbl[0] = (delegate* unmanaged)&ID2D1EffectImplMethods.QueryInterface; lpVtbl[1] = (delegate* unmanaged)&ID2D1EffectImplMethods.AddRef; lpVtbl[2] = (delegate* unmanaged)&ID2D1EffectImplMethods.Release; lpVtbl[3] = (delegate* unmanaged)&ID2D1EffectImplMethods.Initialize; lpVtbl[4] = (delegate* unmanaged)&ID2D1EffectImplMethods.PrepareForRender; lpVtbl[5] = (delegate* unmanaged)&ID2D1EffectImplMethods.SetGraph; +#else + lpVtbl[0] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1EffectImplMethods.QueryInterfaceWrapper); + lpVtbl[1] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1EffectImplMethods.AddRefWrapper); + lpVtbl[2] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1EffectImplMethods.ReleaseWrapper); + lpVtbl[3] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1EffectImplMethods.InitializeWrapper); + lpVtbl[4] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1EffectImplMethods.PrepareForRenderWrapper); + lpVtbl[5] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1EffectImplMethods.SetGraphWrapper); +#endif // ID2D1DrawTransform +#if NET6_0_OR_GREATER lpVtbl[6 + 0] = (delegate* unmanaged)&ID2D1DrawTransformMethods.QueryInterface; lpVtbl[6 + 1] = (delegate* unmanaged)&ID2D1DrawTransformMethods.AddRef; lpVtbl[6 + 2] = (delegate* unmanaged)&ID2D1DrawTransformMethods.Release; @@ -124,6 +172,16 @@ internal unsafe partial struct PixelShaderEffect lpVtbl[6 + 5] = (delegate* unmanaged)&ID2D1DrawTransformMethods.MapInputRectsToOutputRect; lpVtbl[6 + 6] = (delegate* unmanaged)&ID2D1DrawTransformMethods.MapInvalidRect; lpVtbl[6 + 7] = (delegate* unmanaged)&ID2D1DrawTransformMethods.SetDrawInfo; +#else + lpVtbl[6 + 0] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.QueryInterfaceWrapper); + lpVtbl[6 + 1] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.AddRefWrapper); + lpVtbl[6 + 2] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.ReleaseWrapper); + lpVtbl[6 + 3] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.GetInputCountWrapper); + lpVtbl[6 + 4] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.MapOutputRectToInputRectsWrapper); + lpVtbl[6 + 5] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.MapInputRectsToOutputRectWrapper); + lpVtbl[6 + 6] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.MapInvalidRectWrapper); + lpVtbl[6 + 7] = (void*)Marshal.GetFunctionPointerForDelegate(ID2D1DrawTransformMethods.SetDrawInfoWrapper); +#endif VtblForID2D1EffectImpl = lpVtbl; VtblForID2D1DrawTransform = &lpVtbl[6]; @@ -213,7 +271,7 @@ internal unsafe partial struct PixelShaderEffect } /// - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [UnmanagedCallersOnly] public static int GetConstantBuffer(IUnknown* effect, byte* data, uint dataSize, uint* actualSize) { PixelShaderEffect* @this = (PixelShaderEffect*)effect; @@ -235,7 +293,7 @@ internal unsafe partial struct PixelShaderEffect } /// - [UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvStdcall) })] + [UnmanagedCallersOnly] public static int SetConstantBuffer(IUnknown* effect, byte* data, uint dataSize) { PixelShaderEffect* @this = (PixelShaderEffect*)effect;