GBE: fix the hack code of sampler offset handling.
authorZhigang Gong <zhigang.gong@intel.com>
Fri, 17 Jan 2014 04:26:47 +0000 (12:26 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Fri, 17 Jan 2014 06:27:55 +0000 (14:27 +0800)
Previous implementation use a virtual register to pass the offset
to the back end side which is too hacky, now fix it.

Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: "Yang, Rong R" <rong.r.yang@intel.com>
backend/src/backend/gen_insn_selection.cpp
backend/src/ir/instruction.cpp
backend/src/ir/instruction.hpp
backend/src/llvm/llvm_gen_backend.cpp

index 74480aa..f34da74 100644 (file)
@@ -2924,12 +2924,6 @@ namespace gbe
       GenRegister msgPayloads[4];
       GenRegister dst[insn.getDstNum()], src[insn.getSrcNum()];
       uint32_t srcNum = insn.getSrcNum();
-      uint32_t samplerOffset = 0;
-      if (srcNum == 4) {
-      /* We have the clamp border workaround. */
-        samplerOffset = insn.getSrc(srcNum - 1).value() * 8;
-        srcNum--;
-      }
 
       for( int i = 0; i < 4; ++i)
         msgPayloads[i] = sel.selReg(sel.reg(FAMILY_DWORD), TYPE_U32);
@@ -2941,7 +2935,8 @@ namespace gbe
         src[valueID] = sel.selReg(insn.getSrc(valueID), insn.getSrcType());
 
       uint32_t bti = insn.getImageIndex();
-      uint32_t sampler = insn.getSamplerIndex() + samplerOffset;
+      /* We have the clamp border workaround. */
+      uint32_t sampler = insn.getSamplerIndex() + insn.getSamplerOffset() * 8;
 
       sel.SAMPLE(dst, insn.getDstNum(), src, srcNum, msgPayloads, 4, bti, sampler);
       return true;
index 3a532ea..3eb28ea 100644 (file)
@@ -491,7 +491,7 @@ namespace ir {
       public TupleDstPolicy<SampleInstruction>
     {
     public:
-      SampleInstruction(uint8_t imageIdx, Tuple dstTuple, Tuple srcTuple, bool dstIsFloat, bool srcIsFloat, uint8_t sampler) {
+      SampleInstruction(uint8_t imageIdx, Tuple dstTuple, Tuple srcTuple, bool dstIsFloat, bool srcIsFloat, uint8_t sampler, uint8_t samplerOffset) {
         this->opcode = OP_SAMPLE;
         this->dst = dstTuple;
         this->src = srcTuple;
@@ -499,6 +499,7 @@ namespace ir {
         this->srcIsFloat = srcIsFloat;
         this->samplerIdx = sampler;
         this->imageIdx = imageIdx;
+        this->samplerOffset = samplerOffset;
       }
       INLINE bool wellFormed(const Function &fn, std::string &why) const;
       INLINE void out(std::ostream &out, const Function &fn) const {
@@ -522,11 +523,12 @@ namespace ir {
       INLINE Type getSrcType(void) const { return this->srcIsFloat ? TYPE_FLOAT : TYPE_S32; }
       INLINE Type getDstType(void) const { return this->dstIsFloat ? TYPE_FLOAT : TYPE_U32; }
       INLINE const uint8_t getSamplerIndex(void) const { return this->samplerIdx; }
-
-      uint16_t srcIsFloat:1;
-      uint16_t dstIsFloat:1;
-      uint16_t samplerIdx:4;
-      uint16_t imageIdx:8;
+      INLINE const uint8_t getSamplerOffset(void) const { return this->samplerOffset; }
+      uint8_t srcIsFloat:1;
+      uint8_t dstIsFloat:1;
+      uint8_t samplerIdx:4;
+      uint8_t samplerOffset:2;
+      uint8_t imageIdx;
       static const uint32_t srcNum = 4;
       static const uint32_t dstNum = 4;
     };
@@ -1473,6 +1475,7 @@ DECL_MEM_FN(SyncInstruction, uint32_t, getParameters(void), getParameters())
 DECL_MEM_FN(SampleInstruction, Type, getSrcType(void), getSrcType())
 DECL_MEM_FN(SampleInstruction, Type, getDstType(void), getDstType())
 DECL_MEM_FN(SampleInstruction, const uint8_t, getSamplerIndex(void), getSamplerIndex())
+DECL_MEM_FN(SampleInstruction, const uint8_t, getSamplerOffset(void), getSamplerOffset())
 DECL_MEM_FN(SampleInstruction, const uint8_t, getImageIndex(void), getImageIndex())
 DECL_MEM_FN(TypedWriteInstruction, Type, getSrcType(void), getSrcType())
 DECL_MEM_FN(TypedWriteInstruction, Type, getCoordType(void), getCoordType())
@@ -1657,8 +1660,8 @@ DECL_MEM_FN(GetSamplerInfoInstruction, const uint8_t, getSamplerIndex(void), get
   }
 
   // SAMPLE
-  Instruction SAMPLE(uint8_t imageIndex, Tuple dst, Tuple src, bool dstIsFloat, bool srcIsFloat, uint8_t sampler) {
-    return internal::SampleInstruction(imageIndex, dst, src, dstIsFloat, srcIsFloat, sampler).convert();
+  Instruction SAMPLE(uint8_t imageIndex, Tuple dst, Tuple src, bool dstIsFloat, bool srcIsFloat, uint8_t sampler, uint8_t samplerOffset) {
+    return internal::SampleInstruction(imageIndex, dst, src, dstIsFloat, srcIsFloat, sampler, samplerOffset).convert();
   }
 
   Instruction TYPED_WRITE(uint8_t imageIndex, Tuple src, Type srcType, Type coordType) {
index 66b64dd..88f7ebf 100644 (file)
@@ -367,6 +367,7 @@ namespace ir {
 
     const uint8_t getImageIndex() const;
     const uint8_t getSamplerIndex(void) const;
+    const uint8_t getSamplerOffset(void) const;
     Type getSrcType(void) const;
     Type getDstType(void) const;
     /*! Return true if the given instruction is an instance of this class */
@@ -672,7 +673,7 @@ namespace ir {
   /*! typed write */
   Instruction TYPED_WRITE(uint8_t imageIndex, Tuple src, Type srcType, Type coordType);
   /*! sample textures */
-  Instruction SAMPLE(uint8_t imageIndex, Tuple dst, Tuple src, bool dstIsFloat, bool srcIsFloat, uint8_t sampler);
+  Instruction SAMPLE(uint8_t imageIndex, Tuple dst, Tuple src, bool dstIsFloat, bool srcIsFloat, uint8_t sampler, uint8_t samplerOffset);
   /*! get image information , such as width/height/depth/... */
   Instruction GET_IMAGE_INFO(int infoType, Register dst, uint8_t imageIndex, Register infoReg);
   /*! get sampler information  */
index 650e48b..1520b4a 100644 (file)
@@ -2412,19 +2412,16 @@ namespace gbe
             srcTupleData.push_back(ucoord);
             srcTupleData.push_back(vcoord);
             srcTupleData.push_back(wcoord);
+            uint8_t samplerOffset = 0;
 #ifdef GEN7_SAMPLER_CLAMP_BORDER_WORKAROUND
             GBE_ASSERT(AI != AE); Constant *CPV = dyn_cast<Constant>(*AI);
             assert(CPV);
             auto x = processConstant<ir::Immediate>(CPV, InsertExtractFunctor(ctx));
             GBE_ASSERTM(x.type == ir::TYPE_U32 || x.type == ir::TYPE_S32, "Invalid sampler type");
-            ir::Register offsetReg(x.data.u32);
-            srcTupleData.push_back(offsetReg);
-#else
-            ir::Register offsetReg(0);
+            samplerOffset = x.data.u32;
 #endif
-            srcTupleData.push_back(offsetReg);
             const ir::Tuple dstTuple = ctx.arrayTuple(&dstTupleData[0], elemNum);
-            const ir::Tuple srcTuple = ctx.arrayTuple(&srcTupleData[0], 4);
+            const ir::Tuple srcTuple = ctx.arrayTuple(&srcTupleData[0], 3);
 
             ir::Type srcType = ir::TYPE_S32, dstType = ir::TYPE_U32;
 
@@ -2456,7 +2453,8 @@ namespace gbe
                 GBE_ASSERT(0); // never been here.
             }
 
-            ctx.SAMPLE(surfaceID, dstTuple, srcTuple, dstType == ir::TYPE_FLOAT, srcType == ir::TYPE_FLOAT, sampler);
+            ctx.SAMPLE(surfaceID, dstTuple, srcTuple, dstType == ir::TYPE_FLOAT,
+                       srcType == ir::TYPE_FLOAT, sampler, samplerOffset);
             break;
           }
           case GEN_OCL_WRITE_IMAGE0: