Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

ShProgramNode.hpp

00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory 00004 // Project administrator: Michael D. McCool 00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa, 00006 // Michael D. McCool 00007 // 00008 // This software is provided 'as-is', without any express or implied 00009 // warranty. In no event will the authors be held liable for any damages 00010 // arising from the use of this software. 00011 // 00012 // Permission is granted to anyone to use this software for any purpose, 00013 // including commercial applications, and to alter it and redistribute it 00014 // freely, subject to the following restrictions: 00015 // 00016 // 1. The origin of this software must not be misrepresented; you must 00017 // not claim that you wrote the original software. If you use this 00018 // software in a product, an acknowledgment in the product documentation 00019 // would be appreciated but is not required. 00020 // 00021 // 2. Altered source versions must be plainly marked as such, and must 00022 // not be misrepresented as being the original software. 00023 // 00024 // 3. This notice may not be removed or altered from any source 00025 // distribution. 00027 #ifndef SHPROGRAMNODE_HPP 00028 #define SHPROGRAMNODE_HPP 00029 00030 #include <list> 00031 #include <map> 00032 #include <utility> 00033 #include <string> 00034 #include "ShDllExport.hpp" 00035 #include "ShRefCount.hpp" 00036 #include "ShTokenizer.hpp" 00037 #include "ShVariableNode.hpp" 00038 #include "ShCtrlGraph.hpp" 00039 #include "ShTextureNode.hpp" 00040 #include "ShChannelNode.hpp" 00041 #include "ShPaletteNode.hpp" 00042 #include "ShMeta.hpp" 00043 00044 namespace SH { 00045 00046 class ShBackendCode; 00047 class ShBackend; 00048 00051 class 00052 SH_DLLEXPORT ShProgramNode : public virtual ShRefCountable, public virtual ShMeta { 00053 public: 00054 ShProgramNode(const std::string& target); 00055 00056 ~ShProgramNode(); 00057 00063 void compile(const ShPointer<ShBackend>& backend); 00064 00067 void compile(const std::string& target, const ShPointer<ShBackend>& backend); 00068 00070 std::string describe_interface() const; 00071 00075 ShPointer<ShBackendCode> code(); 00076 00080 ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend); 00081 00083 ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend); 00084 00086 void updateUniform(const ShVariableNodePtr& uniform); 00087 00090 ShTokenizer tokenizer; 00091 00095 ShPointer<ShCtrlGraph> ctrlGraph; 00096 00099 void collectVariables(); 00100 00101 typedef std::list<ShVariableNodePtr> VarList; 00102 typedef std::list<ShTextureNodePtr> TexList; 00103 typedef std::list<ShChannelNodePtr> ChannelList; 00104 typedef std::list<ShPaletteNodePtr> PaletteList; 00105 00106 VarList::const_iterator inputs_begin() const; 00107 VarList::const_iterator inputs_end() const; 00108 VarList::const_iterator outputs_begin() const; 00109 VarList::const_iterator outputs_end() const; 00110 VarList::const_iterator temps_begin() const; 00111 VarList::const_iterator temps_end() const; 00112 VarList::const_iterator constants_begin() const; 00113 VarList::const_iterator constants_end() const; 00114 VarList::const_iterator uniforms_begin() const; 00115 VarList::const_iterator uniforms_end() const; 00116 00117 TexList::const_iterator textures_begin() const; 00118 TexList::const_iterator textures_end() const; 00119 00120 ChannelList::const_iterator channels_begin() const; 00121 ChannelList::const_iterator channels_end() const; 00122 00123 PaletteList::const_iterator palettes_begin() const; 00124 PaletteList::const_iterator palettes_end() const; 00125 00126 00127 VarList inputs; 00128 VarList outputs; 00129 VarList temps; 00130 VarList constants; 00131 VarList uniforms; 00132 TexList textures; 00133 ChannelList channels; 00134 PaletteList palettes; 00135 00137 std::string target() const { return m_target; } 00138 00140 std::string& target() { return m_target; } 00141 00143 ShPointer<ShProgramNode> clone() const; 00144 00146 static std::ostream& print(std::ostream& out, const VarList& list); 00147 00149 bool finished() const; 00150 00152 void finish(); 00153 00157 void assign(const ShVariableNodePtr& var) const; 00158 00159 private: 00160 00161 std::string m_target; 00162 00163 void collectNodeVars(const ShPointer<ShCtrlGraphNode>& node); 00164 void collectVar(const ShVariableNodePtr& node); 00165 00166 typedef std::map< std::pair< std::string, ShPointer<ShBackend> >, 00167 ShPointer<ShBackendCode> > CodeMap; 00168 CodeMap m_code; 00169 00170 bool m_finished; 00171 00172 00173 mutable ShVariableNodePtr m_assigned_var; 00174 }; 00175 00176 typedef ShPointer<ShProgramNode> ShProgramNodePtr; 00177 typedef ShPointer<const ShProgramNode> ShProgramNodeCPtr; 00178 00179 } 00180 00181 #endif 00182

Generated on Fri Nov 5 16:51:20 2004 for Sh by doxygen 1.3.7