X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Ffinalize.h;h=1fe5fa45a494b02988c90f37068ee4c34e760ca1;hp=e0904b2e40eab2272accfd1cf4c8e6d4972ac4fd;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=6ff7aea73057e4a650d8b0ac659d9bba05ba02e2 diff --git a/source/glsl/finalize.h b/source/glsl/finalize.h index e0904b2e..1fe5fa45 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,19 +8,66 @@ 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) { } + }; + + std::map > used_locations; + std::map uniforms; + std::map > used_bindings; + std::vector unplaced_variables; + std::vector unbound_textures; + std::vector unbound_blocks; + +public: + void apply(Module &, const Features &); +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); + + virtual void visit(VariableDeclaration &); + virtual void visit(InterfaceBlock &); + virtual void visit(FunctionDeclaration &) { } +}; + /** Generates default precision declarations or removes precision declarations 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: @@ -34,15 +81,13 @@ features. */ class LegacyConverter: private TraversingVisitor { private: - Stage *stage; + Stage *stage = 0; Features features; - VariableDeclaration *frag_out; + VariableDeclaration *frag_out = 0; NodeList::iterator uniform_insert_point; std::set nodes_to_remove; public: - LegacyConverter(); - virtual void apply(Stage &, const Features &); private: @@ -58,10 +103,14 @@ private: bool supports_unified_sampling_functions() const; virtual void visit(FunctionCall &); bool supports_interface_layouts() const; + bool supports_stage_interface_layouts() const; bool supports_centroid_sampling() const; bool supports_sample_sampling() const; + 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 &); };