From fd6f585ccec1aee2ba997f0653da19b72c138c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 05:20:36 +0300 Subject: [PATCH] fix(av1): RDOQ walked the 2D zigzag's tail on a 1-D transform unit Every candidate was already priced through the class-aware writer, so no decision was wrong; but the pass spends its budget from the tail of the scan backwards, and for a V_DCT/H_DCT unit the tail of the 2D zigzag is not the tail of the Mrow/Mcol scan its eob is measured in. It now walks the unit's own scan. --- crates/ec-av1/src/tile.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 676d7c37..09c05856 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -4959,7 +4959,19 @@ pub(crate) fn rdoq( // cannot cost two hundred re-codings. let mut budget = rdoq_budget(); let max_level = rdoq_max_level(); - for &position in scan_of(coded).iter().rev() { + // lane-txw: the tail this walks back from is the tail of the unit's OWN + // scan -- a `V_DCT`/`H_DCT` unit is coded in `Mrow_Scan`/`Mcol_Scan`, so + // the 2D zigzag's last positions are not the ones whose removal shortens + // its eob. Every candidate is still priced through the class-aware writer + // ([`write_coeffs`]), so this changes which positions the budget reaches, + // never whether a decision is right. + let class = crate::decode::TxClass::of(tx_type); + let order: &[u16] = if class == crate::decode::TxClass::TwoD { + scan_of(coded) + } else { + class_scan_of(coded, class) + }; + for &position in order.iter().rev() { if budget == 0 { break; }