X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Ffinalize.h;h=f9502954f6b1d6ed9983e403c14414870ae63090;hp=3db581be732cd3c5ea7e0b40fce67498db9e1e45;hb=76cc18518fc8b0b4fa11fda153e7d9b3899ed112;hpb=8f2713a3f1501e90016bb8069ecd08dde2f90e56 diff --git a/source/glsl/finalize.h b/source/glsl/finalize.h index 3db581be..f9502954 100644 --- a/source/glsl/finalize.h +++ b/source/glsl/finalize.h @@ -1,5 +1,5 @@ -#ifndef MSP_GL_SL_COMPATIBILITY_H_ -#define MSP_GL_SL_COMPATIBILITY_H_ +#ifndef MSP_GL_SL_FINALIZE_H_ +#define MSP_GL_SL_FINALIZE_H_ #include #include "visitor.h" @@ -8,18 +8,34 @@ namespace Msp { namespace GL { namespace SL { +/** Assigns offset layout qualifiers to struct members. */ +class StructOrganizer: private TraversingVisitor +{ +private: + int offset = -1; + +public: + void apply(Stage &s) { s.content.visit(*this); } + +private: + virtual void visit(StructDeclaration &); + virtual void visit(VariableDeclaration &); +}; + +/** Assigns location and binding layout qualifiers to interface variables and +blocks. */ class LocationAllocator: private TraversingVisitor { private: struct Uniform { - int location; - int desc_set; - int bind_point; - - Uniform(): location(-1), desc_set(-1), bind_point(-1) { } + int location = -1; + int desc_set = 0; + int bind_point = -1; }; + Features features; + bool alloc_new = true; std::map > used_locations; std::map uniforms; std::map > used_bindings; @@ -28,14 +44,14 @@ private: std::vector unbound_blocks; public: - void apply(Module &, const Features &); + void apply(Module &, const Features &, bool = true); private: void apply(Stage &); void allocate_locations(const std::string &); void bind_uniform(RefPtr &, const std::string &, unsigned); - void add_layout_value(RefPtr &, const std::string &, unsigned); + bool visit_uniform(const std::string &, RefPtr &); virtual void visit(VariableDeclaration &); virtual void visit(InterfaceBlock &); virtual void visit(FunctionDeclaration &) { } @@ -46,14 +62,12 @@ according to the requirements of the target API. */ class PrecisionConverter: private TraversingVisitor { private: - Stage *stage; + Stage *stage = 0; std::set have_default; NodeList::iterator insert_point; std::set nodes_to_remove; public: - PrecisionConverter(); - void apply(Stage &); private: @@ -62,34 +76,66 @@ private: virtual void visit(VariableDeclaration &); }; +/** Base class for feature converters. */ +class FeatureConverter: protected TraversingVisitor +{ +protected: + Stage *stage = 0; + Features features; + + FeatureConverter() = default; + +public: + void apply(Stage &, const Features &); +protected: + virtual void apply() = 0; + + void unsupported(const std::string &); + + bool check_version(const Version &) const; + bool check_extension(bool Features::*) const; +}; + /** Converts structures of the syntax tree to match a particular set of features. */ -class LegacyConverter: private TraversingVisitor +class StructuralFeatureConverter: public FeatureConverter { private: - Stage *stage; - Features features; - VariableDeclaration *frag_out; + VariableDeclaration *frag_out = 0; NodeList::iterator uniform_insert_point; std::set nodes_to_remove; + RefPtr r_replaced_reference; + bool r_flattened_interface = false; public: - LegacyConverter(); - - virtual void apply(Stage &, const Features &); - + void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); } private: - void unsupported(const std::string &); + virtual void apply(); virtual void visit(Block &); - bool check_version(const Version &) const; - bool check_extension(bool Features::*) const; + virtual void visit(RefPtr &); bool supports_stage(Stage::Type) const; bool supports_unified_interface_syntax() const; virtual void visit(VariableReference &); + virtual void visit(InterfaceBlockReference &); + virtual void visit(MemberAccess &); virtual void visit(Assignment &); bool supports_unified_sampling_functions() const; virtual void visit(FunctionCall &); + virtual void visit(VariableDeclaration &); + bool supports_interface_blocks(const std::string &) const; + virtual void visit(InterfaceBlock &); +}; + +/** Converts qualifiers on variables and blocksto match a particular set of +features. */ +class QualifierConverter: private FeatureConverter +{ +public: + void apply(Stage &s, const Features &f) { FeatureConverter::apply(s, f); } +private: + virtual void apply(); + bool supports_interface_layouts() const; bool supports_stage_interface_layouts() const; bool supports_centroid_sampling() const; @@ -97,7 +143,6 @@ private: bool supports_uniform_location() const; bool supports_binding() const; virtual void visit(VariableDeclaration &); - bool supports_interface_blocks(const std::string &) const; bool supports_interface_block_location() const; virtual void visit(InterfaceBlock &); };