diff --git a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md
index 7bd22acc..1320d2f5 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md
+++ b/src/ComputeSharp.D2D1.SourceGenerators/AnalyzerReleases.Shipped.md
@@ -52,3 +52,6 @@ CMPSD2D0042 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github
CMPSD2D0043 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0044 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
CMPSD2D0045 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+CMPSD2D0046 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+CMPSD2D0047 | ComputeSharp.D2D1.Shaders | Error | [Documentation](https://github.com/Sergio0694/ComputeSharp)
+CMPSD2D0048 | 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 a546df0a..7a916e99 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs
@@ -547,7 +547,7 @@ internal static class DiagnosticDescriptors
///
public static readonly DiagnosticDescriptor OutOfRangeInputIndex = new DiagnosticDescriptor(
id: "CMPSD2D0039",
- title: "Our of range D2D1 shader input indices",
+ title: "Out of range D2D1 shader input indices",
messageFormat: "The D2D1 shader of type {0} is using some out of range input indices",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
@@ -595,7 +595,7 @@ internal static class DiagnosticDescriptors
///
public static readonly DiagnosticDescriptor OutOfRangeInputDescriptionIndex = new DiagnosticDescriptor(
id: "CMPSD2D0042",
- title: "Our of range D2D1 shader input description indices",
+ title: "Out of range D2D1 shader input description indices",
messageFormat: "The D2D1 shader of type {0} is using some out of range input description indices",
category: "ComputeSharp.D2D1.Shaders",
defaultSeverity: DiagnosticSeverity.Error,
@@ -650,4 +650,52 @@ internal static class DiagnosticDescriptors
isEnabledByDefault: true,
description: "A D2D1 shader using functionality that needs position info (ie. when [D2DRequiresPosition] is used, which is mandatory when calling either D2D.GetScenePosition() or D2D.SampleInputAtPosition(int, float2)) needs to be annotated accordingly.",
helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
+
+ ///
+ /// Gets a for a shader with an out of range resource texture index (or more).
+ ///
+ /// Format: "The D2D1 shader of type {0} is using some out of range resource texture indices".
+ ///
+ ///
+ public static readonly DiagnosticDescriptor ResourceTextureIndexOverlappingWithInputIndex = new DiagnosticDescriptor(
+ id: "CMPSD2D0046",
+ title: "D2D1 shader resource texture indices overlapping input indices",
+ messageFormat: "The D2D1 shader of type {0} is using some resource texture indices that overlap with the shader input indices",
+ category: "ComputeSharp.D2D1.Shaders",
+ defaultSeverity: DiagnosticSeverity.Error,
+ isEnabledByDefault: true,
+ description: "A D2D1 shader must have all the indices of its resource textures in the valid range (between the input count and 16, exclusive).",
+ helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
+
+ ///
+ /// Gets a for a shader with an out of range resource texture index (or more).
+ ///
+ /// Format: "The D2D1 shader of type {0} is using some out of range resource texture indices".
+ ///
+ ///
+ public static readonly DiagnosticDescriptor OutOfRangeResourceTextureIndex = new DiagnosticDescriptor(
+ id: "CMPSD2D0047",
+ title: "Out of range D2D1 shader resource texture indices",
+ messageFormat: "The D2D1 shader of type {0} is using some out of range resource texture indices",
+ category: "ComputeSharp.D2D1.Shaders",
+ defaultSeverity: DiagnosticSeverity.Error,
+ isEnabledByDefault: true,
+ description: "A D2D1 shader must have all the indices of its resource textures in the valid range (between the input count and 16, exclusive).",
+ helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
+
+ ///
+ /// Gets a for repeated indices for D2D resource texture indices.
+ ///
+ /// Format: "The D2D1 shader of type {0} is using repeated indices for some of its [D2DResourceTextureIndex] attributes".
+ ///
+ ///
+ public static readonly DiagnosticDescriptor RepeatedD2DResourceTextureIndices = new DiagnosticDescriptor(
+ id: "CMPSD2D0048",
+ title: "Repeated D2D1 shader resource texture indices",
+ messageFormat: "The D2D1 shader of type {0} is using repeated indices for some of its [D2DResourceTextureIndex] attributes",
+ category: "ComputeSharp.D2D1.Shaders",
+ defaultSeverity: DiagnosticSeverity.Error,
+ isEnabledByDefault: true,
+ description: "A D2D1 shader must only have unique indices for all of its [D2DResourceTextureIndex] attributes.",
+ helpLinkUri: "https://github.com/Sergio0694/ComputeSharp");
}
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs
index 05000c74..f110aae9 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadInputDescriptionsMethod.cs
@@ -57,7 +57,7 @@ partial class ID2D1ShaderGenerator
inputDescriptions = ImmutableArray.Empty;
- // Validate the input count (ignore if invalid, this will be validated by the HLSL source generator)
+ // Validate the input count (ignore if invalid, this will be validated by GetInputType() generator)
if (inputCount is not (>= 0 and <= 8))
{
goto End;
diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs
index a16d3549..aaf1e680 100644
--- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs
+++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadResourceTextureDescriptionsMethod.cs
@@ -5,6 +5,7 @@ using ComputeSharp.D2D1.SourceGenerators.Models;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Mappings;
using Microsoft.CodeAnalysis;
+using static ComputeSharp.D2D1.SourceGenerators.Diagnostics.DiagnosticDescriptors;
namespace ComputeSharp.D2D1.SourceGenerators;
@@ -72,10 +73,19 @@ partial class ID2D1ShaderGenerator
// Extract the resource texture descriptions for the rest of the pipeline
resourceTextureDescriptions = resourceTextureInfos.Select(static info => new ResourceTextureDescription(info.Index, info.Rank)).ToImmutableArray();
+ // If the input count is invalid, do nothing and avoid emitting potentially incorrect
+ // diagnostics based on the resource texture indices with respect to the input count.
+ // The GetInputType() generator has already emitted diagnostic for this error, so this
+ // generator can just wait for users to go back and fix that issue before proceeding.
+ if (inputCount is not (>= 0 and <= 8))
+ {
+ return;
+ }
+
// Validate that the resource texture indices don't overlap with the shader inputs
if (resourceTextureInfos.Any(info => info.Index < inputCount))
{
- // TODO: overlap with textures
+ diagnostics.Add(ResourceTextureIndexOverlappingWithInputIndex, structDeclarationSymbol, structDeclarationSymbol);
return;
}
@@ -83,7 +93,7 @@ partial class ID2D1ShaderGenerator
// Validate that no resource texture has an index greater than or equal to 16
if (resourceTextureInfos.Any(info => info.Index >= 16))
{
- // TODO: diagnostic
+ diagnostics.Add(OutOfRangeResourceTextureIndex, structDeclarationSymbol, structDeclarationSymbol);
return;
}
@@ -93,7 +103,7 @@ partial class ID2D1ShaderGenerator
// All input description indices must be unique
if (resourceTextureIndices.Count != resourceTextureInfos.Count)
{
- // TODO: diagnostic
+ diagnostics.Add(RepeatedD2DResourceTextureIndices, structDeclarationSymbol, structDeclarationSymbol);
}
}
}