From d9aafb8506f34d2ac7f55dbae191ca52ccfbc24c Mon Sep 17 00:00:00 2001
From: Karsten Suehring <karsten.suehring@hhi.fraunhofer.de>
Date: Wed, 21 Aug 2019 16:48:27 +0200
Subject: [PATCH] improve configurability of fast intra decision introduced in
 JVET-O0050

- add option to completely disable
- add iparameter to software manual
---
 cfg/encoder_lowdelay_P_vtm.cfg        |  2 +-
 cfg/encoder_lowdelay_vtm.cfg          |  2 +-
 cfg/encoder_randomaccess_vtm.cfg      |  2 +-
 doc/software-manual.tex               | 13 +++++++++++++
 source/App/EncoderApp/EncApp.cpp      |  2 +-
 source/App/EncoderApp/EncAppCfg.cpp   |  8 ++++++--
 source/App/EncoderApp/EncAppCfg.h     |  2 +-
 source/Lib/CommonLib/Contexts.cpp     |  2 ++
 source/Lib/EncoderLib/EncCfg.h        |  6 +++---
 source/Lib/EncoderLib/IntraSearch.cpp | 19 +++++++++++--------
 10 files changed, 40 insertions(+), 18 deletions(-)
 mode change 100644 => 100755 doc/software-manual.tex

diff --git a/cfg/encoder_lowdelay_P_vtm.cfg b/cfg/encoder_lowdelay_P_vtm.cfg
index fcc83ed92..465f1e9a0 100644
--- a/cfg/encoder_lowdelay_P_vtm.cfg
+++ b/cfg/encoder_lowdelay_P_vtm.cfg
@@ -141,7 +141,7 @@ ISPFast                      : 0
 FastMrg                      : 1
 AMaxBT                       : 1
 FastMIP                      : 0
-FastLocalDualTree            : 1
+FastLocalDualTreeMode        : 2
 
 # Encoder optimization tools
 AffineAmvrEncOpt             : 0
diff --git a/cfg/encoder_lowdelay_vtm.cfg b/cfg/encoder_lowdelay_vtm.cfg
index a1c98ae3c..937768722 100644
--- a/cfg/encoder_lowdelay_vtm.cfg
+++ b/cfg/encoder_lowdelay_vtm.cfg
@@ -145,7 +145,7 @@ ISPFast                      : 0
 FastMrg                      : 1
 AMaxBT                       : 1
 FastMIP                      : 0
-FastLocalDualTree            : 1
+FastLocalDualTreeMode        : 2
 
 # Encoder optimization tools
 AffineAmvrEncOpt             : 0
diff --git a/cfg/encoder_randomaccess_vtm.cfg b/cfg/encoder_randomaccess_vtm.cfg
index 7c4404bdf..0face3aa8 100644
--- a/cfg/encoder_randomaccess_vtm.cfg
+++ b/cfg/encoder_randomaccess_vtm.cfg
@@ -164,7 +164,7 @@ FastMrg                      : 1
 AMaxBT                       : 1
 FastMIP                      : 0
 FastLFNST                    : 0
-FastLocalDualTree            : 0
+FastLocalDualTreeMode        : 1
 
 # Encoder optimization tools
 AffineAmvrEncOpt             : 1
diff --git a/doc/software-manual.tex b/doc/software-manual.tex
old mode 100644
new mode 100755
index 02dad6abe..4a1f25cdd
--- a/doc/software-manual.tex
+++ b/doc/software-manual.tex
@@ -1291,6 +1291,19 @@ Enabling this parameter can reduce the visibility of CU boundaries in the coded
 \end{tabular}
 \\
 
+\Option{FastLocalDualTreeMode} &
+%\ShortOption{\None} &
+\Default{0} &
+Controls intra coding speedup introducted with local dual tree mode. 
+\par
+\begin{tabular}{cp{0.45\textwidth}}
+ 0 & Disabled\\
+ 1 & Stop testing intra modes in inter slices, if best cost is more that 1.5 times inter cost.\\
+ 2 & Test only one intra mode in inter slices\\
+\end{tabular}
+\\
+
+
 \end{OptionTableNoShorthand}
 
 %%
diff --git a/source/App/EncoderApp/EncApp.cpp b/source/App/EncoderApp/EncApp.cpp
index 21c65e025..0faf62012 100644
--- a/source/App/EncoderApp/EncApp.cpp
+++ b/source/App/EncoderApp/EncApp.cpp
@@ -363,7 +363,7 @@ void EncApp::xInitLibCfg()
   m_cEncLib.setUseMIP                                            ( m_MIP );
   m_cEncLib.setUseFastMIP                                        ( m_useFastMIP );
 #if JVET_O0050_LOCAL_DUAL_TREE
-  m_cEncLib.setUseFastLocalDualTree                              ( m_useFastLocalDualTree );
+  m_cEncLib.setFastLocalDualTreeMode                             ( m_fastLocalDualTreeMode );
 #endif
   m_cEncLib.setCrossComponentPredictionEnabledFlag               ( m_crossComponentPredictionEnabledFlag );
   m_cEncLib.setUseReconBasedCrossCPredictionEstimate             ( m_reconBasedCrossCPredictionEstimate );
diff --git a/source/App/EncoderApp/EncAppCfg.cpp b/source/App/EncoderApp/EncAppCfg.cpp
index 75c2ef47e..bcecaabe0 100644
--- a/source/App/EncoderApp/EncAppCfg.cpp
+++ b/source/App/EncoderApp/EncAppCfg.cpp
@@ -992,7 +992,7 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
   ("MIP",                                             m_MIP,                                             true,  "Enable MIP (matrix-based intra prediction)")
   ("FastMIP",                                         m_useFastMIP,                                     false,  "Fast encoder search for MIP (matrix-based intra prediction)")
 #if JVET_O0050_LOCAL_DUAL_TREE
-  ("FastLocalDualTree",                               m_useFastLocalDualTree,                           false,  "Fast intra pass coding for local dual-tree in intra coding region (SCIPU)")
+  ("FastLocalDualTreeMode",                           m_fastLocalDualTreeMode,                              0,  "Fast intra pass coding for local dual-tree in intra coding region, 0: off, 1: use threshold, 2: one intra mode only")
 #endif
   // Unit definition parameters
   ("MaxCUWidth",                                      m_uiMaxCUWidth,                                     64u)
@@ -2848,6 +2848,10 @@ bool EncAppCfg::xCheckParameter()
   xConfirmPara( abs(m_sliceChromaQpOffsetIntraOrPeriodic[1]  + m_crQpOffset ) > 12, "Intra/periodic Cr QP Offset, when combined with the PPS Cr offset, exceeds supported range (-12 to 12)" );
 #endif
 
+#if JVET_O0050_LOCAL_DUAL_TREE
+  xConfirmPara( m_fastLocalDualTreeMode < 0 || m_fastLocalDualTreeMode > 2, "FastLocalDualTreeMode must be in range [0..2]" );
+#endif
+
   int extraRPLs = 0;
   //start looping through frames in coding order until we can verify that the GOP structure is correct.
   while (!verifiedGOP && !errorGOP)
@@ -3624,7 +3628,7 @@ void EncAppCfg::xPrintParameter()
 #endif
   if( m_MIP ) msg(VERBOSE, "FastMIP:%d ", m_useFastMIP);
 #if JVET_O0050_LOCAL_DUAL_TREE
-  msg( VERBOSE, "FastLocalDualTree:%d ", m_useFastLocalDualTree );
+  msg( VERBOSE, "FastLocalDualTree:%d ", m_fastLocalDualTreeMode );
 #endif
 
   msg( VERBOSE, "NumSplitThreads:%d ", m_numSplitThreads );
diff --git a/source/App/EncoderApp/EncAppCfg.h b/source/App/EncoderApp/EncAppCfg.h
index 16d0993ce..dd4862a0e 100644
--- a/source/App/EncoderApp/EncAppCfg.h
+++ b/source/App/EncoderApp/EncAppCfg.h
@@ -353,7 +353,7 @@ protected:
   bool      m_MIP;
   bool      m_useFastMIP;
 #if JVET_O0050_LOCAL_DUAL_TREE
-  bool      m_useFastLocalDualTree;
+  int       m_fastLocalDualTreeMode;
 #endif
 
 
diff --git a/source/Lib/CommonLib/Contexts.cpp b/source/Lib/CommonLib/Contexts.cpp
index 7fbbd59ec..bec85ae80 100755
--- a/source/Lib/CommonLib/Contexts.cpp
+++ b/source/Lib/CommonLib/Contexts.cpp
@@ -241,6 +241,7 @@ const CtxSet ContextSetCfg::Split12Flag = ContextSetCfg::addCtxSet
   {  12,  12,  12,  13, },
 });
 
+#if JVET_O0050_LOCAL_DUAL_TREE
 const CtxSet ContextSetCfg::ModeConsFlag = ContextSetCfg::addCtxSet
 ({
   {  40,  28, },
@@ -248,6 +249,7 @@ const CtxSet ContextSetCfg::ModeConsFlag = ContextSetCfg::addCtxSet
   { CNU, CNU, },
   {   1,   0, },
 });
+#endif
 
 const CtxSet ContextSetCfg::SkipFlag = ContextSetCfg::addCtxSet
 ({
diff --git a/source/Lib/EncoderLib/EncCfg.h b/source/Lib/EncoderLib/EncCfg.h
index b2e2501e9..a256bb732 100644
--- a/source/Lib/EncoderLib/EncCfg.h
+++ b/source/Lib/EncoderLib/EncCfg.h
@@ -356,7 +356,7 @@ protected:
   bool      m_MIP;
   bool      m_useFastMIP;
 #if JVET_O0050_LOCAL_DUAL_TREE
-  bool      m_useFastLocalDualTree;
+  int       m_fastLocalDualTreeMode;
 #endif
 #if MAX_TB_SIZE_SIGNALLING
   uint32_t  m_log2MaxTbSize;
@@ -1010,8 +1010,8 @@ public:
   void      setUseFastMIP                   ( bool b )       { m_useFastMIP = b; }
   bool      getUseFastMIP                   () const         { return m_useFastMIP; }
 #if JVET_O0050_LOCAL_DUAL_TREE
-  void      setUseFastLocalDualTree         ( bool b )       { m_useFastLocalDualTree = b; }
-  bool      getUseFastLocalDualTree         () const         { return m_useFastLocalDualTree; }
+  void     setFastLocalDualTreeMode         ( int i )        { m_fastLocalDualTreeMode = i; }
+  int      getFastLocalDualTreeMode         () const         { return m_fastLocalDualTreeMode; }
 #endif
 
 #if MAX_TB_SIZE_SIGNALLING
diff --git a/source/Lib/EncoderLib/IntraSearch.cpp b/source/Lib/EncoderLib/IntraSearch.cpp
index d9c2b821a..e20e8597d 100644
--- a/source/Lib/EncoderLib/IntraSearch.cpp
+++ b/source/Lib/EncoderLib/IntraSearch.cpp
@@ -1336,19 +1336,22 @@ bool IntraSearch::estIntraPredLumaQT( CodingUnit &cu, Partitioner &partitioner,
 
       csTemp->releaseIntermediateData();
 #if JVET_O0050_LOCAL_DUAL_TREE
-      if( cu.isConsIntra() && !cu.slice->isIntra() && csBest->cost != MAX_DOUBLE && costInterCU != COST_UNKNOWN && mode >= 0 )
+      if( m_pcEncCfg->getFastLocalDualTreeMode() )
       {
-        if( m_pcEncCfg->getUseFastLocalDualTree() )
+        if( cu.isConsIntra() && !cu.slice->isIntra() && csBest->cost != MAX_DOUBLE && costInterCU != COST_UNKNOWN && mode >= 0 )
         {
-          //Note: only try one intra mode, which is especially useful to reduce EncT for LDB case (around 4%)
-          break;
-        }
-        else
-        {
-          if( csBest->cost > costInterCU * 1.5 )
+          if( m_pcEncCfg->getFastLocalDualTreeMode() == 2 )
           {
+            //Note: only try one intra mode, which is especially useful to reduce EncT for LDB case (around 4%)
             break;
           }
+          else
+          {
+            if( csBest->cost > costInterCU * 1.5 )
+            {
+              break;
+            }
+          }
         }
       }
 #endif
-- 
GitLab