summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZack Rusin <zack@tungstengraphics.com>2008-02-13 09:26:56 -0500
committerZack Rusin <zack@tungstengraphics.com>2008-02-13 09:26:56 -0500
commit2e75f39bc4286cebb7330f54d7acf5b8f1d9777f (patch)
tree8aa760b92718dbc5ec8125f55b0afb920badba9c /src
parent12d5b078e8390cb2c598def31fd75260a54ace1a (diff)
make swizzling on incoming arguments work
Diffstat (limited to 'src')
-rw-r--r--src/mesa/pipe/llvm/storagesoa.cpp54
-rw-r--r--src/mesa/pipe/llvm/storagesoa.h21
-rw-r--r--src/mesa/pipe/llvm/tgsitollvm.cpp15
3 files changed, 67 insertions, 23 deletions
diff --git a/src/mesa/pipe/llvm/storagesoa.cpp b/src/mesa/pipe/llvm/storagesoa.cpp
index 7b758b1665..a65b5c14d9 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 <llvm/BasicBlock.h>
@@ -87,8 +88,7 @@ llvm::Value *StorageSoa::addrElement(int idx) const
return 0;
}
-std::vector<llvm::Value*> StorageSoa::inputElement(int idx, int swizzle,
- llvm::Value *indIdx)
+std::vector<llvm::Value*> StorageSoa::inputElement(int idx, llvm::Value *indIdx)
{
std::vector<llvm::Value*> res(4);
@@ -100,8 +100,7 @@ std::vector<llvm::Value*> StorageSoa::inputElement(int idx, int swizzle,
return res;
}
-std::vector<llvm::Value*> StorageSoa::constElement(int idx, int swizzle,
- llvm::Value *indIdx)
+std::vector<llvm::Value*> StorageSoa::constElement(int idx, llvm::Value *indIdx)
{
std::vector<llvm::Value*> res(4);
llvm::Value *xChannel = elementPointer(m_consts, idx, 0);
@@ -117,8 +116,7 @@ std::vector<llvm::Value*> StorageSoa::constElement(int idx, int swizzle,
return res;
}
-std::vector<llvm::Value*> StorageSoa::outputElement(int idx, int swizzle,
- llvm::Value *indIdx)
+std::vector<llvm::Value*> StorageSoa::outputElement(int idx, llvm::Value *indIdx)
{
std::vector<llvm::Value*> res(4);
@@ -130,8 +128,7 @@ std::vector<llvm::Value*> StorageSoa::outputElement(int idx, int swizzle,
return res;
}
-std::vector<llvm::Value*> StorageSoa::tempElement(int idx, int swizzle,
- llvm::Value *indIdx)
+std::vector<llvm::Value*> StorageSoa::tempElement(int idx, llvm::Value *indIdx)
{
std::vector<llvm::Value*> res(4);
@@ -143,15 +140,15 @@ std::vector<llvm::Value*> StorageSoa::tempElement(int idx, int swizzle,
return res;
}
-std::vector<llvm::Value*> StorageSoa::immediateElement(int idx, int swizzle)
+std::vector<llvm::Value*> StorageSoa::immediateElement(int idx)
{
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);
+ 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<llvm::Value*> StorageSoa::argument(Argument type, int idx, int swizzle,
+ llvm::Value *indIdx )
+{
+ std::vector<llvm::Value*> 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<llvm::Value*> 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 2d07e836f4..9443234c82 100644
--- a/src/mesa/pipe/llvm/storagesoa.h
+++ b/src/mesa/pipe/llvm/storagesoa.h
@@ -44,22 +44,26 @@ namespace llvm {
class StorageSoa
{
public:
+ enum Argument {
+ Input,
+ Output,
+ Temp,
+ Const,
+ Immediate
+ };
+public:
StorageSoa(llvm::BasicBlock *block,
llvm::Value *input,
llvm::Value *output,
llvm::Value *consts,
llvm::Value *temps);
+ std::vector<llvm::Value*> argument(Argument type, int idx, int swizzle,
+ llvm::Value *indIdx =0);
void addImmediate(float *vec);
llvm::Value * addrElement(int idx) const;
- std::vector<llvm::Value*> inputElement(int idx, int swizzle, llvm::Value *indIdx =0);
- std::vector<llvm::Value*> constElement(int idx, int swizzle, llvm::Value *indIdx =0);
- std::vector<llvm::Value*> outputElement(int idx, int swizzle, llvm::Value *indIdx =0);
- std::vector<llvm::Value*> tempElement(int idx, int swizzle, llvm::Value *indIdx =0);
- std::vector<llvm::Value*> immediateElement(int idx, int swizzle);
-
llvm::Value *extractIndex(llvm::Value *vec);
void storeOutput(int dstIdx, const std::vector<llvm::Value*> &val,
@@ -79,6 +83,11 @@ private:
llvm::Module *currentModule() const;
llvm::Value *createConstGlobalVector(float *vec);
+ std::vector<llvm::Value*> inputElement(int idx, llvm::Value *indIdx =0);
+ std::vector<llvm::Value*> constElement(int idx, llvm::Value *indIdx =0);
+ std::vector<llvm::Value*> outputElement(int idx, llvm::Value *indIdx =0);
+ std::vector<llvm::Value*> tempElement(int idx, llvm::Value *indIdx =0);
+ std::vector<llvm::Value*> 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 20fce9c9cc..10c417996a 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;