#include "gallivm_p.h"
#include "pipe/p_shader_tokens.h"
+#include "pipe/p_debug.h"
+
#include <llvm/BasicBlock.h>
#include <llvm/Module.h>
#include <llvm/Value.h>
return 0;
}
-void StorageSoa::storeOutput(int dstIdx, const std::vector<llvm::Value*> &val,
- int mask)
-{
- if (mask != TGSI_WRITEMASK_XYZW) {
- fprintf(stderr, "requires swizzle!!\n");
- assert(0);
- } else {
- llvm::Value *xChannel = elementPointer(m_output, dstIdx, 0);
- llvm::Value *yChannel = elementPointer(m_output, dstIdx, 1);
- llvm::Value *zChannel = elementPointer(m_output, dstIdx, 2);
- llvm::Value *wChannel = elementPointer(m_output, dstIdx, 3);
-
- StoreInst *st = new StoreInst(val[0], xChannel, false, m_block);
- st = new StoreInst(val[1], yChannel, false, m_block);
- st = new StoreInst(val[2], zChannel, false, m_block);
- st = new StoreInst(val[3], wChannel, false, m_block);
- }
-}
-
-void StorageSoa::storeTemp(int idx, const std::vector<llvm::Value*> &val,
- int mask)
-{
- if (mask != TGSI_WRITEMASK_XYZW) {
- fprintf(stderr, "requires swizzle!!\n");
- assert(0);
- } else {
- llvm::Value *xChannel = elementPointer(m_temps, idx, 0);
- llvm::Value *yChannel = elementPointer(m_temps, idx, 1);
- llvm::Value *zChannel = elementPointer(m_temps, idx, 2);
- llvm::Value *wChannel = elementPointer(m_temps, idx, 3);
-
- StoreInst *st = new StoreInst(val[0], xChannel, false, m_block);
- st = new StoreInst(val[1], yChannel, false, m_block);
- st = new StoreInst(val[2], zChannel, false, m_block);
- st = new StoreInst(val[3], wChannel, false, m_block);
- }
-}
-
-void StorageSoa::storeAddress(int idx, const std::vector<llvm::Value*> &val,
- int mask)
-{
-}
-
llvm::Value * StorageSoa::elementPointer(llvm::Value *ptr, int index,
int channel) const
{
case Immediate:
val = immediateElement(idx);
break;
+ case Address:
+ debug_printf("Address not handled in the fetch phase!\n");
+ assert(0);
+ break;
}
if (!gallivm_is_swizzle(swizzle))
return val;
res[3] = val[gallivm_w_swizzle(swizzle)];
return res;
}
+
+void StorageSoa::store(Argument type, int idx, const std::vector<llvm::Value*> &val,
+ int mask)
+{
+ llvm::Value *out = 0;
+ switch(type) {
+ case Output:
+ out = m_output;
+ break;
+ case Temp:
+ out = m_temps;
+ break;
+ case Input:
+ out = m_input;
+ break;
+ default:
+ debug_printf("Can't save output of this type: %d !\n", type);
+ assert(0);
+ break;
+ }
+
+ if ((mask & TGSI_WRITEMASK_X)) {
+ llvm::Value *xChannel = elementPointer(out, idx, 0);
+ new StoreInst(val[0], xChannel, false, m_block);
+ }
+ if ((mask & TGSI_WRITEMASK_Y)) {
+ llvm::Value *yChannel = elementPointer(out, idx, 1);
+ new StoreInst(val[1], yChannel, false, m_block);
+ }
+ if ((mask & TGSI_WRITEMASK_Z)) {
+ llvm::Value *zChannel = elementPointer(out, idx, 2);
+ new StoreInst(val[2], zChannel, false, m_block);
+ }
+ if ((mask & TGSI_WRITEMASK_W)) {
+ llvm::Value *wChannel = elementPointer(out, idx, 3);
+ new StoreInst(val[3], wChannel, false, m_block);
+ }
+}
Output,
Temp,
Const,
- Immediate
+ Immediate,
+ Address
};
public:
StorageSoa(llvm::BasicBlock *block,
llvm::Value *consts,
llvm::Value *temps);
+
std::vector<llvm::Value*> argument(Argument type, int idx, int swizzle,
llvm::Value *indIdx =0);
+ void store(Argument type, int idx, const std::vector<llvm::Value*> &val,
+ int mask);
+
void addImmediate(float *vec);
llvm::Value * addrElement(int idx) const;
llvm::Value *extractIndex(llvm::Value *vec);
-
- void storeOutput(int dstIdx, const std::vector<llvm::Value*> &val,
- int mask);
- void storeTemp(int idx, const std::vector<llvm::Value*> &val,
- int mask);
- void storeAddress(int idx, const std::vector<llvm::Value*> &val,
- int mask);
private:
llvm::Value *elementPointer(llvm::Value *ptr, int index,
int channel) const;
struct tgsi_full_dst_register *dst = &inst->FullDstRegisters[i];
if (dst->DstRegister.File == TGSI_FILE_OUTPUT) {
- storage->storeOutput(dst->DstRegister.Index, out, dst->DstRegister.WriteMask);
+ storage->store(StorageSoa::Output,
+ dst->DstRegister.Index, out, dst->DstRegister.WriteMask);
} else if (dst->DstRegister.File == TGSI_FILE_TEMPORARY) {
- storage->storeTemp(dst->DstRegister.Index, out, dst->DstRegister.WriteMask);
+ storage->store(StorageSoa::Temp,
+ dst->DstRegister.Index, out, dst->DstRegister.WriteMask);
} else if (dst->DstRegister.File == TGSI_FILE_ADDRESS) {
- storage->storeAddress(dst->DstRegister.Index, out, dst->DstRegister.WriteMask);
+ storage->store(StorageSoa::Address,
+ dst->DstRegister.Index, out, dst->DstRegister.WriteMask);
} else {
fprintf(stderr, "ERROR: unsupported LLVM destination!");
assert(!"wrong destination");