Use shared static field rewriter in DX12/D2D generators

このコミットが含まれているのは:
Sergio Pedri committed 2023-12-06 21:12:42 +01:00
1 親 c0e78bb1a2
コミット 4f60d70411
2ファイル変更
+26 -72

検索条件に一致するファイルはありません

+13 -35
ファイルの表示
@@ -265,55 +265,33 @@ partial class ComputeShaderDescriptorGenerator
foreach (ISymbol memberSymbol in structDeclarationSymbol.GetMembers())
{
// Find all declared static fields in the type
// Pre-filter fields that cannot be valid, to reduce the calls to check the [GroupShared] attribute
if (memberSymbol is not IFieldSymbol { IsImplicitlyDeclared: false, IsStatic: true, IsConst: false, } fieldSymbol)
{
continue;
}
if (!fieldSymbol.TryGetSyntaxNode(token, out VariableDeclaratorSyntax? variableDeclarator))
{
continue;
}
// Ignore [GroupShared] fields, they'll be gathered in a separate rewriting step
if (fieldSymbol.TryGetAttributeWithFullyQualifiedMetadataName("ComputeSharp.GroupSharedAttribute", out _))
{
continue;
}
// Constant properties must be of a primitive, vector or matrix type
if (fieldSymbol.Type is not INamedTypeSymbol typeSymbol ||
!HlslKnownTypes.IsKnownHlslType(typeSymbol.GetFullyQualifiedMetadataName()))
{
diagnostics.Add(InvalidShaderStaticFieldType, variableDeclarator, structDeclarationSymbol, fieldSymbol.Name, fieldSymbol.Type);
continue;
}
_ = HlslKnownKeywords.TryGetMappedName(fieldSymbol.Name, out string? mapping);
string typeDeclaration = fieldSymbol.IsReadOnly switch
{
true => $"static const {HlslKnownTypes.GetMappedName(typeSymbol)}",
false => $"static {HlslKnownTypes.GetMappedName(typeSymbol)}"
};
token.ThrowIfCancellationRequested();
StaticFieldRewriter staticFieldRewriter = new(
if (HlslDefinitionsSyntaxProcessor.TryGetStaticField(
structDeclarationSymbol,
fieldSymbol,
semanticModel,
discoveredTypes,
constantDefinitions,
diagnostics,
token);
ExpressionSyntax? processedDeclaration = staticFieldRewriter.Visit(variableDeclarator);
token.ThrowIfCancellationRequested();
string? assignment = processedDeclaration?.NormalizeWhitespace(eol: "\n").ToFullString();
builder.Add((mapping ?? fieldSymbol.Name, typeDeclaration, assignment));
token,
out string? name,
out string? typeDeclaration,
out string? assignmentExpression,
out _))
{
builder.Add((name, typeDeclaration, assignmentExpression));
}
}
return builder.ToImmutable();