From 8f13876ea467071d6beed8c340af6d0f32a4ae25 Mon Sep 17 00:00:00 2001 From: xiujunwang Date: Sat, 10 Oct 2026 03:09:46 +0800 Subject: [PATCH] rdoq: skip uncoded cost setup for trailing zero groups --- source/common/quant.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/source/common/quant.cpp b/source/common/quant.cpp index 91db643ae..c65d5c044 100644 --- a/source/common/quant.cpp +++ b/source/common/quant.cpp @@ -717,20 +717,26 @@ uint32_t Quant::rdoQuant(const CUData &cu, int16_t *dstCoeff, TextType ttype, ui uint32_t scanPos = 0; uint32_t c1 = 1; - /* Initialize the uncoded distortion for every coefficient. This lets the - * coefficient loop replace uncoded costs with coded costs as needed. */ + /* Trailing zero groups have the same distortion in every candidate, + * including CBF=0, so omit that common additive cost. Coefficients remain + * in raster order; use the existing 4x4-group primitives. */ + for (int cg = 0; cg <= cgLastScanPos; cg++) + { + const uint32_t group = scanCG[cg]; + const uint32_t base = ((group >> log2TrSizeCG) * trSize + + (group & (cgStride - 1))) * 4; + if (usePsyMask) + primitives.cu[log2TrSize - 2].psyRdoQuant(m_resiDctCoeff, sourceDct, costUncoded, &totalUncodedCost, &totalRdCost, &psyScale, base); + else + primitives.cu[log2TrSize - 2].nonPsyRdoQuant(m_resiDctCoeff, costUncoded, &totalUncodedCost, &totalRdCost, base); + } if (usePsyMask) { - primitives.cu[log2TrSize - 2].psyRdoQuantAll(m_resiDctCoeff, sourceDct, costUncoded, &totalUncodedCost, &totalRdCost, &psyScale); - - /* DC distortion does not include the psy-RDOQ reconstruction bias. */ - int64_t dcPsyCost = PSYVALUE(sourceDct[0] - m_resiDctCoeff[0]); + const int64_t dcPsyCost = PSYVALUE(sourceDct[0] - m_resiDctCoeff[0]); costUncoded[0] += dcPsyCost; totalUncodedCost += dcPsyCost; totalRdCost += dcPsyCost; } - else - primitives.cu[log2TrSize - 2].nonPsyRdoQuantAll(m_resiDctCoeff, costUncoded, &totalUncodedCost, &totalRdCost); /* iterate over coding groups in reverse scan order */ for (int cgScanPos = cgLastScanPos; cgScanPos >= 0; cgScanPos--) {