Index: branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TComDataCU.cpp	(revision 432)
+++ branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TComDataCU.cpp	(revision 441)
@@ -209,14 +209,77 @@
 #endif
 #if LGE_VSP_INHERIT_D0092
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+         assert(pDInfo->m_aRefIdx[0] < 0);
+         iVspDirTrue[0] = pDInfo->m_aListIdx[0];
+         Int iRefIdxList0 = NOT_VALID;
+         Int iRefIdxList1 = NOT_VALID;
+         iRefIdxList0 = getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_0)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_0));
+         if ( getSlice()->isInterB() )
+         {
+            iRefIdxList1 = getSlice()->getRefPic(REF_PIC_LIST_1, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_1)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_1));
+         }
+
+#if MTK_VSP_USING_NBDV_D0105
+        //pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0], pDInfo->m_aListIdx[0]==REF_PIC_LIST_0 ? iRefIdxList0 :NOT_VALID  );
+        pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0],  iRefIdxList0 );
+#else
+        pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0],  iRefIdxList0 );
+#endif
+         if ( getSlice()->isInterB() )
+         {
+#if MTK_VSP_USING_NBDV_D0105
+          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], iRefIdxList1 );
+          //pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0],  iRefIdxList1);
+#else
+          pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], iRefIdxList1);
+#endif
+         }
+         iVSPIndexTrue[iCount] = 1;
+#else
+
+#if !MERL_General_Fix
+         Int iRefIdxList0 = NOT_VALID;
+         Int iRefIdxList1 = NOT_VALID;
+         iRefIdxList0 = getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_0)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_0));
+         if ( getSlice()->isInterB() )
+         {
+           iRefIdxList1 = getSlice()->getRefPic(REF_PIC_LIST_1, 0)->getPOC()==getSlice()->getPOC() ? 0 : (getSlice()->getNewRefIdx(REF_PIC_LIST_1)==-1 ? NOT_VALID : getSlice()->getNewRefIdx(REF_PIC_LIST_1));
+         }
+#if MTK_VSP_USING_NBDV_D0105
+         pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0],  iRefIdxList0 );
+#else
+         pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0],  iRefIdxList0 );
+#endif
+         if ( getSlice()->isInterB() )
+         {
+#if MTK_VSP_USING_NBDV_D0105
+           pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], iRefIdxList1 );
+#else
+           pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], iRefIdxList1);
+#endif
+         }
+         iVSPIndexTrue[iCount] = 1;
+#else
          Int iRefIdx = NOT_VALID;
+
 #if QC_BVSP_CleanUP_D0191
          iRefIdx = getSlice()->getRefPic(REF_PIC_LIST_0, 0)->getPOC()==getSlice()->getPOC() ? 0: getSlice()->getNewRefIdx(REF_PIC_LIST_0);
 #endif
+#if MTK_VSP_USING_NBDV_D0105
+         pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCandNoRef[0], iRefIdx );
+#else
          pcMvFieldNeighbours[iCount<<1].setMvField(pDInfo->m_acMvCand[0], iRefIdx );
+#endif
          if ( getSlice()->isInterB() )
          {
+#if MTK_VSP_USING_NBDV_D0105
+           pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCandNoRef[0], iRefIdx );
+#else
              pcMvFieldNeighbours[(iCount<<1)+1].setMvField( pDInfo->m_acMvCand[0], iRefIdx );
+#endif
          }
          iVSPIndexTrue[iCount] = 1;
+#endif
+#endif
 #else
           // get Mv using checked disparity vector
@@ -4478,8 +4541,16 @@
   //===== vsp 3 =====
 #if LGE_VSP_INHERIT_D0092
-    if ( !xAddVspMergeCand(3, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+    if ( !xAddVspMergeCand(3, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+      , iVSPDirTrue
+#endif
+      ) )
 #else
     if( iCount < 4 + extraMergeCand )
-        if ( !xAddVspMergeCand(3, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) )
+        if ( !xAddVspMergeCand(3, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
+#if MERL_VSP_NBDV_RefVId_Fix_D0166
+          , iVSPDirTrue
+#endif   
+          ) )
 #endif
             return;
@@ -4636,9 +4707,9 @@
   if( iCount < 4 + extraMergeCand )
 #if LGE_VSP_INHERIT_D0092
-    if ( !xAddVspMergeCand(5, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo) 
+    if ( !xAddVspMergeCand(5, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
 #if MERL_VSP_NBDV_RefVId_Fix_D0166
          , iVSPDirTrue
 #endif
-)
+))
 #else
     if ( !xAddVspMergeCand(5, 1, bVspMvZeroDone, uiDepth, abCandIsInter, iCount, puhInterDirNeighbours, pcMvFieldNeighbours, iVSPIndexTrue, mrgCandIdx, &cDisInfo
@@ -4646,5 +4717,5 @@
          , iVSPDirTrue
 #endif
-            ) 
+            )) 
 #endif
       return;
@@ -5606,4 +5677,6 @@
 #endif
 #endif
+#else
+          picDepth = getSlice()->getRefPicBaseDepth();
 #endif
 
Index: branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TComPrediction.cpp	(revision 432)
+++ branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TComPrediction.cpp	(revision 441)
@@ -821,13 +821,25 @@
 
 #else // MERL_VSP_NBDV_RefVId_Fix_D0166
-
+   // Step 1: get depth reference
+#if QC_BVSP_CleanUP_D0191
+  RefPicList privateRefPicList = REF_PIC_LIST_0;
+  Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
+  Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
+  privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
+  if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1== NOT_VALID )
+  {
+    assert(0);
+  }
+  Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
+  Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
+  Int refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, privateRefIdx);
+#else
   //recover VSP reference frame according to negative refIdx number
   RefPicList privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
   assert(privateRefPicList == REF_PIC_LIST_0 || privateRefPicList == REF_PIC_LIST_1);
-
-  // Step 1: get depth reference
   Int  refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr ); // texture ref index, a trick when storing refIdx
   Int  viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);  // texture view id
   Int  refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, refIdx);     // texture POC
+#endif
   TComPic* pRefPicBaseDepth = pcCU->getSlice()->getDepthRefPic(viewId, refPoc);
 
@@ -873,7 +885,20 @@
 TComPic*  TComPrediction::xGetVspRefTxt(TComDataCU* pcCU, UInt uiPartAddr, RefPicList eRefPicList)
 {
+#if QC_BVSP_CleanUP_D0191
+  RefPicList privateRefPicList = REF_PIC_LIST_0;
+  Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
+  Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
+  privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
+  if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1==NOT_VALID )
+  {
+    assert(0);
+  }
+  Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
+  Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
+#else
   RefPicList  privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
   Int         refIdx = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr ); // texture ref index, a trick when storing refIdx
   Int         viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);  // texture view id
+#endif
   TComPic*    refPic = NULL;
 
@@ -882,5 +907,9 @@
   if (privateRefPicList == eRefPicList)
   {
+#if QC_BVSP_CleanUP_D0191
+    Int  refIdxt = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
+#else
     Int  refIdxt = -1-pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
+#endif
     assert(refIdxt>= 0);
     refPic = pcCU->getSlice()->getRefPic(eRefPicList, refIdxt);
@@ -904,5 +933,9 @@
     if (isFound == false)
     {
+#if QC_BVSP_CleanUP_D0191
+      Int  refIdxTxt = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
+#else
       Int  refIdxTxt = -1-pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
+#endif
       assert(refIdxTxt >= 0);
       refPic = pcCU->getSlice()->getRefPic(privateRefPicList, refIdxTxt);
@@ -1227,4 +1260,7 @@
   Bool biDecision = 0;
   Int  predDirVSP = 0;
+#if QC_BVSP_CleanUP_D0191
+  RefPicList privateRefPicList = REF_PIC_LIST_0;
+#endif
   if (pcCU->getVSPIndex(uiPartAddr) != 0) // is VSP
   {
@@ -1232,4 +1268,18 @@
     //test whether VSP is Bi or Uni
     //Step1. Get derived DV view id
+#if QC_BVSP_CleanUP_D0191
+    RefPicList otherRefPicList = REF_PIC_LIST_1;
+    Int refIdxList0 = pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr );
+    Int refIdxList1 = pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr );
+    privateRefPicList = refIdxList0 != NOT_VALID ? REF_PIC_LIST_0 : REF_PIC_LIST_1;
+    if(privateRefPicList == REF_PIC_LIST_1 && refIdxList1==NOT_VALID )
+    {
+      assert(0);
+    }
+    Int privateRefIdx = privateRefPicList == REF_PIC_LIST_0 ? refIdxList0 : refIdxList1;
+    Int viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, privateRefIdx);
+    Int refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, privateRefIdx);
+#else
+    Int  refIdx = pcCU->getCUMvField( privateRefPicList )->getRefIdx( uiPartAddr );
     RefPicList privateRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
     RefPicList otherRefPicList = privateRefPicList == REF_PIC_LIST_0 ? REF_PIC_LIST_1 : REF_PIC_LIST_0;
@@ -1239,5 +1289,5 @@
     Int  viewId = pcCU->getSlice()->getRefViewId(privateRefPicList, refIdx);
     Int  refPoc = pcCU->getSlice()->getRefPOC(privateRefPicList, refIdx);
-
+#endif
     assert(refPoc == pcCU->getSlice()->getPOC());
 //    if(refPoc != pcCU->getSlice()->getPOC() )
@@ -1308,5 +1358,9 @@
 #else
       //Reference list loop termination
+#if QC_BVSP_CleanUP_D0191
+      RefPicList privateVSPRefPicList = privateRefPicList;
+#else
       RefPicList privateVSPRefPicList = (RefPicList) pcCU->getVSPDir( uiPartAddr );
+#endif
       if( (pcCU->getVSPIndex(uiPartAddr)!=0) &&  iRefList != privateVSPRefPicList && !biDecision  ) 
       {//when VSP mode, if it is uni prediction, the other reference list should skip
Index: branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TypeDef.h	(revision 432)
+++ branches/HTM-6.2-dev0-Fix/source/Lib/TLibCommon/TypeDef.h	(revision 441)
@@ -209,5 +209,5 @@
 
 
-#define MERL_General_Fix                     0 // General fix by MERL
+#define MERL_General_Fix                     1// General fix by MERL
 #define MERL_VSP_C0152_BugFix_ForNoDepthCase 1 // MERL bugfix for test condition of no depth
 #define QC_BVSP_CleanUP_D0191                    1
Index: branches/HTM-6.2-dev0-Fix/source/Lib/TLibDecoder/TDecCu.cpp
===================================================================
--- branches/HTM-6.2-dev0-Fix/source/Lib/TLibDecoder/TDecCu.cpp	(revision 432)
+++ branches/HTM-6.2-dev0-Fix/source/Lib/TLibDecoder/TDecCu.cpp	(revision 441)
@@ -458,5 +458,5 @@
       pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, 0, uiDepth );  // Initialize
 #if MERL_VSP_NBDV_RefVId_Fix_D0166
-      pcCU->setVSPDirSubParts( iVSPDirTrue[iVSPIdx-1], uiAbsPartIdx, 0, uiDepth );
+      pcCU->setVSPDirSubParts( 0, uiAbsPartIdx, 0, uiDepth );
 #endif
 #if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
Index: branches/HTM-6.2-dev0-Fix/source/Lib/TLibDecoder/TDecEntropy.cpp
===================================================================
--- branches/HTM-6.2-dev0-Fix/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 432)
+++ branches/HTM-6.2-dev0-Fix/source/Lib/TLibDecoder/TDecEntropy.cpp	(revision 441)
@@ -380,5 +380,5 @@
         pcCU->setVSPIndexSubParts( iVSPIdx, uiSubPartIdx, uiPartIdx, uiDepth );               // Initialize
 #if MERL_VSP_NBDV_RefVId_Fix_D0166
-        pcCU->setVSPDirSubParts( iVSPDirTrue[iVSPIdx-1], uiSubPartIdx, uiPartIdx, uiDepth );  // Initialize
+        pcCU->setVSPDirSubParts( 0, uiSubPartIdx, uiPartIdx, uiDepth );  // Initialize
 #endif
 #if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
Index: branches/HTM-6.2-dev0-Fix/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/HTM-6.2-dev0-Fix/source/Lib/TLibEncoder/TEncCu.cpp	(revision 432)
+++ branches/HTM-6.2-dev0-Fix/source/Lib/TLibEncoder/TEncCu.cpp	(revision 441)
@@ -2054,5 +2054,5 @@
             rpcTempCU->setVSPIndexSubParts( iVSPIdx, 0, 0, uhDepth );
 #if MERL_VSP_NBDV_RefVId_Fix_D0166
-            rpcTempCU->setVSPDirSubParts( iVSPDirTrue[iVSPIdx-1], 0, 0, uhDepth ); // interprets depth relative to LCU level
+            rpcTempCU->setVSPDirSubParts(0, 0, 0, uhDepth ); // interprets depth relative to LCU level
 #endif
 #if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
Index: branches/HTM-6.2-dev0-Fix/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/HTM-6.2-dev0-Fix/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 432)
+++ branches/HTM-6.2-dev0-Fix/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 441)
@@ -3030,5 +3030,5 @@
         pcCU->setVSPIndexSubParts( iVSPIdx, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
 #if MERL_VSP_NBDV_RefVId_Fix_D0166
-        pcCU->setVSPDirSubParts( iVSPDirTrue[iVSPIdx-1], uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
+        pcCU->setVSPDirSubParts(0, uiAbsPartIdx, iPUIdx, pcCU->getDepth( uiAbsPartIdx ) );
 #endif
 #if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
@@ -3794,5 +3794,5 @@
           pcCU->setVSPIndexSubParts( iVSPIdx, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
 #if MERL_VSP_NBDV_RefVId_Fix_D0166
-          pcCU->setVSPDirSubParts( iVSPDirTrue[iVSPIdx-1], uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+          pcCU->setVSPDirSubParts( 0, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
 #endif
 #if QC_BVSP_CleanUP_D0191 && !LGE_VSP_INHERIT_D0092
