Remove some HLSL rewriting duplicated code
このコミットが含まれているのは:
1 親
945f6514b8
コミット
ae23529485
3ファイル変更
+17
-24
検索条件に一致するファイルはありません
@@ -15,15 +15,8 @@ partial class ShaderSourceRewriter
|
||||
public bool NeedsD2DRequiresScenePositionAttribute { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, InvocationExpressionSyntax node, string? mappedType)
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, ExpressionSyntax expression, ArgumentSyntax arguments)
|
||||
{
|
||||
// Get the syntax for the argument syntax transformation (to pack arguments if needed, just like in the DX12 rewriter)
|
||||
ArgumentSyntax coordinateSyntax = mappedType switch
|
||||
{
|
||||
not null => Argument(InvocationExpression(IdentifierName(mappedType!), ArgumentList(node.ArgumentList.Arguments))),
|
||||
null => node.ArgumentList.Arguments[0]
|
||||
};
|
||||
|
||||
string fieldName = (operation.Instance as IFieldReferenceOperation)?.Member.Name ?? "";
|
||||
|
||||
_ = HlslKnownKeywords.TryGetMappedName(fieldName, out string? mapped);
|
||||
@@ -31,8 +24,8 @@ partial class ShaderSourceRewriter
|
||||
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
|
||||
// For instance: texture.Sample(uv) will be rewritten as texture.Sample(__sampler__texture, uv).
|
||||
return
|
||||
InvocationExpression(node.Expression)
|
||||
.AddArgumentListArguments(Argument(IdentifierName($"__sampler__{mapped ?? fieldName}")), coordinateSyntax);
|
||||
InvocationExpression(expression)
|
||||
.AddArgumentListArguments(Argument(IdentifierName($"__sampler__{mapped ?? fieldName}")), arguments);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
||||
@@ -398,8 +398,15 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
}
|
||||
else if (HlslKnownMethods.TryGetMappedResourceSamplerAccessType(metadataName, out string? mapping))
|
||||
{
|
||||
// Get the syntax for the argument syntax transformation (adding the vector type constructor if needed)
|
||||
ArgumentSyntax coordinateSyntax = mapping switch
|
||||
{
|
||||
not null => Argument(InvocationExpression(IdentifierName(mapping!), ArgumentList(updatedNode.ArgumentList.Arguments))),
|
||||
null => updatedNode.ArgumentList.Arguments[0]
|
||||
};
|
||||
|
||||
// Rewrite texture resource sampled accesses, if needed
|
||||
return RewriteSampledTextureAccess(operation, updatedNode, mapping);
|
||||
return RewriteSampledTextureAccess(operation, updatedNode.Expression, coordinateSyntax);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -435,10 +442,10 @@ internal sealed partial class ShaderSourceRewriter : HlslSourceRewriter
|
||||
/// Rewrites a sampled texture access.
|
||||
/// </summary>
|
||||
/// <param name="operation">The <see cref="IInvocationOperation"/> instance for the sampled texture access.</param>
|
||||
/// <param name="node">The input <see cref="InvocationExpressionSyntax"/> instance for the node to rewrite.</param>
|
||||
/// <param name="mappedType">The mapped type name to use for the sampled access, if any.</param>
|
||||
/// <param name="expression">The input <see cref="ExpressionSyntax"/> instance for the node to rewrite.</param>
|
||||
/// <param name="arguments">The input <see cref="ArgumentSyntax"/> with the updated arguments for the expression to rewrite.</param>
|
||||
/// <returns>A <see cref="SyntaxNode"/> representing the rewritten sampled texture access.</returns>
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, InvocationExpressionSyntax node, string? mappedType);
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, ExpressionSyntax expression, ArgumentSyntax arguments);
|
||||
|
||||
/// <summary>
|
||||
/// Tracks a property access to a known HLSL property.
|
||||
|
||||
@@ -33,24 +33,17 @@ partial class ShaderSourceRewriter
|
||||
public bool IsSamplerUsed { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, InvocationExpressionSyntax node, string? mappedType)
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, ExpressionSyntax expression, ArgumentSyntax arguments)
|
||||
{
|
||||
IsSamplerUsed = true;
|
||||
|
||||
// Get the syntax for the argument syntax transformation (adding the vector type constructor if needed)
|
||||
ArgumentSyntax coordinateSyntax = mappedType switch
|
||||
{
|
||||
not null => Argument(InvocationExpression(IdentifierName(mappedType!), ArgumentList(node.ArgumentList.Arguments))),
|
||||
null => node.ArgumentList.Arguments[0]
|
||||
};
|
||||
|
||||
// Transform a method invocation syntax into a sampling call with the implicit static linear sampler.
|
||||
// For instance: texture.Sample(uv) will be rewritten as texture.SampleLevel(__sampler, uv, 0).
|
||||
return
|
||||
InvocationExpression(((MemberAccessExpressionSyntax)node.Expression).WithName(IdentifierName("SampleLevel")))
|
||||
InvocationExpression(((MemberAccessExpressionSyntax)expression).WithName(IdentifierName("SampleLevel")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(IdentifierName("__sampler")),
|
||||
coordinateSyntax,
|
||||
arguments,
|
||||
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
|
||||
}
|
||||
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする