diff --git a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs index af38826c..a895ec4c 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/ID2D1ShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -337,15 +337,21 @@ partial class ID2D1ShaderGenerator INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type; // Convert the name to the fully qualified HLSL version - if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullMetadataName(), out string? mapped)) + if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullMetadataName(), out string? mappedType)) { - mapped = fieldType.GetFullMetadataName().ToHlslIdentifierName(); + mappedType = fieldType.GetFullMetadataName().ToHlslIdentifierName(); + } + + // Get the field name as a valid HLSL identifier + if (!HlslKnownKeywords.TryGetMappedName(field.Name, out string? mappedName)) + { + mappedName = field.Name; } structDeclaration = structDeclaration.AddMembers( FieldDeclaration(VariableDeclaration( - IdentifierName(mapped!)).AddVariables( - VariableDeclarator(Identifier(field.Name))))); + IdentifierName(mappedType!)).AddVariables( + VariableDeclarator(Identifier(mappedName!))))); } // Insert the trailing ; right after the closing bracket (after normalization) diff --git a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs index 7bf7efdf..990a6aae 100644 --- a/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs +++ b/src/ComputeSharp.SourceGenerators/IShaderGenerator.CreateBuildHlslSourceMethod.cs @@ -465,15 +465,21 @@ partial class IShaderGenerator INamedTypeSymbol fieldType = (INamedTypeSymbol)field.Type; // Convert the name to the fully qualified HLSL version - if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullMetadataName(), out string? mapped)) + if (!HlslKnownTypes.TryGetMappedName(fieldType.GetFullMetadataName(), out string? mappedType)) { - mapped = fieldType.GetFullMetadataName().ToHlslIdentifierName(); + mappedType = fieldType.GetFullMetadataName().ToHlslIdentifierName(); + } + + // Get the field name as a valid HLSL identifier + if (!HlslKnownKeywords.TryGetMappedName(field.Name, out string? mappedName)) + { + mappedName = field.Name; } structDeclaration = structDeclaration.AddMembers( FieldDeclaration(VariableDeclaration( - IdentifierName(mapped!)).AddVariables( - VariableDeclarator(Identifier(field.Name))))); + IdentifierName(mappedType!)).AddVariables( + VariableDeclarator(Identifier(mappedName!))))); } // Insert the trailing ; right after the closing bracket (after normalization)