From a028d3d93d0f88575f533ccae9dd43e6f0dc6362 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 24 Nov 2020 23:49:33 +0100 Subject: [PATCH] Fixed compilation error exception handling --- .../Exceptions/HlslCompilationException.cs | 11 +++++++---- .../Translation/ShaderCompiler.cs | 15 +++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs b/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs index 13a95b6d..840db2e6 100644 --- a/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs +++ b/src/ComputeSharp.Shaders/Exceptions/HlslCompilationException.cs @@ -19,11 +19,14 @@ namespace ComputeSharp.Exceptions [Pure] private static string GetExceptionMessage(string error) { - StringBuilder builder = new StringBuilder(); - builder.Append("The Dxc compiler encountered an error while trying to compile the shader."); + StringBuilder builder = new(512); + + 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.AppendLine("If you're sure that your C# shader code is valid, please open an issue an include a working repro and the following error message:"); - builder.AppendLine(error.TrimEnd()); + 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(); } diff --git a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs index d6c63147..2253debe 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs @@ -114,22 +114,13 @@ namespace ComputeSharp.Shaders.Translation /// This method always throws and never actually returs. [DoesNotReturn] [MethodImpl(MethodImplOptions.NoInlining)] - private static ComPtr ThrowHslsCompilationException(ComPtr dxcOperationResult) + private static ComPtr ThrowHslsCompilationException(IDxcOperationResult* dxcOperationResult) { using ComPtr dxcBlobEncodingError = default; - dxcOperationResult.Get()->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf()).Assert(); + dxcOperationResult->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf()).Assert(); - using ComPtr dxcBlobUtf16Error = default; - - DxcLibrary.Get()->GetBlobAsUtf16( - dxcBlobEncodingError.Upcast().Get(), - dxcBlobUtf16Error.Upcast().GetAddressOf()).Assert(); - - string message = new string( - (char*)dxcBlobUtf16Error.Get()->GetStringPointer(), - 0, - checked((int)dxcBlobUtf16Error.Get()->GetStringLength())); + string message = new((sbyte*)dxcBlobEncodingError.Get()->GetBufferPointer()); throw new HlslCompilationException(message); }