X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Freflect.h;h=8de915729ce50e8748c9e8011419d5bd4f7cf6b8;hb=cc5483cc709fdf7b6966a3e69dabfcafebaaffa0;hp=c03a5ccbd8b57044db6b28355863bac292c47a75;hpb=8f5f54a9e165dae424e5b0bb8e488c3d01849bf6;p=libs%2Fgl.git diff --git a/source/glsl/reflect.h b/source/glsl/reflect.h index c03a5ccb..8de91572 100644 --- a/source/glsl/reflect.h +++ b/source/glsl/reflect.h @@ -7,6 +7,35 @@ namespace Msp { namespace GL { namespace SL { +/** Compares two types for equality. Struct types are compared recursively. */ +class TypeComparer: private NodeVisitor +{ +private: + Node *first; + Node *second; + unsigned first_tag; + bool r_result; + + static unsigned next_tag; + +public: + TypeComparer(); + + bool apply(TypeDeclaration &t1, TypeDeclaration &t2) { compare(t1, t2); return r_result; } + +private: + void compare(Node &, Node &); + template + T *multi_visit(T &); + virtual void visit(Literal &); + virtual void visit(VariableReference &); + virtual void visit(BasicTypeDeclaration &); + virtual void visit(ImageTypeDeclaration &); + virtual void visit(StructDeclaration &); + virtual void visit(VariableDeclaration &); +}; + +/** Determines the number of interface locations required by a variable. */ class LocationCounter: private NodeVisitor { private: @@ -24,6 +53,53 @@ private: virtual void visit(VariableDeclaration &); }; +/** Determines the size and alignment of a variable or a type, in bytes. */ +class MemoryRequirementsCalculator: private NodeVisitor +{ +public: + struct Result + { + unsigned size; + unsigned alignment; + unsigned stride; + + Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { } + }; +private: + unsigned r_size; + unsigned r_alignment; + int r_offset; + +public: + Result apply(VariableDeclaration &v) { v.visit(*this); return Result(r_size, r_alignment); } + Result apply(TypeDeclaration &t) { t.visit(*this); return Result(r_size, r_alignment); } + +private: + virtual void visit(BasicTypeDeclaration &); + virtual void visit(StructDeclaration &); + virtual void visit(VariableDeclaration &); +}; + +/** Collects dependencies of a function. This includes global variables, +interface blocks, other functions and types. */ +class DependencyCollector: private TraversingVisitor +{ +private: + std::set dependencies; + std::set locals; + std::set visited_functions; + +public: + std::set apply(FunctionDeclaration &); + +private: + virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); + virtual void visit(FunctionCall &); + virtual void visit(VariableDeclaration &); + virtual void visit(FunctionDeclaration &); +}; + } // namespace SL } // namespace GL } // namespace Msp