Share prettify logic for FXC error messages with generator
このコミットが含まれているのは:
1 親
50f3b74d3c
コミット
44849d5d3e
3ファイル変更
+23
-26
検索条件に一致するファイルはありません
@@ -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:
|
||||
|
||||
+2
-16
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fixes up an exception message to improve the way it's displayed in VS.
|
||||
/// </summary>
|
||||
/// <param name="message">The input exception message.</param>
|
||||
/// <returns>The updated exception message.</returns>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,16 +175,12 @@ internal static unsafe partial class D3DCompiler
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an exception when a shader compilation fails.
|
||||
/// Returns a "prettified" version of an FXC error message.
|
||||
/// </summary>
|
||||
/// <param name="d3DOperationResult">The input (faulting) operation.</param>
|
||||
/// <returns>This method always throws and never actually returs.</returns>
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static void ThrowHslsCompilationException(ID3DBlob* d3DOperationResult)
|
||||
/// <param name="message">The input error message.</param>
|
||||
/// <returns>The "prettified" error message.</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws an exception when a shader compilation fails.
|
||||
/// </summary>
|
||||
/// <param name="d3DOperationResult">The input (faulting) operation.</param>
|
||||
/// <returns>This method always throws and never actually returs.</returns>
|
||||
[DoesNotReturn]
|
||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private static void ThrowHslsCompilationException(ID3DBlob* d3DOperationResult)
|
||||
{
|
||||
string message = new((sbyte*)d3DOperationResult->GetBufferPointer());
|
||||
string updatedMessage = PrettifyFxcErrorMessage(message);
|
||||
|
||||
throw new FxcCompilationException(updatedMessage);
|
||||
}
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする