diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs
index daefc4ec..81a3e914 100644
--- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs
+++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs
@@ -68,6 +68,11 @@ namespace ComputeSharp.Graphics.Helpers
///
private uint index;
+ ///
+ /// Indicates whether or not the enumerator has completed the enumeration of all possible devices.
+ ///
+ private bool isCompleted;
+
///
/// The current instance to return.
///
@@ -103,47 +108,80 @@ namespace ComputeSharp.Graphics.Helpers
}
}
+ if (this.isCompleted) return false;
+
while (true)
{
using ComPtr dxgiAdapter1 = default;
- HRESULT enumAdapters1Result = dxgiFactory4.Get()->EnumAdapters1(this.index, dxgiAdapter1.GetAddressOf());
+ HRESULT enumAdapters1Result = this.dxgiFactory4.Get()->EnumAdapters1(this.index, dxgiAdapter1.GetAddressOf());
if (enumAdapters1Result == FX.DXGI_ERROR_NOT_FOUND)
{
- return false;
- }
+ this.dxgiFactory4.Get()->EnumWarpAdapter(FX.__uuidof(), dxgiAdapter1.GetVoidAddressOf()).Assert();
- enumAdapters1Result.Assert();
+ DXGI_ADAPTER_DESC1 dxgiDescription1;
- this.index++;
+ dxgiAdapter1.Get()->GetDesc1(&dxgiDescription1).Assert();
- DXGI_ADAPTER_DESC1 dxgiDescription1;
-
- dxgiAdapter1.Get()->GetDesc1(&dxgiDescription1).Assert();
-
- if (dxgiDescription1.DedicatedVideoMemory == 0) continue;
-
- HRESULT createDeviceResult = FX.D3D12CreateDevice(
- dxgiAdapter1.AsIUnknown().Get(),
- D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
- FX.__uuidof(),
- null);
-
- if (FX.SUCCEEDED(createDeviceResult) &&
- this.predicate(new GraphicsDeviceInfo(&dxgiDescription1)))
- {
- using ComPtr d3D12Device = default;
-
- FX.D3D12CreateDevice(
+ HRESULT createDeviceResult = FX.D3D12CreateDevice(
dxgiAdapter1.AsIUnknown().Get(),
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
FX.__uuidof(),
- d3D12Device.GetVoidAddressOf()).Assert();
+ null);
- this.graphicsDevice = GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
+ if (FX.SUCCEEDED(createDeviceResult) &&
+ this.predicate(new GraphicsDeviceInfo(&dxgiDescription1)))
+ {
+ using ComPtr d3D12Device = default;
- return true;
+ FX.D3D12CreateDevice(
+ dxgiAdapter1.AsIUnknown().Get(),
+ D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
+ FX.__uuidof(),
+ d3D12Device.GetVoidAddressOf()).Assert();
+
+ this.graphicsDevice = GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
+ this.isCompleted = true;
+
+ return true;
+ }
+
+ return false;
+ }
+ else
+ {
+ enumAdapters1Result.Assert();
+
+ this.index++;
+
+ DXGI_ADAPTER_DESC1 dxgiDescription1;
+
+ dxgiAdapter1.Get()->GetDesc1(&dxgiDescription1).Assert();
+
+ if (dxgiDescription1.DedicatedVideoMemory == 0) continue;
+
+ HRESULT createDeviceResult = FX.D3D12CreateDevice(
+ dxgiAdapter1.AsIUnknown().Get(),
+ D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
+ FX.__uuidof(),
+ null);
+
+ if (FX.SUCCEEDED(createDeviceResult) &&
+ this.predicate(new GraphicsDeviceInfo(&dxgiDescription1)))
+ {
+ using ComPtr d3D12Device = default;
+
+ FX.D3D12CreateDevice(
+ dxgiAdapter1.AsIUnknown().Get(),
+ D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
+ FX.__uuidof(),
+ d3D12Device.GetVoidAddressOf()).Assert();
+
+ this.graphicsDevice = GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
+
+ return true;
+ }
}
}
}
diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
index 8af50a6d..036f771a 100644
--- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
+++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs
@@ -123,15 +123,8 @@ namespace ComputeSharp.Graphics.Helpers
using ComPtr dxgiAdapter1 = default;
- HRESULT enumWarpAdapterResult = dxgiFactory4.Get()->EnumWarpAdapter(FX.__uuidof(), dxgiAdapter1.GetVoidAddressOf());
-
- if (enumWarpAdapterResult == FX.DXGI_ERROR_NOT_FOUND)
- {
- return false;
- }
-
- enumWarpAdapterResult.Assert();
-
+ dxgiFactory4.Get()->EnumWarpAdapter(FX.__uuidof(), dxgiAdapter1.GetVoidAddressOf()).Assert();
+
dxgiAdapter1.Get()->GetDesc1(dxgiDescription1).Assert();
HRESULT createDeviceResult = FX.D3D12CreateDevice(
diff --git a/tests/ComputeSharp.Tests/InitializationTests.cs b/tests/ComputeSharp.Tests/InitializationTests.cs
index 68c87389..586b5b4e 100644
--- a/tests/ComputeSharp.Tests/InitializationTests.cs
+++ b/tests/ComputeSharp.Tests/InitializationTests.cs
@@ -20,7 +20,16 @@ namespace ComputeSharp.Tests
{
Assert.IsTrue(Gpu.Default.Luid != default);
Assert.IsTrue(Gpu.Default.Name is { Length: > 0 });
- Assert.IsTrue(Gpu.Default.MemorySize != 0);
+
+ if (Gpu.Default.IsHardwareAccelerated)
+ {
+ Assert.IsTrue(Gpu.Default.DedicatedMemorySize != 0);
+ }
+ else
+ {
+ Assert.IsTrue(Gpu.Default.SharedMemorySize != 0);
+ }
+
Assert.IsTrue(Gpu.Default.ComputeUnits != 0);
Assert.IsTrue(Gpu.Default.WavefrontSize != 0);
}