00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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 #ifndef WIN32
00037 struct lt_dlhandle_struct;
00038 #endif
00039
00040 namespace SH {
00041
00042 class ShStream;
00043
00044 class
00045 SH_DLLEXPORT ShBackendCode : public ShRefCountable {
00046 public:
00047 virtual ~ShBackendCode();
00048
00051 virtual bool allocateRegister(const ShVariableNodePtr& var) = 0;
00052
00056 virtual void freeRegister(const ShVariableNodePtr& var) = 0;
00057
00059 virtual void upload() = 0;
00060
00062 virtual void bind() = 0;
00063
00065 virtual void unbind() = 0;
00066
00068 virtual void update() = 0;
00069
00071 virtual void updateUniform(const ShVariableNodePtr& uniform) = 0;
00072
00073 virtual std::ostream& print(std::ostream& out) = 0;
00074
00076
00077
00078 virtual std::ostream& describe_interface(std::ostream& out) = 0;
00079 };
00080
00081 typedef ShPointer<ShBackendCode> ShBackendCodePtr;
00082 typedef ShPointer<const ShBackendCode> ShBackendCodeCPtr;
00083
00084
00085 class
00086 SH_DLLEXPORT ShBackendSet : public ShRefCountable {
00087 public:
00088 virtual ~ShBackendSet();
00089
00090 virtual void link() = 0;
00091
00092 virtual void bind() = 0;
00093 virtual void unbind() = 0;
00094 };
00095
00096 typedef ShPointer<ShBackendSet> ShBackendSetPtr;
00097 typedef ShPointer<const ShBackendSet> ShBackendSetCPtr;
00098
00099 class ShTransformer;
00100 class
00101 SH_DLLEXPORT ShBackend : public ShRefCountable {
00102 public:
00103 virtual ~ShBackend();
00104
00106 virtual std::string name() const { return "";}
00107
00109 virtual std::string version() const = 0;
00110
00112 virtual ShBackendCodePtr generate_code(const std::string& target,
00113 const ShProgramNodeCPtr& shader) = 0;
00114
00115 virtual ShBackendSetPtr generate_set(const ShProgramSet& s);
00116
00118 virtual void execute(const ShProgramNodeCPtr& program, ShStream& dest) = 0;
00119
00121 virtual void unbind_all_programs();
00122
00124 static void unbind_all_backends();
00125
00127 static bool use_backend(const std::string& backend_name);
00128
00130 static bool have_backend(const std::string& backend_name);
00131
00133 static void clear_backends();
00134
00136 static std::string target_handler(const std::string& target, bool restrict_to_selected);
00137
00139 static ShPointer<ShBackend> get_backend(const std::string& target);
00140
00144 static std::list<std::string> derived_targets(const std::string& target);
00145
00146 #ifndef WIN32
00147 typedef lt_dlhandle_struct* LibraryHandle;
00148 #else
00149 typedef void* LibraryHandle;
00150 #endif
00151 typedef std::map<std::string, LibraryHandle> LibraryMap;
00152 typedef std::map<std::string, ShPointer<ShBackend> > BackendMap;
00153 typedef std::set<std::string> BackendSet;
00154
00155 protected:
00156 ShBackend();
00157
00158 private:
00159 static BackendMap* m_instantiated_backends;
00160 static BackendSet* m_selected_backends;
00161 static LibraryMap* m_loaded_libraries;
00162 static bool m_done_init;
00163 static bool m_all_backends_loaded;
00164
00166 static void init();
00167
00170 static std::string lookup_filename(const std::string& backend_name);
00171
00173 static bool is_valid_name(const std::string& backend_name);
00174
00177 static bool load_library(const std::string& filename);
00178
00180 static void load_libraries(const std::string& directory);
00181
00184 static int target_cost(const std::string& backend_name, const std::string& target);
00185
00187 static ShPointer<ShBackend> instantiate_backend(const std::string& backend_name);
00188 };
00189
00190 typedef ShPointer<ShBackend> ShBackendPtr;
00191 typedef ShPointer<const ShBackend> ShBackendCPtr;
00192
00193 }
00194
00195 #endif