Use PipelineStageArgs throughout GrSkSLFP and PipelineStageCodeGenerator
Making it easier to modify the objects that are emitted by the generator
and consumed by the FP (as a pre-cursor to sampling children with
explicit coords).
Change-Id: Id746a23537c97ba7a8ac27a63622503f59c902f5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/266377
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/effects/GrSkSLFP.cpp b/src/gpu/effects/GrSkSLFP.cpp
index a995b0b..81d89b8 100644
--- a/src/gpu/effects/GrSkSLFP.cpp
+++ b/src/gpu/effects/GrSkSLFP.cpp
@@ -19,11 +19,7 @@
class GrGLSLSkSLFP : public GrGLSLFragmentProcessor {
public:
- GrGLSLSkSLFP(SkSL::String glsl, std::vector<SkSL::Compiler::FormatArg> formatArgs,
- std::vector<SkSL::Compiler::GLSLFunction> functions)
- : fGLSL(glsl)
- , fFormatArgs(std::move(formatArgs))
- , fFunctions(std::move(functions)) {}
+ GrGLSLSkSLFP(SkSL::PipelineStageArgs&& args) : fArgs(std::move(args)) {}
SkSL::String expandFormatArgs(const SkSL::String& raw,
const EmitArgs& args,
@@ -103,7 +99,7 @@
childNames.push_back(SkStringPrintf("_child%d", i));
this->invokeChild(i, &childNames[i], args);
}
- for (const auto& f : fFunctions) {
+ for (const auto& f : fArgs.fFunctions) {
fFunctionNames.emplace_back();
SkSL::String body = this->expandFormatArgs(f.fBody.c_str(), args, f.fFormatArgs,
coords.c_str(), childNames);
@@ -114,7 +110,7 @@
body.c_str(),
&fFunctionNames.back());
}
- fragBuilder->codeAppend(this->expandFormatArgs(fGLSL.c_str(), args, fFormatArgs,
+ fragBuilder->codeAppend(this->expandFormatArgs(fArgs.fCode.c_str(), args, fArgs.fFormatArgs,
coords.c_str(), childNames).c_str());
}
@@ -159,9 +155,7 @@
}
// nearly-finished GLSL; still contains printf-style "%s" format tokens
- const SkSL::String fGLSL;
- std::vector<SkSL::Compiler::FormatArg> fFormatArgs;
- std::vector<SkSL::Compiler::GLSLFunction> fFunctions;
+ SkSL::PipelineStageArgs fArgs;
std::vector<UniformHandle> fUniformHandles;
std::vector<SkString> fFunctionNames;
};
@@ -219,8 +213,7 @@
// Note: This is actually SkSL (again) but with inline format specifiers.
SkSL::PipelineStageArgs args;
SkAssertResult(fEffect->toPipelineStage(fInputs.get(), fShaderCaps.get(), &args));
- return new GrGLSLSkSLFP(std::move(args.fCode), std::move(args.fFormatArgs),
- std::move(args.fFunctions));
+ return new GrGLSLSkSLFP(std::move(args));
}
void GrSkSLFP::onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const {
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 7bfdce1..9ce454d 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -1606,8 +1606,7 @@
SkASSERT(program.fIsOptimized);
fSource = program.fSource.get();
StringStream buffer;
- PipelineStageCodeGenerator cg(fContext.get(), &program, this, &buffer, &outArgs->fFormatArgs,
- &outArgs->fFunctions);
+ PipelineStageCodeGenerator cg(fContext.get(), &program, this, &buffer, outArgs);
bool result = cg.generateCode();
fSource = nullptr;
if (result) {
diff --git a/src/sksl/SkSLPipelineStageCodeGenerator.cpp b/src/sksl/SkSLPipelineStageCodeGenerator.cpp
index 8a7998e..08cedbf 100644
--- a/src/sksl/SkSLPipelineStageCodeGenerator.cpp
+++ b/src/sksl/SkSLPipelineStageCodeGenerator.cpp
@@ -19,11 +19,9 @@
const Program* program,
ErrorReporter* errors,
OutputStream* out,
- std::vector<Compiler::FormatArg>* outFormatArgs,
- std::vector<Compiler::GLSLFunction>* outFunctions)
+ PipelineStageArgs* outArgs)
: INHERITED(context, program, errors, out)
- , fFormatArgs(outFormatArgs)
- , fFunctions(outFunctions) {}
+ , fArgs(outArgs) {}
void PipelineStageCodeGenerator::writeHeader() {
}
@@ -82,8 +80,8 @@
}
SkASSERT(found);
this->write("%s");
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kChildProcessor,
- index));
+ fArgs->fFormatArgs.push_back(
+ Compiler::FormatArg(Compiler::FormatArg::Kind::kChildProcessor, index));
return;
}
if (c.fFunction.fBuiltin) {
@@ -99,8 +97,8 @@
++index;
}
}
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kFunctionName,
- index));
+ fArgs->fFormatArgs.push_back(
+ Compiler::FormatArg(Compiler::FormatArg::Kind::kFunctionName, index));
this->write("(");
const char* separator = "";
for (const auto& arg : c.fArguments) {
@@ -120,19 +118,19 @@
switch (ref.fVariable.fModifiers.fLayout.fBuiltin) {
case SK_INCOLOR_BUILTIN:
this->write("%s");
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kInput));
+ fArgs->fFormatArgs.push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kInput));
break;
case SK_OUTCOLOR_BUILTIN:
this->write("%s");
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kOutput));
+ fArgs->fFormatArgs.push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kOutput));
break;
case SK_MAIN_X_BUILTIN:
this->write("%s");
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kCoordX));
+ fArgs->fFormatArgs.push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kCoordX));
break;
case SK_MAIN_Y_BUILTIN:
this->write("%s");
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kCoordY));
+ fArgs->fFormatArgs.push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kCoordY));
break;
default:
if (ref.fVariable.fModifiers.fFlags & Modifiers::kUniform_Flag) {
@@ -158,8 +156,8 @@
}
}
SkASSERT(found);
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kUniform,
- index));
+ fArgs->fFormatArgs.push_back(
+ Compiler::FormatArg(Compiler::FormatArg::Kind::kUniform, index));
} else {
this->write(ref.fVariable.fName);
}
@@ -216,8 +214,8 @@
fOut = &buffer;
if (f.fDeclaration.fName == "main") {
this->write("%s = %s;\n");
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kOutput));
- fFormatArgs->push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kInput));
+ fArgs->fFormatArgs.push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kOutput));
+ fArgs->fFormatArgs.push_back(Compiler::FormatArg(Compiler::FormatArg::Kind::kInput));
for (const auto& s : ((Block&) *f.fBody).fStatements) {
this->writeStatement(*s);
this->writeLine();
@@ -239,8 +237,8 @@
}
fOut = oldOut;
result.fBody = buffer.str();
- result.fFormatArgs = std::move(*fFormatArgs);
- fFunctions->push_back(result);
+ result.fFormatArgs = std::move(fArgs->fFormatArgs);
+ fArgs->fFunctions.push_back(result);
}
}
diff --git a/src/sksl/SkSLPipelineStageCodeGenerator.h b/src/sksl/SkSLPipelineStageCodeGenerator.h
index 13b319d..39b5c22 100644
--- a/src/sksl/SkSLPipelineStageCodeGenerator.h
+++ b/src/sksl/SkSLPipelineStageCodeGenerator.h
@@ -18,8 +18,7 @@
public:
PipelineStageCodeGenerator(const Context* context, const Program* program,
ErrorReporter* errors, OutputStream* out,
- std::vector<Compiler::FormatArg>* outFormatArgs,
- std::vector<Compiler::GLSLFunction>* outFunctions);
+ PipelineStageArgs* outArgs);
private:
void writeHeader() override;
@@ -44,8 +43,7 @@
void writeProgramElement(const ProgramElement& p) override;
- std::vector<Compiler::FormatArg>* fFormatArgs;
- std::vector<Compiler::GLSLFunction>* fFunctions;
+ PipelineStageArgs* fArgs;
typedef GLSLCodeGenerator INHERITED;
};