Remove ThrowHelper APIs in D2D1 projects, switch to new extensions
このコミットが含まれているのは:
1 親
5a4fd9a4ce
コミット
92fbf75185
17ファイル変更
+87
-194
検索条件に一致するファイルはありません
@@ -20,6 +20,19 @@ internal static class ArgumentExceptionExtensions
|
||||
throw new ArgumentException(null, parameterName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> for a given parameter name and message.
|
||||
/// </summary>
|
||||
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
|
||||
/// <param name="parameterName">The name of the parameter to report in the exception.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with <paramref name="parameterName"/>.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void Throw(this ArgumentException? _, string? parameterName, string? message)
|
||||
{
|
||||
throw new ArgumentException(message, parameterName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="ArgumentException"/> for a given parameter name.
|
||||
/// </summary>
|
||||
|
||||
@@ -8,6 +8,19 @@ namespace System;
|
||||
/// </summary>
|
||||
internal static class InvalidOperationExceptionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws an <see cref="InvalidOperationException"/> for a given parameter name.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type to let the compiler assume it returns.</typeparam>
|
||||
/// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param>
|
||||
/// <returns>This method never returns any values.</returns>
|
||||
/// <exception cref="InvalidOperationException">Thrown with no parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static T Throw<T>(this InvalidOperationException? _)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="InvalidOperationException"/> if <paramref name="condition"/> is <see langword="true"/>.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace System;
|
||||
|
||||
@@ -30,4 +31,28 @@ internal static class NotSupportedExceptionExtensions
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="NotSupportedException"/> 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>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ThrowIf(this NotSupportedException? _, [DoesNotReturnIf(true)] bool condition)
|
||||
{
|
||||
if (condition)
|
||||
{
|
||||
Throw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an <see cref="NotSupportedException"/> for a given parameter name.
|
||||
/// </summary>
|
||||
/// <exception cref="NotSupportedException">Always thrown with no parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
private static void Throw()
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using Windows.Graphics.Effects;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Buffers;
|
||||
@@ -103,10 +102,7 @@ internal struct GraphicsEffectSourceBuffer
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
if ((uint)index >= 16)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The index must be in the [0, 15] range.");
|
||||
}
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16);
|
||||
|
||||
ref SourceReference r0 = ref Unsafe.As<GraphicsEffectSourceBuffer, SourceReference>(ref this);
|
||||
ref SourceReference r1 = ref Unsafe.Add(ref r0, index);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Buffers;
|
||||
@@ -103,10 +102,7 @@ internal struct ResourceTextureManagerBuffer
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
get
|
||||
{
|
||||
if ((uint)index >= 16)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The index must be in the [0, 15] range.");
|
||||
}
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16);
|
||||
|
||||
ref D2D1ResourceTextureManager? r0 = ref Unsafe.As<ResourceTextureManagerBuffer, D2D1ResourceTextureManager?>(ref this);
|
||||
ref D2D1ResourceTextureManager? r1 = ref Unsafe.Add(ref r0, index);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
|
||||
namespace ComputeSharp.D2D1.Uwp.Collections;
|
||||
|
||||
@@ -22,10 +21,7 @@ internal static class FixedCountList<T>
|
||||
|
||||
Span<T> span = array.AsSpan(index);
|
||||
|
||||
if (list.Indices.Length > span.Length)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(array), "The destination array range is smaller than the number of source items.");
|
||||
}
|
||||
default(ArgumentException).ThrowIf(list.Indices.Length > span.Length, nameof(array));
|
||||
|
||||
foreach (int i in list.Indices)
|
||||
{
|
||||
@@ -42,18 +38,11 @@ internal static class FixedCountList<T>
|
||||
public static void CopyTo(IFixedCountList<T> list, Array array, int index)
|
||||
{
|
||||
default(ArgumentNullException).ThrowIfNull(array);
|
||||
|
||||
if ((uint)index >= array.Length)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The starting array index is out of range.");
|
||||
}
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, array.Length);
|
||||
|
||||
int remainingLength = array.Length - index;
|
||||
|
||||
if (list.Indices.Length > remainingLength)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(array), "The destination array range is smaller than the number of source items.");
|
||||
}
|
||||
default(ArgumentException).ThrowIf(list.Indices.Length > remainingLength, nameof(array));
|
||||
|
||||
foreach (int i in list.Indices)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.ResourceManagers;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Effects.TransformMappers;
|
||||
@@ -158,9 +157,7 @@ internal static unsafe class ID2D1EffectExtensions
|
||||
}
|
||||
|
||||
// There was no way to retrieve the correct managed wrapper
|
||||
ThrowHelper.ThrowInvalidOperationException("Cannot retrieve a D2D1ResourceTextureManager instance wrapping a native object that was set externally.");
|
||||
|
||||
return null;
|
||||
return default(InvalidOperationException).Throw<D2D1ResourceTextureManager?>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Interop.Effects;
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
@@ -350,10 +349,7 @@ unsafe partial class PixelShaderEffect<T>
|
||||
if (source is null)
|
||||
{
|
||||
// If the source is null and that is not valid here (eg. when drawing), just throw
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_ALLOW_NULL_EFFECT_INPUTS) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("The effect has one or more sources set to null, and null effect inputs are not valid at this time.");
|
||||
}
|
||||
default(InvalidOperationException).ThrowIf((flags & WIN2D_GET_D2D_IMAGE_FLAGS_ALLOW_NULL_EFFECT_INPUTS) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ABI.Microsoft.Graphics.Canvas;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Uwp.Buffers;
|
||||
using ComputeSharp.D2D1.Uwp.Extensions;
|
||||
using ComputeSharp.Interop;
|
||||
@@ -147,10 +146,7 @@ unsafe partial class PixelShaderEffect<T>
|
||||
}
|
||||
|
||||
// If unrealization isn't requested for failures, just throw
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(value), "The effect source is not valid (it must implement ICanvasImageInterop).");
|
||||
}
|
||||
default(InvalidOperationException).ThrowIf((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE);
|
||||
|
||||
Unrealize(value, index);
|
||||
|
||||
@@ -184,10 +180,7 @@ unsafe partial class PixelShaderEffect<T>
|
||||
// on that specific source will just fail during the recursive traversal, but that couldn't be checked from here anyway.
|
||||
if (sourceCanvasDeviceType == WIN2D_GET_DEVICE_ASSOCIATION_TYPE_CREATION_DEVICE && !this.canvasDevice.Get()->IsSameInstance(sourceCanvasDevice.Get()))
|
||||
{
|
||||
if ((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(value), "The effect source is realized on a different canvas device.");
|
||||
}
|
||||
default(InvalidOperationException).ThrowIf((flags & WIN2D_GET_D2D_IMAGE_FLAGS_UNREALIZE_ON_FAILURE) == WIN2D_GET_D2D_IMAGE_FLAGS_NONE);
|
||||
|
||||
Unrealize(value, index);
|
||||
|
||||
|
||||
+4
-18
@@ -4,7 +4,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Shaders.Loaders;
|
||||
using ComputeSharp.D2D1.Uwp.Buffers;
|
||||
@@ -56,16 +55,17 @@ partial class PixelShaderEffect<T>
|
||||
{
|
||||
get
|
||||
{
|
||||
ValidateIndex(index);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16, nameof(index));
|
||||
default(ArgumentOutOfRangeException).ThrowIf((IndexBitmask & (1 << index)) == 0, nameof(index));
|
||||
|
||||
return Owner.GetResourceTextureManager(index);
|
||||
}
|
||||
set
|
||||
{
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, 16, nameof(index));
|
||||
default(ArgumentOutOfRangeException).ThrowIf((IndexBitmask & (1 << index)) == 0, nameof(index));
|
||||
default(ArgumentNullException).ThrowIfNull(value);
|
||||
|
||||
ValidateIndex(index);
|
||||
|
||||
Owner.SetResourceTextureManager(value, index);
|
||||
}
|
||||
}
|
||||
@@ -218,20 +218,6 @@ partial class PixelShaderEffect<T>
|
||||
throw new NotSupportedException("IList.RemoveAt is not supported for ResourceTextureManagerCollection.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the input index for <see cref="this[int]"/>.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to validate.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is out of range.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void ValidateIndex(int index)
|
||||
{
|
||||
if ((uint)index >= 16 || (IndexBitmask & (1 << index)) == 0)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The input index is not a valid resource texture manager index for the current effect.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bitmask of indices for resource textures in the target shader.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Interop;
|
||||
using ComputeSharp.D2D1.Uwp.Buffers;
|
||||
using ComputeSharp.D2D1.Uwp.Collections;
|
||||
@@ -50,13 +49,13 @@ partial class PixelShaderEffect<T>
|
||||
{
|
||||
get
|
||||
{
|
||||
ValidateIndex(index);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, D2D1PixelShader.GetInputCount<T>(), nameof(index));
|
||||
|
||||
return Owner.GetSource(index);
|
||||
}
|
||||
set
|
||||
{
|
||||
ValidateIndex(index);
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, D2D1PixelShader.GetInputCount<T>(), nameof(index));
|
||||
|
||||
Owner.SetSource(value, index);
|
||||
}
|
||||
@@ -205,20 +204,6 @@ partial class PixelShaderEffect<T>
|
||||
throw new NotSupportedException("IList.RemoveAt is not supported for SourceCollection.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Validates the input index for <see cref="this[int]"/>.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to validate.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="index"/> is out of range.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void ValidateIndex(int index)
|
||||
{
|
||||
if ((uint)index >= D2D1PixelShader.GetInputCount<T>())
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The input index is not a valid source index for the current effect.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the collection of valid indices for the current effect.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ComputeSharp.D2D1.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
internal static class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentException"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentException">Thrown with the specified parameters.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentException(string? name, string? message)
|
||||
{
|
||||
throw new ArgumentException(message, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeException(string? name)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="ArgumentOutOfRangeException"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">The argument name.</param>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowArgumentOutOfRangeException(string? name, string? message)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(name, message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="InvalidOperationException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="InvalidOperationException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowInvalidOperationException(string? message)
|
||||
{
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a new <see cref="NotSupportedException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to include in the exception.</param>
|
||||
/// <exception cref="NotSupportedException">Thrown with the specified parameter.</exception>
|
||||
[DoesNotReturn]
|
||||
public static void ThrowNotSupportedException(string? message)
|
||||
{
|
||||
throw new NotSupportedException(message);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Buffers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
|
||||
namespace ComputeSharp.D2D1.Shaders.Interop.Buffers;
|
||||
|
||||
@@ -40,10 +39,7 @@ internal sealed unsafe class PinnedBufferMemoryManager : MemoryManager<byte>
|
||||
/// <inheritdoc/>
|
||||
public override unsafe MemoryHandle Pin(int elementIndex = 0)
|
||||
{
|
||||
if ((uint)elementIndex >= this.length)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(elementIndex));
|
||||
}
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(elementIndex, 0, this.length);
|
||||
|
||||
return new(this.buffer + elementIndex);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
|
||||
namespace ComputeSharp.D2D1.Interop;
|
||||
|
||||
@@ -94,31 +93,31 @@ public static class D2D1EffectRegistrationData
|
||||
case LoadingResult.Success:
|
||||
return data;
|
||||
case LoadingResult.EmptyBuffer:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The input blob is empty.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The input blob is empty.");
|
||||
break;
|
||||
case LoadingResult.BufferTooShort:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The input blob is too short.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The input blob is too short.");
|
||||
break;
|
||||
case LoadingResult.BufferTooLong:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The input blob is too long.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The input blob is too long.");
|
||||
break;
|
||||
case LoadingResult.MismatchedBlobVersionId:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The blob version id from the input blob does not match.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The blob version id from the input blob does not match.");
|
||||
break;
|
||||
case LoadingResult.InvalidNumberOfInputs:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The input blob has an invalid number of inputs.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The input blob has an invalid number of inputs.");
|
||||
break;
|
||||
case LoadingResult.InvalidPropertyXml:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The property XML value in the input blob is invalid.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The property XML value in the input blob is invalid.");
|
||||
break;
|
||||
case LoadingResult.InvalidNumberOfBindings:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The input blob declares an invalid number of bindings.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The input blob declares an invalid number of bindings.");
|
||||
break;
|
||||
case LoadingResult.InvalidBindingPropertyName:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The input blob has an invalid property name for one of its property bindings.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The input blob has an invalid property name for one of its property bindings.");
|
||||
break;
|
||||
default:
|
||||
ThrowHelper.ThrowArgumentException(nameof(blob), "The input blob failed to be loaded for an unknown reason.");
|
||||
default(ArgumentException).Throw(nameof(blob), "The input blob failed to be loaded for an unknown reason.");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using ComputeSharp.D2D1.Shaders.Interop.Buffers;
|
||||
using ComputeSharp.D2D1.Shaders.Loaders;
|
||||
using TerraFX.Interop.DirectX;
|
||||
@@ -132,10 +131,7 @@ public static class D2D1PixelShader
|
||||
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1CompileOptions compileOptions)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if ((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(compileOptions), "The PackMatrixColumnMajor compile options is not compatible with ComputeSharp.D2D1 shaders.");
|
||||
}
|
||||
default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions));
|
||||
|
||||
return LoadOrCompileBytecode<T>(null, compileOptions | D2D1CompileOptions.PackMatrixRowMajor, out _, out _);
|
||||
}
|
||||
@@ -167,10 +163,7 @@ public static class D2D1PixelShader
|
||||
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1CompileOptions compileOptions, out D2D1ShaderProfile shaderProfile)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if ((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(compileOptions), "The PackMatrixColumnMajor compile options is not compatible with ComputeSharp.D2D1 shaders.");
|
||||
}
|
||||
default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions));
|
||||
|
||||
return LoadOrCompileBytecode<T>(null, compileOptions | D2D1CompileOptions.PackMatrixRowMajor, out shaderProfile, out _);
|
||||
}
|
||||
@@ -193,10 +186,7 @@ public static class D2D1PixelShader
|
||||
public static ReadOnlyMemory<byte> LoadBytecode<T>(D2D1ShaderProfile shaderProfile, D2D1CompileOptions compileOptions)
|
||||
where T : unmanaged, ID2D1PixelShader
|
||||
{
|
||||
if ((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0)
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(compileOptions), "The PackMatrixColumnMajor compile options is not compatible with ComputeSharp.D2D1 shaders.");
|
||||
}
|
||||
default(ArgumentException).ThrowIf((compileOptions & D2D1CompileOptions.PackMatrixColumnMajor) != 0, nameof(compileOptions));
|
||||
|
||||
return LoadOrCompileBytecode<T>(shaderProfile, compileOptions | D2D1CompileOptions.PackMatrixRowMajor, out _, out _);
|
||||
}
|
||||
@@ -280,10 +270,7 @@ public static class D2D1PixelShader
|
||||
{
|
||||
Unsafe.SkipInit(out T shader);
|
||||
|
||||
if ((uint)index >= shader.GetInputCount())
|
||||
{
|
||||
ThrowHelper.ThrowArgumentOutOfRangeException(nameof(index), "The input index is outside of range for the target pixel shader type.");
|
||||
}
|
||||
default(ArgumentOutOfRangeException).ThrowIfNotInRange(index, 0, (int)shader.GetInputCount());
|
||||
|
||||
return (D2D1PixelShaderInputType)shader.GetInputType((uint)index);
|
||||
}
|
||||
@@ -395,7 +382,7 @@ public static class D2D1PixelShader
|
||||
{
|
||||
if (!TryGetConstantBuffer(in shader, span, out int writtenBytes))
|
||||
{
|
||||
ThrowHelper.ThrowArgumentException(nameof(span), "The destination span is too short.");
|
||||
default(ArgumentException).Throw(nameof(span));
|
||||
}
|
||||
|
||||
return writtenBytes;
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using ComputeSharp.D2D1.__Internals;
|
||||
using ComputeSharp.D2D1.Extensions;
|
||||
using ComputeSharp.D2D1.Helpers;
|
||||
using TerraFX.Interop.DirectX;
|
||||
using TerraFX.Interop.Windows;
|
||||
|
||||
@@ -49,16 +48,9 @@ internal unsafe struct D2D1ShaderBytecodeLoader : ID2D1BytecodeLoader
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
unsafe void ID2D1BytecodeLoader.LoadDynamicBytecode(IntPtr handle)
|
||||
{
|
||||
if (this.embeddedBytecodePtr is not null ||
|
||||
this.d3DBlob.Get() is not null)
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("The shader has already been initialized.");
|
||||
}
|
||||
|
||||
if (handle == IntPtr.Zero)
|
||||
{
|
||||
ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration.");
|
||||
}
|
||||
default(InvalidOperationException).ThrowIf(this.embeddedBytecodePtr is not null);
|
||||
default(InvalidOperationException).ThrowIf(this.d3DBlob.Get() is not null);
|
||||
default(NotSupportedException).ThrowIf(handle == IntPtr.Zero);
|
||||
|
||||
this.d3DBlob = new ComPtr<ID3DBlob>((ID3DBlob*)handle);
|
||||
}
|
||||
@@ -67,11 +59,8 @@ internal unsafe struct D2D1ShaderBytecodeLoader : ID2D1BytecodeLoader
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
void ID2D1BytecodeLoader.LoadEmbeddedBytecode(ReadOnlySpan<byte> bytecode)
|
||||
{
|
||||
if (this.embeddedBytecodePtr is not null ||
|
||||
this.d3DBlob.Get() is not null)
|
||||
{
|
||||
ThrowHelper.ThrowInvalidOperationException("The shader has already been initialized.");
|
||||
}
|
||||
default(InvalidOperationException).ThrowIf(this.embeddedBytecodePtr is not null);
|
||||
default(InvalidOperationException).ThrowIf(this.d3DBlob.Get() is not null);
|
||||
|
||||
this.embeddedBytecodePtr = (byte*)Unsafe.AsPointer(ref MemoryMarshal.GetReference(bytecode));
|
||||
this.embeddedBytecodeSize = bytecode.Length;
|
||||
|
||||
@@ -35,7 +35,7 @@ internal struct ShaderBytecodeLoader : IBytecodeLoader
|
||||
public unsafe void LoadDynamicBytecode(IntPtr handle)
|
||||
{
|
||||
default(InvalidOperationException).ThrowIf(this.cachedShader is not null);
|
||||
default(InvalidOperationException).ThrowIf(handle == IntPtr.Zero);
|
||||
default(NotSupportedException).ThrowIf(handle == IntPtr.Zero);
|
||||
|
||||
this.cachedShader = new ICachedShader.Dynamic((IDxcBlob*)handle);
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする