diff --git a/src/ComputeSharp/Gpu.cs b/src/ComputeSharp/Gpu.cs
index 79520bcf..75507597 100644
--- a/src/ComputeSharp/Gpu.cs
+++ b/src/ComputeSharp/Gpu.cs
@@ -14,15 +14,24 @@ namespace ComputeSharp
///
public static class Gpu
{
+ ///
+ /// Initializes the field and property
+ ///
+ static Gpu()
+ {
+ Devices = DeviceHelper.QueryAllSupportedDevices();
+ IsSupported = Devices.Any();
+ }
+
///
/// The loaded collection of supported devices and descriptions
///
- private static IReadOnlyList<(ID3D12Device Device, AdapterDescription Description)>? _Devices;
+ private static readonly IReadOnlyList<(ID3D12Device Device, AdapterDescription Description)> Devices;
///
/// Gets whether or not the APIs can be used on the current machine (ie. if there is at least a supported GPU device)
///
- public static bool IsSupported { get; } = (_Devices = DeviceHelper.QueryAllSupportedDevices()).Any();
+ public static bool IsSupported { get; }
private static GraphicsDevice? _Default;
@@ -35,7 +44,7 @@ namespace ComputeSharp
{
if (!IsSupported) throw new NotSupportedException("There isn't a supported GPU device on the current machine");
- return _Default ??= new GraphicsDevice(_Devices![0].Device, _Devices[0].Description);
+ return _Default ??= new GraphicsDevice(Devices[0].Device, Devices[0].Description);
}
}
@@ -44,6 +53,6 @@ namespace ComputeSharp
///
/// A sequence of supported objects that can be used to run compute shaders
[Pure]
- public static IEnumerable EnumerateDevices() => _Devices.Select(device => new GraphicsDevice(device.Device, device.Description));
+ public static IEnumerable EnumerateDevices() => Devices.Select(device => new GraphicsDevice(device.Device, device.Description));
}
}