Use DSL to simplify applyInvocationIDWorkaround

Now that the DSL is available from within the compiler, we can use it
instead of the previous complex IR tree generation.

Change-Id: I7a95d245dbc21386790a1cc786899b38cbdf5345
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/409897
Reviewed-by: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2021-05-18 12:09:01 -04:00 committed by Skia Commit-Bot
parent 4af11a109a
commit be65cd5543

View File

@ -14,6 +14,7 @@
#include "include/private/SkSLLayout.h"
#include "include/private/SkTArray.h"
#include "include/sksl/DSLCore.h"
#include "src/core/SkScopeExit.h"
#include "src/sksl/SkSLAnalysis.h"
#include "src/sksl/SkSLCompiler.h"
@ -685,44 +686,20 @@ std::unique_ptr<Block> IRGenerator::applyInvocationIDWorkaround(std::unique_ptr<
std::move(main));
invokeDecl->setDefinition(invokeDef.get());
fProgramElements->push_back(std::move(invokeDef));
std::vector<std::unique_ptr<VarDeclaration>> variables;
const Variable* loopIdx = &(*fSymbolTable)["sk_InvocationID"]->as<Variable>();
auto test = BinaryExpression::Make(
fContext,
VariableReference::Make(/*offset=*/-1, loopIdx),
Token::Kind::TK_LT,
IntLiteral::Make(fContext, /*offset=*/-1, fInvocations));
auto next = PostfixExpression::Make(
fContext,
VariableReference::Make(/*offset=*/-1, loopIdx, VariableRefKind::kReadWrite),
Token::Kind::TK_PLUSPLUS);
ASTNode endPrimitiveID(&fFile->fNodes, -1, ASTNode::Kind::kIdentifier, "EndPrimitive");
std::unique_ptr<Expression> endPrimitive = this->convertExpression(endPrimitiveID);
using namespace SkSL::dsl;
DSLVar loopIdx = DSLVar("sk_InvocationID");
std::unique_ptr<Expression> endPrimitive = this->convertIdentifier(/*offset=*/-1,
"EndPrimitive");
SkASSERT(endPrimitive);
StatementArray loopBody;
loopBody.reserve_back(2);
loopBody.push_back(ExpressionStatement::Make(fContext, this->call(/*offset=*/-1,
*invokeDecl,
ExpressionArray{})));
loopBody.push_back(ExpressionStatement::Make(fContext, this->call(/*offset=*/-1,
std::move(endPrimitive),
ExpressionArray{})));
auto assignment = BinaryExpression::Make(
fContext,
VariableReference::Make(/*offset=*/-1, loopIdx, VariableRefKind::kWrite),
Token::Kind::TK_EQ,
IntLiteral::Make(fContext, /*offset=*/-1, /*value=*/0));
auto initializer = ExpressionStatement::Make(fContext, std::move(assignment));
auto loop = ForStatement::Make(fContext, /*offset=*/-1,
std::move(initializer),
std::move(test),
std::move(next),
Block::Make(/*offset=*/-1, std::move(loopBody)),
fSymbolTable);
StatementArray children;
children.push_back(std::move(loop));
return Block::Make(/*offset=*/-1, std::move(children));
std::unique_ptr<Statement> block = DSLBlock(
For(loopIdx = 0, loopIdx < fInvocations, loopIdx++, DSLBlock(
DSLFunction(invokeDecl)(),
DSLExpression(std::move(endPrimitive))({})
))
).release();
return std::unique_ptr<Block>(&block.release()->as<Block>());
}
std::unique_ptr<Statement> IRGenerator::getNormalizeSkPositionCode() {