Added initial WARP fallback device property
このコミットが含まれているのは:
1 親
e4147643b1
コミット
6da306e7d2
2ファイル変更
+69
検索条件に一致するファイルはありません
@@ -60,6 +60,25 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
return ThrowHelper.ThrowNotSupportedException<GraphicsDevice>("There isn't a supported GPU device on the current machine");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the warp <see cref="GraphicsDevice"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>The default <see cref="GraphicsDevice"/> instance supporting at least DX12.0.</returns>
|
||||
/// <exception cref="NotSupportedException">Thrown when a default device is not available.</exception>
|
||||
public static unsafe GraphicsDevice GetWarpDevice()
|
||||
{
|
||||
using ComPtr<ID3D12Device> d3D12Device = default;
|
||||
|
||||
DXGI_ADAPTER_DESC1 dxgiDescription1;
|
||||
|
||||
if (TryGetWarpDevice(d3D12Device.GetAddressOf(), &dxgiDescription1))
|
||||
{
|
||||
return GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
|
||||
}
|
||||
|
||||
return ThrowHelper.ThrowNotSupportedException<GraphicsDevice>("There isn't a supported device on the current machine");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to check or create a default <see cref="ID3D12Device"/> object.
|
||||
/// </summary>
|
||||
@@ -106,6 +125,42 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to check or create a warp <see cref="ID3D12Device"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">A pointer to the <see cref="ID3D12Device"/> object to create, or <see langword="null"/>.</param>
|
||||
/// <param name="dxgiDescription1">A pointer to the <see cref="DXGI_ADAPTER_DESC1"/> value for the device found.</param>
|
||||
/// <returns>Whether a warp device was created successfully.</returns>
|
||||
private static unsafe bool TryGetWarpDevice(ID3D12Device** d3D12Device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
using ComPtr<IDXGIFactory4> dxgiFactory4 = default;
|
||||
|
||||
EnableDebugMode();
|
||||
|
||||
FX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, FX.__uuidof<IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IDXGIAdapter1> dxgiAdapter1 = default;
|
||||
|
||||
HRESULT enumWarpAdapterResult = dxgiFactory4.Get()->EnumWarpAdapter(FX.__uuidof<IDXGIAdapter1>(), dxgiAdapter1.GetVoidAddressOf());
|
||||
|
||||
if (enumWarpAdapterResult == FX.DXGI_ERROR_NOT_FOUND)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
enumWarpAdapterResult.Assert();
|
||||
|
||||
dxgiAdapter1.Get()->GetDesc1(dxgiDescription1).Assert();
|
||||
|
||||
HRESULT createDeviceResult = FX.D3D12CreateDevice(
|
||||
dxgiAdapter1.AsIUnknown().Get(),
|
||||
D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_11_0,
|
||||
FX.__uuidof<ID3D12Device>(),
|
||||
(void**)d3D12Device);
|
||||
|
||||
return FX.SUCCEEDED(createDeviceResult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The creation flags for <see cref="IDXGIFactory"/> instances.
|
||||
/// </summary>
|
||||
|
||||
@@ -16,6 +16,11 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
private static readonly Lazy<GraphicsDevice> DefaultFactory = new(DeviceHelper.GetDefaultDevice);
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Lazy{T}"/> instance used to produce the warp device for <see cref="Fallback"/>.
|
||||
/// </summary>
|
||||
private static readonly Lazy<GraphicsDevice> WarpFactory = new(DeviceHelper.GetWarpDevice);
|
||||
|
||||
/// <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).
|
||||
@@ -31,6 +36,15 @@ namespace ComputeSharp
|
||||
/// <remarks>Make sure to check <see cref="IsSupported"/> before accessing this property.</remarks>
|
||||
public static GraphicsDevice Default => DefaultFactory.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the fallback <see cref="GraphicsDevice"/> instance for the current machine.
|
||||
/// This is a software version of a device that can be used when no supported GPU is available.
|
||||
/// This instance cannot be manually disposed - attempting to do so is safe and it will
|
||||
/// not cause an exception, but it will simply do nothing and not dispose the device.
|
||||
/// </summary>
|
||||
/// <exception cref="NotSupportedException">Thrown when a fallback device is not available.</exception>
|
||||
public static GraphicsDevice Fallback => WarpFactory.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Enumerates all the currently available DX12.0 devices. Note that creating a device is a relatively
|
||||
/// expensive operation, so consider using <see cref="QueryDevices"/> to be able to filter the available
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする