From 3ad17eaa6d886210a2207274def31248c12f0f48 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 23 Nov 2023 20:26:44 +0100 Subject: [PATCH] Use IComObject in remaining D2D types Also adopt collection expressions for all IIDs --- .../ICanvasFactoryNative.cs | 7 ++- .../D2D1DrawInfoUpdateContextImpl.cs | 4 +- .../ID2D1DrawInfoUpdateContext.cs | 18 +++--- .../ID2D1DrawInfoUpdateContextInternal.cs | 18 +++--- .../DirectX/um/d2d1effects/CLSID.cs | 10 ++-- .../DirectX/um/dxcapi/CLSID.cs | 5 +- .../Windows/um/objidlbase/IID.cs | 12 ++-- .../Windows/um/wincodec/GUID.cs | 60 +++++++++++-------- 8 files changed, 77 insertions(+), 57 deletions(-) diff --git a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs index 457adf14..c6ea0c58 100644 --- a/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs +++ b/samples/ComputeSharp.SwapChain.D2D1.Cli/Backend/ABI.Microsoft.Graphics.Canvas/ICanvasFactoryNative.cs @@ -6,7 +6,7 @@ using TerraFX.Interop; using WinRT; using WinRT.Interop; -#pragma warning disable CS0649, IDE1006 +#pragma warning disable CS0649, IDE0055, IDE1006 namespace ABI.Microsoft.Graphics.Canvas; @@ -22,7 +22,8 @@ internal unsafe struct ICanvasFactoryNative : IUnknown.Interface { get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x0D, 0x44, 0x5C, 0x69, 0xB3, 0x04, 0xDD, 0x4E, @@ -33,7 +34,7 @@ internal unsafe struct ICanvasFactoryNative : IUnknown.Interface 0x9F, 0x72, 0x02 - }; + ]; return (Guid*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)); } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.cs index 7d4c4f3f..8560794f 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/D2D1DrawInfoUpdateContextImpl.cs @@ -132,7 +132,7 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl // ID2D1DrawInfoUpdateContext if (riid->Equals(Windows.__uuidof()) || - riid->Equals(ID2D1DrawInfoUpdateContext.Guid)) + riid->Equals(Windows.__uuidof())) { _ = Interlocked.Increment(ref this.referenceCount); @@ -142,7 +142,7 @@ internal unsafe partial struct D2D1DrawInfoUpdateContextImpl } // ID2D1DrawInfoUpdateContextInternal - if (riid->Equals(ID2D1DrawInfoUpdateContextInternal.Guid)) + if (riid->Equals(Windows.__uuidof())) { _ = Interlocked.Increment(ref this.referenceCount); diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContext.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContext.cs index 5624ac28..efe8517a 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContext.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContext.cs @@ -3,23 +3,23 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.Win32; -#pragma warning disable CS0649 +#pragma warning disable CS0649, IDE0055 namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers; /// /// The updater for type to use with built-in effects. /// -internal unsafe struct ID2D1DrawInfoUpdateContext +internal unsafe struct ID2D1DrawInfoUpdateContext : IComObject { - /// - /// Gets the for (430C5B40-AE16-485F-90E6-4FA4915144B6). - /// - public static ref readonly Guid Guid + /// + static Guid* IComObject.IID { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x40, 0x5B, 0x0C, 0x43, 0x16, 0xAE, 0x5F, 0x48, @@ -30,9 +30,9 @@ internal unsafe struct ID2D1DrawInfoUpdateContext 0x51, 0x44, 0xB6 - }; + ]; - return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + return (Guid*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)); } } diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContextInternal.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContextInternal.cs index e0861293..b5910f7e 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContextInternal.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/TransformMappers/ID2D1DrawInfoUpdateContextInternal.cs @@ -3,23 +3,23 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using ComputeSharp.Win32; -#pragma warning disable CS0649 +#pragma warning disable CS0649, IDE0055 namespace ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers; /// /// An internal version of that supports being closed, to manage lifetime scopes. /// -internal unsafe struct ID2D1DrawInfoUpdateContextInternal +internal unsafe struct ID2D1DrawInfoUpdateContextInternal : IComObject { - /// - /// Gets the for (CF2F5BB0-3F5E-4D6E-8FF1-D9A7EB6C0250). - /// - public static ref readonly Guid Guid + /// + static Guid* IComObject.IID { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0xB0, 0x5B, 0x2F, 0xCF, 0x5E, 0x3F, 0x6E, 0x4D, @@ -30,9 +30,9 @@ internal unsafe struct ID2D1DrawInfoUpdateContextInternal 0x6C, 0x02, 0x50 - }; + ]; - return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); + return (Guid*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(data)); } } diff --git a/src/ComputeSharp.Win32.D2D1/DirectX/um/d2d1effects/CLSID.cs b/src/ComputeSharp.Win32.D2D1/DirectX/um/d2d1effects/CLSID.cs index 233ee71e..dad2dca8 100644 --- a/src/ComputeSharp.Win32.D2D1/DirectX/um/d2d1effects/CLSID.cs +++ b/src/ComputeSharp.Win32.D2D1/DirectX/um/d2d1effects/CLSID.cs @@ -17,7 +17,8 @@ internal static partial class CLSID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x20, 0x3C, 0xC2, 0x61, 0x69, 0xAE, 0x8E, 0x4D, @@ -29,7 +30,7 @@ internal static partial class CLSID 0xF6, 0x38, 0xF2 - }; + ]; return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); } @@ -41,7 +42,8 @@ internal static partial class CLSID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0xC7, 0xC5, 0x26, 0x6C, 0xE0, 0x34, 0xFC, 0x46, @@ -53,7 +55,7 @@ internal static partial class CLSID 0x06, 0xE2, 0x28 - }; + ]; return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); } diff --git a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs index 326cda20..e2db0796 100644 --- a/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs +++ b/src/ComputeSharp.Win32.D3D12/DirectX/um/dxcapi/CLSID.cs @@ -18,7 +18,8 @@ internal static partial class CLSID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0xAF, 0xD6, 0x45, 0x62, 0xE0, 0x66, 0xFD, 0x48, @@ -30,7 +31,7 @@ internal static partial class CLSID 0x96, 0x74, 0x8C - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); diff --git a/src/ComputeSharp.Win32.D3D12/Windows/um/objidlbase/IID.cs b/src/ComputeSharp.Win32.D3D12/Windows/um/objidlbase/IID.cs index 72e17ac5..d43ecba3 100644 --- a/src/ComputeSharp.Win32.D3D12/Windows/um/objidlbase/IID.cs +++ b/src/ComputeSharp.Win32.D3D12/Windows/um/objidlbase/IID.cs @@ -14,9 +14,11 @@ internal static partial class IID { public static ref readonly Guid IID_ISequentialStream { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x30, 0x3A, 0x73, 0x0C, 0x1C, 0x2A, 0xCE, 0x11, @@ -28,7 +30,7 @@ internal static partial class IID 0x44, 0x77, 0x3D - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -37,9 +39,11 @@ internal static partial class IID public static ref readonly Guid IID_IStream { + [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -51,7 +55,7 @@ internal static partial class IID 0x00, 0x00, 0x46 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); diff --git a/src/ComputeSharp.Win32.D3D12/Windows/um/wincodec/GUID.cs b/src/ComputeSharp.Win32.D3D12/Windows/um/wincodec/GUID.cs index ff2cfdcf..59ed46de 100644 --- a/src/ComputeSharp.Win32.D3D12/Windows/um/wincodec/GUID.cs +++ b/src/ComputeSharp.Win32.D3D12/Windows/um/wincodec/GUID.cs @@ -18,7 +18,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x7E, 0xD8, 0xF1, 0x0A, 0xFE, 0xFC, 0x88, 0x41, @@ -30,7 +31,7 @@ internal static partial class GUID 0x71, 0xCB, 0xE3 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -43,7 +44,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0xF4, 0xFA, 0x7C, 0x1B, 0x3F, 0x71, 0x3C, 0x47, @@ -55,7 +57,7 @@ internal static partial class GUID 0x5F, 0xAE, 0xAF - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -68,7 +70,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0xAA, 0xA5, 0xE4, 0x19, 0x62, 0x56, 0xC5, 0x4F, @@ -80,7 +83,7 @@ internal static partial class GUID 0x8E, 0x10, 0x57 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -93,7 +96,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x30, 0xCC, 0x3B, 0x16, 0xE9, 0xE2, 0x0B, 0x4F, @@ -105,7 +109,7 @@ internal static partial class GUID 0xB7, 0x88, 0xA3 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -118,7 +122,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0xAA, 0x7C, 0xA3, 0x57, 0x7A, 0x36, 0x40, 0x45, @@ -130,7 +135,7 @@ internal static partial class GUID 0x09, 0x3A, 0x4B - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -143,7 +148,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x95, 0xCB, 0x67, 0x99, 0x85, 0x2E, 0xC8, 0x4A, @@ -155,7 +161,7 @@ internal static partial class GUID 0xD4, 0x25, 0xC9 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -168,7 +174,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x24, 0xC3, 0xDD, 0x6F, 0x03, 0x4E, 0xFE, 0x4B, @@ -180,7 +187,7 @@ internal static partial class GUID 0x8D, 0xC9, 0x08 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -193,7 +200,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x24, 0xC3, 0xDD, 0x6F, 0x03, 0x4E, 0xFE, 0x4B, @@ -205,7 +213,7 @@ internal static partial class GUID 0x8D, 0xC9, 0x0B - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -218,7 +226,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x24, 0xC3, 0xDD, 0x6F, 0x03, 0x4E, 0xFE, 0x4B, @@ -230,7 +239,7 @@ internal static partial class GUID 0x8D, 0xC9, 0x0C - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -243,7 +252,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x24, 0xC3, 0xDD, 0x6F, 0x03, 0x4E, 0xFE, 0x4B, @@ -255,7 +265,7 @@ internal static partial class GUID 0x8D, 0xC9, 0x0F - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -268,7 +278,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x2D, 0xAD, 0xC7, 0xF5, 0x8D, 0x6A, 0xDD, 0x43, @@ -280,7 +291,7 @@ internal static partial class GUID 0x26, 0x1A, 0xE9 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data)); @@ -293,7 +304,8 @@ internal static partial class GUID [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - ReadOnlySpan data = new byte[] { + ReadOnlySpan data = + [ 0x24, 0xC3, 0xDD, 0x6F, 0x03, 0x4E, 0xFE, 0x4B, @@ -305,7 +317,7 @@ internal static partial class GUID 0x8D, 0xC9, 0x16 - }; + ]; Debug.Assert(data.Length == Unsafe.SizeOf()); return ref Unsafe.As(ref MemoryMarshal.GetReference(data));