From 62d81ad03f5b3bd3a2cf28ff4af3d06b670ec75f Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 8 Oct 2023 20:41:16 +0200 Subject: [PATCH] Remove implicit ComPtr operators --- .../Extensions/ICanvasDeviceExtensions.cs | 2 +- ...ixelShaderEffect.ID2D1EffectImplMethods.cs | 2 +- .../Effects/PixelShaderEffect.Properties.cs | 6 +++--- .../Shaders/Translation/ShaderCompiler.cs | 2 +- .../Helpers/SwapChainManager.cs | 2 +- .../Graphics/Commands/CommandList.cs | 4 ++-- .../ID3D12DescriptorHandleAllocator.cs | 2 +- .../Graphics/GraphicsDevice.Execute.cs | 8 ++++---- .../Graphics/GraphicsDevice.Resources.cs | 8 ++++---- .../Graphics/Resources/Abstract/Buffer{T}.cs | 2 +- .../Resources/Abstract/Texture1D{T}.cs | 2 +- .../Resources/Abstract/Texture2D{T}.cs | 2 +- .../Resources/Abstract/Texture3D{T}.cs | 2 +- .../Resources/Abstract/TransferBuffer{T}.cs | 2 +- .../Abstract/TransferTexture1D{T}.cs | 2 +- .../Abstract/TransferTexture2D{T}.cs | 2 +- .../Abstract/TransferTexture3D{T}.cs | 2 +- .../Shaders/Models/PipelineData.cs | 4 ++-- src/TerraFX.Interop.Windows/ComPtr`1.cs | 20 ------------------- 19 files changed, 28 insertions(+), 48 deletions(-) diff --git a/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs b/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs index ed84a11b..ab5a75e4 100644 --- a/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs +++ b/src/ComputeSharp.D2D1.UI/Extensions/ICanvasDeviceExtensions.cs @@ -77,7 +77,7 @@ internal static unsafe class ICanvasDeviceExtensions else { // Otherwise, just use the input device context - *d2D1DeviceContextEffective = new ComPtr(d2D1DeviceContext); + ComPtr.WriteTo(d2D1DeviceContext, out *d2D1DeviceContextEffective); } } } \ No newline at end of file diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs index befe939c..016291a9 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.ID2D1EffectImplMethods.cs @@ -153,7 +153,7 @@ internal unsafe partial struct PixelShaderEffect for (int i = 0; i < resourceTextureDescriptions.Length; i++) { - using ComPtr resourceTextureManager = @this->resourceTextureManagerBuffer[i]; + using ComPtr resourceTextureManager = new(@this->resourceTextureManagerBuffer[i]); // If the current resource texture manager is not set, we cannot render, as there's an unbound resource texture if (resourceTextureManager.Get() is null) diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs index a9aabc4c..33aed1bf 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Effects/PixelShaderEffect.Properties.cs @@ -244,7 +244,7 @@ unsafe partial struct PixelShaderEffect default(ArgumentNullException).ThrowIfNull(value); - using ComPtr unknown = (IUnknown*)value; + using ComPtr unknown = new((IUnknown*)value); using ComPtr transformMapper = default; // Check that the input object implements ID2D1TransformMapper @@ -280,7 +280,7 @@ unsafe partial struct PixelShaderEffect default(ArgumentOutOfRangeException).ThrowIfLessThan((int)dataSize, sizeof(void*), nameof(dataSize)); default(ArgumentOutOfRangeException).ThrowIfGreaterThanOrEqual(index, GetGlobals().ResourceTextureCount); - using ComPtr resourceTextureManager = this.resourceTextureManagerBuffer[index]; + using ComPtr resourceTextureManager = new(this.resourceTextureManagerBuffer[index]); resourceTextureManager.CopyTo((ID2D1ResourceTextureManager**)data).Assert(); @@ -316,7 +316,7 @@ unsafe partial struct PixelShaderEffect default(ArgumentNullException).ThrowIfNull(value); - using ComPtr unknown = (IUnknown*)value; + using ComPtr unknown = new((IUnknown*)value); using ComPtr resourceTextureManager = default; // Check that the input object implements ID2D1ResourceTextureManager diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs index 146c9e4f..4451830d 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs @@ -134,7 +134,7 @@ internal sealed unsafe partial class ShaderCompiler return dxcBlobBytecode.Move(); } - return ThrowHslsCompilationException(dxcOperationResult); + return ThrowHslsCompilationException(dxcOperationResult.Get()); } /// diff --git a/src/ComputeSharp.UI/Helpers/SwapChainManager.cs b/src/ComputeSharp.UI/Helpers/SwapChainManager.cs index a1894e3c..d2829172 100644 --- a/src/ComputeSharp.UI/Helpers/SwapChainManager.cs +++ b/src/ComputeSharp.UI/Helpers/SwapChainManager.cs @@ -337,7 +337,7 @@ internal sealed unsafe partial class SwapChainManager : ReferenceTracked this.d3D12Device.Get()->CreateCommandList( 0, D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_DIRECT, - this.d3D12CommandAllocator, + this.d3D12CommandAllocator.Get(), null, Win32.__uuidof(), (void**)d3D12GraphicsCommandList).Assert(); diff --git a/src/ComputeSharp/Graphics/Commands/CommandList.cs b/src/ComputeSharp/Graphics/Commands/CommandList.cs index 2544d0c1..c7d3c6d7 100644 --- a/src/ComputeSharp/Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp/Graphics/Commands/CommandList.cs @@ -55,7 +55,7 @@ internal unsafe struct CommandList : IDisposable // Set the heap descriptor if the command list is not for copy operations if (d3D12CommandListType is not D3D12_COMMAND_LIST_TYPE_COPY) { - device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList); + device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList.Get()); } } @@ -78,7 +78,7 @@ internal unsafe struct CommandList : IDisposable out this.d3D12CommandAllocator.GetPinnableReference()); // Set the heap descriptor for the command list - device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList); + device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList.Get()); } /// diff --git a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs index 00c94b3f..6a245080 100644 --- a/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs +++ b/src/ComputeSharp/Graphics/Commands/Interop/ID3D12DescriptorHandleAllocator.cs @@ -83,7 +83,7 @@ internal unsafe struct ID3D12DescriptorHandleAllocator : IDisposable /// /// Gets the in use for the current instance. /// - public readonly ID3D12DescriptorHeap* D3D12DescriptorHeap => this.d3D12DescriptorHeap; + public readonly ID3D12DescriptorHeap* D3D12DescriptorHeap => this.d3D12DescriptorHeap.Get(); /// /// Rents a new bundle of CPU and GPU handles to use in a resource. diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs b/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs index 897a7ce3..e51e42c6 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.Execute.cs @@ -49,14 +49,14 @@ unsafe partial class GraphicsDevice { case D3D12_COMMAND_LIST_TYPE_COMPUTE: commandListPool = ref this.computeCommandListPool; - d3D12CommandQueue = this.d3D12ComputeCommandQueue; - d3D12Fence = this.d3D12ComputeFence; + d3D12CommandQueue = this.d3D12ComputeCommandQueue.Get(); + d3D12Fence = this.d3D12ComputeFence.Get(); d3D12FenceValue = ref this.nextD3D12ComputeFenceValue; break; case D3D12_COMMAND_LIST_TYPE_COPY: commandListPool = ref this.copyCommandListPool; - d3D12CommandQueue = this.d3D12CopyCommandQueue; - d3D12Fence = this.d3D12CopyFence; + d3D12CommandQueue = this.d3D12CopyCommandQueue.Get(); + d3D12Fence = this.d3D12CopyFence.Get(); d3D12FenceValue = ref this.nextD3D12CopyFenceValue; break; default: default(ArgumentException).Throw(nameof(commandList)); return; diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.Resources.cs b/src/ComputeSharp/Graphics/GraphicsDevice.Resources.cs index 24cfa1a5..3a0f89a7 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.Resources.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.Resources.cs @@ -31,7 +31,7 @@ unsafe partial class GraphicsDevice } else { - allocation = null; + allocation = default; d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource(resourceType, sizeInBytes, IsCacheCoherentUMA); } } @@ -68,7 +68,7 @@ unsafe partial class GraphicsDevice } else { - allocation = null; + allocation = default; d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource( resourceType, @@ -114,7 +114,7 @@ unsafe partial class GraphicsDevice } else { - allocation = null; + allocation = default; d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource( resourceType, @@ -164,7 +164,7 @@ unsafe partial class GraphicsDevice } else { - allocation = null; + allocation = default; d3D12Resource = this.d3D12Device.Get()->CreateCommittedResource( resourceType, diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs index 55006d31..4cf4dfee 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Buffer{T}.cs @@ -150,7 +150,7 @@ public abstract unsafe partial class Buffer : IReferenceTrackedObject, IGraph /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the instance for the current resource. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture1D{T}.cs index ac6372e2..e9f025da 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture1D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture1D{T}.cs @@ -135,7 +135,7 @@ public abstract unsafe partial class Texture1D : IReferenceTrackedObject, IGr /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the instance for the current resource. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs index 5aa0b7ac..e95ff83f 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture2D{T}.cs @@ -144,7 +144,7 @@ public abstract unsafe partial class Texture2D : IReferenceTrackedObject, IGr /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the instance for the current resource. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs index 03692f34..18077312 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/Texture3D{T}.cs @@ -153,7 +153,7 @@ public abstract unsafe partial class Texture3D : IReferenceTrackedObject, IGr /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the instance for the current resource. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs index fb1f8d02..bfe72475 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferBuffer{T}.cs @@ -95,7 +95,7 @@ public abstract unsafe partial class TransferBuffer : IReferenceTrackedObject /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the pointer to the start of the mapped buffer data. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs index 1a41b43a..f2195d9c 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture1D{T}.cs @@ -100,7 +100,7 @@ public abstract unsafe partial class TransferTexture1D : IReferenceTrackedObj /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the value for the current resource. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs index 790b4515..f0c2d780 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture2D{T}.cs @@ -107,7 +107,7 @@ public abstract unsafe partial class TransferTexture2D : IReferenceTrackedObj /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the value for the current resource. diff --git a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs index 26caf240..e1df8a3d 100644 --- a/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Abstract/TransferTexture3D{T}.cs @@ -115,7 +115,7 @@ public abstract unsafe partial class TransferTexture3D : IReferenceTrackedObj /// /// Gets the instance currently mapped. /// - internal ID3D12Resource* D3D12Resource => this.d3D12Resource; + internal ID3D12Resource* D3D12Resource => this.d3D12Resource.Get(); /// /// Gets the value for the current resource. diff --git a/src/ComputeSharp/Shaders/Models/PipelineData.cs b/src/ComputeSharp/Shaders/Models/PipelineData.cs index b00f6762..617fac35 100644 --- a/src/ComputeSharp/Shaders/Models/PipelineData.cs +++ b/src/ComputeSharp/Shaders/Models/PipelineData.cs @@ -35,12 +35,12 @@ internal sealed unsafe class PipelineData : ReferenceTrackedObject /// /// Gets the instance for the current object. /// - public ID3D12RootSignature* D3D12RootSignature => this.d3D12RootSignature; + public ID3D12RootSignature* D3D12RootSignature => this.d3D12RootSignature.Get(); /// /// Gets the instance for the current object. /// - public ID3D12PipelineState* D3D12PipelineState => this.d3D12PipelineState; + public ID3D12PipelineState* D3D12PipelineState => this.d3D12PipelineState.Get(); /// protected override void DangerousOnDispose() diff --git a/src/TerraFX.Interop.Windows/ComPtr`1.cs b/src/TerraFX.Interop.Windows/ComPtr`1.cs index e06aae5a..092aa947 100644 --- a/src/TerraFX.Interop.Windows/ComPtr`1.cs +++ b/src/TerraFX.Interop.Windows/ComPtr`1.cs @@ -98,26 +98,6 @@ internal unsafe struct ComPtr : IDisposable InternalAddRef(); } - /// Creates a new instance from a second one and increments the ref count. - /// The other instance to copy. - public ComPtr(ComPtr other) - { - ptr_ = other.ptr_; - InternalAddRef(); - } - - /// Converts a raw pointer to a new instance and increments the ref count. - /// The raw pointer to wrap. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator ComPtr(T* other) - => new ComPtr(other); - - /// Unwraps a instance and returns the internal raw pointer. - /// The instance to unwrap. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static implicit operator T*(ComPtr other) - => other.Get(); - /// Converts the current object reference to type and assigns that to a target value. /// The interface type to use to try casting the current COM object. /// A raw pointer to the target value to write to.