make swizzling on incoming arguments work
authorZack Rusin <zack@tungstengraphics.com>
Wed, 13 Feb 2008 14:26:56 +0000 (09:26 -0500)
committerZack Rusin <zack@tungstengraphics.com>
Wed, 13 Feb 2008 14:26:56 +0000 (09:26 -0500)
src/mesa/pipe/llvm/storagesoa.cpp
src/mesa/pipe/llvm/storagesoa.h
src/mesa/pipe/llvm/tgsitollvm.cpp

index 7b758b1665c94e03931fdecc26142391937ffdbf..a65b5c14d9f69dedf97c56e2c93af7c64d372813 100644 (file)
@@ -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;
+}
index 2d07e836f4b4f85ffec2eade09c0cb727624a1c6..9443234c82f59ca37e45447730a56b6fa7e3e255 100644 (file)
@@ -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<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;
 
index 20fce9c9cc6959611b9ecf523f5531bee1fa37f2..10c417996aec46bc5934b31a6a934746ab602eb6 100644 (file)
@@ -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;