From cb0268286ebad757b2b4e6c60c6f0c97d2bdc394 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 25 Feb 2021 19:42:52 +0100 Subject: [PATCH] Minor rebase fixes --- src/ComputeSharp/ComputeSharp.csproj | 12 ++- .../Extensions/Interop/AllocatorExtensions.cs | 2 +- .../Graphics/Interop/AllocationPtr.cs | 93 ------------------- .../Graphics/Interop/AllocatorPtr.cs | 81 ---------------- 4 files changed, 9 insertions(+), 179 deletions(-) delete mode 100644 src/ComputeSharp/Graphics/Interop/AllocationPtr.cs delete mode 100644 src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index c35b06c5..eb294ea0 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -7,10 +7,14 @@ ComputeSharp - - - - + + + + + + + + - /// A -equivalent type to safely work with pointers. - /// - /// - /// While this type is not marked as so that it can also be used in fields, make sure to - /// keep the reference counts properly tracked if you do store instances on the heap. - /// - internal unsafe struct AllocationPtr : IDisposable - { - /// - /// The raw pointer to an object, if existing. - /// - private Allocation* pointer; - - /// - /// Creates a new instance from a raw pointer. - /// - /// The raw pointer to wrap. - public AllocationPtr(Allocation* other) - { - pointer = other; - } - - /// - /// Unwraps a instance and returns the internal raw pointer. - /// - /// The instance to unwrap. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Allocation*(AllocationPtr other) - { - return other.Get(); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dispose() - { - Allocation* pointer = this.pointer; - - if (pointer != null) - { - this.pointer = null; - - pointer->Release(); - } - } - - /// - /// Gets the currently wrapped raw pointer to an object. - /// - /// The raw pointer wrapped by the current instance. - [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Allocation* Get() - { - return this.pointer; - } - - /// - /// Gets the address of the current instance as a raw double pointer. - /// This method is only valid when the current instance is on the stack or pinned. - /// - /// The raw pointer to the current instance. - [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Allocation** GetAddressOf() - { - return (Allocation**)Unsafe.AsPointer(ref Unsafe.AsRef(in this)); - } - - /// - /// Gets the address of the current instance as a raw double pointer. - /// - /// The raw pointer to the input instance. - /// This method is only valid when the current instance is on the stack or pinned. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public AllocationPtr Move() - { - AllocationPtr copy = this; - - this = default; - - return copy; - } - } -} diff --git a/src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs b/src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs deleted file mode 100644 index bee25d48..00000000 --- a/src/ComputeSharp/Graphics/Interop/AllocatorPtr.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.ComponentModel; -using System.Diagnostics.Contracts; -using System.Runtime.CompilerServices; -using TerraFX.Interop; - -namespace ComputeSharp.Graphics -{ - /// - /// A -equivalent type to safely work with pointers. - /// - /// - /// While this type is not marked as so that it can also be used in fields, make sure to - /// keep the reference counts properly tracked if you do store instances on the heap. - /// - internal unsafe struct AllocatorPtr : IDisposable - { - /// - /// The raw pointer to an object, if existing. - /// - private Allocator* pointer; - - /// - /// Creates a new instance from a raw pointer. - /// - /// The raw pointer to wrap. - public AllocatorPtr(Allocator* other) - { - pointer = other; - } - - /// - /// Unwraps a instance and returns the internal raw pointer. - /// - /// The instance to unwrap. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator Allocator*(AllocatorPtr other) - { - return other.Get(); - } - - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void Dispose() - { - Allocator* pointer = this.pointer; - - if (pointer != null) - { - this.pointer = null; - - pointer->Release(); - } - } - - /// - /// Gets the currently wrapped raw pointer to an object. - /// - /// The raw pointer wrapped by the current instance. - [Pure] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly Allocator* Get() - { - return this.pointer; - } - - /// - /// Gets the address of the current instance as a managed reference to pointer. - /// - /// The reference to the current instance. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - [EditorBrowsable(EditorBrowsableState.Never)] - public readonly ref Allocator* GetPinnableReference() - { - fixed (Allocator** ptr = &this.pointer) - { - return ref *ptr; - } - } - } -}