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

ShProgram.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright 2003-2005 Serious Hack Inc.
00004 // 
00005 // This software is provided 'as-is', without any express or implied
00006 // warranty. In no event will the authors be held liable for any damages
00007 // arising from the use of this software.
00008 // 
00009 // Permission is granted to anyone to use this software for any purpose,
00010 // including commercial applications, and to alter it and redistribute it
00011 // freely, subject to the following restrictions:
00012 // 
00013 // 1. The origin of this software must not be misrepresented; you must
00014 // not claim that you wrote the original software. If you use this
00015 // software in a product, an acknowledgment in the product documentation
00016 // would be appreciated but is not required.
00017 // 
00018 // 2. Altered source versions must be plainly marked as such, and must
00019 // not be misrepresented as being the original software.
00020 // 
00021 // 3. This notice may not be removed or altered from any source
00022 // distribution.
00024 #ifndef SHPROGRAM_HPP
00025 #define SHPROGRAM_HPP
00026 
00027 #include "ShDllExport.hpp"
00028 #include "ShProgramNode.hpp"
00029 #include "ShBackend.hpp"
00030 
00031 namespace SH {
00032 
00033 class ShStream;
00034 template<typename T> class ShChannel;
00035 class ShRecord;
00036 
00039 class
00040 SH_DLLEXPORT ShProgram : public ShMetaForwarder {
00041 public:
00042   ShProgram();
00043   ShProgram(const ShProgram& other);
00044   ShProgram(const std::string& target);
00045   ShProgram(const ShProgramNodePtr& node);
00046 
00047   ShProgram& operator=(const ShProgram& other);
00048   
00050   ShProgramNodeCPtr node() const { return m_node; }
00051 
00053   ShProgramNodePtr node() { return m_node; }
00054   
00059   void compile(const ShPointer<ShBackend>& backend) { m_node->compile(backend); }
00060 
00064   void compile(const std::string& target, const ShPointer<ShBackend>& backend)
00065   {
00066     m_node->compile(target, backend);
00067   }
00068 
00072   bool is_compiled() const { return m_node->is_compiled(); }
00073 
00076   bool is_compiled(const std::string& target) const
00077   { 
00078     return m_node->is_compiled(target);
00079   }
00080 
00083   std::string describe_interface() const
00084   {
00085     return m_node->describe_interface();
00086   }
00087   
00091   ShPointer<ShBackendCode> code() { return m_node->code(); }
00092   
00096   ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend) {
00097     return m_node->code(backend);
00098   }
00099 
00101   ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend)
00102   {
00103     return m_node->code(target, backend);
00104   }
00105 
00107   void updateUniform(const ShVariableNodePtr& uniform)
00108   {
00109     m_node->updateUniform(uniform);
00110   }
00111 
00112   std::string target() const { return m_node->target(); }
00113 
00115   std::string& target() { return m_node->target(); }
00116 
00117   ShProgramNode::VarList::const_iterator inputs_begin() const { return m_node->inputs_begin(); }
00118   ShProgramNode::VarList::const_iterator inputs_end() const { return m_node->inputs_end(); }
00119   ShProgramNode::VarList::const_iterator outputs_begin() const { return m_node->outputs_begin(); }
00120   ShProgramNode::VarList::const_iterator outputs_end() const { return m_node->outputs_end(); }
00121   ShProgramNode::VarList::const_iterator temps_begin() const { return m_node->temps_begin(); }
00122   ShProgramNode::VarList::const_iterator temps_end() const { return m_node->temps_end(); }
00123   ShProgramNode::VarList::const_iterator constants_begin() const { return m_node->constants_begin(); }
00124   ShProgramNode::VarList::const_iterator constants_end() const { return m_node->constants_end(); }
00125   ShProgramNode::VarList::const_iterator uniforms_begin() const { return m_node->uniforms_begin(); }
00126   ShProgramNode::VarList::const_iterator uniforms_end() const { return m_node->uniforms_end(); }
00127   ShProgramNode::TexList::const_iterator textures_begin() const { return m_node->textures_begin(); }
00128   ShProgramNode::TexList::const_iterator textures_end() const { return m_node->textures_end(); }
00129   ShProgramNode::ChannelList::const_iterator channels_begin() const { return m_node->channels_begin(); }
00130   ShProgramNode::ChannelList::const_iterator channels_end() const { return m_node->channels_end(); }
00131   ShProgramNode::PaletteList::const_iterator palettes_begin() const { return m_node->palettes_begin(); }
00132   ShProgramNode::PaletteList::const_iterator palettes_end() const { return m_node->palettes_end(); }
00133 
00134   // Call operators for channels and streams.
00135   // Equivalent to operator<< invocations.
00136   // Note that the template functions are implemented in
00137   // ShChannelImpl.hpp
00138   template<typename T0>
00139   ShProgram operator()(const ShChannel<T0>& t0) const;
00140   ShProgram operator()(const ShStream& s0) const;
00141   template<typename T0, typename T1>
00142   ShProgram operator()(const ShChannel<T0>& t0,
00143                         const ShChannel<T1>& t1) const;
00144   ShProgram operator()(const ShStream& s0,
00145                         const ShStream& s1) const;
00146   template<typename T0, typename T1, typename T2>
00147   ShProgram operator()(const ShChannel<T0>& t0,
00148                         const ShChannel<T1>& t1,
00149                         const ShChannel<T2>& t2) const;
00150   ShProgram operator()(const ShStream& s0,
00151                         const ShStream& s1,
00152                         const ShStream& s2) const;
00153   template<typename T0, typename T1, typename T2, typename T3>
00154   ShProgram operator()(const ShChannel<T0>& t0,
00155                         const ShChannel<T1>& t1,
00156                         const ShChannel<T2>& t2,
00157                         const ShChannel<T3>& t3) const;
00158   ShProgram operator()(const ShStream& s0,
00159                         const ShStream& s1,
00160                         const ShStream& s2,
00161                         const ShStream& s3) const;
00162   template<typename T0, typename T1, typename T2, typename T3,
00163            typename T4>
00164   ShProgram operator()(const ShChannel<T0>& t0,
00165                         const ShChannel<T1>& t1,
00166                         const ShChannel<T2>& t2,
00167                         const ShChannel<T3>& t3,
00168                         const ShChannel<T4>& t4) const;
00169   ShProgram operator()(const ShStream& s0,
00170                         const ShStream& s1,
00171                         const ShStream& s2,
00172                         const ShStream& s3,
00173                         const ShStream& s4) const;
00174   
00175   // Call operators for records
00176   // May want to merge these with above in the long term. 
00177   ShProgram operator()(const ShRecord &rec) const;
00178   ShProgram operator()(const ShVariable &v0) const;
00179   ShProgram operator()(const ShVariable &v0, 
00180                        const ShVariable &v1) const;
00181   ShProgram operator()(const ShVariable &v0, 
00182                        const ShVariable &v1, 
00183                        const ShVariable &v2) const;
00184   ShProgram operator()(const ShVariable &v0, 
00185                        const ShVariable &v1, 
00186                        const ShVariable &v2, 
00187                        const ShVariable &v3) const;
00188   
00189 private:
00190 
00191   ShProgramNodePtr m_node;
00192 };
00193 
00194 }
00195 
00196 #endif
00197 

Generated on Wed Jun 15 18:12:41 2005 for Sh by  doxygen 1.4.3-20050530