static void
-translate_immediate(llvm::Module *module,
+translate_immediate(Storage *storage,
struct tgsi_full_immediate *imm)
{
+ float vec[4];
+ int i;
+ for (i = 0; i < imm->Immediate.Size - 1; ++i) {
+ switch( imm->Immediate.DataType ) {
+ case TGSI_IMM_FLOAT32:
+ vec[i] = imm->u.ImmediateFloat32[i].Float;
+ break;
+ default:
+ assert( 0 );
+ }
+ }
+ printf("-------------- VEC = %f %f %f %f\n",
+ vec[0], vec[1], vec[2], vec[3]);
+ storage->addImmediate(vec);
}
static void
val = storage->tempElement(src->SrcRegister.Index);
} else if (src->SrcRegister.File == TGSI_FILE_OUTPUT) {
val = storage->outputElement(src->SrcRegister.Index, indIdx);
+ } else if (src->SrcRegister.File == TGSI_FILE_IMMEDIATE) {
+ val = storage->immediateElement(src->SrcRegister.Index);
} else {
fprintf(stderr, "ERROR: not supported llvm source %d\n", src->SrcRegister.File);
return;
break;
case TGSI_TOKEN_TYPE_IMMEDIATE:
- translate_immediate(mod,
+ translate_immediate(&storage,
&parse.FullToken.FullImmediate);
break;
m_tempStack.pop();
}
#endif //MESA_LLVM
+
+llvm::Value * Storage::immediateElement(int idx)
+{
+ return m_immediates[idx];
+}
+
+void Storage::addImmediate(float *val)
+{
+ std::vector<Constant*> vec(4);
+ vec[0] = ConstantFP::get(Type::FloatTy, APFloat(val[0]));
+ vec[1] = ConstantFP::get(Type::FloatTy, APFloat(val[1]));
+ vec[2] = ConstantFP::get(Type::FloatTy, APFloat(val[2]));
+ vec[3] = ConstantFP::get(Type::FloatTy, APFloat(val[3]));
+ m_immediates.push_back(ConstantVector::get(m_floatVecType, vec));
+}
llvm::Value *inputElement(int idx, llvm::Value *indIdx =0);
llvm::Value *constElement(int idx, llvm::Value *indIdx =0);
llvm::Value *outputElement(int idx, llvm::Value *indIdx =0);
+ llvm::Value *immediateElement(int idx);
llvm::Value *tempElement(int idx);
void setTempElement(int idx, llvm::Value *val, int mask);
void pushTemps();
void popTemps();
+ void addImmediate(float *val);
+
private:
llvm::Value *maskWrite(llvm::Value *src, int mask, llvm::Value *templ);
const char *name(const char *prefix);
std::vector<llvm::Value*> m_temps;
std::vector<llvm::Value*> m_addrs;
std::vector<llvm::Value*> m_dstCache;
+ std::vector<llvm::Constant*> m_immediates;
llvm::VectorType *m_floatVecType;
llvm::VectorType *m_intVecType;
#define TGSI_DEBUG 0
-#define EMIT_IMMEDIATES 0
-
/*
* Map mesa register file to TGSI register file.
case PROGRAM_UNIFORM:
return TGSI_FILE_CONSTANT;
case PROGRAM_CONSTANT:
-#if EMIT_IMMEDIATES
return TGSI_FILE_IMMEDIATE;
-#else
- return TGSI_FILE_CONSTANT;
-#endif
case PROGRAM_INPUT:
return TGSI_FILE_INPUT;
case PROGRAM_OUTPUT:
case TGSI_FILE_OUTPUT:
return outputMapping[index];
-#if EMIT_IMMEDIATES
case TGSI_FILE_IMMEDIATE:
return immediateMapping[index];
-#endif
default:
return index;
return writemask;
}
-#if EMIT_IMMEDIATES
static struct tgsi_full_immediate
make_immediate(const float *value, uint size)
{
imm.u.ImmediateFloat32 = (struct tgsi_immediate_float32 *) value;
return imm;
}
-#endif
static void
compile_instruction(
struct tgsi_full_instruction fullinst;
GLuint preamble_size = 0;
GLuint immediates[1000];
-#if EMIT_IMMEDIATES
GLuint numImmediates = 0;
-#endif
assert(procType == TGSI_PROCESSOR_FRAGMENT ||
procType == TGSI_PROCESSOR_VERTEX);
}
/* immediates/literals */
-#if EMIT_IMMEDIATES
for (i = 0; i < program->Parameters->NumParameters; i++) {
if (program->Parameters->Parameters[i].Type == PROGRAM_CONSTANT) {
struct tgsi_full_immediate fullimm
numImmediates++;
}
}
-#endif
for( i = 0; i < program->NumInstructions; i++ ) {
compile_instruction(