Fix overzealous destruction of DSL FP VarDeclarations.

Previously, if a DSL-based FP attempted to sample from another DSL-based
FP, all VarDeclarations for both FPs would be erased as soon as the
inner FP called EndFragmentProcessor. We now use the DSL stack to save
and restore the VarDeclarations array when FPs are nested.

Change-Id: I7481d89ac62ca6cdc6fc828ffdc61d6a36affbdc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400539
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
John Stiles 2021-04-23 14:42:22 -04:00 committed by Skia Commit-Bot
parent 56bc148786
commit 3befaf23a9
2 changed files with 7 additions and 3 deletions

View File

@ -95,14 +95,16 @@ const char* DSLWriter::Name(const char* name) {
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
void DSLWriter::StartFragmentProcessor(GrGLSLFragmentProcessor* processor,
GrGLSLFragmentProcessor::EmitArgs* emitArgs) {
Instance().fStack.push({processor, emitArgs});
DSLWriter& instance = Instance();
instance.fStack.push({processor, emitArgs, StatementArray{}});
CurrentEmitArgs()->fFragBuilder->fDeclarations.swap(instance.fStack.top().fSavedDeclarations);
IRGenerator().pushSymbolTable();
}
void DSLWriter::EndFragmentProcessor() {
DSLWriter& instance = Instance();
SkASSERT(!instance.fStack.empty());
CurrentEmitArgs()->fFragBuilder->fDeclarations.reset();
CurrentEmitArgs()->fFragBuilder->fDeclarations.swap(instance.fStack.top().fSavedDeclarations);
instance.fStack.pop();
IRGenerator().popSymbolTable();
}

View File

@ -19,6 +19,7 @@
#if !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
#endif // !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
#include <list>
#include <stack>
class AutoDSLContext;
@ -220,8 +221,9 @@ private:
struct StackFrame {
GrGLSLFragmentProcessor* fProcessor;
GrGLSLFragmentProcessor::EmitArgs* fEmitArgs;
SkSL::StatementArray fSavedDeclarations;
};
std::stack<StackFrame> fStack;
std::stack<StackFrame, std::list<StackFrame>> fStack;
#endif // !defined(SKSL_STANDALONE) && SK_SUPPORT_GPU
friend class DSLCore;