diff options
author | Zack Rusin <zack@tungstengraphics.com> | 2008-02-13 08:31:13 -0500 |
---|---|---|
committer | Zack Rusin <zack@tungstengraphics.com> | 2008-02-13 08:33:16 -0500 |
commit | 7e51d2a9986231f4ca44a3643628645923e4d468 (patch) | |
tree | e06b54b3586eeebc491154099a89177cf01a4c32 /src/mesa/pipe | |
parent | c107d572104890c83647ad611d303fe1fae70e8f (diff) |
implement immediates and make them work
Diffstat (limited to 'src/mesa/pipe')
-rw-r--r-- | src/mesa/pipe/llvm/storagesoa.cpp | 65 | ||||
-rw-r--r-- | src/mesa/pipe/llvm/storagesoa.h | 7 |
2 files changed, 71 insertions, 1 deletions
diff --git a/src/mesa/pipe/llvm/storagesoa.cpp b/src/mesa/pipe/llvm/storagesoa.cpp index 7292333a80..7b758b1665 100644 --- a/src/mesa/pipe/llvm/storagesoa.cpp +++ b/src/mesa/pipe/llvm/storagesoa.cpp @@ -41,6 +41,7 @@ using namespace llvm; + StorageSoa::StorageSoa(llvm::BasicBlock *block, llvm::Value *input, llvm::Value *output, @@ -57,6 +58,28 @@ StorageSoa::StorageSoa(llvm::BasicBlock *block, void StorageSoa::addImmediate(float *vec) { + float vals[4]; //decompose into soa + + vals[0] = vec[0]; vals[1] = vec[0]; vals[2] = vec[0]; vals[3] = vec[0]; + llvm::Value *xChannel = createConstGlobalVector(vals); + + vals[0] = vec[1]; vals[1] = vec[1]; vals[2] = vec[1]; vals[3] = vec[1]; + llvm::Value *yChannel = createConstGlobalVector(vals); + + + vals[0] = vec[2]; vals[1] = vec[2]; vals[2] = vec[2]; vals[3] = vec[2]; + llvm::Value *zChannel = createConstGlobalVector(vals); + + vals[0] = vec[3]; vals[1] = vec[3]; vals[2] = vec[3]; vals[3] = vec[3]; + llvm::Value *wChannel = createConstGlobalVector(vals); + + std::vector<llvm::Value*> res(4); + res[0] = xChannel; + res[1] = yChannel; + res[2] = zChannel; + res[3] = wChannel; + + m_immediates[m_immediates.size()] = res; } llvm::Value *StorageSoa::addrElement(int idx) const @@ -123,6 +146,12 @@ std::vector<llvm::Value*> StorageSoa::tempElement(int idx, int swizzle, std::vector<llvm::Value*> StorageSoa::immediateElement(int idx, int swizzle) { std::vector<llvm::Value*> res(4); + res = m_immediates[idx]; + + res[0] = new LoadInst(res[0], name("immx"), false, m_block); + res[1] = new LoadInst(res[1], name("immx"), false, m_block); + res[2] = new LoadInst(res[2], name("immx"), false, m_block); + res[3] = new LoadInst(res[3], name("immx"), false, m_block); return res; } @@ -226,3 +255,39 @@ llvm::Value *StorageSoa::alignedArrayLoad(llvm::Value *val) load->setAlignment(8); return load; } + +llvm::Module * StorageSoa::currentModule() const +{ + if (!m_block || !m_block->getParent()) + return 0; + + return m_block->getParent()->getParent(); +} + +llvm::Value * StorageSoa::createConstGlobalVector(float *vec) +{ + VectorType *vectorType = VectorType::get(Type::FloatTy, 4); + GlobalVariable *immediate = new GlobalVariable( + /*Type=*/vectorType, + /*isConstant=*/true, + /*Linkage=*/GlobalValue::ExternalLinkage, + /*Initializer=*/0, // has initializer, specified below + /*Name=*/name("immediate"), + currentModule()); + + std::vector<Constant*> immValues; + ConstantFP *constx = ConstantFP::get(Type::FloatTy, APFloat(vec[0])); + ConstantFP *consty = ConstantFP::get(Type::FloatTy, APFloat(vec[1])); + ConstantFP *constz = ConstantFP::get(Type::FloatTy, APFloat(vec[2])); + ConstantFP *constw = ConstantFP::get(Type::FloatTy, APFloat(vec[3])); + immValues.push_back(constx); + immValues.push_back(consty); + immValues.push_back(constz); + immValues.push_back(constw); + Constant *constVector = ConstantVector::get(vectorType, immValues); + + // Global Variable Definitions + immediate->setInitializer(constVector); + + return immediate; +} diff --git a/src/mesa/pipe/llvm/storagesoa.h b/src/mesa/pipe/llvm/storagesoa.h index 43b23951de..2d07e836f4 100644 --- a/src/mesa/pipe/llvm/storagesoa.h +++ b/src/mesa/pipe/llvm/storagesoa.h @@ -38,6 +38,7 @@ namespace llvm { class LoadInst; class Value; class VectorType; + class Module; } class StorageSoa @@ -74,7 +75,9 @@ private: int channel) const; const char *name(const char *prefix) const; llvm::ConstantInt *constantInt(int) const; - llvm::Value *alignedArrayLoad(llvm::Value *val); + llvm::Value *alignedArrayLoad(llvm::Value *val); + llvm::Module *currentModule() const; + llvm::Value *createConstGlobalVector(float *vec); private: llvm::BasicBlock *m_block; @@ -84,6 +87,8 @@ private: llvm::Value *m_consts; llvm::Value *m_temps; + std::map<int, std::vector<llvm::Value*> > m_immediates; + mutable std::map<int, llvm::ConstantInt*> m_constInts; mutable char m_name[32]; mutable int m_idx; |