Implement extended swizzling.
authorZack Rusin <zack@tungstengraphics.com>
Mon, 22 Oct 2007 18:01:52 +0000 (14:01 -0400)
committerZack Rusin <zack@tungstengraphics.com>
Wed, 24 Oct 2007 15:21:05 +0000 (11:21 -0400)
src/mesa/pipe/llvm/llvmtgsi.cpp
src/mesa/pipe/llvm/storage.cpp
src/mesa/pipe/llvm/storage.h

index d40a7cc380a3ceaf48c1c6b3240136e6e81c1b4b..69d54bf9af241b8cddc9e443ef6a373e1bc7b739 100644 (file)
@@ -162,10 +162,26 @@ translate_instruction(llvm::Module *module,
              src->SrcRegisterExtSwz.ExtSwizzleY != TGSI_EXTSWIZZLE_Y ||
              src->SrcRegisterExtSwz.ExtSwizzleZ != TGSI_EXTSWIZZLE_Z ||
              src->SrcRegisterExtSwz.ExtSwizzleW != TGSI_EXTSWIZZLE_W) {
-            int swizzle = src->SrcRegisterExtSwz.ExtSwizzleX * 1000;
-            swizzle += src->SrcRegisterExtSwz.ExtSwizzleY * 100;
-            swizzle += src->SrcRegisterExtSwz.ExtSwizzleZ * 10;
-            swizzle += src->SrcRegisterExtSwz.ExtSwizzleW * 1;
+            int swizzle = 0;
+
+            if (src->SrcRegisterExtSwz.ExtSwizzleX != TGSI_EXTSWIZZLE_X)
+               swizzle = src->SrcRegisterExtSwz.ExtSwizzleX * 1000;
+            else
+               swizzle = src->SrcRegister.SwizzleX * 1000;
+            if (src->SrcRegisterExtSwz.ExtSwizzleY != TGSI_EXTSWIZZLE_Y)
+               swizzle += src->SrcRegisterExtSwz.ExtSwizzleY * 100;
+            else
+               swizzle += src->SrcRegister.SwizzleY  * 100;
+            if (src->SrcRegisterExtSwz.ExtSwizzleZ != TGSI_EXTSWIZZLE_Z)
+               swizzle += src->SrcRegisterExtSwz.ExtSwizzleZ * 10;
+            else
+               swizzle += src->SrcRegister.SwizzleZ  * 10;
+            if (src->SrcRegisterExtSwz.ExtSwizzleW != TGSI_EXTSWIZZLE_W)
+               swizzle += src->SrcRegisterExtSwz.ExtSwizzleW * 1;
+            else
+               swizzle += src->SrcRegister.SwizzleW  * 1;
+            /*fprintf(stderr, "EXT XXXXXXXX swizzle x = %d\n", swizzle);*/
+
             val = storage->shuffleVector(val, swizzle);
          }
       } else if (src->SrcRegister.SwizzleX != TGSI_SWIZZLE_X ||
@@ -176,13 +192,16 @@ translate_instruction(llvm::Module *module,
          swizzle += src->SrcRegister.SwizzleY  * 100;
          swizzle += src->SrcRegister.SwizzleZ  * 10;
          swizzle += src->SrcRegister.SwizzleW  * 1;
+         /*fprintf(stderr, "XXXXXXXX swizzle = %d\n", swizzle);*/
          val = storage->shuffleVector(val, swizzle);
       }
       inputs[i] = val;
    }
 
    /*if (inputs[0])
-     instr->printVector(inputs[0]);*/
+     instr->printVector(inputs[0]);
+   if (inputs[1])
+   instr->printVector(inputs[1]);*/
    llvm::Value *out = 0;
    switch (inst->Instruction.Opcode) {
    case TGSI_OPCODE_ARL:
index 0fe973b78e8d236aa338fcd0259a8154d4bd541b..3bf37c75673e96171cf05b5b79fbf4fb50ddf1aa 100644 (file)
@@ -25,6 +25,7 @@ Storage::Storage(llvm::BasicBlock *block, llvm::Value *out,
 
    m_undefFloatVec = UndefValue::get(m_floatVecType);
    m_undefIntVec   = UndefValue::get(m_intVecType);
+   m_extSwizzleVec = 0;
 
    m_numConsts = 0;
 }
@@ -32,6 +33,27 @@ Storage::Storage(llvm::BasicBlock *block, llvm::Value *out,
 //can only build vectors with all members in the [0, 9] range
 llvm::Constant *Storage::shuffleMask(int vec)
 {
+   if (!m_extSwizzleVec) {
+      Constant *const_vec = Constant::getNullValue(m_floatVecType);
+      InsertElementInst *res = new InsertElementInst(const_vec,
+                                                     ConstantFP::get(Type::FloatTy, APFloat(0.f)),
+                                                     unsigned(0),
+                                                     name("extswx"), m_block);
+      res = new InsertElementInst(res, ConstantFP::get(Type::FloatTy, APFloat(1.f)),
+                                  unsigned(1),
+                                  name("extswy"),
+                                  m_block);
+      res = new InsertElementInst(res, ConstantFP::get(Type::FloatTy, APFloat(0.f)),
+                                  unsigned(2),
+                                  name("extswz"),
+                                  m_block);
+      res = new InsertElementInst(res, ConstantFP::get(Type::FloatTy, APFloat(1.f)),
+                                  unsigned(3),
+                                  name("extsww"),
+                                  m_block);
+      m_extSwizzleVec = res;
+   }
+
    if (m_intVecs.find(vec) != m_intVecs.end()) {
       return m_intVecs[vec];
    }
@@ -79,6 +101,7 @@ llvm::Value *Storage::inputElement(int idx)
                                  false, m_block);
    load->setAlignment(8);
    m_inputs[idx] = load;
+
    return load;
 }
 
@@ -103,7 +126,7 @@ llvm::Value *Storage::shuffleVector(llvm::Value *vec, int shuffle)
 {
    Constant *mask = shuffleMask(shuffle);
    ShuffleVectorInst *res =
-      new ShuffleVectorInst(vec, m_undefFloatVec, mask,
+      new ShuffleVectorInst(vec, m_extSwizzleVec, mask,
                             name("shuffle"), m_block);
    return res;
 }
index 66a33633325acb14e66d3ae19b848c3a7c126e0e..da7b0dbe0143752ae7e84fb3caec1331c2b89a6e 100644 (file)
@@ -57,6 +57,8 @@ private:
    llvm::Value      *m_undefFloatVec;
    llvm::Value      *m_undefIntVec;
 
+   llvm::Value      *m_extSwizzleVec;
+
    char        m_name[32];
    int         m_idx;