diff --git a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md index e6f78fde..2678d236 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md +++ b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md @@ -57,3 +57,4 @@ CMPSD2D0047 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github CMPSD2D0048 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0049 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) CMPSD2D0050 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) +CMPSD2D0051 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp) diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index a1d5d3a2..0a87ce13 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -728,4 +728,20 @@ partial class DiagnosticDescriptors isEnabledByDefault: true, description: "All fields of a D2D1 resource texture type must be annotated using the [D2DResourceTextureIndex] attribute.", helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); + + /// + /// Gets a for a resource texture using an invalid element type. + /// + /// Format: "The field \"{0}\" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)". + /// + /// + public static readonly DiagnosticDescriptor InvalidResourceTextureElementType = new DiagnosticDescriptor( + id: "CMPSD2D0051", + title: "Missing [D2DResourceTextureIndex] attribute", + messageFormat: "The field \"{0}\" (in type {1}) using a D2D1 resource texture of type {2} has an invalid element type (only float and float4 type arguments are supported)", + category: "ComputeSharp.D2D1.Shaders", + defaultSeverity: DiagnosticSeverity.Error, + isEnabledByDefault: true, + description: "The element type of D2D1 resource texture fields in a D2D1 shader must be either float or float4.", + helpLinkUri: "https://github.com/Sergio0694/ComputeSharp"); } diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index 2e0ea8c3..a838ae1e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -132,6 +132,20 @@ partial class ID2D1ShaderGenerator // Handle resource textures as a special case if (HlslKnownTypes.IsResourceTextureType(metadataName)) { + ITypeSymbol resourceTextureTypeArgumentSymbol = typeSymbol.TypeArguments[0]; + + // Validate that the type argument is only either float or float4 + if (!resourceTextureTypeArgumentSymbol.HasFullyQualifiedName("System.Single") && + !resourceTextureTypeArgumentSymbol.HasFullyQualifiedName("ComputeSharp.Float4")) + { + diagnostics.Add( + InvalidResourceTextureElementType, + fieldSymbol, + fieldSymbol.Name, + structDeclarationSymbol, + fieldSymbol.Type); + } + int index = 0; // If [D2DResourceTextureIndex] is present, get the resource texture index.