From 6532a20479c1fbb5c484ca8cd6ab9e1042b20b99 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 28 Sep 2023 20:34:05 +0200 Subject: [PATCH] Remove DispatchDataInfo model --- ...eateInitializeFromDispatchDataMethod.Syntax.cs | 6 +++--- ...nerator.CreateLoadDispatchDataMethod.Syntax.cs | 15 ++++++++++----- .../ID2D1ShaderGenerator.cs | 11 ++++++----- .../Models/D2D1ShaderInfo.cs | 6 ++++-- .../Models/DispatchDataInfo.cs | 10 ---------- 5 files changed, 23 insertions(+), 25 deletions(-) delete mode 100644 src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs index 7ad7435a..6848e527 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateInitializeFromDispatchDataMethod.Syntax.cs @@ -19,9 +19,9 @@ partial class ID2D1ShaderGenerator /// /// Creates a instance for the InitializeFromDispatchData method. /// - /// The dispatch info gathered for the current shader. + /// The discovered fields of the current shader. /// The resulting instance for the InitializeFromDispatchData method. - public static MethodDeclarationSyntax GetSyntax(DispatchDataInfo dispatchInfo) + public static MethodDeclarationSyntax GetSyntax(EquatableArray fields) { // This code produces a method declaration as follows: // @@ -35,7 +35,7 @@ partial class ID2D1ShaderGenerator .AddParameterListParameters(Parameter(Identifier("data")).WithType( GenericName(Identifier("global::System.ReadOnlySpan")) .AddTypeArgumentListArguments(PredefinedType(Token(SyntaxKind.ByteKeyword))))) - .WithBody(Block(GetDispatchDataUnloadingStatements(dispatchInfo.FieldInfos))); + .WithBody(Block(GetDispatchDataUnloadingStatements(fields))); } /// diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs index 0390b344..413d6342 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateLoadDispatchDataMethod.Syntax.cs @@ -24,19 +24,24 @@ partial class ID2D1ShaderGenerator /// Creates a instance for the LoadDispatchDataMethod method. /// /// The hiararchy info of the shader type. - /// The dispatch info gathered for the current shader. + /// The description on shader instance fields. + /// The size of the shader constant buffer. /// Any additional instances needed by the generated code, if needed. /// The resulting instance for the LoadDispatchDataMethod method. - public static MethodDeclarationSyntax GetSyntax(HierarchyInfo hierarchyInfo, DispatchDataInfo dispatchInfo, out TypeDeclarationSyntax[] additionalTypes) + public static MethodDeclarationSyntax GetSyntax( + HierarchyInfo hierarchyInfo, + EquatableArray fields, + int constantBufferSizeInBytes, + out TypeDeclarationSyntax[] additionalTypes) { // Declare the mapping constant buffer type, if needed (ie. if the shader has at least one field) - if (dispatchInfo.FieldInfos.Length == 0) + if (fields.Length == 0) { additionalTypes = Array.Empty(); } else { - additionalTypes = new[] { GetConstantBufferDeclaration(hierarchyInfo, dispatchInfo.FieldInfos, dispatchInfo.ConstantBufferSizeInBytes) }; + additionalTypes = new[] { GetConstantBufferDeclaration(hierarchyInfo, fields, constantBufferSizeInBytes) }; } // This code produces a method declaration as follows: @@ -51,7 +56,7 @@ partial class ID2D1ShaderGenerator .AddModifiers(Token(SyntaxKind.ReadOnlyKeyword), Token(SyntaxKind.UnsafeKeyword)) .AddTypeParameterListParameters(TypeParameter(Identifier("TLoader"))) .AddParameterListParameters(Parameter(Identifier("loader")).AddModifiers(Token(SyntaxKind.RefKeyword)).WithType(IdentifierName("TLoader"))) - .WithBody(Block(GetDispatchDataLoadingStatements(dispatchInfo.FieldInfos, dispatchInfo.ConstantBufferSizeInBytes))); + .WithBody(Block(GetDispatchDataLoadingStatements(fields, constantBufferSizeInBytes))); } /// diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs index 4888ed8f..c27b699e 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.cs @@ -144,7 +144,8 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator EffectDescription: effectDescription, EffectCategory: effectCategory, EffectAuthor: effectAuthor, - DispatchData: new DispatchDataInfo(fieldInfos, constantBufferSizeInBytes), + ConstantBufferSizeInBytes: constantBufferSizeInBytes, + Fields: fieldInfos, InputTypes: new InputTypesInfo(inputTypes), ResourceTextureDescriptions: new ResourceTextureDescriptionsInfo(resourceTextureDescriptions), HlslShaderSource: new HlslShaderSourceInfo( @@ -279,15 +280,15 @@ public sealed partial class ID2D1ShaderGenerator : IIncrementalGenerator }); // Get the info for InitializeFromDispatchData() and LoadDispatchData() (hierarchy and dispatch data) - IncrementalValuesProvider<(HierarchyInfo Hierarchy, DispatchDataInfo Dispatch)> dispatchDataInfo = + IncrementalValuesProvider<(HierarchyInfo Hierarchy, EquatableArray Fields, int ConstantBufferSizeInBytes)> dispatchDataInfo = shaderInfoWithErrors - .Select(static (item, _) => (item.Hierarchy, item.DispatchData)); + .Select(static (item, _) => (item.Hierarchy, item.Fields, item.ConstantBufferSizeInBytes)); // Generate the InitializeFromDispatchData() and LoadDispatchData() methods context.RegisterSourceOutput(dispatchDataInfo, static (context, item) => { - MethodDeclarationSyntax initializeFromDispatchDataMethod = InitializeFromDispatchData.GetSyntax(item.Dispatch); - MethodDeclarationSyntax loadDispatchDataMethod = LoadDispatchData.GetSyntax(item.Hierarchy, item.Dispatch, out TypeDeclarationSyntax[] additionalTypes); + MethodDeclarationSyntax initializeFromDispatchDataMethod = InitializeFromDispatchData.GetSyntax(item.Fields); + MethodDeclarationSyntax loadDispatchDataMethod = LoadDispatchData.GetSyntax(item.Hierarchy, item.Fields, item.ConstantBufferSizeInBytes, out TypeDeclarationSyntax[] additionalTypes); CompilationUnitSyntax compilationUnit = GetCompilationUnitFromMembers( item.Hierarchy, memberDeclarations: new (MemberDeclarationSyntax, bool)[] { (initializeFromDispatchDataMethod, false), (loadDispatchDataMethod, true) }, diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs index e55ef2df..8d1f286f 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/Models/D2D1ShaderInfo.cs @@ -12,7 +12,8 @@ namespace ComputeSharp.D2D1.SourceGenerators.Models; /// The effect description for the shader type, if available. /// The effect category for the shader type, if available. /// The effect author for the shader type, if available. -/// The gathered shader dispatch data. +/// The size of the shader constant buffer. +/// The description on shader instance fields. /// The gathered input types for the shader. /// The gathered resource texture descriptions for the shader. /// The processed HLSL source for the shader. @@ -27,7 +28,8 @@ internal sealed record D2D1ShaderInfo( string? EffectDescription, string? EffectCategory, string? EffectAuthor, - DispatchDataInfo DispatchData, + int ConstantBufferSizeInBytes, + EquatableArray Fields, InputTypesInfo InputTypes, ResourceTextureDescriptionsInfo ResourceTextureDescriptions, HlslShaderSourceInfo HlslShaderSource, diff --git a/src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs b/src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs deleted file mode 100644 index f2bb9a0a..00000000 --- a/src/ComputeSharp.D2D1.SourceGenerators/Models/DispatchDataInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using ComputeSharp.SourceGeneration.Helpers; - -namespace ComputeSharp.D2D1.SourceGenerators.Models; - -/// -/// A model representing gathered info on a shader dispatch data. -/// -/// The description on shader instance fields. -/// The size of the shader constant buffer. -internal sealed record DispatchDataInfo(EquatableArray FieldInfos, int ConstantBufferSizeInBytes); \ No newline at end of file