13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _RSGVARIABLEMANAGER_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _RSGVARIABLEMANAGER_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Random Shader Generator 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Variable manager. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Memory management: 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Variable manager owns variable objects until they are either explictly 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * removed or moved to currently active scope. After that the ownership 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * is transferred to Scope or the object that called removeEntry(). 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgDefs.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgVariable.hpp" 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgVariableValue.hpp" 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgNameAllocator.hpp" 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <iterator> 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <set> 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace rsg 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ValueEntry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueEntry (const Variable* variable); 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ValueEntry (void) {} 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Variable* getVariable (void) const { return m_variable; } 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ConstValueRangeAccess getValueRange (void) const { return m_valueRange.asAccess(); } 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueRangeAccess getValueRange (void) { return m_valueRange.asAccess(); } 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Variable* m_variable; 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueRange m_valueRange; 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Variable scope manages variable allocation. 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass VariableScope 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableScope (void); 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~VariableScope (void); 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Variable* allocate (const VariableType& type, Variable::Storage storage, const char* name); 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void declare (Variable* variable); //!< Move from live set to declared set 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void removeLive (const Variable* variable); //!< Just remove from live set (when migrating to parent). 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<Variable*>& getDeclaredVariables (void) const { return m_declaredVariables; } 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Variable*>& getLiveVariables (void) { return m_liveVariables; } 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<Variable*>& getLiveVariables (void) const { return m_liveVariables; } 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableScope (const VariableScope& other); 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableScope& operator= (const VariableScope& other); 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Variable*> m_declaredVariables; //!< Variables declared in this scope. Not available for expressions. 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Variable*> m_liveVariables; //!< Live variables (available for expression) that can be declared in this scope. 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ValueScope 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueScope (void); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ValueScope (void); 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueEntry* allocate (const Variable* variable); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueEntry* findEntry (const Variable* variable) const; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setValue (const Variable* variable, ConstValueRangeAccess value); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void removeValue (const Variable* variable); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ValueEntry*>& getValues (void) { return m_entries; } 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<ValueEntry*>& getValues (void) const { return m_entries; } 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void clear (void); 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueScope (const ValueScope& other); 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueScope& operator= (const ValueScope& other); 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ValueEntry*> m_entries; 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ReservedScalars 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int numScalars; 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ReservedScalars (void) 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : numScalars(0) 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// \todo [2011-05-26 pyry] Clean up this a bit, separate const variant. 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <typename Item, typename Iterator, class Filter> 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass FilteredIterator : public std::iterator<std::input_iterator_tag, Item> 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FilteredIterator (Iterator iter, Iterator end, Filter filter) 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : m_iter (iter) 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_end (end) 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry , m_filter (filter) 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FilteredIterator operator+ (ptrdiff_t offset) const 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Iterator nextEntry = m_iter; 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (offset--) 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry nextEntry = findNext(m_filter, nextEntry, m_end); 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return FilteredIterator(nextEntry, m_end, m_filter); 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FilteredIterator& operator++ () 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Pre-increment 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_iter = findNext(m_filter, m_iter, m_end); 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *this; 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FilteredIterator operator++ (int) 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Post-increment 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry FilteredIterator copy = *this; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry m_iter = findNext(m_filter, m_iter, m_end); 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return copy; 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator== (const FilteredIterator& other) const 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_iter == other.m_iter; 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator!= (const FilteredIterator& other) const 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return m_iter != other.m_iter; 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Item& operator* (void) 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_iter != m_end); 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_ASSERT(m_filter(*m_iter)); 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return *m_iter; 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry static Iterator findNext (Filter filter, Iterator iter, Iterator end) 1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry do 1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry iter++; 1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (iter != end && !filter(*iter)); 1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return iter; 1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Iterator m_iter; 1793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Iterator m_end; 1803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Filter m_filter; 1813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1833c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <class Filter> 1843c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ValueEntryIterator : public FilteredIterator<const ValueEntry*, std::vector<const ValueEntry*>::const_iterator, Filter> 1853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1863c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueEntryIterator (std::vector<const ValueEntry*>::const_iterator begin, std::vector<const ValueEntry*>::const_iterator end, Filter filter) 1883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry : FilteredIterator<const ValueEntry*, std::vector<const ValueEntry*>::const_iterator, Filter>(begin, end, filter) 1893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 1903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 1913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1933c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass VariableManager 1943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1953c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableManager (NameAllocator& nameAllocator); 1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~VariableManager (void); 1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getNumAllocatedScalars (void) const { return m_numAllocatedScalars; } 2003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getNumAllocatedShaderInScalars (void) const { return m_numAllocatedShaderInScalars; } 2013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getNumAllocatedShaderInVariables(void) const { return m_numAllocatedShaderInVariables; } 2023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int getNumAllocatedUniformScalars (void) const { return m_numAllocatedUniformScalars; } 2033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void reserve (ReservedScalars& store, int numScalars); 2053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void release (ReservedScalars& store); 2063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Variable* allocate (const VariableType& type); 2083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Variable* allocate (const VariableType& type, Variable::Storage storage, const char* name); 2093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setStorage (Variable* variable, Variable::Storage storage); 2113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setValue (const Variable* variable, ConstValueRangeAccess value); 2133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ValueEntry* getValue (const Variable* variable) const; 2143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ValueEntry* getParentValue (const Variable* variable) const; 2153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void removeValueFromCurrentScope (const Variable* variable); 2173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void declareVariable (Variable* variable); 2193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool canDeclareInCurrentScope (const Variable* variable) const; 2203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<Variable*>& getLiveVariables (void) const; 2213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void pushVariableScope (VariableScope& scope); 2233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void popVariableScope (void); 2243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void pushValueScope (ValueScope& scope); 2263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void popValueScope (void); 2273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry template <class Filter> 2293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueEntryIterator<Filter> getBegin (Filter filter = Filter()) const; 2303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry template <class Filter> 2323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueEntryIterator<Filter> getEnd (Filter filter = Filter()) const; 2333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry template <class Filter> 2353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool hasEntry (Filter filter = Filter()) const; 2363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2373c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 2383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableManager (const VariableManager& other); 2393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableManager& operator= (const VariableManager& other); 2403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableScope& getCurVariableScope (void) { return *m_variableScopeStack.back(); } 2423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const VariableScope& getCurVariableScope (void) const { return *m_variableScopeStack.back(); } 2433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueScope& getCurValueScope (void) { return *m_valueScopeStack.back(); } 2453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const ValueScope& getCurValueScope (void) const { return *m_valueScopeStack.back(); } 2463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<VariableScope*> m_variableScopeStack; 2483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ValueScope*> m_valueScopeStack; 2493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<const ValueEntry*> m_entryCache; //!< For faster value entry access. 2513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numAllocatedScalars; 2533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numAllocatedShaderInScalars; 2543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numAllocatedShaderInVariables; 2553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry int m_numAllocatedUniformScalars; 2563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NameAllocator& m_nameAllocator; 2573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2593c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <class Filter> 2603c827367444ee418f129b2c238299f49d3264554Jarkko PoyryValueEntryIterator<Filter> VariableManager::getBegin (Filter filter) const 2613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<const ValueEntry*>::const_iterator first = m_entryCache.begin(); 2633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry while (first != m_entryCache.end() && !filter(*first)) 2643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry first++; 2653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ValueEntryIterator<Filter>(first, m_entryCache.end(), filter); 2663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2683c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <class Filter> 2693c827367444ee418f129b2c238299f49d3264554Jarkko PoyryValueEntryIterator<Filter> VariableManager::getEnd (Filter filter) const 2703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return ValueEntryIterator<Filter>(m_entryCache.end(), m_entryCache.end(), filter); 2723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2743c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <class Filter> 2753c827367444ee418f129b2c238299f49d3264554Jarkko Poyrybool VariableManager::hasEntry (Filter filter) const 2763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for (std::vector<const ValueEntry*>::const_iterator i = m_entryCache.begin(); i != m_entryCache.end(); i++) 2783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (filter(*i)) 2803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 2813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 2833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 2843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Common filters 2863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2873c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass AnyEntry 2883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 2893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 2903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef ValueEntryIterator<AnyEntry> Iterator; 2913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator() (const ValueEntry* entry) const 2933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 2943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry DE_UNREF(entry); 2953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 2963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 2973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 2983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 2993c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass IsWritableEntry 3003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3013c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 3023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator() (const ValueEntry* entry) const 3033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry switch (entry->getVariable()->getStorage()) 3053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case Variable::STORAGE_LOCAL: 3073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case Variable::STORAGE_SHADER_OUT: 3083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case Variable::STORAGE_PARAMETER_IN: 3093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case Variable::STORAGE_PARAMETER_OUT: 3103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry case Variable::STORAGE_PARAMETER_INOUT: 3113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return true; 3123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry default: 3143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return false; 3153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 3183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate <Variable::Storage Storage> 3203c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass EntryStorageFilter 3213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 3223c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 3233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry typedef ValueEntryIterator<EntryStorageFilter<Storage> > Iterator; 3243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry bool operator() (const ValueEntry* entry) const 3263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 3273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return entry->getVariable()->getStorage() == Storage; 3283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } 3293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 3303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3313c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef EntryStorageFilter<Variable::STORAGE_LOCAL> LocalEntryFilter; 3323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef EntryStorageFilter<Variable::STORAGE_SHADER_IN> ShaderInEntryFilter; 3333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef EntryStorageFilter<Variable::STORAGE_SHADER_OUT> ShaderOutEntryFilter; 3343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rsg 3363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 3373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _RSGVARIABLEMANAGER_HPP 338