Simplify code in all exception types
このコミットが含まれているのは:
1 親
3be6767584
コミット
afd4649a55
6ファイル変更
+41
-52
検索条件に一致するファイルはありません
@@ -10,9 +10,9 @@ public sealed class InvalidExecutionContextException : InvalidOperationException
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="InvalidExecutionContextException"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="memberName">The member name of the caller API.</param>
|
||||
/// <param name="memberName">The member name of the invoked API.</param>
|
||||
internal InvalidExecutionContextException(string memberName)
|
||||
: base($"The API {memberName} can only be used from within an HLSL shader.")
|
||||
: base("The invoked API can only be used from within an HLSL shader.")
|
||||
{
|
||||
MemberName = memberName;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace ComputeSharp.D2D1.Exceptions;
|
||||
|
||||
@@ -24,15 +23,15 @@ public sealed class FxcCompilationException : Exception
|
||||
/// <returns>A formatted error message for a new <see cref="FxcCompilationException"/> instance.</returns>
|
||||
private static string GetExceptionMessage(string error)
|
||||
{
|
||||
StringBuilder builder = new(512);
|
||||
#if NET6_0_OR_GREATER
|
||||
ReadOnlySpan<char> message = error.AsSpan().Trim();
|
||||
#else
|
||||
string message = error.Trim();
|
||||
#endif
|
||||
|
||||
_ = builder.AppendLine("The FXC compiler encountered one or more errors while trying to compile the shader:");
|
||||
_ = builder.AppendLine();
|
||||
_ = builder.AppendLine(error.Trim());
|
||||
_ = builder.AppendLine();
|
||||
_ = builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
|
||||
_ = builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
|
||||
|
||||
return builder.ToString();
|
||||
return
|
||||
$"""The FXC compiler encountered one or more errors while trying to compile the shader: "{message}". """ +
|
||||
$"""Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp. """ +
|
||||
$"""If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.""";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace ComputeSharp.Exceptions;
|
||||
|
||||
@@ -24,15 +23,15 @@ public sealed class DxcCompilationException : Exception
|
||||
/// <returns>A formatted error message for a new <see cref="DxcCompilationException"/> instance.</returns>
|
||||
private static string GetExceptionMessage(string error)
|
||||
{
|
||||
StringBuilder builder = new(512);
|
||||
#if NET6_0_OR_GREATER
|
||||
ReadOnlySpan<char> message = error.AsSpan().Trim();
|
||||
#else
|
||||
string message = error.Trim();
|
||||
#endif
|
||||
|
||||
_ = builder.AppendLine("The DXC compiler encountered one or more errors while trying to compile the shader:");
|
||||
_ = builder.AppendLine();
|
||||
_ = builder.AppendLine(error.Trim());
|
||||
_ = builder.AppendLine();
|
||||
_ = builder.AppendLine("Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp.");
|
||||
_ = builder.Append("If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.");
|
||||
|
||||
return builder.ToString();
|
||||
return
|
||||
$"""The DXC compiler encountered one or more errors while trying to compile the shader: "{message}". """ +
|
||||
$"""Make sure to only be using supported features by checking the README file in the ComputeSharp repository: https://github.com/Sergio0694/ComputeSharp. """ +
|
||||
$"""If you're sure that your C# shader code is valid, please open an issue an include a working repro and this error message.""";
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using ComputeSharp.Interop;
|
||||
using ComputeSharp.Resources;
|
||||
|
||||
@@ -32,15 +31,13 @@ public sealed class GraphicsDeviceMismatchException : InvalidOperationException
|
||||
/// </remarks>
|
||||
private static GraphicsDeviceMismatchException Create(IReferenceTrackedObject resource, GraphicsDevice sourceDevice, GraphicsDevice destinationDevice)
|
||||
{
|
||||
StringBuilder builder = new(512);
|
||||
string message =
|
||||
$"""Invalid pairing of graphics devices used to run a compute shader and allocate memory buffers. """ +
|
||||
$"""The target device to run the compute shader is "{destinationDevice}". """ +
|
||||
$"""The buffer of type {resource.GetType()} was allocated on device "{sourceDevice}". """ +
|
||||
$"""Make sure to always allocate buffers on the same device used to actually run the code that accesses them.""";
|
||||
|
||||
_ = builder.AppendLine("Invalid pairing of graphics devices used to run a compute shader and allocate memory buffers.");
|
||||
_ = builder.AppendLine($"The target device to run the compute shader is \"{destinationDevice}\".");
|
||||
_ = builder.AppendLine($"The buffer of type {resource.GetType()} was allocated on device \"{sourceDevice}\".");
|
||||
_ = builder.Append("Make sure to always allocate buffers on the same device used to actually run the code that accesses them.");
|
||||
_ = builder.ToString();
|
||||
|
||||
return new(builder.ToString());
|
||||
return new(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace ComputeSharp.Exceptions;
|
||||
|
||||
@@ -24,14 +23,12 @@ public sealed class UnsupportedDoubleOperationException : NotSupportedException
|
||||
/// <returns>A new <see cref="UnsupportedTextureTypeException"/> instance with a formatted error message.</returns>
|
||||
private static UnsupportedDoubleOperationException Create(Type type)
|
||||
{
|
||||
StringBuilder builder = new(256);
|
||||
string message =
|
||||
$"The device in use does not support creating resources of type {type}, as it does not support using double precision floating point numbers. " +
|
||||
$"As a possible workaround, consider replacing usage of the double type with single precision floating point numbers. " +
|
||||
$"Note that double precision operations are only partially supported on GPU devices, and are far slower than single precision ones.";
|
||||
|
||||
_ = builder.AppendLine($"The device in use does not support creating resources of type {type}, as it does not support using double precision floating point numbers.");
|
||||
_ = builder.AppendLine("As a possible workaround, consider replacing usage of the double type with single precision floating point numbers.");
|
||||
_ = builder.AppendLine("Note that double precision operations are only partially supported on GPU devices, and are far slower than single precision ones.");
|
||||
_ = builder.ToString();
|
||||
|
||||
return new(builder.ToString());
|
||||
return new(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace ComputeSharp.Exceptions;
|
||||
|
||||
@@ -25,22 +24,20 @@ public sealed class UnsupportedTextureTypeException : NotSupportedException
|
||||
/// <returns>A new <see cref="UnsupportedTextureTypeException"/> instance with a formatted error message.</returns>
|
||||
private static UnsupportedTextureTypeException Create(int rank, Type type)
|
||||
{
|
||||
StringBuilder builder = new(256);
|
||||
|
||||
_ = builder.AppendLine($"The device in use does not support creating {rank}D textures of type {type}.");
|
||||
_ = builder.Append($"Make sure to check the support at runtime by using {nameof(GraphicsDevice)}.");
|
||||
|
||||
_ = builder.AppendLine(rank switch
|
||||
string suggestedMethods = rank switch
|
||||
{
|
||||
1 => $"{nameof(GraphicsDevice.IsReadOnlyTexture1DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture1DSupportedForType)}<T>().",
|
||||
2 => $"{nameof(GraphicsDevice.IsReadOnlyTexture2DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture2DSupportedForType)}<T>().",
|
||||
3 => $"{nameof(GraphicsDevice.IsReadOnlyTexture3DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture3DSupportedForType)}<T>().",
|
||||
1 => $"{nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadOnlyTexture1DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture1DSupportedForType)}<T>()",
|
||||
2 => $"{nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadOnlyTexture2DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture2DSupportedForType)}<T>()",
|
||||
3 => $"{nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadOnlyTexture3DSupportedForType)}<T>() or {nameof(GraphicsDevice)}.{nameof(GraphicsDevice.IsReadWriteTexture3DSupportedForType)}<T>()",
|
||||
_ => default(ArgumentException).Throw<string>(nameof(rank))
|
||||
});
|
||||
};
|
||||
|
||||
_ = builder.Append("As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
|
||||
string message =
|
||||
$"The device in use does not support creating {rank}D textures of type {type}. " +
|
||||
$"Make sure to check the support at runtime by using {suggestedMethods}. " +
|
||||
$"As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.";
|
||||
|
||||
return new(builder.ToString());
|
||||
return new(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする