[x265] [PATCH RFC] psyrd: use psyrdcost for selecting best mode across depth
# HG changeset patch # User Sumalatha Polureddysumala...@multicorewareinc.com # Date 1401087565 -19800 # Node ID cbe5cc0e48b4122518ca732a1b32de16ba25c467 # Parent 5134e76aa729b6fece18701fdc00390c2f2ffb32 psyrd: use psyrdcost for selecting best mode across depth diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibCommon/TComDataCU.cpp --- a/source/Lib/TLibCommon/TComDataCU.cpp Thu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibCommon/TComDataCU.cpp Mon May 26 12:29:25 2014 +0530 @@ -218,6 +218,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= pic-getNumPartInCU(); char* qp = pic-getCU(getAddr())-getQP(); m_baseQp = pic-getCU(getAddr())-m_baseQp; @@ -309,6 +310,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; uint8_t cuSize = g_maxCUSize depth; @@ -345,6 +347,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; uint8_t cuSize = g_maxCUSize depth; @@ -393,6 +396,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; for (int i = 0; i 4; i++) @@ -457,6 +461,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; for (int i = 0; i 4; i++) @@ -520,6 +525,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; TComDataCU* rpcCU = m_pic-getCU(m_cuAddr); @@ -550,6 +556,7 @@ m_totalDistortion += cu-m_totalDistortion; m_totalBits+= cu-m_totalBits; +m_psyCost += cu-m_psyCost; uint32_t offset = cu-getTotalNumPart() * partUnitIdx; uint32_t numPartition = cu-getTotalNumPart(); @@ -610,6 +617,7 @@ rpcCU-m_totalCost = m_totalCost; rpcCU-m_totalDistortion = m_totalDistortion; rpcCU-m_totalBits = m_totalBits; +rpcCU-m_psyCost = m_psyCost; int sizeInBool = sizeof(bool) * m_numPartitions; int sizeInChar = sizeof(char) * m_numPartitions; @@ -695,6 +703,7 @@ cu-m_totalCost = m_totalCost; cu-m_totalDistortion = m_totalDistortion; cu-m_totalBits = m_totalBits; +cu-m_psyCost = m_psyCost; int sizeInBool = sizeof(bool) * qNumPart; int sizeInChar = sizeof(char) * qNumPart; diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibCommon/TComDataCU.h --- a/source/Lib/TLibCommon/TComDataCU.hThu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibCommon/TComDataCU.hMon May 26 12:29:25 2014 +0530 @@ -168,6 +168,7 @@ uint64_t m_totalCost; /// sum of partition RD costs uint32_t m_totalDistortion; /// sum of partition distortion uint32_t m_totalBits; /// sum of partition signal bits +uint32_t m_psyCost; uint64_t m_avgCost[4]; // stores the avg cost of CU's in frame for each depth uint32_t m_count[4]; uint64_t m_sa8dCost; diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibEncoder/TEncCu.cpp --- a/source/Lib/TLibEncoder/TEncCu.cpp Thu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibEncoder/TEncCu.cpp Mon May 26 12:29:25 2014 +0530 @@ -601,7 +601,14 @@ m_entropyCoder-resetBits(); m_entropyCoder-encodeSplitFlag(outBestCU, 0, depth); outBestCU-m_totalBits += m_entropyCoder-getNumberOfWrittenBits(); // split bits -outBestCU-m_totalCost = m_rdCost-calcRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits); +if (m_rdCost-psyRdEnabled()) +{ +outBestCU-m_totalCost = m_rdCost-calcPsyRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits, outBestCU-m_psyCost); +} +else +{ +outBestCU-m_totalCost = m_rdCost-calcRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits); +} } outTempCU-initEstData(depth); @@ -648,7 +655,14 @@ m_entropyCoder-encodeSplitFlag(outTempCU, 0, depth); outTempCU-m_totalBits += m_entropyCoder-getNumberOfWrittenBits(); // split bits } -outTempCU-m_totalCost = m_rdCost-calcRdCost(outTempCU-m_totalDistortion, outTempCU-m_totalBits); +if (m_rdCost-psyRdEnabled()) +{ +outTempCU-m_totalCost = m_rdCost-calcPsyRdCost(outTempCU-m_totalDistortion, outTempCU-m_totalBits, outTempCU-m_psyCost); +} +else +{ +outTempCU-m_totalCost = m_rdCost-calcRdCost(outTempCU-m_totalDistortion, outTempCU-m_totalBits); +} if ((g_maxCUSize depth) ==
Re: [x265] [PATCH RFC] psyrd: use psyrdcost for selecting best mode across depth
On Mon, May 26, 2014 at 3:02 PM, sumala...@multicorewareinc.com wrote: # HG changeset patch # User Sumalatha Polureddysumala...@multicorewareinc.com # Date 1401087565 -19800 # Node ID cbe5cc0e48b4122518ca732a1b32de16ba25c467 # Parent 5134e76aa729b6fece18701fdc00390c2f2ffb32 psyrd: use psyrdcost for selecting best mode across depth diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibCommon/TComDataCU.cpp --- a/source/Lib/TLibCommon/TComDataCU.cpp Thu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibCommon/TComDataCU.cpp Mon May 26 12:29:25 2014 +0530 @@ -218,6 +218,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= pic-getNumPartInCU(); char* qp = pic-getCU(getAddr())-getQP(); m_baseQp = pic-getCU(getAddr())-m_baseQp; @@ -309,6 +310,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; uint8_t cuSize = g_maxCUSize depth; @@ -345,6 +347,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; uint8_t cuSize = g_maxCUSize depth; @@ -393,6 +396,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; for (int i = 0; i 4; i++) @@ -457,6 +461,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; for (int i = 0; i 4; i++) @@ -520,6 +525,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; TComDataCU* rpcCU = m_pic-getCU(m_cuAddr); @@ -550,6 +556,7 @@ m_totalDistortion += cu-m_totalDistortion; m_totalBits+= cu-m_totalBits; +m_psyCost += cu-m_psyCost; uint32_t offset = cu-getTotalNumPart() * partUnitIdx; uint32_t numPartition = cu-getTotalNumPart(); @@ -610,6 +617,7 @@ rpcCU-m_totalCost = m_totalCost; rpcCU-m_totalDistortion = m_totalDistortion; rpcCU-m_totalBits = m_totalBits; +rpcCU-m_psyCost = m_psyCost; int sizeInBool = sizeof(bool) * m_numPartitions; int sizeInChar = sizeof(char) * m_numPartitions; @@ -695,6 +703,7 @@ cu-m_totalCost = m_totalCost; cu-m_totalDistortion = m_totalDistortion; cu-m_totalBits = m_totalBits; +cu-m_psyCost = m_psyCost; int sizeInBool = sizeof(bool) * qNumPart; int sizeInChar = sizeof(char) * qNumPart; diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibCommon/TComDataCU.h --- a/source/Lib/TLibCommon/TComDataCU.hThu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibCommon/TComDataCU.hMon May 26 12:29:25 2014 +0530 @@ -168,6 +168,7 @@ uint64_t m_totalCost; /// sum of partition RD costs uint32_t m_totalDistortion; /// sum of partition distortion uint32_t m_totalBits; /// sum of partition signal bits +uint32_t m_psyCost; uint64_t m_avgCost[4]; // stores the avg cost of CU's in frame for each depth uint32_t m_count[4]; uint64_t m_sa8dCost; diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibEncoder/TEncCu.cpp --- a/source/Lib/TLibEncoder/TEncCu.cpp Thu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibEncoder/TEncCu.cpp Mon May 26 12:29:25 2014 +0530 @@ -601,7 +601,14 @@ m_entropyCoder-resetBits(); m_entropyCoder-encodeSplitFlag(outBestCU, 0, depth); outBestCU-m_totalBits += m_entropyCoder-getNumberOfWrittenBits(); // split bits -outBestCU-m_totalCost = m_rdCost-calcRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits); +if (m_rdCost-psyRdEnabled()) +{ +outBestCU-m_totalCost = m_rdCost-calcPsyRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits, outBestCU-m_psyCost); If our objective is to catch unintended comparisons between psyCost and regular RD cost, you should save the above cost (with psyRd enabled) into m_psyCost. +} +else +{ +outBestCU-m_totalCost = m_rdCost-calcRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits); +} } outTempCU-initEstData(depth); @@ -648,7 +655,14 @@ m_entropyCoder-encodeSplitFlag(outTempCU, 0, depth); outTempCU-m_totalBits += m_entropyCoder-getNumberOfWrittenBits(); // split bits } -outTempCU-m_totalCost = m_rdCost-calcRdCost(outTempCU-m_totalDistortion, outTempCU-m_totalBits); +if (m_rdCost-psyRdEnabled()) +{ +
Re: [x265] [PATCH RFC] psyrd: use psyrdcost for selecting best mode across depth
On Mon, May 26, 2014 at 4:26 PM, Deepthi Nandakumar deep...@multicorewareinc.com wrote: On Mon, May 26, 2014 at 3:02 PM, sumala...@multicorewareinc.com wrote: # HG changeset patch # User Sumalatha Polureddysumala...@multicorewareinc.com # Date 1401087565 -19800 # Node ID cbe5cc0e48b4122518ca732a1b32de16ba25c467 # Parent 5134e76aa729b6fece18701fdc00390c2f2ffb32 psyrd: use psyrdcost for selecting best mode across depth diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibCommon/TComDataCU.cpp --- a/source/Lib/TLibCommon/TComDataCU.cpp Thu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibCommon/TComDataCU.cpp Mon May 26 12:29:25 2014 +0530 @@ -218,6 +218,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= pic-getNumPartInCU(); char* qp = pic-getCU(getAddr())-getQP(); m_baseQp = pic-getCU(getAddr())-m_baseQp; @@ -309,6 +310,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; uint8_t cuSize = g_maxCUSize depth; @@ -345,6 +347,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; uint8_t cuSize = g_maxCUSize depth; @@ -393,6 +396,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; for (int i = 0; i 4; i++) @@ -457,6 +461,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; for (int i = 0; i 4; i++) @@ -520,6 +525,7 @@ m_sa8dCost = MAX_INT64; m_totalDistortion = 0; m_totalBits= 0; +m_psyCost = 0; m_numPartitions= cu-getTotalNumPart() 2; TComDataCU* rpcCU = m_pic-getCU(m_cuAddr); @@ -550,6 +556,7 @@ m_totalDistortion += cu-m_totalDistortion; m_totalBits+= cu-m_totalBits; +m_psyCost += cu-m_psyCost; uint32_t offset = cu-getTotalNumPart() * partUnitIdx; uint32_t numPartition = cu-getTotalNumPart(); @@ -610,6 +617,7 @@ rpcCU-m_totalCost = m_totalCost; rpcCU-m_totalDistortion = m_totalDistortion; rpcCU-m_totalBits = m_totalBits; +rpcCU-m_psyCost = m_psyCost; int sizeInBool = sizeof(bool) * m_numPartitions; int sizeInChar = sizeof(char) * m_numPartitions; @@ -695,6 +703,7 @@ cu-m_totalCost = m_totalCost; cu-m_totalDistortion = m_totalDistortion; cu-m_totalBits = m_totalBits; +cu-m_psyCost = m_psyCost; int sizeInBool = sizeof(bool) * qNumPart; int sizeInChar = sizeof(char) * qNumPart; diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibCommon/TComDataCU.h --- a/source/Lib/TLibCommon/TComDataCU.hThu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibCommon/TComDataCU.hMon May 26 12:29:25 2014 +0530 @@ -168,6 +168,7 @@ uint64_t m_totalCost; /// sum of partition RD costs uint32_t m_totalDistortion; /// sum of partition distortion uint32_t m_totalBits; /// sum of partition signal bits +uint32_t m_psyCost; uint64_t m_avgCost[4]; // stores the avg cost of CU's in frame for each depth uint32_t m_count[4]; uint64_t m_sa8dCost; diff -r 5134e76aa729 -r cbe5cc0e48b4 source/Lib/TLibEncoder/TEncCu.cpp --- a/source/Lib/TLibEncoder/TEncCu.cpp Thu May 22 21:46:21 2014 -0500 +++ b/source/Lib/TLibEncoder/TEncCu.cpp Mon May 26 12:29:25 2014 +0530 @@ -601,7 +601,14 @@ m_entropyCoder-resetBits(); m_entropyCoder-encodeSplitFlag(outBestCU, 0, depth); outBestCU-m_totalBits += m_entropyCoder-getNumberOfWrittenBits(); // split bits -outBestCU-m_totalCost = m_rdCost-calcRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits); +if (m_rdCost-psyRdEnabled()) +{ +outBestCU-m_totalCost = m_rdCost-calcPsyRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits, outBestCU-m_psyCost); If our objective is to catch unintended comparisons between psyCost and regular RD cost, you should save the above cost (with psyRd enabled) into m_psyCost. psyCost is the difference in energy between src and recon and it is calculated for each mode when psyrd is enabled psyRdCost is calculated from dist, bits and psycost. In this place, it has tobe calculated again for the new bits with already calculated distortion and psycost for best mode. +} +else +{ +outBestCU-m_totalCost = m_rdCost-calcRdCost(outBestCU-m_totalDistortion, outBestCU-m_totalBits); +} }