Added errors for invalid group shared fields
このコミットが含まれているのは:
1 親
4b280bf2b6
コミット
4fe3c857be
4ファイル変更
+69
-6
検索条件に一致するファイルはありません
@@ -21,7 +21,7 @@ namespace ComputeSharp.Sample
|
||||
using ReadWriteBuffer<float> gpuBuffer = Gpu.Default.AllocateReadWriteBuffer(array);
|
||||
|
||||
// Run the shader
|
||||
Gpu.Default.For(100, new MainKernel(gpuBuffer));
|
||||
Gpu.Default.For(100, new MainKernel());
|
||||
|
||||
// Print the initial matrix
|
||||
PrintMatrix(array, width, height, "BEFORE");
|
||||
@@ -41,6 +41,9 @@ namespace ComputeSharp.Sample
|
||||
{
|
||||
public readonly ReadWriteBuffer<float> buffer;
|
||||
|
||||
[GroupShared]
|
||||
public static string[] Foo;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Execute()
|
||||
{
|
||||
|
||||
@@ -5,4 +5,6 @@
|
||||
|
||||
Rule ID | Category | Severity | Notes
|
||||
--------|----------|----------|-------
|
||||
CMPS0001 | ComputeSharp.IComputeShader | Error | IComputeShaderSourceGenerator, [Documentation](https://github.com/Sergio0694/ComputeSharp)
|
||||
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)
|
||||
@@ -22,5 +22,37 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
|
||||
isEnabledByDefault: true,
|
||||
description: "A type representing a compute shader contains a field of a type that is not supported in HLSL.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid group shared field type.
|
||||
/// <para>
|
||||
/// Format: <c>"The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2}"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static DiagnosticDescriptor InvalidGroupSharedFieldType { get; } = new(
|
||||
id: "CMPS0002",
|
||||
title: "Invalid group shared field type",
|
||||
messageFormat: "The compute shader of type {0} contains a group shared field \"{1}\" of an invalid type {2} (it must be an array)",
|
||||
category: typeof(IComputeShader).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "A group shared field must be of an array type.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for an invalid group shared field element type.
|
||||
/// <para>
|
||||
/// Format: <c>"The compute shader of type {0} contains a group shared field \"{1}\" of an invalid element type {2}"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static DiagnosticDescriptor InvalidGroupSharedFieldElementType { get; } = new(
|
||||
id: "CMPS0003",
|
||||
title: "Invalid group shared field 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");
|
||||
}
|
||||
}
|
||||
@@ -51,7 +51,7 @@ namespace ComputeSharp.SourceGenerators
|
||||
|
||||
// Explore the syntax tree and extract the processed info
|
||||
var processedMembers = GetProcessedMembers(context, structDeclarationSymbol, discoveredTypes).ToArray();
|
||||
var sharedBuffers = GetGroupSharedMembers(structDeclarationSymbol, discoveredTypes).ToArray();
|
||||
var sharedBuffers = GetGroupSharedMembers(context, structDeclarationSymbol, discoveredTypes).ToArray();
|
||||
var (entryPoint, localFunctions) = GetProcessedMethods(structDeclaration, structDeclarationSymbol, semanticModel, discoveredTypes, staticMethods, constantDefinitions);
|
||||
var processedTypes = GetProcessedTypes(discoveredTypes).ToArray();
|
||||
var processedMethods = localFunctions.Concat(staticMethods.Values).Select(static method => method.NormalizeWhitespace().ToFullString()).ToArray();
|
||||
@@ -135,19 +135,45 @@ namespace ComputeSharp.SourceGenerators
|
||||
/// <summary>
|
||||
/// Gets a sequence of captured members and their mapped names.
|
||||
/// </summary>
|
||||
/// <param name="context">The current generator context in use.</param>
|
||||
/// <param name="structDeclarationSymbol">The input <see cref="INamedTypeSymbol"/> instance to process.</param>
|
||||
/// <param name="types">The collection of currently discovered types.</param>
|
||||
/// <returns>A sequence of captured members in <paramref name="structDeclarationSymbol"/>.</returns>
|
||||
[Pure]
|
||||
private static IEnumerable<(string Name, string Type, int? Count)> GetGroupSharedMembers(INamedTypeSymbol structDeclarationSymbol, ICollection<INamedTypeSymbol> types)
|
||||
private static IEnumerable<(string Name, string Type, int? Count)> GetGroupSharedMembers(
|
||||
GeneratorExecutionContext context,
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
ICollection<INamedTypeSymbol> types)
|
||||
{
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (!fieldSymbol.IsStatic) continue;
|
||||
|
||||
AttributeData attribute = fieldSymbol.GetAttributes().First(static a => a.AttributeClass is { Name: nameof(GroupSharedAttribute) });
|
||||
AttributeData? attribute = fieldSymbol.GetAttributes().FirstOrDefault(static a => a.AttributeClass is { Name: nameof(GroupSharedAttribute) });
|
||||
|
||||
if (attribute is null) continue;
|
||||
|
||||
if (fieldSymbol.Type is not IArrayTypeSymbol typeSymbol)
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
DiagnosticDescriptors.InvalidGroupSharedFieldType,
|
||||
fieldSymbol.Locations.FirstOrDefault(),
|
||||
structDeclarationSymbol, fieldSymbol.Name, fieldSymbol.Type));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeSymbol.ElementType.IsUnmanagedType)
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
DiagnosticDescriptors.InvalidGroupSharedFieldElementType,
|
||||
fieldSymbol.Locations.FirstOrDefault(),
|
||||
structDeclarationSymbol, fieldSymbol.Name, fieldSymbol.Type));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
int? bufferSize = (int?)attribute.ConstructorArguments.FirstOrDefault().Value;
|
||||
IArrayTypeSymbol typeSymbol = (IArrayTypeSymbol)fieldSymbol.Type;
|
||||
|
||||
string typeName = HlslKnownTypes.GetMappedElementName(typeSymbol);
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする