The compound_type/wedge_idx CDF row of a rectangular inter block is its own BLOCK_SIZES_ALL index, not the enclosing square side's
Browse files at this commit06654199a68f314f45fa24a1112388386b82870aParent: 0402f49- fix
- the compound_type/wedge_idx CDF row of a rectangular inter block is its own BLOCK_SIZES_ALL index, not the enclosing square side's
2 changed files +75 -8
crates/ec-av1/src/decode.rsmodified+73 -7
| @@ -16051,6 +16051,54 @@ fn is_any_masked_compound_used_here(side: usize) -> bool { | |||
| 16051 | side.min(side) >= 8 | 16051 | side.min(side) >= 8 |
| 16052 | } | 16052 | } |
| 16053 | 16053 | ||
| 16054 | +/// The `BLOCK_SIZES_ALL` index of a `bw x bh` block (libaom `enum BLOCK_SIZE`, | ||
| 16055 | +/// `blockd.h`) -- the row every size-indexed inter CDF table | ||
| 16056 | +/// (`compound_type_cdf`, `wedge_idx_cdf`) is keyed by. Our `decode_inter_block` | ||
| 16057 | +/// carries the enclosing SQUARE `side` for context purposes (the accepted | ||
| 16058 | +/// strip corner-cut), so a 16x8 / 8x16 PARTITION_HORZ/VERT strip that reads | ||
| 16059 | +/// one of those symbols off `side` alone takes BLOCK_16X16's row and desyncs | ||
| 16060 | +/// (lane-inter16ab r3: a real 16x8 compound strip with `comp_group_idx == 1`, | ||
| 16061 | +/// decode-order frame 5, our range 64901 vs the oracle's 47271 at the very | ||
| 16062 | +/// next block's mode read). | ||
| 16063 | +fn bsize_all_index(bw: usize, bh: usize) -> Option<usize> { | ||
| 16064 | + Some(match (bw, bh) { | ||
| 16065 | + (4, 4) => 0, | ||
| 16066 | + (4, 8) => 1, | ||
| 16067 | + (8, 4) => 2, | ||
| 16068 | + (8, 8) => 3, | ||
| 16069 | + (8, 16) => 4, | ||
| 16070 | + (16, 8) => 5, | ||
| 16071 | + (16, 16) => 6, | ||
| 16072 | + (16, 32) => 7, | ||
| 16073 | + (32, 16) => 8, | ||
| 16074 | + (32, 32) => 9, | ||
| 16075 | + (32, 64) => 10, | ||
| 16076 | + (64, 32) => 11, | ||
| 16077 | + (64, 64) => 12, | ||
| 16078 | + (64, 128) => 13, | ||
| 16079 | + (128, 64) => 14, | ||
| 16080 | + (128, 128) => 15, | ||
| 16081 | + (4, 16) => 16, | ||
| 16082 | + (16, 4) => 17, | ||
| 16083 | + (8, 32) => 18, | ||
| 16084 | + (32, 8) => 19, | ||
| 16085 | + (16, 64) => 20, | ||
| 16086 | + (64, 16) => 21, | ||
| 16087 | + _ => return None, | ||
| 16088 | + }) | ||
| 16089 | +} | ||
| 16090 | + | ||
| 16091 | +/// `av1_wedge_params_lookup[bsize].wedge_types > 0` (libaom `reconinter.c`): | ||
| 16092 | +/// the block sizes that carry a wedge codebook at all. A `compound_type` | ||
| 16093 | +/// symbol is written only for these; every other size infers | ||
| 16094 | +/// `COMPOUND_DIFFWTD`. | ||
| 16095 | +fn wedge_used_bsize(bw: usize, bh: usize) -> bool { | ||
| 16096 | + matches!( | ||
| 16097 | + (bw, bh), | ||
| 16098 | + (8, 8) | (8, 16) | (16, 8) | (16, 16) | (16, 32) | (32, 16) | (32, 32) | (8, 32) | (32, 8) | ||
| 16099 | + ) | ||
| 16100 | +} | ||
| 16101 | + | ||
| 16054 | /// Whether a compound reference pair is unidirectional (both references on | 16102 | /// Whether a compound reference pair is unidirectional (both references on |
| 16055 | /// the same temporal side of the current frame) -- `has_uni_comp_refs` | 16103 | /// the same temporal side of the current frame) -- `has_uni_comp_refs` |
| 16056 | /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition: | 16104 | /// (libaom `av1_reference_frame_utils.h`/`pred_common.c`'s own definition: |
| @@ -16895,16 +16943,23 @@ fn decode_inter_block( | |||
| 16895 | // writes NO `compound_type` symbol there and INFERS | 16943 | // writes NO `compound_type` symbol there and INFERS |
| 16896 | // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal | 16944 | // `COMPOUND_DIFFWTD` -- only the 1-bit `mask_type` literal |
| 16897 | // follows. `None` here is exactly that inferred arm. | 16945 | // follows. `None` here is exactly that inferred arm. |
| 16898 | - let wedge_bsize = match side { | 16946 | + // lane-inter16ab r3: the row is this block's TRUE |
| 16899 | - 8 => Some(3), | 16947 | + // `BLOCK_SIZES_ALL` index, not the enclosing square `side`'s |
| 16900 | - 16 => Some(6), | 16948 | + // -- a 16x8 strip reads `compound_type_cdf[BLOCK_16X8]`. |
| 16901 | - 32 => Some(9), | 16949 | + let wedge_bsize = |
| 16902 | - _ => None, | 16950 | + bsize_all_index(write_w, write_h).filter(|_| wedge_used_bsize(write_w, write_h)); |
| 16903 | - }; | ||
| 16904 | let compound_type = match wedge_bsize { | 16951 | let compound_type = match wedge_bsize { |
| 16905 | Some(b) => dec.symbol(&mut cdfs.compound_type[b]), | 16952 | Some(b) => dec.symbol(&mut cdfs.compound_type[b]), |
| 16906 | None => 1, | 16953 | None => 1, |
| 16907 | }; | 16954 | }; |
| 16955 | + if wedge_bsize.is_some() && compound_type == 0 && write_w != write_h { | ||
| 16956 | + // The wedge mask codebook (`wedge.rs`) is built for the | ||
| 16957 | + // square sizes only; a rect wedge block is refused by | ||
| 16958 | + // name rather than blended with the wrong mask. | ||
| 16959 | + return Err(unsupported( | ||
| 16960 | + "a COMPOUND_WEDGE mask on a rectangular inter block (the wedge codebook is square-only)", | ||
| 16961 | + )); | ||
| 16962 | + } | ||
| 16908 | if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) { | 16963 | if let Some(wedge_bsize) = wedge_bsize.filter(|_| compound_type == 0) { |
| 16909 | // COMPOUND_WEDGE: lane-wedge r3, codebook checksum- | 16964 | // COMPOUND_WEDGE: lane-wedge r3, codebook checksum- |
| 16910 | // verified vs independent C dump (wedge.rs). | 16965 | // verified vs independent C dump (wedge.rs). |
| @@ -17904,8 +17959,19 @@ fn decode_inter_block( | |||
| 17904 | // `enable_interintra_wedge` seq bit -- the wedge flag | 17959 | // `enable_interintra_wedge` seq bit -- the wedge flag |
| 17905 | // (`av1_is_wedge_used(bsize)` holds for 16x16/32x32). | 17960 | // (`av1_is_wedge_used(bsize)` holds for 16x16/32x32). |
| 17906 | let ii = dec.symbol(&mut cdfs.interintra_mode[bsize_group]) as u8; | 17961 | let ii = dec.symbol(&mut cdfs.interintra_mode[bsize_group]) as u8; |
| 17907 | - let wedge_bsize = if side == 16 { 6 } else { 9 }; | 17962 | + // lane-inter16ab r3 (same class as the compound |
| 17963 | + // `compound_type` row below): the row is the block's TRUE | ||
| 17964 | + // `BLOCK_SIZES_ALL` index -- a 16x8 / 32x16 interintra | ||
| 17965 | + // strip is BLOCK_16X8 / BLOCK_32X16, not its square | ||
| 17966 | + // `side`'s BLOCK_16X16 / BLOCK_32X32. | ||
| 17967 | + let wedge_bsize = bsize_all_index(write_w, write_h) | ||
| 17968 | + .expect("interintra shape is a BLOCK_SIZES_ALL size"); | ||
| 17908 | let wedge = dec.symbol(&mut cdfs.wedge_interintra[wedge_bsize]) == 1; | 17969 | let wedge = dec.symbol(&mut cdfs.wedge_interintra[wedge_bsize]) == 1; |
| 17970 | + if wedge && write_w != write_h { | ||
| 17971 | + return Err(unsupported( | ||
| 17972 | + "a wedge interintra mask on a rectangular inter block (the wedge codebook is square-only)", | ||
| 17973 | + )); | ||
| 17974 | + } | ||
| 17909 | if wedge { | 17975 | if wedge { |
| 17910 | // lane-wii r2 (spec 5.11.25): `wedge_index` is an | 17976 | // lane-wii r2 (spec 5.11.25): `wedge_index` is an |
| 17911 | // ADAPTING CDF symbol over the same `wedge_bsize` row; | 17977 | // ADAPTING CDF symbol over the same `wedge_bsize` row; |
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
| @@ -77,7 +77,8 @@ const REFUSALS: &[&str] = &[ | |||
| 77 | // r2 residue: `vartx_leaves` is a list of SQUARE units, and | 77 | // r2 residue: `vartx_leaves` is a list of SQUARE units, and |
| 78 | // `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 -- the split tree | 78 | // `sub_tx_size_map[TX_16X4]` is the rectangular TX_8X4 -- the split tree |
| 79 | // and its per-unit residual reader both need rect leaves. | 79 | // and its per-unit residual reader both need rect leaves. |
| 80 | - "a split transform on a 16x16-level 1:4 inter strip (sub_tx_size_map[TX_16X4] is the rectangular TX_8X4)", | 80 | + "a COMPOUND_WEDGE mask on a rectangular inter block (the wedge codebook is square-only)", |
| 81 | + "a wedge interintra mask on a rectangular inter block (the wedge codebook is square-only)", | ||
| 81 | // r2 residue: `decode_intra_rect_in_inter` codes chroma at the strip's own | 82 | // r2 residue: `decode_intra_rect_in_inter` codes chroma at the strip's own |
| 82 | // halved footprint, which for a 16x4 strip is an 8x2 transform libaom | 83 | // halved footprint, which for a 16x4 strip is an 8x2 transform libaom |
| 83 | // never wrote (its chroma is the PAIR's 8x4, coded by the odd strip). | 84 | // never wrote (its chroma is the PAIR's 8x4, coded by the odd strip). |