From 960ce21899ef6275588b740c68e612c6383ffd66 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 12 Oct 2023 22:03:02 +0200 Subject: [PATCH 1/3] Remove ComPtr.GetVoidAddressOf from DX12 projects --- .../Interop/ID3D12MemoryAllocatorImpl.cs | 3 +-- .../Shaders/Interop/ReflectionServices.cs | 4 ++-- .../Shaders/Translation/ShaderCompiler.cs | 4 ++-- .../Extensions/IDXGIAdapterExtensions.cs | 2 +- .../Extensions/Interop/ComPtrExtensions.cs | 18 ----------------- .../Interop/ID3D12DeviceExtensions.cs | 20 +++++++++---------- .../Helpers/DeviceHelper.Enumerator.cs | 8 ++++---- .../Helpers/DeviceHelper.ID3D12InfoQueue.cs | 3 +-- .../Helpers/DeviceHelper.IDXGIFactory6.cs | 6 +++--- .../Graphics/Helpers/DeviceHelper.cs | 8 ++++---- .../Graphics/Helpers/WICHelper.cs | 2 +- .../Interop/ID3D12DeviceExtensions.cs | 4 ++-- 12 files changed, 31 insertions(+), 51 deletions(-) diff --git a/src/ComputeSharp.D3D12MemoryAllocator/Interop/ID3D12MemoryAllocatorImpl.cs b/src/ComputeSharp.D3D12MemoryAllocator/Interop/ID3D12MemoryAllocatorImpl.cs index eb601f4e..58471658 100644 --- a/src/ComputeSharp.D3D12MemoryAllocator/Interop/ID3D12MemoryAllocatorImpl.cs +++ b/src/ComputeSharp.D3D12MemoryAllocator/Interop/ID3D12MemoryAllocatorImpl.cs @@ -2,7 +2,6 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; -using ComputeSharp.Core.Extensions; using ComputeSharp.Interop.Allocation; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -199,7 +198,7 @@ internal unsafe struct ID3D12MemoryAllocatorImpl pOptimizedClearValue: null, ppAllocation: d3D12MA_allocation.GetAddressOf(), riidResource: Windows.__uuidof(), - ppvResource: d3D12Resource.GetVoidAddressOf()); + ppvResource: (void**)d3D12Resource.GetAddressOf()); if (!Windows.SUCCEEDED(hresult)) { diff --git a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs index 250ba163..8b8e0ced 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Interop/ReflectionServices.cs @@ -115,7 +115,7 @@ public static class ReflectionServices DirectX.DxcCreateInstance( (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcLibrary)), Windows.__uuidof(), - dxcUtils.GetVoidAddressOf()).Assert(); + (void**)dxcUtils.GetAddressOf()).Assert(); using ComPtr d3D12ShaderReflection = default; @@ -126,7 +126,7 @@ public static class ReflectionServices dxcUtils.Get()->CreateReflection( &dxcBuffer, Windows.__uuidof(), - d3D12ShaderReflection.GetVoidAddressOf()).Assert(); + (void**)d3D12ShaderReflection.GetAddressOf()).Assert(); D3D12_SHADER_DESC d3D12ShaderDescription; diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs index 7eac1c94..ff33ffde 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.cs @@ -46,12 +46,12 @@ internal sealed unsafe partial class ShaderCompiler DirectX.DxcCreateInstance( (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcCompiler)), Windows.__uuidof(), - dxcCompiler.GetVoidAddressOf()).Assert(); + (void**)dxcCompiler.GetAddressOf()).Assert(); DirectX.DxcCreateInstance( (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in CLSID.CLSID_DxcLibrary)), Windows.__uuidof(), - dxcLibrary.GetVoidAddressOf()).Assert(); + (void**)dxcLibrary.GetAddressOf()).Assert(); dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).Assert(); diff --git a/src/ComputeSharp.WinUI/Extensions/IDXGIAdapterExtensions.cs b/src/ComputeSharp.WinUI/Extensions/IDXGIAdapterExtensions.cs index 1d581f8a..5349e613 100644 --- a/src/ComputeSharp.WinUI/Extensions/IDXGIAdapterExtensions.cs +++ b/src/ComputeSharp.WinUI/Extensions/IDXGIAdapterExtensions.cs @@ -22,7 +22,7 @@ internal static unsafe class IDXGIAdapterExtensions { using ComPtr dxgiAdapter1 = default; - dxgiAdapter.QueryInterface(Win32.__uuidof(), dxgiAdapter1.GetVoidAddressOf()).Assert(); + dxgiAdapter.QueryInterface(Win32.__uuidof(), (void**)dxgiAdapter1.GetAddressOf()).Assert(); using ComPtr dxgiOutput = default; diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs index 7909fd04..916fa9c5 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs @@ -29,24 +29,6 @@ internal static class ComPtrExtensions return ref Unsafe.As, ComPtr>(ref Unsafe.AsRef(in ptr)); } - /// - /// Gets the address of the current instance as a raw double pointer. - /// - /// The type to wrap in the current instance. - /// The input instance to get the address for. - /// 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 static unsafe void** GetVoidAddressOf(this in ComPtr ptr) -#if NET6_0_OR_GREATER - where T : unmanaged, IUnknown.Interface -#else - where T : unmanaged -#endif - { - return (void**)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr)); - } - /// /// Moves the current instance and resets it without releasing the reference. /// diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs index c77fd2a2..cb9a7742 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ID3D12DeviceExtensions.cs @@ -80,7 +80,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12ResourceStates, null, Windows.__uuidof(), - d3D12Resource.GetVoidAddressOf()).Assert(); + (void**)d3D12Resource.GetAddressOf()).Assert(); return d3D12Resource.Move(); } @@ -140,7 +140,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12ResourceStates, null, Windows.__uuidof(), - d3D12Resource.GetVoidAddressOf()).Assert(); + (void**)d3D12Resource.GetAddressOf()).Assert(); return d3D12Resource.Move(); } @@ -202,7 +202,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12ResourceStates, null, Windows.__uuidof(), - d3D12Resource.GetVoidAddressOf()).Assert(); + (void**)d3D12Resource.GetAddressOf()).Assert(); return d3D12Resource.Move(); } @@ -266,7 +266,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12ResourceStates, null, Windows.__uuidof(), - d3D12Resource.GetVoidAddressOf()).Assert(); + (void**)d3D12Resource.GetAddressOf()).Assert(); return d3D12Resource.Move(); } @@ -281,7 +281,7 @@ internal static unsafe class ID3D12DeviceExtensions { ComPtr d3D12InfoQueue = default; - d3D12Device.QueryInterface(Windows.__uuidof(), d3D12InfoQueue.GetVoidAddressOf()).Assert(); + d3D12Device.QueryInterface(Windows.__uuidof(), (void**)d3D12InfoQueue.GetAddressOf()).Assert(); D3D12_MESSAGE_ID* d3D12MessageIds = stackalloc D3D12_MESSAGE_ID[3] { @@ -332,7 +332,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12Device.CreateCommandQueue( &d3D12CommandQueueDesc, Windows.__uuidof(), - d3D12CommandQueue.GetVoidAddressOf()).Assert(); + (void**)d3D12CommandQueue.GetAddressOf()).Assert(); return d3D12CommandQueue.Move(); } @@ -351,7 +351,7 @@ internal static unsafe class ID3D12DeviceExtensions 0, D3D12_FENCE_FLAG_NONE, Windows.__uuidof(), - d3D12Fence.GetVoidAddressOf()).Assert(); + (void**)d3D12Fence.GetAddressOf()).Assert(); return d3D12Fence.Move(); } @@ -377,7 +377,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12Device.CreateDescriptorHeap( &d3D12DescriptorHeapDesc, Windows.__uuidof(), - d3D12DescriptorHeap.GetVoidAddressOf()).Assert(); + (void**)d3D12DescriptorHeap.GetAddressOf()).Assert(); return d3D12DescriptorHeap.Move(); } @@ -545,7 +545,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12Device.CreateCommandAllocator( d3D12CommandListType, Windows.__uuidof(), - d3D12CommandAllocator.GetVoidAddressOf()).Assert(); + (void**)d3D12CommandAllocator.GetAddressOf()).Assert(); return d3D12CommandAllocator.Move(); } @@ -573,7 +573,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12CommandAllocator, d3D12PipelineState, Windows.__uuidof(), - d3D12GraphicsCommandList.GetVoidAddressOf()).Assert(); + (void**)d3D12GraphicsCommandList.GetAddressOf()).Assert(); return d3D12GraphicsCommandList.Move(); } diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs index 8e336831..df41949f 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs @@ -126,11 +126,11 @@ partial class DeviceHelper this.index, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, Windows.__uuidof(), - dxgiAdapter1.GetVoidAddressOf()); + (void**)dxgiAdapter1.GetAddressOf()); if (enumAdapters1Result == DXGI.DXGI_ERROR_NOT_FOUND) { - this.dxgiFactory6.Get()->EnumWarpAdapter(Windows.__uuidof(), dxgiAdapter1.GetVoidAddressOf()).Assert(); + this.dxgiFactory6.Get()->EnumWarpAdapter(Windows.__uuidof(), (void**)dxgiAdapter1.GetAddressOf()).Assert(); DXGI_ADAPTER_DESC1 dxgiDescription1; @@ -151,7 +151,7 @@ partial class DeviceHelper dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), - d3D12Device.GetVoidAddressOf()).Assert(); + (void**)d3D12Device.GetAddressOf()).Assert(); this.graphicsDevice = GetOrCreateDevice(d3D12Device.Get(), (IDXGIAdapter*)dxgiAdapter1.Get(), &dxgiDescription1); this.isCompleted = true; @@ -192,7 +192,7 @@ partial class DeviceHelper dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), - d3D12Device.GetVoidAddressOf()).Assert(); + (void**)d3D12Device.GetAddressOf()).Assert(); if (d3D12Device.Get()->IsShaderModelSupported(D3D_SHADER_MODEL_6_0)) { diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs index 6d51f371..0c190ede 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.ID3D12InfoQueue.cs @@ -3,7 +3,6 @@ using System.ComponentModel; using System.Diagnostics; using System.Runtime.InteropServices; using System.Text; -using ComputeSharp.Core.Extensions; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; using static TerraFX.Interop.DirectX.D3D12_MESSAGE_ID; @@ -105,7 +104,7 @@ partial class DeviceHelper // Get the DRED data int hresult = device.D3D12Device->QueryInterface( riid: Windows.__uuidof(), - ppvObject: d3D12DeviceRemovedExtendedData.GetVoidAddressOf()); + ppvObject: (void**)d3D12DeviceRemovedExtendedData.GetAddressOf()); default(Win32Exception).ThrowIfFailed(hresult); diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs index 71813ff1..4d8bf14d 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.IDXGIFactory6.cs @@ -44,7 +44,7 @@ partial class DeviceHelper using ComPtr dxgiFactory4 = default; - DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof(), dxgiFactory4.GetVoidAddressOf()).Assert(); + DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof(), (void**)dxgiFactory4.GetAddressOf()).Assert(); HRESULT result = dxgiFactory4.CopyTo(dxgiFactory6); @@ -73,7 +73,7 @@ partial class DeviceHelper using ComPtr d3D12Debug = default; using ComPtr d3D12Debug1 = default; - DirectX.D3D12GetDebugInterface(Windows.__uuidof(), d3D12Debug.GetVoidAddressOf()).Assert(); + DirectX.D3D12GetDebugInterface(Windows.__uuidof(), (void**)d3D12Debug.GetAddressOf()).Assert(); d3D12Debug.Get()->EnableDebugLayer(); @@ -93,7 +93,7 @@ partial class DeviceHelper DirectX.D3D12GetDebugInterface( riid: Windows.__uuidof(), - ppvDebug: d3D12DeviceRemovedExtendedDataSettings.GetVoidAddressOf()).Assert(); + ppvDebug: (void**)d3D12DeviceRemovedExtendedDataSettings.GetAddressOf()).Assert(); // Enable the auto-breadcrumbs and page faults reporting d3D12DeviceRemovedExtendedDataSettings.Get()->SetAutoBreadcrumbsEnablement(D3D12_DRED_ENABLEMENT.D3D12_DRED_ENABLEMENT_FORCED_ON); diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs index 5e008830..2bd3540e 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs @@ -71,7 +71,7 @@ internal static partial class DeviceHelper i++, DXGI_GPU_PREFERENCE_HIGH_PERFORMANCE, Windows.__uuidof(), - dxgiAdapter1.GetVoidAddressOf()); + (void**)dxgiAdapter1.GetAddressOf()); if (enumAdapters1Result == DXGI.DXGI_ERROR_NOT_FOUND) { @@ -101,7 +101,7 @@ internal static partial class DeviceHelper dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), - d3D12DeviceCandidate.GetVoidAddressOf()); + (void**)d3D12DeviceCandidate.GetAddressOf()); // Check and throw if the device is a device lost state and not disposed properly default(InvalidOperationException).ThrowIf(createDeviceResult.IsDeviceLostReason()); @@ -135,7 +135,7 @@ internal static partial class DeviceHelper using ComPtr dxgiAdapter1 = default; - dxgiFactory6.Get()->EnumWarpAdapter(Windows.__uuidof(), dxgiAdapter1.GetVoidAddressOf()).Assert(); + dxgiFactory6.Get()->EnumWarpAdapter(Windows.__uuidof(), (void**)dxgiAdapter1.GetAddressOf()).Assert(); dxgiAdapter1.Get()->GetDesc1(dxgiDescription1).Assert(); @@ -145,7 +145,7 @@ internal static partial class DeviceHelper dxgiAdapter1.AsIUnknown().Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), - d3D12DeviceCandidate.GetVoidAddressOf()); + (void**)d3D12DeviceCandidate.GetAddressOf()); default(InvalidOperationException).ThrowIf(createDeviceResult.IsDeviceLostReason()); diff --git a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs index c1fde3b6..2fdca628 100644 --- a/src/ComputeSharp/Graphics/Helpers/WICHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/WICHelper.cs @@ -30,7 +30,7 @@ internal sealed unsafe class WICHelper null, (uint)CLSCTX.CLSCTX_INPROC_SERVER, Windows.__uuidof(), - wicImagingFactory2.GetVoidAddressOf()).Assert(); + (void**)wicImagingFactory2.GetAddressOf()).Assert(); this.wicImagingFactory2 = wicImagingFactory2.Move(); } diff --git a/src/ComputeSharp/Shaders/Extensions/Interop/ID3D12DeviceExtensions.cs b/src/ComputeSharp/Shaders/Extensions/Interop/ID3D12DeviceExtensions.cs index e93441c7..3cb499f6 100644 --- a/src/ComputeSharp/Shaders/Extensions/Interop/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp/Shaders/Extensions/Interop/ID3D12DeviceExtensions.cs @@ -83,7 +83,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D3Blob.Get()->GetBufferPointer(), d3D3Blob.Get()->GetBufferSize(), Windows.__uuidof(), - d3D12RootSignature.GetVoidAddressOf()).Assert(); + (void**)d3D12RootSignature.GetAddressOf()).Assert(); return d3D12RootSignature.Move(); } @@ -113,7 +113,7 @@ internal static unsafe class ID3D12DeviceExtensions d3D12Device.CreateComputePipelineState( &d3D12ComputePipelineStateDescription, Windows.__uuidof(), - d3D12PipelineState.GetVoidAddressOf()).Assert(); + (void**)d3D12PipelineState.GetAddressOf()).Assert(); return d3D12PipelineState.Move(); } From e89433da46343a72ef9dc5a724e502b9d3b79eb7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 12 Oct 2023 22:03:10 +0200 Subject: [PATCH 2/3] Remove ComPtr.GetVoidAddressOf from D2D1 projects --- .../Extensions/ICanvasDeviceExtensions.cs | 4 ++-- .../Extensions/IUnknownExtensions.cs | 4 ++-- .../Extensions/ComPtrExtensions.cs | 14 -------------- .../Shaders/Interop/D2D1ReflectionServices.cs | 4 ++-- .../Extensions/ID2D1EffectContextExtensions.cs | 3 +-- 5 files changed, 7 insertions(+), 22 deletions(-) diff --git a/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs b/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs index cf59c1f5..43d57c5e 100644 --- a/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs +++ b/src/ComputeSharp.D2D1.WinUI/Extensions/ICanvasDeviceExtensions.cs @@ -24,7 +24,7 @@ internal static unsafe class ICanvasDeviceExtensions // Get the ICanvasResourceWrapperNative wrapper around the input device canvasDevice.QueryInterface( riid: Win32.__uuidof(), - ppvObject: canvasDeviceResourceWrapperNative.GetVoidAddressOf()).Assert(); + ppvObject: (void**)canvasDeviceResourceWrapperNative.GetAddressOf()).Assert(); // Get the underlying ID2D1Device1 instance in use HRESULT hresult = canvasDeviceResourceWrapperNative.Get()->GetNativeResource( @@ -61,7 +61,7 @@ internal static unsafe class ICanvasDeviceExtensions // Get the ID2D1DeviceContextPool interface reference canvasDevice.QueryInterface( riid: Win32.__uuidof(), - ppvObject: d2D1DeviceContextPool.GetVoidAddressOf()).Assert(); + ppvObject: (void**)d2D1DeviceContextPool.GetAddressOf()).Assert(); // Get a new ID2D1DeviceContextLease object from the retrieved pool d2D1DeviceContextPool.Get()->GetDeviceContextLease(d2D1DeviceContextLease).Assert(); diff --git a/src/ComputeSharp.D2D1.WinUI/Extensions/IUnknownExtensions.cs b/src/ComputeSharp.D2D1.WinUI/Extensions/IUnknownExtensions.cs index 8166a47c..54e8527a 100644 --- a/src/ComputeSharp.D2D1.WinUI/Extensions/IUnknownExtensions.cs +++ b/src/ComputeSharp.D2D1.WinUI/Extensions/IUnknownExtensions.cs @@ -35,8 +35,8 @@ internal static unsafe class IUnknownExtensions using ComPtr leftUnknown = default; using ComPtr rightUnknown = default; - ((IUnknown*)Unsafe.AsPointer(ref left))->QueryInterface(Win32.__uuidof(), leftUnknown.GetVoidAddressOf()).Assert(); - ((IUnknown*)right)->QueryInterface(Win32.__uuidof(), rightUnknown.GetVoidAddressOf()).Assert(); + ((IUnknown*)Unsafe.AsPointer(ref left))->QueryInterface(Win32.__uuidof(), (void**)leftUnknown.GetAddressOf()).Assert(); + ((IUnknown*)right)->QueryInterface(Win32.__uuidof(), (void**)rightUnknown.GetAddressOf()).Assert(); return leftUnknown.Get() == rightUnknown.Get(); } diff --git a/src/ComputeSharp.D2D1/Extensions/ComPtrExtensions.cs b/src/ComputeSharp.D2D1/Extensions/ComPtrExtensions.cs index 43613112..067b72d2 100644 --- a/src/ComputeSharp.D2D1/Extensions/ComPtrExtensions.cs +++ b/src/ComputeSharp.D2D1/Extensions/ComPtrExtensions.cs @@ -9,20 +9,6 @@ namespace ComputeSharp.D2D1.Extensions; /// Trimmed down version of the same file in ComputeSharp. internal static class ComPtrExtensions { - /// - /// Gets the address of the current instance as a raw double pointer. - /// - /// The type to wrap in the current instance. - /// The input instance to get the address for. - /// 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 static unsafe void** GetVoidAddressOf(this in ComPtr ptr) - where T : unmanaged - { - return (void**)Unsafe.AsPointer(ref Unsafe.AsRef(in ptr)); - } - /// /// Moves the current instance and resets it without releasing the reference. /// diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs index 2141af17..7d478063 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/D2D1ReflectionServices.cs @@ -44,7 +44,7 @@ public static class D2D1ReflectionServices pSrcData: hlslBytecodePtr, SrcDataSize: (nuint)hlslBytecode.Length, pInterface: Windows.__uuidof(), - ppReflector: d3D11ShaderReflection.GetVoidAddressOf()).Assert(); + ppReflector: (void**)d3D11ShaderReflection.GetAddressOf()).Assert(); } } else @@ -59,7 +59,7 @@ public static class D2D1ReflectionServices pSrcData: (byte*)dynamicBytecode.Get()->GetBufferPointer(), SrcDataSize: dynamicBytecode.Get()->GetBufferSize(), pInterface: Windows.__uuidof(), - ppReflector: d3D11ShaderReflection.GetVoidAddressOf()).Assert(); + ppReflector: (void**)d3D11ShaderReflection.GetAddressOf()).Assert(); } D3D11_SHADER_DESC d3D11ShaderDescription; diff --git a/src/ComputeSharp.D2D1/Shaders/Interop/Extensions/ID2D1EffectContextExtensions.cs b/src/ComputeSharp.D2D1/Shaders/Interop/Extensions/ID2D1EffectContextExtensions.cs index a9148353..a96347e7 100644 --- a/src/ComputeSharp.D2D1/Shaders/Interop/Extensions/ID2D1EffectContextExtensions.cs +++ b/src/ComputeSharp.D2D1/Shaders/Interop/Extensions/ID2D1EffectContextExtensions.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.CompilerServices; -using ComputeSharp.D2D1.Extensions; using TerraFX.Interop.DirectX; using TerraFX.Interop.Windows; @@ -89,7 +88,7 @@ internal static unsafe class ID2D1EffectContextExtensions pSrcData: bytecode, SrcDataSize: (uint)bytecodeSize, pInterface: Windows.__uuidof(), - ppReflector: d3D11ShaderReflection.GetVoidAddressOf()); + ppReflector: (void**)d3D11ShaderReflection.GetAddressOf()); if (!Windows.SUCCEEDED(hresult)) { From 9dae753625846e106027e00ce2a592588022952b Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 12 Oct 2023 22:05:47 +0200 Subject: [PATCH 3/3] Remove ComPtr.AsIUnknown extension --- .../Extensions/Interop/ComPtrExtensions.cs | 21 ------------------- .../Helpers/DeviceHelper.Enumerator.cs | 8 +++---- .../Graphics/Helpers/DeviceHelper.cs | 4 ++-- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs index 916fa9c5..fed3d8e3 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/ComPtrExtensions.cs @@ -8,27 +8,6 @@ namespace ComputeSharp.Core.Extensions; /// internal static class ComPtrExtensions { - /// - /// Reinterprets the current instance as one of type . - /// - /// The type of the current instance. - /// The input instance to upcast. - /// A instance of type . - /// - /// This method is meant to be used in a chained expression and it does not increment the reference - /// count for the input pointer. Do not expose the return value of this extension to consumers. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe ref readonly ComPtr AsIUnknown(this in ComPtr ptr) -#if NET6_0_OR_GREATER - where T : unmanaged, IUnknown.Interface -#else - where T : unmanaged -#endif - { - return ref Unsafe.As, ComPtr>(ref Unsafe.AsRef(in ptr)); - } - /// /// Moves the current instance and resets it without releasing the reference. /// diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs index df41949f..06974338 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.Enumerator.cs @@ -137,7 +137,7 @@ partial class DeviceHelper dxgiAdapter1.Get()->GetDesc1(&dxgiDescription1).Assert(); HRESULT createDeviceResult = DirectX.D3D12CreateDevice( - dxgiAdapter1.AsIUnknown().Get(), + (IUnknown*)dxgiAdapter1.Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), null); @@ -148,7 +148,7 @@ partial class DeviceHelper using ComPtr d3D12Device = default; DirectX.D3D12CreateDevice( - dxgiAdapter1.AsIUnknown().Get(), + (IUnknown*)dxgiAdapter1.Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), (void**)d3D12Device.GetAddressOf()).Assert(); @@ -178,7 +178,7 @@ partial class DeviceHelper } HRESULT createDeviceResult = DirectX.D3D12CreateDevice( - dxgiAdapter1.AsIUnknown().Get(), + (IUnknown*)dxgiAdapter1.Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), null); @@ -189,7 +189,7 @@ partial class DeviceHelper using ComPtr d3D12Device = default; DirectX.D3D12CreateDevice( - dxgiAdapter1.AsIUnknown().Get(), + (IUnknown*)dxgiAdapter1.Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), (void**)d3D12Device.GetAddressOf()).Assert(); diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs index 2bd3540e..c97e1b76 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs @@ -98,7 +98,7 @@ internal static partial class DeviceHelper // 3) The call fails for other reasons. In this case the adapter is simply skipped. // This might be the case if an adapter doesn't support the requested feature level. HRESULT createDeviceResult = DirectX.D3D12CreateDevice( - dxgiAdapter1.AsIUnknown().Get(), + (IUnknown*)dxgiAdapter1.Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), (void**)d3D12DeviceCandidate.GetAddressOf()); @@ -142,7 +142,7 @@ internal static partial class DeviceHelper using ComPtr d3D12DeviceCandidate = default; HRESULT createDeviceResult = DirectX.D3D12CreateDevice( - dxgiAdapter1.AsIUnknown().Get(), + (IUnknown*)dxgiAdapter1.Get(), D3D_FEATURE_LEVEL_11_0, Windows.__uuidof(), (void**)d3D12DeviceCandidate.GetAddressOf());