From: Zack Rusin Date: Wed, 13 Feb 2008 14:26:56 +0000 (-0500) Subject: make swizzling on incoming arguments work X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2e75f39bc4286cebb7330f54d7acf5b8f1d9777f;p=mesa.git make swizzling on incoming arguments work --- diff --git a/src/mesa/pipe/llvm/storagesoa.cpp b/src/mesa/pipe/llvm/storagesoa.cpp index 7b758b1665c..a65b5c14d9f 100644 --- a/src/mesa/pipe/llvm/storagesoa.cpp +++ b/src/mesa/pipe/llvm/storagesoa.cpp @@ -27,6 +27,7 @@ #include "storagesoa.h" +#include "gallivm_p.h" #include "pipe/p_shader_tokens.h" #include @@ -87,8 +88,7 @@ llvm::Value *StorageSoa::addrElement(int idx) const return 0; } -std::vector StorageSoa::inputElement(int idx, int swizzle, - llvm::Value *indIdx) +std::vector StorageSoa::inputElement(int idx, llvm::Value *indIdx) { std::vector res(4); @@ -100,8 +100,7 @@ std::vector StorageSoa::inputElement(int idx, int swizzle, return res; } -std::vector StorageSoa::constElement(int idx, int swizzle, - llvm::Value *indIdx) +std::vector StorageSoa::constElement(int idx, llvm::Value *indIdx) { std::vector res(4); llvm::Value *xChannel = elementPointer(m_consts, idx, 0); @@ -117,8 +116,7 @@ std::vector StorageSoa::constElement(int idx, int swizzle, return res; } -std::vector StorageSoa::outputElement(int idx, int swizzle, - llvm::Value *indIdx) +std::vector StorageSoa::outputElement(int idx, llvm::Value *indIdx) { std::vector res(4); @@ -130,8 +128,7 @@ std::vector StorageSoa::outputElement(int idx, int swizzle, return res; } -std::vector StorageSoa::tempElement(int idx, int swizzle, - llvm::Value *indIdx) +std::vector StorageSoa::tempElement(int idx, llvm::Value *indIdx) { std::vector res(4); @@ -143,15 +140,15 @@ std::vector StorageSoa::tempElement(int idx, int swizzle, return res; } -std::vector StorageSoa::immediateElement(int idx, int swizzle) +std::vector StorageSoa::immediateElement(int idx) { std::vector 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); + res[1] = new LoadInst(res[1], name("immy"), false, m_block); + res[2] = new LoadInst(res[2], name("immz"), false, m_block); + res[3] = new LoadInst(res[3], name("immw"), false, m_block); return res; } @@ -291,3 +288,36 @@ llvm::Value * StorageSoa::createConstGlobalVector(float *vec) return immediate; } + +std::vector StorageSoa::argument(Argument type, int idx, int swizzle, + llvm::Value *indIdx ) +{ + std::vector val(4); + switch(type) { + case Input: + val = inputElement(idx, indIdx); + break; + case Output: + val = outputElement(idx, indIdx); + break; + case Temp: + val = tempElement(idx, indIdx); + break; + case Const: + val = constElement(idx, indIdx); + break; + case Immediate: + val = immediateElement(idx); + break; + } + if (!gallivm_is_swizzle(swizzle)) + return val; + + std::vector res(4); + + res[0] = val[gallivm_x_swizzle(swizzle)]; + res[1] = val[gallivm_y_swizzle(swizzle)]; + res[2] = val[gallivm_z_swizzle(swizzle)]; + res[3] = val[gallivm_w_swizzle(swizzle)]; + return res; +} diff --git a/src/mesa/pipe/llvm/storagesoa.h b/src/mesa/pipe/llvm/storagesoa.h index 2d07e836f4b..9443234c82f 100644 --- a/src/mesa/pipe/llvm/storagesoa.h +++ b/src/mesa/pipe/llvm/storagesoa.h @@ -43,6 +43,14 @@ namespace llvm { class StorageSoa { +public: + enum Argument { + Input, + Output, + Temp, + Const, + Immediate + }; public: StorageSoa(llvm::BasicBlock *block, llvm::Value *input, @@ -50,16 +58,12 @@ public: llvm::Value *consts, llvm::Value *temps); + std::vector argument(Argument type, int idx, int swizzle, + llvm::Value *indIdx =0); void addImmediate(float *vec); llvm::Value * addrElement(int idx) const; - std::vector inputElement(int idx, int swizzle, llvm::Value *indIdx =0); - std::vector constElement(int idx, int swizzle, llvm::Value *indIdx =0); - std::vector outputElement(int idx, int swizzle, llvm::Value *indIdx =0); - std::vector tempElement(int idx, int swizzle, llvm::Value *indIdx =0); - std::vector immediateElement(int idx, int swizzle); - llvm::Value *extractIndex(llvm::Value *vec); void storeOutput(int dstIdx, const std::vector &val, @@ -79,6 +83,11 @@ private: llvm::Module *currentModule() const; llvm::Value *createConstGlobalVector(float *vec); + std::vector inputElement(int idx, llvm::Value *indIdx =0); + std::vector constElement(int idx, llvm::Value *indIdx =0); + std::vector outputElement(int idx, llvm::Value *indIdx =0); + std::vector tempElement(int idx, llvm::Value *indIdx =0); + std::vector immediateElement(int idx); private: llvm::BasicBlock *m_block; diff --git a/src/mesa/pipe/llvm/tgsitollvm.cpp b/src/mesa/pipe/llvm/tgsitollvm.cpp index 20fce9c9cc6..10c417996ae 100644 --- a/src/mesa/pipe/llvm/tgsitollvm.cpp +++ b/src/mesa/pipe/llvm/tgsitollvm.cpp @@ -706,15 +706,20 @@ translate_instructionir(llvm::Module *module, indIdx = storage->extractIndex(indIdx); } if (src->SrcRegister.File == TGSI_FILE_CONSTANT) { - val = storage->constElement(src->SrcRegister.Index, swizzle, indIdx); + val = storage->argument(StorageSoa::Const, + src->SrcRegister.Index, swizzle, indIdx); } else if (src->SrcRegister.File == TGSI_FILE_INPUT) { - val = storage->inputElement(src->SrcRegister.Index, swizzle, indIdx); + val = storage->argument(StorageSoa::Input, + src->SrcRegister.Index, swizzle, indIdx); } else if (src->SrcRegister.File == TGSI_FILE_TEMPORARY) { - val = storage->tempElement(src->SrcRegister.Index, swizzle); + val = storage->argument(StorageSoa::Temp, + src->SrcRegister.Index, swizzle); } else if (src->SrcRegister.File == TGSI_FILE_OUTPUT) { - val = storage->outputElement(src->SrcRegister.Index, swizzle, indIdx); + val = storage->argument(StorageSoa::Output, + src->SrcRegister.Index, swizzle, indIdx); } else if (src->SrcRegister.File == TGSI_FILE_IMMEDIATE) { - val = storage->immediateElement(src->SrcRegister.Index, swizzle); + val = storage->argument(StorageSoa::Immediate, + src->SrcRegister.Index, swizzle); } else { fprintf(stderr, "ERROR: not supported llvm source %d\n", src->SrcRegister.File); return;