[Beignet] [PATCH 1/2] GBE: fix the hack code of sampler offset handling.

Yang, Rong R rong.r.yang at intel.com
Thu Jan 16 22:38:16 PST 2014


The patchset LGTM.

-----Original Message-----
From: beignet-bounces at lists.freedesktop.org [mailto:beignet-bounces at lists.freedesktop.org] On Behalf Of Zhigang Gong
Sent: Friday, January 17, 2014 1:12 PM
To: beignet at lists.freedesktop.org
Cc: Gong, Zhigang
Subject: [Beignet] [PATCH 1/2] GBE: fix the hack code of sampler offset handling.

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 at intel.com>
---
 backend/src/backend/gen_insn_selection.cpp |    9 ++-------
 backend/src/ir/instruction.cpp             |   19 +++++++++++--------
 backend/src/ir/instruction.hpp             |    3 ++-
 backend/src/llvm/llvm_gen_backend.cpp      |   12 +++++-------
 4 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/backend/src/backend/gen_insn_selection.cpp b/backend/src/backend/gen_insn_selection.cpp
index 74480aa..f34da74 100644
--- a/backend/src/backend/gen_insn_selection.cpp
+++ b/backend/src/backend/gen_insn_selection.cpp
@@ -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;
diff --git a/backend/src/ir/instruction.cpp b/backend/src/ir/instruction.cpp index 3a532ea..3eb28ea 100644
--- a/backend/src/ir/instruction.cpp
+++ b/backend/src/ir/instruction.cpp
@@ -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) { diff --git a/backend/src/ir/instruction.hpp b/backend/src/ir/instruction.hpp index 66b64dd..88f7ebf 100644
--- a/backend/src/ir/instruction.hpp
+++ b/backend/src/ir/instruction.hpp
@@ -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  */
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp
index ebead77..e75dd49 100644
--- a/backend/src/llvm/llvm_gen_backend.cpp
+++ b/backend/src/llvm/llvm_gen_backend.cpp
@@ -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:
--
1.7.9.5

_______________________________________________
Beignet mailing list
Beignet at lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/beignet


More information about the Beignet mailing list