Update HLSL rewriters to use new Sample APIs
このコミットが含まれているのは:
1 親
0dd0bd587a
コミット
945f6514b8
6ファイル変更
+111
-136
検索条件に一致するファイルはありません
@@ -1,37 +0,0 @@
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Operations;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
|
||||
|
||||
/// <inheritdoc cref="HlslSourceRewriter"/>
|
||||
partial class HlslSourceRewriter
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IPropertyReferenceOperation operation, ElementAccessExpressionSyntax node, string? mappedType)
|
||||
{
|
||||
// Get the syntax for the argument syntax transformation as described above
|
||||
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);
|
||||
|
||||
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
|
||||
// For instance: texture[uv] will be rewritten as texture.Sample(__sampler__texture, uv).
|
||||
return
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
node.Expression,
|
||||
IdentifierName("Sample")))
|
||||
.AddArgumentListArguments(Argument(IdentifierName($"__sampler__{mapped ?? fieldName}")), coordinateSyntax);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using ComputeSharp.SourceGeneration.Mappings;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Operations;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
|
||||
|
||||
@@ -12,6 +14,27 @@ partial class ShaderSourceRewriter
|
||||
/// </summary>
|
||||
public bool NeedsD2DRequiresScenePositionAttribute { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, InvocationExpressionSyntax node, string? mappedType)
|
||||
{
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
private partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする