diff --git a/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs b/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs index d8b6ceb4..1aa1122d 100644 --- a/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/SyntaxNodeExtensions.cs @@ -109,9 +109,10 @@ namespace ComputeSharp.Shaders.Extensions } // Process the input node if it's a known method invocation - if (HlslKnownMethods.TryGetMappedName(containingMemberSymbolInfo.Symbol, memberSymbol) is string mappedName) + if (HlslKnownMethods.TryGetMappedName(containingMemberSymbolInfo.Symbol, memberSymbol, out string? mappedName)) { - return SyntaxFactory.IdentifierName(mappedName).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia()); + string expression = memberSymbol.IsStatic ? mappedName : $"{node.Expression}{mappedName}"; + return SyntaxFactory.IdentifierName(expression).WithLeadingTrivia(node.GetLeadingTrivia()).WithTrailingTrivia(node.GetTrailingTrivia()); } // Handle static fields as a special case diff --git a/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs b/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs index f2075bf2..4c0cc9b5 100644 --- a/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs +++ b/src/ComputeSharp.Shaders/Mappings/HlslKnownMethods.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Diagnostics.Contracts; using System.Linq; using System.Reflection; @@ -262,21 +263,15 @@ namespace ComputeSharp.Shaders.Mappings /// /// The containing member symbol for the method to check /// The symbol for the method to check + /// The mapped name, if one is found /// The HLSL-compatible method name that can be used in an HLSL shader [Pure] - public static string? TryGetMappedName(ISymbol containingMemberSymbol, ISymbol memberSymbol) + public static bool TryGetMappedName(ISymbol containingMemberSymbol, ISymbol memberSymbol, [NotNullWhen(true)] out string? mapped) { string fullTypeName = containingMemberSymbol.IsStatic ? containingMemberSymbol.ToString() : memberSymbol.ContainingType.ToString(); // Check if the target method is a known method - if (KnownMethods.TryGetValue($"{fullTypeName}{Type.Delimiter}{memberSymbol.Name}", out string mapped)) - { - // Return the static method if possible, otherwise access the parent instance - if (memberSymbol.IsStatic) return mapped; - return $"{containingMemberSymbol.Name}{mapped}"; - } - - return null; + return KnownMethods.TryGetValue($"{fullTypeName}{Type.Delimiter}{memberSymbol.Name}", out mapped); } } }