diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs
index 484d75dc..b46bcfd2 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderSourceGenerator.Execute.cs
@@ -174,14 +174,14 @@ partial class D2DPixelShaderSourceGenerator
D2DPixelShaderSourceCompilationFailedWithWin32Exception,
sourceInfo.MethodName,
e.HResult,
- ID2D1ShaderGenerator.LoadBytecode.FixupExceptionMessage(e.Message));
+ D3DCompiler.PrettifyFxcErrorMessage(e.Message));
}
catch (FxcCompilationException e)
{
diagnostic = DeferredDiagnosticInfo.Create(
D2DPixelShaderSourceCompilationFailedWithFxcCompilationException,
sourceInfo.MethodName,
- ID2D1ShaderGenerator.LoadBytecode.FixupExceptionMessage(e.Message));
+ D3DCompiler.PrettifyFxcErrorMessage(e.Message));
}
End:
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs
index 733e10e6..1f9759b3 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadBytecodeMethod.cs
@@ -3,7 +3,6 @@ using System.Collections.Immutable;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
-using System.Text.RegularExpressions;
using System.Threading;
using ComputeSharp.D2D1.Exceptions;
using ComputeSharp.D2D1.Shaders.Translation;
@@ -188,25 +187,12 @@ partial class ID2D1ShaderGenerator
}
catch (Win32Exception e)
{
- return new HlslBytecodeInfo.Win32Error(FixupExceptionMessage(e.Message));
+ return new HlslBytecodeInfo.Win32Error(D3DCompiler.PrettifyFxcErrorMessage(e.Message));
}
catch (FxcCompilationException e)
{
- return new HlslBytecodeInfo.FxcError(FixupExceptionMessage(e.Message));
+ return new HlslBytecodeInfo.FxcError(D3DCompiler.PrettifyFxcErrorMessage(e.Message));
}
}
-
- ///
- /// Fixes up an exception message to improve the way it's displayed in VS.
- ///
- /// The input exception message.
- /// The updated exception message.
- internal static string FixupExceptionMessage(string message)
- {
- // Add square brackets around error headers
- message = Regex.Replace(message, @"((?:error|warning) \w+):", static m => $"[{m.Groups[1].Value}]:");
-
- return message.NormalizeToSingleLine();
- }
}
}
\ No newline at end of file
diff --git a/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs b/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs
index 3159873f..26f5fe00 100644
--- a/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs
+++ b/src/ComputeSharp.D2D1/Shaders/Translation/D3DCompiler.cs
@@ -175,16 +175,12 @@ internal static unsafe partial class D3DCompiler
}
///
- /// Throws an exception when a shader compilation fails.
+ /// Returns a "prettified" version of an FXC error message.
///
- /// The input (faulting) operation.
- /// This method always throws and never actually returs.
- [DoesNotReturn]
- [MethodImpl(MethodImplOptions.NoInlining)]
- private static void ThrowHslsCompilationException(ID3DBlob* d3DOperationResult)
+ /// The input error message.
+ /// The "prettified" error message.
+ public static string PrettifyFxcErrorMessage(string message)
{
- string message = new((sbyte*)d3DOperationResult->GetBufferPointer());
-
// The error message will be in a format like this:
// "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\Roslyn\Shader@0x0000019AD1B4BA70(22,32-35): error X3004: undeclared identifier 'this'"
// This regex tries to match the unnecessary header and remove it, if present. This doesn't need to be bulletproof, and this regex should match all cases anyway.
@@ -227,6 +223,21 @@ internal static unsafe partial class D3DCompiler
updatedMessage += '.';
}
+ return updatedMessage;
+ }
+
+ ///
+ /// Throws an exception when a shader compilation fails.
+ ///
+ /// The input (faulting) operation.
+ /// This method always throws and never actually returs.
+ [DoesNotReturn]
+ [MethodImpl(MethodImplOptions.NoInlining)]
+ private static void ThrowHslsCompilationException(ID3DBlob* d3DOperationResult)
+ {
+ string message = new((sbyte*)d3DOperationResult->GetBufferPointer());
+ string updatedMessage = PrettifyFxcErrorMessage(message);
+
throw new FxcCompilationException(updatedMessage);
}