Added Gpu.QueryAll method to list all available GPUs

このコミットが含まれているのは:
Sergio Pedri committed 2019-08-13 12:13:59 +02:00
1 親 a93bcc807c
コミット 17ea1a0f71
2ファイル変更
+58 -5

検索条件に一致するファイルはありません

+36 -3
ファイルの表示
@@ -2,6 +2,8 @@
using System.Threading;
using SharpDX.Direct3D;
using SharpDX.Direct3D12;
using SharpDX.DXGI;
using Device = SharpDX.Direct3D12.Device;
namespace ComputeSharp.Graphics
{
@@ -9,12 +11,21 @@ namespace ComputeSharp.Graphics
{
private readonly AutoResetEvent fenceEvent = new AutoResetEvent(false);
public GraphicsDevice(bool enableDebugLayer = false)
/// <summary>
/// Creates a new <see cref="GraphicsDevice"/> instance for the default GPU on the current machine
/// </summary>
public GraphicsDevice() : this(new Device(null, FeatureLevel)) { }
/// <summary>
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="Device"/>
/// </summary>
/// <param name="device">The <see cref="Device"/> to use for the new <see cref="GraphicsDevice"/> instance</param>
private GraphicsDevice(Device device)
{
#if DEBUG
if (enableDebugLayer) DebugInterface.Get().EnableDebugLayer();
DebugInterface.Get().EnableDebugLayer();
#endif
NativeDevice = new Device(null, FeatureLevel);
NativeDevice = device;
WavefrontSize = NativeDevice.D3D12Options1.WaveLaneCountMin;
NativeComputeCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Compute));
@@ -41,6 +52,28 @@ namespace ComputeSharp.Graphics
CopyCommandList.Close();
}
/// <summary>
/// Tries to create a new <see cref="GraphicsDevice"/> instance from the input <see cref="Adapter"/> object
/// </summary>
/// <param name="adapter">The input <see cref="Adapter"/> for the current GPU being targeted</param>
/// <param name="result">The resulting <see cref="GraphicsDevice"/> value, in case of success</param>
/// <returns>A <see langword="bool"/> value indicating whether or not the resulting device was created correctly</returns>
public static bool TryGetFromAdapter(Adapter adapter, out GraphicsDevice? result)
{
try
{
Device device = new Device(adapter, FeatureLevel);
result = new GraphicsDevice(device);
return true;
}
catch
{
result = null;
return false;
}
}
/// <summary>
/// Gets the number of lanes in a SIMD wave on the current device (also known as "wavefront size" or "warp width")
/// </summary>
+22 -2
ファイルの表示
@@ -1,4 +1,7 @@
using ComputeSharp.Graphics;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using ComputeSharp.Graphics;
using SharpDX.DXGI;
namespace ComputeSharp
{
@@ -12,6 +15,23 @@ namespace ComputeSharp
/// <summary>
/// Gets the default <see cref="GraphicsDevice"/> instance for the current machine
/// </summary>
public static GraphicsDevice Default => _Default ??= new GraphicsDevice(true);
public static GraphicsDevice Default => _Default ??= new GraphicsDevice();
/// <summary>
/// Gets a collection of all the supported graphics devices on the current machine
/// </summary>
/// <returns>The collection of <see cref="GraphicsDevice"/> objects with support for DX12.1</returns>
[Pure]
public static IReadOnlyList<GraphicsDevice> QueryAll()
{
using Factory factory = new Factory1();
List<GraphicsDevice> devices = new List<GraphicsDevice>();
foreach (Adapter adapter in factory.Adapters)
if (GraphicsDevice.TryGetFromAdapter(adapter, out GraphicsDevice? device))
devices.Add(device!);
return devices;
}
}
}