Added DSL sk_SampleCoord var

Change-Id: I539a288765243b2b9d994240c7917b036590f49d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/370916
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2021-02-17 15:52:09 -05:00 committed by Skia Commit-Bot
parent 24ec76454a
commit 8d03eb0945
4 changed files with 26 additions and 0 deletions

View File

@ -22,6 +22,24 @@ namespace dsl {
DSLVar::DSLVar(const char* name)
: fName(name) {
#if SK_SUPPORT_GPU && !defined(SKSL_STANDALONE)
if (!strcmp(name, "sk_SampleCoord")) {
fName = DSLWriter::CurrentEmitArgs()->fSampleCoord;
// The actual sk_SampleCoord variable hasn't been created by GrGLSLFPFragmentBuilder yet, so
// if we attempt to look it up in the symbol table we'll get null. As we are currently
// converting all DSL code into strings rather than nodes, all we really need is a
// correctly-named variable with the right type, so we just create a placeholder for it.
// TODO(skia/11330): we'll need to fix this when switching over to nodes.
fVar = DSLWriter::SymbolTable()->takeOwnershipOfIRNode(std::make_unique<SkSL::Variable>(
/*offset=*/-1,
DSLWriter::IRGenerator().fModifiers->addToPool(SkSL::Modifiers()),
fName,
DSLWriter::Context().fTypes.fFloat2.get(),
/*builtin=*/true,
SkSL::VariableStorage::kGlobal));
return;
}
#endif
const SkSL::Symbol* result = (*DSLWriter::SymbolTable())[fName];
SkASSERTF(result, "could not find '%s' in symbol table", fName);
fVar = &result->as<SkSL::Variable>();

View File

@ -119,6 +119,8 @@ private:
const SkSL::Variable* fVar = nullptr;
const char* fName;
friend DSLVar sk_SampleCoord();
friend class DSLCore;
friend class DSLExpression;
friend class DSLWriter;

View File

@ -25,6 +25,10 @@ void EndFragmentProcessor() {
DSLWriter::EndFragmentProcessor();
}
DSLVar sk_SampleCoord() {
return DSLVar("sk_SampleCoord");
}
DSLExpression SampleChild(int index, DSLExpression coords) {
std::unique_ptr<SkSL::Expression> coordsExpr = coords.release();
SkString code = DSLWriter::CurrentProcessor()->invokeChild(index, *DSLWriter::CurrentEmitArgs(),

View File

@ -23,6 +23,8 @@ void StartFragmentProcessor(GrGLSLFragmentProcessor* processor,
void EndFragmentProcessor();
DSLVar sk_SampleCoord();
DSLExpression SampleChild(int index, DSLExpression coords = DSLExpression());
GrGLSLUniformHandler::UniformHandle VarUniformHandle(const DSLVar& var);