diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs index 28f15412..ea0d2d07 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Diagnostics/DiagnosticDescriptors.cs @@ -475,13 +475,13 @@ internal static class DiagnosticDescriptors /// /// Gets a for a invalid D2D input count value. /// - /// Format: "The D2D1 shader of type {0} is using an incorrect value for [D2DInputCount] (the number of inputs must be in the [1, 8] range)". + /// Format: "The D2D1 shader of type {0} is using an incorrect value for [D2DInputCount] (the number of inputs must be in the [0, 8] range)". /// /// public static readonly DiagnosticDescriptor InvalidD2DInputCount = new DiagnosticDescriptor( id: "CMPSD2D0035", title: "Invalid D2D1 shader input count", - messageFormat: "The D2D1 shader of type {0} is using an incorrect value for [D2DInputCount] (the number of inputs must be in the [1, 8] range)", + messageFormat: "The D2D1 shader of type {0} is using an incorrect value for [D2DInputCount] (the number of inputs must be in the [0, 8] range)", category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, @@ -549,6 +549,6 @@ internal static class DiagnosticDescriptors category: "ComputeSharp.D2D1.Shaders", defaultSeverity: DiagnosticSeverity.Error, isEnabledByDefault: true, - description: "A D2D1 shader must have all the indices of its simple and complex inputs in the valid range (between 1 and the number of declared inputs).", + description: "A D2D1 shader must have all the indices of its simple and complex inputs in the valid range (between 0 and the number of declared inputs).", 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 8cdb0a82..50639df8 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -417,13 +417,19 @@ partial class ID2D1ShaderGenerator inputComplexIndices = inputComplexIndicesBuilder.ToImmutable(); // Validate the input count - if (rawInputCount is not (>= 1 and <= 8)) + if (rawInputCount is not (>= 0 and <= 8)) { diagnostics.Add(InvalidD2DInputCount, structDeclarationSymbol, structDeclarationSymbol); return; } + // All simple indices must be in range + if (inputSimpleIndicesBuilder.Concat(inputComplexIndicesBuilder).Any(i => (uint)i >= rawInputCount)) + { + diagnostics.Add(OutOfRangeInputIndex, structDeclarationSymbol, structDeclarationSymbol); + } + HashSet inputSimpleIndicesAsSet = new(inputSimpleIndicesBuilder); HashSet inputComplexIndicesAsSet = new(inputComplexIndicesBuilder); @@ -450,14 +456,6 @@ partial class ID2D1ShaderGenerator return; } - - int maxAllowedInputIndex = rawInputCount - 1; - - // All simple indices must be in range - if (inputSimpleIndicesBuilder.Concat(inputComplexIndicesBuilder).Any(i => i < 0 || i > maxAllowedInputIndex)) - { - diagnostics.Add(OutOfRangeInputIndex, structDeclarationSymbol, structDeclarationSymbol); - } } ///