diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs
index 2d44b94d..e78440aa 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs
+++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Runtime.CompilerServices;
-using System.Text.RegularExpressions;
using System.Threading;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
@@ -78,11 +77,11 @@ partial class ComputeShaderDescriptorGenerator
}
catch (Win32Exception e)
{
- return new HlslBytecodeInfo.Win32Error(e.NativeErrorCode, FixupExceptionMessage(e.Message));
+ return new HlslBytecodeInfo.Win32Error(e.NativeErrorCode, DxcShaderCompiler.FixupExceptionMessage(e.Message));
}
catch (DxcCompilationException e)
{
- return new HlslBytecodeInfo.CompilerError(FixupExceptionMessage(e.Message));
+ return new HlslBytecodeInfo.CompilerError(DxcShaderCompiler.FixupExceptionMessage(e.Message));
}
}
@@ -140,24 +139,5 @@ partial class ComputeShaderDescriptorGenerator
diagnostics.Add(diagnostic);
}
}
-
- ///
- /// Fixes up an exception message to improve the way it's displayed in VS.
- ///
- /// The input exception message.
- /// The updated exception message.
- private static string FixupExceptionMessage(string message)
- {
- // Add square brackets around error headers
- message = Regex.Replace(message, @"^(error|warning):", static m => $"[{m.Groups[1].Value}]:", RegexOptions.Multiline);
-
- // Remove lines with notes
- message = Regex.Replace(message, @"^note:.+", string.Empty, RegexOptions.Multiline);
-
- // Remove syntax error indicators
- message = Regex.Replace(message, @"^ +\^", string.Empty, RegexOptions.Multiline);
-
- return message.NormalizeToSingleLine();
- }
}
}
\ No newline at end of file
diff --git a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs
index 6b82a99f..f3cdf3f1 100644
--- a/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs
+++ b/src/ComputeSharp.SourceGenerators/Dxc/DxcShaderCompiler.cs
@@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Threading;
+using ComputeSharp.SourceGeneration.Extensions;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Graphics.Direct3D.Dxc;
@@ -274,6 +275,25 @@ internal sealed unsafe class DxcShaderCompiler
return (d3D12ShaderReflection.Get()->GetRequiresFlags() & doublePrecisionFlags) != 0;
}
+ ///
+ /// Fixes up an exception message to improve the way it's displayed in VS.
+ ///
+ /// The input exception message.
+ /// The updated exception message.
+ public static string FixupExceptionMessage(string message)
+ {
+ // Add square brackets around error headers
+ message = Regex.Replace(message, @"^(error|warning):", static m => $"[{m.Groups[1].Value}]:", RegexOptions.Multiline);
+
+ // Remove lines with notes
+ message = Regex.Replace(message, @"^note:.+", string.Empty, RegexOptions.Multiline);
+
+ // Remove syntax error indicators
+ message = Regex.Replace(message, @"^ +\^", string.Empty, RegexOptions.Multiline);
+
+ return message.NormalizeToSingleLine();
+ }
+
///
/// Throws an exception when a shader compilation fails.
///