using System.Collections.Generic;
using System.Diagnostics.Contracts;
using Vortice.Direct3D;
using Vortice.Direct3D12;
using Vortice.DXGI;
namespace ComputeSharp.Graphics.Helpers
{
///
/// A with methods to inspect the available devices on the current machine
///
internal 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<(ID3D12Device, AdapterDescription)> QueryAllSupportedDevices()
{
if (!DXGI.CreateDXGIFactory1(out IDXGIFactory1 factory).Success) return new (ID3D12Device, AdapterDescription)[0];
try
{
List<(ID3D12Device, AdapterDescription)> devices = new List<(ID3D12Device, AdapterDescription)>();
foreach (IDXGIAdapter1 adapter in factory.Adapters1)
{
if (adapter.Description.DedicatedVideoMemory == 0) continue;
if (D3D12.D3D12CreateDevice(adapter, FeatureLevel.Level_12_0, out ID3D12Device device).Success)
devices.Add((device, adapter.Description));
}
return devices;
}
finally
{
// Explicit using statement
factory?.Dispose();
}
}
}
}