implement swizzling on writes
authorZack Rusin <zack@tungstengraphics.com>
Thu, 14 Feb 2008 03:53:00 +0000 (22:53 -0500)
committerZack Rusin <zack@tungstengraphics.com>
Fri, 15 Feb 2008 06:17:16 +0000 (01:17 -0500)
src/mesa/pipe/llvm/storagesoa.cpp
src/mesa/pipe/llvm/storagesoa.h
src/mesa/pipe/llvm/tgsitollvm.cpp

index a65b5c14d9f69dedf97c56e2c93af7c64d372813..75e7a36bc24ea3ce46c7defd6c2355cd1ab538a8 100644 (file)
@@ -30,6 +30,8 @@
 #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>
@@ -158,49 +160,6 @@ llvm::Value * StorageSoa::extractIndex(llvm::Value *vec)
    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
 {
@@ -309,6 +268,10 @@ std::vector<llvm::Value*> StorageSoa::argument(Argument type, int idx, int swizz
    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;
@@ -321,3 +284,41 @@ std::vector<llvm::Value*> StorageSoa::argument(Argument type, int idx, int swizz
    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);
+   }
+}
index 9443234c82f59ca37e45447730a56b6fa7e3e255..8880bf5ec6746d1c5b019404c681d0375a28d6c0 100644 (file)
@@ -49,7 +49,8 @@ public:
       Output,
       Temp,
       Const,
-      Immediate
+      Immediate,
+      Address
    };
 public:
    StorageSoa(llvm::BasicBlock *block,
@@ -58,20 +59,17 @@ public:
               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;
index 10c417996aec46bc5934b31a6a934746ab602eb6..287a86c60cb61011adc0a5383330623c9b7f26d0 100644 (file)
@@ -1063,11 +1063,14 @@ translate_instructionir(llvm::Module *module,
       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");