diff --git a/src/ComputeSharp.Graphics/GraphicsDevice.cs b/src/ComputeSharp.Graphics/GraphicsDevice.cs
index e685f8e9..1c7ae3c4 100644
--- a/src/ComputeSharp.Graphics/GraphicsDevice.cs
+++ b/src/ComputeSharp.Graphics/GraphicsDevice.cs
@@ -203,6 +203,8 @@ namespace ComputeSharp.Graphics
///
protected override void OnDispose()
{
+ if (DeviceHelper.GetDefaultDeviceLuid() == Luid) return;
+
DeviceHelper.NotifyDisposedDevice(this);
this.d3D12Device.Dispose();
diff --git a/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs b/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs
index 7ec594d3..4ea257dc 100644
--- a/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs
+++ b/src/ComputeSharp.Graphics/GraphicsDeviceInfo.cs
@@ -13,7 +13,7 @@ namespace ComputeSharp.Graphics
/// The available info for the associate device.
internal unsafe GraphicsDeviceInfo(DXGI_ADAPTER_DESC1* dxgiDescription1)
{
- Luid = *(Luid*)&dxgiDescription1->AdapterLuid;
+ Luid = Luid.FromLUID(dxgiDescription1->AdapterLuid);
Name = new string((char*)dxgiDescription1->Description);
MemorySize = dxgiDescription1->DedicatedVideoMemory;
}
diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
index f8d6982e..23842348 100644
--- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
+++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
@@ -26,6 +26,21 @@ namespace ComputeSharp.Graphics.Helpers
return TryGetDefaultDevice(null, &dxgiDescription1);
}
+ ///
+ /// Gets the of the default device.
+ ///
+ /// The of the default device supporting at least DX12.0.
+ /// This methods assumes that a default device is available.
+ [Pure]
+ public static unsafe Luid GetDefaultDeviceLuid()
+ {
+ DXGI_ADAPTER_DESC1 dxgiDescription1;
+
+ _ = TryGetDefaultDevice(null, &dxgiDescription1);
+
+ return Luid.FromLUID(dxgiDescription1.AdapterLuid);
+ }
+
///
/// Gets the default instance.
///