Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 116)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncCfg.cpp	(revision 118)
@@ -292,4 +292,9 @@
   Int*    cfg_IntraPeriod   [MAX_LAYERS];
   Int*    cfg_conformanceMode  [MAX_LAYERS];
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int*    cfg_numDirectRefLayers [MAX_LAYERS];
+  string cfg_refLayerIds   [MAX_LAYERS];
+  string* cfg_refLayerIdsPtr   [MAX_LAYERS];
+#endif
   for(UInt layer = 0; layer < MAX_LAYERS; layer++)
   {
@@ -302,4 +307,8 @@
     cfg_IntraPeriod[layer]  = &m_acLayerCfg[layer].m_iIntraPeriod; 
     cfg_conformanceMode[layer] = &m_acLayerCfg[layer].m_conformanceMode;
+#if VPS_EXTN_DIRECT_REF_LAYERS
+    cfg_numDirectRefLayers  [layer] = &m_acLayerCfg[layer].m_numDirectRefLayers;
+    cfg_refLayerIdsPtr      [layer]  = &cfg_refLayerIds[layer];
+#endif
   }
 #if AVC_SYNTAX
@@ -337,4 +346,8 @@
   ("FrameRate%d,-fr%d",       cfg_FrameRate,  0, MAX_LAYERS, "Frame rate for layer %d")
   ("LambdaModifier%d,-LM%d",  m_adLambdaModifier, ( double )1.0, MAX_TLAYER, "Lambda modifier for temporal layer %d")
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  ("NumDirectRefLayers%d",    cfg_numDirectRefLayers, -1, MAX_LAYERS, "Number of direct reference layers")
+  ("RefLayerIds%d",           cfg_refLayerIdsPtr, string(""), MAX_LAYERS, "direct reference layer IDs")
+#endif
   ("NumLayers",               m_numLayers, 1, "Number of layers to code")
   ("ConformanceMode%d",       cfg_conformanceMode,0, MAX_LAYERS, "Window conformance mode (0: no cropping, 1:automatic padding, 2: padding, 3:cropping")
@@ -717,4 +730,37 @@
     m_pRowHeight = NULL;
   }
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  for(Int layer = 0; layer < MAX_LAYERS; layer++)
+  {
+    Char* pRefLayerIds = cfg_refLayerIds[layer].empty() ? NULL: strdup(cfg_refLayerIds[layer].c_str());
+    if( m_acLayerCfg[layer].m_numDirectRefLayers > 0 )
+    {
+      char *refLayerId;
+      int  i=0;
+      m_acLayerCfg[layer].m_refLayerIds = new Int[m_acLayerCfg[layer].m_numDirectRefLayers];
+      refLayerId = strtok(pRefLayerIds, " ,-");
+      while(refLayerId != NULL)
+      {
+        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" );
+          exit( EXIT_FAILURE );
+        }
+        *( m_acLayerCfg[layer].m_refLayerIds + i ) = atoi( refLayerId );
+        refLayerId = strtok(NULL, " ,-");
+        i++;
+      }
+      if( i < m_acLayerCfg[layer].m_numDirectRefLayers )
+      {
+        printf( "The width of some columns is not defined.\n" );
+        exit( EXIT_FAILURE );
+      }
+    }
+    else
+    {
+      m_acLayerCfg[layer].m_refLayerIds = NULL;
+    }
+  }
+#endif
 #if SIGNAL_BITRATE_PICRATE_IN_VPS
   readBoolString(cfg_bitRateInfoPresentFlag, m_bitRatePicRateMaxTLayers, m_bitRateInfoPresentFlag, "bit rate info. present flag" );
@@ -1511,5 +1557,17 @@
   }
 #endif
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  xConfirmPara( (m_acLayerCfg[0].m_numDirectRefLayers != 0) && (m_acLayerCfg[0].m_numDirectRefLayers != -1), "Layer 0 cannot have any reference layers" );
+  // NOTE: m_numDirectRefLayers  (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_numDirectRefLayers > layer, "Cannot reference more layers than before current layer");
+    for(Int i = 0; i < m_acLayerCfg[layer].m_numDirectRefLayers; i++)
+    {
+      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] > layer, "Cannot reference higher layers");
+      xConfirmPara(m_acLayerCfg[layer].m_refLayerIds[i] == layer, "Cannot reference the current layer itself");
+    }
+  }
+#endif
 #undef xConfirmPara
   if (check_failed)
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 116)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncLayerCfg.h	(revision 118)
@@ -42,5 +42,8 @@
   Int       m_iIntraPeriod;                                   ///< period of I-slice (random access period)
   Double    m_fQP;                                            ///< QP value of key-picture (floating point)
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int       *m_refLayerIds;
+  Int       m_numDirectRefLayers;
+#endif
 #if SVC_EXTENSION
   Int       m_iWaveFrontSubstreams; //< If iWaveFrontSynchro, this is the number of substreams per frame (dependent tiles) or per tile (independent tiles).
@@ -80,5 +83,9 @@
   Int     getIntQP()                  {return m_iQP;              } 
   Int*    getdQPs()                   {return m_aidQP;            }
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  Int     getNumDirectRefLayers()     {return m_numDirectRefLayers;}
+  Int*    getRefLayerIds()            {return m_refLayerIds;      }
+  Int     getRefLayerId(Int i)        {return m_refLayerIds[i];   }
+#endif
 }; // END CLASS DEFINITION TAppEncLayerCfg
 
Index: branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp
===================================================================
--- branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp	(revision 116)
+++ branches/HM-10.0-dev-SHM/source/App/TAppEncoder/TAppEncTop.cpp	(revision 118)
@@ -140,5 +140,23 @@
     m_acTEncTop[layer].setMaxTempLayer                 ( m_maxTempLayer );
     m_acTEncTop[layer].setUseAMP( m_enableAMP );
-
+#if VPS_EXTN_DIRECT_REF_LAYERS
+    if(layer)
+    {
+      if(m_acLayerCfg[layer].getNumDirectRefLayers() == -1)
+      {
+        // Not included in the configuration file; assume that each layer depends on previous layer
+        m_acTEncTop[layer].setNumDirectRefLayers       (1);      // One ref. layer
+        m_acTEncTop[layer].setRefLayerId               (0, layer - 1);   // Previous layer
+      }
+      else
+      {
+        m_acTEncTop[layer].setNumDirectRefLayers       ( m_acLayerCfg[layer].getNumDirectRefLayers() );      
+        for(Int i = 0; i < m_acTEncTop[layer].getNumDirectRefLayers(); i++)
+        {
+          m_acTEncTop[layer].setRefLayerId             ( i, m_acLayerCfg[layer].getRefLayerId(i));
+        }        
+      }
+    }
+#endif
     //===== Slice ========
 
@@ -763,4 +781,25 @@
   }
 #endif
+#if VPS_EXTN_DIRECT_REF_LAYERS
+  // Direct reference layers
+  for(UInt layerCtr = 1;layerCtr <= vps->getMaxLayers() - 1; layerCtr++)
+  {
+    vps->setNumDirectRefLayers( layerCtr, m_acTEncTop[layerCtr].getNumDirectRefLayers() );
+    for(Int i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    {
+      vps->setRefLayerId( layerCtr, i, m_acTEncTop[layerCtr].getRefLayerId(i) );
+    }
+    // Set direct dependency flag
+    // Initialize flag to 0
+    for(Int refLayerCtr = 0; refLayerCtr < layerCtr; refLayerCtr++)
+    {
+      vps->setDirectDependencyFlag( layerCtr, refLayerCtr, false );
+    }
+    for(Int i = 0; i < vps->getNumDirectRefLayers(layerCtr); i++)
+    {
+      vps->setDirectDependencyFlag( layerCtr, vps->getLayerIdInVps(m_acTEncTop[layerCtr].getRefLayerId(i)), true);
+    }
+  }
+#endif
 #else
   m_cTEncTop.init();
