From fcb2b5995642f2540f78175815634a2d0e1a96f7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 1 Dec 2020 18:30:15 +0100 Subject: [PATCH] Minor code tweaks --- .../Buffers/Abstract/Buffer{T}.cs | 4 +--- .../GraphicsDeviceMismatchException.cs | 17 +++++++++++++++-- .../Exceptions/HlslCompilationException.cs | 17 ++++++++++++----- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs index 7e9d13cf..e4880443 100644 --- a/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp.Graphics/Buffers/Abstract/Buffer{T}.cs @@ -279,9 +279,7 @@ namespace ComputeSharp.Graphics.Buffers.Abstract { if (GraphicsDevice != device) { - void Throw() => throw GraphicsDeviceMismatchException.Create(this, device); - - Throw(); + GraphicsDeviceMismatchException.Throw(this, device); } } } diff --git a/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs b/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs index edf3b8fe..fe2c4490 100644 --- a/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs +++ b/src/ComputeSharp.Graphics/Exceptions/GraphicsDeviceMismatchException.cs @@ -7,7 +7,7 @@ using ComputeSharp.Graphics.Buffers.Abstract; namespace ComputeSharp.Exceptions { /// - /// A custom that indicates when mismatched devices are being used. + /// A custom that indicates when mismatched devices are being used. /// public sealed class GraphicsDeviceMismatchException : InvalidOperationException { @@ -28,7 +28,7 @@ namespace ComputeSharp.Exceptions /// The target instance that was used. /// A new instance with a formatted error message. [Pure] - public static GraphicsDeviceMismatchException Create(Buffer buffer, GraphicsDevice device) + private static GraphicsDeviceMismatchException Create(Buffer buffer, GraphicsDevice device) where T : unmanaged { StringBuilder builder = new(512); @@ -41,5 +41,18 @@ namespace ComputeSharp.Exceptions return new(builder.ToString()); } + + /// + /// Throws a new instance from the specified parameters. + /// + /// The type of values in the input buffer. + /// The input that was used. + /// The target instance that was used. + [Pure] + internal static void Throw(Buffer buffer, GraphicsDevice device) + where T : unmanaged + { + throw Create(buffer, device); + } } } \ No newline at end of file diff --git a/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs b/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs index 840db2e6..bb94d393 100644 --- a/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs +++ b/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs @@ -5,17 +5,24 @@ using System.Text; namespace ComputeSharp.Exceptions { /// - /// A custom that indicates when mismatched devices are being used + /// A custom type that indicates when a shader compilation with the DXC compiler has failed. /// public sealed class HlslCompilationException : Exception { /// - /// Creates a new instance + /// Creates a new instance /// - /// The error message produced by the Dxc compiler - internal HlslCompilationException(string error) : base(GetExceptionMessage(error)) { } + /// The error message produced by the DXC compiler + internal HlslCompilationException(string error) + : base(GetExceptionMessage(error)) + { + } - // Gets a proper exception message for a given compilation error + /// + /// Gets a formatted exception message for a given compilation error. + /// + /// The input compilatin error message from the DXC compiler. + /// A formatted error message for a new instance. [Pure] private static string GetExceptionMessage(string error) {