#include "storagesoa.h"
+#include "gallivm_p.h"
#include "pipe/p_shader_tokens.h"
#include <llvm/BasicBlock.h>
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);
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);
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);
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);
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;
}
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;
+}
class StorageSoa
{
+public:
+ enum Argument {
+ Input,
+ Output,
+ Temp,
+ Const,
+ Immediate
+ };
public:
StorageSoa(llvm::BasicBlock *block,
llvm::Value *input,
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,
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;
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;