X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Foptimize.h;h=4113f21465a990e85a4fa701351b8277cec09cfe;hb=2280a09a286bbff2eb41783f8023863f320a3736;hp=08ee082b99cd9e070dd5003de3cdc936ef21d396;hpb=d5c38c181cac4da490c96123e5a88a8c06785e55;p=libs%2Fgl.git diff --git a/source/glsl/optimize.h b/source/glsl/optimize.h index 08ee082b..4113f214 100644 --- a/source/glsl/optimize.h +++ b/source/glsl/optimize.h @@ -9,9 +9,25 @@ namespace Msp { namespace GL { namespace SL { +/** Assigns values to specialization constants, turning them into normal +constants. */ +class ConstantSpecializer: private TraversingVisitor +{ +private: + const std::map *values; + +public: + ConstantSpecializer(); + + void apply(Stage &, const std::map &); + +private: + virtual void visit(VariableDeclaration &); +}; + /** Finds functions which are candidates for inlining. Currently this means -functions which have no parameters, contain no more than one return statement, -and are only called once. */ +functions which have no flow control statements, no more than one return +statement, and are only called once. */ class InlineableFunctionLocator: private TraversingVisitor { private: @@ -23,7 +39,7 @@ private: public: InlineableFunctionLocator(); - const std::set &apply(Stage &s) { s.content.visit(*this); return inlineable; } + std::set apply(Stage &s) { s.content.visit(*this); return inlineable; } private: virtual void visit(FunctionCall &); @@ -39,10 +55,16 @@ dependencies of the inlined statements to appear before the target function. */ class InlineContentInjector: private TraversingVisitor { private: + enum Pass + { + REFERENCED, + INLINE, + RENAME + }; + FunctionDeclaration *source_func; Block staging_block; - std::string remap_prefix; - unsigned remap_names; + Pass pass; RefPtr r_inlined_statement; std::set dependencies; std::set referenced_names; @@ -51,7 +73,7 @@ private: public: InlineContentInjector(); - const std::string &apply(Stage &, FunctionDeclaration &, Block &, const NodeList::iterator &, FunctionDeclaration &); + std::string apply(Stage &, FunctionDeclaration &, Block &, const NodeList::iterator &, FunctionCall &); private: virtual void visit(VariableReference &); @@ -102,7 +124,7 @@ private: bool trivial; bool available; - ExpressionInfo(); + ExpressionInfo(): expression(0), assign_scope(0), inline_point(0), trivial(false), available(true) { } }; std::map expressions;