From 3daafd3e16533f6ab9ca65d6802e4570b524a557 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 10 Jan 2021 18:37:13 +0100 Subject: [PATCH] Fixed handling of constants in source generators --- .../AutoConstructorGenerator.cs | 9 ++++----- .../IComputeShaderDataLoaderGenerator.cs | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs b/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs index b82df4d0..40ebf95d 100644 --- a/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/AutoConstructorGenerator.cs @@ -42,12 +42,11 @@ namespace ComputeSharp.SourceGenerators var structName = structDeclaration.Identifier.Text; var structModifiers = structDeclaration.Modifiers; var fields = ( - from fieldDeclaration in structDeclaration.Members.OfType() - let fieldType = fieldDeclaration.Declaration.Type - let typeName = semanticModel.GetTypeInfo(fieldType).Type!.ToDisplayString() + from fieldSymbol in structDeclarationSymbol.GetMembers().OfType() + where !fieldSymbol.IsConst + let typeName = fieldSymbol.Type!.ToDisplayString() let fieldFullType = ParseTypeName(typeName) - from fieldVariable in fieldDeclaration.Declaration.Variables - select (Type: fieldFullType, fieldVariable.Identifier)).ToImmutableArray(); + select (Type: fieldFullType, Identifier: Identifier(fieldSymbol.Name))).ToImmutableArray(); // Create the constructor declaration for the type. This will // produce a constructor with simple initialization of all variables: diff --git a/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs b/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs index 1d1e59ec..2922aa8a 100644 --- a/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs +++ b/src/ComputeSharp.SourceGenerators/IComputeShaderDataLoaderGenerator.cs @@ -141,6 +141,8 @@ namespace ComputeSharp.SourceGenerators } else if (HlslKnownTypes.IsScalarOrVectorType(typeName)) { + if (fieldSymbol.IsConst) continue; + var (fieldSize, fieldPack) = HlslKnownSizes.GetTypeInfo(typeName); // Calculate the right offset with 16-bytes padding (HLSL constant buffer).