diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs new file mode 100644 index 00000000..c7052482 --- /dev/null +++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using System.Diagnostics.Contracts; +using SharpDX.DXGI; +using Device = SharpDX.Direct3D12.Device; + +namespace ComputeSharp.Graphics.Helpers +{ + /// + /// A with methods to inspect the available devices on the current machine + /// + public static class DeviceHelper + { + /// + /// Gets a collection of all the supported devices on the current machine + /// + /// The collection of objects with support for DX12.1 + [Pure] + public static IReadOnlyList QueryAllSupportedDevices() + { + using Factory factory = new Factory1(); + List devices = new List(); + + foreach (Adapter adapter in factory.Adapters) + { + if (adapter.Description.DedicatedVideoMemory == 0) continue; + try + { + Device device = new Device(adapter, GraphicsDevice.FeatureLevel); + devices.Add(device); + } + catch + { + // Unsupported device + } + } + + return devices; + } + } +} diff --git a/src/ComputeSharp/Gpu.cs b/src/ComputeSharp/Gpu.cs index 960b115c..ad3e247f 100644 --- a/src/ComputeSharp/Gpu.cs +++ b/src/ComputeSharp/Gpu.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Diagnostics.Contracts; using System.Linq; using ComputeSharp.Graphics; -using SharpDX.DXGI; +using ComputeSharp.Graphics.Helpers; using Device = SharpDX.Direct3D12.Device; namespace ComputeSharp @@ -16,7 +16,7 @@ namespace ComputeSharp /// /// 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 = QueryAllSupportedDevices()).Any(); + public static bool IsSupported { get; } = (_Devices = DeviceHelper.QueryAllSupportedDevices()).Any(); private static GraphicsDevice _Default; @@ -42,32 +42,5 @@ namespace ComputeSharp // The loaded collection of supported devices private static IReadOnlyList _Devices; - - /// - /// Gets a collection of all the supported devices on the current machine - /// - /// The collection of objects with support for DX12.1 - [Pure] - private static IReadOnlyList QueryAllSupportedDevices() - { - using Factory factory = new Factory1(); - List devices = new List(); - - foreach (Adapter adapter in factory.Adapters) - { - if (adapter.Description.DedicatedVideoMemory == 0) continue; - try - { - Device device = new Device(adapter, GraphicsDevice.FeatureLevel); - devices.Add(device); - } - catch - { - // Unsupported device - } - } - - return devices; - } } }