fixed skslc SPIR-V memory error
authorEthan Nicholas <ethannicholas@google.com>
Thu, 30 Mar 2017 18:11:58 +0000 (14:11 -0400)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Thu, 30 Mar 2017 19:39:20 +0000 (19:39 +0000)
BUG=skia:6446

Change-Id: Ibc55124db60d6a05964ddcd02d285e313379f93e
Reviewed-on: https://skia-review.googlesource.com/10756
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>

src/sksl/SkSLCompiler.cpp
src/sksl/SkSLIRGenerator.cpp
src/sksl/SkSLSPIRVCodeGenerator.cpp
src/sksl/SkSLSPIRVCodeGenerator.h
src/sksl/ir/SkSLInterfaceBlock.h
src/sksl/ir/SkSLSymbolTable.h

index 1cbc441..08b49e6 100644 (file)
@@ -49,8 +49,8 @@ namespace SkSL {
 
 Compiler::Compiler()
 : fErrorCount(0) {
-    auto types = std::shared_ptr<SymbolTable>(new SymbolTable(*this));
-    auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, *this));
+    auto types = std::shared_ptr<SymbolTable>(new SymbolTable(this));
+    auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, this));
     fIRGenerator = new IRGenerator(&fContext, symbols, *this);
     fTypes = types;
     #define ADD_TYPE(t) types->addWithoutOwnership(fContext.f ## t ## _Type->fName, \
index ae2a90f..2a4c85d 100644 (file)
@@ -108,7 +108,7 @@ IRGenerator::IRGenerator(const Context* context, std::shared_ptr<SymbolTable> sy
 , fErrors(errorReporter) {}
 
 void IRGenerator::pushSymbolTable() {
-    fSymbolTable.reset(new SymbolTable(std::move(fSymbolTable), fErrors));
+    fSymbolTable.reset(new SymbolTable(std::move(fSymbolTable), &fErrors));
 }
 
 void IRGenerator::popSymbolTable() {
@@ -665,7 +665,8 @@ std::unique_ptr<InterfaceBlock> IRGenerator::convertInterfaceBlock(const ASTInte
                                                                        (int) i)));
         }
     }
-    return std::unique_ptr<InterfaceBlock>(new InterfaceBlock(intf.fPosition, *var,
+    return std::unique_ptr<InterfaceBlock>(new InterfaceBlock(intf.fPosition,
+                                                              var,
                                                               intf.fTypeName,
                                                               intf.fInstanceName,
                                                               std::move(sizes),
index 93ec4ce..2fa4e64 100644 (file)
@@ -1865,7 +1865,7 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, S
         // need to remap to a top-left coordinate system
         if (fRTHeightStructId == (SpvId) -1) {
             // height variable hasn't been written yet
-            std::shared_ptr<SymbolTable> st(new SymbolTable(fErrors));
+            std::shared_ptr<SymbolTable> st(new SymbolTable(&fErrors));
             ASSERT(fRTHeightFieldIndex == (SpvId) -1);
             std::vector<Type::Field> fields;
             fields.emplace_back(Modifiers(), SkString(SKSL_RTHEIGHT_NAME),
@@ -1874,8 +1874,12 @@ SpvId SPIRVCodeGenerator::writeVariableReference(const VariableReference& ref, S
             Type intfStruct(Position(), name, fields);
             Layout layout(-1, -1, 1, -1, -1, -1, -1, false, false, false, Layout::Format::kUnspecified,
                           false, Layout::kUnspecified_Primitive, -1, -1);
-            Variable intfVar(Position(), Modifiers(layout, Modifiers::kUniform_Flag), name,
-                             intfStruct, Variable::kGlobal_Storage);
+            Variable* intfVar = new Variable(Position(),
+                                             Modifiers(layout, Modifiers::kUniform_Flag),
+                                             name,
+                                             intfStruct,
+                                             Variable::kGlobal_Storage);
+            fSynthetics.takeOwnership(intfVar);
             InterfaceBlock intf(Position(), intfVar, name, SkString(""),
                                 std::vector<std::unique_ptr<Expression>>(), st);
             fRTHeightStructId = this->writeInterfaceBlock(intf);
index 1cdc653..ea160b1 100644 (file)
@@ -74,7 +74,8 @@ public:
     , fBoolTrue(0)
     , fBoolFalse(0)
     , fSetupFragPosition(false)
-    , fCurrentBlock(0) {
+    , fCurrentBlock(0)
+    , fSynthetics(nullptr, errors) {
         this->setupIntrinsics();
     }
 
@@ -299,6 +300,8 @@ private:
     std::stack<SpvId> fContinueTarget;
     SpvId fRTHeightStructId = (SpvId) -1;
     SpvId fRTHeightFieldIndex = (SpvId) -1;
+    // holds variables synthesized during output, for lifetime purposes
+    SymbolTable fSynthetics;
 
     friend class PointerLValue;
     friend class SwizzleLValue;
index 0de37c5..0ec33e3 100644 (file)
@@ -25,11 +25,11 @@ namespace SkSL {
  * At the IR level, this is represented by a single variable of struct type.
  */
 struct InterfaceBlock : public ProgramElement {
-    InterfaceBlock(Position position, const Variable& var, SkString typeName, SkString instanceName,
+    InterfaceBlock(Position position, const Variable* var, SkString typeName, SkString instanceName,
                    std::vector<std::unique_ptr<Expression>> sizes,
                    std::shared_ptr<SymbolTable> typeOwner)
     : INHERITED(position, kInterfaceBlock_Kind)
-    , fVariable(std::move(var))
+    , fVariable(*var)
     , fTypeName(std::move(typeName))
     , fInstanceName(std::move(instanceName))
     , fSizes(std::move(sizes))
index df8dc71..948a447 100644 (file)
@@ -24,12 +24,12 @@ struct FunctionDeclaration;
  */
 class SymbolTable {
 public:
-    SymbolTable(ErrorReporter& errorReporter)
-    : fErrorReporter(errorReporter) {}
+    SymbolTable(ErrorReporter* errorReporter)
+    : fErrorReporter(*errorReporter) {}
 
-    SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter& errorReporter)
+    SymbolTable(std::shared_ptr<SymbolTable> parent, ErrorReporter* errorReporter)
     : fParent(parent)
-    , fErrorReporter(errorReporter) {}
+    , fErrorReporter(*errorReporter) {}
 
     const Symbol* operator[](const SkString& name);