Added error for shaders with no resources
このコミットが含まれているのは:
1 親
103f3abbe1
コミット
74f60ad5c2
2ファイル変更
+36
-5
検索条件に一致するファイルはありません
@@ -70,5 +70,21 @@ namespace ComputeSharp.SourceGenerators.Diagnostics
|
||||
isEnabledByDefault: true,
|
||||
description: "A group shared field must be static.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for a shader with no resources.
|
||||
/// <para>
|
||||
/// Format: <c>"The compute shader of type {0} contains no resources to work on."</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static DiagnosticDescriptor MissingShaderResources { get; } = new(
|
||||
id: "CMPS0005",
|
||||
title: "Missing shader resources",
|
||||
messageFormat: "The compute shader of type {0} contains no resources to work on.",
|
||||
category: typeof(IComputeShader).FullName,
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "A compute shader must contain at least one resource.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
}
|
||||
}
|
||||
@@ -93,6 +93,8 @@ namespace ComputeSharp.SourceGenerators
|
||||
INamedTypeSymbol structDeclarationSymbol,
|
||||
ICollection<INamedTypeSymbol> types)
|
||||
{
|
||||
bool hlslResourceFound = false;
|
||||
|
||||
foreach (var fieldSymbol in structDeclarationSymbol.GetMembers().OfType<IFieldSymbol>())
|
||||
{
|
||||
if (fieldSymbol.IsStatic) continue;
|
||||
@@ -123,13 +125,18 @@ namespace ComputeSharp.SourceGenerators
|
||||
|
||||
string metadataName = typeSymbol.GetFullMetadataName();
|
||||
|
||||
// Track the type of items in the current buffer
|
||||
if (HlslKnownTypes.IsStructuredBufferType(metadataName))
|
||||
// Allowed fields must be either resources, unmanaged values or delegates
|
||||
if (HlslKnownTypes.IsTypedResourceType(metadataName))
|
||||
{
|
||||
types.Add((INamedTypeSymbol)typeSymbol.TypeArguments[0]);
|
||||
hlslResourceFound = true;
|
||||
|
||||
// Track the type of items in the current buffer
|
||||
if (HlslKnownTypes.IsStructuredBufferType(metadataName))
|
||||
{
|
||||
types.Add((INamedTypeSymbol)typeSymbol.TypeArguments[0]);
|
||||
}
|
||||
}
|
||||
else if (!HlslKnownTypes.IsTypedResourceType(metadataName) &&
|
||||
!typeSymbol.IsUnmanagedType &&
|
||||
else if (!typeSymbol.IsUnmanagedType &&
|
||||
typeSymbol.TypeKind != TypeKind.Delegate)
|
||||
{
|
||||
// Shaders can only capture valid HLSL resource types or unmanaged types
|
||||
@@ -148,6 +155,14 @@ namespace ComputeSharp.SourceGenerators
|
||||
// Yield back the current mapping for the name (if the name used a reserved keyword)
|
||||
yield return new[] { fieldSymbol.Name, mapping ?? fieldSymbol.Name, typeName };
|
||||
}
|
||||
|
||||
if (!hlslResourceFound)
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
DiagnosticDescriptors.MissingShaderResources,
|
||||
structDeclarationSymbol.Locations.FirstOrDefault(),
|
||||
structDeclarationSymbol));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする