Update HLSL rewriters to use new Sample APIs
このコミットが含まれているのは:
1 親
0dd0bd587a
コミット
945f6514b8
6ファイル変更
+111
-136
検索条件に一致するファイルはありません
@@ -1,42 +0,0 @@
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses a texture sampler at least once.
|
||||
/// </summary>
|
||||
public bool IsSamplerUsed { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IPropertyReferenceOperation operation, ElementAccessExpressionSyntax node, string? mappedType)
|
||||
{
|
||||
IsSamplerUsed = true;
|
||||
|
||||
// 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]
|
||||
};
|
||||
|
||||
// Transform an indexer syntax into a sampling call with the implicit static linear sampler.
|
||||
// For instance: texture[uv] will be rewritten as texture.SampleLevel(__sampler, uv, 0).
|
||||
return
|
||||
InvocationExpression(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
node.Expression,
|
||||
IdentifierName("SampleLevel")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(IdentifierName("__sampler")),
|
||||
coordinateSyntax,
|
||||
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using ComputeSharp.SourceGeneration.Extensions;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Operations;
|
||||
using static ComputeSharp.SourceGeneration.Diagnostics.DiagnosticDescriptors;
|
||||
using static Microsoft.CodeAnalysis.CSharp.SyntaxFactory;
|
||||
|
||||
namespace ComputeSharp.SourceGeneration.SyntaxRewriters;
|
||||
|
||||
@@ -25,6 +27,33 @@ partial class ShaderSourceRewriter
|
||||
/// </summary>
|
||||
public bool IsGridIdsUsed { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether or not the shader uses a texture sampler at least once.
|
||||
/// </summary>
|
||||
public bool IsSamplerUsed { get; private set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
private partial SyntaxNode RewriteSampledTextureAccess(IInvocationOperation operation, InvocationExpressionSyntax node, string? mappedType)
|
||||
{
|
||||
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")))
|
||||
.AddArgumentListArguments(
|
||||
Argument(IdentifierName("__sampler")),
|
||||
coordinateSyntax,
|
||||
Argument(LiteralExpression(SyntaxKind.NumericLiteralExpression, Literal(0))));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
private partial void TrackKnownPropertyAccess(IMemberReferenceOperation operation, MemberAccessExpressionSyntax node, string mappedName)
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする