Skip to content

Commit 469bd4b

Browse files
committed
Add unit tests for RdCost::GetSADwMask
This function is only called for powers of two widths and heights of at least 8. The mask parameter elements are either zero or one. The `applyWeight` parameter appears to be always zero, so hard-code this in the test.
1 parent dfebb7d commit 469bd4b

File tree

2 files changed

+54
-8
lines changed

2 files changed

+54
-8
lines changed

source/Lib/CommonLib/RdCost.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ class RdCost
117117
Distortion ( *m_fxdWtdPredPtr )( const DistParam& dp, uint32_t fixedWeight );
118118
Distortion ( *m_wtdPredPtr[2] )( const DistParam& dp, ChromaFormat chmFmt, const uint32_t* lumaWeights );
119119

120-
private:
121120
// for distortion
122-
123121
FpDistFunc m_afpDistortFunc[2][DF_TOTAL_FUNCTIONS]; // [eDFunc]
124122
FpDistFuncX5 m_afpDistortFuncX5[2]; // [eDFunc]
123+
124+
private:
125125
vvencCostMode m_costMode;
126126
double m_distortionWeight[MAX_NUM_COMP]; // only chroma values are used.
127127
double m_dLambda;

test/vvenc_unit_test/vvenc_unit_test.cpp

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,6 +1080,53 @@ static bool check_fixWeightedSSE( RdCost* ref, RdCost* opt, unsigned num_cases,
10801080
return passed;
10811081
}
10821082

1083+
static bool check_SADwMask( RdCost* ref, RdCost* opt, unsigned num_cases, int width, int height )
1084+
{
1085+
std::ostringstream sstm;
1086+
sstm << "RdCost::m_afpDistortFunc[0][DF_SAD_WITH_MASK] " << " w=" << width << " h=" << height;
1087+
printf( "Testing %s\n", sstm.str().c_str());
1088+
1089+
DimensionGenerator rng;
1090+
InputGenerator<Pel> g1{ 1, /*is_signed=*/false }; // Masks are either 0 or 1.
1091+
InputGenerator<Pel> g10{ 10, /*is_signed=*/false };
1092+
1093+
bool passed = true;
1094+
for( unsigned i = 0; i < num_cases; i++ )
1095+
{
1096+
int org_stride = rng.get( width, 1024 );
1097+
int cur_stride = rng.get( width, 1024 );
1098+
int mask_stride = rng.get( width, 1024 );
1099+
std::vector<Pel> orgBuf( org_stride * height );
1100+
std::vector<Pel> curBuf( cur_stride * height );
1101+
std::vector<Pel> maskBuf( mask_stride * height );
1102+
bool negStepX = rng.get( 0, 1 ) != 0;
1103+
1104+
DistParam dtParam;
1105+
dtParam.org.buf = orgBuf.data();
1106+
dtParam.org.stride = org_stride;
1107+
dtParam.cur.buf = curBuf.data();
1108+
dtParam.cur.stride = cur_stride;
1109+
dtParam.mask = maskBuf.data() + (negStepX ? width : 0);
1110+
dtParam.maskStride = mask_stride;
1111+
dtParam.maskStride2 = negStepX ? width : -width;
1112+
dtParam.org.width = width;
1113+
dtParam.org.height = height;
1114+
dtParam.bitDepth = 10;
1115+
dtParam.subShift = rng.get( 0, 1 );
1116+
dtParam.applyWeight = 0; // applyWeight appears to be always zero.
1117+
dtParam.stepX = negStepX ? -1 : 1;
1118+
1119+
std::generate( orgBuf.begin(), orgBuf.end(), g10 );
1120+
std::generate( curBuf.begin(), curBuf.end(), g10 );
1121+
std::generate( maskBuf.begin(), maskBuf.end(), g1);
1122+
1123+
Distortion sum_ref = ref->m_afpDistortFunc[0][DF_SAD_WITH_MASK]( dtParam );
1124+
Distortion sum_opt = opt->m_afpDistortFunc[0][DF_SAD_WITH_MASK]( dtParam );
1125+
passed = compare_value( sstm.str(), sum_ref, sum_opt ) && passed;
1126+
}
1127+
return passed;
1128+
}
1129+
10831130
static bool test_RdCost()
10841131
{
10851132
RdCost ref;
@@ -1097,13 +1144,12 @@ static bool test_RdCost()
10971144
for( int w : widths )
10981145
{
10991146
passed = check_lumaWeightedSSE( &ref, &opt, num_cases, w, h ) && passed;
1100-
}
1101-
}
1102-
for( int h : heights )
1103-
{
1104-
for( int w : widths )
1105-
{
11061147
passed = check_fixWeightedSSE( &ref, &opt, num_cases, w, h ) && passed;
1148+
1149+
if (w >= 8 && h >= 8)
1150+
{
1151+
passed = check_SADwMask( &ref, &opt, num_cases, w, h ) && passed;
1152+
}
11071153
}
11081154
}
11091155
return passed;

0 commit comments

Comments
 (0)