Rect masked compound read the SQUARE envelope's compound_type/wedge_idx CDF row
Browse files at this commitf7508701c7e60f306e600327cfc31c244120dfc8Parent: 60b3ba2- fix
- rect masked compound read the SQUARE envelope's compound_type/wedge_idx CDF row
2 changed files +125 -32
crates/ec-av1/src/decode.rsmodified+123 -31
| @@ -14987,6 +14987,12 @@ fn resolve_interp_filter( | |||
| 14987 | } else { | 14987 | } else { |
| 14988 | sym0 | 14988 | sym0 |
| 14989 | }; | 14989 | }; |
| 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 | + } | ||
| 14990 | ( | 14996 | ( |
| 14991 | mc::InterpFilterKind::from_switchable_symbol(sym1 as usize), | 14997 | mc::InterpFilterKind::from_switchable_symbol(sym1 as usize), |
| 14992 | mc::InterpFilterKind::from_switchable_symbol(sym0 as usize), | 14998 | mc::InterpFilterKind::from_switchable_symbol(sym0 as usize), |
| @@ -15975,6 +15981,67 @@ fn is_any_masked_compound_used_here(side: usize) -> bool { | |||
| 15975 | side.min(side) >= 8 | 15981 | side.min(side) >= 8 |
| 15976 | } | 15982 | } |
| 15977 | 15983 | ||
| 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 | + | ||
| 15978 | /// Whether a compound reference pair is unidirectional (both references on | 16045 | /// Whether a compound reference pair is unidirectional (both references on |
| 15979 | /// the same temporal side of the current frame) -- `has_uni_comp_refs` | 16046 | /// the same temporal side of the current frame) -- `has_uni_comp_refs` |
| 15980 | /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition: | 16047 | /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition: |
| @@ -16764,12 +16831,18 @@ fn decode_inter_block( | |||
| 16764 | let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side); | 16831 | let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side); |
| 16765 | let comp_group_idx = if !skip_mode | 16832 | let comp_group_idx = if !skip_mode |
| 16766 | && enable_masked_compound | 16833 | && enable_masked_compound |
| 16767 | - && is_any_masked_compound_used_here(side) | 16834 | + && masked_compound_used_wh(write_w, write_h) |
| 16768 | { | 16835 | { |
| 16769 | dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) | 16836 | dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) |
| 16770 | } else { | 16837 | } else { |
| 16771 | 0 | 16838 | 0 |
| 16772 | }; | 16839 | }; |
| 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 | + } | ||
| 16773 | // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a | 16846 | // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a |
| 16774 | // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup) | 16847 | // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup) |
| 16775 | // for a `COMPOUND_WEDGE` block -- exactly one of the two is set | 16848 | // for a `COMPOUND_WEDGE` block -- exactly one of the two is set |
| @@ -16791,12 +16864,11 @@ fn decode_inter_block( | |||
| 16791 | // writes NO `compound_type` symbol there and INFERS | 16864 | // writes NO `compound_type` symbol there and INFERS |
| 16792 | // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal | 16865 | // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal |
| 16793 | // follows. `None` here is exactly that inferred arm. | 16866 | // follows. `None` here is exactly that inferred arm. |
| 16794 | - let wedge_bsize = match side { | 16867 | + // lane-intersub8 r4: the block's TRUE footprint, not the |
| 16795 | - 8 => Some(3), | 16868 | + // square envelope -- `compound_type_cdf`/`wedge_idx_cdf` are |
| 16796 | - 16 => Some(6), | 16869 | + // `BLOCK_SIZES_ALL`-indexed. |
| 16797 | - 32 => Some(9), | 16870 | + let wedge_bsize = |
| 16798 | - _ => None, | 16871 | + bsize_index(write_w, write_h).filter(|_| wedge_used_wh(write_w, write_h)); |
| 16799 | - }; | ||
| 16800 | let compound_type = match wedge_bsize { | 16872 | let compound_type = match wedge_bsize { |
| 16801 | Some(b) => dec.symbol(&mut cdfs.compound_type[b]), | 16873 | Some(b) => dec.symbol(&mut cdfs.compound_type[b]), |
| 16802 | None => 1, | 16874 | None => 1, |
| @@ -16804,6 +16876,14 @@ fn decode_inter_block( | |||
| 16804 | if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) { | 16876 | if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) { |
| 16805 | // COMPOUND_WEDGE: lane-wedge r3, codebook checksum- | 16877 | // COMPOUND_WEDGE: lane-wedge r3, codebook checksum- |
| 16806 | // verified vs independent C dump (wedge.rs). | 16878 | // 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 | + } | ||
| 16807 | let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); | 16887 | let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]); |
| 16808 | let wedge_sign = dec.literal(1); | 16888 | let wedge_sign = dec.literal(1); |
| 16809 | WEDGE_HITS.with(|c| c.set(c.get() + 1)); | 16889 | WEDGE_HITS.with(|c| c.set(c.get() + 1)); |
| @@ -17035,6 +17115,12 @@ fn decode_inter_block( | |||
| 17035 | ref_order_hints[(ref1 - LAST_FRAME) as usize], | 17115 | ref_order_hints[(ref1 - LAST_FRAME) as usize], |
| 17036 | ); | 17116 | ); |
| 17037 | let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); | 17117 | 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 | + } | ||
| 17038 | if idx == 1 { | 17124 | if idx == 1 { |
| 17039 | (8, 8, 1u8) | 17125 | (8, 8, 1u8) |
| 17040 | } else { | 17126 | } else { |
| @@ -22643,39 +22729,45 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 22643 | )?; | 22729 | )?; |
| 22644 | continue; | 22730 | continue; |
| 22645 | } | 22731 | } |
| 22646 | - if part8 == PARTITION_HORZ { | 22732 | + if part8 == PARTITION_HORZ |
| 22647 | - // lane-intersub8 r3: the two-BLOCK_8X4 | 22733 | + && std::env::var_os("EC_AV1_SUB8_HORZ").is_none() |
| 22648 | - // shape IS implemented below | 22734 | + { |
| 22649 | - // ([`decode_inter_sub8_rect2`], same | 22735 | + // lane-intersub8 r4: the r3 desync IS |
| 22650 | - // function as the 4x8 one), and it | 22736 | + // root-caused and fixed (rect masked |
| 22651 | - // decodes most streams exact -- but a | 22737 | + // compound read `BLOCK_16X16`'s |
| 22652 | - // measured 4-of-28-attempt sweep | 22738 | + // `compound_type`/`wedge_idx` CDF row |
| 22653 | - // (transposed-structure source, cq | 22739 | + // for a 16x8 block); every mode-info |
| 22654 | - // 12..32, both depths) desyncs in the | 22740 | + // range on the 28-arm transposed |
| 22655 | - // MODE INFO of the 16x8 inter block | 22741 | + // sweep now matches aomdec element |
| 22656 | - // immediately to its right: entry | 22742 | + // for element. What is left is a |
| 22657 | - // ranges match at that block's | 22743 | + // POST-ENTROPY pixel band: 3 of 28 |
| 22658 | - // `EC_MODE` print and differ by its | 22744 | + // arms (8-bit cq32 sp9, 10-bit cq12 |
| 22659 | - // first coefficient TU, so some | 22745 | + // sp3, 10-bit cq16 sp3) differ by |
| 22660 | - // per-row neighbour band this group | 22746 | + // |d| <= 2 in luma only, scattered |
| 22661 | - // leaves behind is wrong. Refused by | 22747 | + // over the bottom-left corner |
| 22662 | - // name rather than shipped as silent | 22748 | + // (x < 48, y >= 112) from the first |
| 22663 | - // pixel drift; the 4x8 twin is gated. | 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. | ||
| 22664 | return Err(unsupported( | 22755 | 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)", |
| 22666 | )); | 22757 | )); |
| 22667 | } | 22758 | } |
| 22668 | - if part8 == PARTITION_VERT { | 22759 | + if part8 == PARTITION_VERT || part8 == PARTITION_HORZ { |
| 22669 | - // lane-intersub8 r3: two BLOCK_8X4 / | 22760 | + // lane-intersub8 r3/r4: two BLOCK_8X4 |
| 22670 | - // BLOCK_4X8 inter leaves, chroma once | 22761 | + // (HORZ) / BLOCK_4X8 (VERT) inter |
| 22671 | - // per 8x8 on the second of them. | 22762 | + // leaves, chroma once per 8x8 on the |
| 22763 | + // second of them. | ||
| 22672 | decode_inter_sub8_rect2( | 22764 | decode_inter_sub8_rect2( |
| 22673 | &mut dec, | 22765 | &mut dec, |
| 22674 | &mut cdfs, | 22766 | &mut cdfs, |
| 22675 | &mut neighbours, | 22767 | &mut neighbours, |
| 22676 | &mut grid, | 22768 | &mut grid, |
| 22677 | leaf_mi, | 22769 | leaf_mi, |
| 22678 | - true, | 22770 | + part8 == PARTITION_VERT, |
| 22679 | mi_cols, | 22771 | mi_cols, |
| 22680 | mi_rows, | 22772 | mi_rows, |
| 22681 | &mut y, | 22773 | &mut y, |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
| @@ -36,7 +36,8 @@ const REFUSALS: &[&str] = &[ | |||
| 36 | "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)", | 36 | "an intra 4x4 block inside an inter frame's sub-8x8 split (this decoder codes only inter 4x4 sub-blocks there)", |
| 37 | "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)", | 37 | "an intra 8x4/4x8 block inside an inter frame's sub-8x8 HORZ/VERT partition (this decoder codes only inter sub-blocks there)", |
| 38 | "a sub-8x8 inter block under a scaled reference (superres, unimplemented)", | 38 | "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)", | ||
| 40 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", | 41 | "a 1:4 rect strip that actually uses a palette (reconstruction is not ported at this shape)", |
| 41 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 42 | "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |
| 42 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", | 43 | "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", |