Add additional diagnostics for invalid shader discovered types

このコミットが含まれているのは:
Sergio Pedri committed 2022-04-24 21:04:33 +02:00
1 親 7318f5bd54
コミット d51c0f5bf0
9ファイル変更
+173 -32

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

+1
ファイルの表示
@@ -47,3 +47,4 @@ CMPSD2D0037 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
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)
CMPSD2D0041 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+18 -2
ファイルの表示
@@ -555,16 +555,32 @@ internal static class DiagnosticDescriptors
/// <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>.
/// Format: <c>"The method {0} cannot be used in a D2D1 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)",
messageFormat: "The method {0} cannot be used in a D2D1 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");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid discovered type.
/// <para>
/// Format: <c>"The D2D1 shader of type {0} uses the invalid type {1}"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor InvalidDiscoveredType = new DiagnosticDescriptor(
id: "CMPSD2D0041",
title: "Invalid discovered type",
messageFormat: "The D2D1 shader of type {0} uses the invalid type {1} (only some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used)",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "D2D1 shaders can only use supported types (some .NET primitives and vector types, HLSL primitive, vector and matrix types, and custom types containing these types can be used).",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
@@ -56,7 +56,7 @@ partial class ID2D1ShaderGenerator
var semanticModelProvider = new SemanticModelProvider(compilation);
var valueFields = GetInstanceFields(builder, structDeclarationSymbol, discoveredTypes);
var (entryPoint, processedMethods) = GetProcessedMethods(builder, structDeclaration, structDeclarationSymbol, semanticModelProvider, discoveredTypes, staticMethods, constantDefinitions);
var declaredTypes = GetDeclaredTypes(discoveredTypes);
var declaredTypes = GetDeclaredTypes(builder, structDeclarationSymbol, discoveredTypes);
var definedConstants = GetDefinedConstants(constantDefinitions);
var staticFields = GetStaticFields(builder, semanticModelProvider, structDeclaration, structDeclarationSymbol, discoveredTypes, constantDefinitions);
@@ -310,13 +310,20 @@ partial class ID2D1ShaderGenerator
/// <summary>
/// Gets the sequence of processed discovered custom types.
/// </summary>
/// <param name="diagnostics">The collection of produced <see cref="Diagnostic"/> instances.</param>
/// <param name="structDeclarationSymbol">The type symbol for the shader type.</param>
/// <param name="types">The sequence of discovered custom types.</param>
/// <returns>A sequence of custom type definitions to add to the shader source.</returns>
private static ImmutableArray<(string Name, string Definition)> GetDeclaredTypes(IEnumerable<INamedTypeSymbol> types)
private static ImmutableArray<(string Name, string Definition)> GetDeclaredTypes(
ImmutableArray<Diagnostic>.Builder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
IEnumerable<INamedTypeSymbol> types)
{
ImmutableArray<(string, string)>.Builder builder = ImmutableArray.CreateBuilder<(string, string)>();
IReadOnlyCollection<INamedTypeSymbol> invalidTypes;
foreach (var type in HlslKnownTypes.GetCustomTypes(types))
// Process the discovered types
foreach (var type in HlslKnownTypes.GetCustomTypes(types, out invalidTypes))
{
var structType = type.GetFullMetadataName().ToHlslIdentifierName();
var structDeclaration = StructDeclaration(structType);
@@ -349,6 +356,12 @@ partial class ID2D1ShaderGenerator
.ToFullString()));
}
// Process the invalid types
foreach (INamedTypeSymbol invalidType in invalidTypes)
{
diagnostics.Add(InvalidDiscoveredType, structDeclarationSymbol, structDeclarationSymbol, invalidType);
}
return builder.ToImmutable();
}