From d9dffde1310e519a9c6f987f6c3a8e1ff47c0bb7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sat, 20 Aug 2022 14:56:05 +0200 Subject: [PATCH] Remove pinning from ComPtr.GetPinnableReference() --- src/ComputeSharp/Graphics/Commands/CommandList.cs | 2 ++ src/TerraFX.Interop.Windows/ComPtr`1.cs | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ComputeSharp/Graphics/Commands/CommandList.cs b/src/ComputeSharp/Graphics/Commands/CommandList.cs index eb7e9d53..15381bbe 100644 --- a/src/ComputeSharp/Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp/Graphics/Commands/CommandList.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading.Tasks; using ComputeSharp.Core.Extensions; @@ -125,6 +126,7 @@ internal unsafe struct CommandList : IDisposable /// /// A double pointer to the current object to execute. [MethodImpl(MethodImplOptions.AggressiveInlining)] + [UnscopedRef] public readonly ref ID3D12CommandList* GetD3D12CommandListPinnableAddressOf() { // This method should return a ref ID3D12CommandList*, so it can't just call this.d3D12GraphicsCommandList.GetPinnableReference(). diff --git a/src/TerraFX.Interop.Windows/ComPtr`1.cs b/src/TerraFX.Interop.Windows/ComPtr`1.cs index dd8c38ab..9a218855 100644 --- a/src/TerraFX.Interop.Windows/ComPtr`1.cs +++ b/src/TerraFX.Interop.Windows/ComPtr`1.cs @@ -9,6 +9,7 @@ using System.Diagnostics; using System.Runtime.CompilerServices; using static TerraFX.Interop.Windows.Windows; using static TerraFX.Interop.Windows.S; +using System.Diagnostics.CodeAnalysis; namespace TerraFX.Interop.Windows { @@ -248,12 +249,10 @@ namespace TerraFX.Interop.Windows /// The raw pointer to the current instance. [MethodImpl(MethodImplOptions.AggressiveInlining)] [EditorBrowsable(EditorBrowsableState.Never)] + [UnscopedRef] public readonly ref T* GetPinnableReference() { - fixed (T** ptr = &ptr_) - { - return ref *ptr; - } + return ref Unsafe.AsRef(in this).ptr_; } /// Releases the current COM object in use and gets the address of the instance as a raw double pointer. This method is only valid when the current instance is on the stack or pinned.