From e68861e6797cf80a40be1827b04130c93d9062d7 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 8 Apr 2022 19:56:48 +0200 Subject: [PATCH] Implement ID2D1Shader.LoadDispatchData generator --- ...eSharp.D2D1Interop.SourceGenerators.csproj | 3 + ...tor.CreateLoadDispatchDataMethod.Syntax.cs | 141 ++++++++++++++ ...rGenerator.CreateLoadDispatchDataMethod.cs | 177 ++++++++++++++++++ ...ers.cs => ID2D1ShaderGenerator.Helpers.cs} | 15 +- .../ID2D1ShaderGenerator.cs | 105 +++++++++++ .../IShaderGenerator.cs | 16 -- .../Models/DispatchDataInfo.cs | 8 - 7 files changed, 432 insertions(+), 33 deletions(-) create mode 100644 src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs create mode 100644 src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs rename src/ComputeSharp.D2D1Interop.SourceGenerators/{IShaderGenerator.Helpers.cs => ID2D1ShaderGenerator.Helpers.cs} (92%) create mode 100644 src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs delete mode 100644 src/ComputeSharp.D2D1Interop.SourceGenerators/IShaderGenerator.cs diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/ComputeSharp.D2D1Interop.SourceGenerators.csproj b/src/ComputeSharp.D2D1Interop.SourceGenerators/ComputeSharp.D2D1Interop.SourceGenerators.csproj index 241f979a..feb032ad 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/ComputeSharp.D2D1Interop.SourceGenerators.csproj +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ComputeSharp.D2D1Interop.SourceGenerators.csproj @@ -61,6 +61,9 @@ + + + diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs new file mode 100644 index 00000000..c2c0aceb --- /dev/null +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -0,0 +1,141 @@ +using System.Collections.Immutable; +using ComputeSharp.D2D1Interop.__Internals; +using ComputeSharp.D2D1Interop.SourceGenerators.Models; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; + +#pragma warning disable CS0618 + +namespace ComputeSharp.D2D1Interop.SourceGenerators; + +/// +partial class ID2D1ShaderGenerator +{ + /// + private static partial class LoadDispatchData + { + /// + /// Creates a instance for the LoadDispatchDataMethod method. + /// + /// The array of values for all captured fields. + /// The total number of needed 32 bit constants in the shader root signature. + /// The resulting instance for the LoadDispatchDataMethod method. + public static MethodDeclarationSyntax GetSyntax(ImmutableArray fieldInfos, int root32BitConstantsCount) + { + // This code produces a method declaration as follows: + // + // readonly void global::ComputeSharp.D2D1Interop.__Internals.ID2D1Shader.LoadDispatchData(ref TLoader loader) + // { + // + // } + return + MethodDeclaration( + PredefinedType(Token(SyntaxKind.VoidKeyword)), + Identifier("LoadDispatchData")) + .WithExplicitInterfaceSpecifier(ExplicitInterfaceSpecifier(IdentifierName($"global::ComputeSharp.D2D1Interop.__Internals.{nameof(ID2D1Shader)}"))) + .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword)) + .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader"))) + .AddParameterListParameters(Parameter(Identifier("loader")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(IdentifierName("TLoader"))) + .WithBody(Block(GetDispatchDataLoadingStatements(fieldInfos, root32BitConstantsCount))); + } + + /// + /// Gets a sequence of statements to load the dispatch data for a given shader. + /// + /// The array of values for all captured fields. + /// The total number of needed 32 bit constants in the shader root signature. + /// The sequence of instances to load shader dispatch data. + private static ImmutableArray GetDispatchDataLoadingStatements(ImmutableArray fieldInfos, int root32BitConstantsCount) + { + ImmutableArray.Builder statements = ImmutableArray.CreateBuilder(); + + // Generate loading statements for each captured field + foreach (FieldInfo fieldInfo in fieldInfos) + { + switch (fieldInfo) + { + case FieldInfo.Primitive primitive: + + // Read a primitive value and serialize it into the target buffer. This will generate: + // + // global::System.Runtime.CompilerServices.Unsafe.As>( + // ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint))) = + statements.Add(ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){primitive.Offset}))"), + ParseExpression($"{string.Join(".", primitive.FieldPath)}")))); + break; + + case FieldInfo.NonLinearMatrix matrix: + string rowTypeName = $"global::ComputeSharp.{matrix.ElementName}{matrix.Columns}"; + string rowLocalName = $"__{string.Join("_", matrix.FieldPath)}__row0"; + + // Declare a local to index into individual rows. This will generate: + // + // ref = ref global::System.Runtime.CompilerServices.Unsafe.As, >( + // ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in )); + statements.Add(ParseStatement($"ref {rowTypeName} {rowLocalName} = ref global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in {string.Join(".", matrix.FieldPath)}));")); + + // Generate the loading code for each individual row, with proper alignment. + // This will result in the following (assuming Float2x3 m): + // + // ref global::ComputeSharp.Float3 __m__row0 = ref global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AsRef(in m)); + // global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint)rawDataOffset)) =, global::System.Runtime.CompilerServices.Unsafe.Add(ref __m__row0, 0); + // global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint)(rawDataOffset + 16))) = global::System.Runtime.CompilerServices.Unsafe.Add(ref __m__row0, 1); + for (int j = 0; j < matrix.Rows; j++) + { + statements.Add(ExpressionStatement( + AssignmentExpression( + SyntaxKind.SimpleAssignmentExpression, + ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.As(ref global::System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref r0, (nint){matrix.Offsets[j]}))"), + ParseExpression($"global::System.Runtime.CompilerServices.Unsafe.Add(ref {rowLocalName}, {j})")))); + } + break; + } + } + + // global::System.Span span0 = stackalloc uint[]; + statements.Insert(0, + LocalDeclarationStatement( + VariableDeclaration( + GenericName(Identifier("global::System.Span")) + .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.UIntKeyword)))) + .AddVariables( + VariableDeclarator(Identifier("span0")) + .WithInitializer(EqualsValueClause( + StackAllocArrayCreationExpression( + ArrayType(PredefinedType(Token(SyntaxKind.UIntKeyword))) + .AddRankSpecifiers( + ArrayRankSpecifier(SingletonSeparatedList( + LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(root32BitConstantsCount))))))))))); + + // ref uint r0 = ref span0[0]; + statements.Insert(1, + LocalDeclarationStatement( + VariableDeclaration(RefType(PredefinedType(Token(SyntaxKind.UIntKeyword)))) + .AddVariables( + VariableDeclarator(Identifier("r0")) + .WithInitializer(EqualsValueClause( + RefExpression( + ElementAccessExpression(IdentifierName("span0")) + .AddArgumentListArguments(Argument( + LiteralExpression( + SyntaxKind.NumericLiteralExpression, + Literal(0)))))))))); + + // loader.LoadCapturedValues(span0); + statements.Add( + ExpressionStatement( + InvocationExpression( + MemberAccessExpression( + SyntaxKind.SimpleMemberAccessExpression, + IdentifierName("loader"), + IdentifierName("LoadCapturedValues"))) + .AddArgumentListArguments(Argument(IdentifierName("span0"))))); + + return statements.ToImmutable(); + } + } +} diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs new file mode 100644 index 00000000..775dd4c3 --- /dev/null +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Collections.Immutable; +using System.Linq; +using System.Runtime.CompilerServices; +using ComputeSharp.Core.Helpers; +using ComputeSharp.D2D1Interop.SourceGenerators.Diagnostics; +using ComputeSharp.D2D1Interop.SourceGenerators.Extensions; +using ComputeSharp.D2D1Interop.SourceGenerators.Mappings; +using ComputeSharp.D2D1Interop.SourceGenerators.Models; +using Microsoft.CodeAnalysis; +using static ComputeSharp.D2D1Interop.SourceGenerators.Diagnostics.DiagnosticDescriptors; + +namespace ComputeSharp.D2D1Interop.SourceGenerators; + +/// +public sealed partial class ID2D1ShaderGenerator +{ + /// + /// A helper with all logic to generate the LoadDispatchData method. + /// + private static partial class LoadDispatchData + { + /// + /// Explores a given type hierarchy and generates statements to load fields. + /// + /// The current shader type being explored. + /// The total number of needed 32 bit constants in the shader root signature. + /// The resulting diagnostics from the processing operation. + /// The sequence of instances for all captured resources and values. + public static ImmutableArray GetInfo( + ITypeSymbol structDeclarationSymbol, + out int root32BitConstantCount, + out ImmutableArray diagnostics) + { + // Helper method that uses boxes instead of ref-s (illegal in enumerators) + static IEnumerable GetCapturedFieldInfos( + ITypeSymbol currentTypeSymbol, + ImmutableArray fieldPath, + StrongBox rawDataOffset) + { + bool isFirstField = true; + + foreach ( + IFieldSymbol fieldSymbol in + from fieldSymbol in currentTypeSymbol.GetMembers().OfType() + where fieldSymbol.Type is INamedTypeSymbol { IsStatic: false } && + !fieldSymbol.IsConst && !fieldSymbol.IsStatic && + !fieldSymbol.IsFixedSizeBuffer + select fieldSymbol) + { + string fieldName = fieldSymbol.Name; + string typeName = fieldSymbol.Type.GetFullMetadataName(); + + // Disambiguates the name of target fields against the current input parameters + if (fieldName is "loader") + { + fieldName = $"this.{fieldName}"; + } + + // The first item in each nested struct needs to be aligned to 16 bytes + if (isFirstField && fieldPath.Length > 0) + { + rawDataOffset.Value = AlignmentHelper.Pad(rawDataOffset.Value, 16); + + isFirstField = false; + } + + if (HlslKnownTypes.IsKnownHlslType(typeName)) + { + yield return GetHlslKnownTypeFieldInfo(fieldPath.Add(fieldName), typeName, ref rawDataOffset.Value); + } + else if (fieldSymbol.Type.IsUnmanagedType) + { + // Custom struct type defined by the user + foreach (var fieldInfo in GetCapturedFieldInfos(fieldSymbol.Type, fieldPath.Add(fieldName), rawDataOffset)) + { + yield return fieldInfo; + } + } + } + } + + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(); + + // Setup the resource and byte offsets for tracking + StrongBox rawDataOffsetAsBox = new(); + + // Traverse all shader fields and gather info, and update the tracking offsets + ImmutableArray fieldInfos = GetCapturedFieldInfos( + structDeclarationSymbol, + ImmutableArray.Empty, + rawDataOffsetAsBox).ToImmutableArray(); + + // After all the captured fields have been processed, ansure the reported byte size for + // the local variables is padded to a multiple of a 32 bit value. This is necessary to + // enable loading all the dispatch data after reinterpreting it to a sequence of values + // of size 32 bits (via SetComputeRoot32BitConstants), without reading out of bounds. + root32BitConstantCount = AlignmentHelper.Pad(rawDataOffsetAsBox.Value, sizeof(int)) / sizeof(int); + + // 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 rootSignatureDwordSize = root32BitConstantCount; + + if (rootSignatureDwordSize > 64) + { + builder.Add(ShaderDispatchDataSizeExceeded, structDeclarationSymbol, structDeclarationSymbol); + } + + diagnostics = builder.ToImmutable(); + + return fieldInfos; + } + + /// + /// Gets info on a given captured HLSL primitive type (either a scalar, a vector or a matrix). + /// + /// The current path of the field with respect to the shader instance. + /// The type name currently being read. + /// The current offset within the loaded data buffer. + private static FieldInfo GetHlslKnownTypeFieldInfo( + ImmutableArray fieldPath, + string typeName, + ref int rawDataOffset) + { + // For scalar, vector and linear matrix types, serialize the value normally. + // Only the initial alignment needs to be considered, while data is packed. + var (fieldSize, fieldPack) = HlslKnownSizes.GetTypeInfo(typeName); + + // Check if the current type is a matrix type with more than one row. In this + // case, each row is aligned as if it was a separate array, so the start of + // each row needs to be at a multiple of 16 bytes (a float4 register). + if (HlslKnownTypes.IsNonLinearMatrixType(typeName, out string? elementName, out int rows, out int columns)) + { + ImmutableArray.Builder builder = ImmutableArray.CreateBuilder(rows); + + for (int j = 0; j < rows; j++) + { + int startingRawDataOffset = AlignmentHelper.Pad(rawDataOffset, 16); + + builder.Add(startingRawDataOffset); + + rawDataOffset = startingRawDataOffset + fieldPack * columns; + } + + return new FieldInfo.NonLinearMatrix( + fieldPath, + typeName, + elementName!, + rows, + columns, + builder.MoveToImmutable()); + } + else + { + // Calculate the right offset with 16-bytes padding (HLSL constant buffer). + // Since we're in a constant buffer, we need to both pad the starting offset + // to be aligned to the packing size of the type, and also to align the initial + // offset to ensure that values do not cross 16 bytes boundaries either. + int startingRawDataOffset = AlignmentHelper.AlignToBoundary( + AlignmentHelper.Pad(rawDataOffset, fieldPack), + fieldSize, + 16); + + rawDataOffset = startingRawDataOffset + fieldSize; + + return new FieldInfo.Primitive(fieldPath, typeName, startingRawDataOffset); + } + } + } +} diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/IShaderGenerator.Helpers.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.Helpers.cs similarity index 92% rename from src/ComputeSharp.D2D1Interop.SourceGenerators/IShaderGenerator.Helpers.cs rename to src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.Helpers.cs index 989f4db4..cf979517 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/IShaderGenerator.Helpers.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.Helpers.cs @@ -1,30 +1,27 @@ using System.Collections.Generic; -using ComputeSharp.D2D1Interop.__Internals; using ComputeSharp.D2D1Interop.SourceGenerators.Models; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory; -#pragma warning disable CS0618 - namespace ComputeSharp.D2D1Interop.SourceGenerators; /// -public sealed partial class ID2D1ShaderGenerator +partial class ID2D1ShaderGenerator { /// /// Gets the shader type for a given shader, if any. /// /// The input instance to check. - /// The instance for . - /// Whether or not implements . - private static bool IsD2D1ShaderType(INamedTypeSymbol typeSymbol, INamedTypeSymbol d2D1ShaderSymbol) + /// The instance for . + /// Whether or not implements . + private static bool IsD2D1PixelShaderType(INamedTypeSymbol typeSymbol, INamedTypeSymbol d2D1PixelShaderSymbol) { foreach (INamedTypeSymbol interfaceSymbol in typeSymbol.Interfaces) { - if (interfaceSymbol.Name == nameof(ID2D1Shader) && - SymbolEqualityComparer.Default.Equals(interfaceSymbol, d2D1ShaderSymbol)) + if (interfaceSymbol.Name == nameof(ID2D1PixelShader) && + SymbolEqualityComparer.Default.Equals(interfaceSymbol, d2D1PixelShaderSymbol)) { return true; } diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs new file mode 100644 index 00000000..99dce673 --- /dev/null +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/ID2D1ShaderGenerator.cs @@ -0,0 +1,105 @@ +using System.Collections.Immutable; +using ComputeSharp.D2D1Interop.SourceGenerators.Diagnostics; +using ComputeSharp.D2D1Interop.SourceGenerators.Extensions; +using ComputeSharp.D2D1Interop.SourceGenerators.Models; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace ComputeSharp.D2D1Interop.SourceGenerators; + +/// +/// A source generator creating data loaders for the type. +/// +[Generator] +public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator +{ + /// + public void Initialize(IncrementalGeneratorInitializationContext context) + { + // Check whether [SkipLocalsInit] can be used + IncrementalValueProvider canUseSkipLocalsInit = + context.CompilationProvider + .Select(static (compilation, token) => + compilation.Options is CSharpCompilationOptions { AllowUnsafe: true } && + compilation.GetTypeByMetadataName("System.Runtime.CompilerServices.SkipLocalsInitAttribute") is not null); + + // Get all declared struct types and their type symbols + IncrementalValuesProvider<(StructDeclarationSyntax Syntax, INamedTypeSymbol Symbol)> structDeclarations = + context.SyntaxProvider + .CreateSyntaxProvider( + static (node, token) => node is StructDeclarationSyntax structDeclaration, + static (context, token) => ( + (StructDeclarationSyntax)context.Node, + Symbol: (INamedTypeSymbol?)context.SemanticModel.GetDeclaredSymbol(context.Node, token))) + .Where(static pair => pair.Symbol is { Interfaces.IsEmpty: false })!; + + // Get the symbol for the ID2D1PixelShader interface + IncrementalValueProvider pixelShaderInterface = + context.CompilationProvider + .Select(static (compilation, token) => compilation.GetTypeByMetadataName(typeof(ID2D1PixelShader).FullName)!); + + // Filter struct declarations that implement the shader interface, and also gather the hierarchy info + IncrementalValuesProvider<(StructDeclarationSyntax Syntax, INamedTypeSymbol Symbol, HierarchyInfo Hierarchy)> shaderDeclarations = + structDeclarations + .Combine(pixelShaderInterface) + .Where(static item => IsD2D1PixelShaderType(item.Left.Symbol, item.Right)) + .Select(static (item, token) => (item.Left.Syntax, item.Left.Symbol, HierarchyInfo.From(item.Left.Symbol))); + + // Get the dispatch data, HLSL source and embedded bytecode info. This info is computed on the + // same step as parts are shared in following sub-branches in the incremental generator pipeline. + IncrementalValuesProvider<(Result Dispatch, Result Hlsl, Result ThreadIds)> shaderInfoWithErrors = + shaderDeclarations + .Combine(context.CompilationProvider) + .Select(static (item, token) => + { + // LoadDispatchData() info + ImmutableArray fieldInfos = LoadDispatchData.GetInfo( + item.Left.Symbol, + out int root32BitConstantCount, + out ImmutableArray dispatchDataDiagnostics); + + token.ThrowIfCancellationRequested(); + + DispatchDataInfo dispatchDataInfo = new( + item.Left.Hierarchy, + fieldInfos, + root32BitConstantCount); + + token.ThrowIfCancellationRequested(); + + // TODO + + return ( + new Result(dispatchDataInfo, dispatchDataDiagnostics), + new Result(null!, ImmutableArray.Empty), + new Result(null!, ImmutableArray.Empty)); + }); + + // Output the diagnostics + context.ReportDiagnostics(shaderInfoWithErrors.Select(static (item, token) => item.Dispatch.Errors)); + context.ReportDiagnostics(shaderInfoWithErrors.Select(static (item, token) => item.Hlsl.Errors)); + context.ReportDiagnostics(shaderInfoWithErrors.Select(static (item, token) => item.ThreadIds.Errors)); + + // Filter all items to enable caching at a coarse level, and remove diagnostics + IncrementalValuesProvider<(DispatchDataInfo Dispatch, HlslShaderSourceInfo Hlsl, ThreadIdsInfo ThreadIds)> shaderInfo = + shaderInfoWithErrors + .Select(static (item, token) => (item.Dispatch.Value, item.Hlsl.Value, item.ThreadIds.Value)) + .WithComparers(DispatchDataInfo.Comparer.Default, HlslShaderSourceInfo.Comparer.Default, ThreadIdsInfo.Comparer.Default); + + // Get a filtered sequence to enable caching + IncrementalValuesProvider dispatchDataInfo = + shaderInfo + .Select(static (item, token) => item.Dispatch) + .WithComparer(DispatchDataInfo.Comparer.Default); + + // Generate the LoadDispatchData() methods + context.RegisterSourceOutput(dispatchDataInfo.Combine(canUseSkipLocalsInit), static (context, item) => + { + MethodDeclarationSyntax loadDispatchDataMethod = LoadDispatchData.GetSyntax(item.Left.FieldInfos, item.Left.Root32BitConstantCount); + CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMethod(item.Left.Hierarchy, loadDispatchDataMethod, item.Right); + + context.AddSource($"{item.Left.Hierarchy.FilenameHint}.{nameof(LoadDispatchData)}", compilationUnit.ToFullString()); + }); + } +} diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/IShaderGenerator.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/IShaderGenerator.cs deleted file mode 100644 index 39f0acf7..00000000 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/IShaderGenerator.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.CodeAnalysis; - -namespace ComputeSharp.D2D1Interop.SourceGenerators; - -/// -/// A source generator creating data loaders for the type. -/// -[Generator] -public sealed partial class IShaderGenerator : IIncrementalGenerator -{ - /// - public void Initialize(IncrementalGeneratorInitializationContext context) - { - - } -} diff --git a/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/DispatchDataInfo.cs b/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/DispatchDataInfo.cs index 00a4d8f9..d2f2b1fd 100644 --- a/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/DispatchDataInfo.cs +++ b/src/ComputeSharp.D2D1Interop.SourceGenerators/Models/DispatchDataInfo.cs @@ -9,15 +9,11 @@ namespace ComputeSharp.D2D1Interop.SourceGenerators.Models; /// A model representing gathered info on a shader dispatch data. /// /// The hierarchy data for the shader. -/// The shader interface type. /// The description on shader instance fields. -/// The total number of captured resources. /// The size of the shader root signature, in 32 bit constants. internal sealed record DispatchDataInfo( HierarchyInfo Hierarchy, - Type Type, ImmutableArray FieldInfos, - int ResourceCount, int Root32BitConstantCount) { /// @@ -50,9 +46,7 @@ internal sealed record DispatchDataInfo( return HierarchyInfo.Comparer.Default.Equals(x.Hierarchy, y.Hierarchy) && - x.Type == y.Type && x.FieldInfos.SequenceEqual(y.FieldInfos, FieldInfo.Comparer.Default) && - x.ResourceCount == y.ResourceCount && x.Root32BitConstantCount == y.Root32BitConstantCount; } @@ -62,9 +56,7 @@ internal sealed record DispatchDataInfo( HashCode hashCode = default; hashCode.Add(HierarchyInfo.Comparer.Default.GetHashCode(obj.Hierarchy)); - hashCode.Add(obj.Type); hashCode.AddRange(obj.FieldInfos, FieldInfo.Comparer.Default); - hashCode.Add(obj.ResourceCount); hashCode.Add(obj.Root32BitConstantCount); return hashCode.ToHashCode();