Add app config switch to enable the debug mode
このコミットが含まれているのは:
1 親
7c39dbba98
コミット
5c17ea5401
5ファイル変更
+79
-44
検索条件に一致するファイルはありません
@@ -1,9 +1,7 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
#if DEBUG
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
#endif
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
@@ -34,23 +32,36 @@ internal static class HResultExtensions
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Assert(this int result)
|
||||
{
|
||||
#if DEBUG
|
||||
bool hasErrorsOrWarnings = DeviceHelper.FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings();
|
||||
// This forward branch is predicted taken by the JIT, and when tier-1 JIT kicks in
|
||||
// it will just be removed if the IsDebugOutputEnabled flag is not set. The resulting
|
||||
// single branch can then be inlined without bloating the code size in the caller.
|
||||
if (!Configuration.IsDebugOutputEnabled)
|
||||
{
|
||||
if (result < 0)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Move the extended debug logic into a non inlineable method to help the inliner in the standard case
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
static void AssertWithDebugInfo(int result)
|
||||
{
|
||||
bool hasErrorsOrWarnings = DeviceHelper.FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings();
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(result);
|
||||
}
|
||||
if (result < 0)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(result);
|
||||
}
|
||||
|
||||
if (hasErrorsOrWarnings)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception("Warning or error detected by ID3D12InfoQueue.");
|
||||
if (hasErrorsOrWarnings)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception("Warning or error detected by ID3D12InfoQueue.");
|
||||
}
|
||||
}
|
||||
|
||||
AssertWithDebugInfo(result);
|
||||
}
|
||||
#else
|
||||
if (result < 0)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(result);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
#if DEBUG
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
#endif
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
@@ -15,12 +13,10 @@ internal static partial class DeviceHelper
|
||||
/// </summary>
|
||||
internal static readonly Dictionary<Luid, GraphicsDevice> DevicesCache = new();
|
||||
|
||||
#if DEBUG
|
||||
/// <summary>
|
||||
/// The local map of <see cref="ID3D12InfoQueue"/> instances for the existing devices.
|
||||
/// </summary>
|
||||
private static readonly Dictionary<Luid, ComPtr<ID3D12InfoQueue>> D3D12InfoQueueMap = new();
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a <see cref="GraphicsDevice"/> instance for an <see cref="ID3D12Device"/> object.
|
||||
@@ -41,9 +37,10 @@ internal static partial class DeviceHelper
|
||||
|
||||
DevicesCache.Add(luid, device);
|
||||
|
||||
#if DEBUG
|
||||
D3D12InfoQueueMap.Add(luid, d3D12Device->CreateInfoQueue());
|
||||
#endif
|
||||
if (Configuration.IsDebugOutputEnabled)
|
||||
{
|
||||
D3D12InfoQueueMap.Add(luid, d3D12Device->CreateInfoQueue());
|
||||
}
|
||||
}
|
||||
|
||||
return device;
|
||||
@@ -60,11 +57,12 @@ internal static partial class DeviceHelper
|
||||
{
|
||||
DevicesCache.Remove(device.Luid);
|
||||
|
||||
#if DEBUG
|
||||
D3D12InfoQueueMap.Remove(device.Luid, out ComPtr<ID3D12InfoQueue> queue);
|
||||
if (Configuration.IsDebugOutputEnabled)
|
||||
{
|
||||
D3D12InfoQueueMap.Remove(device.Luid, out ComPtr<ID3D12InfoQueue> queue);
|
||||
|
||||
queue.Dispose();
|
||||
#endif
|
||||
queue.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
#if DEBUG
|
||||
|
||||
#if NET6_0_OR_GREATER
|
||||
using System;
|
||||
#endif
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
using static TerraFX.Interop.DirectX.D3D12_MESSAGE_SEVERITY;
|
||||
#if !NET6_0_OR_GREATER
|
||||
#if NET6_0_OR_GREATER
|
||||
using Enum = System.Enum;
|
||||
#else
|
||||
using Enum = ComputeSharp.NetStandard.System.Enum;
|
||||
#endif
|
||||
|
||||
@@ -119,5 +116,3 @@ internal static partial class DeviceHelper
|
||||
return hasErrorsOrWarnings;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -20,11 +20,11 @@ internal static partial class DeviceHelper
|
||||
/// <summary>
|
||||
/// The creation flags for <see cref="IDXGIFactory"/> instances.
|
||||
/// </summary>
|
||||
private const uint IDXGIFactoryCreationFlags =
|
||||
private static readonly uint IDXGIFactoryCreationFlags =
|
||||
#if DEBUG
|
||||
DXGI.DXGI_CREATE_FACTORY_DEBUG;
|
||||
#else
|
||||
0;
|
||||
Configuration.IsDebugOutputEnabled ? (uint)DXGI.DXGI_CREATE_FACTORY_DEBUG : 0;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
@@ -35,9 +35,10 @@ internal static partial class DeviceHelper
|
||||
{
|
||||
using ComPtr<IDXGIFactory4> dxgiFactory4 = default;
|
||||
|
||||
#if DEBUG
|
||||
EnableDebugMode();
|
||||
#endif
|
||||
if (Configuration.IsDebugOutputEnabled)
|
||||
{
|
||||
EnableDebugMode();
|
||||
}
|
||||
|
||||
DirectX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, Windows.__uuidof<IDXGIFactory4>(), dxgiFactory4.GetVoidAddressOf()).Assert();
|
||||
|
||||
@@ -60,7 +61,6 @@ internal static partial class DeviceHelper
|
||||
return;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// <summary>
|
||||
/// Enables the debug layer for DirectX APIs.
|
||||
/// </summary>
|
||||
@@ -79,7 +79,6 @@ internal static partial class DeviceHelper
|
||||
d3D12Debug1.Get()->SetEnableSynchronizedCommandQueueValidation(Windows.TRUE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// A custom <see cref="IDXGIFactory6"/> fallback implementation to use on systems with no support for it.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
|
||||
/// <summary>
|
||||
/// A container for all shared <see cref="AppContext"/> configuration switches for ComputeSharp.
|
||||
/// </summary>
|
||||
internal static class Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// The configuration property name for <see cref="IsDebugOutputEnabled"/>.
|
||||
/// </summary>
|
||||
private const string EnableDebugOutput = "COMPUTESHARP_ENABLE_DEBUG_OUTPUT";
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether or not the debug output is enabled.
|
||||
/// </summary>
|
||||
public static readonly bool IsDebugOutputEnabled = GetConfigurationValue(EnableDebugOutput);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a configuration value for a specified property.
|
||||
/// </summary>
|
||||
/// <param name="propertyName">The property name to retrieve the value for.</param>
|
||||
/// <returns>The value of the specified configuration setting.</returns>
|
||||
private static bool GetConfigurationValue(string propertyName)
|
||||
{
|
||||
if (AppContext.TryGetSwitch(propertyName, out bool isEnabled))
|
||||
{
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする