From 5e7c70d2d25e029ecb35cb59c2f42fd8b35bcbc0 Mon Sep 17 00:00:00 2001 From: Alexey Filippov <alexey.filippov@huawei.com> Date: Sun, 7 Apr 2019 21:04:24 +0300 Subject: [PATCH] cShift-related modifications and macro-related clean-up in UnitTools.cpp --- source/Lib/CommonLib/RdCost.cpp | 77 +++++++++++++++++++++------ source/Lib/CommonLib/RdCost.h | 15 +++++- source/Lib/CommonLib/TypeDef.h | 8 +-- source/Lib/CommonLib/UnitTools.cpp | 6 +-- source/Lib/EncoderLib/EncCu.cpp | 6 +++ source/Lib/EncoderLib/InterSearch.cpp | 8 +++ source/Lib/EncoderLib/IntraSearch.cpp | 3 ++ 7 files changed, 99 insertions(+), 24 deletions(-) diff --git a/source/Lib/CommonLib/RdCost.cpp b/source/Lib/CommonLib/RdCost.cpp index fe4b62f78..202f55456 100644 --- a/source/Lib/CommonLib/RdCost.cpp +++ b/source/Lib/CommonLib/RdCost.cpp @@ -380,6 +380,10 @@ Distortion RdCost::getDistPart( const CPelBuf &org, const CPelBuf &cur, int bitD #if WCG_EXT if( orgLuma ) { +#if JVET_N0671_RDCOST_FIX + cDtParam.cShiftX = getComponentScaleX(compID, m_cf); + cDtParam.cShiftY = getComponentScaleY(compID, m_cf); +#endif if( isChroma(compID) ) { cDtParam.orgLuma = *orgLuma; @@ -3025,9 +3029,10 @@ Distortion RdCost::xGetSSE_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const int iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const int cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else - const int cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY + const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif Distortion uiSum = 0; @@ -3040,7 +3045,12 @@ Distortion RdCost::xGetSSE_WTD( const DistParam &rcDtParam ) } piOrg += iStrideOrg; piCur += iStrideCur; + +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } @@ -3061,9 +3071,10 @@ Distortion RdCost::xGetSSE2_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const size_t iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const size_t cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else - const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY + const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif Distortion uiSum = 0; @@ -3074,7 +3085,11 @@ Distortion RdCost::xGetSSE2_WTD( const DistParam &rcDtParam ) uiSum += getWeightedMSE(rcDtParam.compID, piOrg[1 ], piCur[1 ], uiShift, piOrgLuma[size_t(1)<<cShift]); // piOrg[1] - piCur[1]; uiSum += Distortion(( iTemp * iTemp ) >> uiShift); piOrg += iStrideOrg; piCur += iStrideCur; +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } @@ -3095,9 +3110,10 @@ Distortion RdCost::xGetSSE4_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const size_t iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const size_t cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else - const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY + const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif Distortion uiSum = 0; @@ -3110,7 +3126,11 @@ Distortion RdCost::xGetSSE4_WTD( const DistParam &rcDtParam ) uiSum += getWeightedMSE(rcDtParam.compID, piOrg[3 ], piCur[3 ], uiShift, piOrgLuma[size_t(3)<<cShift] ); // piOrg[3] - piCur[3]; uiSum += Distortion(( iTemp * iTemp ) >> uiShift); piOrg += iStrideOrg; piCur += iStrideCur; +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } @@ -3131,9 +3151,10 @@ Distortion RdCost::xGetSSE8_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const size_t iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const size_t cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else - const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY + const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif Distortion uiSum = 0; @@ -3150,7 +3171,11 @@ Distortion RdCost::xGetSSE8_WTD( const DistParam &rcDtParam ) uiSum += getWeightedMSE(rcDtParam.compID, piOrg[7 ], piCur[7 ], uiShift, piOrgLuma[size_t(7)<<cShift ]); // piOrg[7] - piCur[7]; uiSum += Distortion(( iTemp * iTemp ) >> uiShift); piOrg += iStrideOrg; piCur += iStrideCur; +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } @@ -3170,9 +3195,10 @@ Distortion RdCost::xGetSSE16_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const size_t iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const size_t cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else - const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY + const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif Distortion uiSum = 0; uint32_t uiShift = DISTORTION_PRECISION_ADJUSTMENT(rcDtParam.bitDepth) << 1; @@ -3196,7 +3222,12 @@ Distortion RdCost::xGetSSE16_WTD( const DistParam &rcDtParam ) uiSum += getWeightedMSE(rcDtParam.compID, piOrg[15 ], piCur[15 ], uiShift, piOrgLuma[size_t(15)<<cShift ]); //piOrg[15] - piCur[15]; uiSum += Distortion(( iTemp * iTemp ) >> uiShift); piOrg += iStrideOrg; piCur += iStrideCur; + +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } @@ -3216,9 +3247,10 @@ Distortion RdCost::xGetSSE16N_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const size_t iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const size_t cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else - const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY + const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif Distortion uiSum = 0; uint32_t uiShift = DISTORTION_PRECISION_ADJUSTMENT(rcDtParam.bitDepth) << 1; @@ -3245,7 +3277,11 @@ Distortion RdCost::xGetSSE16N_WTD( const DistParam &rcDtParam ) } piOrg += iStrideOrg; piCur += iStrideCur; +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } @@ -3265,9 +3301,10 @@ Distortion RdCost::xGetSSE32_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const size_t iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const size_t cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else - const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY + const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif Distortion uiSum = 0; @@ -3308,7 +3345,11 @@ Distortion RdCost::xGetSSE32_WTD( const DistParam &rcDtParam ) uiSum += getWeightedMSE(rcDtParam.compID, piOrg[31], piCur[31], uiShift, piOrgLuma[size_t(31)<<cShift ]); // iTemp = piOrg[31] - piCur[31]; uiSum += Distortion(( iTemp * iTemp ) >> uiShift); piOrg += iStrideOrg; piCur += iStrideCur; +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } @@ -3328,7 +3369,8 @@ Distortion RdCost::xGetSSE64_WTD( const DistParam &rcDtParam ) const Pel* piOrgLuma = rcDtParam.orgLuma.buf; const size_t iStrideOrgLuma = rcDtParam.orgLuma.stride; #if JVET_N0671_RDCOST_FIX - const size_t cShift = 0; + const size_t cShift = rcDtParam.cShiftX; + const size_t cShiftY = rcDtParam.cShiftY; #else const size_t cShift = (rcDtParam.compID==COMPONENT_Y) ? 0 : 1; // assume 420, could use getComponentScaleX, getComponentScaleY #endif @@ -3403,7 +3445,12 @@ Distortion RdCost::xGetSSE64_WTD( const DistParam &rcDtParam ) uiSum += getWeightedMSE(rcDtParam.compID, piOrg[63], piCur[63], uiShift, piOrgLuma[size_t(63)<<cShift]); // iTemp = piOrg[63] - piCur[63]; uiSum += Distortion(( iTemp * iTemp ) >> uiShift); piOrg += iStrideOrg; piCur += iStrideCur; + +#if JVET_N0671_RDCOST_FIX + piOrgLuma += iStrideOrgLuma<<cShiftY; +#else piOrgLuma += iStrideOrgLuma<<cShift; +#endif } return ( uiSum ); } diff --git a/source/Lib/CommonLib/RdCost.h b/source/Lib/CommonLib/RdCost.h index 22e5b1b68..5523d62c9 100644 --- a/source/Lib/CommonLib/RdCost.h +++ b/source/Lib/CommonLib/RdCost.h @@ -87,10 +87,15 @@ public: // (vertical) subsampling shift (for reducing complexity) // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc. int subShift; - +#if JVET_N0671_RDCOST_FIX + int cShiftX; + int cShiftY; +#endif DistParam() : org(), cur(), step( 1 ), bitDepth( 0 ), useMR( false ), applyWeight( false ), isBiPred( false ), wpCur( nullptr ), compID( MAX_NUM_COMPONENT ), maximumDistortionForEarlyExit( std::numeric_limits<Distortion>::max() ), subShift( 0 ) - +#if JVET_N0671_RDCOST_FIX + , cShiftX(-1), cShiftY(-1) +#endif { } }; @@ -112,6 +117,9 @@ private: static uint32_t m_signalType; static double m_chromaWeight; static int m_lumaBD; +#if JVET_N0671_RDCOST_FIX + ChromaFormat m_cf; +#endif // JVET_N0671_RDCOST_FIX #endif double m_DistScale; double m_dLambdaMotionSAD[2 /* 0=standard, 1=for transquant bypass when mixed-lossless cost evaluation enabled*/]; @@ -128,6 +136,9 @@ public: virtual ~RdCost(); #if WCG_EXT +#if JVET_N0671_RDCOST_FIX + void setChromaFormat ( const ChromaFormat & _cf) { m_cf = _cf; } +#endif double calcRdCost ( uint64_t fracBits, Distortion distortion, bool useUnadjustedLambda = true ); #else double calcRdCost ( uint64_t fracBits, Distortion distortion ); diff --git a/source/Lib/CommonLib/TypeDef.h b/source/Lib/CommonLib/TypeDef.h index 2ce1e1f73..848259148 100644 --- a/source/Lib/CommonLib/TypeDef.h +++ b/source/Lib/CommonLib/TypeDef.h @@ -50,6 +50,10 @@ #include <assert.h> #include <cassert> +#define JVET_N0470_SMVD_FIX 1 // remove mvd_l1_zero_flag condition, align to spec text. + +#define JVET_N0235_SMVD_SPS 1 + #define JVET_N0671 1 #if JVET_N0671 @@ -65,10 +69,6 @@ #endif //JVET_N0671 -#define JVET_N0470_SMVD_FIX 1 // remove mvd_l1_zero_flag condition, align to spec text. - -#define JVET_N0235_SMVD_SPS 1 - #define JVET_N0843_BVP_SIMPLIFICATION 1 #define JVET_N0448_N0380 1 // When MaxNumMergeCand is 1, MMVD_BASE_MV_NUM is inferred to be 1. diff --git a/source/Lib/CommonLib/UnitTools.cpp b/source/Lib/CommonLib/UnitTools.cpp index ec5d36eca..d0050c240 100644 --- a/source/Lib/CommonLib/UnitTools.cpp +++ b/source/Lib/CommonLib/UnitTools.cpp @@ -987,11 +987,11 @@ uint32_t PU::getFinalIntraMode( const PredictionUnit &pu, const ChannelType &chT uiIntraMode = lumaPU.intraDir[0]; } - if( pu.chromaFormat == CHROMA_422 && !isLuma( chType ) #if JVET_N0671_CHROMA_FORMAT_422 - && uiIntraMode < NUM_LUMA_MODE + if( pu.chromaFormat == CHROMA_422 && !isLuma( chType ) && uiIntraMode < NUM_LUMA_MODE ) // map directional, planar and dc +#else + if( pu.chromaFormat == CHROMA_422 && !isLuma( chType ) ) #endif //JVET_N0671_CHROMA_FORMAT_422 - ) // map directional, planar and dc { uiIntraMode = g_chroma422IntraAngleMappingTable[uiIntraMode]; } diff --git a/source/Lib/EncoderLib/EncCu.cpp b/source/Lib/EncoderLib/EncCu.cpp index c5e361b80..3d0f61a4d 100644 --- a/source/Lib/EncoderLib/EncCu.cpp +++ b/source/Lib/EncoderLib/EncCu.cpp @@ -3707,6 +3707,9 @@ Distortion EncCu::getDistortionDb( CodingStructure &cs, CPelBuf org, CPelBuf rec { Distortion dist = 0; #if WCG_EXT +#if JVET_N0671_RDCOST_FIX + m_pcRdCost->setChromaFormat(cs.sps->getChromaFormatIdc()); +#endif CPelBuf orgLuma = cs.picture->getOrigBuf( cs.area.blocks[COMPONENT_Y] ); if ( m_pcEncCfg->getLumaLevelToDeltaQPMapping().isEnabled() || ( m_pcEncCfg->getReshaper() && ( cs.slice->getReshapeInfo().getUseSliceReshaper() && m_pcReshape->getCTUFlag() ) ) ) @@ -4140,6 +4143,9 @@ void EncCu::xEncodeDontSplit( CodingStructure &cs, Partitioner &partitioner ) #if REUSE_CU_RESULTS void EncCu::xReuseCachedResult( CodingStructure *&tempCS, CodingStructure *&bestCS, Partitioner &partitioner ) { +#if JVET_N0671_RDCOST_FIX + m_pcRdCost->setChromaFormat(tempCS->sps->getChromaFormatIdc()); +#endif BestEncInfoCache* bestEncCache = dynamic_cast<BestEncInfoCache*>( m_modeCtrl ); CHECK( !bestEncCache, "If this mode is chosen, mode controller has to implement the mode caching capabilities" ); EncTestMode cachedMode; diff --git a/source/Lib/EncoderLib/InterSearch.cpp b/source/Lib/EncoderLib/InterSearch.cpp index 51079bb74..af871b34e 100644 --- a/source/Lib/EncoderLib/InterSearch.cpp +++ b/source/Lib/EncoderLib/InterSearch.cpp @@ -6287,6 +6287,10 @@ void InterSearch::xEstimateInterResidualQT(CodingStructure &cs, Partitioner &par { const UnitArea& currArea = partitioner.currArea(); const SPS &sps = *cs.sps; +#if JVET_N0671_RDCOST_FIX + m_pcRdCost->setChromaFormat(sps.getChromaFormatIdc()); +#endif + const uint32_t numValidComp = getNumberValidComponents( sps.getChromaFormatIdc() ); const uint32_t numTBlocks = getNumberValidTBlocks ( *cs.pcv ); const CodingUnit &cu = *cs.getCU(partitioner.chType); @@ -6921,6 +6925,10 @@ void InterSearch::encodeResAndCalcRdInterCU(CodingStructure &cs, Partitioner &pa , const bool luma, const bool chroma ) { +#if JVET_N0671_RDCOST_FIX + m_pcRdCost->setChromaFormat(cs.sps->getChromaFormatIdc()); +#endif + CodingUnit &cu = *cs.getCU( partitioner.chType ); const ChromaFormat format = cs.area.chromaFormat;; diff --git a/source/Lib/EncoderLib/IntraSearch.cpp b/source/Lib/EncoderLib/IntraSearch.cpp index 141da8b2c..258b886a8 100644 --- a/source/Lib/EncoderLib/IntraSearch.cpp +++ b/source/Lib/EncoderLib/IntraSearch.cpp @@ -1581,6 +1581,9 @@ void IntraSearch::xIntraCodingTUBlock(TransformUnit &tu, const ComponentID &comp } CodingStructure &cs = *tu.cs; +#if JVET_N0671_RDCOST_FIX + m_pcRdCost->setChromaFormat(cs.sps->getChromaFormatIdc()); +#endif const CompArea &area = tu.blocks[compID]; const SPS &sps = *cs.sps; -- GitLab