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

ArbCode.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 ARBCODE_HPP 00028 #define ARBCODE_HPP 00029 00030 #include "GlBackend.hpp" 00031 #include "ShTransformer.hpp" 00032 #include "ShVariableNode.hpp" 00033 #include "ShVariable.hpp" 00034 #include "ShCtrlGraph.hpp" 00035 #include "ShTextureNode.hpp" 00036 #include "ShProgram.hpp" 00037 #include "ShSwizzle.hpp" 00038 #include "ShRefCount.hpp" 00039 #include "ShStructural.hpp" 00040 #include "ArbLimits.hpp" 00041 #include "ArbReg.hpp" 00042 #include "ArbInst.hpp" 00043 00044 namespace shgl { 00045 00046 class ArbCode; 00047 class ArbBindingSpecs; 00048 class ArbMapping; 00049 00050 // Filters for code emission and environment setup 00051 const unsigned int SH_ARB_ANY = 0x000; // All targets 00052 const unsigned int SH_ARB_FP = 0x001; // ARB_fragment_program 00053 const unsigned int SH_ARB_VP = 0x002; // ARB_vertex_program 00054 const unsigned int SH_ARB_NVFP = 0x004; // NV_fragment_program_option 00055 const unsigned int SH_ARB_NVFP2 = 0x008; // NV_fragment_program2 00056 const unsigned int SH_ARB_ATIDB = 0x010; // ATI_draw_buffers 00057 const unsigned int SH_ARB_NVVP2 = 0x020; // NV_vertex_program2_option 00058 const unsigned int SH_ARB_NVVP3 = 0x040; // NV_vertex_program3 00059 const unsigned int SH_ARB_VEC1 = 0x080; // Maximum source has length 1 00060 const unsigned int SH_ARB_VEC2 = 0x100; // Maximum source has length 2 00061 const unsigned int SH_ARB_VEC3 = 0x200; // Maximum source has length 3 00062 const unsigned int SH_ARB_VEC4 = 0x400; // Maximum source has length 4 00063 const unsigned int SH_ARB_END = 0x800; // Not a filter. End of 00064 // table. 00065 00066 class ArbCode : public SH::ShBackendCode { 00067 public: 00068 ArbCode(const SH::ShProgramNodeCPtr& program, const std::string& target, 00069 TextureStrategy* textures); 00070 virtual ~ArbCode(); 00071 00072 virtual bool allocateRegister(const SH::ShVariableNodePtr& var); 00073 virtual void freeRegister(const SH::ShVariableNodePtr& var); 00074 00075 virtual void upload(); 00076 virtual void bind(); 00077 virtual void updateUniform(const SH::ShVariableNodePtr& uniform); 00078 00079 std::ostream& print(std::ostream& out); 00080 std::ostream& printInputOutputFormat(std::ostream& out); 00081 00083 void generate(); 00084 00085 private: 00086 00088 void genNode(SH::ShCtrlGraphNodePtr node); 00089 00093 void genStructNode(const SH::ShStructuralNodePtr& node); 00094 00096 void emit(const SH::ShStatement& stmt); 00097 00099 void emit_div(const SH::ShStatement& stmt); 00100 void emit_sqrt(const SH::ShStatement& stmt); 00101 void emit_lerp(const SH::ShStatement& stmt); 00102 void emit_dot2(const SH::ShStatement& stmt); 00103 void emit_eq(const SH::ShStatement& stmt); 00104 void emit_ceil(const SH::ShStatement& stmt); 00105 void emit_mod(const SH::ShStatement& stmt); 00106 void emit_trig(const SH::ShStatement& stmt); 00107 void emit_invtrig(const SH::ShStatement& stmt); 00108 void emit_tan(const SH::ShStatement& stmt); 00109 void emit_exp(const SH::ShStatement& stmt); 00110 void emit_log(const SH::ShStatement& stmt); 00111 void emit_norm(const SH::ShStatement& stmt); 00112 void emit_sgn(const SH::ShStatement& stmt); 00113 void emit_tex(const SH::ShStatement& stmt); 00114 void emit_nvcond(const SH::ShStatement& stmt); 00115 void emit_cmul(const SH::ShStatement& stmt); 00116 void emit_csum(const SH::ShStatement& stmt); 00117 void emit_kil(const SH::ShStatement& stmt); 00118 00120 void allocRegs(); 00121 00123 void allocInputs(const ArbLimits& limits); 00124 00126 void allocOutputs(const ArbLimits& limits); 00127 00129 void allocParam(const ArbLimits& limits, const SH::ShVariableNodePtr& node); 00130 00132 void allocConsts(const ArbLimits& limits); 00133 00135 void allocTemps(const ArbLimits& limits); 00136 00138 void allocTextures(const ArbLimits& limits); 00139 00141 void bindTextures(); 00142 00144 void bindTexture(const SH::ShTextureNodePtr& node); 00145 00146 void bindSpecial(const SH::ShProgramNode::VarList::const_iterator& begin, 00147 const SH::ShProgramNode::VarList::const_iterator& end, 00148 const ArbBindingSpecs& specs, 00149 std::vector<int>& bindings, 00150 ArbRegType type, int& num); 00151 00153 std::ostream& printVar(std::ostream& out, bool dest, const SH::ShVariable& var, 00154 bool collectingOp, 00155 const SH::ShSwizzle& destSwiz) const; 00156 00159 bool printSamplingInstruction(std::ostream& out, const ArbInst& inst) const; 00160 00161 int getLabel(SH::ShCtrlGraphNodePtr node); 00162 00163 TextureStrategy* m_textures; 00164 SH::ShProgramNodePtr m_shader; // internally visible shader ShTransformered to fit this target (ARB) 00165 SH::ShProgramNodeCPtr m_originalShader; // original shader (should alway use this for external (e.g. globals)) 00166 std::string m_unit; 00167 00168 typedef std::vector<ArbInst> ArbInstList; 00169 ArbInstList m_instructions; 00170 00172 std::list<int> m_tempRegs; 00173 00175 int m_numTemps; 00176 00178 int m_numInputs; 00179 00181 int m_numOutputs; 00182 00184 int m_numParams; 00185 00187 int m_numConsts; 00188 00190 int m_numTextures; 00191 00192 typedef std::map<SH::ShVariableNodePtr, 00193 SH::ShPointer<ArbReg> > RegMap; 00194 RegMap m_registers; 00195 00196 typedef std::list< SH::ShPointer<ArbReg> > RegList; 00197 RegList m_reglist; 00198 00199 std::vector<int> m_outputBindings; 00200 std::vector<int> m_inputBindings; 00201 00203 SH::ShTransformer::VarSplitMap m_splits; 00204 00206 unsigned int m_programId; 00207 00208 static ArbMapping table[]; 00209 00210 // Extensions and language alternatives available. See list above 00211 unsigned int m_environment; 00212 00213 typedef std::map<SH::ShCtrlGraphNodePtr, int> LabelMap; 00214 LabelMap m_label_map; 00215 int m_max_label; 00216 }; 00217 00218 typedef SH::ShPointer<ArbCode> ArbCodePtr; 00219 00220 00221 } 00222 00223 #endif

Generated on Mon Oct 18 14:17:38 2004 for Sh by doxygen 1.3.7