Skip generating for generic shader types, and warn
このコミットが含まれているのは:
1 親
4df52a9e40
コミット
bf7c470cb3
6ファイル変更
+26
-18
検索条件に一致するファイルはありません
@@ -39,8 +39,9 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
|
||||
return default;
|
||||
}
|
||||
|
||||
// If the type symbol doesn't have at least one interface, it can't possibly be a shader type
|
||||
if (context.TargetSymbol is not INamedTypeSymbol { AllInterfaces.Length: > 0 } typeSymbol)
|
||||
// If the type symbol doesn't have at least one interface, it can't possibly be a shader type.
|
||||
// Additionally, shader types cannot be generic (including nested inside generic types).
|
||||
if (context.TargetSymbol is not INamedTypeSymbol { AllInterfaces.Length: > 0, IsGenericType: false } typeSymbol)
|
||||
{
|
||||
return default;
|
||||
}
|
||||
|
||||
+6
-5
@@ -45,13 +45,14 @@ public sealed class InvalidGeneratedComputeShaderDescriptorAttributeTargetAnalyz
|
||||
return;
|
||||
}
|
||||
|
||||
// If the type doesn't implement IComputeShader nor IComputeShader<TPixel>, we can emit a diagnostic
|
||||
if (!MissingComputeShaderDescriptorOnComputeShaderAnalyzer.IsComputeShaderType(typeSymbol, computeShaderSymbol, pixelShaderSymbol))
|
||||
// If the type is generic or it doesn't implement IComputeShader nor IComputeShader<TPixel>, we emit a diagnostic
|
||||
if (typeSymbol.IsGenericType ||
|
||||
!MissingComputeShaderDescriptorOnComputeShaderAnalyzer.IsComputeShaderType(typeSymbol, computeShaderSymbol, pixelShaderSymbol))
|
||||
{
|
||||
context.ReportDiagnostic(Diagnostic.Create(
|
||||
InvalidGeneratedComputeShaderDescriptorAttributeTarget,
|
||||
attribute.GetLocation(),
|
||||
typeSymbol));
|
||||
InvalidGeneratedComputeShaderDescriptorAttributeTarget,
|
||||
attribute.GetLocation(),
|
||||
typeSymbol));
|
||||
}
|
||||
}, SymbolKind.NamedType);
|
||||
});
|
||||
|
||||
@@ -754,17 +754,17 @@ partial class DiagnosticDescriptors
|
||||
/// <summary>
|
||||
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[GeneratedComputeShaderDescriptor]</c> attribute is being used on an invalid target type.
|
||||
/// <para>
|
||||
/// Format: <c>"The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only types implementing the IComputeShader or IComputeShader<TPixel> interface are valid)"</c>.
|
||||
/// Format: <c>"The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only non generic types implementing the IComputeShader or IComputeShader<TPixel> interface are valid)"</c>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static readonly DiagnosticDescriptor InvalidGeneratedComputeShaderDescriptorAttributeTarget = new(
|
||||
id: "CMPS0054",
|
||||
title: "Invalid [GeneratedComputeShaderDescriptor] attribute target",
|
||||
messageFormat: "The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only types implementing the IComputeShader or IComputeShader<TPixel> interface are valid)",
|
||||
messageFormat: "The type {0} is not a valid target for the [GeneratedComputeShaderDescriptor] attribute (only non generic types implementing the IComputeShader or IComputeShader<TPixel> interface are valid)",
|
||||
category: "ComputeSharp.Shaders",
|
||||
defaultSeverity: DiagnosticSeverity.Error,
|
||||
isEnabledByDefault: true,
|
||||
description: "The [GeneratedComputeShaderDescriptor] attribute must be used on types that implement the IComputeShader or IComputeShader<TPixel> interfaces.",
|
||||
description: "The [GeneratedComputeShaderDescriptor] attribute must be used on non generic types that implement the IComputeShader or IComputeShader<TPixel> interfaces.",
|
||||
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
|
||||
|
||||
/// <summary>
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする