diff --git a/src/ComputeSharp.Graphics/Extensions/ComPtrExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ComPtrExtensions.cs
index 474b30d0..c21a29bb 100644
--- a/src/ComputeSharp.Graphics/Extensions/ComPtrExtensions.cs
+++ b/src/ComputeSharp.Graphics/Extensions/ComPtrExtensions.cs
@@ -9,6 +9,24 @@ namespace ComputeSharp.Core.Extensions
///
public 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.
+ ///
+ [Pure]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static unsafe ref readonly ComPtr AsIUnknown(this in ComPtr ptr)
+ where T : unmanaged
+ {
+ return ref Unsafe.As, ComPtr>(ref Unsafe.AsRef(in ptr));
+ }
+
///
/// Gets the address of the current instance as a raw double pointer.
///
diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs
index 76f73c32..e2368d46 100644
--- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs
+++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs
@@ -123,7 +123,7 @@ namespace ComputeSharp.Graphics.Helpers
if (dxgiDescription1.DedicatedVideoMemory == 0) continue;
HRESULT createDeviceResult = FX.D3D12CreateDevice(
- dxgiAdapter1.Upcast().Get(),
+ dxgiAdapter1.AsIUnknown().Get(),
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0,
FX.__uuidof(),
null);
@@ -134,7 +134,7 @@ namespace ComputeSharp.Graphics.Helpers
using ComPtr d3d12device = default;
FX.D3D12CreateDevice(
- dxgiAdapter1.Upcast().Get(),
+ dxgiAdapter1.AsIUnknown().Get(),
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0,
FX.__uuidof(),
d3d12device.GetVoidAddressOf()).Assert();
diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
index 67fc7188..61e90d91 100644
--- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
+++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
@@ -94,7 +94,7 @@ namespace ComputeSharp.Graphics.Helpers
if (dxgiDescription1->DedicatedVideoMemory == 0) continue;
HRESULT createDeviceResult = FX.D3D12CreateDevice(
- dxgiAdapter1.Upcast().Get(),
+ dxgiAdapter1.AsIUnknown().Get(),
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0,
FX.__uuidof(),
(void**)d3d12device);