Added support for mapped members
このコミットが含まれているのは:
1 親
d176042528
コミット
5c97525672
3ファイル変更
+208
-6
検索条件に一致するファイルはありません
@@ -1,7 +1,10 @@
|
||||
using ComputeSharp.SourceGenerators.Extensions;
|
||||
using System.Numerics;
|
||||
using ComputeSharp.Shaders.Mappings;
|
||||
using ComputeSharp.SourceGenerators.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Operations;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
@@ -110,13 +113,22 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
{
|
||||
var updatedNode = (MemberAccessExpressionSyntax)base.VisitMemberAccessExpression(node)!;
|
||||
|
||||
// If the current member access is a field or property access, check the lookup table
|
||||
// to see if the member should be rewritten for HLSL compliance, and rewrite if needed.
|
||||
if (node.IsKind(SyntaxKind.SimpleMemberAccessExpression) &&
|
||||
this.semanticModel.GetSymbolInfo(node).Symbol is ISymbol nodeSymbol &&
|
||||
nodeSymbol.ContainingType.ToDisplayString() == typeof(ThreadIds).FullName)
|
||||
this.semanticModel.GetOperation(node) is IMemberReferenceOperation operation &&
|
||||
HlslKnownMembers.TryGetMappedName(operation.Member.ToDisplayString(), out string? mapping))
|
||||
{
|
||||
// When accessing ThreadIds members, they are in lowercase in HLSL. This is
|
||||
// because the type is mapped to uint3, which has the xyz members.
|
||||
return updatedNode.WithName(IdentifierName(updatedNode.Name.ToString().ToLower()));
|
||||
// Static and instance members are handled differently, with static members being
|
||||
// converted into a literal expression, and instance getting an updated identifier.
|
||||
// For instance, consider these two cases:
|
||||
// - Vector3.One (static) => float3(1.0f, 1.0f, 1.0f)
|
||||
// - ThredIds.X (instance) => [arg].x
|
||||
return operation.Member.IsStatic switch
|
||||
{
|
||||
true => ParseExpression(mapping!),
|
||||
false => updatedNode.WithName(IdentifierName(mapping!))
|
||||
};
|
||||
}
|
||||
|
||||
return updatedNode;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする