From 056128054ab84b8c1d5138e53bbd6bfe3046e43e Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 19 Apr 2022 11:12:16 +0200 Subject: [PATCH] Remove [FixedAddressValueType] use --- .../Interop/D2D1InteropServices.Effects.cs | 23 +++++++++++-------- .../Interop/Effects/PixelShaderEffect.cs | 12 ++++++---- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.Effects.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.Effects.cs index c60500ad..15f0b0b7 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.Effects.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1InteropServices.Effects.cs @@ -109,15 +109,18 @@ unsafe partial class D2D1InteropServices (void*)Marshal.GetFunctionPointerForDelegate(PixelShaderEffect.SetConstantBufferWrapper); #endif - // Register the effect - ((ID2D1Factory1*)d2D1Factory1)->RegisterEffectFromString( - classId: PixelShaderEffect.For.Id, - propertyXml: (ushort*)pXml, - bindings: &d2D1PropertyBinding, - bindingsCount: 1, - effectFactory: PixelShaderEffect.For.Factory).Assert(); + fixed (Guid* pGuid = &PixelShaderEffect.For.Id) + { + // Register the effect + ((ID2D1Factory1*)d2D1Factory1)->RegisterEffectFromString( + classId: pGuid, + propertyXml: (ushort*)pXml, + bindings: &d2D1PropertyBinding, + bindingsCount: 1, + effectFactory: PixelShaderEffect.For.Factory).Assert(); + } - effectId = *PixelShaderEffect.For.Id; + effectId = PixelShaderEffect.For.Id; } } @@ -193,7 +196,7 @@ unsafe partial class D2D1InteropServices using ArrayPoolBinaryWriter writer = new(ArrayPoolBinaryWriter.DefaultInitialBufferSize); // Effect id and number of inputs - writer.Write(*PixelShaderEffect.For.Id); + writer.Write(PixelShaderEffect.For.Id); writer.Write(PixelShaderEffect.For.NumberOfInputs); // Build the XML text @@ -246,7 +249,7 @@ unsafe partial class D2D1InteropServices // Effect factory writer.Write((nint)PixelShaderEffect.For.Factory); - effectId = *PixelShaderEffect.For.Id; + effectId = PixelShaderEffect.For.Id; return writer.WrittenSpan.ToArray(); } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs index a33c0d17..03095ba5 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.cs @@ -79,7 +79,11 @@ internal unsafe partial struct PixelShaderEffect /// /// The for the shader. /// - [FixedAddressValueType] + /// + /// This field could have used to reduce some verbosity where it is + /// being used to pass its address to a native API, but the attribute is incompatible with collectible assemblies. + /// Because of that, it can't be used, as this project is explicitly meant to support plugin-like scenarios. + /// private static Guid shaderId; /// @@ -147,12 +151,12 @@ internal unsafe partial struct PixelShaderEffect } /// - /// Gets a pointer to the id of the effect. + /// Gets a reference to the id of the effect. /// - public static Guid* Id + public static ref Guid Id { [MethodImpl(MethodImplOptions.AggressiveInlining)] - get => (Guid*)Unsafe.AsPointer(ref shaderId); + get => ref shaderId; } ///