From 8b43dadea286be40e6b6e0b94235d828e999df83 Mon Sep 17 00:00:00 2001 From: Brian Osman Date: Fri, 9 Oct 2020 13:31:42 -0400 Subject: [PATCH] In SPIRVCodeGenerator, use the Program's ModifiersPool We were passing in the IR generator's which had already been reset, so technically belonged to the *next* Program to be compiled. Change-Id: Ib68c283591f02d1642bb7c2d9658f5caa76b0f15 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324700 Commit-Queue: Brian Osman Commit-Queue: Ethan Nicholas Auto-Submit: Brian Osman Reviewed-by: Ethan Nicholas --- src/sksl/SkSLCompiler.cpp | 5 ++--- src/sksl/SkSLModifiersPool.h | 4 ---- src/sksl/SkSLSPIRVCodeGenerator.cpp | 2 +- src/sksl/SkSLSPIRVCodeGenerator.h | 28 ++++++++++++++-------------- src/sksl/ir/SkSLProgram.h | 5 +---- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp index 7c551d6d26..66300c1cf2 100644 --- a/src/sksl/SkSLCompiler.cpp +++ b/src/sksl/SkSLCompiler.cpp @@ -1609,7 +1609,6 @@ bool Compiler::optimize(Program& program) { break; } } - program.finish(); return fErrorCount == 0; } @@ -1619,7 +1618,7 @@ bool Compiler::toSPIRV(Program& program, OutputStream& out) { #ifdef SK_ENABLE_SPIRV_VALIDATION StringStream buffer; fSource = program.fSource.get(); - SPIRVCodeGenerator cg(fContext.get(), fIRGenerator->fModifiers.get(), &program, this, &buffer); + SPIRVCodeGenerator cg(fContext.get(), &program, this, &buffer); bool result = cg.generateCode(); fSource = nullptr; if (result) { @@ -1637,7 +1636,7 @@ bool Compiler::toSPIRV(Program& program, OutputStream& out) { } #else fSource = program.fSource.get(); - SPIRVCodeGenerator cg(fContext.get(), fIRGenerator->fModifiers.get(), &program, this, &out); + SPIRVCodeGenerator cg(fContext.get(), &program, this, &out); bool result = cg.generateCode(); fSource = nullptr; #endif diff --git a/src/sksl/SkSLModifiersPool.h b/src/sksl/SkSLModifiersPool.h index 31e9bc4939..79a273575a 100644 --- a/src/sksl/SkSLModifiersPool.h +++ b/src/sksl/SkSLModifiersPool.h @@ -59,10 +59,6 @@ public: return Handle(this, index); } - void finish() { - fModifiersMap.clear(); - } - private: std::vector fModifiers; std::unordered_map fModifiersMap; diff --git a/src/sksl/SkSLSPIRVCodeGenerator.cpp b/src/sksl/SkSLSPIRVCodeGenerator.cpp index d541d7386b..e3f056ef1d 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.cpp +++ b/src/sksl/SkSLSPIRVCodeGenerator.cpp @@ -1879,7 +1879,7 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, O Modifiers modifiers(layout, Modifiers::kUniform_Flag); const Variable* intfVar = fSynthetics.takeOwnershipOfSymbol( std::make_unique(/*offset=*/-1, - fModifiers.handle(modifiers), + fProgram.fModifiers->handle(modifiers), name, &intfStruct, /*builtin=*/false, diff --git a/src/sksl/SkSLSPIRVCodeGenerator.h b/src/sksl/SkSLSPIRVCodeGenerator.h index 21f9f4ec03..a5f1b5271f 100644 --- a/src/sksl/SkSLSPIRVCodeGenerator.h +++ b/src/sksl/SkSLSPIRVCodeGenerator.h @@ -104,19 +104,20 @@ public: virtual void store(SpvId value, OutputStream& out) = 0; }; - SPIRVCodeGenerator(const Context* context, ModifiersPool* modifiers, - const Program* program, ErrorReporter* errors, OutputStream* out) - : INHERITED(program, errors, out) - , fContext(*context) - , fModifiers(*modifiers) - , fDefaultLayout(MemoryLayout::k140_Standard) - , fCapabilities(0) - , fIdCount(1) - , fBoolTrue(0) - , fBoolFalse(0) - , fSetupFragPosition(false) - , fCurrentBlock(0) - , fSynthetics(errors) { + SPIRVCodeGenerator(const Context* context, + const Program* program, + ErrorReporter* errors, + OutputStream* out) + : INHERITED(program, errors, out) + , fContext(*context) + , fDefaultLayout(MemoryLayout::k140_Standard) + , fCapabilities(0) + , fIdCount(1) + , fBoolTrue(0) + , fBoolFalse(0) + , fSetupFragPosition(false) + , fCurrentBlock(0) + , fSynthetics(errors) { this->setupIntrinsics(); } @@ -367,7 +368,6 @@ private: void writeGeometryShaderExecutionMode(SpvId entryPoint, OutputStream& out); const Context& fContext; - ModifiersPool& fModifiers; const MemoryLayout fDefaultLayout; uint64_t fCapabilities; diff --git a/src/sksl/ir/SkSLProgram.h b/src/sksl/ir/SkSLProgram.h index 4ac778eb56..2314faab49 100644 --- a/src/sksl/ir/SkSLProgram.h +++ b/src/sksl/ir/SkSLProgram.h @@ -177,10 +177,6 @@ struct Program { const std::vector>& elements() const { return fElements; } - void finish() { - fModifiers->finish(); - } - Kind fKind; std::unique_ptr fSource; Settings fSettings; @@ -195,6 +191,7 @@ private: std::unique_ptr fModifiers; friend class Compiler; + friend class SPIRVCodeGenerator; // fModifiers }; } // namespace SkSL