Implemented support for GetDimensions properties
このコミットが含まれているのは:
1 親
b26fda5e8f
コミット
e67d1161f3
3ファイル変更
+102
-44
検索条件に一致するファイルはありません
@@ -306,7 +306,23 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
true => ParseExpression(mapping!),
|
||||
false => updatedNode.WithName(IdentifierName(mapping!))
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// If the current member access is an access to any of the size properties in the available
|
||||
// resource types (either buffer or texture types), then rewrite the subtree to transform the
|
||||
// property access into an invocation of an autogenerated static helper method to get the target
|
||||
// dimension for the buffer in use. The helper method is added to the list of static helpers.
|
||||
if (operation is IPropertyReferenceOperation propertyOperation &&
|
||||
HlslKnownMembers.TryGetAccessorRankAndAxis(propertyOperation.Property.GetFullMetadataName(), out int rank, out int axis))
|
||||
{
|
||||
INamedTypeSymbol resourceType = (INamedTypeSymbol)this.semanticModel.GetTypeInfo(node.Expression).Type!;
|
||||
string resourceName = HlslKnownTypes.GetMappedName(resourceType);
|
||||
MethodDeclarationSyntax methodSyntax = CreateResourceDimensionAccessorMethod(resourceName, rank, axis);
|
||||
|
||||
this.staticMethods.Add(propertyOperation.Property.GetMethod!, methodSyntax);
|
||||
|
||||
return InvocationExpression(IdentifierName(methodSyntax.Identifier)).AddArgumentListArguments(Argument(updatedNode.Expression));
|
||||
}
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
@@ -416,5 +432,45 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
|
||||
return updatedToken.WithoutTrivia();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a method to get a specific dimension size for a specified resource type.
|
||||
/// </summary>
|
||||
/// <param name="resourceType">The input resource type.</param>
|
||||
/// <param name="rank">The rank of the resource (must be 2 for structured buffers).</param>
|
||||
/// <param name="axis">The target axis to get the dimension for.</param>
|
||||
/// <returns>A <see cref="MethodDeclarationSyntax"/> instance with the requested tree.</returns>
|
||||
private static MethodDeclarationSyntax CreateResourceDimensionAccessorMethod(string resourceType, int rank, int axis)
|
||||
{
|
||||
// Create a static method to get a specified dimension for a target resource type.
|
||||
// The method will automatically create the necessary number of temporary variables
|
||||
// depending on the rank of the input resource (eg. 2 for Texture2D<T> resources).
|
||||
// For instance, this code will generate the following tree for Texture2D<float>.Width:
|
||||
//
|
||||
// static int __get_Dimension0(Texture2D<float> texture)
|
||||
// {
|
||||
// uint _0, _1;
|
||||
// texture.GetDimensions(_0, _1);
|
||||
//
|
||||
// return _0;
|
||||
// }
|
||||
return
|
||||
MethodDeclaration(PredefinedType(Token(SyntaxKind.IntKeyword)), $"__get_Dimension{axis}")
|
||||
.AddModifiers(Token(SyntaxKind.StaticKeyword))
|
||||
.AddParameterListParameters(
|
||||
Parameter(Identifier("resource"))
|
||||
.WithType(IdentifierName(resourceType)))
|
||||
.WithBody(Block(
|
||||
LocalDeclarationStatement(
|
||||
VariableDeclaration(PredefinedType(Token(SyntaxKind.UIntKeyword)))
|
||||
.AddVariables(Enumerable.Range(0, rank).Select(static i => VariableDeclarator(Identifier("_" + i))).ToArray())),
|
||||
ExpressionStatement(
|
||||
InvocationExpression(MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("resource"),
|
||||
IdentifierName("GetDimensions")))
|
||||
.AddArgumentListArguments(Enumerable.Range(0, rank).Select(static i => Argument(IdentifierName("_" + i))).ToArray())),
|
||||
ReturnStatement(IdentifierName("_" + axis))));
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする