Add and use Win32ExceptionExtensions throw helpers
このコミットが含まれているのは:
1 親
fe41277fe7
コミット
72338416c2
5ファイル変更
+72
-25
検索条件に一致するファイルはありません
@@ -18,7 +18,7 @@ internal static class ArgumentNullExceptionExtensions
|
||||
[DoesNotReturn]
|
||||
public static void Throw(this ArgumentNullException? _, string? parameterName)
|
||||
{
|
||||
Throw(parameterName);
|
||||
throw new ArgumentNullException(parameterName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System.ComponentModel;
|
||||
|
||||
/// <summary>
|
||||
/// Throw helper extensions for <see cref="Win32Exception"/>.
|
||||
/// </summary>
|
||||
internal static class Win32ExceptionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="Win32Exception"/> for a given error code.
|
||||
/// </summary>
|
||||
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
|
||||
/// <param name="hresult">The error code to report.</param>
|
||||
[DoesNotReturn]
|
||||
public static void Throw(this Win32Exception? _, int hresult)
|
||||
{
|
||||
throw new Win32Exception(hresult);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="Win32Exception"/> if <paramref name="condition"/> is <see langword="true"/>.
|
||||
/// </summary>
|
||||
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
|
||||
/// <param name="condition">The condition to decide whether to throw the exception.</param>
|
||||
/// <param name="hresult">The error code to report.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ThrowIf(this Win32Exception? _, [DoesNotReturnIf(true)] bool condition, int hresult)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
Throw(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="Win32Exception"/> if a given error code represents an error.
|
||||
/// </summary>
|
||||
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
|
||||
/// <param name="hresult">The error code to check.</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ThrowIfFailed(this Win32Exception? _, int hresult)
|
||||
{
|
||||
if (hresult < 0)
|
||||
{
|
||||
Throw(hresult);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="Win32Exception"/> for a given error code.
|
||||
/// </summary>
|
||||
/// <param name="hresult">The error code to report.</param>
|
||||
/// <exception cref="Win32Exception">Thrown with the given error code.</exception>
|
||||
[DoesNotReturn]
|
||||
private static void Throw(int hresult)
|
||||
{
|
||||
throw new Win32Exception(hresult);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
@@ -38,10 +37,7 @@ internal static class HRESULTExtensions
|
||||
// single branch can then be inlined without bloating the code size in the caller.
|
||||
if (!Configuration.IsDebugOutputEnabled)
|
||||
{
|
||||
if (result < 0)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(result);
|
||||
}
|
||||
default(Win32Exception).ThrowIfFailed(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -51,15 +47,11 @@ internal static class HRESULTExtensions
|
||||
{
|
||||
bool hasErrorsOrWarnings = DeviceHelper.FlushAllID3D12InfoQueueMessagesAndCheckForErrorsOrWarnings();
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(result);
|
||||
}
|
||||
// First, check whether the current call has failed, and report that
|
||||
default(Win32Exception).ThrowIfFailed(result);
|
||||
|
||||
if (hasErrorsOrWarnings)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception("Warning or error detected by ID3D12InfoQueue.");
|
||||
}
|
||||
// If that's not the case, then throw if any errors are present in the info queue
|
||||
default(Win32Exception).ThrowIf(hasErrorsOrWarnings, E.E_FAIL);
|
||||
}
|
||||
|
||||
AssertWithDebugInfo(result);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks.Sources;
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Commands.Interop;
|
||||
@@ -215,7 +215,7 @@ unsafe partial class GraphicsDevice
|
||||
|
||||
NativeMemory.Free(callbackContext);
|
||||
|
||||
ThrowHelper.ThrowWin32Exception("Failed to register the compute context completion callback.");
|
||||
default(Win32Exception).Throw(E.E_FAIL);
|
||||
}
|
||||
|
||||
return waitForFenceValueTaskSource;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using CommunityToolkit.Diagnostics;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
@@ -107,20 +107,14 @@ partial class DeviceHelper
|
||||
riid: Windows.__uuidof<ID3D12DeviceRemovedExtendedData1>(),
|
||||
ppvObject: d3D12DeviceRemovedExtendedData.GetVoidAddressOf());
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(hresult);
|
||||
}
|
||||
default(Win32Exception).ThrowIfFailed(hresult);
|
||||
|
||||
D3D12_DRED_AUTO_BREADCRUMBS_OUTPUT1 d3D12DredAutoBreadcrumbsOutput;
|
||||
|
||||
// Get the auto breadcrumbs for the current event
|
||||
hresult = d3D12DeviceRemovedExtendedData.Get()->GetAutoBreadcrumbsOutput1(&d3D12DredAutoBreadcrumbsOutput);
|
||||
|
||||
if (hresult != S.S_OK)
|
||||
{
|
||||
ThrowHelper.ThrowWin32Exception(hresult);
|
||||
}
|
||||
default(Win32Exception).ThrowIfFailed(hresult);
|
||||
|
||||
_ = builder.AppendLine("[DRED breadcrumbs START] ===============================");
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする