Improve HLSL build errors for D2D1 shaders output message
このコミットが含まれているのは:
1 親
ee01ddd9db
コミット
1de2962ae3
2ファイル変更
+52
-3
検索条件に一致するファイルはありません
+51
-2
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Buffers;
|
||||
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;
|
||||
@@ -111,15 +113,62 @@ partial class ID2D1ShaderGenerator
|
||||
}
|
||||
catch (Win32Exception e)
|
||||
{
|
||||
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, e.Message);
|
||||
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithWin32Exception, e.HResult, FixupExceptionMessage(e.Message));
|
||||
}
|
||||
catch (FxcCompilationException e)
|
||||
{
|
||||
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithDxcCompilationException, e.Message);
|
||||
diagnostic = new DiagnosticInfo(EmbeddedBytecodeFailedWithDxcCompilationException, FixupExceptionMessage(e.Message));
|
||||
}
|
||||
|
||||
End:
|
||||
return bytecode;
|
||||
}
|
||||
|
||||
/// <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>
|
||||
private static string FixupExceptionMessage(string message)
|
||||
{
|
||||
// Add square brackets around error headers
|
||||
message = Regex.Replace(message, @"((?:error|warning) \w+):", static m => $"[{m.Groups[1].Value}]:");
|
||||
|
||||
char[] buffer = ArrayPool<char>.Shared.Rent(message.Length);
|
||||
int index = 0;
|
||||
char lastCharacter = '\0';
|
||||
|
||||
foreach (char newCharacter in message)
|
||||
{
|
||||
char pendingCharacter = newCharacter;
|
||||
|
||||
// Ignore '\r' characters
|
||||
if (pendingCharacter is '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert newlines to spaces (this avoids VS droppping multiline diagnostics)
|
||||
if (pendingCharacter is '\n')
|
||||
{
|
||||
pendingCharacter = ' ';
|
||||
}
|
||||
|
||||
// Drop duplicate spaces
|
||||
if (pendingCharacter is ' ' &&
|
||||
lastCharacter is ' ')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
buffer[index++] = lastCharacter = pendingCharacter;
|
||||
}
|
||||
|
||||
string text = buffer.AsSpan(0, index).ToString();
|
||||
|
||||
ArrayPool<char>.Shared.Return(buffer);
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ internal static unsafe partial class D2D1ShaderCompiler
|
||||
// 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.
|
||||
message = Regex.Replace(message, @"^[A-Z]:\\(?:[^\\]+\\)+Shader@0x[0-9A-F]+\([\d,-]+\): ", "");
|
||||
message = Regex.Replace(message, @"[A-Z]:\\[^:]+: (\w+ \w+:)", static m => m.Groups[1].Value).Trim();
|
||||
|
||||
// Add a trailing '.' if not present
|
||||
if (message is { Length: > 0 } &&
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする