Added exception on warning/error manual detection

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-16 13:07:55 +01:00
1 親 b141f0d8c1
コミット f43305ec4f
2ファイル変更
+39 -33

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

+12 -2
ファイルの表示
@@ -22,13 +22,23 @@ namespace ComputeSharp.Core.Extensions
public static void Assert(this HRESULT result)
{
#if DEBUG
DeviceHelper.FlushAllID3D12InfoQueueMessages();
#endif
bool hasErrorsOrWarnings = DeviceHelper.FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings();
if (result < 0)
{
ThrowHelper.ThrowWin32Exception(result);
}
if (hasErrorsOrWarnings)
{
ThrowHelper.ThrowWin32Exception("Warning or error detected by ID3D12InfoQueue");
}
#else
if (result < 0)
{
ThrowHelper.ThrowWin32Exception(result);
}
#endif
}
}
}
+27 -31
ファイルの表示
@@ -5,6 +5,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using TerraFX.Interop;
using static TerraFX.Interop.D3D12_MESSAGE_SEVERITY;
namespace ComputeSharp.Graphics.Helpers
{
@@ -13,9 +14,13 @@ namespace ComputeSharp.Graphics.Helpers
{
/// <summary>
/// Flushes all the pending debug messages for all existing <see cref="ID3D12Device"/> instances to the console/debugger.
/// It also checks whether or not there are any error messages being logged that didn't result in an actual crash yet.
/// </summary>
public static unsafe void FlushAllID3D12InfoQueueMessages()
/// <return>Whether or not there are any logged errors or warnings.</return>
public static unsafe bool FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings()
{
bool hasErrorsOrWarnings = false;
lock (DevicesCache)
{
int j = 0;
@@ -28,38 +33,27 @@ namespace ComputeSharp.Graphics.Helpers
ulong messages = queue.Get()->GetNumStoredMessagesAllowedByRetrievalFilter();
if (messages > 0)
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.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("==================================================");
builder.AppendLine($"[D3D12 message #{i} for \"{device}\" (HW: {device.IsHardwareAccelerated}, UMA: {device.IsCacheCoherentUMA})]");
builder.AppendLine($"[Category]: {Enum.GetName(message->Category)}");
builder.AppendLine($"[Severity]: {Enum.GetName(message->Severity)}");
builder.AppendLine($"[ID]: {Enum.GetName(message->ID)}");
builder.Append($"[Description]: \"{new string(message->pDescription)}\"");
for (ulong i = 0; i < messages; i++)
Marshal.FreeHGlobal((IntPtr)message);
if (message->Severity is D3D12_MESSAGE_SEVERITY_ERROR or D3D12_MESSAGE_SEVERITY_CORRUPTION or D3D12_MESSAGE_SEVERITY_WARNING)
{
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);
hasErrorsOrWarnings = true;
}
string text = builder.ToString();
@@ -72,13 +66,15 @@ namespace ComputeSharp.Graphics.Helpers
{
Console.WriteLine(text);
}
queue.Get()->ClearStoredMessages();
}
queue.Get()->ClearStoredMessages();
j++;
}
}
return hasErrorsOrWarnings;
}
}
}