00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00051
const unsigned int SH_ARB_ANY = 0x000;
00052
const unsigned int SH_ARB_FP = 0x001;
00053
const unsigned int SH_ARB_VP = 0x002;
00054
const unsigned int SH_ARB_NVFP = 0x004;
00055
const unsigned int SH_ARB_NVFP2 = 0x008;
00056
const unsigned int SH_ARB_ATIDB = 0x010;
00057
const unsigned int SH_ARB_NVVP2 = 0x020;
00058
const unsigned int SH_ARB_NVVP3 = 0x040;
00059
const unsigned int SH_ARB_VEC1 = 0x080;
00060
const unsigned int SH_ARB_VEC2 = 0x100;
00061
const unsigned int SH_ARB_VEC3 = 0x200;
00062
const unsigned int SH_ARB_VEC4 = 0x400;
00063
const unsigned int SH_ARB_END = 0x800;
00064
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;
00165
SH::ShProgramNodeCPtr m_originalShader;
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
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