Index: branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 282)
@@ -153,4 +153,12 @@
     }
   }
+
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    if( m_acLayerCfg[layer].m_numActiveRefLayers > 0 )
+    {
+      delete [] m_acLayerCfg[layer].m_predLayerIds;
+    }
+  }
 #endif
 }
@@ -329,6 +337,10 @@
 #if VPS_EXTN_DIRECT_REF_LAYERS
   Int*    cfg_numDirectRefLayers [MAX_LAYERS];
-  string cfg_refLayerIds   [MAX_LAYERS];
-  string* cfg_refLayerIdsPtr   [MAX_LAYERS];
+  string  cfg_refLayerIds        [MAX_LAYERS];
+  string* cfg_refLayerIdsPtr     [MAX_LAYERS];
+
+  Int*    cfg_numActiveRefLayers [MAX_LAYERS];
+  string  cfg_predLayerIds       [MAX_LAYERS];
+  string* cfg_predLayerIdsPtr    [MAX_LAYERS];
 #endif
 #if SCALED_REF_LAYER_OFFSETS
@@ -360,4 +372,6 @@
     cfg_numDirectRefLayers  [layer] = &m_acLayerCfg[layer].m_numDirectRefLayers;
     cfg_refLayerIdsPtr      [layer]  = &cfg_refLayerIds[layer];
+    cfg_numActiveRefLayers  [layer] = &m_acLayerCfg[layer].m_numActiveRefLayers;
+    cfg_predLayerIdsPtr     [layer]  = &cfg_predLayerIds[layer];
 #endif
 #if SCALED_REF_LAYER_OFFSETS
@@ -422,4 +436,6 @@
   ("NumDirectRefLayers%d",    cfg_numDirectRefLayers, -1, MAX_LAYERS, "Number of direct reference layers")
   ("RefLayerIds%d",           cfg_refLayerIdsPtr, string(""), MAX_LAYERS, "direct reference layer IDs")
+  ("NumActiveRefLayers%d",    cfg_numActiveRefLayers, -1, MAX_LAYERS, "Number of active reference layers")
+  ("PredLayerIds%d",          cfg_predLayerIdsPtr, string(""), MAX_LAYERS, "inter-layer prediction layer IDs")
 #endif
   ("NumLayers",               m_numLayers, 1, "Number of layers to code")
@@ -890,5 +906,5 @@
         if( i >= m_acLayerCfg[layer].m_numDirectRefLayers )
         {
-          printf( "The number of columns whose width are defined is larger than the allowed number of columns.\n" );
+          printf( "NumDirectRefLayers: The number of columns whose width are defined is larger than the allowed number of columns.\n" );
           exit( EXIT_FAILURE );
         }
@@ -899,5 +915,5 @@
       if( i < m_acLayerCfg[layer].m_numDirectRefLayers )
       {
-        printf( "The width of some columns is not defined.\n" );
+        printf( "NumDirectRefLayers: The width of some columns is not defined.\n" );
         exit( EXIT_FAILURE );
       }
@@ -906,4 +922,36 @@
     {
       m_acLayerCfg[layer].m_refLayerIds = NULL;
+    }
+  }
+
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    Char* pPredLayerIds = cfg_predLayerIds[layer].empty() ? NULL: strdup(cfg_predLayerIds[layer].c_str());
+    if( m_acLayerCfg[layer].m_numActiveRefLayers > 0 )
+    {
+      char *refLayerId;
+      int  i=0;
+      m_acLayerCfg[layer].m_predLayerIds = new Int[m_acLayerCfg[layer].m_numActiveRefLayers];
+      refLayerId = strtok(pPredLayerIds, " ,-");
+      while(refLayerId != NULL)
+      {
+        if( i >= m_acLayerCfg[layer].m_numActiveRefLayers )
+        {
+          printf( "NumActiveRefLayers: The number of columns whose width are defined is larger than the allowed number of columns.\n" );
+          exit( EXIT_FAILURE );
+        }
+        *( m_acLayerCfg[layer].m_predLayerIds + i ) = atoi( refLayerId );
+        refLayerId = strtok(NULL, " ,-");
+        i++;
+      }
+      if( i < m_acLayerCfg[layer].m_numActiveRefLayers )
+      {
+        printf( "NumActiveRefLayers: The width of some columns is not defined.\n" );
+        exit( EXIT_FAILURE );
+      }
+    }
+    else
+    {
+      m_acLayerCfg[layer].m_predLayerIds = NULL;
     }
   }
@@ -1840,4 +1888,15 @@
     }
   }
+
+  xConfirmPara( (m_acLayerCfg[0].m_numActiveRefLayers != 0) && (m_acLayerCfg[0].m_numActiveRefLayers != -1), "Layer 0 cannot have any active reference layers" );
+  // NOTE: m_numActiveRefLayers  (for any layer) could be -1 (not signalled in cfg), in which case only the "previous layer" would be taken for reference
+  for(Int layer = 1; layer < MAX_LAYERS; layer++)
+  {
+    xConfirmPara(m_acLayerCfg[layer].m_numActiveRefLayers > m_acLayerCfg[layer].m_numDirectRefLayers, "Cannot reference more layers than NumDirectRefLayers");
+    for(Int i = 0; i < m_acLayerCfg[layer].m_numActiveRefLayers; i++)
+    {
+      xConfirmPara(m_acLayerCfg[layer].m_predLayerIds[i] > m_acLayerCfg[layer].m_numDirectRefLayers, "Cannot reference higher layers");
+    }
+  }
 #endif
 #undef xConfirmPara
Index: branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 258)
+++ branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 282)
@@ -45,4 +45,6 @@
   Int       *m_refLayerIds;
   Int       m_numDirectRefLayers;
+  Int       *m_predLayerIds;
+  Int       m_numActiveRefLayers;
 #endif
 
@@ -108,4 +110,8 @@
   Int*    getRefLayerIds()            {return m_refLayerIds;      }
   Int     getRefLayerId(Int i)        {return m_refLayerIds[i];   }
+
+  Int     getNumActiveRefLayers()     {return m_numActiveRefLayers;}
+  Int*    getPredLayerIds()           {return m_predLayerIds;     }
+  Int     getPredLayerId(Int i)       {return m_predLayerIds[i];  }
 #endif
 #if RC_SHVC_HARMONIZATION
Index: branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/App/TAppEncoder/TAppEncTop.cpp	(revision 282)
@@ -159,5 +159,22 @@
         {
           m_acTEncTop[layer].setRefLayerId             ( i, m_acLayerCfg[layer].getRefLayerId(i));
-        }        
+        }
+      }
+
+      if(m_acLayerCfg[layer].getNumActiveRefLayers() == -1)
+      {
+        m_acTEncTop[layer].setNumActiveRefLayers( m_acLayerCfg[layer].getNumDirectRefLayers() );
+        for( Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++ )
+        {
+          m_acTEncTop[layer].setPredLayerId(i, i);
+        }
+      }
+      else
+      {
+        m_acTEncTop[layer].setNumActiveRefLayers       ( m_acLayerCfg[layer].getNumActiveRefLayers() );      
+        for(Int i = 0; i < m_acTEncTop[layer].getNumActiveRefLayers(); i++)
+        {
+          m_acTEncTop[layer].setPredLayerId             ( i, m_acLayerCfg[layer].getPredLayerId(i));
+        }
       }
     }
@@ -886,5 +903,5 @@
   vps->setNumProfileTierLevel(vps->getNumLayerSets());   
   vps->setDefaultOneTargetOutputLayerFlag(true);
-  for(Int i = 1; i < vps->getNumLayerSets(); i++)
+  for(i = 1; i < vps->getNumLayerSets(); i++)
   {
     vps->setProfileLevelTierIdx(i, i);
@@ -910,7 +927,10 @@
 #if VPS_EXTN_DIRECT_REF_LAYERS
   // Direct reference layers
+  UInt maxDirectRefLayers = 0;
   for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
   {
     vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() );
+    maxDirectRefLayers = max<UInt>( maxDirectRefLayers, vps->getNumDirectRefLayers( layerCtr ) );
+
     for(i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
     {
@@ -930,5 +950,5 @@
 #endif
 #if JCTVC_M0458_INTERLAYER_RPS_SIG        
-    vps->setMaxOneActiveRefLayerFlag(true); 
+    vps->setMaxOneActiveRefLayerFlag(maxDirectRefLayers > 1 ? false : true); 
 #endif 
 #else
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComDataCU.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComDataCU.cpp	(revision 282)
@@ -1750,8 +1750,11 @@
   // check BL mode
   UInt          uiCUAddrBase, uiAbsPartAddrBase;
-  TComDataCU*   pcTempCU = getBaseColCU( uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
+  // the right reference layerIdc should be specified, currently it is set to m_layerId-1
+  TComDataCU*   pcTempCU = getBaseColCU(m_layerId - 1, uiAbsPartIdx, uiCUAddrBase, uiAbsPartAddrBase );
 
   if( pcTempCU->getPredictionMode( uiAbsPartAddrBase ) != MODE_INTRA )
+  {
     return( NUM_INTRA_MODE-1 );
+  }
 
   // compute set of enabled modes g_reducedSetIntraModes[...]
@@ -4182,5 +4185,5 @@
 
 #if SVC_COL_BLK
-TComDataCU*  TComDataCU::getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
 {
 #if 1 // it should provide identical resutls
@@ -4188,5 +4191,5 @@
   UInt uiPelY = getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiCuAbsPartIdx] ];
 
-  return getBaseColCU( uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
+  return getBaseColCU( refLayerIdc, uiPelX, uiPelY, uiCUAddrBase, uiAbsPartIdxBase );
 #else
   TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
@@ -4237,7 +4240,7 @@
 }
 
-TComDataCU*  TComDataCU::getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
-{
-  TComPic* cBaseColPic = m_pcSlice->getBaseColPic();
+TComDataCU*  TComDataCU::getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase )
+{
+  TComPic* cBaseColPic = m_pcSlice->getBaseColPic(refLayerIdc);
 
 #if !SIMPLIFIED_MV_POS_SCALING
@@ -4269,9 +4272,9 @@
   Int leftStartL = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowLeftOffset();
   Int topStartL  = this->getSlice()->getSPS()->getScaledRefLayerWindow().getWindowTopOffset();
-  Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[m_layerId][0] + (1<<15)) >> 16;
-  Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
+  Int iBX = ((uiPelX - leftStartL)*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
+  Int iBY = ((uiPelY - topStartL )*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
 #else
-  Int iBX = (uiPelX*g_posScalingFactor[m_layerId][0] + (1<<15)) >> 16;
-  Int iBY = (uiPelY*g_posScalingFactor[m_layerId][1] + (1<<15)) >> 16;
+  Int iBX = (uiPelX*g_posScalingFactor[refLayerIdc][0] + (1<<15)) >> 16;
+  Int iBY = (uiPelY*g_posScalingFactor[refLayerIdc][1] + (1<<15)) >> 16;
 #endif
 #else
@@ -4295,6 +4298,6 @@
   const Window &confEL = m_pcPic->getPicYuvRec()->getConformanceWindow();
 
-  Int widthBL   = m_pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-  Int heightBL  = m_pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+  Int widthBL   = m_pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+  Int heightBL  = m_pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
 #endif
   if( iBX >= widthBL || iBY >= heightBL ) //outside of the reference layer cropped picture
@@ -4316,10 +4319,10 @@
 }
 
-Void TComDataCU::scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase )
+Void TComDataCU::scaleBaseMV( UInt refLayerIdc, TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase )
 {
   TComMvField cMvFieldBase;
   TComMv cMv;
 #if SIMPLIFIED_MV_POS_SCALING
-  cMv = rcMvFieldBase.getMv().scaleMv( g_mvScalingFactor[m_layerId][0], g_mvScalingFactor[m_layerId][1] );
+  cMv = rcMvFieldBase.getMv().scaleMv( g_mvScalingFactor[refLayerIdc][0], g_mvScalingFactor[refLayerIdc][1] );
 #else
   const Window &confBL = m_pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComDataCU.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComDataCU.h	(revision 282)
@@ -554,7 +554,7 @@
 
 #if SVC_COL_BLK 
-  TComDataCU*   getBaseColCU( UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
-  TComDataCU*   getBaseColCU( UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
-  Void          scaleBaseMV( TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiCuAbsPartIdx, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
+  TComDataCU*   getBaseColCU( UInt refLayerIdc, UInt uiPelX, UInt uiPelY, UInt &uiCUAddrBase, UInt &uiAbsPartIdxBase );
+  Void          scaleBaseMV( UInt refLayerIdc, TComMvField& rcMvFieldEnhance, TComMvField& rcMvFieldBase );
 #endif
 };
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 282)
@@ -67,9 +67,9 @@
 , m_pNDBFilterYuvTmp                      (NULL)
 , m_bCheckLTMSB                           (false)
+{
 #if SVC_EXTENSION
-, m_bSpatialEnhLayer( false )
-, m_pcFullPelBaseRec( NULL )
-#endif
-{
+  memset( m_pcFullPelBaseRec, 0, sizeof( m_pcFullPelBaseRec ) );
+  memset( m_bSpatialEnhLayer, false, sizeof( m_bSpatialEnhLayer ) );
+#endif
   m_apcPicYuv[0]      = NULL;
   m_apcPicYuv[1]      = NULL;
@@ -91,7 +91,10 @@
   m_apcPicYuv[1]  = new TComPicYuv;  m_apcPicYuv[1]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
 
-  if (m_bSpatialEnhLayer)
-  {
-    m_pcFullPelBaseRec = new TComPicYuv;  m_pcFullPelBaseRec->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+  for( Int i = 0; i < MAX_LAYERS; i++ )
+  {
+    if( m_bSpatialEnhLayer[i] )
+    {
+      m_pcFullPelBaseRec[i] = new TComPicYuv;  m_pcFullPelBaseRec[i]->create( iWidth, iHeight, uiMaxWidth, uiMaxHeight, uiMaxDepth, pcSps );
+    }
   }
 
@@ -173,9 +176,12 @@
   deleteSEIs(m_SEIs);
 #if SVC_EXTENSION && SVC_UPSAMPLING
-  if (m_bSpatialEnhLayer)
-  {
-    m_pcFullPelBaseRec->destroy();
-    delete m_pcFullPelBaseRec;
-    m_pcFullPelBaseRec  = NULL;
+  for( Int i = 0; i < MAX_LAYERS; i++ )
+  {
+    if( m_bSpatialEnhLayer[i] )
+    {
+      m_pcFullPelBaseRec[i]->destroy();
+      delete m_pcFullPelBaseRec[i];
+      m_pcFullPelBaseRec[i]  = NULL;
+    }
   }
 #endif 
@@ -562,5 +568,5 @@
 
 #if REF_IDX_MFM
-Void TComPic::copyUpsampledMvField(TComPic* pcPicBase)
+Void TComPic::copyUpsampledMvField(UInt refLayerIdc, TComPic* pcPicBase)
 {
 #if AVC_SYNTAX && !ILP_DECODED_PICTURE
@@ -592,5 +598,5 @@
 
       TComDataCU *pcColCU = 0;
-      pcColCU = pcCUDes->getBaseColCU(pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx);
+      pcColCU = pcCUDes->getBaseColCU(refLayerIdc, pelX + 8, pelY + 8, baseCUAddr, baseAbsPartIdx);
 
 #if AVC_SYNTAX && !ILP_DECODED_PICTURE
@@ -607,5 +613,5 @@
           TComMvField sMvFieldBase, sMvField;
           pcColCU->getMvField( pcColCU, baseAbsPartIdx, (RefPicList)refPicList, sMvFieldBase);
-          pcCUDes->scaleBaseMV( sMvField, sMvFieldBase );
+          pcCUDes->scaleBaseMV( refLayerIdc, sMvField, sMvFieldBase );
 
           pcCUDes->getCUMvField((RefPicList)refPicList)->setMvField(sMvField, absPartIdx);
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPic.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPic.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPic.h	(revision 282)
@@ -92,6 +92,6 @@
   SEIMessages  m_SEIs; ///< Any SEI messages that have been received.  If !NULL we own the object.
 #if SVC_EXTENSION
-  Bool                  m_bSpatialEnhLayer;       // whether current layer is a spatial enhancement layer,
-  TComPicYuv*           m_pcFullPelBaseRec;    // upsampled base layer recontruction for difference domain inter prediction
+  Bool                  m_bSpatialEnhLayer[MAX_LAYERS];       // whether current layer is a spatial enhancement layer,
+  TComPicYuv*           m_pcFullPelBaseRec[MAX_LAYERS];    // upsampled base layer recontruction for difference domain inter prediction
 #endif
 
@@ -114,8 +114,8 @@
   Void          setLayerId (UInt layerId) { m_layerId = layerId; }
   UInt          getLayerId ()               { return m_layerId; }
-  Bool          isSpatialEnhLayer()             { return m_bSpatialEnhLayer; }
-  Void          setSpatialEnhLayerFlag (Bool b) { m_bSpatialEnhLayer = b; }
-  Void          setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
-  TComPicYuv*   getFullPelBaseRec   ()  { return  m_pcFullPelBaseRec;  }
+  Bool          isSpatialEnhLayer(UInt refLayerIdc)             { return m_bSpatialEnhLayer[refLayerIdc]; }
+  Void          setSpatialEnhLayerFlag (UInt refLayerIdc, Bool b) { m_bSpatialEnhLayer[refLayerIdc] = b; }
+  Void          setFullPelBaseRec   (UInt refLayerIdc, TComPicYuv* p) { m_pcFullPelBaseRec[refLayerIdc] = p; }
+  TComPicYuv*   getFullPelBaseRec   (UInt refLayerIdc)  { return  m_pcFullPelBaseRec[refLayerIdc];  }
 #endif
 #if REF_IDX_ME_ZEROMV || ENCODER_FAST_MODE || REF_IDX_MFM
@@ -124,5 +124,5 @@
 
 #if REF_IDX_MFM
-  Void          copyUpsampledMvField  (  TComPic* pcPicBase );
+  Void          copyUpsampledMvField  ( UInt refLayerIdc, TComPic* pcPicBase );
   Void          initUpsampledMvField  ();
 #endif
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPrediction.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPrediction.cpp	(revision 282)
@@ -774,12 +774,12 @@
 #if SVC_UPSAMPLING
 #if SCALED_REF_LAYER_OFFSETS
-Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
-{
-  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic, window);
+Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window)
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic, window);
 }
 #else
-Void TComPrediction::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
-{
-  m_cUsf.upsampleBasePic( pcUsPic, pcBasePic, pcTempPic);
+Void TComPrediction::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic)
+{
+  m_cUsf.upsampleBasePic( refLayerIdc, pcUsPic, pcBasePic, pcTempPic);
 }
 #endif
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPrediction.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPrediction.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComPrediction.h	(revision 282)
@@ -123,7 +123,7 @@
 #if SVC_UPSAMPLING
 #if SCALED_REF_LAYER_OFFSETS
-  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
 #else
-  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
 #endif
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComSlice.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComSlice.cpp	(revision 282)
@@ -92,5 +92,4 @@
 #if SVC_EXTENSION
 , m_layerId                     ( 0 )
-, m_pcBaseColPic                  ( NULL )
 #endif
 , m_bTLayerSwitchingFlag          ( false )
@@ -122,5 +121,7 @@
   m_aiNumRefIdx[0] = m_aiNumRefIdx[1] = m_aiNumRefIdx[2] = 0;
 #endif
-  
+
+#if SVC_EXTENSION
+  memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
 #if REF_IDX_FRAMEWORK
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -131,4 +132,5 @@
   m_numILRRefIdx = 0;
 #endif 
+#endif
 #endif
 
@@ -518,33 +520,37 @@
 
 #if REF_IDX_FRAMEWORK
-  //inter-layer reference picture
+  for( i = 0; i < m_activeNumILRRefIdx; i++ )
+  {
+    UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+    //inter-layer reference picture
 #if REF_IDX_MFM
 
 #if ILR_RESTR
-  Int maxSubLayerForILPPlus1 = (getLayerId() > 0 && m_activeNumILRRefIdx > 0)? getVPS()->getMaxSublayerForIlpPlus1(ilpPic[0]->getSlice(0)->getLayerId()) : 0;
+    Int maxSubLayerForILPPlus1 = ( m_layerId > 0 && m_activeNumILRRefIdx > 0)? m_pcVPS->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId()) : 0;
 #if ZERO_NUM_DIRECT_LAYERS
-  if( getLayerId() > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[0]->getSlice(0)->getTLayer())<=  maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[0]->getSlice(0)->getRapPicFlag()) )  ) 
-#else
-  if( getLayerId() && ( ( (Int)(ilpPic[0]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[0]->getSlice(0)->getRapPicFlag()) )  )
+    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=  maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  ) 
+#else
+    if( m_layerId > 0 && ( ( (Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )  )
 #endif
 
 #else
 #if ZERO_NUM_DIRECT_LAYERS
-  if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
-#else
-  if (getLayerId())
-#endif
-#endif
-  {
-    if(!(getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && getSPS()->getMFMEnabledFlag())
-    { 
-      ilpPic[0]->copyUpsampledMvField(getBaseColPic());
-    }
-    else
-    {
-      ilpPic[0]->initUpsampledMvField();
-    }
-  #endif
-    ilpPic[0]->setIsLongTerm(1);
+    if( m_layerId > 0 && m_activeNumILRRefIdx > 0 )
+#else
+    if( m_layerId > 0 )
+#endif
+#endif
+    {
+      if(!(m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) && m_pcSPS->getMFMEnabledFlag())
+      { 
+        ilpPic[refLayerIdc]->copyUpsampledMvField( refLayerIdc, m_pcBaseColPic[refLayerIdc] );
+      }
+      else
+      {
+        ilpPic[refLayerIdc]->initUpsampledMvField();
+      }
+#endif
+      ilpPic[refLayerIdc]->setIsLongTerm(1);
+    }
   }
 #endif
@@ -555,9 +561,9 @@
 #if ILR_RESTR
   Int numInterLayerRPSPics = 0;
-  if (getLayerId()>0)
-  {
-    for (i=0; i < getVPS()->getNumDirectRefLayers(getLayerId()); i++)
-    {
-      maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[i]->getSlice(0)->getLayerId());
+  if( m_layerId > 0 )
+  {
+    for( i=0; i < m_pcVPS->getNumDirectRefLayers( m_layerId ); i++ )
+    {
+      Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[i]->getSlice(0)->getLayerId());
       if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<= maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag() ) )
       {
@@ -570,6 +576,6 @@
       m_activeNumILRRefIdx = numInterLayerRPSPics;
     }
-#if MAX_ONE_RESAMPLING_DIRECT_LAYERS
-    if(getVPS()->getScalabilityMask(1))
+#if MAX_ONE_RESAMPLING_DIRECT_LAYERS && SIMPLIFIED_MV_POS_SCALING
+    if( m_pcVPS->getScalabilityMask(1) )
     {
       Int numResampler = 0;
@@ -581,12 +587,8 @@
                           );
 
-      Int widthEL   = getPic()->getPicYuvRec()->getWidth();
-      Int heightEL  = getPic()->getPicYuvRec()->getHeight();      
-      for (i=0; i < m_activeNumILRRefIdx; i++)
-      {
-        Int widthBL   =  ilpPic[getInterLayerPredLayerIdc(i)]->getSlice(0)->getBaseColPic()->getPicYuvRec()->getWidth();
-        Int heightBL  =  ilpPic[getInterLayerPredLayerIdc(i)]->getSlice(0)->getBaseColPic()->getPicYuvRec()->getHeight();
-
-        if(!(widthEL == widthBL && heightEL == heightBL && (scalingOffset)))
+      for( i=0; i < m_activeNumILRRefIdx; i++ )
+      {
+        UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+        if(!( g_posScalingFactor[refLayerIdc][0] == 65536 && g_posScalingFactor[refLayerIdc][1] == 65536 ) && (scalingOffset)) // ratio 1x
         {
           numResampler++;
@@ -660,5 +662,5 @@
     }
 #if REF_IDX_FRAMEWORK
-    if(getLayerId())
+    if( m_layerId > 0 )
     {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -668,9 +670,10 @@
 #endif 
       {
+        Int refLayerIdc = m_interLayerPredLayerIdc[i];
 #if ILR_RESTR
-         maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[i]->getSlice(0)->getLayerId());
-        if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag()) )
-#endif
-        rpsCurrList0[cIdx] = ilpPic[i];
+         Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
+#endif
+        rpsCurrList0[cIdx] = ilpPic[refLayerIdc];
       }
     }
@@ -692,5 +695,5 @@
     }
 #if REF_IDX_FRAMEWORK
-    if(getLayerId())
+    if( m_layerId > 0 )
     {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -700,9 +703,10 @@
 #endif 
       {
+        Int refLayerIdc = m_interLayerPredLayerIdc[i];
 #if ILR_RESTR
-        maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[i]->getSlice(0)->getLayerId());
-        if( ((Int)(ilpPic[i]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[i]->getSlice(0)->getRapPicFlag()) )
-#endif
-        rpsCurrList1[cIdx] = ilpPic[i];
+        Int maxSubLayerForILPPlus1 = getVPS()->getMaxSublayerForIlpPlus1(ilpPic[refLayerIdc]->getSlice(0)->getLayerId());
+        if( ((Int)(ilpPic[refLayerIdc]->getSlice(0)->getTLayer())<=maxSubLayerForILPPlus1-1) || (maxSubLayerForILPPlus1==0 && ilpPic[refLayerIdc]->getSlice(0)->getRapPicFlag()) )
+#endif
+        rpsCurrList1[cIdx] = ilpPic[refLayerIdc];
       }
     }
@@ -737,15 +741,15 @@
 Void TComSlice::setRefPicListModificationSvc()
 {
-  if( !this->getPPS()->getListsModificationPresentFlag()) 
+  if( !m_pcPPS->getListsModificationPresentFlag()) 
   {
     return;
   }
 
-  if(this->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && this->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA)
+  if(m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP && m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA)
   {
     return;
   }
 
-  TComRefPicListModification* refPicListModification = this->getRefPicListModification();
+  TComRefPicListModification* refPicListModification = &m_RefPicListModification;
   Int numberOfRpsCurrTempList = this->getNumRpsCurrTempList();  // total number of ref pics in listTemp0 including inter-layer ref pics
 
@@ -821,7 +825,7 @@
 
 #if REF_IDX_FRAMEWORK
-  if( m_eSliceType == I_SLICE || ( getSPS()->getLayerId() && 
-    (getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
-    (getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) ) )
+  if( m_eSliceType == I_SLICE || ( m_pcSPS->getLayerId() && 
+    (m_eNalUnitType >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
+    (m_eNalUnitType <= NAL_UNIT_CODED_SLICE_CRA) ) )
 #else
   if (m_eSliceType == I_SLICE) 
@@ -846,5 +850,5 @@
   }
 #if REF_IDX_FRAMEWORK
-  if(getLayerId())
+  if( m_layerId > 0 )
   {
 #if JCTVC_M0458_INTERLAYER_RPS_SIG
@@ -2592,48 +2596,54 @@
 #endif
 
-Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt layerID )
+Void TComSlice::setBaseColPic(  TComList<TComPic*>& rcListPic, UInt refLayerIdc )
 {  
-  if (layerID == 0)
-  {
-    m_pcBaseColPic = NULL;
+  if(m_layerId == 0)
+  {
+    memset( m_pcBaseColPic, 0, sizeof( m_pcBaseColPic ) );
     return;
   }        
-  setBaseColPic(xGetRefPic(rcListPic, getPOC())); 
+  setBaseColPic(refLayerIdc, xGetRefPic(rcListPic, getPOC())); 
 }
 #endif 
 
 #if REF_IDX_MFM
-Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic *pcRefPicBL )
-{
-  //set reference picture POC of each ILP reference 
-  Int thePoc = ilpPic[0]->getPOC(); 
-  assert(thePoc >= 0); 
-  assert(thePoc == pcRefPicBL->getPOC());
-
-  ilpPic[0]->getSlice(0)->setBaseColPic( pcRefPicBL );
-
-  //copy reference pictures marking from the reference layer
-  ilpPic[0]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
-  
-  for( Int refList = 0; refList < 2; refList++ )
-  {
-    RefPicList refPicList = RefPicList( refList );
-    
-    //set reference POC of ILP
-    ilpPic[0]->getSlice(0)->setNumRefIdx(refPicList, pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList));
-    assert(ilpPic[0]->getSlice(0)->getNumRefIdx(refPicList) >= 0);
-    assert(ilpPic[0]->getSlice(0)->getNumRefIdx(refPicList) <= MAX_NUM_REF);
-
-    //initialize reference POC of ILP
-    for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx++)
-    {
-      ilpPic[0]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(refPicList, refIdx), refPicList, refIdx);
-      ilpPic[0]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(refPicList, refIdx), refPicList, refIdx);
-    }
-
-    for(Int refIdx = pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx < MAX_NUM_REF; refIdx++) 
-    { 
-      ilpPic[0]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
-      ilpPic[0]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
+Void TComSlice::setRefPOCListILP( TComPic** ilpPic, TComPic** pcRefPicRL )
+{
+  for( UInt i = 0; i < m_activeNumILRRefIdx; i++ )
+  {
+    UInt refLayerIdc = m_interLayerPredLayerIdc[i];
+
+    TComPic* pcRefPicBL = pcRefPicRL[refLayerIdc];
+    //set reference picture POC of each ILP reference 
+    Int thePoc = ilpPic[refLayerIdc]->getPOC(); 
+    assert(thePoc >= 0); 
+    assert(thePoc == pcRefPicBL->getPOC());
+
+    ilpPic[refLayerIdc]->getSlice(0)->setBaseColPic( refLayerIdc, pcRefPicBL );
+
+    //copy reference pictures marking from the reference layer
+    ilpPic[refLayerIdc]->getSlice(0)->copySliceInfo(pcRefPicBL->getSlice(0));
+
+    for( Int refList = 0; refList < 2; refList++ )
+    {
+      RefPicList refPicList = RefPicList( refList );
+
+      //set reference POC of ILP
+      ilpPic[refLayerIdc]->getSlice(0)->setNumRefIdx(refPicList, pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList));
+      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) >= 0);
+      assert(ilpPic[refLayerIdc]->getSlice(0)->getNumRefIdx(refPicList) <= MAX_NUM_REF);
+
+      //initialize reference POC of ILP
+      for(Int refIdx = 0; refIdx < pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx++)
+      {
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(pcRefPicBL->getSlice(0)->getRefPOC(refPicList, refIdx), refPicList, refIdx);
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(pcRefPicBL->getSlice(0)->getRefPic(refPicList, refIdx), refPicList, refIdx);
+      }
+
+      for(Int refIdx = pcRefPicBL->getSlice(0)->getNumRefIdx(refPicList); refIdx < MAX_NUM_REF; refIdx++) 
+      { 
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPOC(0, refPicList, refIdx); 
+        ilpPic[refLayerIdc]->getSlice(0)->setRefPic(NULL, refPicList, refIdx); 
+      }
     }
   }
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComSlice.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComSlice.h	(revision 282)
@@ -1494,6 +1494,6 @@
 #if SVC_EXTENSION
   UInt        m_layerId;
-  TComPic*    m_pcBaseColPic;
-  TComPicYuv* m_pcFullPelBaseRec;
+  TComPic*    m_pcBaseColPic[MAX_LAYERS];
+  TComPicYuv* m_pcFullPelBaseRec[MAX_LAYERS];
 #endif 
   Bool        m_bTLayerSwitchingFlag;
@@ -1775,13 +1775,14 @@
 
 #if SVC_EXTENSION
-  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt layerID );
-  Void      setBaseColPic       ( TComPic* p)     { m_pcBaseColPic = p; }
-  TComPic*  getBaseColPic       ()                { return m_pcBaseColPic; }
+  Void      setBaseColPic       ( TComList<TComPic*>& rcListPic , UInt refLayerIdc );
+  Void      setBaseColPic       (UInt refLayerIdc, TComPic* p)     { m_pcBaseColPic[refLayerIdc] = p; }
+  TComPic*  getBaseColPic       (UInt refLayerIdc)                { return m_pcBaseColPic[refLayerIdc]; }
+  TComPic** getBaseColPic       ()                { return &m_pcBaseColPic[0]; }
 
   Void      setLayerId (UInt layerId)   { m_layerId = layerId; }
   UInt      getLayerId ()               { return m_layerId;    }
 
-  Void        setFullPelBaseRec   ( TComPicYuv* p) { m_pcFullPelBaseRec = p; }
-  TComPicYuv* getFullPelBaseRec   ()               { return  m_pcFullPelBaseRec;  }
+  Void        setFullPelBaseRec   (UInt refLayerIdc, TComPicYuv* p) { m_pcFullPelBaseRec[refLayerIdc] = p; }
+  TComPicYuv* getFullPelBaseRec   (UInt refLayerIdc)               { return  m_pcFullPelBaseRec[refLayerIdc];  }
 
 #if AVC_SYNTAX
@@ -1794,5 +1795,5 @@
 
 #if REF_IDX_MFM
-  Void      setRefPOCListILP(TComPic** ilpPic, TComPic *pcRefPicBL);
+  Void      setRefPOCListILP(TComPic** ilpPic, TComPic** pcRefPicRL);
 #endif
 
@@ -1801,14 +1802,15 @@
   Void      setActiveNumILRRefIdx     ( Int i )         { m_activeNumILRRefIdx = i;     }  
 
-  Int       getInterLayerPredLayerIdc (UInt Idx )               { return  m_interLayerPredLayerIdc[Idx];}
-  Void      setInterLayerPredLayerIdc (UInt val, UInt Idx)      { m_interLayerPredLayerIdc[Idx] = val;  }
+  Int       getInterLayerPredLayerIdc (UInt layerIdx)                        { return  m_interLayerPredLayerIdc[layerIdx];}
+  Void      setInterLayerPredLayerIdc (UInt refLayerIdc, UInt layerIdx)      { m_interLayerPredLayerIdc[layerIdx] = refLayerIdc;  }
 
   Void      setInterLayerPredEnabledFlag     ( Bool   val )    { m_interLayerPredEnabledFlag = val; }
   Bool      getInterLayerPredEnabledFlag     ()                { return m_interLayerPredEnabledFlag;}
-
 #else
   Void      setNumILRRefIdx     ( Int i )               { m_numILRRefIdx = i;     }
 #endif 
 #endif
+
+TComPic* getRefPic(TComList<TComPic*>& rcListPic, Int poc) { return xGetRefPic( rcListPic, poc ); } 
 
 #endif //SVC_EXTENSION
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.cpp	(revision 282)
@@ -74,7 +74,7 @@
 
 #if SCALED_REF_LAYER_OFFSETS
-Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
-#else
-Void TComUpsampleFilter::upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
+Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window )
+#else
+Void TComUpsampleFilter::upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic )
 #endif
 {
@@ -127,5 +127,13 @@
   Pel* piDstV;
 
-  if( widthEL == widthBL && heightEL == heightBL )
+#if SIMPLIFIED_MV_POS_SCALING
+  Int scaleX = g_posScalingFactor[refLayerIdc][0];
+  Int scaleY = g_posScalingFactor[refLayerIdc][1];
+#else
+  Int   scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
+  Int   scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
+#endif
+
+  if( scaleX == 65536 && scaleY == 65536 ) // ratio 1x
   {
     piSrcY = piSrcBufY - scalEL.getWindowLeftOffset() - scalEL.getWindowTopOffset() * strideEL;
@@ -196,7 +204,4 @@
     Int shiftYM4 = shiftY - 4;
 
-    Int   scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
-    Int   scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
-
 #if ILP_DECODED_PICTURE
     widthEL   = pcUsPic->getWidth ();
@@ -334,6 +339,8 @@
     shiftYM4 = shiftY - 4;
 
+#if !SIMPLIFIED_MV_POS_SCALING
     scaleX     = ( ( widthBL << shiftX ) + ( widthEL >> 1 ) ) / widthEL;
     scaleY     = ( ( heightBL << shiftY ) + ( heightEL >> 1 ) ) / heightEL;
+#endif
 
 #if ILP_DECODED_PICTURE
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TComUpsampleFilter.h	(revision 282)
@@ -44,7 +44,7 @@
 
 #if SCALED_REF_LAYER_OFFSETS
-  Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
+  Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic, const Window window );
 #else
- Void upsampleBasePic( TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
+ Void upsampleBasePic( UInt refLayerIdc, TComPicYuv* pcUsPic, TComPicYuv* pcBasePic, TComPicYuv* pcTempPic );
 #endif
 };
Index: branches/SHM-2.1-dev/source/Lib/TLibCommon/TypeDef.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibCommon/TypeDef.h	(revision 282)
@@ -47,5 +47,5 @@
 #define SCALED_REF_LAYER_OFFSET_FLAG     1      ///< M0309: Signal scaled reference layer offsets in SPS
 #define SCALED_REF_LAYER_OFFSETS         1      ///< M0309: Signal scaled reference layer offsets in SPS
-#define MAX_LAYERS                       2      ///< max number of layers the codec is supposed to handle
+#define MAX_LAYERS                       3      ///< max number of layers the codec is supposed to handle
 
 #define VPS_RENAME                       1      ///< Rename variables max_layer_id and num_layer_sets_minus1 in VPS
Index: branches/SHM-2.1-dev/source/Lib/TLibDecoder/TDecTop.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibDecoder/TDecTop.cpp	(revision 282)
@@ -160,5 +160,5 @@
     if (m_cIlpPic[0] == NULL)
     {
-      for (Int j=0; j< 1/*MAX_NUM_REF*/; j++)  // to be set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
+      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++)  // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
       {
 
@@ -180,11 +180,16 @@
 Void TDecTop::setILRPic(TComPic *pcPic)
 {
-  if(m_cIlpPic[0])
-  {
-    m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
-    m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
-    m_cIlpPic[0]->setLayerId(pcPic->getSlice(0)->getBaseColPic()->getLayerId()); //set reference layerId
-    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
-    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
+  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
+  {
+    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
+
+    if(m_cIlpPic[refLayerIdc])
+    {
+      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
+      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
+      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
+      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
+      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
+    }
   }
 }
@@ -248,24 +253,30 @@
     if(m_layerId > 0)
     {
+      for(UInt i = 0; i < pcSlice->getVPS()->getNumDirectRefLayers( m_layerId ); i++ )
+      {
+        const Window scalEL = pcSlice->getSPS()->getScaledRefLayerWindow();
+        Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+
 #if VPS_EXTN_DIRECT_REF_LAYERS
-      TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( m_layerId - 1 );
-#else
-      TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
-#endif
-      //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
-      TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
-      if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() )
-      {
-        rpcPic->setSpatialEnhLayerFlag( true );
-
-        //only for scalable extension
-        assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
-      }
+        TDecTop *pcTDecTopBase = (TDecTop *)getRefLayerDec( i );
+#else
+        TDecTop *pcTDecTopBase = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
+        //TComPic*                      pcPic = *(pcTDecTopBase->getListPic()->begin()); 
+        TComPicYuv* pcPicYuvRecBase = (*(pcTDecTopBase->getListPic()->begin()))->getPicYuvRec(); 
+        if(pcPicYuvRecBase->getWidth() != pcSlice->getSPS()->getPicWidthInLumaSamples() || pcPicYuvRecBase->getHeight() != pcSlice->getSPS()->getPicHeightInLumaSamples() || !zeroOffsets )
+        {
+          rpcPic->setSpatialEnhLayerFlag( i, true );
+
+          //only for scalable extension
+          assert( pcSlice->getVPS()->getScalabilityMask(1) == true );
+        }
 #if MAX_ONE_RESAMPLING_DIRECT_LAYERS
-      if(pcSlice->getVPS()->getScalabilityMask(1))
-      {
-         pcSlice->setPic(rpcPic);
-      }
-#endif
+        if(pcSlice->getVPS()->getScalabilityMask(1))
+        {
+          pcSlice->setPic(rpcPic);
+        }
+#endif
+      }
     }
 #endif
@@ -812,86 +823,94 @@
     if(m_layerId > 0)
     {
+      for( i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+      {
+        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
 #if AVC_BASE
-      if( m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
-      {
-        pcSlice->setBaseColPic ( *m_ppcTDecTop[0]->getListPic()->begin() );
+        if( pcSlice->getVPS()->getRefLayerId( m_layerId, refLayerIdc ) == 0 && m_parameterSetManagerDecoder[0].getActiveVPS()->getAvcBaseLayerFlag() )
+        {
+          pcSlice->setBaseColPic ( refLayerIdc, *m_ppcTDecTop[0]->getListPic()->begin() );
 #if AVC_SYNTAX
-        TComPic* pBLPic = pcSlice->getBaseColPic();
-        if( pcSlice->getPOC() == 0 )
-        {
-          // initialize partition order.
-          UInt* piTmp = &g_auiZscanToRaster[0];
-          initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
-          initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
-        }      
-        pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
-        pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
-#endif
-      }
-      else
-      {
+          TComPic* pBLPic = pcSlice->getBaseColPic(refLayerIdc);
+          if( pcSlice->getPOC() == 0 )
+          {
+            // initialize partition order.
+            UInt* piTmp = &g_auiZscanToRaster[0];
+            initZscanToRaster( pBLPic->getPicSym()->getMaxDepth() + 1, 1, 0, piTmp );
+            initRasterToZscan( pBLPic->getPicSym()->getMaxCUWidth(), pBLPic->getPicSym()->getMaxCUHeight(), pBLPic->getPicSym()->getMaxDepth() + 1 );
+          }      
+          pBLPic->getSlice( 0 )->initBaseLayerRPL( pcSlice );
+          pBLPic->readBLSyntax( m_ppcTDecTop[0]->getBLSyntaxFile(), SYNTAX_BYTES );
+#endif
+        }
+        else
+        {
 #if VPS_EXTN_DIRECT_REF_LAYERS
-        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( m_layerId - 1 );
+          TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
+#else
+          TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
+#endif
+          TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
+          pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
+        }
+#else
+#if VPS_EXTN_DIRECT_REF_LAYERS
+        TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( refLayerIdc );
 #else
         TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
 #endif
         TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
-        pcSlice->setBaseColPic ( *cListPic, m_layerId );
-      }
-#else
-#if VPS_EXTN_DIRECT_REF_LAYERS
-      TDecTop *pcTDecTop = (TDecTop *)getRefLayerDec( m_layerId );
-#else
-      TDecTop *pcTDecTop = (TDecTop *)getLayerDec( m_layerId-1 );
-#endif
-      TComList<TComPic*> *cListPic = pcTDecTop->getListPic();
-      pcSlice->setBaseColPic ( *cListPic, m_layerId );
+        pcSlice->setBaseColPic ( *cListPic, refLayerIdc );
 #endif
 
 #if SIMPLIFIED_MV_POS_SCALING
 #if SCALED_REF_LAYER_OFFSETS
-      const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow();
-
-      Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth();
-      Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight();
-
-      Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
-      Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-#else
-      const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
-      const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
-
-      Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-      Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-      Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-      Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
-      g_mvScalingFactor[m_layerId][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
-      g_mvScalingFactor[m_layerId][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
-
-      g_posScalingFactor[m_layerId][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
-      g_posScalingFactor[m_layerId][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
+        const Window &scalEL = pcSlice->getSPS()->getScaledRefLayerWindow();
+
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
+#else
+        const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
+        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
+
+        Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+        Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#endif
+        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
+        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
+
+        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
+        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
 #endif
 
 #if SVC_UPSAMPLING
-      if ( pcPic->isSpatialEnhLayer())
-      {    
+        if( pcPic->isSpatialEnhLayer(refLayerIdc) )
+        {    
 #if SCALED_REF_LAYER_OFFSETS
-        m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() );
-#else
-        m_cPrediction.upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
-#endif
-      }
-      else
-      {
-        pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
-      }
-      pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
-#endif
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() );
+#else
+          m_cPrediction.upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
+#endif
+        }
+        else
+        {
+          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
+        }
+        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
+#endif
+      }
     }
 
 #if REF_IDX_FRAMEWORK
+#if ZERO_NUM_DIRECT_LAYERS
+    if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() )
+#else
     if(m_layerId > 0)
+#endif
     {
       setILRPic(pcPic);
@@ -1292,10 +1311,4 @@
 #endif
   }
-
-  // currently only one reference layer is supported
-  assert( vps->getNumDirectRefLayers( m_layerId ) == 1 );
-#if JCTVC_M0458_INTERLAYER_RPS_SIG
-  assert( vps->getMaxOneActiveRefLayerFlag() == 1 );
-#endif 
   
   return (TDecTop *)getLayerDec( vps->getRefLayerId( m_layerId, refLayerIdc ) );
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCavlc.cpp	(revision 282)
@@ -1067,5 +1067,5 @@
           if( !pcSlice->getVPS()->getMaxOneActiveRefLayerFlag()) 
           {
-            WRITE_CODE(pcSlice->getActiveNumILRRefIdx() - 1, numBits,"num_inter_layer_ref_pics_minus1");           
+            WRITE_CODE(pcSlice->getActiveNumILRRefIdx() - 1, numBits,"num_inter_layer_ref_pics_minus1");
           }       
           for(Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCfg.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCfg.h	(revision 282)
@@ -145,4 +145,7 @@
   Int       m_numDirectRefLayers;
   Int       m_refLayerId[MAX_VPS_LAYER_ID_PLUS1];
+
+  Int       m_numActiveRefLayers;
+  Int       m_predLayerId[MAX_VPS_LAYER_ID_PLUS1];
 #endif
   //======= Transform =============
@@ -405,4 +408,10 @@
   Int       getRefLayerId                   (Int i)                         { return m_refLayerId[i];           }
   Void      setRefLayerId                   (Int i, Int refLayerId)         { m_refLayerId[i] = refLayerId;     }
+
+  Int       getNumActiveRefLayers           ()                              { return m_numActiveRefLayers;      }
+  Void      setNumActiveRefLayers           (Int num)                       { m_numActiveRefLayers = num;       }
+
+  Int       getPredLayerId                  (Int i)                         { return m_predLayerId[i];          }
+  Void      setPredLayerId                  (Int i, Int refLayerId)         { m_predLayerId[i] = refLayerId;    }
 #endif
   //======== Transform =============
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCu.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCu.cpp	(revision 282)
@@ -108,4 +108,5 @@
   // initialize conversion matrix from partition index to pel
   initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );
+
 }
 
@@ -455,12 +456,11 @@
   {
 #if (ENCODER_FAST_MODE)
-    bool testInter = true;
+    Bool testInter = true;
     if (rpcBestCU->getLayerId() > 0)
     {
-      if (rpcBestCU->getSlice()->getBaseColPic()->getSlice(0)->getSliceType() == I_SLICE)
-      {
-        testInter = false;
-      }
-
+        if(pcSlice->getSliceType() == P_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx()) 
+            testInter = false; 
+        if(pcSlice->getSliceType() == B_SLICE && pcSlice->getNumRefIdx(REF_PIC_LIST_0) == pcSlice->getActiveNumILRRefIdx() && pcSlice->getNumRefIdx(REF_PIC_LIST_1) == pcSlice->getActiveNumILRRefIdx()) 
+            testInter = false;
     }
 #endif
@@ -767,11 +767,13 @@
       }
 #endif
-
 #if (ENCODER_FAST_MODE)
-        if(pcPic->getLayerId() > 0)
-        { 
-          xCheckRDCostILRUni( rpcBestCU, rpcTempCU); 
-          rpcTempCU->initEstData( uiDepth, iQP );
-       }
+      if(pcPic->getLayerId() > 0)
+      {
+        for(Int refLayer = 0; refLayer < pcSlice->getActiveNumILRRefIdx(); refLayer++)
+        {  
+           xCheckRDCostILRUni( rpcBestCU, rpcTempCU, pcSlice->getInterLayerPredLayerIdc(refLayer));
+           rpcTempCU->initEstData( uiDepth, iQP );
+        }
+      }
 #endif
 
@@ -1812,38 +1814,26 @@
 }
 #endif
-
 #if (ENCODER_FAST_MODE)
-Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU)
+Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU, UInt refLayerId)
 {
   UChar uhDepth = rpcTempCU->getDepth( 0 );
-
   rpcTempCU->setDepthSubParts( uhDepth, 0 );
-
 #if SKIP_FLAG
   rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth );
 #endif
-
   rpcTempCU->setPartSizeSubParts  ( SIZE_2Nx2N,  0, uhDepth );  //2Nx2N
   rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
   rpcTempCU->setCUTransquantBypassSubParts  ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth );
-
-  Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] );
-
+  Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], refLayerId );
   if(!exitILR)
   {
-    return;
-  }
-
+     return;
+  }
   m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false );
-
   rpcTempCU->getTotalCost()  = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() );
-
   xCheckDQP( rpcTempCU );
   xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
-
   return;
 }
 #endif
-
-
 //! \}
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCu.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCu.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncCu.h	(revision 282)
@@ -158,5 +158,5 @@
 #endif
 #if ENCODER_FAST_MODE
-  Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU );
+  Void  xCheckRDCostILRUni  ( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt refLayerId);
 #endif
   Void  xCheckDQP           ( TComDataCU*  pcCU );
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 282)
@@ -535,55 +535,54 @@
     if (m_layerId > 0)
     {
+      for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
+      {
+        UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
 #if VPS_EXTN_DIRECT_REF_LAYERS
-      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(m_layerId-1)->getListPic();
-#else
-      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
-#endif
-      pcSlice->setBaseColPic (*cListPic, m_layerId );
-      
+        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(refLayerIdc)->getListPic();
+#else
+        TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic();
+#endif
+        pcSlice->setBaseColPic( *cListPic, refLayerIdc );
+
 #if SIMPLIFIED_MV_POS_SCALING
 #if SCALED_REF_LAYER_OFFSETS
-      const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow();
-
-      Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth();
-      Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight();
-
-      Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
-      Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
-#else
-      const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow();
-      const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
-
-      Int widthBL   = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
-      Int heightBL  = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
-
-      Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
-      Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
-#endif
-      g_mvScalingFactor[m_layerId][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
-      g_mvScalingFactor[m_layerId][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
-
-      g_posScalingFactor[m_layerId][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
-      g_posScalingFactor[m_layerId][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
-#endif
-
-#if ZERO_NUM_DIRECT_LAYERS
-      if( pcSlice->getActiveNumILRRefIdx() )
-#endif
-      {
+        const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow();
+
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth()  - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset()  - scalEL.getWindowBottomOffset();
+#else
+        const Window &confBL = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getConformanceWindow();
+        const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow();
+
+        Int widthBL   = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset();
+        Int heightBL  = pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset();
+
+        Int widthEL   = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset();
+        Int heightEL  = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset();
+#endif
+        g_mvScalingFactor[refLayerIdc][0] = widthEL  == widthBL  ? 4096 : Clip3(-4096, 4095, ((widthEL  << 8) + (widthBL  >> 1)) / widthBL);
+        g_mvScalingFactor[refLayerIdc][1] = heightEL == heightBL ? 4096 : Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL);
+
+        g_posScalingFactor[refLayerIdc][0] = ((widthBL  << 16) + (widthEL  >> 1)) / widthEL;
+        g_posScalingFactor[refLayerIdc][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL;
+#endif
+
 #if SVC_UPSAMPLING
-        if ( pcPic->isSpatialEnhLayer())
+        if( pcPic->isSpatialEnhLayer(refLayerIdc))
         { 
 #if SCALED_REF_LAYER_OFFSETS
-          m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() );
-#else
-          m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() );
+          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() );
+#else
+          m_pcPredSearch->upsampleBasePic( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc), pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec(), pcPic->getPicYuvRec() );
 #endif
         }
         else
         {
-          pcPic->setFullPelBaseRec( pcSlice->getBaseColPic()->getPicYuvRec() );
-        }
-        pcSlice->setFullPelBaseRec ( pcPic->getFullPelBaseRec() );
+          pcPic->setFullPelBaseRec( refLayerIdc, pcSlice->getBaseColPic(refLayerIdc)->getPicYuvRec() );
+        }
+        pcSlice->setFullPelBaseRec ( refLayerIdc, pcPic->getFullPelBaseRec(refLayerIdc) );
 #endif
       }
@@ -595,7 +594,9 @@
     {
 #if IDR_ALIGNMENT
-      if( pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
-      {
-        pcSlice->setNalUnitType(pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType());
+      TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(0)->getListPic();
+      TComPic* picLayer0 = pcSlice->getRefPic(*cListPic, pcSlice->getPOC() );
+      if( picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || picLayer0->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP )
+      {
+        pcSlice->setNalUnitType(picLayer0->getSlice(0)->getNalUnitType());
       }
       else
@@ -935,4 +936,11 @@
     {
       pcSlice->getSPS()->setTMVPFlagsPresent(1);
+#if SVC_EXTENSION
+      if( pcSlice->getIdrPicFlag() )
+      {
+        pcSlice->setEnableTMVPFlag(0);
+      }
+      else
+#endif
       pcSlice->setEnableTMVPFlag(1);
     }
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSearch.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSearch.cpp	(revision 282)
@@ -3287,8 +3287,4 @@
 #endif
 
-#if (ENCODER_FAST_MODE)
-    Bool          testILR;
-#endif
-
     xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
     
@@ -3312,20 +3308,9 @@
       RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
       
-#if (ENCODER_FAST_MODE)
-      if (pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1)
-      {
-        testILR = false;
-      }
-      else
-      {
-        testILR = true;
-      }
-#endif
-
       for ( Int iRefIdxTemp = 0; iRefIdxTemp < pcCU->getSlice()->getNumRefIdx(eRefPicList); iRefIdxTemp++ )
       {
 #if (ENCODER_FAST_MODE)
         TComPic* pcPic    = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdxTemp );
-        if( !testILR && pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N) ) 
+        if( pcPic->isILR(pcCU->getLayerId()) && (ePartSize == SIZE_2Nx2N) ) 
         {
           continue;
@@ -6305,143 +6290,146 @@
 
 #if ENCODER_FAST_MODE
-Bool TEncSearch::predInterSearchILRUni( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv )
+Bool TEncSearch::predInterSearchILRUni( TComDataCU* pcCU, TComYuv* pcOrgYuv, TComYuv*& rpcPredYuv, TComYuv*& rpcResiYuv, TComYuv*& rpcRecoYuv, UInt refLayerId )
 {
-  rpcPredYuv->clear();
-  rpcRecoYuv->clear();
-
-  Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
-
-  TComMv        cMv[2];
-  TComMv        cMvPred[2][33];
-  TComMv        cMvTemp[2][33];
-  TComMv        TempMv;
-
-  Int           iRefIdx[2]={0,0};
-
-  Int           aaiMvpIdx[2][33];
-  Int           aaiMvpNum[2][33];
-
-  UInt          uiMbBits[3] = {1, 1, 0};
-  UInt          uiLastMode = 0;
-
-  UInt          uiCost[2]   = { MAX_UINT, MAX_UINT };     //uni, rdCost
-  UInt          uiCostTemp;
-  UInt          biPDistTemp = MAX_INT;
-  UInt          uiBitsTemp;
-
-  PartSize      ePartSize = pcCU->getPartitionSize( 0 );  //2Nx2N
-  Int           iPartIdx  = 0;                            //one PU in CU
-  UInt          uiPartAddr;
-  Int           iRoiWidth, iRoiHeight;
-
-  xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
-  pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
-
-  for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++)  //list
-  {
-    RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
-
-    Int  iRefIdxTemp = -1;
-    Bool foundILR    = false;
-    for( Int refIdx = 0; refIdx < pcCU->getSlice()->getNumRefIdx(eRefPicList); refIdx++ )
-    {
-      if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->isILR(pcCU->getLayerId()) )
-      {
-        iRefIdxTemp = refIdx;
-        foundILR    = true;
-        break;
-      }
-    }
-
-    if(!foundILR)  //no ILR in eRefPiclist
-    {
-      continue;  
-    }
-
-    uiBitsTemp = uiMbBits[iRefList];
-    if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) 
-    { 
-      uiBitsTemp += iRefIdxTemp+1; 
-      if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; 
-    }
-
-    xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);
-    aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);
-    aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);
-
-    uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
-
-    xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
-    xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
-
-    if( uiCostTemp < uiCost[iRefList] )
-    {
-      uiCost[iRefList] = uiCostTemp;
-
-      cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
-      iRefIdx[iRefList] = iRefIdxTemp;
-
-      pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
-      pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
-    }
-  }
-
-  if( uiCost[0] == MAX_UINT && uiCost[1] == MAX_UINT )  //no ILR in both list0 and list1
-  {
-    return false;
-  }
-
-  //  Clear Motion Field 
-  pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); 
-  pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); 
-  pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx ); 
-  pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx );
-
-  pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
-  pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
-  pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
-  pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
-
-  if( uiCost[0] <= uiCost[1] )  //list0 ILR
-  {
-    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv    ( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
-    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
-
-    TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 
-    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
-
-    pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
-
-    pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
-    pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
-  }
-  else if( uiCost[1] < uiCost[0] )  //list1 ILR
-  {
-    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv    ( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
-    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
-
-    TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 
-    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
-
-    pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
-
-    pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
-    pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
-  }
-  else
-  {
-    assert(0);
-  }
-
-  pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
-
-  motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx );
-
-  setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
-
-  return true;
+    rpcPredYuv->clear();
+    rpcRecoYuv->clear();
+
+    Int           iNumPredDir = pcCU->getSlice()->isInterP() ? 1 : 2;
+
+    TComMv        cMv[2];
+    TComMv        cMvPred[2][33];
+    TComMv        cMvTemp[2][33];
+    TComMv        TempMv;
+
+    Int           iRefIdx[2]={0,0};
+
+    Int           aaiMvpIdx[2][33];
+    Int           aaiMvpNum[2][33];
+
+    UInt          uiMbBits[3] = {1, 1, 0};
+    UInt          uiLastMode = 0;
+
+    UInt          uiCost[2]   = { MAX_UINT, MAX_UINT };     //uni, rdCost
+    UInt          uiCostTemp;
+    UInt          biPDistTemp = MAX_INT;
+    UInt          uiBitsTemp;
+
+    PartSize      ePartSize = pcCU->getPartitionSize( 0 );  //2Nx2N
+    Int           iPartIdx  = 0;                            //one PU in CU
+    UInt          uiPartAddr;
+    Int           iRoiWidth, iRoiHeight;
+    Bool          bILRSearched = false;
+
+    xGetBlkBits( ePartSize, pcCU->getSlice()->isInterP(), iPartIdx, uiLastMode, uiMbBits);
+    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iRoiWidth, iRoiHeight );
+
+    for( Int iRefList = 0; iRefList < iNumPredDir; iRefList++)  //list
+    {
+        if(bILRSearched)
+           continue;
+
+        RefPicList  eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
+
+        Int  iRefIdxTemp = -1;
+        Bool foundILR    = false;
+
+        for( Int refIdx = 0; refIdx < pcCU->getSlice()->getNumRefIdx(eRefPicList); refIdx++ )
+        {
+            if( pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->isILR(pcCU->getLayerId()) && pcCU->getSlice()->getRefPic(eRefPicList, refIdx)->getLayerId() == refLayerId )
+            {
+                iRefIdxTemp = refIdx;
+                foundILR    = true;
+                bILRSearched = true;
+                break;
+            }
+        }
+
+        if(!foundILR)  //no ILR in eRefPiclist
+        {
+            continue;  
+        }
+
+        uiBitsTemp = uiMbBits[iRefList];
+        if ( pcCU->getSlice()->getNumRefIdx(eRefPicList) > 1 ) 
+        { 
+            uiBitsTemp += iRefIdxTemp+1; 
+            if ( iRefIdxTemp == pcCU->getSlice()->getNumRefIdx(eRefPicList)-1 ) uiBitsTemp--; 
+        }
+
+        xEstimateMvPredAMVP( pcCU, pcOrgYuv, iPartIdx, eRefPicList, iRefIdxTemp, cMvPred[iRefList][iRefIdxTemp], false, &biPDistTemp);
+        aaiMvpIdx[iRefList][iRefIdxTemp] = pcCU->getMVPIdx(eRefPicList, uiPartAddr);
+        aaiMvpNum[iRefList][iRefIdxTemp] = pcCU->getMVPNum(eRefPicList, uiPartAddr);
+
+        uiBitsTemp += m_auiMVPIdxCost[aaiMvpIdx[iRefList][iRefIdxTemp]][AMVP_MAX_NUM_CANDS];
+
+        xMotionEstimation ( pcCU, pcOrgYuv, iPartIdx, eRefPicList, &cMvPred[iRefList][iRefIdxTemp], iRefIdxTemp, cMvTemp[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp );
+        xCheckBestMVP(pcCU, eRefPicList, cMvTemp[iRefList][iRefIdxTemp], cMvPred[iRefList][iRefIdxTemp], aaiMvpIdx[iRefList][iRefIdxTemp], uiBitsTemp, uiCostTemp);
+
+        if( uiCostTemp < uiCost[iRefList] )
+        {
+            uiCost[iRefList] = uiCostTemp;
+
+            cMv[iRefList]     = cMvTemp[iRefList][iRefIdxTemp];
+            iRefIdx[iRefList] = iRefIdxTemp;
+
+            pcCU->getCUMvField(eRefPicList)->setAllMv( cMv[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
+            pcCU->getCUMvField(eRefPicList)->setAllRefIdx( iRefIdx[iRefList], ePartSize, uiPartAddr, 0, iPartIdx );
+        }
+    }
+
+    if( uiCost[0] == MAX_UINT && uiCost[1] == MAX_UINT )  //no ILR in both list0 and list1
+    {
+        return false;
+    }
+
+    //  Clear Motion Field 
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); 
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvField( TComMvField(), ePartSize, uiPartAddr, 0, iPartIdx ); 
+    pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx ); 
+    pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd    ( TComMv(),      ePartSize, uiPartAddr, 0, iPartIdx );
+
+    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+    pcCU->setMVPIdxSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+    pcCU->setMVPNumSubParts( -1, REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+
+    if( uiCost[0] <= uiCost[1] )  //list0 ILR
+    {
+        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMv    ( cMv[0], ePartSize, uiPartAddr, 0, iPartIdx );
+        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllRefIdx( iRefIdx[0], ePartSize, uiPartAddr, 0, iPartIdx );
+
+        TempMv = cMv[0] - cMvPred[0][iRefIdx[0]]; 
+        pcCU->getCUMvField(REF_PIC_LIST_0)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
+
+        pcCU->setInterDirSubParts( 1, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
+
+        pcCU->setMVPIdxSubParts( aaiMvpIdx[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+        pcCU->setMVPNumSubParts( aaiMvpNum[0][iRefIdx[0]], REF_PIC_LIST_0, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+    }
+    else if( uiCost[1] < uiCost[0] )  //list1 ILR
+    {
+        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMv    ( cMv[1], ePartSize, uiPartAddr, 0, iPartIdx );
+        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllRefIdx( iRefIdx[1], ePartSize, uiPartAddr, 0, iPartIdx );
+
+        TempMv = cMv[1] - cMvPred[1][iRefIdx[1]]; 
+        pcCU->getCUMvField(REF_PIC_LIST_1)->setAllMvd( TempMv, ePartSize, uiPartAddr, 0, iPartIdx );
+
+        pcCU->setInterDirSubParts( 2, uiPartAddr, iPartIdx, pcCU->getDepth(0) );
+
+        pcCU->setMVPIdxSubParts( aaiMvpIdx[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr)); 
+        pcCU->setMVPNumSubParts( aaiMvpNum[1][iRefIdx[1]], REF_PIC_LIST_1, uiPartAddr, iPartIdx, pcCU->getDepth(uiPartAddr));
+    }
+    else
+    {
+        assert(0);
+    }
+
+    pcCU->setMergeFlagSubParts( false, uiPartAddr, iPartIdx, pcCU->getDepth( uiPartAddr ) );
+
+    motionCompensation ( pcCU, rpcPredYuv, REF_PIC_LIST_X, iPartIdx );
+    setWpScalingDistParam( pcCU, -1, REF_PIC_LIST_X );
+
+    return true;
 }
-
-
 #endif
 
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSearch.h
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSearch.h	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSearch.h	(revision 282)
@@ -216,11 +216,5 @@
   
 #if (ENCODER_FAST_MODE)
-  Bool predInterSearchILRUni    ( TComDataCU* pcCU,
-                                  TComYuv*    pcOrgYuv,
-                                  TComYuv*&   rpcPredYuv,
-                                  TComYuv*&   rpcResiYuv,
-                                  TComYuv*&   rpcRecoYuv
-                                );
-
+  Bool predInterSearchILRUni    ( TComDataCU* pcCU, TComYuv*    pcOrgYuv, TComYuv*&   rpcPredYuv, TComYuv*&   rpcResiYuv, TComYuv*&   rpcRecoYuv, UInt        refLayerId );
 #endif
   
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 282)
@@ -493,8 +493,8 @@
     if( rpcSlice->getNumILRRefIdx() > 0 )
     {
-      rpcSlice->setActiveNumILRRefIdx( rpcSlice->getNumILRRefIdx() );
+      rpcSlice->setActiveNumILRRefIdx( m_ppcTEncTop[layerId]->getNumActiveRefLayers() );
       for( Int i = 0; i < rpcSlice->getActiveNumILRRefIdx(); i++ )
       {
-        rpcSlice->setInterLayerPredLayerIdc(i, i);
+        rpcSlice->setInterLayerPredLayerIdc( m_ppcTEncTop[layerId]->getPredLayerId(i), i );
       }
       rpcSlice->setInterLayerPredEnabledFlag(1);
@@ -995,7 +995,4 @@
     TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr );
     pcCU->initCU( rpcPic, uiCUAddr );
-#if SVC_EXTENSION
-    pcCU->setLayerId(m_pcCfg->getLayerId());
-#endif
 
 #if !RATE_CONTROL_LAMBDA_DOMAIN
Index: branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncTop.cpp
===================================================================
--- branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 258)
+++ branches/SHM-2.1-dev/source/Lib/TLibEncoder/TEncTop.cpp	(revision 282)
@@ -507,15 +507,21 @@
       if(m_layerId > 0)
       {
+        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
+        {
+          const Window scalEL = getSPS()->getScaledRefLayerWindow();
+          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+
 #if VPS_EXTN_DIRECT_REF_LAYERS
-        TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( m_layerId - 1 );
-#else
-        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
-#endif
-        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
-        {
-          pcEPic->setSpatialEnhLayerFlag( true );
-
-          //only for scalable extension
-          assert( m_cVPS.getScalabilityMask(1) == true );
+          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
+#else
+          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
+#endif
+          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
+          {
+            pcEPic->setSpatialEnhLayerFlag( i, true );
+
+            //only for scalable extension
+            assert( m_cVPS.getScalabilityMask(1) == true );
+          }
         }
       }
@@ -538,15 +544,21 @@
       if(m_layerId > 0)
       {
+        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
+        {
+          const Window scalEL = getSPS()->getScaledRefLayerWindow();
+          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
+
 #if VPS_EXTN_DIRECT_REF_LAYERS
-        TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( m_layerId - 1 );
-#else
-        TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
-#endif
-        if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() )
-        {
-          rpcPic->setSpatialEnhLayerFlag( true );
-
-          //only for scalable extension
-          assert( m_cVPS.getScalabilityMask(1) == true );
+          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
+#else
+          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
+#endif
+          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
+          {
+            rpcPic->setSpatialEnhLayerFlag( i, true );
+
+            //only for scalable extension
+            assert( m_cVPS.getScalabilityMask(1) == true );
+          }
         }
       }
@@ -1210,8 +1222,5 @@
   }
 
-  // currently only one reference layer is supported
-  assert( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() == 1 );
-
-  return (TEncTop *)getLayerEnc( getVPS()->getRefLayerId( m_layerId, refLayerIdc ) );
+  return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdc ) );
 }
 #endif
@@ -1235,5 +1244,5 @@
     if (m_cIlpPic[0] == NULL)
     {
-      for (Int j=0; j<1/*MAX_NUM_REF*/; j++)
+      for (Int j=0; j < MAX_LAYERS /*MAX_NUM_REF*/; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
       {
         m_cIlpPic[j] = new  TComPic;
@@ -1254,11 +1263,16 @@
 Void TEncTop::setILRPic(TComPic *pcPic)
 {
-  if(m_cIlpPic[0])
-  {
-    m_cIlpPic[0]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(), m_cIlpPic[0]->getPicYuvRec());
-    m_cIlpPic[0]->getSlice(0)->setPOC(pcPic->getPOC());
-    m_cIlpPic[0]->setLayerId(pcPic->getSlice(0)->getBaseColPic()->getLayerId()); //set reference layerId
-    m_cIlpPic[0]->getPicYuvRec()->setBorderExtension(false);
-    m_cIlpPic[0]->getPicYuvRec()->extendPicBorder();
+  for( Int i = 0; i < pcPic->getSlice(0)->getActiveNumILRRefIdx(); i++ )
+  {
+    Int refLayerIdc = pcPic->getSlice(0)->getInterLayerPredLayerIdc(i);
+
+    if(m_cIlpPic[refLayerIdc])
+    {
+      m_cIlpPic[refLayerIdc]->copyUpsampledPictureYuv(pcPic->getFullPelBaseRec(refLayerIdc), m_cIlpPic[refLayerIdc]->getPicYuvRec());
+      m_cIlpPic[refLayerIdc]->getSlice(0)->setPOC(pcPic->getPOC());
+      m_cIlpPic[refLayerIdc]->setLayerId(pcPic->getSlice(0)->getBaseColPic(refLayerIdc)->getLayerId()); //set reference layerId
+      m_cIlpPic[refLayerIdc]->getPicYuvRec()->setBorderExtension(false);
+      m_cIlpPic[refLayerIdc]->getPicYuvRec()->extendPicBorder();
+    }
   }
 }
