Enabled shader generation for texture indexer overloads
このコミットが含まれているのは:
1 親
c262cd5519
コミット
c208dc29b1
4ファイル変更
+60
-1
検索条件に一致するファイルはありません
@@ -74,6 +74,26 @@ namespace ComputeSharp.SourceGenerators.Extensions
|
||||
return symbol.ToDisplayString(FullyQualifiedWithoutGlobalAndParametersFormat);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full metadata name for a given <see cref="IPropertySymbol"/> instance.
|
||||
/// </summary>
|
||||
/// <param name="symbol">The input <see cref="IPropertySymbol"/> instance.</param>
|
||||
/// <returns>The full metadata name for <paramref name="symbol"/>.</returns>
|
||||
[Pure]
|
||||
public static string GetFullMetadataName(this IPropertySymbol symbol)
|
||||
{
|
||||
string declaringTypeName = symbol.ContainingType.GetFullMetadataName();
|
||||
|
||||
if (symbol.IsIndexer)
|
||||
{
|
||||
var parameters = string.Join(", ", symbol.Parameters.Select(static p => ((INamedTypeSymbol)p.Type).GetFullMetadataName()));
|
||||
|
||||
return $"{declaringTypeName}.this[{parameters}]";
|
||||
}
|
||||
|
||||
return $"{declaringTypeName}.{symbol.Name}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a valid filename for a target symbol and generator type.
|
||||
/// </summary>
|
||||
|
||||
@@ -12,6 +12,17 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
/// </summary>
|
||||
internal static class HlslKnownMembers
|
||||
{
|
||||
/// <summary>
|
||||
/// The mapping of supported known indexers to HLSL vector type names.
|
||||
/// </summary>
|
||||
private static readonly IReadOnlyDictionary<string, string> KnownIndexers = new Dictionary<string, string>
|
||||
{
|
||||
[$"ComputeSharp.ReadOnlyTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadWriteTexture2D`1.this[{typeof(int).FullName}, {typeof(int).FullName}]"] = "int2",
|
||||
[$"ComputeSharp.ReadOnlyTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3",
|
||||
[$"ComputeSharp.ReadWriteTexture3D`1.this[{typeof(int).FullName}, {typeof(int).FullName}, {typeof(int).FullName}]"] = "int3"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The mapping of supported known members to HLSL names.
|
||||
/// </summary>
|
||||
@@ -162,5 +173,17 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
{
|
||||
return KnownMembers.TryGetValue(name, out mapped);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the mapped HLSL-compatible indexer vector type name for the input indexer name.
|
||||
/// </summary>
|
||||
/// <param name="name">The input fully qualified indexer name.</param>
|
||||
/// <param name="mapped">The mapped type name, if one is found.</param>
|
||||
/// <returns>The HLSL-compatible type name that can be used in an HLSL shader for the given indexer.</returns>
|
||||
[Pure]
|
||||
public static bool TryGetMappedIndexerTypeName(string name, out string? mapped)
|
||||
{
|
||||
return KnownIndexers.TryGetValue(name, out mapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,7 +41,7 @@ namespace ComputeSharp.SourceGenerators.Mappings
|
||||
[typeof(Double2).FullName] = "double2",
|
||||
[typeof(Double3).FullName] = "double3",
|
||||
[typeof(Double4).FullName] = "double4",
|
||||
[typeof(ThreadIds).FullName] = "uint3"
|
||||
[typeof(ThreadIds).FullName] = "int3"
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -342,6 +342,22 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitElementAccessExpression(ElementAccessExpressionSyntax node)
|
||||
{
|
||||
var updatedNode = (ElementAccessExpressionSyntax)base.VisitElementAccessExpression(node)!;
|
||||
|
||||
if (this.semanticModel.GetOperation(node) is IPropertyReferenceOperation operation &&
|
||||
HlslKnownMembers.TryGetMappedIndexerTypeName(operation.Property.GetFullMetadataName(), out string? mapping))
|
||||
{
|
||||
var index = InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments));
|
||||
|
||||
return updatedNode.WithArgumentList(BracketedArgumentList(SingletonSeparatedList(Argument(index))));
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitArgument(ArgumentSyntax node)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする