Add diagnostic for invalid method calls from shaders
このコミットが含まれているのは:
1 親
0c0d97e475
コミット
7318f5bd54
7ファイル変更
+76
-2
検索条件に一致するファイルはありません
@@ -46,3 +46,4 @@ CMPSD2D0036 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
|
||||
CMPSD2D0037 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPSD2D0038 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPSD2D0039 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPSD2D0040 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
@@ -551,4 +551,20 @@ internal static class DiagnosticDescriptors
|
||||
isEnabledByDefault: true,
|
||||
description: "A D2D1 shader must have all the indices of its simple and complex inputs in the valid range (between 0 and the number of declared inputs).",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for a method invocation that is not valid from a shader.
|
||||
/// <para>
|
||||
/// Format: <c>"The method {0} cannot be used in a shader (methods need to either be HLSL intrinsics or with source available for analysis)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidMethodCall = new DiagnosticDescriptor(
|
||||
id: "CMPSD2D0040",
|
||||
title: "Invalid method invocation from a D2D1 shader",
|
||||
messageFormat: "The method {0} cannot be used in a shader (methods need to either be HLSL intrinsics or with source available for analysis)",
|
||||
category: "ComputeSharp.D2D1.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "A D2D1 shader can only invoke methods that are either HLSL intrinsics or with source available for analysis.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
@@ -305,8 +305,14 @@ internal sealed class ShaderSourceRewriter : HlslSourceRewriter
|
||||
|
||||
if (!this.staticMethods.ContainsKey(method))
|
||||
{
|
||||
if (method.DeclaringSyntaxReferences.FirstOrDefault()?.GetSyntax() is not MethodDeclarationSyntax methodNode)
|
||||
{
|
||||
Diagnostics.Add(InvalidMethodCall, node, method);
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
ShaderSourceRewriter shaderSourceRewriter = new(SemanticModel, DiscoveredTypes, this.staticMethods, ConstantDefinitions, Diagnostics);
|
||||
MethodDeclarationSyntax methodNode = (MethodDeclarationSyntax)method.DeclaringSyntaxReferences[0].GetSyntax();
|
||||
MethodDeclarationSyntax processedMethod = shaderSourceRewriter.Visit(methodNode)!.NormalizeWhitespace(eol: "\n").WithoutTrivia();
|
||||
|
||||
this.staticMethods.Add(method, processedMethod.WithIdentifier(Identifier(methodIdentifier)));
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする