X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Freflect.h;h=63dfe7bec53ed2e843d2f8857d8cb18b056a6fb2;hb=c4aeeced7b397d46772577775bd3a0d6c4706cba;hp=162ed9c0b8bcf4ddb01daf17724e4308138decd0;hpb=8967d38bc578f1653c1dde01dce49a8f7b0c912e;p=libs%2Fgl.git diff --git a/source/glsl/reflect.h b/source/glsl/reflect.h index 162ed9c0..63dfe7be 100644 --- a/source/glsl/reflect.h +++ b/source/glsl/reflect.h @@ -7,6 +7,39 @@ namespace Msp { namespace GL { namespace SL { +bool is_scalar(const BasicTypeDeclaration &); +bool is_vector_or_matrix(const BasicTypeDeclaration &); +BasicTypeDeclaration *get_element_type(BasicTypeDeclaration &); +bool can_convert(const BasicTypeDeclaration &, const BasicTypeDeclaration &); + +/** 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 { @@ -25,7 +58,7 @@ private: virtual void visit(VariableDeclaration &); }; -/** Determines the size and alignment of a variable, in bytes. */ +/** Determines the size and alignment of a variable or a type, in bytes. */ class MemoryRequirementsCalculator: private NodeVisitor { public: @@ -33,8 +66,9 @@ public: { unsigned size; unsigned alignment; + unsigned stride; - Result(unsigned s, unsigned a): size(s), alignment(a) { } + Result(unsigned s, unsigned a): size(s), alignment(a), stride(s+a-1-(s+a-1)%a) { } }; private: unsigned r_size; @@ -43,6 +77,7 @@ private: 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 &); @@ -57,6 +92,7 @@ class DependencyCollector: private TraversingVisitor private: std::set dependencies; std::set locals; + std::set visited_functions; public: std::set apply(FunctionDeclaration &); @@ -66,6 +102,7 @@ private: virtual void visit(InterfaceBlockReference &); virtual void visit(FunctionCall &); virtual void visit(VariableDeclaration &); + virtual void visit(FunctionDeclaration &); }; } // namespace SL