From 9e93a557495ed66e55d6e88a0f0643e531717f5c Mon Sep 17 00:00:00 2001 From: Beyley Thomas Date: Tue, 11 Jan 2022 17:03:52 -0800 Subject: [PATCH] Add line number and shader stage to the SpirvCompilationException in CompileGlslToSpirv --- src/Veldrid.SPIRV/SpirvCompilation.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Veldrid.SPIRV/SpirvCompilation.cs b/src/Veldrid.SPIRV/SpirvCompilation.cs index d22836a..4a99ff1 100644 --- a/src/Veldrid.SPIRV/SpirvCompilation.cs +++ b/src/Veldrid.SPIRV/SpirvCompilation.cs @@ -1,5 +1,6 @@ using System; using System.Text; +using System.Text.RegularExpressions; namespace Veldrid.SPIRV { @@ -333,10 +334,19 @@ internal static unsafe SpirvCompilationResult CompileGlslToSpirv( try { result = VeldridSpirvNative.CompileGlslToSpirv(&info); - if (!result->Succeeded) + if (!result->Succeeded) { - throw new SpirvCompilationException( + SpirvCompilationException ex = new SpirvCompilationException( "Compilation failed: " + Util.GetString((byte*)result->GetData(0), result->GetLength(0))); + + MatchCollection mc = Regex.Matches(ex.Message, @":\d+:"); + if (mc.Count != 0) { + ex.Data.Add("LineNumber", int.Parse(mc[0].Value.Trim(':'))); + } + ex.Data.Add("ShaderStage", stage); + + + throw ex; } uint length = result->GetLength(0);