diff --git a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj index f8982662..7fc70f5b 100644 --- a/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj +++ b/samples/ComputeSharp.Benchmark/ComputeSharp.Benchmark.csproj @@ -1,4 +1,4 @@ - + Exe @@ -21,6 +21,7 @@ + diff --git a/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj b/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj index bf266575..386056d1 100644 --- a/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj +++ b/samples/ComputeSharp.ImageProcessing/ComputeSharp.ImageProcessing.csproj @@ -12,6 +12,7 @@ + diff --git a/samples/ComputeSharp.Sample/Helpers/Formatting.cs b/samples/ComputeSharp.Sample/Helpers/Formatting.cs index 54c23634..ff4a1abb 100644 --- a/samples/ComputeSharp.Sample/Helpers/Formatting.cs +++ b/samples/ComputeSharp.Sample/Helpers/Formatting.cs @@ -1,7 +1,6 @@ using System; using System.Globalization; using System.Linq; -using CommunityToolkit.Diagnostics; namespace ComputeSharp.Sample; @@ -19,12 +18,6 @@ internal static class Formatting /// The name of the matrix to print. public static void PrintMatrix(float[] array, int width, int height, string name) { - Guard.IsNotNull(array); - Guard.IsGreaterThan(width, 0); - Guard.IsGreaterThan(height, 0); - Guard.IsEqualTo(array.Length, (long)width * height, nameof(array)); - Guard.IsNotNullOrEmpty(name); - int pad = 48 - name.Length; string title = $"{new string('=', pad / 2)} {name} {new string('=', (pad + 1) / 2)}"; diff --git a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj index 62a03e70..3c5b8b74 100644 --- a/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj +++ b/samples/ComputeSharp.SwapChain.Uwp/ComputeSharp.SwapChain.Uwp.csproj @@ -160,6 +160,9 @@ + + 8.1.0 + 8.1.0 diff --git a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj index 33c791d5..4b8cb8cf 100644 --- a/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj +++ b/samples/ComputeSharp.SwapChain.WinUI/ComputeSharp.SwapChain.WinUI.csproj @@ -29,6 +29,7 @@ + diff --git a/src/ComputeSharp.Core/Polyfills/NotSupportedExceptionExtensions.cs b/src/ComputeSharp.Core/Polyfills/NotSupportedExceptionExtensions.cs new file mode 100644 index 00000000..601b7876 --- /dev/null +++ b/src/ComputeSharp.Core/Polyfills/NotSupportedExceptionExtensions.cs @@ -0,0 +1,33 @@ +using System.Diagnostics.CodeAnalysis; + +namespace System; + +/// +/// Throw helper extensions for . +/// +internal static class NotSupportedExceptionExtensions +{ + /// + /// Throws an . + /// + /// Dummy value to invoke the extension upon (always pass . + /// Thrown with no parameters. + [DoesNotReturn] + public static void Throw(this NotSupportedException? _) + { + throw new NotSupportedException(); + } + + /// + /// Throws an for a given parameter name. + /// + /// The type to let the compiler assume it returns. + /// Dummy value to invoke the extension upon (always pass . + /// This method never returns any values. + /// Thrown with no parameters. + [DoesNotReturn] + public static T Throw(this NotSupportedException? _) + { + throw new NotSupportedException(); + } +} diff --git a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs index 7ec3bb05..f92c8808 100644 --- a/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs +++ b/src/ComputeSharp.Dynamic/Shaders/Translation/ShaderCompiler.LibraryLoading.cs @@ -3,7 +3,6 @@ using System; using System.IO; using System.Runtime.InteropServices; -using CommunityToolkit.Diagnostics; using TerraFX.Interop.Windows; namespace ComputeSharp.Shaders.Translation; @@ -31,7 +30,7 @@ unsafe partial class ShaderCompiler { Architecture.X64 => "win-x64", Architecture.Arm64 => "win-arm64", - _ => ThrowHelper.ThrowNotSupportedException("Invalid process architecture.") + _ => default(NotSupportedException).Throw() }; // Test whether the native libraries are present in the same folder of the executable diff --git a/src/ComputeSharp/ComputeSharp.csproj b/src/ComputeSharp/ComputeSharp.csproj index 79918a4f..f10eabdd 100644 --- a/src/ComputeSharp/ComputeSharp.csproj +++ b/src/ComputeSharp/ComputeSharp.csproj @@ -18,10 +18,6 @@ - - - - diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.IBufferWriter.cs b/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.IBufferWriter.cs index 8e3a90a5..54c34722 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.IBufferWriter.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.IBufferWriter.cs @@ -4,7 +4,6 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; #if NET6_0_OR_GREATER -using CommunityToolkit.Diagnostics; using TerraFX.Interop; #endif using TerraFX.Interop.Windows; @@ -49,7 +48,7 @@ unsafe partial class IWICStreamExtensions { #if NET6_0_OR_GREATER /// - static Guid* INativeGuid.NativeGuid => (Guid*)ThrowHelper.ThrowNotSupportedException(); + static Guid* INativeGuid.NativeGuid => (Guid*)default(NotSupportedException).Throw(); #else /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] diff --git a/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.Stream.cs b/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.Stream.cs index 57b348da..c471afd5 100644 --- a/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.Stream.cs +++ b/src/ComputeSharp/Graphics/Extensions/Interop/IWICStreamExtensions.Stream.cs @@ -3,7 +3,6 @@ using System.IO; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; -using CommunityToolkit.Diagnostics; #if NET6_0_OR_GREATER using TerraFX.Interop; #endif @@ -51,7 +50,7 @@ internal static unsafe partial class IWICStreamExtensions { #if NET6_0_OR_GREATER /// - static Guid* INativeGuid.NativeGuid => (Guid*)ThrowHelper.ThrowNotSupportedException(); + static Guid* INativeGuid.NativeGuid => (Guid*)default(NotSupportedException).Throw(); #else /// [UnmanagedFunctionPointer(CallingConvention.StdCall)] @@ -571,7 +570,7 @@ internal static unsafe partial class IWICStreamExtensions } else { - ThrowHelper.ThrowNotSupportedException(); + default(NotSupportedException).Throw(); } pstatstg->type = (uint)STGTY_STREAM; diff --git a/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs b/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs index 7d12c742..15f9f470 100644 --- a/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs +++ b/src/ComputeSharp/Graphics/GraphicsDevice.DeviceLost.cs @@ -35,7 +35,7 @@ unsafe partial class GraphicsDevice // For the same reason, this method doesn't have to worry about raising the event either. if (Volatile.Read(ref Unsafe.As(ref this.deviceRemovedReason)) != S.S_OK) { - static void Throw(object self) => throw new InvalidOperationException($"The device \"{self}\" has been lost and can no longer be used."); + static void Throw(object self) => throw new InvalidOperationException($"""The device "{self}" has been lost and can no longer be used."""); Throw(this); } diff --git a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs index 4a551e48..5e008830 100644 --- a/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs +++ b/src/ComputeSharp/Graphics/Helpers/DeviceHelper.cs @@ -1,5 +1,4 @@ using System; -using CommunityToolkit.Diagnostics; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Extensions; using TerraFX.Interop.DirectX; @@ -45,7 +44,7 @@ internal static partial class DeviceHelper return GetOrCreateDevice(d3D12Device.Get(), dxgiAdapter.Get(), &dxgiDescription1); } - return ThrowHelper.ThrowNotSupportedException("Failed to retrieve the default device."); + return default(NotSupportedException).Throw(); } /// diff --git a/src/ComputeSharp/Graphics/Resources/Views/TextureView2D{T}.cs b/src/ComputeSharp/Graphics/Resources/Views/TextureView2D{T}.cs index bfd0b0b9..dacdb730 100644 --- a/src/ComputeSharp/Graphics/Resources/Views/TextureView2D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Views/TextureView2D{T}.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel; using System.Runtime.CompilerServices; -using CommunityToolkit.Diagnostics; #pragma warning disable CS0809, CA1065 @@ -194,11 +193,8 @@ public readonly unsafe ref struct TextureView2D /// Thrown when doesn't match the size of the current instance. public void CopyTo(TextureView2D destination) { - if (destination.width != this.width || - destination.height != this.height) - { - ThrowHelper.ThrowArgumentException(); - } + default(ArgumentException).ThrowIf(destination.width != this.width, nameof(destination)); + default(ArgumentException).ThrowIf(destination.height != this.height, nameof(destination)); if (IsEmpty) { diff --git a/src/ComputeSharp/Graphics/Resources/Views/TextureView3D{T}.cs b/src/ComputeSharp/Graphics/Resources/Views/TextureView3D{T}.cs index d1d5ddb7..de271ed9 100644 --- a/src/ComputeSharp/Graphics/Resources/Views/TextureView3D{T}.cs +++ b/src/ComputeSharp/Graphics/Resources/Views/TextureView3D{T}.cs @@ -1,7 +1,6 @@ using System; using System.ComponentModel; using System.Runtime.CompilerServices; -using CommunityToolkit.Diagnostics; #pragma warning disable CS0809, CA1065 @@ -224,12 +223,9 @@ public readonly unsafe ref struct TextureView3D /// Thrown when doesn't match the size of the current instance. public void CopyTo(TextureView3D destination) { - if (destination.width != this.width || - destination.height != this.height || - destination.depth != this.depth) - { - ThrowHelper.ThrowArgumentException(); - } + default(ArgumentException).ThrowIf(destination.width != this.width, nameof(destination)); + default(ArgumentException).ThrowIf(destination.height != this.height, nameof(destination)); + default(ArgumentException).ThrowIf(destination.depth != this.depth, nameof(destination)); if (IsEmpty) { diff --git a/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs index c4c02754..0c6ddda1 100644 --- a/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs +++ b/src/ComputeSharp/Shaders/Dispatching/ShaderBytecodeLoader.cs @@ -1,6 +1,5 @@ using System; using System.Runtime.CompilerServices; -using CommunityToolkit.Diagnostics; using ComputeSharp.__Internals; using ComputeSharp.Shaders.Models; using TerraFX.Interop.DirectX; @@ -27,23 +26,16 @@ internal struct ShaderBytecodeLoader : IBytecodeLoader [MethodImpl(MethodImplOptions.AggressiveInlining)] public ICachedShader GetCachedShader() { - if (this.cachedShader is not ICachedShader cachedShader) - { - return ThrowHelper.ThrowInvalidOperationException("The shader has not been initialized."); - } + default(InvalidOperationException).ThrowIf(this.cachedShader is null); - return cachedShader; + return this.cachedShader; } /// public unsafe void LoadDynamicBytecode(IntPtr handle) { default(InvalidOperationException).ThrowIf(this.cachedShader is not null); - - if (handle == IntPtr.Zero) - { - ThrowHelper.ThrowNotSupportedException("Runtime shader compilation is not supported by the current configuration."); - } + default(InvalidOperationException).ThrowIf(handle == IntPtr.Zero); this.cachedShader = new ICachedShader.Dynamic((IDxcBlob*)handle); } diff --git a/tests/ComputeSharp.Tests.DeviceLost/ComputeSharp.Tests.DeviceLost.csproj b/tests/ComputeSharp.Tests.DeviceLost/ComputeSharp.Tests.DeviceLost.csproj index 9e55b7d2..26319e57 100644 --- a/tests/ComputeSharp.Tests.DeviceLost/ComputeSharp.Tests.DeviceLost.csproj +++ b/tests/ComputeSharp.Tests.DeviceLost/ComputeSharp.Tests.DeviceLost.csproj @@ -7,6 +7,7 @@ + diff --git a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj index a6298c32..9e941a11 100644 --- a/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj +++ b/tests/ComputeSharp.Tests.DisableDynamicCompilation/ComputeSharp.Tests.DisableDynamicCompilation.csproj @@ -7,6 +7,7 @@ + diff --git a/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj index 9a94155a..928d7b64 100644 --- a/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj +++ b/tests/ComputeSharp.Tests.Internals/ComputeSharp.Tests.Internals.csproj @@ -7,6 +7,7 @@ + diff --git a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj index dec3ee8d..b7d12abe 100644 --- a/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj +++ b/tests/ComputeSharp.Tests/ComputeSharp.Tests.csproj @@ -7,6 +7,7 @@ +