]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/optimize.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / glsl / optimize.h
index ae55e5af10f5590f886906355342327a8ddb87be..807b7a89ac90feb4c8f2d57afbeb2e2f5bb17596 100644 (file)
@@ -71,7 +71,6 @@ public:
 
 private:
        virtual void visit(VariableReference &);
-       virtual void visit(InterfaceBlockReference &);
        virtual void visit(FunctionCall &);
        virtual void visit(VariableDeclaration &);
        virtual void visit(Return &);
@@ -122,6 +121,7 @@ private:
                Block *assign_scope = 0;
                std::vector<ExpressionUse> uses;
                bool trivial = false;
+               bool blocked = false;
        };
 
        std::list<ExpressionInfo> expressions;
@@ -151,6 +151,52 @@ private:
        virtual void visit(Iteration &);
 };
 
+/**
+Breaks aggregates up into separate variables if only the individual fields are
+accessed and not the aggregate as a whole.
+*/
+class AggregateDismantler: public TraversingVisitor
+{
+private:
+       struct AggregateMember
+       {
+               const VariableDeclaration *declaration = 0;
+               unsigned index = 0;
+               RefPtr<Expression> initializer;
+               std::vector<RefPtr<Expression> *> references;
+       };
+
+       struct Aggregate
+       {
+               VariableDeclaration *declaration = 0;
+               Block *decl_scope = 0;
+               NodeList<Statement>::iterator insert_point;
+               std::vector<AggregateMember> members;
+               bool referenced = false;
+               bool members_referenced = false;
+       };
+
+       NodeList<Statement>::iterator insert_point;
+       std::map<Statement *, Aggregate> aggregates;
+       bool composite_reference = false;
+       Assignment::Target r_reference;
+       Aggregate *r_aggregate_ref = 0;
+
+public:
+       bool apply(Stage &);
+
+private:
+       virtual void visit(Block &);
+       virtual void visit(RefPtr<Expression> &);
+       virtual void visit(VariableReference &);
+       void visit_composite(RefPtr<Expression> &);
+       virtual void visit(MemberAccess &);
+       virtual void visit(BinaryExpression &);
+       virtual void visit(StructDeclaration &) { }
+       virtual void visit(VariableDeclaration &);
+       virtual void visit(FunctionDeclaration &);
+};
+
 /** Replaces expressions consisting entirely of literals with the results of
 evaluating the expression.*/
 class ConstantFolder: private TraversingVisitor
@@ -214,7 +260,7 @@ private:
        bool r_external_side_effects = false;
 
 public:
-       void apply(Stage &);
+       bool apply(Stage &);
 
 private:
        ConstantStatus check_constant_condition(const Expression &);
@@ -229,6 +275,7 @@ private:
        virtual void visit(Iteration &);
 };
 
+/** Removes code which is never executed due to flow control statements. */
 class UnreachableCodeRemover: private TraversingVisitor
 {
 private:
@@ -262,7 +309,6 @@ private:
        virtual void visit(ImageTypeDeclaration &);
        virtual void visit(StructDeclaration &);
        virtual void visit(VariableDeclaration &);
-       virtual void visit(InterfaceBlock &);
        virtual void visit(FunctionDeclaration &);
 };
 
@@ -281,19 +327,17 @@ private:
 
        struct VariableInfo
        {
-               InterfaceBlock *interface_block = 0;
                std::vector<AssignmentInfo *> assignments;
                bool initialized = false;
                bool output = false;
                bool referenced = false;
        };
 
-       typedef std::map<Statement *, VariableInfo> BlockVariableMap;
+       typedef std::map<VariableDeclaration *, VariableInfo> BlockVariableMap;
 
        Stage *stage = 0;
        BlockVariableMap variables;
        std::list<AssignmentInfo> assignments;
-       InterfaceBlock *interface_block = 0;
        Assignment *r_assignment = 0;
        bool assignment_target = false;
        bool r_side_effects = false;
@@ -310,7 +354,6 @@ public:
 private:
        void referenced(const Assignment::Target &, Node &);
        virtual void visit(VariableReference &);
-       virtual void visit(InterfaceBlockReference &);
        void visit_composite(Expression &);
        virtual void visit(MemberAccess &);
        virtual void visit(Swizzle &);
@@ -323,7 +366,6 @@ private:
        virtual void visit(ExpressionStatement &);
        virtual void visit(StructDeclaration &);
        virtual void visit(VariableDeclaration &);
-       virtual void visit(InterfaceBlock &);
        void merge_variables(const BlockVariableMap &);
        virtual void visit(FunctionDeclaration &);
        virtual void visit(Conditional &);