Added error for non static group shared buffer

このコミットが含まれているのは:
Sergio Pedri committed 2021-02-18 00:18:27 +01:00
1 親 e278ac8b36
コミット 707f0be5c4
3ファイル変更
+34 -2

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

+2 -1
ファイルの表示
@@ -7,4 +7,5 @@ Rule ID | Category | Severity | Notes
--------|----------|----------|-------
CMPS0001 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0002 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0003 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0003 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPS0004 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
+17 -1
ファイルの表示
@@ -47,12 +47,28 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
/// </summary>
public static DiagnosticDescriptor InvalidGroupSharedFieldElementType { get; } = new(
id: "CMPS0003",
title: "Invalid group shared field type",
title: "Invalid group shared field element type",
messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be a primitive or unmanaged type)",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A group shared field element must be of a primitive or unmanaged type.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid group shared field declaration.
/// <para>
/// Format: <c>"The compute shader of type {0} contains a group shared field \"{1}\" that is not static."</c>.
/// </para>
/// </summary>
public static DiagnosticDescriptor InvalidGroupSharedFieldDeclaration { get; } = new(
id: "CMPS0004",
title: "Invalid group shared field declaration",
messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" that is not static.",
category: typeof(IComputeShader).FullName,
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "A group shared field must be static.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
}
+15
ファイルの表示
@@ -97,6 +97,19 @@ namespace ComputeSharp.SourceGenerators
{
if (fieldSymbol.IsStatic) continue;
AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass is { Name: nameof(GroupSharedAttribute) });
// Group shared fields must be static
if (attribute is not null)
{
context.ReportDiagnostic(Diagnostic.Create(
DiagnosticDescriptors.InvalidGroupSharedFieldDeclaration,
fieldSymbol.Locations.FirstOrDefault(),
structDeclarationSymbol, fieldSymbol.Name));
continue;
}
// Captured fields must be named type symbols
if (fieldSymbol.Type is not INamedTypeSymbol typeSymbol)
{
@@ -121,6 +134,8 @@ namespace ComputeSharp.SourceGenerators
DiagnosticDescriptors.InvalidShaderField,
fieldSymbol.Locations.FirstOrDefault(),
structDeclarationSymbol, fieldSymbol.Name, typeSymbol));
continue;
}
string typeName = HlslKnownTypes.GetMappedName(typeSymbol);