Added new APIs to the GPU class
このコミットが含まれているのは:
1 親
17ea1a0f71
コミット
ac5ed0ed60
2ファイル変更
+45
-14
検索条件に一致するファイルはありません
@@ -11,16 +11,11 @@ namespace ComputeSharp.Graphics
|
||||
{
|
||||
private readonly AutoResetEvent fenceEvent = new AutoResetEvent(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)
|
||||
public GraphicsDevice(Device device)
|
||||
{
|
||||
#if DEBUG
|
||||
DebugInterface.Get().EnableDebugLayer();
|
||||
|
||||
+44
-8
@@ -1,7 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
using ComputeSharp.Graphics;
|
||||
using SharpDX.DXGI;
|
||||
using Device = SharpDX.Direct3D12.Device;
|
||||
|
||||
namespace ComputeSharp
|
||||
{
|
||||
@@ -10,26 +13,59 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
public static class Gpu
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether or not the <see cref="Gpu"/> APIs can be used on the current machine (ie. if there is at least a supported GPU device)
|
||||
/// </summary>
|
||||
public static bool IsSupported { get; } = (_Devices = QueryAllSupportedDevices()).Any();
|
||||
|
||||
private static GraphicsDevice _Default;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the default <see cref="GraphicsDevice"/> instance for the current machine
|
||||
/// </summary>
|
||||
public static GraphicsDevice Default => _Default ??= new GraphicsDevice();
|
||||
public static GraphicsDevice Default
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsSupported) throw new NotSupportedException("There isn't a supported GPU device on the current machine");
|
||||
|
||||
return _Default ??= new GraphicsDevice(_Devices.First());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of all the supported graphics devices on the current machine
|
||||
/// Enumerates all the available <see cref="GraphicsDevice"/> objects on the current machine
|
||||
/// </summary>
|
||||
/// <returns>The collection of <see cref="GraphicsDevice"/> objects with support for DX12.1</returns>
|
||||
/// <returns>A sequence of supported <see cref="GraphicsDevice"/> objects that can be used to run compute shaders</returns>
|
||||
[Pure]
|
||||
public static IReadOnlyList<GraphicsDevice> QueryAll()
|
||||
public static IEnumerable<GraphicsDevice> EnumerateDevices() => _Devices.Select(device => new GraphicsDevice(device));
|
||||
|
||||
// The loaded collection of supported devices
|
||||
private static IReadOnlyList<Device> _Devices;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of all the supported devices on the current machine
|
||||
/// </summary>
|
||||
/// <returns>The collection of <see cref="Device"/> objects with support for DX12.1</returns>
|
||||
[Pure]
|
||||
private static IReadOnlyList<Device> QueryAllSupportedDevices()
|
||||
{
|
||||
using Factory factory = new Factory1();
|
||||
List<GraphicsDevice> devices = new List<GraphicsDevice>();
|
||||
List<Device> devices = new List<Device>();
|
||||
|
||||
foreach (Adapter adapter in factory.Adapters)
|
||||
if (GraphicsDevice.TryGetFromAdapter(adapter, out GraphicsDevice? device))
|
||||
devices.Add(device!);
|
||||
{
|
||||
if (adapter.Description.DedicatedVideoMemory == 0) continue;
|
||||
try
|
||||
{
|
||||
Device device = new Device(adapter, GraphicsDevice.FeatureLevel);
|
||||
devices.Add(device);
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Unsupported device
|
||||
}
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする