diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs
index b2bc0a1f..2eb8d6a5 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs
+++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Helpers.cs
@@ -10,9 +10,9 @@ partial class ComputeShaderDescriptorGenerator
///
/// The input instance to check.
/// The instance currently in use.
- /// Whether is a "pixel shader like" type.
+ /// Whether is a "pixel shader like" type.
/// Whether is a compute shader type at all.
- private static bool TryGetIsPixelShaderLike(INamedTypeSymbol typeSymbol, Compilation compilation, out bool result)
+ private static bool TryGetIsPixelShaderLike(INamedTypeSymbol typeSymbol, Compilation compilation, out bool isPixelShaderLike)
{
INamedTypeSymbol computeShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader")!;
INamedTypeSymbol pixelShaderSymbol = compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader`1")!;
@@ -21,19 +21,19 @@ partial class ComputeShaderDescriptorGenerator
{
if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol))
{
- result = false;
+ isPixelShaderLike = false;
return true;
}
else if (SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol))
{
- result = true;
+ isPixelShaderLike = true;
return true;
}
}
- result = false;
+ isPixelShaderLike = false;
return false;
}
diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs
index 9e10d0b5..7e711a09 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs
+++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.HlslBytecode.cs
@@ -1,6 +1,4 @@
using ComputeSharp.SourceGeneration.Extensions;
-using ComputeSharp.SourceGeneration.Helpers;
-using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
namespace ComputeSharp.SourceGenerators;
@@ -16,10 +14,9 @@ partial class ComputeShaderDescriptorGenerator
///
/// Extracts the compile options for the current shader.
///
- /// The collection of produced instances.
/// The input instance to process.
/// The requested compile options to use to compile the shader, if present.
- public static CompileOptions GetCompileOptions(ImmutableArrayBuilder diagnostics, INamedTypeSymbol structDeclarationSymbol)
+ public static CompileOptions GetCompileOptions(INamedTypeSymbol structDeclarationSymbol)
{
// If a [CompileOptions] annotation is present, return the explicit options
if (structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.CompileOptionsAttribute", out AttributeData? attributeData) ||
diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs
index 2fd047af..1042650a 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs
+++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.NumThreads.cs
@@ -1,9 +1,5 @@
-using System;
using ComputeSharp.SourceGeneration.Extensions;
-using ComputeSharp.SourceGeneration.Helpers;
-using ComputeSharp.SourceGeneration.Models;
using Microsoft.CodeAnalysis;
-using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
namespace ComputeSharp.SourceGenerators;
@@ -18,14 +14,12 @@ partial class ComputeShaderDescriptorGenerator
///
/// Gets the thread ids values for a given shader type, if available.
///
- /// The collection of produced instances.
/// The input instance to process.
/// The thread ids value for the X axis.
/// The thread ids value for the Y axis.
/// The thread ids value for the Z axis.
/// Whether compilation should be attempted for the current info.
public static void GetInfo(
- ImmutableArrayBuilder diagnostics,
INamedTypeSymbol structDeclarationSymbol,
out int threadsX,
out int threadsY,
@@ -35,8 +29,6 @@ partial class ComputeShaderDescriptorGenerator
// Try to get the attribute that controls shader precompilation (this is always required)
if (!structDeclarationSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.ThreadGroupSizeAttribute", out AttributeData? attribute))
{
- diagnostics.Add(MissingThreadGroupSizeAttribute, structDeclarationSymbol, structDeclarationSymbol);
-
threadsX = threadsY = threadsZ = 0;
isCompilationEnabled = false;
@@ -44,11 +36,9 @@ partial class ComputeShaderDescriptorGenerator
}
// Check for a dispatch axis argument first
- if (attribute.ConstructorArguments.Length == 1)
+ if (attribute.ConstructorArguments is [{ Value: var defaultSize }])
{
- int defaultSize = (int)attribute.ConstructorArguments[0].Value!;
-
- (threadsX, threadsY, threadsZ) = (DefaultThreadGroupSizes)defaultSize switch
+ (threadsX, threadsY, threadsZ) = (DefaultThreadGroupSizes?)(defaultSize as int?) switch
{
DefaultThreadGroupSizes.X => (64, 1, 1),
DefaultThreadGroupSizes.Y => (1, 64, 1),
@@ -60,31 +50,15 @@ partial class ComputeShaderDescriptorGenerator
_ => (0, 0, 0)
};
- // Validate the dispatch axis argument
- if ((threadsX, threadsY, threadsZ) is (0, 0, 0))
- {
- diagnostics.Add(InvalidThreadGroupSizeAttributeDefaultThreadGroupSizes, structDeclarationSymbol, structDeclarationSymbol);
-
- threadsX = threadsY = threadsZ = 0;
- isCompilationEnabled = false;
-
- return;
- }
-
- isCompilationEnabled = true;
+ // Only enable compilation if we have valid thread group size values
+ isCompilationEnabled = (threadsX, threadsY, threadsZ) is not (0, 0, 0);
}
- else if (
- attribute.ConstructorArguments.Length != 3 ||
- attribute.ConstructorArguments[0].Value is not int explicitThreadsX ||
- attribute.ConstructorArguments[1].Value is not int explicitThreadsY ||
- attribute.ConstructorArguments[2].Value is not int explicitThreadsZ ||
- explicitThreadsX is < 1 or > 1024 ||
- explicitThreadsY is < 1 or > 1024 ||
- explicitThreadsZ is < 1 or > 64)
+ else if (attribute.ConstructorArguments is not [{ Value: int explicitThreadsX }, { Value: int explicitThreadsY }, { Value: int explicitThreadsZ }] ||
+ explicitThreadsX is < 1 or > 1024 ||
+ explicitThreadsY is < 1 or > 1024 ||
+ explicitThreadsZ is < 1 or > 64)
{
- // Failed to validate the thread number arguments
- diagnostics.Add(InvalidThreadGroupSizeAttributeValues, structDeclarationSymbol, structDeclarationSymbol);
-
+ // Also disable compilation if we have no valid explicit sizes
threadsX = threadsY = threadsZ = 0;
isCompilationEnabled = false;
@@ -92,6 +66,7 @@ partial class ComputeShaderDescriptorGenerator
}
else
{
+ // Enable compilation and track the explicit thread group sizes
threadsX = explicitThreadsX;
threadsY = explicitThreadsY;
threadsZ = explicitThreadsZ;
diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Resources.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Resources.cs
index e3b40133..50a3e545 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Resources.cs
+++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.Resources.cs
@@ -3,11 +3,9 @@ using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
using ComputeSharp.SourceGeneration.Mappings;
-using ComputeSharp.SourceGeneration.Models;
using ComputeSharp.SourceGeneration.SyntaxProcessors;
using ComputeSharp.SourceGenerators.Models;
using Microsoft.CodeAnalysis;
-using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
namespace ComputeSharp.SourceGenerators;
@@ -22,19 +20,15 @@ partial class ComputeShaderDescriptorGenerator
///
/// Gathers info on all resources captured by a given shader type.
///
- /// The collection of produced instances.
/// The input object currently in use.
/// The current shader type being explored.
/// Indicates whether the current shader uses an implicit texture.
- /// The size of the shader constant buffer.
/// The sequence of instances for all captured resources.
/// The sequence of instances for all captured resources.
public static void GetInfo(
- ImmutableArrayBuilder diagnostics,
Compilation compilation,
ITypeSymbol structDeclarationSymbol,
bool isImplicitTextureUsed,
- int constantBufferSizeInBytes,
out ImmutableArray resources,
out ImmutableArray resourceDescriptors)
{
@@ -96,19 +90,6 @@ partial class ComputeShaderDescriptorGenerator
resources = resourceBuilder.ToImmutable();
resourceDescriptors = resourceDescriptorBuilder.ToImmutable();
-
- // A shader root signature has a maximum size of 64 DWORDs, so 256 bytes.
- // Loaded values in the root signature have the following costs:
- // - Root constants cost 1 DWORD each, since they are 32-bit values.
- // - Descriptor tables cost 1 DWORD each.
- // - Root descriptors (64-bit GPU virtual addresses) cost 2 DWORDs each.
- // So here we check whether the current signature respects that constraint,
- // and emit a build error otherwise. For more info on this, see the docs here:
- // https://docs.microsoft.com/windows/win32/direct3d12/root-signature-limits.
- if ((constantBufferSizeInBytes / sizeof(int)) + resourceBuilder.Count > 64)
- {
- diagnostics.Add(ShaderDispatchDataSizeExceeded, structDeclarationSymbol, structDeclarationSymbol);
- }
}
///
diff --git a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs
index 10b60cfe..9fbceeb7 100644
--- a/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs
+++ b/src/ComputeSharp.SourceGenerators/ComputeShaderDescriptorGenerator.cs
@@ -59,8 +59,6 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
return default;
}
- using ImmutableArrayBuilder diagnostics = new();
-
// Get the fields info
ConstantBuffer.GetInfo(
context.SemanticModel.Compilation,
@@ -73,7 +71,6 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
// Thread group size info
NumThreads.GetInfo(
- diagnostics,
typeSymbol,
out int threadsX,
out int threadsY,
@@ -82,6 +79,13 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
token.ThrowIfCancellationRequested();
+ // Get the compile options as well
+ CompileOptions compileOptions = HlslBytecode.GetCompileOptions(typeSymbol);
+
+ token.ThrowIfCancellationRequested();
+
+ using ImmutableArrayBuilder diagnostics = new();
+
// Transpiled HLSL source info
HlslSource.GetInfo(
diagnostics,
@@ -97,23 +101,16 @@ public sealed partial class ComputeShaderDescriptorGenerator : IIncrementalGener
token.ThrowIfCancellationRequested();
- // Get the resources info
+ // Get the resources info (we must do this after crawling the HLSL source)
Resources.GetInfo(
- diagnostics,
context.SemanticModel.Compilation,
typeSymbol,
isImplicitTextureUsed,
- constantBufferSizeInBytes,
out ImmutableArray resourceInfo,
out ImmutableArray resourceDescriptors);
token.ThrowIfCancellationRequested();
- // Get the compile options as well
- CompileOptions compileOptions = HlslBytecode.GetCompileOptions(diagnostics, typeSymbol);
-
- token.ThrowIfCancellationRequested();
-
// Prepare the lookup key for the HLSL shader bytecode
HlslBytecodeInfoKey hlslInfoKey = new(hlslSource, compileOptions, isCompilationEnabled);
diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/ExcedeedComputeShaderDispatchDataSizeAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/ExcedeedComputeShaderDispatchDataSizeAnalyzer.cs
new file mode 100644
index 00000000..aca40737
--- /dev/null
+++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/ExcedeedComputeShaderDispatchDataSizeAnalyzer.cs
@@ -0,0 +1,153 @@
+using System.Collections.Immutable;
+using System.Linq;
+using ComputeSharp.Graphics.Helpers;
+using ComputeSharp.SourceGeneration.Extensions;
+using ComputeSharp.SourceGeneration.Mappings;
+using ComputeSharp.SourceGeneration.SyntaxProcessors;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.Diagnostics;
+using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
+
+namespace ComputeSharp.SourceGenerators;
+
+///
+/// A diagnostic analyzer that generates errors when a compute shader exceeds the maximum root descriptor size.
+///
+[DiagnosticAnalyzer(LanguageNames.CSharp)]
+public sealed class ExcedeedComputeShaderDispatchDataSizeAnalyzer : DiagnosticAnalyzer
+{
+ ///
+ public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(ShaderDispatchDataSizeExceeded);
+
+ ///
+ public override void Initialize(AnalysisContext context)
+ {
+ context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
+ context.EnableConcurrentExecution();
+
+ context.RegisterCompilationStartAction(static context =>
+ {
+ // Get the IComputeShader and IComputeShader symbols
+ if (context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader") is not { } computeShaderSymbol ||
+ context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader`1") is not { } pixelShaderSymbol)
+ {
+ return;
+ }
+
+ context.RegisterSymbolAction(context =>
+ {
+ // Only struct types are possible targets
+ if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol)
+ {
+ return;
+ }
+
+ // If the type is not a compute shader type, immediately bail out
+ if (!TryGetIsPixelShaderLike(typeSymbol, computeShaderSymbol, pixelShaderSymbol, out bool isPixelShaderLike))
+ {
+ return;
+ }
+
+ // Setup the resource and byte offsets for tracking. This is the same logic as
+ // in ComputeShaderDescriptorGenerator.ConstantBuffer, see there for more info.
+ int constantBufferSizeInBytes = sizeof(int) * (isPixelShaderLike ? 2 : 3);
+
+ // Run the fast-path constant buffer processor logic (same as in the equivalent D2D analyzer)
+ ConstantBufferSyntaxProcessor.GetInfo(
+ context.Compilation,
+ typeSymbol,
+ ref constantBufferSizeInBytes);
+
+ // Pad the size to get the number of root DWORD constants (see more notes in the same method)
+ constantBufferSizeInBytes = AlignmentHelper.Pad(constantBufferSizeInBytes, sizeof(int));
+
+ // Also get the number of captured resources
+ int resourceCount = GetNumberOfResources(typeSymbol);
+
+ // A shader root signature has a maximum size of 64 DWORDs, so 256 bytes.
+ // Loaded values in the root signature have the following costs:
+ // - Root constants cost 1 DWORD each, since they are 32-bit values.
+ // - Descriptor tables cost 1 DWORD each.
+ // - Root descriptors (64-bit GPU virtual addresses) cost 2 DWORDs each.
+ // So here we check whether the current signature respects that constraint,
+ // and emit a build error otherwise. For more info on this, see the docs here:
+ // https://docs.microsoft.com/windows/win32/direct3d12/root-signature-limits.
+ int numberOfDwordConstants = (constantBufferSizeInBytes / sizeof(int)) + resourceCount;
+
+ // Emit an error in case we have in fact exceeded that limit
+ if (numberOfDwordConstants > 64)
+ {
+ context.ReportDiagnostic(Diagnostic.Create(
+ ShaderDispatchDataSizeExceeded,
+ typeSymbol.Locations.First(),
+ typeSymbol,
+ numberOfDwordConstants));
+ }
+ }, SymbolKind.NamedType);
+ });
+ }
+
+ ///
+ /// Gets whether a given type is a compute shader type (ie. implements any of the interfaces).
+ ///
+ /// The input instance to check.
+ /// The for "ComputeSharp.IComputeShader".
+ /// The for "ComputeSharp.IComputeShader`1".
+ /// Whether is a "pixel shader like" type.
+ /// Whether is a compute shader type at all.
+ private static bool TryGetIsPixelShaderLike(
+ INamedTypeSymbol typeSymbol,
+ INamedTypeSymbol computeShaderSymbol,
+ INamedTypeSymbol pixelShaderSymbol,
+ out bool isPixelShaderLike)
+ {
+ foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.AllInterfaces)
+ {
+ if (SymbolEqualityComparer.Default.Equals(interfaceSymbol, computeShaderSymbol))
+ {
+ isPixelShaderLike = false;
+
+ return true;
+ }
+ else if (SymbolEqualityComparer.Default.Equals(interfaceSymbol.ConstructedFrom, pixelShaderSymbol))
+ {
+ isPixelShaderLike = true;
+
+ return true;
+ }
+ }
+
+ isPixelShaderLike = false;
+
+ return false;
+ }
+
+ ///
+ /// Gets the number of captured resources in a given compute shader type.
+ ///
+ /// The shader type to inspect.
+ /// The number of captured resources in the given shader type.
+ private static int GetNumberOfResources(ITypeSymbol typeSymbol)
+ {
+ int resourceCount = 0;
+
+ foreach (ISymbol memberSymbol in typeSymbol.GetMembers())
+ {
+ // Only process instance fields
+ if (memberSymbol is not IFieldSymbol { Type: INamedTypeSymbol, IsConst: false, IsStatic: false, IsFixedSizeBuffer: false } fieldSymbol)
+ {
+ continue;
+ }
+
+ string typeName = fieldSymbol.Type.GetFullyQualifiedMetadataName();
+
+ // Check if the field is a resource
+ if (HlslKnownTypes.IsTypedResourceType(typeName))
+ {
+ resourceCount++;
+ }
+ }
+
+ return resourceCount;
+ }
+}
\ No newline at end of file
diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidThreadGroupSizeAttributeUseAnalyzer.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidThreadGroupSizeAttributeUseAnalyzer.cs
new file mode 100644
index 00000000..1f7fb94b
--- /dev/null
+++ b/src/ComputeSharp.SourceGenerators/Diagnostics/Analyzers/InvalidThreadGroupSizeAttributeUseAnalyzer.cs
@@ -0,0 +1,102 @@
+using System.Collections.Immutable;
+using System.Linq;
+using ComputeSharp.SourceGeneration.Extensions;
+using Microsoft.CodeAnalysis;
+using Microsoft.CodeAnalysis.Diagnostics;
+using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
+
+namespace ComputeSharp.SourceGenerators;
+
+///
+/// A diagnostic analyzer that generates diagnostics for invalid uses of [ThreadGroupSize].
+///
+[DiagnosticAnalyzer(LanguageNames.CSharp)]
+public sealed class InvalidThreadGroupSizeAttributeUseAnalyzer : DiagnosticAnalyzer
+{
+ ///
+ public override ImmutableArray SupportedDiagnostics { get; } = ImmutableArray.Create(
+ MissingThreadGroupSizeAttribute,
+ InvalidThreadGroupSizeAttributeDefaultThreadGroupSizes,
+ InvalidThreadGroupSizeAttributeValues);
+
+ ///
+ public override void Initialize(AnalysisContext context)
+ {
+ context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
+ context.EnableConcurrentExecution();
+
+ context.RegisterCompilationStartAction(static context =>
+ {
+ // Get the IComputeShader, IComputeShader and [ThreadGroupSize] symbols
+ if (context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader") is not { } computeShaderSymbol ||
+ context.Compilation.GetTypeByMetadataName("ComputeSharp.IComputeShader`1") is not { } pixelShaderSymbol ||
+ context.Compilation.GetTypeByMetadataName("ComputeSharp.ThreadGroupSizeAttribute") is not { } threadGroupSizeAttributeSymbol)
+ {
+ return;
+ }
+
+ context.RegisterSymbolAction(context =>
+ {
+ // Only struct types are possible targets
+ if (context.Symbol is not INamedTypeSymbol { TypeKind: TypeKind.Struct } typeSymbol)
+ {
+ return;
+ }
+
+ // If the type is not a compute shader type, immediately bail out
+ if (!MissingComputeShaderDescriptorOnComputeShaderAnalyzer.IsComputeShaderType(typeSymbol, computeShaderSymbol, pixelShaderSymbol))
+ {
+ return;
+ }
+
+ // Warn if the shader type is not using [ThreadGroupSize]
+ if (!typeSymbol.TryGetAttributeWithType(threadGroupSizeAttributeSymbol, out AttributeData? attributeData))
+ {
+ context.ReportDiagnostic(Diagnostic.Create(
+ MissingThreadGroupSizeAttribute,
+ typeSymbol.Locations.First(),
+ typeSymbol));
+
+ return;
+ }
+
+ // If there is a single argument, validate that it is valid
+ if (attributeData.ConstructorArguments is [{ Value: var defaultSize }])
+ {
+ int? rawDefaultSize = defaultSize as int?;
+
+ if ((DefaultThreadGroupSizes?)rawDefaultSize is not
+ (DefaultThreadGroupSizes.X or
+ DefaultThreadGroupSizes.Y or
+ DefaultThreadGroupSizes.Z or
+ DefaultThreadGroupSizes.XY or
+ DefaultThreadGroupSizes.XZ or
+ DefaultThreadGroupSizes.YZ or
+ DefaultThreadGroupSizes.XYZ))
+ {
+ context.ReportDiagnostic(Diagnostic.Create(
+ InvalidThreadGroupSizeAttributeDefaultThreadGroupSizes,
+ attributeData.GetLocation(),
+ typeSymbol));
+ }
+
+ return;
+ }
+
+ // If there are three arguments, validate that they are also valid thread group sizes
+ if (attributeData.ConstructorArguments is not [{ Value: int threadsX }, { Value: int threadsY }, { Value: int threadsZ }] ||
+ threadsX is < 1 or > 1024 ||
+ threadsY is < 1 or > 1024 ||
+ threadsZ is < 1 or > 64)
+ {
+ context.ReportDiagnostic(Diagnostic.Create(
+ InvalidThreadGroupSizeAttributeValues,
+ attributeData.GetLocation(),
+ typeSymbol));
+
+ return;
+ }
+ }, SymbolKind.NamedType);
+ });
+ }
+}
\ No newline at end of file
diff --git a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
index 4cd5a7da..077458cb 100644
--- a/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
+++ b/src/ComputeSharp.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
@@ -560,17 +560,17 @@ partial class DiagnosticDescriptors
///
/// Gets a for a shader with a root signature that is too large.
///
- /// Format: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources".
+ /// Format: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources (the maximum size for the root signature is 64 DWORD constants, but the actual size was {1})".
///
///
public static readonly DiagnosticDescriptor ShaderDispatchDataSizeExceeded = new(
id: "CMPS0041",
title: "Shader dispatch data size exceeded",
- messageFormat: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources",
+ messageFormat: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources (the maximum size for the root signature is 64 DWORD constants, but the actual size was {1})",
category: "ComputeSharp.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
- description: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources.",
+ description: "The compute shader of type {0} has exceeded the maximum allowed size for captured values and resources (the maximum size for the root signature is 64 DWORD constants).",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
///
@@ -592,13 +592,13 @@ partial class DiagnosticDescriptors
///
/// Gets a for invalid thread group sizes.
///
- /// Format: "The shader of type {0} is annotated with invalid [ThreadGroupSize] values".
+ /// Format: "The [ThreadGroupSize] attribute on shader type {0} is using invalid thread group size values".
///
///
public static readonly DiagnosticDescriptor InvalidThreadGroupSizeAttributeValues = new(
id: "CMPS0044",
title: "Invalid values for [ThreadGroupSize] attribute",
- messageFormat: "The shader of type {0} is annotated with invalid [ThreadGroupSize] values",
+ messageFormat: "The [ThreadGroupSize] attribute on shader type {0} is using invalid thread group size values",
category: "ComputeSharp.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
@@ -656,13 +656,13 @@ partial class DiagnosticDescriptors
///
/// Gets a for shaders shader with an invalid DefaultThreadGroupSizes value.
///
- /// Format: "The shader of type {0} is using an invalid DefaultThreadGroupSizes value in its [ThreadGroupSize] attribute".
+ /// Format: "The [ThreadGroupSize] attribute on shader type {0} is using an invalid DefaultThreadGroupSizes value".
///
///
public static readonly DiagnosticDescriptor InvalidThreadGroupSizeAttributeDefaultThreadGroupSizes = new(
id: "CMPS0048",
title: "Invalid DefaultThreadGroupSizes value for [ThreadGroupSize] use",
- messageFormat: "The shader of type {0} is using an invalid DefaultThreadGroupSizes value in its [ThreadGroupSize] attribute",
+ messageFormat: "The [ThreadGroupSize] attribute on shader type {0} is using an invalid DefaultThreadGroupSizes value",
category: "ComputeSharp.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true,
diff --git a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs
index c834aab6..31ea0031 100644
--- a/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs
+++ b/tests/ComputeSharp.D2D1.Tests.SourceGenerators/Test_D2DPixelShaderDescriptorGenerator_Analyzers.cs
@@ -722,7 +722,6 @@ public class Test_D2DPixelShaderDescriptorGenerator_Analyzers
public float s0;
}
-
[D2DInputCount(0)]
internal readonly partial struct {|CMPSD2D0032:MyType|}(Data4 data4) : ID2D1PixelShader
{
diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs
index 447f4cee..3ef2ed33 100644
--- a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs
+++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator.cs
@@ -863,10 +863,12 @@ public class Test_ComputeShaderDescriptorGenerator
/// The task for the operation.
private static async Task VerifyGeneratedDiagnosticsAsync(string source, (string Filename, string Source) result)
{
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_Analyzers.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Analyzers.cs
similarity index 56%
rename from tests/ComputeSharp.Tests.SourceGenerators/Test_Analyzers.cs
rename to tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Analyzers.cs
index e0850fde..4ead59b9 100644
--- a/tests/ComputeSharp.Tests.SourceGenerators/Test_Analyzers.cs
+++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Analyzers.cs
@@ -6,7 +6,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace ComputeSharp.Tests.SourceGenerators;
[TestClass]
-public class Test_Analyzers
+public class Test_ComputeShaderDescriptorGenerator_Analyzers
{
[TestMethod]
public async Task MissingComputeShaderDescriptor_ComputeShader()
@@ -413,4 +413,292 @@ public class Test_Analyzers
await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
}
+
+ [TestMethod]
+ public async Task MissingThreadGroupSizeAttribute_MissingAttribute_Warns()
+ {
+ const string source = """
+ using ComputeSharp;
+
+ internal partial struct {|CMPS0047:MyType|} : IComputeShader
+ {
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task MissingThreadGroupSizeAttribute_AttributePresent_DoesNotWarn()
+ {
+ const string source = """
+ using ComputeSharp;
+
+ [ThreadGroupSize(8, 8, 8)]
+ internal partial struct MyType : IComputeShader
+ {
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task InvalidThreadGroupSizeAttributeDefaultThreadGroupSizes_Default_Warns()
+ {
+ const string source = """
+ using ComputeSharp;
+
+ [{|CMPS0048:ThreadGroupSize(default(DefaultThreadGroupSizes))|}]
+ internal partial struct MyType : IComputeShader
+ {
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task InvalidThreadGroupSizeAttributeDefaultThreadGroupSizes_OutOfRange_Warns()
+ {
+ const string source = """
+ using ComputeSharp;
+
+ [{|CMPS0048:ThreadGroupSize((DefaultThreadGroupSizes)1234)|}]
+ internal partial struct MyType : IComputeShader
+ {
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task InvalidThreadGroupSizeAttributeDefaultThreadGroupSizes_Valid_DoesNotWarn()
+ {
+ const string source = """
+ using ComputeSharp;
+
+ [ThreadGroupSize(DefaultThreadGroupSizes.XY)]
+ internal partial struct MyType : IComputeShader
+ {
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ [DataRow(-1, 1, 1)]
+ [DataRow(1, -1, 1)]
+ [DataRow(1, 1, -1)]
+ [DataRow(1050, 1, 1)]
+ [DataRow(1, 1050, 1)]
+ [DataRow(1, 1, 70)]
+ [DataRow(0, 123456, -12)]
+ public async Task InvalidThreadGroupSizeAttributeValues_OutOfRange_Warns(int threadsX, int threadsY, int threadsZ)
+ {
+ string source = $$"""
+ using ComputeSharp;
+
+ [{|CMPS0044:ThreadGroupSize({{threadsX}}, {{threadsY}}, {{threadsZ}})|}]
+ internal partial struct MyType : IComputeShader
+ {
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task InvalidThreadGroupSizeAttributeValues_Valid_DoesNotWarn()
+ {
+ const string source = """
+ using ComputeSharp;
+
+ [ThreadGroupSize(8, 8, 8)]
+ internal partial struct MyType : IComputeShader
+ {
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task ExceededDispatchDataSize_ConstantBufferTooLarge_WithNestedTypes_Warns()
+ {
+ const string source = """
+ using ComputeSharp;
+ using float1x3 = ComputeSharp.Float1x3;
+ using float2x2 = ComputeSharp.Float2x2;
+ using float3x2 = ComputeSharp.Float3x2;
+ using float4x4 = ComputeSharp.Float4x4;
+ using float2 = ComputeSharp.Float2;
+ using float3 = ComputeSharp.Float3;
+ using float4 = ComputeSharp.Float4;
+
+ public struct Data0
+ {
+ public float4x4 m0;
+ public float4 v0;
+ public float4 v1;
+ public float s0;
+ public float s1;
+ public float s2;
+ public float s3;
+ }
+
+ public struct Data1
+ {
+ public Data0 d0;
+ public Data0 d1;
+ public Data0 d2;
+ public Data0 d3;
+ public Data0 d4;
+ public float3x2 m0;
+ public float2x2 m1;
+ public float3 v0;
+ public float s0;
+ public float s1;
+ }
+
+ public struct Data2
+ {
+ public Data1 d0;
+ public Data1 d1;
+ public Data1 d2;
+ public Data1 d3;
+ public float2x2 m0;
+ public float1x3 m1;
+ public float3 v0;
+ public float4 v1;
+ public float2 v2;
+ public float s0;
+ }
+
+ internal partial struct {|CMPS0041:MyType|}(Data2 data2) : IComputeShader
+ {
+ ReadWriteBuffer result;
+
+ public void Execute()
+ {
+ result[ThreadIds.X] = data2.s0;
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task ExceededDispatchDataSize_ConstantBufferTooLarge_WithDoubles_Warns()
+ {
+ const string source = """
+ using ComputeSharp;
+ using double4x4 = ComputeSharp.Double4x4;
+ using float4 = ComputeSharp.Float4;
+
+ internal partial struct {|CMPS0041:MyType|} : IComputeShader
+ {
+ public readonly ReadWriteBuffer buffer;
+ public readonly double4x4 a;
+ public readonly double4x4 b;
+ public readonly int c;
+ public readonly float4 d;
+
+ public void Execute()
+ {
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
+
+ [TestMethod]
+ public async Task ExceededDispatchDataSize_ConstantBufferTooLarge_WithManyResources_Warns()
+ {
+ const string source = """
+ using ComputeSharp;
+ using float4x4 = ComputeSharp.Float4x4;
+ using float4 = ComputeSharp.Float4;
+
+ public struct Data0
+ {
+ public float4x4 m0;
+ public float4 v0;
+ public float4 v1;
+ public float4 v2;
+ public float s0;
+ public float s1;
+ public float s2;
+ public float s3;
+ }
+
+ internal partial struct {|CMPS0041:MyType|}(Data0 data0) : IComputeShader
+ {
+ ReadWriteBuffer result0;
+ ReadWriteBuffer result1;
+ ReadWriteBuffer result2;
+ ReadWriteBuffer result3;
+ ReadWriteBuffer result4;
+ ReadWriteBuffer result5;
+ ReadWriteBuffer result6;
+ ReadWriteBuffer result7;
+ ReadWriteBuffer result8;
+ ReadWriteBuffer result9;
+ ReadWriteBuffer result10;
+ ReadWriteBuffer result11;
+ ReadWriteBuffer result12;
+ ReadWriteBuffer result13;
+ ReadWriteBuffer result14;
+ ReadWriteBuffer result15;
+ ReadWriteBuffer result16;
+ ReadWriteBuffer result17;
+ ReadWriteBuffer result18;
+ ReadWriteBuffer result19;
+ ReadWriteBuffer result20;
+ ReadWriteBuffer result21;
+ ReadWriteBuffer result22;
+ ReadWriteBuffer result23;
+ ReadWriteBuffer result24;
+ ReadWriteBuffer result25;
+ ReadWriteBuffer result26;
+ ReadWriteBuffer result27;
+ ReadWriteBuffer result28;
+ ReadWriteBuffer result29;
+ ReadWriteBuffer result30;
+ ReadWriteBuffer result31;
+
+ public void Execute()
+ {
+ result0[ThreadIds.X] = data0.s0;
+ }
+ }
+ """;
+
+ await CSharpAnalyzerWithLanguageVersionTest.VerifyAnalyzerAsync(source);
+ }
}
\ No newline at end of file
diff --git a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs
index a0a4445b..2f4a468d 100644
--- a/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs
+++ b/tests/ComputeSharp.Tests.SourceGenerators/Test_ComputeShaderDescriptorGenerator_Diagnostics.cs
@@ -25,7 +25,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0001", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0001");
}
[TestMethod]
@@ -46,7 +46,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0001", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0001");
}
[TestMethod]
@@ -64,7 +64,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0005", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0005");
}
[TestMethod]
@@ -94,7 +94,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, diagnosticsId, "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, diagnosticsId);
}
[TestMethod]
@@ -121,7 +121,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, diagnosticsId, "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, diagnosticsId);
}
[TestMethod]
@@ -146,7 +146,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0006", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0006");
}
[TestMethod]
@@ -169,7 +169,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0050");
}
[TestMethod]
@@ -192,7 +192,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0010", "CMPS0031", "CMPS0050");
}
[TestMethod]
@@ -215,7 +215,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0011", "CMPS0031", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0011", "CMPS0031", "CMPS0050");
}
[TestMethod]
@@ -240,7 +240,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0012", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0012");
}
[TestMethod]
@@ -262,7 +262,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0012", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0012");
}
[TestMethod]
@@ -285,7 +285,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0012", "CMPS0013", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0012", "CMPS0013");
}
[TestMethod]
@@ -310,7 +310,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0014", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0014");
}
[TestMethod]
@@ -338,7 +338,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0015", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0015");
}
[TestMethod]
@@ -363,7 +363,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0016", "CMPS0032", "CMPS0035", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0016", "CMPS0032", "CMPS0035");
}
[TestMethod]
@@ -388,7 +388,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0017", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0017");
}
[TestMethod]
@@ -413,7 +413,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0018", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0018");
}
[TestMethod]
@@ -436,7 +436,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0019", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0019");
}
[TestMethod]
@@ -459,7 +459,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0020", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0020");
}
[TestMethod]
@@ -484,7 +484,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0021", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0021");
}
[TestMethod]
@@ -507,7 +507,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0022", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0022");
}
[TestMethod]
@@ -532,7 +532,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0023", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0023");
}
[TestMethod]
@@ -555,7 +555,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0024", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0024");
}
[TestMethod]
@@ -578,7 +578,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0032", "CMPS0025", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0032", "CMPS0025");
}
[TestMethod]
@@ -601,7 +601,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0026", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0026");
}
[TestMethod]
@@ -629,7 +629,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0027", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0027");
}
[TestMethod]
@@ -652,7 +652,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0028", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0028", "CMPS0050");
}
[TestMethod]
@@ -675,7 +675,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0050");
}
[TestMethod]
@@ -700,7 +700,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0029", "CMPS0031", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0029", "CMPS0031");
}
[TestMethod]
@@ -729,7 +729,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0030", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0030", "CMPS0050");
}
[TestMethod]
@@ -752,7 +752,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0031", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0031", "CMPS0050");
}
[TestMethod]
@@ -775,7 +775,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0032", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0032");
}
[TestMethod]
@@ -798,7 +798,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0033", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0033");
}
[TestMethod]
@@ -823,7 +823,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0034", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0034");
}
[TestMethod]
@@ -848,7 +848,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0035", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0035");
}
[TestMethod]
@@ -873,7 +873,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0035", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0035");
}
[TestMethod]
@@ -896,7 +896,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0036", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0036");
}
[TestMethod]
@@ -924,7 +924,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0037", "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0037", "CMPS0050");
}
[TestMethod]
@@ -948,7 +948,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0038", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0038");
}
[TestMethod]
@@ -972,7 +972,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040");
}
[TestMethod]
@@ -1001,7 +1001,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040");
}
[TestMethod]
@@ -1028,7 +1028,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040");
}
[TestMethod]
@@ -1052,7 +1052,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040");
}
[TestMethod]
@@ -1076,137 +1076,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040", "CMPS0047");
- }
-
- [TestMethod]
- public void ShaderDispatchDataSizeExceeded()
- {
- const string source = """
- using ComputeSharp;
- using double4x4 = ComputeSharp.Double4x4;
- using float4 = ComputeSharp.Float4;
-
- namespace MyFancyApp.Sample;
-
- [GeneratedComputeShaderDescriptor]
- public partial struct MyShader : IComputeShader
- {
- public readonly ReadWriteBuffer buffer;
- public readonly double4x4 a;
- public readonly double4x4 b;
- public readonly int c;
- public readonly float4 d;
-
- public void Execute()
- {
- }
- }
- """;
-
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0041", "CMPS0047");
- }
-
- [TestMethod]
- [DataRow(-1, 1, 1)]
- [DataRow(1, -1, 1)]
- [DataRow(1, 1, -1)]
- [DataRow(1050, 1, 1)]
- [DataRow(1, 1050, 1)]
- [DataRow(1, 1, 70)]
- public void InvalidThreadGroupSizeValues(int threadsX, int threadsY, int threadsZ)
- {
- string source = $$"""
- using System;
- using ComputeSharp;
-
- namespace MyFancyApp.Sample;
-
- [ThreadGroupSize({{threadsX}}, {{threadsY}}, {{threadsZ}})]
- [GeneratedComputeShaderDescriptor]
- public partial struct MyShader : IComputeShader
- {
- public ReadWriteBuffer buffer;
-
- public void Execute()
- {
- }
- }
- """;
-
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0044");
- }
-
- [TestMethod]
- public void InvalidThreadGroupSizeDispatchSize_Flags()
- {
- const string source = """
- using System;
- using ComputeSharp;
-
- namespace MyFancyApp.Sample;
-
- [ThreadGroupSize(default)]
- [GeneratedComputeShaderDescriptor]
- public partial struct MyShader : IComputeShader
- {
- public ReadWriteBuffer buffer;
-
- public void Execute()
- {
- }
- }
- """;
-
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0048");
- }
-
- [TestMethod]
- public void InvalidThreadGroupSizeDispatchSize_ExplicitValue()
- {
- const string source = """
- using System;
- using ComputeSharp;
-
- namespace MyFancyApp.Sample;
-
- [ThreadGroupSize((DefaultThreadGroupSizes)243712)]
- [GeneratedComputeShaderDescriptor]
- public partial struct MyShader : IComputeShader
- {
- public ReadWriteBuffer buffer;
-
- public void Execute()
- {
- }
- }
- """;
-
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0048");
- }
-
- [TestMethod]
- public void InvalidThreadGroupSizeDispatchSize_ExplicitValue_Negative()
- {
- const string source = """
- using System;
- using ComputeSharp;
-
- namespace MyFancyApp.Sample;
-
- [ThreadGroupSize((DefaultThreadGroupSizes)(-289))]
- [GeneratedComputeShaderDescriptor]
- public partial struct MyShader : IComputeShader
- {
- public ReadWriteBuffer buffer;
-
- public void Execute()
- {
- }
- }
- """;
-
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0048");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0040");
}
[TestMethod]
@@ -1230,7 +1100,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0049", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0049");
}
[TestMethod]
@@ -1254,7 +1124,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0063", "CMPS0047");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0063");
}
[TestMethod]
@@ -1278,7 +1148,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0050");
}
[TestMethod]
@@ -1308,7 +1178,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0050");
}
[TestMethod]
@@ -1336,7 +1206,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0050");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0050");
}
// See https://github.com/Sergio0694/ComputeSharp/issues/690
@@ -1363,7 +1233,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0059");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0059");
}
[TestMethod]
@@ -1389,7 +1259,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0059");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0059");
}
[TestMethod]
@@ -1410,7 +1280,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0031", "CMPS0047", "CMPS0059");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0031", "CMPS0059");
}
[TestMethod]
@@ -1431,7 +1301,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0031", "CMPS0047", "CMPS0060");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0031", "CMPS0060");
}
[TestMethod]
@@ -1464,7 +1334,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0061");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0061");
}
[TestMethod]
@@ -1493,7 +1363,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0049");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0049");
}
[TestMethod]
@@ -1525,7 +1395,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0062");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0062");
}
[TestMethod]
@@ -1562,7 +1432,7 @@ public class Test_ComputeShaderDescriptorGenerator_Diagnostics
}
""";
- CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0047", "CMPS0062");
+ CSharpGeneratorTest.VerifyDiagnostics(source, "CMPS0062");
}
[TestMethod]