Improve HLSL build error diagnostics for DX12 package

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:04:33 +02:00
1 親 14fa96998f
コミット e1d823a833
5ファイル変更
+94 -40

検索条件に一致するファイルはありません

+17
ファイルの表示
@@ -1,5 +1,6 @@
using System;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using ComputeSharp.Core.Extensions;
using ComputeSharp.Exceptions;
using TerraFX.Interop.DirectX;
@@ -151,6 +152,22 @@ internal sealed unsafe partial class ShaderCompiler
string message = new((sbyte*)dxcBlobEncodingError.Get()->GetBufferPointer());
// The error message will be in a format like this:
// "hlsl.hlsl:11:20: error: redefinition of 'float1' as different kind of symbol
// static const float float1 = asfloat(0xFFC00000);
// ^
// note: previous definition is here"
// These regex-s try to match the unnecessary headers and remove them, if present.
// This doesn't need to be bulletproof, and these regex-s should match all cases anyway.
message = Regex.Replace(message, @"^hlsl\.hlsl:\d+:\d+: (\w+:)", static m => m.Groups[1].Value, RegexOptions.Multiline);
// Add a trailing '.' if not present
if (message is { Length: > 0 } &&
message[message.Length - 1] != '.')
{
message += '.';
}
throw new DxcCompilationException(message);
}
}