diff options
author | Zack Rusin <[email protected]> | 2007-10-29 10:59:24 -0400 |
---|---|---|
committer | Zack Rusin <[email protected]> | 2007-10-30 05:15:05 -0400 |
commit | b0f3b5910ebd0737600ab7b1fdc135d74f2617f4 (patch) | |
tree | 2e4ebcc7f6d13ea151aac92cd3f19741a0bf0845 /src | |
parent | 8b2f997af572dd3aca00c4888adf2b0a60656331 (diff) |
Enable immediates in TGSI and work with them in LLVM code.
Enables immediates by default in the TGSI translation code
and adds code handling it in llvm tgsi translation.
Diffstat (limited to 'src')
-rw-r--r-- | src/mesa/pipe/llvm/llvmtgsi.cpp | 20 | ||||
-rw-r--r-- | src/mesa/pipe/llvm/storage.cpp | 15 | ||||
-rw-r--r-- | src/mesa/pipe/llvm/storage.h | 4 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_mesa_to_tgsi.c | 14 |
4 files changed, 37 insertions, 16 deletions
diff --git a/src/mesa/pipe/llvm/llvmtgsi.cpp b/src/mesa/pipe/llvm/llvmtgsi.cpp index 4611ac17664..ec38c695b93 100644 --- a/src/mesa/pipe/llvm/llvmtgsi.cpp +++ b/src/mesa/pipe/llvm/llvmtgsi.cpp @@ -164,9 +164,23 @@ translate_declaration(llvm::Module *module, 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 @@ -200,6 +214,8 @@ translate_instruction(llvm::Module *module, 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; @@ -679,7 +695,7 @@ tgsi_to_llvm(struct gallivm_prog *prog, const struct tgsi_token *tokens) break; case TGSI_TOKEN_TYPE_IMMEDIATE: - translate_immediate(mod, + translate_immediate(&storage, &parse.FullToken.FullImmediate); break; diff --git a/src/mesa/pipe/llvm/storage.cpp b/src/mesa/pipe/llvm/storage.cpp index ff62fcf3e49..1aaabbe8828 100644 --- a/src/mesa/pipe/llvm/storage.cpp +++ b/src/mesa/pipe/llvm/storage.cpp @@ -393,3 +393,18 @@ void Storage::popTemps() 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)); +} diff --git a/src/mesa/pipe/llvm/storage.h b/src/mesa/pipe/llvm/storage.h index ac3e4d5af97..f9a82ef857d 100644 --- a/src/mesa/pipe/llvm/storage.h +++ b/src/mesa/pipe/llvm/storage.h @@ -65,6 +65,7 @@ public: 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); @@ -87,6 +88,8 @@ public: 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); @@ -102,6 +105,7 @@ private: 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; diff --git a/src/mesa/state_tracker/st_mesa_to_tgsi.c b/src/mesa/state_tracker/st_mesa_to_tgsi.c index 75195968e5c..36b41ea7e89 100644 --- a/src/mesa/state_tracker/st_mesa_to_tgsi.c +++ b/src/mesa/state_tracker/st_mesa_to_tgsi.c @@ -38,8 +38,6 @@ #define TGSI_DEBUG 0 -#define EMIT_IMMEDIATES 0 - /* * Map mesa register file to TGSI register file. @@ -60,11 +58,7 @@ map_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: @@ -101,10 +95,8 @@ map_register_file_index( case TGSI_FILE_OUTPUT: return outputMapping[index]; -#if EMIT_IMMEDIATES case TGSI_FILE_IMMEDIATE: return immediateMapping[index]; -#endif default: return index; @@ -166,7 +158,6 @@ convert_writemask( return writemask; } -#if EMIT_IMMEDIATES static struct tgsi_full_immediate make_immediate(const float *value, uint size) { @@ -177,7 +168,6 @@ make_immediate(const float *value, uint size) imm.u.ImmediateFloat32 = (struct tgsi_immediate_float32 *) value; return imm; } -#endif static void compile_instruction( @@ -661,9 +651,7 @@ tgsi_translate_mesa_program( 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); @@ -804,7 +792,6 @@ tgsi_translate_mesa_program( } /* 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 @@ -818,7 +805,6 @@ tgsi_translate_mesa_program( numImmediates++; } } -#endif for( i = 0; i < program->NumInstructions; i++ ) { compile_instruction( |