Added format validation to create texture ND types
このコミットが含まれているのは:
1 親
914d56a3a8
コミット
1f1ba35324
4ファイル変更
+82
-3
検索条件に一致するファイルはありません
@@ -52,7 +52,6 @@ namespace ComputeSharp.Exceptions
|
||||
/// <typeparam name="T">The type of values in the input buffer.</typeparam>
|
||||
/// <param name="buffer">The input <see cref="Buffer{T}"/> that was used.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance that was used.</param>
|
||||
[Pure]
|
||||
internal static void Throw<T>(Buffer<T> buffer, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
@@ -65,7 +64,6 @@ namespace ComputeSharp.Exceptions
|
||||
/// <typeparam name="T">The type of values in the input buffer.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture2D{T}"/> that was used.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance that was used.</param>
|
||||
[Pure]
|
||||
internal static void Throw<T>(Texture2D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
@@ -78,7 +76,6 @@ namespace ComputeSharp.Exceptions
|
||||
/// <typeparam name="T">The type of values in the input buffer.</typeparam>
|
||||
/// <param name="texture">The input <see cref="Texture3D{T}"/> that was used.</param>
|
||||
/// <param name="device">The target <see cref="GraphicsDevice"/> instance that was used.</param>
|
||||
[Pure]
|
||||
internal static void Throw<T>(Texture3D<T> texture, GraphicsDevice device)
|
||||
where T : unmanaged
|
||||
{
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Text;
|
||||
using ComputeSharp.Graphics;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
namespace ComputeSharp.Exceptions
|
||||
{
|
||||
/// <summary>
|
||||
/// A custom <see cref="InvalidOperationException"/> that indicates when a texture was attempted to be created with an unsupported type.
|
||||
/// </summary>
|
||||
public sealed class UnsupportedTextureTypeException : InvalidOperationException
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="UnsupportedTextureTypeException"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="message">The message that describes the error.</param>
|
||||
private UnsupportedTextureTypeException(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="UnsupportedTextureTypeException"/> instance from the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="rank">The rank of the texture that couldn't be created.</param>
|
||||
/// <param name="type">The element type of texture that was being created.</param>
|
||||
/// <returns>A new <see cref="UnsupportedTextureTypeException"/> instance with a formatted error message.</returns>
|
||||
[Pure]
|
||||
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
|
||||
{
|
||||
2 => $"{nameof(GraphicsDevice.IsTexture2DSupportedForType)}<T>().",
|
||||
3 => $"{nameof(GraphicsDevice.IsTexture3DSupportedForType)}<T>().",
|
||||
_ => ThrowHelper.ThrowArgumentException<string>("Invalid texture rank")
|
||||
});
|
||||
|
||||
builder.AppendLine($"As a possible workaround on older devices, consider using a texture type of lower rank, or a linear buffer.");
|
||||
builder.ToString();
|
||||
|
||||
return new(builder.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnsupportedTextureTypeException"/> instance from the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values in the texture that couldn't be created.</typeparam>
|
||||
internal static void ThrowForTexture2D<T>()
|
||||
where T : unmanaged
|
||||
{
|
||||
throw Create(2, typeof(T));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="UnsupportedTextureTypeException"/> instance from the specified parameters.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of values in the texture that couldn't be created.</typeparam>
|
||||
internal static void ThrowForTexture3D<T>()
|
||||
where T : unmanaged
|
||||
{
|
||||
throw Create(3, typeof(T));
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする