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

ShBackend.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 SHBACKEND_HPP
00025 #define SHBACKEND_HPP
00026 
00027 #include <vector>
00028 #include <iosfwd>
00029 #include <string>
00030 #include "ShDllExport.hpp"
00031 #include "ShRefCount.hpp"
00032 #include "ShProgram.hpp"
00033 #include "ShProgramSet.hpp"
00034 #include "ShVariableNode.hpp"
00035 
00036 namespace SH  {
00037 
00038 class ShStream;
00039 
00040 class
00041 SH_DLLEXPORT ShBackendCode : public ShRefCountable {
00042 public:
00043   virtual ~ShBackendCode();
00044 
00047   virtual bool allocateRegister(const ShVariableNodePtr& var) = 0;
00048 
00052   virtual void freeRegister(const ShVariableNodePtr& var) = 0;
00053   
00055   virtual void upload() = 0;
00056 
00058   virtual void bind() = 0;
00059 
00061   virtual void unbind() = 0;
00062 
00064   virtual void update() = 0;
00065 
00067   virtual void updateUniform(const ShVariableNodePtr& uniform) = 0;
00068 
00069   virtual std::ostream& print(std::ostream& out) = 0;
00070 
00072   // (Useful for how to format long tuple input on targets 
00073   // that only support limited tuple lengths) 
00074   virtual std::ostream& describe_interface(std::ostream& out) = 0;
00075 };
00076 
00077 typedef ShPointer<ShBackendCode> ShBackendCodePtr;
00078 typedef ShPointer<const ShBackendCode> ShBackendCodeCPtr;
00079 
00080 // A backend-specific set of programs, to be linked together/bound at once
00081 class
00082 SH_DLLEXPORT ShBackendSet : public ShRefCountable {
00083 public:
00084   virtual ~ShBackendSet();
00085 
00086   virtual void link() = 0;
00087 
00088   virtual void bind() = 0;
00089   virtual void unbind() = 0;
00090 };
00091 
00092 typedef ShPointer<ShBackendSet> ShBackendSetPtr;
00093 typedef ShPointer<const ShBackendSet> ShBackendSetCPtr;
00094 
00095 class ShTransformer;
00096 class
00097 SH_DLLEXPORT ShBackend : public ShRefCountable {
00098 public:
00099   virtual ~ShBackend();
00100   virtual std::string name() const = 0;
00101 
00105   virtual ShBackendCodePtr generate_code(const std::string& target,
00106                                          const ShProgramNodeCPtr& shader) = 0;
00107 
00108   virtual ShBackendSetPtr generate_set(const ShProgramSet& s);
00109   
00110   // execute a stream program, if supported
00111   virtual void execute(const ShProgramNodeCPtr& program, ShStream& dest) = 0;
00112 
00113   // Unbind all programs bound under this backend
00114   virtual void unbind_all();
00115   
00116   typedef std::vector< ShPointer<ShBackend> > ShBackendList;
00117 
00118   static ShBackendList::iterator begin();
00119   static ShBackendList::iterator end();
00120 
00121   static ShPointer<ShBackend> lookup(const std::string& name);
00122 
00123 protected:
00124   ShBackend();
00125   
00126 private:
00127   static void init();
00128 
00129   static ShBackendList* m_backends;
00130   static bool m_doneInit;
00131 };
00132 
00133 typedef ShPointer<ShBackend> ShBackendPtr;
00134 typedef ShPointer<const ShBackend> ShBackendCPtr;
00135 
00136 }
00137 
00138 #endif

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