SkSL DSL code is now automatically incorporated into the output
Previously, a manual codeAppend call was required to add a statement. We now automatically invoke codeAppend when a statement is destroyed. Change-Id: I09eaf230b1d58242c3ff6abb85e970ed5ed3bce2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/371141 Auto-Submit: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
2bb5ef3e9f
commit
3af656b276
@ -35,9 +35,8 @@ public:
|
||||
Var blueAlpha(kUniform_Modifier, kHalf2);
|
||||
fBlueAlphaUniform = VarUniformHandle(blueAlpha);
|
||||
Var coords(kFloat4);
|
||||
args.fFragBuilder->codeAppend(Declare(coords, sk_FragCoord()));
|
||||
args.fFragBuilder->codeAppend(Return(Half4(Swizzle(coords, X, Y) / 100,
|
||||
blueAlpha)));
|
||||
Declare(coords, sk_FragCoord());
|
||||
Return(Half4(Swizzle(coords, X, Y) / 100, blueAlpha));
|
||||
EndFragmentProcessor();
|
||||
}
|
||||
|
||||
|
@ -89,12 +89,10 @@ void GrGLSLShaderBuilder::emitFunctionPrototype(GrSLType returnType,
|
||||
this->functions().append(";\n");
|
||||
}
|
||||
|
||||
void GrGLSLShaderBuilder::codeAppend(SkSL::dsl::Statement stmt) {
|
||||
void GrGLSLShaderBuilder::codeAppend(std::unique_ptr<SkSL::Statement> stmt) {
|
||||
SkASSERT(SkSL::dsl::DSLWriter::CurrentProcessor());
|
||||
std::unique_ptr<SkSL::Statement> skslStmt = stmt.release();
|
||||
if (skslStmt) {
|
||||
this->codeAppend(skslStmt->description().c_str());
|
||||
}
|
||||
SkASSERT(stmt);
|
||||
this->codeAppend(stmt->description().c_str());
|
||||
}
|
||||
|
||||
static inline void append_texture_swizzle(SkString* out, GrSwizzle swizzle) {
|
||||
|
@ -20,9 +20,13 @@
|
||||
class GrGLSLColorSpaceXformHelper;
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
class Statement;
|
||||
|
||||
namespace dsl {
|
||||
class DSLStatement;
|
||||
} // namespace dsl
|
||||
|
||||
} // namespace SkSL
|
||||
|
||||
/**
|
||||
@ -117,7 +121,7 @@ public:
|
||||
|
||||
void codeAppend(const char* str, size_t length) { this->code().append(str, length); }
|
||||
|
||||
void codeAppend(SkSL::dsl::DSLStatement stmt);
|
||||
void codeAppend(std::unique_ptr<SkSL::Statement> stmt);
|
||||
|
||||
void codePrependf(const char format[], ...) SK_PRINTF_LIKE(2, 3) {
|
||||
va_list args;
|
||||
|
@ -19,6 +19,10 @@
|
||||
|
||||
#include "math.h"
|
||||
|
||||
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#endif
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
namespace dsl {
|
||||
@ -63,6 +67,13 @@ DSLExpression::DSLExpression(const DSLVar& var)
|
||||
SkSL::VariableReference::RefKind::kRead)) {}
|
||||
|
||||
DSLExpression::~DSLExpression() {
|
||||
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
|
||||
if (fExpression && DSLWriter::InFragmentProcessor()) {
|
||||
DSLWriter::CurrentEmitArgs()->fFragBuilder->codeAppend(
|
||||
DSLStatement(this->release()).release());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
SkASSERTF(fExpression == nullptr,
|
||||
"Expression destroyed without being incorporated into program");
|
||||
}
|
||||
|
@ -13,6 +13,10 @@
|
||||
#include "src/sksl/dsl/priv/DSLWriter.h"
|
||||
#include "src/sksl/ir/SkSLExpressionStatement.h"
|
||||
|
||||
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
|
||||
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
|
||||
#endif
|
||||
|
||||
namespace SkSL {
|
||||
|
||||
namespace dsl {
|
||||
@ -38,6 +42,16 @@ DSLStatement::DSLStatement(std::unique_ptr<SkSL::Statement> stmt)
|
||||
}
|
||||
}
|
||||
|
||||
DSLStatement::~DSLStatement() {
|
||||
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
|
||||
if (fStatement && DSLWriter::InFragmentProcessor()) {
|
||||
DSLWriter::CurrentEmitArgs()->fFragBuilder->codeAppend(this->release());
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
SkASSERTF(!fStatement, "Statement destroyed without being incorporated into program");
|
||||
}
|
||||
|
||||
} // namespace dsl
|
||||
|
||||
} // namespace SkSL
|
||||
|
@ -36,9 +36,7 @@ public:
|
||||
|
||||
DSLStatement(DSLStatement&&) = default;
|
||||
|
||||
~DSLStatement() {
|
||||
SkASSERTF(!fStatement, "Statement destroyed without being incorporated into program");
|
||||
}
|
||||
~DSLStatement();
|
||||
|
||||
std::unique_ptr<SkSL::Statement> release() {
|
||||
return std::move(fStatement);
|
||||
@ -53,6 +51,7 @@ private:
|
||||
|
||||
friend class DSLBlock;
|
||||
friend class DSLCore;
|
||||
friend class DSLExpression;
|
||||
friend class DSLWriter;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user