Skip generating for generic shader types, and warn

このコミットが含まれているのは:
Sergio Pedri committed 2023-11-26 16:35:20 +01:00
1 親 4df52a9e40
コミット bf7c470cb3
6ファイル変更
+26 -18

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

+3 -2
ファイルの表示
@@ -39,8 +39,9 @@ public sealed partial class D2DPixelShaderDescriptorGenerator : IIncrementalGene
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.
// Also check for generic types, just like with DX12 shaders (including nesting inside generics).
if (context.TargetSymbol is not INamedTypeSymbol { AllInterfaces.Length: > 0, IsGenericType: false } typeSymbol)
{
return default;
}
@@ -38,9 +38,14 @@ public sealed class InvalidD2DGeneratedPixelShaderDescriptorAttributeTargetAnaly
return;
}
// Emit a diagnostic if the target type is using [D2DGeneratedPixelShaderDescriptor] but does not implement ID2D1PixelShader
if (typeSymbol.TryGetAttributeWithType(d2DGeneratedPixelShaderDescriptorAttributeSymbol, out AttributeData? attribute) &&
!typeSymbol.HasInterfaceWithType(d2D1PixelShaderSymbol))
// If the type does not have [D2DGeneratedPixelShaderDescriptor], we can stop here
if (!typeSymbol.TryGetAttributeWithType(d2DGeneratedPixelShaderDescriptorAttributeSymbol, out AttributeData? attribute))
{
return;
}
// Emit a diagnostic if the target type is generic or does not implement ID2D1PixelShader
if (typeSymbol.IsGenericType || !typeSymbol.HasInterfaceWithType(d2D1PixelShaderSymbol))
{
context.ReportDiagnostic(Diagnostic.Create(
InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget,
+3 -3
ファイルの表示
@@ -978,17 +978,17 @@ partial class DiagnosticDescriptors
/// <summary>
/// Gets a <see cref="DiagnosticDescriptor"/> for when the <c>[D2DGeneratedPixelShaderDescriptor]</c> attribute is being used on an invalid target type.
/// <para>
/// Format: <c>"The type {0} is not a valid target for the [D2DGeneratedPixelShaderDescriptor] attribute (only types implementing the ID2D1PixelShader interface are valid)"</c>.
/// Format: <c>"The type {0} is not a valid target for the [D2DGeneratedPixelShaderDescriptor] attribute (only non generic types implementing the ID2D1PixelShader interface are valid)"</c>.
/// </para>
/// </summary>
public static readonly DiagnosticDescriptor InvalidD2DGeneratedPixelShaderDescriptorAttributeTarget = new(
id: "CMPSD2D0066",
title: "Invalid [D2DGeneratedPixelShaderDescriptor] attribute target",
messageFormat: "The type {0} is not a valid target for the [D2DGeneratedPixelShaderDescriptor] attribute (only types implementing ID2D1PixelShader interface are valid)",
messageFormat: "The type {0} is not a valid target for the [D2DGeneratedPixelShaderDescriptor] attribute (only non generic types implementing ID2D1PixelShader interface are valid)",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
description: "The [D2DGeneratedPixelShaderDescriptor] attribute must be used on types that implement the ID2D1PixelShader interface.",
description: "The [D2DGeneratedPixelShaderDescriptor] attribute must be used on non generic types that implement the ID2D1PixelShader interface.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
/// <summary>
+3 -2
ファイルの表示
@@ -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;
}
@@ -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);
});
+3 -3
ファイルの表示
@@ -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&lt;TPixel&gt; 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&lt;TPixel&gt; 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>