forge
Explore
Log in

Don't you dare go Hollow

Rect masked compound read the SQUARE envelope's compound_type/wedge_idx CDF row

Browse files at this commit

f7508701c7e60f306e600327cfc31c244120dfc8Ahmet Kaan GümüşParent: 60b3ba2
  • fix
    • rect masked compound read the SQUARE envelope's compound_type/wedge_idx CDF row
Show full message
fix(av1): rect masked compound read the SQUARE envelope's compound_type/wedge_idx CDF row

A 16x8 (or any non-square) compound block with comp_group_idx==1 read
BLOCK_16X16's compound_type_cdf/wedge_idx_cdf row instead of BLOCK_16X8's,
because decode_inter_block indexed those tables by its square `side` argument
rather than the block's true (write_w, write_h) footprint -- class
table-indexed-by-raw-size. The same square envelope also decided
is_any_masked_compound_used, so a 4x16/16x4 strip would read a comp_group_idx
symbol libaom never writes.

Root cause proven by range ladder on a 192x128 6-frame 8-bit AV1 stream
(transposed-structure geq source, cq14, rect partitions on): entering the 16x8
block both decoders are at rng 46505, agree through the mv (58288), and after
the fix agree at the end of mode info (61760) and at the next block (60694);
that stream now decodes pixel-exact on every decode-order frame, where before
it drifted from decode-order frame 5.

Also: a COMPOUND_WEDGE mask on a non-square block is refused by name (the
wedge codebook here is built per square side only), and EC_TRACE_MODE gains
EC_CGI / EC_CIDX / EC_IF rungs (comp_group_idx, compound_idx, interp filter:
ctx + value + range) -- the rungs that localized this.

The sub-8x8 HORZ (two BLOCK_8X4) refusal STAYS: with the fix, 3 of 28 sweep
arms still differ by |d| <= 2 in luma only, in the bottom-left corner, with an
element-exact entropy ladder -- a post-entropy filter/reconstruction defect.
EC_AV1_SUB8_HORZ=1 decodes it for that bisect.
crates/ec-av1/src/decode.rsmodified+123 -31
@@ -14987,6 +14987,12 @@ fn resolve_interp_filter(
1498714987 } else {
1498814988 sym0
1498914989 };
14990+ if std::env::var_os("EC_TRACE_MODE").is_some() {
14991+ eprintln!(
14992+ "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",
14993+ dec.debug_state().0
14994+ );
14995+ }
1499014996 (
1499114997 mc::InterpFilterKind::from_switchable_symbol(sym1 as usize),
1499214998 mc::InterpFilterKind::from_switchable_symbol(sym0 as usize),
@@ -15975,6 +15981,67 @@ fn is_any_masked_compound_used_here(side: usize) -> bool {
1597515981 side.min(side) >= 8
1597615982 }
1597715983
15984+/// libaom's `BLOCK_SIZES_ALL` index of a `w`x`h` block (`common_data.h`'s own
15985+/// enum order) -- the row every bsize-indexed CDF (`compound_type_cdf`,
15986+/// `wedge_idx_cdf`) is read at. lane-intersub8 r4: these two used to be
15987+/// indexed by the caller's SQUARE envelope, so a 16x8 compound block read
15988+/// `BLOCK_16X16`'s row (class table-indexed-by-raw-size) and desynced the
15989+/// tile at its first masked-compound rect block.
15990+fn bsize_index(w: usize, h: usize) -> Option<usize> {
15991+ Some(match (w, h) {
15992+ (4, 4) => 0,
15993+ (4, 8) => 1,
15994+ (8, 4) => 2,
15995+ (8, 8) => 3,
15996+ (8, 16) => 4,
15997+ (16, 8) => 5,
15998+ (16, 16) => 6,
15999+ (16, 32) => 7,
16000+ (32, 16) => 8,
16001+ (32, 32) => 9,
16002+ (32, 64) => 10,
16003+ (64, 32) => 11,
16004+ (64, 64) => 12,
16005+ (64, 128) => 13,
16006+ (128, 64) => 14,
16007+ (128, 128) => 15,
16008+ (4, 16) => 16,
16009+ (16, 4) => 17,
16010+ (8, 32) => 18,
16011+ (32, 8) => 19,
16012+ (16, 64) => 20,
16013+ (64, 16) => 21,
16014+ _ => return None,
16015+ })
16016+}
16017+
16018+/// `is_any_masked_compound_used` (libaom `reconinter.h`) on the block's TRUE
16019+/// footprint: `is_comp_ref_allowed` is `AOMMIN(bw, bh) >= 8`, and every
16020+/// shape that clears it has either a wedge or a DIFFWTD compound available.
16021+fn masked_compound_used_wh(w: usize, h: usize) -> bool {
16022+ w.min(h) >= 8
16023+}
16024+
16025+/// `av1_wedge_params_lookup[bsize].wedge_types > 0` (libaom `reconinter.c`):
16026+/// the shapes whose `compound_type` symbol is really coded. Everything else
16027+/// with a compound mask infers `COMPOUND_DIFFWTD` without a symbol.
16028+fn wedge_used_wh(w: usize, h: usize) -> bool {
16029+ matches!(
16030+ (w, h),
16031+ (8, 8)
16032+ | (8, 16)
16033+ | (16, 8)
16034+ | (16, 16)
16035+ | (16, 32)
16036+ | (32, 16)
16037+ | (32, 32)
16038+ | (8, 32)
16039+ | (32, 8)
16040+ | (16, 64)
16041+ | (64, 16)
16042+ )
16043+}
16044+
1597816045 /// Whether a compound reference pair is unidirectional (both references on
1597916046 /// the same temporal side of the current frame) -- `has_uni_comp_refs`
1598016047 /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition:
@@ -16764,12 +16831,18 @@ fn decode_inter_block(
1676416831 let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side);
1676516832 let comp_group_idx = if !skip_mode
1676616833 && enable_masked_compound
16767- && is_any_masked_compound_used_here(side)
16834+ && masked_compound_used_wh(write_w, write_h)
1676816835 {
1676916836 dec.symbol(&mut cdfs.comp_group_idx[group_ctx])
1677016837 } else {
1677116838 0
1677216839 };
16840+ if std::env::var_os("EC_TRACE_MODE").is_some() {
16841+ eprintln!(
16842+ "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",
16843+ dec.debug_state().0
16844+ );
16845+ }
1677316846 // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a
1677416847 // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup)
1677516848 // for a `COMPOUND_WEDGE` block -- exactly one of the two is set
@@ -16791,12 +16864,11 @@ fn decode_inter_block(
1679116864 // writes NO `compound_type` symbol there and INFERS
1679216865 // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal
1679316866 // follows. `None` here is exactly that inferred arm.
16794- let wedge_bsize = match side {
16795- 8 => Some(3),
16796- 16 => Some(6),
16797- 32 => Some(9),
16798- _ => None,
16799- };
16867+ // lane-intersub8 r4: the block's TRUE footprint, not the
16868+ // square envelope -- `compound_type_cdf`/`wedge_idx_cdf` are
16869+ // `BLOCK_SIZES_ALL`-indexed.
16870+ let wedge_bsize =
16871+ bsize_index(write_w, write_h).filter(|_| wedge_used_wh(write_w, write_h));
1680016872 let compound_type = match wedge_bsize {
1680116873 Some(b) => dec.symbol(&mut cdfs.compound_type[b]),
1680216874 None => 1,
@@ -16804,6 +16876,14 @@ fn decode_inter_block(
1680416876 if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) {
1680516877 // COMPOUND_WEDGE: lane-wedge r3, codebook checksum-
1680616878 // verified vs independent C dump (wedge.rs).
16879+ if write_w != write_h {
16880+ // lane-intersub8 r4: the wedge codebook here is built
16881+ // per SQUARE side only; a rect block's own codebook
16882+ // (BLOCK_16X8 etc.) is a different mask set.
16883+ return Err(unsupported(
16884+ "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
16885+ ));
16886+ }
1680716887 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
1680816888 let wedge_sign = dec.literal(1);
1680916889 WEDGE_HITS.with(|c| c.set(c.get() + 1));
@@ -17035,6 +17115,12 @@ fn decode_inter_block(
1703517115 ref_order_hints[(ref1 - LAST_FRAME) as usize],
1703617116 );
1703717117 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
17118+ if std::env::var_os("EC_TRACE_MODE").is_some() {
17119+ eprintln!(
17120+ "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",
17121+ dec.debug_state().0
17122+ );
17123+ }
1703817124 if idx == 1 {
1703917125 (8, 8, 1u8)
1704017126 } else {
@@ -22643,39 +22729,45 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2264322729 )?;
2264422730 continue;
2264522731 }
22646- if part8 == PARTITION_HORZ {
22647- // lane-intersub8 r3: the two-BLOCK_8X4
22648- // shape IS implemented below
22649- // ([`decode_inter_sub8_rect2`], same
22650- // function as the 4x8 one), and it
22651- // decodes most streams exact -- but a
22652- // measured 4-of-28-attempt sweep
22653- // (transposed-structure source, cq
22654- // 12..32, both depths) desyncs in the
22655- // MODE INFO of the 16x8 inter block
22656- // immediately to its right: entry
22657- // ranges match at that block's
22658- // `EC_MODE` print and differ by its
22659- // first coefficient TU, so some
22660- // per-row neighbour band this group
22661- // leaves behind is wrong. Refused by
22662- // name rather than shipped as silent
22663- // pixel drift; the 4x8 twin is gated.
22732+ if part8 == PARTITION_HORZ
22733+ && std::env::var_os("EC_AV1_SUB8_HORZ").is_none()
22734+ {
22735+ // lane-intersub8 r4: the r3 desync IS
22736+ // root-caused and fixed (rect masked
22737+ // compound read `BLOCK_16X16`'s
22738+ // `compound_type`/`wedge_idx` CDF row
22739+ // for a 16x8 block); every mode-info
22740+ // range on the 28-arm transposed
22741+ // sweep now matches aomdec element
22742+ // for element. What is left is a
22743+ // POST-ENTROPY pixel band: 3 of 28
22744+ // arms (8-bit cq32 sp9, 10-bit cq12
22745+ // sp3, 10-bit cq16 sp3) differ by
22746+ // |d| <= 2 in luma only, scattered
22747+ // over the bottom-left corner
22748+ // (x < 48, y >= 112) from the first
22749+ // frame that references an 8x4 group
22750+ // -- a filter/reconstruction defect,
22751+ // not a desync. Still refused by name
22752+ // rather than shipped as silent pixel
22753+ // drift; `EC_AV1_SUB8_HORZ=1` decodes
22754+ // it for the r5 bisect.
2266422755 return Err(unsupported(
22665- "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; decoded, but a measured sweep desyncs the block to its right)",
22756+ "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)",
2266622757 ));
2266722758 }
22668- if part8 == PARTITION_VERT {
22669- // lane-intersub8 r3: two BLOCK_8X4 /
22670- // BLOCK_4X8 inter leaves, chroma once
22671- // per 8x8 on the second of them.
22759+ if part8 == PARTITION_VERT || part8 == PARTITION_HORZ {
22760+ // lane-intersub8 r3/r4: two BLOCK_8X4
22761+ // (HORZ) / BLOCK_4X8 (VERT) inter
22762+ // leaves, chroma once per 8x8 on the
22763+ // second of them.
2267222764 decode_inter_sub8_rect2(
2267322765 &mut dec,
2267422766 &mut cdfs,
2267522767 &mut neighbours,
2267622768 &mut grid,
2267722769 leaf_mi,
22678- true,
22770+ part8 == PARTITION_VERT,
2267922771 mi_cols,
2268022772 mi_rows,
2268122773 &mut y,
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
@@ -36,7 +36,8 @@ const REFUSALS: &[&str] = &[
3636 "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)",
3737 "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)",
3838 "a sub-8x8 inter block under a scaled reference (superres, unimplemented)",
39- "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; decoded, but a measured sweep desyncs the block to its right)",
39+ "an inter 8x8 HORZ partition (two BLOCK_8X4 inter leaves; entropy-exact now, but a measured sweep still drifts |d|<=2 in luma after the filters)",
40+ "a COMPOUND_WEDGE mask on a non-square inter block (rect wedge codebook unimplemented)",
4041 "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)",
4142 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
4243 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",