forge
Explore
Log in

Don't you dare go Hollow

lane-av1422warp r33: reviewer rework -- OBMC snap, hot-path env, two docs, one wrong number

Browse files at this commit

4e1fb2356eba9fcb91325f07eefb17b69035264dAhmet Kaan GümüşParent: 7398829
Reviewer FAIL addressed, all five findings.

P2 (a4532a41) OBMC PAIR-MERGE SNAP. The snap was clamped on the wrong
value. libaom (obmc.h:44-46) snaps the pair index `& ~1` UNCONDITIONALLY
and reads at `snap + 1`; only the REPORTED offset
(`above_mi_col - mi_col`) is negative, and it feeds
`av1_setup_build_prediction_by_above_pred` while the READ feeds
`above_filter.get(mi_col + src4)` and the MiInfo itself. Clamping the
snapped index to `mi_col`/`mi_row` silenced the underflow and in exchange
read the neighbour one column RIGHT of libaom's, then stepped past
`mi_col + 1` entirely. Both sites now keep the snap and clamp only the
offset. The tuple is `usize`, so libaom's -1 is carried as 0; that is
noted in the code rather than glossed.

New gate the_obmc_pair_merge_snap_reads_libaoms_neighbour_not_one_to_the_
right pins the snapped READ against a synthetic grid with distinguishable
neighbours at the pair's even half, odd half, and the column to the right.
Mutation-proven both ways. It is necessary because NO STREAM IN THE CORPUS
exercises this branch: a1.obu's 1338 traced OBMC neighbours are identical
before and after the fix, since its 4-wide pair never starts on an odd
edge.

P2 HOT-PATH ENV LOOKUP. `SymbolDecoder::symbol` called
`std::env::var_os("EC_SYMR")` on every symbol read of every stream,
production formats included. Now `envflags::env_flag!("EC_SYMR")`, one
LazyLock per call site (the ecdump_armed precedent at msac.rs:1059).
Proved byte-identical: same build, both forms, identical 246735-line
EC_SYMR traces.

P3 MI_SIZE DOC. The doc claimed "MI_SIZE (aom_scale.h)" and 8. libaom's
MI_SIZE is 4 (av1/common/enums.h:39-40) and lives in enums.h. Renamed
MI_SIZE_8PX; both its doc and read_lr's are restated in 8-pixel terms,
with why the value is double libaom's (its denom is a pixel count, so
numerator and denominator already sit on opposite scales) and the paired
trace named as the authority. The rename is so nobody corrects it to 4.

P3 TOP-HALF CENSUS WAS AN UPPER BOUND, AND 248 WAS WRONG.
top_half_warp_hits incremented on "either slot's model > TRANSLATION"
alone, omitting `is_globalmv && side >= 8`, so it counted blocks that are
not global-mv blocks. It now increments on `is_global_mv0 || is_global_mv1`
-- libaom's own `is_global_mv_block` -- with the census moved below their
definition. CORRECTED UPPER-HALF FIGURE: 3 warp, 3 compound. Not 248.
Frame-global figures unchanged (compound_warp 25, compound_warp_8 18,
rotzoom_gm_warp 84, lr_wiener 22, lr_sgrproj 10). The gate doc and the
lift section are corrected; 248 was never a count of anything real.

P3 ACCESSOR DOCS. Both claimed a committed reader that does not exist and
cannot: with the header refusal standing no committed test decodes a 4:2:2
stream. Both now say so.

NO CHANGE to the 4:2:2 refusal, which stays unconditional. NO committed
bypass. Stream still 246735/246735 paired and 16/16 pixel-exact.
crates/ec-av1/src/decode.rsmodified+165 -30
@@ -4499,16 +4499,32 @@ thread_local! {
4499 }4499 }
4500 4500
4501 /// How many `GLOBAL_GLOBALMV` (compound) inter blocks decoded in the frame's4501 /// How many `GLOBAL_GLOBALMV` (compound) inter blocks decoded in the frame's
4502-/// upper half. Read by the pinned 4:2:2 coverage gate.4502+/// upper half -- the block's top mode-info row is under `mi_rows / 2`.
4503-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates4503+///
4504+/// NO COMMITTED TEST READS THIS, and none can while the 4:2:2 header refusal
4505+/// stands: the pinned 4:2:2 coverage gate asserts the byte pin and the
4506+/// refusal by name, so nothing in the suite ever decodes a 4:2:2 stream.
4507+/// The figure quoted for that fixture comes from a patch-run-restore build
4508+/// with the `EC_AV1_ALLOW_422_PROBE` bypass applied and then reverted, which
4509+/// is the same discipline every 4:2:2 lane in this family uses.
4510+#[allow(dead_code)]
4504 pub(crate) fn top_half_compound_hits() -> usize {4511 pub(crate) fn top_half_compound_hits() -> usize {
4505 TOP_HALF_COMPOUND_HITS.with(std::cell::Cell::get)4512 TOP_HALF_COMPOUND_HITS.with(std::cell::Cell::get)
4506 }4513 }
4507 4514
4508-/// How many inter blocks in the frame's upper half had at least one active4515+/// How many inter blocks in the frame's upper half satisfy libaom's
4509-/// reference slot on a non-`TRANSLATION` global-motion model -- i.e. blocks4516+/// `is_global_mv_block` on at least one reference slot -- mode
4510-/// whose prediction goes through `crate::warp`.4517+/// `GLOBAL_GLOBALMV` AND block >= 8x8 AND that slot's own global-motion
4511-#[allow(dead_code)] // read only from the `#[cfg(test)]` gates4518+/// model > `TRANSLATION`. This is the block set whose prediction goes
4519+/// through `crate::warp`, and it is exactly `is_global_mv0 || is_global_mv1`
4520+/// as computed at the increment site; it is NOT merely "some slot has a
4521+/// non-TRANSLATION model", which also counts blocks that are not global-mv
4522+/// blocks.
4523+///
4524+/// Like [`top_half_compound_hits`], no committed test reads it: with the
4525+/// 4:2:2 header refusal in force nothing in the suite decodes the stream
4526+/// these numbers describe.
4527+#[allow(dead_code)]
4512 pub(crate) fn top_half_warp_hits() -> usize {4528 pub(crate) fn top_half_warp_hits() -> usize {
4513 TOP_HALF_WARP_HITS.with(std::cell::Cell::get)4529 TOP_HALF_WARP_HITS.with(std::cell::Cell::get)
4514 }4530 }
@@ -31521,10 +31537,17 @@ fn overlappable_above(
31521 // The pair merge: the walk snaps back to the pair's even column31537 // The pair merge: the walk snaps back to the pair's even column
31522 // and the ODD half (the chroma-carrying one) is the neighbour for31538 // and the ODD half (the chroma-carrying one) is the neighbour for
31523 // both -- a 4-wide 1:4 strip is never an OBMC source on its own.31539 // both -- a 4-wide 1:4 strip is never an OBMC source on its own.
31524- // lane-av1422warp r25: as in `overlappable_left`, snapping down31540+ // lane-av1422warp r33 (reviewer P2): the snap must be UNCONDITIONAL.
31525- // lands on `mi_col - 1` at an ODD `mi_col` and the offsets below31541+ // libaom `obmc.h:41-46` is
31526- // underflow (debug-build panic; `usize::MAX` in release). Clamp.31542+ // `above_mi = prev_row_mi + (above_mi_col & ~1) + 1` -- the snapped
31527- col = (col & !1).max(mi_col);31543+ // COLUMN is used as-is and the +1 is what lands it back on the
31544+ // block's own left edge. Clamping the snapped INDEX to `mi_col`
31545+ // (an earlier r25 attempt) moved the index itself, so this
31546+ // decoded the neighbour one column RIGHT of libaom's and, after
31547+ // `col += step`, never visited `mi_col + 1`. Only the REPORTED
31548+ // offset can be negative -- `above_mi - mi_col == -1` -- so the
31549+ // clamp belongs there, not on the index.
31550+ col &= !1;
31528 src = col + 1;31551 src = col + 1;
31529 nb = grid.get(mi_row - 1, src);31552 nb = grid.get(mi_row - 1, src);
31530 step = 2;31553 step = 2;
@@ -31540,7 +31563,7 @@ fn overlappable_above(
31540 // neighbour PREDICTION at a frame edge, which picks the31563 // neighbour PREDICTION at a frame edge, which picks the
31541 // 4-tap kernel below 8 px (class narrow-block-sharp-kernel);31564 // 4-tap kernel below 8 px (class narrow-block-sharp-kernel);
31542 // the destination clip stays in `obmc_blend`.31565 // the destination clip stays in `obmc_blend`.
31543- out.push((col - mi_col, step.min(bw4), info, src - mi_col));31566+ out.push((col.saturating_sub(mi_col), step.min(bw4), info, src - mi_col));
31544 }31567 }
31545 }31568 }
31546 col += step;31569 col += step;
@@ -31577,13 +31600,13 @@ fn overlappable_left(
31577 // The pair merge, left-column mirror: a 4-TALL neighbour (a 16x431600 // The pair merge, left-column mirror: a 4-TALL neighbour (a 16x4
31578 // strip) is half of a chroma pair and the pair's SECOND row is the31601 // strip) is half of a chroma pair and the pair's SECOND row is the
31579 // neighbour for both.31602 // neighbour for both.
31580- // lane-av1422warp r25: `row &= !1` rounds DOWN, so at an ODD31603+ // lane-av1422warp r33 (reviewer P2): the row mirror of the
31581- // `mi_row` it lands on `mi_row - 1` and the `row - mi_row`31604+ // `overlappable_above` fix. libaom's left-column walk snaps
31582- // offsets below underflow -- `usize::MAX` in release, and a31605+ // `(left_mi_row & ~1)` and adds 1; the snap is unconditional and
31583- // debug-build panic ("attempt to subtract with overflow",31606+ // only the REPORTED `row - mi_row` can be -1. The r25 clamp moved
31584- // `overlappable_left` called from `decode_inter_block`) with31607+ // the snapped index itself, which read the neighbour one row
31585- // EC_TRACE_MODE_STEP set. Clamp: the offset can never be negative.31608+ // BELOW libaom's and then skipped `mi_row + 1` entirely.
31586- row = (row & !1).max(mi_row);31609+ row &= !1;
31587 src = row + 1;31610 src = row + 1;
31588 nb = grid.get(src, mi_col - 1);31611 nb = grid.get(src, mi_col - 1);
31589 step = 2;31612 step = 2;
@@ -31595,7 +31618,7 @@ fn overlappable_left(
31595 }31618 }
31596 // lane-t900 r14: `AOMMIN(xd->height, mi_step)` -- see31619 // lane-t900 r14: `AOMMIN(xd->height, mi_step)` -- see
31597 // `overlappable_above`.31620 // `overlappable_above`.
31598- out.push((row - mi_row, step.min(bh4), info, src - mi_row));31621+ out.push((row.saturating_sub(mi_row), step.min(bh4), info, src - mi_row));
31599 }31622 }
31600 }31623 }
31601 row += step;31624 row += step;
@@ -33451,17 +33474,6 @@ fn decode_inter_block(
33451 }33474 }
33452 }33475 }
33453 let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV33476 let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV
33454- if mi_row < mi_rows as usize / 2 {
33455- if is_globalmv {
33456- TOP_HALF_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
33457- }
33458- if global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1
33459- || global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1
33460- {
33461- TOP_HALF_WARP_HITS.with(|c| c.set(c.get() + 1));
33462- }
33463- }
33464- // spec `is_nontrans_global_motion`: ALL active refs' models must
33465 // be non-TRANSLATION (IDENTITY counts) for the compound block's33477 // be non-TRANSLATION (IDENTITY counts) for the compound block's
33466 // interp-filter read to be suppressed.33478 // interp-filter read to be suppressed.
33467 let gm_nontrans_models = is_globalmv33479 let gm_nontrans_models = is_globalmv
@@ -33488,6 +33500,22 @@ fn decode_inter_block(
33488 let is_global_mv1 = is_globalmv33500 let is_global_mv1 = is_globalmv
33489 && side >= 833501 && side >= 8
33490 && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1;33502 && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1;
33503+ // lane-av1422warp r33 (reviewer P3): the top-half census is
33504+ // placed HERE, after `is_global_mv0`/`is_global_mv1`, so it
33505+ // counts the same blocks libaom's `is_global_mv_block` does --
33506+ // mode GLOBAL_GLOBALMV AND block >= 8x8 AND that slot's own gm
33507+ // model > TRANSLATION. An earlier placement tested the model term
33508+ // alone, which counts blocks that are not global-mv blocks at
33509+ // all, so its number was an upper bound dressed up as an
33510+ // engagement figure.
33511+ if mi_row < mi_rows as usize / 2 {
33512+ if is_globalmv {
33513+ TOP_HALF_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
33514+ }
33515+ if is_global_mv0 || is_global_mv1 {
33516+ TOP_HALF_WARP_HITS.with(|c| c.set(c.get() + 1));
33517+ }
33518+ }
33491 // libaom `av1_init_warp_params` + `allow_warp`'s33519 // libaom `av1_init_warp_params` + `allow_warp`'s
33492 // `global_warp_allowed` branch, run once per reference for a33520 // `global_warp_allowed` branch, run once per reference for a
33493 // compound block exactly as for a single-ref one (reconinter.c33521 // compound block exactly as for a single-ref one (reconinter.c
@@ -46147,6 +46175,113 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
46147 46175
46148 #[cfg(test)]46176 #[cfg(test)]
46149 mod tests {46177 mod tests {
46178+ /// lane-av1422warp r33: the OBMC pair-merge snap must move the READ to
46179+ /// libaom's position, not the reported offset.
46180+ ///
46181+ /// libaom `obmc.h:44-46`:
46182+ /// ```c
46183+ /// if (mi_step == 1) {
46184+ /// above_mi_col &= ~1; // snap the INDEX, unconditional
46185+ /// above_mi = prev_row_mi + above_mi_col + 1; // read at snap + 1
46186+ /// mi_step = 2;
46187+ /// }
46188+ /// ```
46189+ /// and the relative offset handed to
46190+ /// `av1_setup_build_prediction_by_above_pred` is
46191+ /// `above_mi_col - mi_col` **after** the snap, which is `-1` at an odd
46192+ /// `mi_col`. An earlier fix clamped the snapped INDEX to `mi_col` to
46193+ /// stop that subtraction underflowing, which silenced the underflow and
46194+ /// in exchange read the neighbour one column RIGHT of libaom's and then
46195+ /// stepped past the block's own right edge.
46196+ ///
46197+ /// The grid here carries DISTINGUISHABLE neighbours at the pair's even
46198+ /// half, its odd half, and the column to the right of the pair, so the
46199+ /// test fails if the walk reads any position but the odd half. It is the
46200+ /// snapped READ this pins -- and no stream in the corpus exercises it
46201+ /// (a1.obu's 1338 traced OBMC neighbours are byte-identical before and
46202+ /// after the fix, because its 4-wide pair never starts on an odd edge),
46203+ /// so nothing else covers this branch.
46204+ #[test]
46205+ fn the_obmc_pair_merge_snap_reads_libaoms_neighbour_not_one_to_the_right() {
46206+ const NAME: &str =
46207+ "the_obmc_pair_merge_snap_reads_libaoms_neighbour_not_one_to_the_right";
46208+ // `ref_frame` 1 == LAST_FRAME, which is what `is_inter` consumers
46209+ // expect; the MV makes each cell individually identifiable.
46210+ let cell = |mv: (i16, i16), size: u8| MiInfo {
46211+ is_inter: true,
46212+ ref_frame: 1,
46213+ ref_frame1: 0,
46214+ mv: mv,
46215+ mv1: (0, 0),
46216+ is_new_mv: true,
46217+ size,
46218+ size_h: size,
46219+ is_global_mv0: false,
46220+ is_global_mv1: false,
46221+ };
46222+ const EVEN: (i16, i16) = (10, 10);
46223+ const ODD: (i16, i16) = (20, 20);
46224+ const RIGHT: (i16, i16) = (30, 30);
46225+
46226+ // --- the above walk, at an ODD `mi_col` ---
46227+ let mut grid = crate::mvstack::MiGrid::new(16, 16);
46228+ // The block under test sits at mi_col 5; the neighbour row is 4.
46229+ // A 4-wide inter cell at the ODD half (5) is what forces
46230+ // `mi_step == 1` and therefore the pair merge.
46231+ grid.set(4, 4, cell(EVEN, 1));
46232+ grid.set(4, 5, cell(ODD, 1));
46233+ grid.set(4, 6, cell(RIGHT, 4)); // one column RIGHT of the pair
46234+ // `bw4 == 2` so `AOMMIN(xd->width, mi_step)` is the pair's own 2
46235+ // rather than clipped to a 1-wide block's 1.
46236+ let nb = overlappable_above(&grid, 5, 5, 2, 16, 4);
46237+ assert!(
46238+ !nb.is_empty(),
46239+ "{NAME}: the above walk found no neighbour at all"
46240+ );
46241+ let (off4, span4, info, src4) = nb[0];
46242+ assert_eq!(
46243+ info.mv, ODD,
46244+ "{NAME}: the above pair merge read the wrong neighbour -- libaom \
46245+ snaps the column and reads snap+1, which is the ODD half"
46246+ );
46247+ assert_ne!(
46248+ info.mv, RIGHT,
46249+ "{NAME}: the clamp moved the snapped index onto mi_col, so the \
46250+ walk read one column RIGHT of libaom"
46251+ );
46252+ assert_eq!(src4, 0, "{NAME}: the read column's relative offset");
46253+ assert_eq!(span4, 2, "{NAME}: the pair steps over BOTH halves");
46254+ // libaom's `above_mi_col - mi_col` is -1 here; this tuple is
46255+ // `usize`, so the reported offset saturates to 0 rather than
46256+ // wrapping to `usize::MAX`. The snap is what the read depends on.
46257+ assert_eq!(off4, 0, "{NAME}: the reported offset must saturate, not wrap");
46258+
46259+ // --- the left walk, at an ODD `mi_row`: the same shape ---
46260+ let mut grid = crate::mvstack::MiGrid::new(16, 16);
46261+ grid.set(4, 4, cell(EVEN, 1));
46262+ grid.set(5, 4, cell(ODD, 1));
46263+ grid.set(6, 4, cell(RIGHT, 4));
46264+ let nb = overlappable_left(&grid, 5, 5, 2, 16, 4);
46265+ assert!(
46266+ !nb.is_empty(),
46267+ "{NAME}: the left walk found no neighbour at all"
46268+ );
46269+ let (off4, span4, info, src4) = nb[0];
46270+ assert_eq!(
46271+ info.mv, ODD,
46272+ "{NAME}: the left pair merge read the wrong neighbour -- libaom \
46273+ snaps the row and reads snap+1, which is the ODD half"
46274+ );
46275+ assert_ne!(
46276+ info.mv, RIGHT,
46277+ "{NAME}: the clamp moved the snapped row onto mi_row, so the walk \
46278+ read one row BELOW libaom"
46279+ );
46280+ assert_eq!(src4, 0, "{NAME}: the read row's relative offset");
46281+ assert_eq!(span4, 2, "{NAME}: the pair steps over BOTH halves");
46282+ assert_eq!(off4, 0, "{NAME}: the reported offset must saturate, not wrap");
46283+ }
46284+
46150 /// lane-twostage: the reference bank these gates decode against --46285 /// lane-twostage: the reference bank these gates decode against --
46151 /// `LAST_FRAME` alone, already in hand (`ref_frame` index 1).46286 /// `LAST_FRAME` alone, already in hand (`ref_frame` index 1).
46152 fn last_only(reference: &Picture) -> RefPix<'_> {46287 fn last_only(reference: &Picture) -> RefPix<'_> {
crates/ec-av1/src/msac.rsmodified+7 -1
@@ -445,7 +445,13 @@ impl<'a> SymbolDecoder<'a> {
445 /// against its `cdf0`, never the raw numbers.445 /// against its `cdf0`, never the raw numbers.
446 #[inline]446 #[inline]
447 pub fn symbol(&mut self, cdf: &mut [u16]) -> usize {447 pub fn symbol(&mut self, cdf: &mut [u16]) -> usize {
448- let symr = std::env::var_os("EC_SYMR").is_some();448+ // lane-av1422warp r33 (reviewer P2): this ran on EVERY symbol read of
449+ // EVERY stream, production formats included, and `std::env::var_os`
450+ // is a real environment scan each time (~30ns x every symbol).
451+ // `env_flag!` keeps one `LazyLock<bool>` per call SITE, so the check
452+ // compiles to an atomic load. The trace is byte-identical: same
453+ // condition, same format, same fields.
454+ let symr = crate::envflags::env_flag!("EC_SYMR");
449 let (pre_value, pre_range, pre_bit) = (self.value, self.range, self.bit);455 let (pre_value, pre_range, pre_bit) = (self.value, self.range, self.bit);
450 let pre_cdf0 = cdf.first().copied().unwrap_or(0);456 let pre_cdf0 = cdf.first().copied().unwrap_or(0);
451 // lane-census: the syntax census charges this symbol's bits to the457 // lane-census: the syntax census charges this symbol's bits to the
crates/ec-av1/src/restoration.rsmodified+33 -9
@@ -479,8 +479,16 @@ fn ceil_div(a: u32, b: u32) -> u32 {
479 /// is >= 64px, so only the top-of-superblock call ever has non-empty479 /// is >= 64px, so only the top-of-superblock call ever has non-empty
480 /// corners, matching this decoder's own once-per-SB call site) and reads480 /// corners, matching this decoder's own once-per-SB call site) and reads
481 /// one `read_lr_unit` per covered `(rrow, rcol)`, per plane, in plane481 /// one `read_lr_unit` per covered `(rrow, rcol)`, per plane, in plane
482-/// order. `sb_mi` is the superblock's mode-info width (`SB_MI`, 16 for the482+/// order.
483-/// 64px superblocks this decoder always uses).483+///
484+/// `mi_row`/`mi_col`/`sb_mi` are all in **mode-info units (4x4)**, in true
485+/// frame coordinates -- this is the one call that converts a superblock's
486+/// position into absolute frame space, so it cannot carry the half-mi
487+/// convention the partition walks use. A 64px superblock is 8 mi and a
488+/// 128px superblock is 16 mi; the callers pass `SB_MI / 2` and `SB_MI`
489+/// respectively (`SB_MI` being 16). The corners themselves then step each
490+/// axis by [`MI_SIZE_8PX`] pixels -- see that constant's doc for why it is
491+/// 8 and not libaom's 4.
484 #[allow(clippy::too_many_arguments)]492 #[allow(clippy::too_many_arguments)]
485 pub(crate) fn read_lr(493 pub(crate) fn read_lr(
486 dec: &mut SymbolDecoder,494 dec: &mut SymbolDecoder,
@@ -514,7 +522,8 @@ pub(crate) fn read_lr(
514 // nine rounds localising: the oracle reads three at mi(30,62),522 // nine rounds localising: the oracle reads three at mi(30,62),
515 // this decoder read one.523 // this decoder read one.
516 //524 //
517- // `MI_SIZE` is 8 -- one mode-info unit is 8 pixels. Superres525+ // One mode-info unit is 8 pixels (`MI_SIZE_8PX`; see its doc for why
526+ // that is not libaom's `MI_SIZE`). Superres
518 // widens the column axis only (spec 7.16), so it enters `num_x`527 // widens the column axis only (spec 7.16), so it enters `num_x`
519 // and `denom_x` and leaves the row axis alone, exactly as libaom528 // and `denom_x` and leaves the row axis alone, exactly as libaom
520 // does with `av1_superres_scaled`.529 // does with `av1_superres_scaled`.
@@ -529,8 +538,8 @@ pub(crate) fn read_lr(
529 } else {538 } else {
530 0539 0
531 };540 };
532- let mi_size_x = MI_SIZE >> ss_x;541+ let mi_size_x = MI_SIZE_8PX >> ss_x;
533- let mi_size_y = MI_SIZE >> ss_y;542+ let mi_size_y = MI_SIZE_8PX >> ss_y;
534 let unit_size = lr.loop_restoration_size[plane];543 let unit_size = lr.loop_restoration_size[plane];
535 let horz_units = grid.horz_units[plane] as u32;544 let horz_units = grid.horz_units[plane] as u32;
536 let vert_units = grid.vert_units[plane] as u32;545 let vert_units = grid.vert_units[plane] as u32;
@@ -577,10 +586,25 @@ thread_local! {
577 static LR_LAST_STRIPE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };586 static LR_LAST_STRIPE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
578 }587 }
579 588
580-/// `MI_SIZE` (aom_scale.h): pixels per mode-info unit. `av1_loop_restoration_589+/// Pixels per mode-info unit (4x4 mi is 8 pixels). This is what
581-/// corners_in_sb` steps the row axis by this, so it is NOT the "half-mi"590+/// `av1_loop_restoration_corners_in_sb` (`restoration.c:1303-1338`) steps
582-/// factor several other helpers here use.591+/// each axis by, subsampled per axis: `MI_SIZE_8PX >> ss_x` for columns,
583-const MI_SIZE: u32 = 8;592+/// `MI_SIZE_8PX >> ss_y` for rows.
593+///
594+/// NAMING, because it is a trap: libaom's own `MI_SIZE` is **4**
595+/// (`av1/common/enums.h:39-40`, `1 << MI_SIZE_LOG2` with `MI_SIZE_LOG2 2`),
596+/// and libaom writes `mi_size_x = MI_SIZE >> ss_x` -- the same expression,
597+/// at half this value. The factor of two is not a transcription slip: its
598+/// `denom_x`/`denom_y` (`rsi->restoration_unit_size`) is a PIXEL count
599+/// (128 for a 128px superblock), so libaom's numerator and denominator
600+/// already sit on opposite scales, and doubling the numerator lands both in
601+/// pixels. This constant is deliberately NOT called `MI_SIZE`, so nobody
602+/// "corrects" it back to 4 and halves every restoration-unit range.
603+///
604+/// The authority is the paired trace, not this comment: at 8 the whole
605+/// 16-frame 4:2:2 stream pairs 246735-for-246735 against the instrumented
606+/// oracle, and at 4 it does not.
607+const MI_SIZE_8PX: u32 = 8;
584 /// `SCALE_NUMERATOR` (aom_scale.h): the superres scale's fixed point, 8.608 /// `SCALE_NUMERATOR` (aom_scale.h): the superres scale's fixed point, 8.
585 const SCALE_NUMERATOR: u32 = 8;609 const SCALE_NUMERATOR: u32 = 8;
586 /// Current value of [`LR_STRIPE0_HITS`].610 /// Current value of [`LR_STRIPE0_HITS`].