Centralize ID3D12DeviceRemovedExtendedDataSettings setup

このコミットが含まれているのは:
Sergio Pedri committed 2022-06-19 02:57:58 +02:00
1 親 639bcb75e1
コミット c0994486bf
5ファイル変更
+25 -63

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

+2 -3
ファイルの表示
@@ -17,6 +17,7 @@ internal static unsafe class ID3D12ResourceExtensions
/// </summary>
/// <param name="d3D12Resource">The target <see cref="ID3D12Resource"/> to map.</param>
/// <returns>A <see cref="ID3D12ResourceMap"/> instance representing the mapped resource.</returns>
/// <exception cref="Exception">Thrown when the mapping operation fails.</exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ID3D12ResourceMap Map(this ref ID3D12Resource d3D12Resource)
{
@@ -32,7 +33,6 @@ internal static unsafe class ID3D12ResourceExtensions
/// </summary>
/// <param name="d3D12Resource">The target <see cref="ID3D12Resource"/> to map.</param>
/// <returns>A pointer to the mapped area for <paramref name="d3D12Resource"/>.</returns>
/// <exception cref="Exception">Thrown when the mapping operation fails.</exception>
/// <remarks>Only use this method to unmap resources that were mapped with <see cref="Map(ref ID3D12Resource)"/>.</remarks>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Unmap(this ref ID3D12Resource d3D12Resource)
@@ -43,9 +43,8 @@ internal static unsafe class ID3D12ResourceExtensions
/// <summary>
/// Assigns a name to a given <see cref="ID3D12Resource"/>.
/// </summary>
/// <param name="d3D12Resource">The target <see cref="ID3D12Resource"/> to map.</param>
/// <param name="d3D12Resource">The target <see cref="ID3D12Resource"/> to set the name for.</param>
/// <param name="wrapper">The wrapper object to get the name from.</param>
/// <exception cref="Exception">Thrown when the mapping operation fails.</exception>
[Conditional("DEBUG")]
public static void SetName(this ref ID3D12Resource d3D12Resource, object wrapper)
{
-2
ファイルの表示
@@ -105,8 +105,6 @@ internal static partial class DeviceHelper
{
this.isInitialized = true;
EnsureDeviceRemovedExtendedDataConfiguration();
fixed (IDXGIFactory6** dxgiFactory6 = this.dxgiFactory6)
{
CreateDXGIFactory6(dxgiFactory6);
-52
ファイルの表示
@@ -1,12 +1,8 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Graphics.Extensions;
using TerraFX.Interop.DirectX;
using TerraFX.Interop.Windows;
#pragma warning disable CA1416
namespace ComputeSharp.Graphics.Helpers;
/// <inheritdoc/>
@@ -22,54 +18,6 @@ internal static partial class DeviceHelper
/// </summary>
private static readonly Dictionary<Luid, ComPtr<ID3D12InfoQueue>> D3D12InfoQueueMap = new();
/// <summary>
/// Indicates whether or not DRED is enabled (see <see href="https://devblogs.microsoft.com/directx/dred/"/>).
/// </summary>
private static volatile bool IsDeviceRemovedExtendedDataConfigurationEnabled;
/// <summary>
/// Ensures the DRED settings are enabled, if not already. If DRED is not configured, this method does nothing.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static unsafe void EnsureDeviceRemovedExtendedDataConfiguration()
{
// Enables DRED, if not enabled already
[MethodImpl(MethodImplOptions.NoInlining)]
static void EnableDeviceRemovedExtendedDataConfigurationIfNeeded()
{
if (IsDeviceRemovedExtendedDataConfigurationEnabled)
{
return;
}
lock (DevicesCache)
{
if (IsDeviceRemovedExtendedDataConfigurationEnabled)
{
return;
}
using ComPtr<ID3D12DeviceRemovedExtendedDataSettings> d3D12DeviceRemovedExtendedDataSettings = default;
DirectX.D3D12GetDebugInterface(
riid: Windows.__uuidof<ID3D12DeviceRemovedExtendedDataSettings>(),
ppvDebug: d3D12DeviceRemovedExtendedDataSettings.GetVoidAddressOf()).Assert();
// Enable the auto-breadcrumbs and page faults reporting
d3D12DeviceRemovedExtendedDataSettings.Get()->SetAutoBreadcrumbsEnablement(D3D12_DRED_ENABLEMENT.D3D12_DRED_ENABLEMENT_FORCED_ON);
d3D12DeviceRemovedExtendedDataSettings.Get()->SetPageFaultEnablement(D3D12_DRED_ENABLEMENT.D3D12_DRED_ENABLEMENT_FORCED_ON);
IsDeviceRemovedExtendedDataConfigurationEnabled = true;
}
}
// If the app context switch is set, ensure the DRED setting is enabled
if (Configuration.IsDeviceRemovedExtendedDataEnabled)
{
EnableDeviceRemovedExtendedDataConfigurationIfNeeded();
}
}
/// <summary>
/// Retrieves a <see cref="GraphicsDevice"/> instance for an <see cref="ID3D12Device"/> object.
/// </summary>
+23 -2
ファイルの表示
@@ -33,13 +33,18 @@ internal static partial class DeviceHelper
/// <param name="dxgiFactory6">The resulting <see cref="IDXGIFactory6"/> instance.</param>
internal static unsafe void CreateDXGIFactory6(IDXGIFactory6** dxgiFactory6)
{
using ComPtr<IDXGIFactory4> dxgiFactory4 = default;
if (Configuration.IsDebugOutputEnabled)
{
EnableDebugMode();
}
if (Configuration.IsDeviceRemovedExtendedDataEnabled)
{
EnableDeviceRemovedExtendedDataConfiguration();
}
using ComPtr<IDXGIFactory4> dxgiFactory4 = default;
DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof<IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert();
HRESULT result = dxgiFactory4.CopyTo(dxgiFactory6);
@@ -80,6 +85,22 @@ internal static partial class DeviceHelper
}
}
/// <summary>
/// Enables the DRED settings are enabled (see <see href="https://devblogs.microsoft.com/directx/dred/"/>).
/// </summary>
private static unsafe void EnableDeviceRemovedExtendedDataConfiguration()
{
using ComPtr<ID3D12DeviceRemovedExtendedDataSettings> d3D12DeviceRemovedExtendedDataSettings = default;
DirectX.D3D12GetDebugInterface(
riid: Windows.__uuidof<ID3D12DeviceRemovedExtendedDataSettings>(),
ppvDebug: d3D12DeviceRemovedExtendedDataSettings.GetVoidAddressOf()).Assert();
// Enable the auto-breadcrumbs and page faults reporting
d3D12DeviceRemovedExtendedDataSettings.Get()->SetAutoBreadcrumbsEnablement(D3D12_DRED_ENABLEMENT.D3D12_DRED_ENABLEMENT_FORCED_ON);
d3D12DeviceRemovedExtendedDataSettings.Get()->SetPageFaultEnablement(D3D12_DRED_ENABLEMENT.D3D12_DRED_ENABLEMENT_FORCED_ON);
}
/// <summary>
/// A custom <see cref="IDXGIFactory6"/> fallback implementation to use on systems with no support for it.
/// </summary>
-4
ファイルの表示
@@ -81,8 +81,6 @@ internal static partial class DeviceHelper
/// <returns>Whether a default device was found with the requested feature level.</returns>
private static unsafe bool TryGetDefaultDevice(ID3D12Device** d3D12Device, IDXGIAdapter** dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
{
EnsureDeviceRemovedExtendedDataConfiguration();
using ComPtr<IDXGIFactory6> dxgiFactory6 = default;
CreateDXGIFactory6(dxgiFactory6.GetAddressOf());
@@ -175,8 +173,6 @@ internal static partial class DeviceHelper
/// <returns>Whether a warp device was created successfully.</returns>
private static unsafe bool TryGetWarpDevice(ID3D12Device** d3D12Device, IDXGIAdapter** dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
{
EnsureDeviceRemovedExtendedDataConfiguration();
using ComPtr<IDXGIFactory6> dxgiFactory6 = default;
CreateDXGIFactory6(dxgiFactory6.GetAddressOf());