Commit a7807c14 authored by Nan Hu's avatar Nan Hu
Browse files

M0428

parent 9248cfdf
......@@ -300,6 +300,9 @@ void EncApp::xInitLibCfg()
m_cEncLib.setQuadtreeTULog2MinSize ( m_quadtreeTULog2MinSize );
m_cEncLib.setQuadtreeTUMaxDepthInter ( m_uiQuadtreeTUMaxDepthInter );
m_cEncLib.setQuadtreeTUMaxDepthIntra ( m_uiQuadtreeTUMaxDepthIntra );
#if JVET_M0428_ENC_DB_OPT
m_cEncLib.setUseEncDbOpt(m_encDbOpt);
#endif
m_cEncLib.setUseFastLCTU ( m_useFastLCTU );
m_cEncLib.setFastInterSearchMode ( m_fastInterSearchMode );
m_cEncLib.setUseEarlyCU ( m_bUseEarlyCU );
......
......@@ -898,6 +898,9 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
("WrapAroundOffset", m_wrapAroundOffset, 0u, "Offset in luma samples used for computing the horizontal wrap-around position")
// ADD_NEW_TOOL : (encoder app) add parsing parameters here
#if JVET_M0428_ENC_DB_OPT
("EncDbOpt", m_encDbOpt, false, "Encoder optimization with deblocking filter")
#endif
#if JVET_M0427_INLOOP_RESHAPER
("LumaReshapeEnable", m_lumaReshapeEnable, false, "Enable Reshaping for Luma Channel")
("ReshapeSignalType", m_reshapeSignalType, 0u, "Input signal type: 0: SDR, 1:PQ, 2:HLG")
......@@ -3246,6 +3249,9 @@ void EncAppCfg::xPrintParameter()
msg(VERBOSE, "(Sigal:%s ", m_reshapeSignalType==0? "SDR" : "HDR-PQ");
msg(VERBOSE, ") ");
}
#endif
#if JVET_M0428_ENC_DB_OPT
msg(VERBOSE, "EncDbOpt:%d ", m_encDbOpt);
#endif
msg( VERBOSE, "\nFAST TOOL CFG: " );
if( m_LargeCTU )
......
......@@ -276,6 +276,9 @@ protected:
uint32_t m_reshapeSignalType;
uint32_t m_intraCMD;
ReshapeCW m_reshapeCW;
#endif
#if JVET_M0428_ENC_DB_OPT
bool m_encDbOpt;
#endif
unsigned m_uiMaxCUWidth; ///< max. CU width in pixel
unsigned m_uiMaxCUHeight; ///< max. CU height in pixel
......
......@@ -751,6 +751,11 @@ void CodingStructure::initSubStructure( CodingStructure& subStruct, const Channe
{
CHECK( this == &subStruct, "Trying to init self as sub-structure" );
#if JVET_M0428_ENC_DB_OPT
subStruct.useDbCost = false;
subStruct.costDbOffset = 0;
#endif
for( uint32_t i = 0; i < subStruct.area.blocks.size(); i++ )
{
CHECKD( subStruct.area.blocks[i].size() != subArea.blocks[i].size(), "Trying to init sub-structure of incompatible size" );
......@@ -852,7 +857,9 @@ void CodingStructure::useSubStructure( const CodingStructure& subStruct, const C
fracBits += subStruct.fracBits;
dist += subStruct.dist;
cost += subStruct.cost;
#if JVET_M0428_ENC_DB_OPT
costDbOffset += subStruct.costDbOffset;
#endif
if( parent )
{
// allow this to be false at the top level
......@@ -916,7 +923,9 @@ void CodingStructure::useSubStructure( const CodingStructure& subStruct, const C
fracBits += subStruct.fracBits;
dist += subStruct.dist;
cost += subStruct.cost;
#if JVET_M0428_ENC_DB_OPT
costDbOffset += subStruct.costDbOffset;
#endif
if( parent )
{
// allow this to be false at the top level
......@@ -978,7 +987,9 @@ void CodingStructure::copyStructure( const CodingStructure& other, const Channel
fracBits = other.fracBits;
dist = other.dist;
cost = other.cost;
#if JVET_M0428_ENC_DB_OPT
costDbOffset = other.costDbOffset;
#endif
CHECKD( area != other.area, "Incompatible sizes" );
const UnitArea dualITreeArea = CS::getArea( *this, this->area, chType );
......@@ -1110,6 +1121,10 @@ void CodingStructure::initStructData( const int &QP, const bool &_isLosses, cons
cost = MAX_DOUBLE;
#if JVET_M0102_INTRA_SUBPARTITIONS
lumaCost = MAX_DOUBLE;
#endif
#if JVET_M0428_ENC_DB_OPT
costDbOffset = 0;
useDbCost = false;
#endif
interHad = std::numeric_limits<Distortion>::max();
}
......
......@@ -179,6 +179,10 @@ public:
static_vector<double, NUM_ENC_FEATURES> features;
double cost;
#if JVET_M0428_ENC_DB_OPT
bool useDbCost;
double costDbOffset;
#endif
#if JVET_M0102_INTRA_SUBPARTITIONS
double lumaCost;
#endif
......
......@@ -126,7 +126,19 @@ void LoopFilter::create( const unsigned uiMaxCUDepth )
m_aapucBS [edgeDir].resize( numPartitions );
m_aapbEdgeFilter[edgeDir].resize( numPartitions );
}
#if JVET_M0428_ENC_DB_OPT
m_bEnc = false;
#endif
}
#if JVET_M0428_ENC_DB_OPT
void LoopFilter::initEncPicYuvBuffer(ChromaFormat chromaFormat, int lumaWidth, int lumaHeight)
{
const UnitArea picArea(chromaFormat, Area(0, 0, lumaWidth, lumaHeight));
m_encPicYuvBuffer.destroy();
m_encPicYuvBuffer.create(picArea);
}
#endif
void LoopFilter::destroy()
{
......@@ -135,6 +147,9 @@ void LoopFilter::destroy()
m_aapucBS [edgeDir].clear();
m_aapbEdgeFilter[edgeDir].clear();
}
#if JVET_M0428_ENC_DB_OPT
m_encPicYuvBuffer.destroy();
#endif
}
/**
......@@ -731,7 +746,11 @@ void LoopFilter::xEdgeFilterLuma(const CodingUnit& cu, const DeblockEdgeDir edge
const CompArea& lumaArea = cu.block(COMPONENT_Y);
const PreCalcValues& pcv = *cu.cs->pcv;
#if JVET_M0428_ENC_DB_OPT
PelBuf picYuvRec = m_bEnc ? m_encPicYuvBuffer.getBuf(lumaArea) : cu.cs->getRecoBuf(lumaArea);
#else
PelBuf picYuvRec = cu.cs->getRecoBuf( lumaArea );
#endif
Pel *piSrc = picYuvRec.buf;
const int iStride = picYuvRec.stride;
Pel *piTmpSrc = piSrc;
......@@ -1003,9 +1022,13 @@ void LoopFilter::xEdgeFilterChroma(const CodingUnit& cu, const DeblockEdgeDir ed
const PreCalcValues& pcv = *cu.cs->pcv;
unsigned rasterIdx = getRasterIdx( lumaPos, pcv );
#if JVET_M0428_ENC_DB_OPT
PelBuf picYuvRecCb = m_bEnc ? m_encPicYuvBuffer.getBuf(cu.block(COMPONENT_Cb)) : cu.cs->getRecoBuf(cu.block(COMPONENT_Cb));
PelBuf picYuvRecCr = m_bEnc ? m_encPicYuvBuffer.getBuf(cu.block(COMPONENT_Cr)) : cu.cs->getRecoBuf(cu.block(COMPONENT_Cr));
#else
PelBuf picYuvRecCb = cu.cs->getRecoBuf( cu.block(COMPONENT_Cb) );
PelBuf picYuvRecCr = cu.cs->getRecoBuf( cu.block(COMPONENT_Cr) );
#endif
Pel *piSrcCb = picYuvRecCb.buf;
Pel *piSrcCr = picYuvRecCr.buf;
const int iStride = picYuvRecCb.stride;
......
......@@ -58,11 +58,16 @@ private:
static_vector<char, MAX_NUM_PARTS_IN_CTU> m_aapucBS [NUM_EDGE_DIR]; ///< Bs for [Ver/Hor][Y/U/V][Blk_Idx]
static_vector<bool, MAX_NUM_PARTS_IN_CTU> m_aapbEdgeFilter[NUM_EDGE_DIR];
LFCUParam m_stLFCUParam; ///< status structure
#if JVET_M0428_ENC_DB_OPT
PelStorage m_encPicYuvBuffer;
bool m_bEnc;
#endif
private:
#if !JVET_M0428_ENC_DB_OPT
/// CU-level deblocking function
void xDeblockCU ( CodingUnit& cu, const DeblockEdgeDir edgeDir );
#endif
// set / get functions
void xSetLoopfilterParam ( const CodingUnit& cu );
......@@ -111,6 +116,14 @@ public:
LoopFilter();
~LoopFilter();
#if JVET_M0428_ENC_DB_OPT
/// CU-level deblocking function
void xDeblockCU(CodingUnit& cu, const DeblockEdgeDir edgeDir);
void initEncPicYuvBuffer(ChromaFormat chromaFormat, int lumaWidth, int lumaHeight);
PelStorage& getDbEncPicYuvBuffer() { return m_encPicYuvBuffer; }
void setEnc(bool b) { m_bEnc = b; }
#endif
void create ( const unsigned uiMaxCUDepth );
void destroy ();
......
......@@ -50,6 +50,8 @@
#include <assert.h>
#include <cassert>
#define JVET_M0428_ENC_DB_OPT 1 // Encoder optimization with deblocking filter
#define JVET_M0055_DEBUG_CTU 1 // DebugCTU encoder debug option
#define JVET_M0297_32PT_MTS_ZERO_OUT 1 // 32 point MTS based on skipping high frequency coefficients
......
......@@ -276,6 +276,9 @@ protected:
unsigned m_reshapeSignalType;
unsigned m_intraCMD;
ReshapeCW m_reshapeCW;
#endif
#if JVET_M0428_ENC_DB_OPT
bool m_encDbOpt;
#endif
bool m_useFastLCTU;
bool m_useFastMrg;
......@@ -847,6 +850,10 @@ public:
void setMaxCodingDepth ( uint32_t u ) { m_maxTotalCUDepth = u; }
uint32_t getMaxCodingDepth () const { return m_maxTotalCUDepth; }
void setLog2DiffMaxMinCodingBlockSize( uint32_t u ) { m_log2DiffMaxMinCodingBlockSize = u; }
#if JVET_M0428_ENC_DB_OPT
void setUseEncDbOpt ( bool n ) { m_encDbOpt = n; }
bool getUseEncDbOpt () const { return m_encDbOpt; }
#endif
void setUseFastLCTU ( bool n ) { m_useFastLCTU = n; }
bool getUseFastLCTU () const { return m_useFastLCTU; }
......
......@@ -320,6 +320,9 @@ void EncCu::init( EncLib* pcEncLib, const SPS& sps PARL_PARAM( const int tId ) )
m_pcEncLib = pcEncLib;
m_dataId = tId;
#endif
#if JVET_M0428_ENC_DB_OPT
m_pcLoopFilter = pcEncLib->getLoopFilter();
#endif
#if JVET_M0170_MRG_SHARELIST
m_shareState = NO_SHARE;
m_pcInterSearch->setShareState(0);
......@@ -655,6 +658,9 @@ bool EncCu::xCheckBestMode( CodingStructure *&tempCS, CodingStructure *&bestCS,
std::swap( tempCS, bestCS );
// store temp best CI for next CU coding
m_CurrCtx->best = m_CABACEstimator->getCtx();
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = true;
#endif
bestCSUpdated = true;
}
}
......@@ -1227,7 +1233,14 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
#endif
const double factor = ( tempCS->currQP[partitioner.chType] > 30 ? 1.1 : 1.075 );
#if JVET_M0428_ENC_DB_OPT
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
if (!tempCS->useDbCost)
CHECK(bestCS->costDbOffset != 0, "error");
const double cost = m_pcRdCost->calcRdCost( uint64_t( m_CABACEstimator->getEstFracBits() + ( ( bestCS->fracBits ) / factor ) ), Distortion( bestCS->dist / factor ) ) + bestCS->costDbOffset / factor;
#else
const double cost = m_pcRdCost->calcRdCost( uint64_t( m_CABACEstimator->getEstFracBits() + ( ( bestCS->fracBits ) / factor ) ), Distortion( bestCS->dist / factor ) );
#endif
m_CABACEstimator->getCtx() = SubCtx( Ctx::SplitFlag, ctxStartSP );
#if JVET_M0421_SPLIT_SIG
......@@ -1238,7 +1251,11 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
m_CABACEstimator->getCtx() = SubCtx( Ctx::BTSplitFlag, ctxStartBT );
#endif
#if JVET_M0428_ENC_DB_OPT
if (cost > bestCS->cost + bestCS->costDbOffset)
#else
if( cost > bestCS->cost )
#endif
{
xCheckBestMode( tempCS, bestCS, partitioner, encTestMode );
return;
......@@ -1346,6 +1363,10 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
{
CHECK( split == CU_QUAD_SPLIT, "Split decision reusing cannot skip quad split" );
tempCS->cost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
tempCS->costDbOffset = 0;
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
#endif
m_CurrCtx--;
partitioner.exitCurrSplit();
bool bestCSUpdated =
......@@ -1474,9 +1495,18 @@ void EncCu::xCheckModeSplit(CodingStructure *&tempCS, CodingStructure *&bestCS,
#endif
{
bestCS->cost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
bestCS->costDbOffset = 0;
#endif
}
}
#if JVET_M0428_ENC_DB_OPT
else
{
bestCS->costDbOffset = 0;
}
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
#endif
// RD check for sub partitioned coding structure.
bool bestCSUpdated =
......@@ -1576,6 +1606,10 @@ void EncCu::xCheckRDCostIntra( CodingStructure *&tempCS, CodingStructure *&bestC
tempCS->interHad = interHad;
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
if( isLuma( partitioner.chType ) )
{
#if JVET_M0102_INTRA_SUBPARTITIONS
......@@ -1696,6 +1730,12 @@ void EncCu::xCheckRDCostIntra( CodingStructure *&tempCS, CodingStructure *&bestC
m_modeCtrl->setBestCostWithoutSplitFlags( tmpCostWithoutSplitFlags );
}
#endif
#if JVET_M0428_ENC_DB_OPT
xCalDebCost(*tempCS, partitioner);
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
#endif
#if !JVET_M0464_UNI_MTS
// we save the cost of the modes for the first EMT pass
if( !emtCuFlag ) static_cast< double& >( costSize2Nx2NemtFirstPass ) = tempCS->cost;
......@@ -1795,6 +1835,11 @@ void EncCu::xCheckIntraPCM(CodingStructure *&tempCS, CodingStructure *&bestCS, P
xCheckDQP( *tempCS, partitioner );
#if JVET_M0428_ENC_DB_OPT
xCalDebCost(*tempCS, partitioner);
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
#endif
#if WCG_EXT
DTRACE_MODE_COST( *tempCS, m_pcRdCost->getLambda( true ) );
#else
......@@ -1927,6 +1972,10 @@ void EncCu::xCheckRDCostHashInter( CodingStructure *&tempCS, CodingStructure *&b
const unsigned wIdx = gp_sizeIdxInfo->idxFrom(tempCS->area.lwidth());
double equGBiCost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
#if JVET_M0464_UNI_MTS
xEncodeInterResidual(tempCS, bestCS, partitioner, encTestMode, 0
, m_pImvTempCS ? m_pImvTempCS[wIdx] : NULL
......@@ -1940,6 +1989,11 @@ void EncCu::xCheckRDCostHashInter( CodingStructure *&tempCS, CodingStructure *&b
, &equGBiCost
#endif
);
#if JVET_M0428_ENC_DB_OPT
if (m_bestModeUpdated && bestCS->cost != MAX_DOUBLE)
xCalDebCost(*bestCS, partitioner);
#endif
}
tempCS->initStructData(encTestMode.qp, encTestMode.lossless);
......@@ -2447,7 +2501,9 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
}
}
}
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
#if !JVET_M0253_HASH_ME
const uint32_t iteration = encTestMode.lossless ? 1 : 2;
......@@ -2658,6 +2714,10 @@ void EncCu::xCheckRDCostMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&
}
}
}
#if JVET_M0428_ENC_DB_OPT
if ( m_bestModeUpdated && bestCS->cost != MAX_DOUBLE )
xCalDebCost( *bestCS, partitioner );
#endif
}
void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode )
......@@ -2857,7 +2917,9 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru
tempCS->initStructData( encTestMode.qp, encTestMode.lossless );
}
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
{
#if !JVET_M0253_HASH_ME
const uint8_t iteration = encTestMode.lossless ? 1 : 2;
......@@ -2959,6 +3021,10 @@ void EncCu::xCheckRDCostMergeTriangle2Nx2N( CodingStructure *&tempCS, CodingStru
}// end loop mrgHADIdx
}
}
#if JVET_M0428_ENC_DB_OPT
if ( m_bestModeUpdated && bestCS->cost != MAX_DOUBLE )
xCalDebCost( *bestCS, partitioner );
#endif
}
void EncCu::xCheckRDCostAffineMerge2Nx2N( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode )
......@@ -2972,7 +3038,9 @@ void EncCu::xCheckRDCostAffineMerge2Nx2N( CodingStructure *&tempCS, CodingStruct
{
return;
}
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
const Slice &slice = *tempCS->slice;
CHECK( slice.getSliceType() == I_SLICE, "Affine Merge modes not available for I-slices" );
......@@ -3255,6 +3323,10 @@ void EncCu::xCheckRDCostAffineMerge2Nx2N( CodingStructure *&tempCS, CodingStruct
}
}
}
#if JVET_M0428_ENC_DB_OPT
if (m_bestModeUpdated && bestCS->cost != MAX_DOUBLE)
xCalDebCost(*bestCS, partitioner);
#endif
}
//////////////////////////////////////////////////////////////////////////////////////////////
// ibc merge/skip mode check
......@@ -3439,6 +3511,9 @@ void EncCu::xCheckRDCostIBCModeMerge2Nx2N(CodingStructure *&tempCS, CodingStruct
tempCS->dist = 0;
tempCS->fracBits = 0;
tempCS->cost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
tempCS->costDbOffset = 0;
#endif
tempCS->initStructData(encTestMode.qp, encTestMode.lossless);
return;
}
......@@ -3449,7 +3524,9 @@ void EncCu::xCheckRDCostIBCModeMerge2Nx2N(CodingStructure *&tempCS, CodingStruct
const unsigned int iteration = encTestMode.lossless ? 1 : 2;
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
// 2. Pass: check candidates using full RD test
for (unsigned int numResidualPass = 0; numResidualPass < iteration; numResidualPass++)
{
......@@ -3566,7 +3643,10 @@ void EncCu::xCheckRDCostIBCModeMerge2Nx2N(CodingStructure *&tempCS, CodingStruct
}
}
}
#if JVET_M0428_ENC_DB_OPT
if ( m_bestModeUpdated && bestCS->cost != MAX_DOUBLE )
xCalDebCost( *bestCS, partitioner );
#endif
}
void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner, const EncTestMode& encTestMode)
......@@ -3578,6 +3658,10 @@ void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&best
tempCS->initStructData(encTestMode.qp, encTestMode.lossless);
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
CodingUnit &cu = tempCS->addCU(CS::getArea(*tempCS, tempCS->area, partitioner.chType), partitioner.chType);
partitioner.setCUData(cu);
......@@ -3604,6 +3688,10 @@ void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&best
CU::addPUs(cu);
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
PredictionUnit& pu = *cu.firstPU;
cu.mmvdSkip = false;
pu.mmvdMergeFlag = false;
......@@ -3664,6 +3752,12 @@ void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&best
xCheckDQP(*tempCS, partitioner);
}
#if JVET_M0428_ENC_DB_OPT
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
if ( m_bestModeUpdated )
xCalDebCost( *tempCS, partitioner );
#endif
DTRACE_MODE_COST(*tempCS, m_pcRdCost->getLambda());
xCheckBestMode(tempCS, bestCS, partitioner, encTestMode);
......@@ -3694,6 +3788,9 @@ void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&best
tempCS->dist = 0;
tempCS->fracBits = 0;
tempCS->cost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
tempCS->costDbOffset = 0;
#endif
}
}
#endif
......@@ -3705,6 +3802,9 @@ void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&best
tempCS->dist = 0;
tempCS->fracBits = 0;
tempCS->cost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
tempCS->costDbOffset = 0;
#endif
}
}
// chroma CU ibc comp
......@@ -3755,6 +3855,11 @@ void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&best
xEncodeDontSplit(*tempCS, partitioner);
xCheckDQP(*tempCS, partitioner);
#if JVET_M0428_ENC_DB_OPT
tempCS->useDbCost = m_pcEncCfg->getUseEncDbOpt();
if (m_bestModeUpdated)
xCalDebCost(*tempCS, partitioner);
#endif
DTRACE_MODE_COST(*tempCS, m_pcRdCost->getLambda());
......@@ -3765,6 +3870,9 @@ void EncCu::xCheckRDCostIBCMode(CodingStructure *&tempCS, CodingStructure *&best
tempCS->dist = 0;
tempCS->fracBits = 0;
tempCS->cost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
tempCS->costDbOffset = 0;
#endif
}
}
}
......@@ -3796,6 +3904,10 @@ void EncCu::xCheckRDCostInter( CodingStructure *&tempCS, CodingStructure *&bestC
double curBestCost = bestCS->cost;
double equGBiCost = MAX_DOUBLE;
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
for( int gbiLoopIdx = 0; gbiLoopIdx < gbiLoopNum; gbiLoopIdx++ )
{
if( m_pcEncCfg->getUseGBiFast() )
......@@ -3900,6 +4012,10 @@ void EncCu::xCheckRDCostInter( CodingStructure *&tempCS, CodingStructure *&bestC
break;
}
} // for( UChar gbiLoopIdx = 0; gbiLoopIdx < gbiLoopNum; gbiLoopIdx++ )
#if JVET_M0428_ENC_DB_OPT
if ( m_bestModeUpdated && bestCS->cost != MAX_DOUBLE )
xCalDebCost( *bestCS, partitioner );
#endif
}
......@@ -3914,6 +4030,10 @@ bool EncCu::xCheckRDCostInterIMV( CodingStructure *&tempCS, CodingStructure *&be
CHECK( iIMV != 1 && iIMV != 2 && iIMV != 3, "Unsupported IMV Mode" );
// Fast 4-Pel Mode
#if JVET_M0428_ENC_DB_OPT
m_bestModeUpdated = tempCS->useDbCost = bestCS->useDbCost = false;
#endif
EncTestMode encTestModeBase = encTestMode; // copy for clearing non-IMV options
encTestModeBase.opts = EncTestModeOpts( encTestModeBase.opts & ETO_IMV ); // clear non-IMV options (is that intended?)
......@@ -4157,6 +4277,11 @@ bool EncCu::xCheckRDCostInterIMV( CodingStructure *&tempCS, CodingStructure *&be
#endif
} // for( UChar gbiLoopIdx = 0; gbiLoopIdx < gbiLoopNum; gbiLoopIdx++ )
#if JVET_M0428_ENC_DB_OPT
if ( m_bestModeUpdated && bestCS->cost != MAX_DOUBLE )
xCalDebCost( *bestCS, partitioner );
#endif
#if JVET_M0246_AFFINE_AMVR
return tempCS->slice->getSPS()->getAffineAmvrEnabledFlag() ? validMode : true;
#else
......@@ -4164,6 +4289,230 @@ bool EncCu::xCheckRDCostInterIMV( CodingStructure *&tempCS, CodingStructure *&be
#endif
}
#if JVET_M0428_ENC_DB_OPT
void EncCu::xCalDebCost(CodingStructure &cs, Partitioner &partitioner, bool calDist)
{
if (cs.cost == MAX_DOUBLE)
cs.costDbOffset = 0;
if (cs.slice->getDeblockingFilterDisable() || (!m_pcEncCfg->getUseEncDbOpt() && !calDist))
return;
m_pcLoopFilter->setEnc(true);
const ChromaFormat format = cs.area.chromaFormat;
CodingUnit* cu = cs.getCU(partitioner.chType);
const Position lumaPos = cu->Y().valid() ? cu->Y().pos() : recalcPosition(format, cu->chType, CHANNEL_TYPE_LUMA, cu->blocks[cu->chType].pos());
bool topEdgeAvai = lumaPos.y > 0 && ((lumaPos.y % 8) == 0);
bool leftEdgeAvai = lumaPos.x > 0 && ((lumaPos.x % 8) == 0);
bool anyEdgeAvai = topEdgeAvai || leftEdgeAvai;
cs.costDbOffset = 0;
if (calDist)
{
const UnitArea currCsArea = clipArea(CS::getArea(cs, cs.area, partitioner.chType), *cs.picture);
ComponentID compStr = (CS::isDualITree(cs) && !isLuma(partitioner.chType)) ? COMPONENT_Cb : COMPONENT_Y;
ComponentID compEnd = (CS::isDualITree(cs) && isLuma(partitioner.chType)) ? COMPONENT_Y : COMPONENT_Cr;
Distortion finalDistortion = 0;
for (int comp = compStr; comp <= compEnd; comp++)
{
const ComponentID compID = ComponentID(comp);
CPelBuf org = cs.getOrgBuf(compID);
CPelBuf reco = cs.getRecoBuf(compID);
finalDistortion += getDistortionDb(cs, org, reco, compID, currCsArea.block(compID), false);
}
//updated distortion
cs.dist = finalDistortion;
}
if (anyEdgeAvai && m_pcEncCfg->getUseEncDbOpt())
{