Add diagnostic for invalid method calls from shaders
このコミットが含まれているのは:
1 親
0c0d97e475
コミット
7318f5bd54
7ファイル変更
+76
-2
検索条件に一致するファイルはありません
@@ -55,3 +55,4 @@ CMPS0045 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Ser
|
||||
CMPS0046 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0047 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0048 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
CMPS0049 | ComputeSharp.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
@@ -680,4 +680,20 @@ internal static class DiagnosticDescriptors
|
||||
isEnabledByDefault: true,
|
||||
description: "The dispatch axis value for a shader marked as embedded bytecode have to be valid (flags are not supported).",
|
||||
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: "CMPS0049",
|
||||
title: "Invalid method invocation from a 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.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "Shaders can only invoke methods that are either HLSL intrinsics or with source available for analysis.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
@@ -416,8 +416,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)));
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする