X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=b8ab3201ccc54aa74fc603fce30caf8b5bd6b683;hb=57ff0b07aca38aee593a85831ba600b77e3b7a7b;hp=ae55e5af10f5590f886906355342327a8ddb87be;hpb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index ae55e5af..b8ab3201 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -151,6 +151,53 @@ 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 initializer; + std::vector *> references; + }; + + struct Aggregate + { + VariableDeclaration *declaration = 0; + Block *decl_scope = 0; + NodeList::iterator insert_point; + std::vector members; + bool referenced = false; + bool members_referenced = false; + }; + + NodeList::iterator insert_point; + std::map 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 &); + virtual void visit(VariableReference &); + void visit_composite(RefPtr &); + virtual void visit(MemberAccess &); + virtual void visit(BinaryExpression &); + virtual void visit(StructDeclaration &) { } + virtual void visit(VariableDeclaration &); + virtual void visit(InterfaceBlock &) { } + virtual void visit(FunctionDeclaration &); +}; + /** Replaces expressions consisting entirely of literals with the results of evaluating the expression.*/ class ConstantFolder: private TraversingVisitor