Introduced IPixelShader<TPixel> interface, initial working support
このコミットが含まれているのは:
1 親
0a0f51bd5f
コミット
49d73b675f
15ファイル変更
+285
-23
検索条件に一致するファイルはありません
@@ -15,13 +15,20 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
/// </summary>
|
||||
private readonly ShaderSourceRewriter shaderSourceRewriter;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether or not the method belongs to a compute shader.
|
||||
/// </summary>
|
||||
private readonly bool isComputeShader;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ExecuteMethodRewriter"/> instance with the specified parameters.
|
||||
/// </summary>
|
||||
/// <param name="shaderSourceRewriter">The <see cref="ShaderSourceRewriter"/> instance used to process the input tree.</param>
|
||||
public ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter)
|
||||
/// <param name="isComputeShader">Indicates whether or not the method belongs to a compute shader.</param>
|
||||
public ExecuteMethodRewriter(ShaderSourceRewriter shaderSourceRewriter, bool isComputeShader)
|
||||
{
|
||||
this.shaderSourceRewriter = shaderSourceRewriter;
|
||||
this.isComputeShader = isComputeShader;
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="CSharpSyntaxRewriter.Visit(SyntaxNode?)"/>
|
||||
@@ -56,11 +63,42 @@ namespace ComputeSharp.SourceGenerators.SyntaxRewriters
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitReturnStatement(ReturnStatementSyntax node)
|
||||
{
|
||||
var updatedNode = (ReturnStatementSyntax)base.VisitReturnStatement(node)!;
|
||||
|
||||
if (this.isComputeShader)
|
||||
{
|
||||
return updatedNode;
|
||||
}
|
||||
|
||||
// __outputTexture[ThreadIds.xy] = <RETURN_EXPRESSION>;
|
||||
return
|
||||
ExpressionStatement(
|
||||
AssignmentExpression(
|
||||
SyntaxKind.SimpleAssignmentExpression,
|
||||
ElementAccessExpression(IdentifierName("__outputTexture"))
|
||||
.AddArgumentListArguments(
|
||||
Argument(
|
||||
MemberAccessExpression(
|
||||
SyntaxKind.SimpleMemberAccessExpression,
|
||||
IdentifierName("ThreadIds"),
|
||||
IdentifierName("xy")))),
|
||||
updatedNode.Expression!));
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override SyntaxNode? VisitMethodDeclaration(MethodDeclarationSyntax node)
|
||||
{
|
||||
var updatedNode = ((MethodDeclarationSyntax)base.VisitMethodDeclaration(node)!).WithModifiers(TokenList());
|
||||
|
||||
// Change the return type if the current shader is a pixel shader
|
||||
if (!this.isComputeShader)
|
||||
{
|
||||
updatedNode = updatedNode.WithReturnType(PredefinedType(Token(SyntaxKind.VoidKeyword)));
|
||||
}
|
||||
|
||||
// When we're rewriting the main compute shader method, we need to insert a range
|
||||
// check to ensure that invocation outside of the requested range are discarded.
|
||||
// The following snippet creates this prologue before the user provided body:
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする