Toggled ID3D12InfoQueue output to DEBUG only

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-15 01:46:18 +01:00
1 親 7ff9f3dcf0
コミット 501ab5f570
5ファイル変更
+129 -86

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

+4 -2
ファイルの表示
@@ -21,10 +21,12 @@ namespace ComputeSharp.Core.Extensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Assert(this HRESULT result)
{
#if DEBUG
DeviceHelper.FlushAllID3D12InfoQueueMessages();
#endif
if (result < 0)
{
DeviceDebugHelper.FlushMessages();
ThrowHelper.ThrowWin32Exception(result);
}
}
+18 -73
ファイルの表示
@@ -1,77 +1,12 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using ComputeSharp.Core.Extensions;
using System.Collections.Generic;
using TerraFX.Interop;
#if DEBUG
using ComputeSharp.Core.Extensions;
using FX = TerraFX.Interop.Windows;
#endif
namespace ComputeSharp.Graphics.Helpers
{
internal static class DeviceDebugHelper
{
public static unsafe void FlushMessages()
{
int j = 0;
foreach (var pair in DeviceHelper.D3D12InfoQueueMap)
{
var device = DeviceHelper.DevicesCache[pair.Key];
var queue = pair.Value;
ulong messages = queue.Get()->GetNumStoredMessages();
if (messages > 0)
{
var builder = new StringBuilder();
builder.AppendLine("====================[ID3D12InfoQueue]====================");
builder.AppendLine($"[ID3D12InfoQueue messages for device #{j}");
builder.AppendLine($"[LUID]: {device.Luid}");
builder.AppendLine($"[NAME]: {device.Name}");
builder.AppendLine($"[DEDICATED MEMORY]: {device.DedicatedMemorySize}");
builder.AppendLine($"[IS HARDWARE]: {device.IsHardwareAccelerated}");
builder.AppendLine($"[IS UMA]: {device.IsCacheCoherentUMA}");
builder.AppendLine($"[COMPUTE UNITS]: {device.ComputeUnits}");
builder.AppendLine($"[WAVE SIZE]: {device.WavefrontSize}");
builder.Append("=========================================================");
for (ulong i = 0; i < messages; i++)
{
nuint length;
queue.Get()->GetMessage(i, null, &length);
D3D12_MESSAGE* message = (D3D12_MESSAGE*)Marshal.AllocHGlobal((nint)length);
queue.Get()->GetMessage(i, message, &length);
builder.AppendLine();
builder.AppendLine($"[D3D12 DEBUG MESSAGE #{i}]");
builder.AppendLine($"[CATEGORY]: {Enum.GetName(message->Category)}");
builder.AppendLine($"[SEVERITY]: {Enum.GetName(message->Severity)}");
builder.AppendLine($"[ID]: {Enum.GetName(message->ID)}");
builder.AppendLine($"[INFO]: \"{new string(message->pDescription)}\"");
builder.Append("=========================================================");
Marshal.FreeHGlobal((IntPtr)message);
}
string text = builder.ToString();
Console.WriteLine(text);
if (Debugger.IsAttached)
{
Debug.WriteLine(text);
}
queue.Get()->ClearStoredMessages();
}
j++;
}
}
}
/// <inheritdoc/>
internal static partial class DeviceHelper
{
@@ -80,7 +15,12 @@ namespace ComputeSharp.Graphics.Helpers
/// </summary>
internal static readonly Dictionary<Luid, GraphicsDevice> DevicesCache = new();
internal static readonly Dictionary<Luid, ComPtr<ID3D12InfoQueue>> D3D12InfoQueueMap = 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.
@@ -100,11 +40,13 @@ namespace ComputeSharp.Graphics.Helpers
DevicesCache.Add(luid, device);
#if DEBUG
ComPtr<ID3D12InfoQueue> d3D12InfoQueue = default;
int res = d3D12Device.Get()->QueryInterface(Windows.__uuidof<ID3D12InfoQueue>(), d3D12InfoQueue.GetVoidAddressOf());
int res = d3D12Device.Get()->QueryInterface(FX.__uuidof<ID3D12InfoQueue>(), d3D12InfoQueue.GetVoidAddressOf());
D3D12InfoQueueMap.Add(luid, d3D12InfoQueue);
#endif
}
return device;
@@ -120,9 +62,12 @@ namespace ComputeSharp.Graphics.Helpers
lock (DevicesCache)
{
DevicesCache.Remove(device.Luid);
D3D12InfoQueueMap.Remove(device.Luid, out var queue);
#if DEBUG
D3D12InfoQueueMap.Remove(device.Luid, out ComPtr<ID3D12InfoQueue> queue);
queue.Dispose();
#endif
}
}
}
+86
ファイルの表示
@@ -0,0 +1,86 @@
#if DEBUG
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using TerraFX.Interop;
namespace ComputeSharp.Graphics.Helpers
{
/// <inheritdoc/>
internal static partial class DeviceHelper
{
/// <summary>
/// Flushes all the pending debug messages for all existing <see cref="ID3D12Device"/> instances to the console/debugger.
/// </summary>
public static unsafe void FlushAllID3D12InfoQueueMessages()
{
lock (DevicesCache)
{
int j = 0;
StringBuilder builder = new(1024);
foreach (var pair in D3D12InfoQueueMap)
{
var device = DevicesCache[pair.Key];
var queue = pair.Value;
ulong messages = queue.Get()->GetNumStoredMessages();
if (messages > 0)
{
builder.Clear();
builder.AppendLine("================ ID3D12InfoQueue =================");
builder.AppendLine($"[ID3D12InfoQueue messages for device #{j}");
builder.AppendLine($"[Luid]: {device.Luid}");
builder.AppendLine($"[Name]: {device.Name}");
builder.AppendLine($"[DedicatedMemorySize]: {device.DedicatedMemorySize}");
builder.AppendLine($"[IsHardwareAccelerated]: {device.IsHardwareAccelerated}");
builder.AppendLine($"[IsCacheCoherentUMA]: {device.IsCacheCoherentUMA}");
builder.AppendLine($"[ComputeUnits]: {device.ComputeUnits}");
builder.AppendLine($"[WavefrontSize]: {device.WavefrontSize}");
builder.Append("==================================================");
for (ulong i = 0; i < messages; i++)
{
nuint length;
queue.Get()->GetMessage(i, null, &length);
D3D12_MESSAGE* message = (D3D12_MESSAGE*)Marshal.AllocHGlobal((nint)length);
queue.Get()->GetMessage(i, message, &length);
builder.AppendLine();
builder.AppendLine($"[D3D12 debug message #{i}]");
builder.AppendLine($"[Category]: {Enum.GetName(message->Category)}");
builder.AppendLine($"[Severity]: {Enum.GetName(message->Severity)}");
builder.AppendLine($"[ID]: {Enum.GetName(message->ID)}");
builder.AppendLine($"[Description]: \"{new string(message->pDescription)}\"");
builder.Append("==================================================");
Marshal.FreeHGlobal((IntPtr)message);
}
string text = builder.ToString();
if (Debugger.IsAttached)
{
Debug.WriteLine(text);
}
else
{
Console.WriteLine(text);
}
queue.Get()->ClearStoredMessages();
}
j++;
}
}
}
}
}
#endif
+8 -1
ファイルの表示
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;
using ComputeSharp.Core.Extensions;
using Microsoft.Toolkit.Diagnostics;
@@ -138,11 +139,17 @@ namespace ComputeSharp.Graphics.Helpers
/// <summary>
/// The creation flags for <see cref="IDXGIFactory"/> instances.
/// </summary>
private const uint IDXGIFactoryCreationFlags = FX.DXGI_CREATE_FACTORY_DEBUG;
private const uint IDXGIFactoryCreationFlags =
#if DEBUG
FX.DXGI_CREATE_FACTORY_DEBUG;
#else
0;
#endif
/// <summary>
/// Enables the debug layer for DirectX APIs.
/// </summary>
[Conditional("DEBUG")]
private static unsafe void EnableDebugMode()
{
using ComPtr<ID3D12Debug> d3D12Debug = default;