diff --git a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ConstantBuffer.Syntax.cs b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ConstantBuffer.Syntax.cs index be7d8692..2d79b8a2 100644 --- a/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ConstantBuffer.Syntax.cs +++ b/src/ComputeSharp.D2D1.SourceGenerators/D2DPixelShaderDescriptorGenerator.ConstantBuffer.Syntax.cs @@ -120,14 +120,16 @@ partial class D2DPixelShaderDescriptorGenerator case FieldInfo.Primitive { TypeName: "System.Boolean" } primitive: // Append a field as a global::ComputeSharp.Bool value (will use the implicit conversion from bool values) - writer.WriteLine($"""/// path.Name))}"/>"""); + writer.WriteFieldXmlSummary(field, fullyQualifiedTypeName); + writer.WriteFieldXmlRemarks(field); writer.WriteLine($"""[FieldOffset({primitive.Offset})]"""); writer.WriteLine($"""public global::ComputeSharp.Bool {string.Join("_", primitive.FieldPath.Select(static path => path.Name))};"""); break; case FieldInfo.Primitive primitive: // Append primitive fields of other types with their mapped names - writer.WriteLine($"""/// path.Name))}"/>"""); + writer.WriteFieldXmlSummary(field, fullyQualifiedTypeName); + writer.WriteFieldXmlRemarks(field); writer.WriteLine($"""[FieldOffset({primitive.Offset})]"""); writer.WriteLine($"""public {HlslKnownTypes.GetMappedName(primitive.TypeName)} {string.Join("_", primitive.FieldPath.Select(static path => path.Name))};"""); break; @@ -140,7 +142,8 @@ partial class D2DPixelShaderDescriptorGenerator for (int j = 0; j < matrix.Rows; j++) { writer.WriteLineIf(j > 0); - writer.WriteLine($"""/// Row {j} of path.Name))}"/>."""); + writer.WriteFieldXmlSummary(field, fullyQualifiedTypeName); + writer.WriteFieldXmlRemarks(field, row: j); writer.WriteLine($"""[FieldOffset({matrix.Offsets[j]})]"""); writer.WriteLine($"""public {rowTypeName} {fieldNamePrefix}_{j};"""); } @@ -345,11 +348,58 @@ partial class D2DPixelShaderDescriptorGenerator /// file static class IndentedTextWriterExtensions { + /// + /// Writes the XML summary for a given field. + /// + /// The instance to write into. + /// The input field to write the XML summary for. + /// The fully qualified type name of the containing type. + public static void WriteFieldXmlSummary(this IndentedTextWriter writer, FieldInfo fieldInfo, string fullyQualifiedTypeName) + { + if (fieldInfo.FieldPath[0].UnspeakableName is null) + { + writer.WriteLine($"""/// """); + } + else + { + writer.WriteLine($"""/// The unspeakable field "{fieldInfo.FieldPath[0].Name}" of ."""); + } + } + + /// + /// Writes the XML remarks for a given field, if needed. + /// + /// The instance to write into. + /// The input field to write the XML remarks for, if needed. + /// The row for the field, if this is a matrix type. + public static void WriteFieldXmlRemarks(this IndentedTextWriter writer, FieldInfo fieldInfo, int? row = null) + { + // The remarks are only needed if the field is nested + if (fieldInfo.FieldPath is not [.., FieldPathPart.Nested nested, FieldPathPart.Leaf leaf]) + { + return; + } + + // Write the correct remarks depending on whether the field can be referenced directly + if (leaf.UnspeakableName is null) + { + writer.Write($"""/// Serialized field mapping to"""); + writer.WriteIf(row is not null, $""" row {row} of"""); + writer.WriteLine($""" ."""); + } + else + { + writer.Write($"""/// Serialized field mapping to"""); + writer.WriteIf(row is not null, $""" row {row} of"""); + writer.WriteLine($""" the unspeakable field "{leaf.Name}" of ."""); + } + } + /// /// Writes an expression to access a given field. /// /// The instance to write into. - /// The input field to generate the expression for. + /// The input field to write the expression for. public static void WriteFieldAccessExpression(this IndentedTextWriter writer, FieldInfo fieldInfo) { writer.Write("shader");