Use shared static field rewriter in DX12/D2D generators
このコミットが含まれているのは:
1 親
c0e78bb1a2
コミット
4f60d70411
2ファイル変更
+26
-72
検索条件に一致するファイルはありません
+13
-37
@@ -256,52 +256,28 @@ partial class D2DPixelShaderDescriptorGenerator
|
||||
|
||||
foreach (ISymbol memberSymbol in structDeclarationSymbol.GetMembers())
|
||||
{
|
||||
// Find all declared static fields in the type
|
||||
if (memberSymbol is not IFieldSymbol { IsImplicitlyDeclared: false, IsStatic: true, IsConst: false, } fieldSymbol)
|
||||
if (memberSymbol is not IFieldSymbol fieldSymbol)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fieldSymbol.TryGetSyntaxNode(token, out VariableDeclaratorSyntax? variableDeclarator))
|
||||
{
|
||||
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);
|
||||
token,
|
||||
out string? name,
|
||||
out string? typeDeclaration,
|
||||
out string? assignmentExpression,
|
||||
out StaticFieldRewriter? staticFieldRewriter))
|
||||
{
|
||||
needsD2D1RequiresScenePosition |= staticFieldRewriter.NeedsD2DRequiresScenePositionAttribute;
|
||||
|
||||
ExpressionSyntax? processedDeclaration = staticFieldRewriter.Visit(variableDeclarator);
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
||||
string? assignment = processedDeclaration?.NormalizeWhitespace(eol: "\n").ToFullString();
|
||||
|
||||
needsD2D1RequiresScenePosition |= staticFieldRewriter.NeedsD2DRequiresScenePositionAttribute;
|
||||
|
||||
builder.Add((mapping ?? fieldSymbol.Name, typeDeclaration, assignment));
|
||||
builder.Add((name, typeDeclaration, assignmentExpression));
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToImmutable();
|
||||
|
||||
@@ -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();
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする