Restore DSLWriter to relying on a Compiler again.
This CL undoes most of the changes from http://review.skia.org/451739 and http://review.skia.org/451741 as these changes opened up a threading can of worms that is probably not solvable. I no longer have a use case for the new dsl::Start APIs. Change-Id: Icf0a86364d258ea3bbf0d18bbdbd130ef590c02f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/452097 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: John Stiles <johnstiles@google.com> Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
parent
ae5705e705
commit
11101181b9
@ -44,9 +44,6 @@ void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind = SkSL::ProgramKind:
|
||||
|
||||
void Start(SkSL::Compiler* compiler, SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings);
|
||||
|
||||
/** Allows lightweight DSL use, but no declaring variables or making function calls. */
|
||||
void Start(SkSL::Context* context, ProgramKind kind, const ProgramSettings& settings);
|
||||
|
||||
/**
|
||||
* Signals the end of DSL output. This must be called sometime between a call to Start() and the
|
||||
* termination of the thread.
|
||||
|
@ -34,23 +34,14 @@ void Start(SkSL::Compiler* compiler, ProgramKind kind) {
|
||||
}
|
||||
|
||||
void Start(SkSL::Compiler* compiler, ProgramKind kind, const ProgramSettings& settings) {
|
||||
DSLWriter::SetInstance(std::make_unique<DSLWriter>(&compiler->context(), compiler,
|
||||
&compiler->irGenerator(), kind, settings,
|
||||
DSLWriter::SetInstance(std::make_unique<DSLWriter>(compiler, kind, settings,
|
||||
compiler->moduleForProgramKind(kind),
|
||||
/*isModule=*/false));
|
||||
}
|
||||
|
||||
void Start(SkSL::Context* context, ProgramKind kind, const ProgramSettings& settings) {
|
||||
DSLWriter::SetInstance(std::make_unique<DSLWriter>(context, /*compiler=*/nullptr,
|
||||
/*irGenerator=*/nullptr, kind, settings,
|
||||
/*module=*/skstd::nullopt,
|
||||
/*isModule=*/false));
|
||||
}
|
||||
|
||||
void StartModule(SkSL::Compiler* compiler, ProgramKind kind, const ProgramSettings& settings,
|
||||
SkSL::ParsedModule module) {
|
||||
DSLWriter::SetInstance(std::make_unique<DSLWriter>(&compiler->context(), compiler,
|
||||
&compiler->irGenerator(), kind, settings,
|
||||
DSLWriter::SetInstance(std::make_unique<DSLWriter>(compiler, kind, settings,
|
||||
module, /*isModule=*/true));
|
||||
}
|
||||
|
||||
|
@ -29,80 +29,58 @@ namespace SkSL {
|
||||
|
||||
namespace dsl {
|
||||
|
||||
DSLWriter::DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler,
|
||||
SkSL::IRGenerator* irGenerator, SkSL::ProgramKind kind,
|
||||
const SkSL::ProgramSettings& settings,
|
||||
skstd::optional<SkSL::ParsedModule> module, bool isModule)
|
||||
: fContext(context)
|
||||
, fCompiler(compiler)
|
||||
, fIRGenerator(irGenerator)
|
||||
, fOldErrorReporter(*fContext->fErrors)
|
||||
DSLWriter::DSLWriter(SkSL::Compiler* compiler, SkSL::ProgramKind kind,
|
||||
const SkSL::ProgramSettings& settings, SkSL::ParsedModule module,
|
||||
bool isModule)
|
||||
: fCompiler(compiler)
|
||||
, fOldErrorReporter(*fCompiler->fContext->fErrors)
|
||||
, fSettings(settings)
|
||||
, fIsModule(isModule) {
|
||||
SkASSERT(fContext);
|
||||
if (fCompiler) {
|
||||
SkASSERT(fContext == fCompiler->fContext.get());
|
||||
}
|
||||
if (fIRGenerator) {
|
||||
SkASSERT(fContext == &fIRGenerator->fContext);
|
||||
}
|
||||
fOldModifiersPool = fCompiler->fContext->fModifiersPool;
|
||||
|
||||
fOldModifiersPool = fContext->fModifiersPool;
|
||||
|
||||
fOldConfig = fContext->fConfig;
|
||||
fOldConfig = fCompiler->fContext->fConfig;
|
||||
|
||||
if (!isModule) {
|
||||
if (fContext->fCaps.useNodePools() && settings.fDSLUseMemoryPool) {
|
||||
if (compiler->context().fCaps.useNodePools() && settings.fDSLUseMemoryPool) {
|
||||
fPool = Pool::Create();
|
||||
fPool->attachToThread();
|
||||
}
|
||||
fModifiersPool = std::make_unique<SkSL::ModifiersPool>();
|
||||
fContext->fModifiersPool = fModifiersPool.get();
|
||||
fCompiler->fContext->fModifiersPool = fModifiersPool.get();
|
||||
}
|
||||
|
||||
fConfig = std::make_unique<SkSL::ProgramConfig>();
|
||||
fConfig->fKind = kind;
|
||||
fConfig->fSettings = settings;
|
||||
fContext->fConfig = fConfig.get();
|
||||
fContext->fErrors = &fDefaultErrorReporter;
|
||||
fCompiler->fContext->fConfig = fConfig.get();
|
||||
fCompiler->fContext->fErrors = &fDefaultErrorReporter;
|
||||
|
||||
if (fIRGenerator && module.has_value()) {
|
||||
fIRGenerator->start(*module, isModule, &fProgramElements, &fSharedElements);
|
||||
}
|
||||
fCompiler->fIRGenerator->start(module, isModule, &fProgramElements, &fSharedElements);
|
||||
}
|
||||
|
||||
DSLWriter::~DSLWriter() {
|
||||
if (SymbolTable()) {
|
||||
if (fIRGenerator) {
|
||||
fIRGenerator->finish();
|
||||
}
|
||||
fCompiler->fIRGenerator->finish();
|
||||
fProgramElements.clear();
|
||||
} else {
|
||||
// We should only be here with a null symbol table if ReleaseProgram was called
|
||||
SkASSERT(fProgramElements.empty());
|
||||
}
|
||||
fContext->fErrors = &fOldErrorReporter;
|
||||
fContext->fConfig = fOldConfig;
|
||||
fContext->fModifiersPool = fOldModifiersPool;
|
||||
fCompiler->fContext->fErrors = &fOldErrorReporter;
|
||||
fCompiler->fContext->fConfig = fOldConfig;
|
||||
fCompiler->fContext->fModifiersPool = fOldModifiersPool;
|
||||
if (fPool) {
|
||||
fPool->detachFromThread();
|
||||
}
|
||||
}
|
||||
|
||||
SkSL::Compiler& DSLWriter::Compiler() {
|
||||
SkSL::Compiler* compiler = Instance().fCompiler;
|
||||
SkASSERT(compiler);
|
||||
return *compiler;
|
||||
}
|
||||
|
||||
SkSL::IRGenerator& DSLWriter::IRGenerator() {
|
||||
SkSL::IRGenerator* irGenerator = Instance().fIRGenerator;
|
||||
SkASSERT(irGenerator);
|
||||
return *irGenerator;
|
||||
return *Compiler().fIRGenerator;
|
||||
}
|
||||
|
||||
SkSL::Context& DSLWriter::Context() {
|
||||
return *Instance().fContext;
|
||||
return Compiler().context();
|
||||
}
|
||||
|
||||
SkSL::ProgramSettings& DSLWriter::Settings() {
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "include/core/SkStringView.h"
|
||||
#include "include/private/SkSLModifiers.h"
|
||||
#include "include/private/SkSLStatement.h"
|
||||
#include "include/private/SkTOptional.h"
|
||||
#include "include/sksl/DSLExpression.h"
|
||||
#include "include/sksl/DSLStatement.h"
|
||||
#include "src/sksl/SkSLMangler.h"
|
||||
@ -50,9 +49,8 @@ class DSLVar;
|
||||
*/
|
||||
class DSLWriter {
|
||||
public:
|
||||
DSLWriter(SkSL::Context* context, SkSL::Compiler* compiler, SkSL::IRGenerator* irGenerator,
|
||||
SkSL::ProgramKind kind, const SkSL::ProgramSettings& settings,
|
||||
skstd::optional<SkSL::ParsedModule> module, bool isModule);
|
||||
DSLWriter(SkSL::Compiler* compiler, SkSL::ProgramKind kind,
|
||||
const SkSL::ProgramSettings& settings, SkSL::ParsedModule module, bool isModule);
|
||||
|
||||
~DSLWriter();
|
||||
|
||||
@ -64,7 +62,7 @@ public:
|
||||
/**
|
||||
* Returns the Compiler used by DSL operations in the current thread.
|
||||
*/
|
||||
static SkSL::Compiler& Compiler();
|
||||
static SkSL::Compiler& Compiler() { return *Instance().fCompiler; }
|
||||
|
||||
/**
|
||||
* Returns the IRGenerator used by DSL operations in the current thread.
|
||||
@ -293,9 +291,7 @@ private:
|
||||
|
||||
std::unique_ptr<SkSL::ProgramConfig> fConfig;
|
||||
std::unique_ptr<SkSL::ModifiersPool> fModifiersPool;
|
||||
SkSL::Context* fContext;
|
||||
SkSL::Compiler* fCompiler;
|
||||
SkSL::IRGenerator* fIRGenerator;
|
||||
std::unique_ptr<Pool> fPool;
|
||||
SkSL::ProgramConfig* fOldConfig;
|
||||
SkSL::ModifiersPool* fOldModifiersPool;
|
||||
|
Loading…
Reference in New Issue
Block a user