From: Zhigang Gong Date: Fri, 17 Jan 2014 04:26:47 +0000 (+0800) Subject: GBE: fix the hack code of sampler offset handling. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=177547dcb678471990be31c029eb3caaa239abfa;p=contrib%2Fbeignet.git 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 Reviewed-by: "Yang, Rong R" --- 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 { 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 650e48b..1520b4a 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(*AI); assert(CPV); auto x = processConstant(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: