Newer
Older

Karsten Suehring
committed
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, true );
IbcLumaCoverage ibcLumaCoverage = cs.getIbcLumaCoverage(cs.area.Cb());
switch (ibcLumaCoverage)
case IBC_LUMA_COVERAGE_PARTIAL:
// do not check IBC
checkIbc = false;
case IBC_LUMA_COVERAGE_NONE:
// do not check IBC
checkIbc = false;

Karsten Suehring
committed
// Add coding modes here
// NOTE: Working back to front, as a stack, which is more efficient with the container
// NOTE: First added modes will be processed at the end.
//////////////////////////////////////////////////////////////////////////
// Add unit split modes
if( !cuECtx.get<bool>( QT_BEFORE_BT ) )
{
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_QT, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
}
if( partitioner.canSplit( CU_TRIV_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_TT_V, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
}
if( partitioner.canSplit( CU_TRIH_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_TT_H, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
}
if( partitioner.canSplit( CU_VERT_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_BT_V, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().set( DID_VERT_SPLIT, true );
}
else
{
m_ComprCUCtxList.back().set( DID_VERT_SPLIT, false );
}
if( partitioner.canSplit( CU_HORZ_SPLIT, cs ) )
{
// add split modes
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_BT_H, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().set( DID_HORZ_SPLIT, true );
}
else
{
m_ComprCUCtxList.back().set( DID_HORZ_SPLIT, false );
}
if( cuECtx.get<bool>( QT_BEFORE_BT ) )
{
for( int qp = maxQP; qp >= minQP; qp-- )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_SPLIT_QT, ETO_STANDARD, qp, false } );

Karsten Suehring
committed
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
}
}
m_ComprCUCtxList.back().testModes.push_back( { ETM_POST_DONT_SPLIT } );
xGetMinMaxQP( minQP, maxQP, cs, partitioner, baseQP, *cs.sps, *cs.pps, false );
bool useLossless = false;
int lowestQP = minQP;
if( cs.pps->getTransquantBypassEnabledFlag() )
{
useLossless = true; // mark that the first iteration is to cost TQB mode.
minQP = minQP - 1; // increase loop variable range by 1, to allow testing of TQB mode along with other QPs
if( m_pcEncCfg->getCUTransquantBypassFlagForceValue() )
{
maxQP = minQP;
}
}
//////////////////////////////////////////////////////////////////////////
// Add unit coding modes: Intra, InterME, InterMerge ...
for( int qpLoop = maxQP; qpLoop >= minQP; qpLoop-- )
{
const int qp = std::max( qpLoop, lowestQP );
const bool lossless = useLossless && qpLoop == minQP;
const bool isReusingCu = isValid( cs, partitioner, qp );
cuECtx.set( IS_REUSING_CU, isReusingCu );
if( isReusingCu )
{
m_ComprCUCtxList.back().testModes.push_back( {ETM_RECO_CACHED, ETO_STANDARD, qp, lossless} );
}
#endif

Karsten Suehring
committed
// add intra modes
m_ComprCUCtxList.back().testModes.push_back( { ETM_IPCM, ETO_STANDARD, qp, lossless } );
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTRA, ETO_STANDARD, qp, lossless } );
// add ibc mode to intra path
if (cs.sps->getSpsNext().getIBCMode() && checkIbc )
m_ComprCUCtxList.back().testModes.push_back({ ETM_IBC, ETO_STANDARD, qp, lossless });
m_ComprCUCtxList.back().testModes.push_back({ ETM_IBC_MERGE, ETO_STANDARD, qp, lossless });

Karsten Suehring
committed
}
// add first pass modes

Karsten Suehring
committed
{
for( int qpLoop = maxQP; qpLoop >= minQP; qpLoop-- )
{
const int qp = std::max( qpLoop, lowestQP );
const bool lossless = useLossless && qpLoop == minQP;
if( m_pcEncCfg->getIMV() )
{
if( m_pcEncCfg->getIMV() == IMV_4PEL )
{
int imv = m_pcEncCfg->getIMV4PelFast() ? 3 : 2;
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, EncTestModeOpts( imv << ETO_IMV_SHIFT ), qp, lossless } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, EncTestModeOpts( 1 << ETO_IMV_SHIFT ), qp, lossless } );

Karsten Suehring
committed
}
// add inter modes
if( m_pcEncCfg->getUseEarlySkipDetection() )
{
if( cs.sps->getSpsNext().getUseTriangle() && cs.slice->isInterB() )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_TRIANGLE, ETO_STANDARD, qp, lossless } );
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_SKIP, ETO_STANDARD, qp, lossless } );
if ( cs.sps->getSpsNext().getUseAffine() || cs.sps->getSBTMVPEnabledFlag() )

Karsten Suehring
committed
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_AFFINE, ETO_STANDARD, qp, lossless } );

Karsten Suehring
committed
}
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, ETO_STANDARD, qp, lossless } );

Karsten Suehring
committed
}
else
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_INTER_ME, ETO_STANDARD, qp, lossless } );
if( cs.sps->getSpsNext().getUseTriangle() && cs.slice->isInterB() )
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_TRIANGLE, ETO_STANDARD, qp, lossless } );
m_ComprCUCtxList.back().testModes.push_back( { ETM_MERGE_SKIP, ETO_STANDARD, qp, lossless } );
if ( cs.sps->getSpsNext().getUseAffine() || cs.sps->getSBTMVPEnabledFlag() )

Karsten Suehring
committed
{
m_ComprCUCtxList.back().testModes.push_back( { ETM_AFFINE, ETO_STANDARD, qp, lossless } );

Karsten Suehring
committed
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
}
}
}
}
// ensure to skip unprobable modes
if( !tryModeMaster( m_ComprCUCtxList.back().testModes.back(), cs, partitioner ) )
{
nextMode( cs, partitioner );
}
m_ComprCUCtxList.back().lastTestMode = EncTestMode();
}
void EncModeCtrlMTnoRQT::finishCULevel( Partitioner &partitioner )
{
m_ComprCUCtxList.pop_back();
}
bool EncModeCtrlMTnoRQT::tryMode( const EncTestMode& encTestmode, const CodingStructure &cs, Partitioner& partitioner )
{
ComprCUCtx& cuECtx = m_ComprCUCtxList.back();
// Fast checks, partitioning depended
// if early skip detected, skip all modes checking but the splits
if( cuECtx.earlySkip && m_pcEncCfg->getUseEarlySkipDetection() && !isModeSplit( encTestmode ) && !( isModeInter( encTestmode ) ) )

Karsten Suehring
committed
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
{
return false;
}
const PartSplit implicitSplit = partitioner.getImplicitSplit( cs );
const bool isBoundary = implicitSplit != CU_DONT_SPLIT;
if( isBoundary && encTestmode.type != ETM_SPLIT_QT )
{
return getPartSplit( encTestmode ) == implicitSplit;
}
else if( isBoundary && encTestmode.type == ETM_SPLIT_QT )
{
return partitioner.canSplit( CU_QUAD_SPLIT, cs );
}
#if REUSE_CU_RESULTS
if( cuECtx.get<bool>( IS_REUSING_CU ) )
{
if( encTestmode.type == ETM_RECO_CACHED )
{
return true;
}
if( isModeNoSplit( encTestmode ) )
{
return false;
}
}
#endif
const Slice& slice = *m_slice;
const SPS& sps = *slice.getSPS();
const uint32_t numComp = getNumberValidComponents( slice.getSPS()->getChromaFormatIdc() );
const uint32_t width = partitioner.currArea().lumaSize().width;
const CodingStructure *bestCS = cuECtx.bestCS;
const CodingUnit *bestCU = cuECtx.bestCU;
const EncTestMode bestMode = bestCS ? getCSEncMode( *bestCS ) : EncTestMode();
CodedCUInfo &relatedCU = getBlkInfo( partitioner.currArea() );
if( cuECtx.minDepth > partitioner.currQtDepth && partitioner.canSplit( CU_QUAD_SPLIT, cs ) )
{
// enforce QT
return encTestmode.type == ETM_SPLIT_QT;
}
else if( encTestmode.type == ETM_SPLIT_QT && cuECtx.maxDepth <= partitioner.currQtDepth )
{
// don't check this QT depth
return false;
}
if( bestCS && bestCS->cus.size() == 1 )
{
// update the best non-split cost
cuECtx.set( BEST_NON_SPLIT_COST, bestCS->cost );
}
if( encTestmode.type == ETM_INTRA )
{
if( getFastDeltaQp() )
{
if( cs.area.lumaSize().width > cs.pcv->fastDeltaQPCuMaxSize )
{
return false; // only check necessary 2Nx2N Intra in fast delta-QP mode
}
}
if( m_pcEncCfg->getUseFastLCTU() && partitioner.currArea().lumaSize().area() > 4096 )
{
return false;
}
if (CS::isDualITree(cs) && (partitioner.currArea().lumaSize().width > 64 || partitioner.currArea().lumaSize().height > 64))
{
return false;
}
#if IBC_SEPERATE_MODE
if (m_pcEncCfg->getUsePbIntraFast() && (!cs.slice->isIntra() || cs.slice->getSPS()->getSpsNext().getIBCMode()) && !interHadActive(cuECtx) && cuECtx.bestCU && !CU::isIntra(*cuECtx.bestCU))
#else

Karsten Suehring
committed
if( m_pcEncCfg->getUsePbIntraFast() && !cs.slice->isIntra() && !interHadActive( cuECtx ) && cuECtx.bestCU && CU::isInter( *cuECtx.bestCU ) )

Karsten Suehring
committed
{
return false;
}
// INTRA MODES
if (cs.sps->getSpsNext().getIBCMode() && !cuECtx.bestTU)

Karsten Suehring
committed
CHECK( !slice.isIntra() && !cuECtx.bestTU, "No possible non-intra encoding for a P- or B-slice found" );
if( !( slice.isIRAP() || bestMode.type == ETM_INTRA ||
#if IBC_SEPERATE_MODE
((!m_pcEncCfg->getDisableIntraPUsInInterSlices()) && (!relatedCU.isInter || !relatedCU.isIBC) && (
#else
( ( !m_pcEncCfg->getDisableIntraPUsInInterSlices() ) && !relatedCU.isInter && (
#endif

Karsten Suehring
committed
( cuECtx.bestTU->cbf[0] != 0 ) ||
( ( numComp > COMPONENT_Cb ) && cuECtx.bestTU->cbf[1] != 0 ) ||
( ( numComp > COMPONENT_Cr ) && cuECtx.bestTU->cbf[2] != 0 ) // avoid very complex intra if it is unlikely
) ) ) )
{
return false;
}
if ((m_pcEncCfg->getIBCFastMethod() & IBC_FAST_METHOD_NOINTRA_IBCCBF0)
&& (bestMode.type == ETM_IBC || bestMode.type == ETM_IBC_MERGE)
&& (!cuECtx.bestCU->Y().valid() || cuECtx.bestTU->cbf[0] == 0)
&& (!cuECtx.bestCU->Cb().valid() || cuECtx.bestTU->cbf[1] == 0)
&& (!cuECtx.bestCU->Cr().valid() || cuECtx.bestTU->cbf[2] == 0))
{
return false;
}

Karsten Suehring
committed
if( lastTestMode().type != ETM_INTRA && cuECtx.bestCS && cuECtx.bestCU && interHadActive( cuECtx ) )
{
// Get SATD threshold from best Inter-CU
if( !cs.slice->isIRAP() && m_pcEncCfg->getUsePbIntraFast() )

Karsten Suehring
committed
{
CodingUnit* bestCU = cuECtx.bestCU;
#if IBC_SEPERATE_MODE
if (bestCU && !CU::isIntra(*bestCU))
#else

Karsten Suehring
committed
if( bestCU && CU::isInter( *bestCU ) )

Karsten Suehring
committed
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
{
DistParam distParam;
const bool useHad = !bestCU->transQuantBypass;
m_pcRdCost->setDistParam( distParam, cs.getOrgBuf( COMPONENT_Y ), cuECtx.bestCS->getPredBuf( COMPONENT_Y ), cs.sps->getBitDepth( CHANNEL_TYPE_LUMA ), COMPONENT_Y, useHad );
cuECtx.interHad = distParam.distFunc( distParam );
}
}
}
return true;
}
else if( encTestmode.type == ETM_IPCM )
{
if( getFastDeltaQp() )
{
const SPS &sps = *cs.sps;
const uint32_t fastDeltaQPCuMaxPCMSize = Clip3( ( uint32_t ) 1 << sps.getPCMLog2MinSize(), ( uint32_t ) 1 << sps.getPCMLog2MaxSize(), 32u );
if( cs.area.lumaSize().width > fastDeltaQPCuMaxPCMSize )
{
return false; // only check necessary PCM in fast deltaqp mode
}
}
// PCM MODES
return sps.getPCMEnabledFlag() && width <= ( 1 << sps.getPCMLog2MaxSize() ) && width >= ( 1 << sps.getPCMLog2MinSize() );

Karsten Suehring
committed
}
else if (encTestmode.type == ETM_IBC || encTestmode.type == ETM_IBC_MERGE)
// IBC MODES
return sps.getSpsNext().getIBCMode() && width <= IBC_MAX_CAND_SIZE && partitioner.currArea().lumaSize().height <= IBC_MAX_CAND_SIZE;

Karsten Suehring
committed
else if( isModeInter( encTestmode ) )
{
// INTER MODES (ME + MERGE/SKIP)
CHECK( slice.isIntra(), "Inter-mode should not be in the I-Slice mode list!" );
if( getFastDeltaQp() )
{
if( encTestmode.type == ETM_MERGE_SKIP )
{
return false;
}
if( cs.area.lumaSize().width > cs.pcv->fastDeltaQPCuMaxSize )

Karsten Suehring
committed
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
{
return false; // only check necessary 2Nx2N Inter in fast deltaqp mode
}
}
// --- Check if we can quit current mode using SAVE/LOAD coding history
if( encTestmode.type == ETM_INTER_ME )
{
if( encTestmode.opts == ETO_STANDARD )
{
// NOTE: ETO_STANDARD is always done when early SKIP mode detection is enabled
if( !m_pcEncCfg->getUseEarlySkipDetection() )
{
if( relatedCU.isSkip || relatedCU.isIntra )
{
return false;
}
}
}
else if ((encTestmode.opts & ETO_IMV) != 0)
{
int imvOpt = (encTestmode.opts & ETO_IMV) >> ETO_IMV_SHIFT;
if (imvOpt == 3 && cuECtx.get<double>(BEST_NO_IMV_COST) * 1.06 < cuECtx.get<double>(BEST_IMV_COST))
{
return false;
}
}
}
if ( encTestmode.type == ETM_AFFINE && relatedCU.isIntra )
{
return false;
}
if( encTestmode.type == ETM_MERGE_TRIANGLE && ( partitioner.currArea().lumaSize().area() < TRIANGLE_MIN_SIZE || relatedCU.isIntra ) )
{
return false;
}

Karsten Suehring
committed
return true;
}
else if( isModeSplit( encTestmode ) )
{
//////////////////////////////////////////////////////////////////////////
// skip-history rule - don't split further if at least for three past levels
// in the split tree it was found that skip is the best mode
//////////////////////////////////////////////////////////////////////////
int skipScore = 0;
#if IBC_SEPERATE_MODE
if ((!slice.isIntra() || slice.getSPS()->getSpsNext().getIBCMode()) && cuECtx.get<bool>(IS_BEST_NOSPLIT_SKIP))
#else

Karsten Suehring
committed
if( !slice.isIntra() && cuECtx.get<bool>( IS_BEST_NOSPLIT_SKIP ) )

Karsten Suehring
committed
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
{
for( int i = 2; i < m_ComprCUCtxList.size(); i++ )
{
if( ( m_ComprCUCtxList.end() - i )->get<bool>( IS_BEST_NOSPLIT_SKIP ) )
{
skipScore += 1;
}
else
{
break;
}
}
}
const PartSplit split = getPartSplit( encTestmode );
if( !partitioner.canSplit( split, cs ) || skipScore >= 2 )
{
if( split == CU_HORZ_SPLIT ) cuECtx.set( DID_HORZ_SPLIT, false );
if( split == CU_VERT_SPLIT ) cuECtx.set( DID_VERT_SPLIT, false );
if( split == CU_QUAD_SPLIT ) cuECtx.set( DID_QUAD_SPLIT, false );
return false;
}
if( m_pcEncCfg->getUseContentBasedFastQtbt() )
{
const CompArea& currArea = partitioner.currArea().Y();
int cuHeight = currArea.height;
int cuWidth = currArea.width;
const bool condIntraInter = m_pcEncCfg->getIntraPeriod() == 1 ? ( partitioner.currBtDepth == 0 ) : ( cuHeight > 32 && cuWidth > 32 );
if( cuWidth == cuHeight && condIntraInter && getPartSplit( encTestmode ) != CU_QUAD_SPLIT )
{
const CPelBuf bufCurrArea = cs.getOrgBuf( partitioner.currArea().block( COMPONENT_Y ) );
double horVal = 0;
double verVal = 0;
double dupVal = 0;
double dowVal = 0;
const double th = m_pcEncCfg->getIntraPeriod() == 1 ? 1.2 : 1.0;
unsigned j, k;
for( j = 0; j < cuWidth - 1; j++ )
{
for( k = 0; k < cuHeight - 1; k++ )
{
horVal += abs( bufCurrArea.at( j + 1, k ) - bufCurrArea.at( j, k ) );
verVal += abs( bufCurrArea.at( j , k + 1 ) - bufCurrArea.at( j, k ) );
dowVal += abs( bufCurrArea.at( j + 1, k ) - bufCurrArea.at( j, k + 1 ) );
dupVal += abs( bufCurrArea.at( j + 1, k + 1 ) - bufCurrArea.at( j, k ) );
}
}
if( horVal > th * verVal && sqrt( 2 ) * horVal > th * dowVal && sqrt( 2 ) * horVal > th * dupVal && ( getPartSplit( encTestmode ) == CU_HORZ_SPLIT || getPartSplit( encTestmode ) == CU_TRIH_SPLIT ) )
{
return false;
}
if( th * dupVal < sqrt( 2 ) * verVal && th * dowVal < sqrt( 2 ) * verVal && th * horVal < verVal && ( getPartSplit( encTestmode ) == CU_VERT_SPLIT || getPartSplit( encTestmode ) == CU_TRIV_SPLIT ) )
{
return false;
}
}
if( m_pcEncCfg->getIntraPeriod() == 1 && cuWidth <= 32 && cuHeight <= 32 && bestCS && bestCS->tus.size() == 1 && bestCU && bestCU->depth == partitioner.currDepth && partitioner.currBtDepth > 1 && isLuma( partitioner.chType ) )
{
if( !bestCU->rootCbf )
{
return false;
}
}
}
if( bestCU && bestCU->skip && bestCU->mtDepth >= m_skipThreshold && !isModeSplit( cuECtx.lastTestMode ) )
{
return false;
}
int featureToSet = -1;
switch( getPartSplit( encTestmode ) )
{
case CU_QUAD_SPLIT:
{
#if ENABLE_SPLIT_PARALLELISM
if( !cuECtx.isLevelSplitParallel )
#endif
if( !cuECtx.get<bool>( QT_BEFORE_BT ) && bestCU )
{
unsigned maxBTD = cs.pcv->getMaxBtDepth( slice, partitioner.chType );
const CodingUnit *cuBR = bestCS->cus.back();
unsigned height = partitioner.currArea().lumaSize().height;

Karsten Suehring
committed
#if IBC_SEPERATE_MODE
if (bestCU && ((bestCU->btDepth == 0 && maxBTD >= ((slice.isIntra() && !slice.getSPS()->getSpsNext().getIBCMode()) ? 3 : 2))
|| (bestCU->btDepth == 1 && cuBR && cuBR->btDepth == 1 && maxBTD >= ((slice.isIntra() && !slice.getSPS()->getSpsNext().getIBCMode()) ? 4 : 3)))
&& (width <= MAX_TU_SIZE_FOR_PROFILE && height <= MAX_TU_SIZE_FOR_PROFILE)
&& cuECtx.get<bool>(DID_HORZ_SPLIT) && cuECtx.get<bool>(DID_VERT_SPLIT))
{
return false;
}
#else

Karsten Suehring
committed
if( bestCU && ( ( bestCU->btDepth == 0 && maxBTD >= ( slice.isIntra() ? 3 : 2 ) )
|| ( bestCU->btDepth == 1 && cuBR && cuBR->btDepth == 1 && maxBTD >= ( slice.isIntra() ? 4 : 3 ) ) )
Xiang Li
committed
&& ( width <= MAX_TU_SIZE_FOR_PROFILE && height <= MAX_TU_SIZE_FOR_PROFILE )

Karsten Suehring
committed
&& cuECtx.get<bool>( DID_HORZ_SPLIT ) && cuECtx.get<bool>( DID_VERT_SPLIT ) )
{
return false;
}

Karsten Suehring
committed
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
}
if( m_pcEncCfg->getUseEarlyCU() && bestCS->cost != MAX_DOUBLE && bestCU && bestCU->skip )
{
return false;
}
if( getFastDeltaQp() && width <= slice.getPPS()->pcv->fastDeltaQPCuMaxSize )
{
return false;
}
}
break;
case CU_HORZ_SPLIT:
featureToSet = DID_HORZ_SPLIT;
break;
case CU_VERT_SPLIT:
featureToSet = DID_VERT_SPLIT;
break;
case CU_TRIH_SPLIT:
if( cuECtx.get<bool>( DID_HORZ_SPLIT ) && bestCU && bestCU->btDepth == partitioner.currBtDepth && !bestCU->rootCbf )
{
return false;
}
if( !cuECtx.get<bool>( DO_TRIH_SPLIT ) )
{
return false;
}
break;
case CU_TRIV_SPLIT:
if( cuECtx.get<bool>( DID_VERT_SPLIT ) && bestCU && bestCU->btDepth == partitioner.currBtDepth && !bestCU->rootCbf )
{
return false;
}
if( !cuECtx.get<bool>( DO_TRIV_SPLIT ) )
{
return false;
}
break;
default:
THROW( "Only CU split modes are governed by the EncModeCtrl" );
return false;
break;
}
switch( split )
{
case CU_HORZ_SPLIT:
case CU_TRIH_SPLIT:
if( cuECtx.get<bool>( QT_BEFORE_BT ) && cuECtx.get<bool>( DID_QUAD_SPLIT ) )
{
if( cuECtx.get<int>( MAX_QT_SUB_DEPTH ) > partitioner.currQtDepth + 1 )
{
if( featureToSet >= 0 ) cuECtx.set( featureToSet, false );
return false;
}
}
break;
case CU_VERT_SPLIT:
case CU_TRIV_SPLIT:
if( cuECtx.get<bool>( QT_BEFORE_BT ) && cuECtx.get<bool>( DID_QUAD_SPLIT ) )
{
if( cuECtx.get<int>( MAX_QT_SUB_DEPTH ) > partitioner.currQtDepth + 1 )
{
if( featureToSet >= 0 ) cuECtx.set( featureToSet, false );
return false;
}
}
break;
default:
break;
}
if( split == CU_QUAD_SPLIT ) cuECtx.set( DID_QUAD_SPLIT, true );
return true;
}
else
{
CHECK( encTestmode.type != ETM_POST_DONT_SPLIT, "Unknown mode" );
if( !bestCS || ( bestCS && isModeSplit( bestMode ) ) )
{
return false;
}
else
{
#if REUSE_CU_RESULTS
setFromCs( *bestCS, partitioner );
#endif
// assume the non-split modes are done and set the marks for the best found mode
if( bestCS && bestCU )
{
if( CU::isInter( *bestCU ) )
{
relatedCU.isInter = true;
#if HM_CODED_CU_INFO
relatedCU.isSkip |= bestCU->skip;
relatedCU.isMMVDSkip |= bestCU->mmvdSkip;

Karsten Suehring
committed
#else
relatedCU.isSkip = bestCU->skip;
#endif
relatedCU.GBiIdx = bestCU->GBiIdx;

Karsten Suehring
committed
}
#if IBC_SEPERATE_MODE//Todo : macro hm_code_cu_info
else if (CU::isIBC(*bestCU))
{
relatedCU.isIBC = true;
#if HM_CODED_CU_INFO
relatedCU.isSkip |= bestCU->skip;
#endif
}
#endif

Karsten Suehring
committed
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
else if( CU::isIntra( *bestCU ) )
{
relatedCU.isIntra = true;
}
#if ENABLE_SPLIT_PARALLELISM
touch( partitioner.currArea() );
#endif
cuECtx.set( IS_BEST_NOSPLIT_SKIP, bestCU->skip );
}
}
return false;
}
}
bool EncModeCtrlMTnoRQT::useModeResult( const EncTestMode& encTestmode, CodingStructure*& tempCS, Partitioner& partitioner )
{
xExtractFeatures( encTestmode, *tempCS );
ComprCUCtx& cuECtx = m_ComprCUCtxList.back();
if( encTestmode.type == ETM_SPLIT_BT_H )
{
cuECtx.set( BEST_HORZ_SPLIT_COST, tempCS->cost );
}
else if( encTestmode.type == ETM_SPLIT_BT_V )
{
cuECtx.set( BEST_VERT_SPLIT_COST, tempCS->cost );
}
else if( encTestmode.type == ETM_SPLIT_TT_H )
{
cuECtx.set( BEST_TRIH_SPLIT_COST, tempCS->cost );
}
else if( encTestmode.type == ETM_SPLIT_TT_V )
{
cuECtx.set( BEST_TRIV_SPLIT_COST, tempCS->cost );
}

Karsten Suehring
committed
{
const CodingUnit cu = *tempCS->getCU( partitioner.chType );
if( !cu.emtFlag )
{
cuECtx.bestEmtSize2Nx2N1stPass = tempCS->cost;
}
}

Karsten Suehring
committed
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
if( m_pcEncCfg->getIMV4PelFast() && m_pcEncCfg->getIMV() && encTestmode.type == ETM_INTER_ME )
{
int imvMode = ( encTestmode.opts & ETO_IMV ) >> ETO_IMV_SHIFT;
if( imvMode == 1 )
{
if( tempCS->cost < cuECtx.get<double>( BEST_IMV_COST ) )
{
cuECtx.set( BEST_IMV_COST, tempCS->cost );
}
}
else if( imvMode == 0 )
{
if( tempCS->cost < cuECtx.get<double>( BEST_NO_IMV_COST ) )
{
cuECtx.set( BEST_NO_IMV_COST, tempCS->cost );
}
}
}
if( encTestmode.type == ETM_SPLIT_QT )
{
int maxQtD = 0;
for( const auto& cu : tempCS->cus )
{
maxQtD = std::max<int>( maxQtD, cu->qtDepth );
}
cuECtx.set( MAX_QT_SUB_DEPTH, maxQtD );
}
if( ( tempCS->sps->getSpsNext().getMTTMode() & 1 ) == 1 )
{
int maxMtD = tempCS->pcv->getMaxBtDepth( *tempCS->slice, partitioner.chType ) + partitioner.currImplicitBtDepth;
if( encTestmode.type == ETM_SPLIT_BT_H )
{
if( tempCS->cus.size() > 2 )
{
int h_2 = tempCS->area.blocks[partitioner.chType].height / 2;
int cu1_h = tempCS->cus.front()->blocks[partitioner.chType].height;
int cu2_h = tempCS->cus.back() ->blocks[partitioner.chType].height;
cuECtx.set( DO_TRIH_SPLIT, cu1_h < h_2 || cu2_h < h_2 || partitioner.currMtDepth + 1 == maxMtD );
}
}
else if( encTestmode.type == ETM_SPLIT_BT_V )
{
if( tempCS->cus.size() > 2 )
{
int w_2 = tempCS->area.blocks[partitioner.chType].width / 2;
int cu1_w = tempCS->cus.front()->blocks[partitioner.chType].width;
int cu2_w = tempCS->cus.back() ->blocks[partitioner.chType].width;
cuECtx.set( DO_TRIV_SPLIT, cu1_w < w_2 || cu2_w < w_2 || partitioner.currMtDepth + 1 == maxMtD );
}
}
}
// for now just a simple decision based on RD-cost or choose tempCS if bestCS is not yet coded
if( !cuECtx.bestCS || tempCS->features[ENC_FT_RD_COST] < cuECtx.bestCS->features[ENC_FT_RD_COST] )
{
cuECtx.bestCS = tempCS;
cuECtx.bestCU = tempCS->cus[0];
cuECtx.bestTU = cuECtx.bestCU->firstTU;
if( isModeInter( encTestmode ) )
{
//Here we take the best cost of both inter modes. We are assuming only the inter modes (and all of them) have come before the intra modes!!!
cuECtx.bestInterCost = cuECtx.bestCS->cost;
}
return true;
}
else
{
return false;
}
}
#if ENABLE_SPLIT_PARALLELISM
void EncModeCtrlMTnoRQT::copyState( const EncModeCtrl& other, const UnitArea& area )
{
const EncModeCtrlMTnoRQT* pOther = dynamic_cast<const EncModeCtrlMTnoRQT*>( &other );
CHECK( !pOther, "Trying to copy state from a different type of controller" );
this->EncModeCtrl ::copyState( *pOther, area );
this->CacheBlkInfoCtrl ::copyState( *pOther, area );
m_skipThreshold = pOther->m_skipThreshold;
}
int EncModeCtrlMTnoRQT::getNumParallelJobs( const CodingStructure &cs, Partitioner& partitioner ) const
{
int numJobs = 1; // for no-split coding
if( partitioner.canSplit( CU_QUAD_SPLIT, cs ) )
{
numJobs = 2;
}
if( partitioner.canSplit( CU_VERT_SPLIT, cs ) )
{
numJobs = 3;
}
if( partitioner.canSplit( CU_HORZ_SPLIT, cs ) )
{
numJobs = 4;
}
if( partitioner.canSplit( CU_TRIV_SPLIT, cs ) )
{
numJobs = 5;
}
if( partitioner.canSplit( CU_TRIH_SPLIT, cs ) )
{
numJobs = 6;
}
CHECK( numJobs >= NUM_RESERVERD_SPLIT_JOBS, "More jobs specified than allowed" );
return numJobs;
}
bool EncModeCtrlMTnoRQT::isParallelSplit( const CodingStructure &cs, Partitioner& partitioner ) const
{
if( partitioner.getImplicitSplit( cs ) != CU_DONT_SPLIT || cs.picture->scheduler.getSplitJobId() != 0 ) return false;
const int numJobs = getNumParallelJobs( cs, partitioner );
const int numPxl = partitioner.currArea().Y().area();
const int parlAt = m_pcEncCfg->getNumSplitThreads() <= 3 ? 1024 : 256;
if( cs.slice->isIntra() && numJobs > 2 && ( numPxl == parlAt || !partitioner.canSplit( CU_QUAD_SPLIT, cs ) ) ) return true;
if( !cs.slice->isIntra() && numJobs > 1 && ( numPxl == parlAt || !partitioner.canSplit( CU_QUAD_SPLIT, cs ) ) ) return true;
return false;
}
bool EncModeCtrlMTnoRQT::parallelJobSelector( const EncTestMode& encTestmode, const CodingStructure &cs, Partitioner& partitioner ) const
{
// Job descriptors
// - 1: all non-split modes
// - 2: QT-split
// - 3: all vertical modes but TT_V
// - 4: all horizontal modes but TT_H
// - 5: TT_V
// - 6: TT_H
switch( cs.picture->scheduler.getSplitJobId() )
{
case 1:
// be sure to execute post dont split
return !isModeSplit( encTestmode );
break;
case 2:
return encTestmode.type == ETM_SPLIT_QT;
break;
case 3:
switch( encTestmode.type )
{
case ETM_SPLIT_BT_V:
return true;
break;
default:
return false;
break;
}
break;
case 4:
switch( encTestmode.type )
{
case ETM_SPLIT_BT_H:
return true;
break;
default:
return false;
break;
}
break;
case 5:
return encTestmode.type == ETM_SPLIT_TT_V;
break;
case 6:
return encTestmode.type == ETM_SPLIT_TT_H;
break;
default:
THROW( "Unknown job-ID for parallelization of EncModeCtrlMTnoRQT: " << cs.picture->scheduler.getSplitJobId() );
break;
}
}
#endif