From f6f73b9e3f514ccf29063a86a742d2a584cc7f95 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 13 Aug 2019 12:50:06 +0200 Subject: [PATCH] Added device description to the GraphicsDevice class --- src/ComputeSharp.Graphics/GraphicsDevice.cs | 25 ++++--------------- .../Helpers/DeviceHelper.cs | 6 ++--- src/ComputeSharp/Gpu.cs | 7 +++--- 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/ComputeSharp.Graphics/GraphicsDevice.cs b/src/ComputeSharp.Graphics/GraphicsDevice.cs index 99a86fb7..edb771bd 100644 --- a/src/ComputeSharp.Graphics/GraphicsDevice.cs +++ b/src/ComputeSharp.Graphics/GraphicsDevice.cs @@ -15,12 +15,14 @@ namespace ComputeSharp.Graphics /// Creates a new instance for the input /// /// The to use for the new instance - public GraphicsDevice(Device device) + /// The available info for the new instance + public GraphicsDevice(Device device, AdapterDescription description) { #if DEBUG DebugInterface.Get().EnableDebugLayer(); #endif NativeDevice = device; + Description = description; WavefrontSize = NativeDevice.D3D12Options1.WaveLaneCountMin; NativeComputeCommandQueue = NativeDevice.CreateCommandQueue(new CommandQueueDescription(SharpDX.Direct3D12.CommandListType.Compute)); @@ -48,26 +50,9 @@ namespace ComputeSharp.Graphics } /// - /// Tries to create a new instance from the input object + /// Gets the available info for the current instance /// - /// The input for the current GPU being targeted - /// The resulting value, in case of success - /// A value indicating whether or not the resulting device was created correctly - 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; - } - } + public AdapterDescription Description { get; } /// /// Gets the number of lanes in a SIMD wave on the current device (also known as "wavefront size" or "warp width") diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs index c7052482..25547e65 100644 --- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs +++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs @@ -15,10 +15,10 @@ namespace ComputeSharp.Graphics.Helpers /// /// The collection of objects with support for DX12.1 [Pure] - public static IReadOnlyList QueryAllSupportedDevices() + public static IReadOnlyList<(Device, AdapterDescription)> QueryAllSupportedDevices() { using Factory factory = new Factory1(); - List devices = new List(); + List<(Device, AdapterDescription)> devices = new List<(Device, AdapterDescription)>(); foreach (Adapter adapter in factory.Adapters) { @@ -26,7 +26,7 @@ namespace ComputeSharp.Graphics.Helpers try { Device device = new Device(adapter, GraphicsDevice.FeatureLevel); - devices.Add(device); + devices.Add((device, adapter.Description)); } catch { diff --git a/src/ComputeSharp/Gpu.cs b/src/ComputeSharp/Gpu.cs index ad3e247f..0bfe9b60 100644 --- a/src/ComputeSharp/Gpu.cs +++ b/src/ComputeSharp/Gpu.cs @@ -4,6 +4,7 @@ using System.Diagnostics.Contracts; using System.Linq; using ComputeSharp.Graphics; using ComputeSharp.Graphics.Helpers; +using SharpDX.DXGI; using Device = SharpDX.Direct3D12.Device; namespace ComputeSharp @@ -29,7 +30,7 @@ namespace ComputeSharp { if (!IsSupported) throw new NotSupportedException("There isn't a supported GPU device on the current machine"); - return _Default ??= new GraphicsDevice(_Devices.First()); + return _Default ??= new GraphicsDevice(_Devices[0].Device, _Devices[0].Description); } } @@ -38,9 +39,9 @@ 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)); + public static IEnumerable EnumerateDevices() => _Devices.Select(device => new GraphicsDevice(device.Device, device.Description)); // The loaded collection of supported devices - private static IReadOnlyList _Devices; + private static IReadOnlyList<(Device Device, AdapterDescription Description)> _Devices; } }