swr/rast: WIP Translation handling
authorGeorge Kyriazis <george.kyriazis@intel.com>
Wed, 18 Apr 2018 20:17:04 +0000 (15:17 -0500)
committerGeorge Kyriazis <george.kyriazis@intel.com>
Fri, 27 Apr 2018 19:36:41 +0000 (14:36 -0500)
Reviewed-by: Bruce Cherniak <bruce.cherniak@intel.com>
src/gallium/drivers/swr/rasterizer/jitter/builder_gfx_mem.cpp
src/gallium/drivers/swr/rasterizer/jitter/builder_gfx_mem.h

index 6ecd96978dd8f99fc83bafff680384a714f7afe1..9b707162b3f2bbc2e7bff055fed3a862f3c8713d 100644 (file)
@@ -160,14 +160,6 @@ namespace SwrJit
         return Builder::LOAD(Ptr, Name);
     }
 
-    LoadInst* BuilderGfxMem::LOAD(Type *Ty, Value *Ptr, const Twine &Name, JIT_MEM_CLIENT usage)
-    {
-        AssertGFXMemoryParams(Ptr, usage);
-
-        Ptr = TranslationHelper(Ptr, Ty);
-        return Builder::LOAD(Ty, Ptr, Name);
-    }
-    
     LoadInst* BuilderGfxMem::LOAD(Value *Ptr, bool isVolatile, const Twine &Name, Type *Ty, JIT_MEM_CLIENT usage)
     {
         AssertGFXMemoryParams(Ptr, usage);
@@ -180,12 +172,25 @@ namespace SwrJit
     {
         AssertGFXMemoryParams(BasePtr, usage);
 
-        // This call is just a pass through to the base class.
-        // It needs to be here to compile due to the combination of virtual overrides and signature overloads.
-        // It doesn't do anything meaningful because the implementation in the base class is going to call 
-        // another version of LOAD inside itself where the actual per offset translation will take place 
-        // and we can't just translate the BasePtr once, each address needs individual translation.
-        return Builder::LOAD(BasePtr, offset, name, Ty, usage);
+        bool bNeedTranslation = false;
+        if (BasePtr->getType() == mInt64Ty)
+        {
+            SWR_ASSERT(Ty);
+            BasePtr = INT_TO_PTR(BasePtr, Ty, name);
+            bNeedTranslation = true;
+        }
+        std::vector<Value*> valIndices;
+        for (auto i : offset)
+        {
+            valIndices.push_back(C(i));
+        }
+        BasePtr = Builder::GEPA(BasePtr, valIndices, name);
+        if (bNeedTranslation)
+        {
+            BasePtr = PTR_TO_INT(BasePtr, mInt64Ty, name);
+        }
+
+        return LOAD(BasePtr, name, Ty, usage);
     }
 
     CallInst* BuilderGfxMem::MASKED_LOAD(Value *Ptr, unsigned Align, Value *Mask, Value *PassThru, const Twine &Name, Type *Ty, JIT_MEM_CLIENT usage)
@@ -196,8 +201,12 @@ namespace SwrJit
         return Builder::MASKED_LOAD(Ptr, Align, Mask, PassThru, Name, Ty, usage);
     }
 
-    Value* BuilderGfxMem::TranslateGfxAddress(Value* xpGfxAddress)
+    Value* BuilderGfxMem::TranslateGfxAddress(Value* xpGfxAddress, Type* PtrTy, const Twine &Name)
     {
-        return INT_TO_PTR(xpGfxAddress, PointerType::get(mInt8Ty, 0));
+        if (PtrTy == nullptr)
+        {
+            PtrTy = mInt8PtrTy;
+        }
+        return INT_TO_PTR(xpGfxAddress, PtrTy, Name);
     }
 }
index f8ec0acdec3ec264d9b1b884377c776bce97fb29..effbe05da139c02c18f491d6a0329a58d7e14a6d 100644 (file)
@@ -48,7 +48,6 @@ namespace SwrJit
 
         virtual LoadInst* LOAD(Value *Ptr, const char *Name, Type *Ty = nullptr, JIT_MEM_CLIENT usage = MEM_CLIENT_INTERNAL);
         virtual LoadInst* LOAD(Value *Ptr, const Twine &Name = "", Type *Ty = nullptr, JIT_MEM_CLIENT usage = MEM_CLIENT_INTERNAL);
-        virtual LoadInst* LOAD(Type *Ty, Value *Ptr, const Twine &Name = "", JIT_MEM_CLIENT usage = MEM_CLIENT_INTERNAL);
         virtual LoadInst* LOAD(Value *Ptr, bool isVolatile, const Twine &Name = "", Type *Ty = nullptr, JIT_MEM_CLIENT usage = MEM_CLIENT_INTERNAL);
         virtual LoadInst* LOAD(Value *BasePtr, const std::initializer_list<uint32_t> &offset, const llvm::Twine& Name = "", Type *Ty = nullptr, JIT_MEM_CLIENT usage = MEM_CLIENT_INTERNAL);
 
@@ -58,7 +57,7 @@ namespace SwrJit
 
         virtual Value *GATHERDD(Value* src, Value* pBase, Value* indices, Value* mask, uint8_t scale = 1, JIT_MEM_CLIENT usage = MEM_CLIENT_INTERNAL);
 
-        Value* TranslateGfxAddress(Value* xpGfxAddress);
+        Value* TranslateGfxAddress(Value* xpGfxAddress, Type* PtrTy = nullptr, const Twine &Name = "");
 
 
     protected: