Wire up support for known named intrinsics
このコミットが含まれているのは:
1 親
651232b906
コミット
29fee3b59d
3ファイル変更
+52
検索条件に一致するファイルはありません
@@ -441,4 +441,43 @@ internal abstract partial class HlslSourceRewriter : CSharpSyntaxRewriter
|
||||
// By default, constructors are not supported, so just return an empty value
|
||||
return CastExpression(targetType, LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Visits a known named intrinsic invocation expression.
|
||||
/// </summary>
|
||||
/// <param name="node">The original input <see cref="BaseObjectCreationExpressionSyntax"/> instance.</param>
|
||||
/// <param name="updatedNode">The updated <see cref="BaseObjectCreationExpressionSyntax"/> instance with tweaked syntax.</param>
|
||||
/// <param name="intrinsicName">The name of the intrinsic method being invoked.</param>
|
||||
/// <returns>The rewritten <see cref="SyntaxNode"/> for the invocation expression, if valid.</returns>
|
||||
/// <exception cref="NotSupportedException">Thrown if the named intrinsic is not recognized.</exception>
|
||||
protected static SyntaxNode? VisitKnownNamedIntrinsicInvocationExpression(
|
||||
InvocationExpressionSyntax node,
|
||||
InvocationExpressionSyntax updatedNode,
|
||||
string? intrinsicName)
|
||||
{
|
||||
// All named intrinsic methods start with a leading "__" prefix
|
||||
if (intrinsicName.AsSpan() is not ['_', '_', .. ReadOnlySpan<char> method])
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Handle and rewrite the current known named intrinsic.
|
||||
// This path should only ever be reached for valid ones.
|
||||
switch (method)
|
||||
{
|
||||
// Conditional select invocations are rewritten as follows:
|
||||
//
|
||||
// C#: Hlsl.ConditionalSelect(mask, left, right)
|
||||
// HLSL: (mask ? left : right)
|
||||
case "ConditionalSelect":
|
||||
return
|
||||
ParenthesizedExpression(
|
||||
ConditionalExpression(
|
||||
updatedNode.ArgumentList.Arguments[0].Expression,
|
||||
updatedNode.ArgumentList.Arguments[1].Expression,
|
||||
updatedNode.ArgumentList.Arguments[2].Expression));
|
||||
default:
|
||||
throw new NotSupportedException($"""Unrecognized intrinsic "{intrinsicName}".""");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -517,6 +517,13 @@ internal sealed partial class ShaderSourceRewriter(
|
||||
// Allow specialized types to track the method invocation, if needed
|
||||
TrackKnownMethodInvocation(metadataName);
|
||||
|
||||
// Special case: handle known named intrinsics being invoked.
|
||||
// These have special lowering to the right HLSL constructs.
|
||||
if (VisitKnownNamedIntrinsicInvocationExpression(node, updatedNode, mapping) is SyntaxNode namedIntrinsic)
|
||||
{
|
||||
return namedIntrinsic;
|
||||
}
|
||||
|
||||
return updatedNode.WithExpression(IdentifierName(mapping!));
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,12 @@ internal sealed partial class StaticFieldRewriter(
|
||||
mapping = HlslKnownMethods.GetMappedNameWithParameters(method.Name, method.Parameters.Select(static p => p.Type.Name));
|
||||
}
|
||||
|
||||
// Handle named intrinsics (see ShaderSourceRewriter for more info)
|
||||
if (VisitKnownNamedIntrinsicInvocationExpression(node, updatedNode, mapping) is SyntaxNode namedIntrinsic)
|
||||
{
|
||||
return namedIntrinsic;
|
||||
}
|
||||
|
||||
return updatedNode.WithExpression(IdentifierName(mapping!));
|
||||
}
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする