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   
00060   void compile(const ShPointer<ShBackend>& backend) { m_node->compile(backend); }
00061 
00064   void compile(const std::string& target, const ShPointer<ShBackend>& backend)
00065   {
00066     m_node->compile(target, backend);
00067   }
00068 
00071   std::string describe_interface() const
00072   {
00073     return m_node->describe_interface();
00074   }
00075   
00079   ShPointer<ShBackendCode> code() { return m_node->code(); }
00080   
00084   ShPointer<ShBackendCode> code(const ShPointer<ShBackend>& backend) {
00085     return m_node->code(backend);
00086   }
00087 
00089   ShPointer<ShBackendCode> code(const std::string& target, const ShPointer<ShBackend>& backend)
00090   {
00091     return m_node->code(target, backend);
00092   }
00093 
00095   void updateUniform(const ShVariableNodePtr& uniform)
00096   {
00097     m_node->updateUniform(uniform);
00098   }
00099 
00100   std::string target() const { return m_node->target(); }
00101 
00103   std::string& target() { return m_node->target(); }
00104 
00105   ShProgramNode::VarList::const_iterator inputs_begin() const { return m_node->inputs_begin(); }
00106   ShProgramNode::VarList::const_iterator inputs_end() const { return m_node->inputs_end(); }
00107   ShProgramNode::VarList::const_iterator outputs_begin() const { return m_node->outputs_begin(); }
00108   ShProgramNode::VarList::const_iterator outputs_end() const { return m_node->outputs_end(); }
00109   ShProgramNode::VarList::const_iterator temps_begin() const { return m_node->temps_begin(); }
00110   ShProgramNode::VarList::const_iterator temps_end() const { return m_node->temps_end(); }
00111   ShProgramNode::VarList::const_iterator constants_begin() const { return m_node->constants_begin(); }
00112   ShProgramNode::VarList::const_iterator constants_end() const { return m_node->constants_end(); }
00113   ShProgramNode::VarList::const_iterator uniforms_begin() const { return m_node->uniforms_begin(); }
00114   ShProgramNode::VarList::const_iterator uniforms_end() const { return m_node->uniforms_end(); }
00115   ShProgramNode::TexList::const_iterator textures_begin() const { return m_node->textures_begin(); }
00116   ShProgramNode::TexList::const_iterator textures_end() const { return m_node->textures_end(); }
00117   ShProgramNode::ChannelList::const_iterator channels_begin() const { return m_node->channels_begin(); }
00118   ShProgramNode::ChannelList::const_iterator channels_end() const { return m_node->channels_end(); }
00119   ShProgramNode::PaletteList::const_iterator palettes_begin() const { return m_node->palettes_begin(); }
00120   ShProgramNode::PaletteList::const_iterator palettes_end() const { return m_node->palettes_end(); }
00121 
00122   // Call operators for channels and streams.
00123   // Equivalent to operator<< invocations.
00124   // Note that the template functions are implemented in
00125   // ShChannelImpl.hpp
00126   template<typename T0>
00127   ShProgram operator()(const ShChannel<T0>& t0) const;
00128   ShProgram operator()(const ShStream& s0) const;
00129   template<typename T0, typename T1>
00130   ShProgram operator()(const ShChannel<T0>& t0,
00131                         const ShChannel<T1>& t1) const;
00132   ShProgram operator()(const ShStream& s0,
00133                         const ShStream& s1) const;
00134   template<typename T0, typename T1, typename T2>
00135   ShProgram operator()(const ShChannel<T0>& t0,
00136                         const ShChannel<T1>& t1,
00137                         const ShChannel<T2>& t2) const;
00138   ShProgram operator()(const ShStream& s0,
00139                         const ShStream& s1,
00140                         const ShStream& s2) const;
00141   template<typename T0, typename T1, typename T2, typename T3>
00142   ShProgram operator()(const ShChannel<T0>& t0,
00143                         const ShChannel<T1>& t1,
00144                         const ShChannel<T2>& t2,
00145                         const ShChannel<T3>& t3) const;
00146   ShProgram operator()(const ShStream& s0,
00147                         const ShStream& s1,
00148                         const ShStream& s2,
00149                         const ShStream& s3) const;
00150   template<typename T0, typename T1, typename T2, typename T3,
00151            typename T4>
00152   ShProgram operator()(const ShChannel<T0>& t0,
00153                         const ShChannel<T1>& t1,
00154                         const ShChannel<T2>& t2,
00155                         const ShChannel<T3>& t3,
00156                         const ShChannel<T4>& t4) const;
00157   ShProgram operator()(const ShStream& s0,
00158                         const ShStream& s1,
00159                         const ShStream& s2,
00160                         const ShStream& s3,
00161                         const ShStream& s4) const;
00162   
00163   // Call operators for records
00164   // May want to merge these with above in the long term. 
00165   ShProgram operator()(const ShRecord &rec) const;
00166   ShProgram operator()(const ShVariable &v0) const;
00167   ShProgram operator()(const ShVariable &v0, 
00168                        const ShVariable &v1) const;
00169   ShProgram operator()(const ShVariable &v0, 
00170                        const ShVariable &v1, 
00171                        const ShVariable &v2) const;
00172   ShProgram operator()(const ShVariable &v0, 
00173                        const ShVariable &v1, 
00174                        const ShVariable &v2, 
00175                        const ShVariable &v3) const;
00176   
00177 private:
00178 
00179   ShProgramNodePtr m_node;
00180 };
00181 
00182 }
00183 
00184 #endif
00185 

Generated on Thu Apr 21 17:32:48 2005 for Sh by  doxygen 1.4.2