Merge branch 'lane-part32': SB-level HORZ/VERT/HORZ_A/HORZ_B/VERT_A/VERT_B at 64x64 gated pixel-exact (has_tr_vert/has_bl_vert tables for VERT_A/B visit order); refusal narrowed to HORZ_4/VERT_4 (verifier PASS, 269/0/24)
Browse files at this commit9 changed files +1233 -43
- crates/ec-av1/src/cdf.rs +56 -21
- crates/ec-av1/src/cdf_state.rs +7 -3
- crates/ec-av1/src/decode.rs +511 -5
- crates/ec-av1/src/encode.rs +72 -2
- crates/ec-av1/src/refusal_inventory.rs +1 -1
- crates/ec-av1/src/stream.rs +225 -11
- lanes/part32-r1.report.md +117 -0
- lanes/part32-r2.report.md +107 -0
- lanes/part32-r5.report.md +137 -0
crates/ec-av1/src/cdf.rsmodified+56 -21
| @@ -266,18 +266,36 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ | ||
| 266 | 266 | 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, |
| 267 | 267 | ]; |
| 268 | 268 | |
| 269 | -/// `av1_default_eob_multi512_cdfs[*][1][*]` (`token_cdfs.h:874-901`, | |
| 270 | -/// lane-sbpart): the end-of-block group of a CHROMA transform with 512 coded | |
| 271 | -/// positions -- what a 32x16/16x32 chroma transform has (the chroma plane of | |
| 272 | -/// an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip, whose luma | |
| 273 | -/// coefficients truncate to the 64x64-superblock's own 32x32 corner-scan | |
| 274 | -/// (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is small enough | |
| 275 | -/// that no truncation applies). Unlike every other `EOB_PT_*` table here, | |
| 276 | -/// libaom's default is the exact same flat distribution at all four | |
| 277 | -/// q-contexts and both `eob_multi_size` selectors (`token_cdfs.h` rows), so | |
| 278 | -/// one constant covers every q-context -- no `_Q0`/`_Q1`/`_Q3` siblings. | |
| 269 | +/// `av1_default_eob_multi512_cdfs[2][1][0]` (`token_cdfs.h:874-901`, | |
| 270 | +/// lane-part32 r4): the end-of-block group of a CHROMA transform with 512 | |
| 271 | +/// coded positions -- what a 32x16/16x32 chroma transform has (the chroma | |
| 272 | +/// plane of an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip, | |
| 273 | +/// whose luma coefficients truncate to the 64x64-superblock's own 32x32 | |
| 274 | +/// corner-scan (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is | |
| 275 | +/// small enough that no truncation applies). | |
| 276 | +/// | |
| 277 | +/// lane-sbpart originally transcribed the `[1][1]` row -- the | |
| 278 | +/// `TX_CLASS_HORIZ`/`VERT` (1D) sibling, whose default IS the flat | |
| 279 | +/// `3277, 6554, ...` ramp at every q-context -- and wrote that flatness into | |
| 280 | +/// this comment as a property of the whole table. The 2D row this decoder | |
| 281 | +/// actually reads is q-dependent like every other `EOB_PT_*` family, so a | |
| 282 | +/// real `--cq-level=45` stream (q-context 3) read the wrong CDF and desynced | |
| 283 | +/// the tile at the first 32x16 chroma transform of the first SB-level | |
| 284 | +/// HORZ/VERT strip. | |
| 279 | 285 | pub const EOB_PT_512_CHROMA: [u16; 11] = [ |
| 280 | - 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, | |
| 286 | + 12015, 14769, 19588, 22052, 24222, 25812, 27300, 29219, 32114, 32768, 0, | |
| 287 | +]; | |
| 288 | +/// [`EOB_PT_512_CHROMA`], q-context 0 (`base_q_idx` 0..=20). | |
| 289 | +pub const EOB_PT_512_CHROMA_Q0: [u16; 11] = [ | |
| 290 | + 5095, 6446, 9996, 13354, 16017, 17986, 20919, 26129, 29140, 32768, 0, | |
| 291 | +]; | |
| 292 | +/// [`EOB_PT_512_CHROMA`], q-context 1 (`base_q_idx` 21..=60). | |
| 293 | +pub const EOB_PT_512_CHROMA_Q1: [u16; 11] = [ | |
| 294 | + 7265, 9979, 15819, 19250, 21780, 23846, 26478, 28396, 31811, 32768, 0, | |
| 295 | +]; | |
| 296 | +/// [`EOB_PT_512_CHROMA`], q-context 3 (`base_q_idx` 121..=255). | |
| 297 | +pub const EOB_PT_512_CHROMA_Q3: [u16; 11] = [ | |
| 298 | + 21093, 23043, 25742, 27658, 29097, 29716, 30073, 30820, 31956, 32768, 0, | |
| 281 | 299 | ]; |
| 282 | 300 | |
| 283 | 301 | /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient, |
| @@ -783,22 +801,39 @@ pub const NZ_MAP_CTX_OFFSET_32: [[u8; 5]; 5] = [ | ||
| 783 | 801 | /// indexes this position table by the raw, un-adjusted `tx_size` -- lane-sbpart |
| 784 | 802 | /// r8 root cause) is genuinely rectangular, not square. Distinct from |
| 785 | 803 | /// [`NZ_MAP_CTX_OFFSET_32`] starting at `(row=1, col=0)`. |
| 804 | +// lane-part32 r3: this table was TRANSPOSED (row/col swapped) as landed by | |
| 805 | +// lane-sbpart r8 -- caught by tracing a real aomenc pin against a patched | |
| 806 | +// aomdec (added per-symbol `EC_TRACE_COEFF` ctx prints to | |
| 807 | +// `read_coeffs_reverse{,_2d}` in `~/.cache/aom-oracle`), which showed our own | |
| 808 | +// `(row=2, col=0)` reading ctx-offset 11 where the real decoder's equivalent | |
| 809 | +// position read 6. Re-derived straight from libaom's own generating | |
| 810 | +// comment in `get_nz_map_ctx_from_stats` (`txb_common.h:199-210`): for | |
| 811 | +// `width < height` (this table, `TX_32X64`), ctx is `11 +` for `row < 2` | |
| 812 | +// *regardless of col* -- the old table instead special-cased `col < 2`, | |
| 813 | +// which is the `width > height` (`TX_64X32`) branch. Confirmed against the | |
| 814 | +// real `av1_nz_map_ctx_offset_32x64`/`_64x32` C arrays in | |
| 815 | +// `av1/common/txb_common.c`, decoded through libaom's own col-major | |
| 816 | +// `pos = col*32+row` raster (same convention [`SCAN_32X16`]'s doc comment | |
| 817 | +// already documents this decoder transcribes out of). | |
| 786 | 818 | pub const NZ_MAP_CTX_OFFSET_32X64: [[u8; 5]; 5] = [ |
| 787 | - [0, 11, 6, 6, 21], | |
| 788 | - [11, 11, 6, 21, 21], | |
| 789 | - [11, 11, 21, 21, 21], | |
| 790 | - [11, 11, 21, 21, 21], | |
| 791 | - [11, 11, 21, 21, 21], | |
| 819 | + [0, 11, 11, 11, 11], | |
| 820 | + [11, 11, 11, 11, 11], | |
| 821 | + [6, 6, 21, 21, 21], | |
| 822 | + [6, 21, 21, 21, 21], | |
| 823 | + [21, 21, 21, 21, 21], | |
| 792 | 824 | ]; |
| 793 | 825 | |
| 794 | 826 | /// [`NZ_MAP_CTX_OFFSET_32X64`]'s `TX_64X32` counterpart (libaom |
| 795 | 827 | /// `av1_nz_map_ctx_offset_64x32`): a `PARTITION_HORZ` strip's luma corner. |
| 828 | +/// `width > height` here, so the `col < 2` branch (offset 16) fires | |
| 829 | +/// regardless of row -- transpose of [`NZ_MAP_CTX_OFFSET_32X64`]'s `row < 2` | |
| 830 | +/// branch, same r3 fix (see that table's doc comment). | |
| 796 | 831 | pub const NZ_MAP_CTX_OFFSET_64X32: [[u8; 5]; 5] = [ |
| 797 | - [0, 16, 16, 16, 16], | |
| 798 | - [16, 16, 16, 16, 16], | |
| 799 | - [6, 6, 21, 21, 21], | |
| 800 | - [6, 21, 21, 21, 21], | |
| 801 | - [21, 21, 21, 21, 21], | |
| 832 | + [0, 16, 6, 6, 21], | |
| 833 | + [16, 16, 6, 21, 21], | |
| 834 | + [16, 16, 21, 21, 21], | |
| 835 | + [16, 16, 21, 21, 21], | |
| 836 | + [16, 16, 21, 21, 21], | |
| 802 | 837 | ]; |
| 803 | 838 | |
| 804 | 839 | /// `Default_Txb_Skip_Cdf[2][2][7..10]` (spec 9.4): the all-zero flag of a |
crates/ec-av1/src/cdf_state.rsmodified+7 -3
| @@ -1026,9 +1026,13 @@ impl Cdfs { | ||
| 1026 | 1026 | cdf::EOB_PT_128_CHROMA, |
| 1027 | 1027 | cdf::EOB_PT_128_CHROMA_Q3, |
| 1028 | 1028 | ), |
| 1029 | - // Flat default at every q-context (see the constant's own doc | |
| 1030 | - // comment) -- no `pick()` needed. | |
| 1031 | - eob_pt_512_chroma: cdf::EOB_PT_512_CHROMA, | |
| 1029 | + eob_pt_512_chroma: pick( | |
| 1030 | + q_ctx, | |
| 1031 | + cdf::EOB_PT_512_CHROMA_Q0, | |
| 1032 | + cdf::EOB_PT_512_CHROMA_Q1, | |
| 1033 | + cdf::EOB_PT_512_CHROMA, | |
| 1034 | + cdf::EOB_PT_512_CHROMA_Q3, | |
| 1035 | + ), | |
| 1032 | 1036 | eob_extra_luma_32: pick( |
| 1033 | 1037 | q_ctx, |
| 1034 | 1038 | cdf::EOB_EXTRA_LUMA_32_Q0, |
crates/ec-av1/src/decode.rsmodified+511 -5
| @@ -1197,6 +1197,29 @@ pub(crate) fn sb_rect_hits() -> usize { | ||
| 1197 | 1197 | SB_RECT_HITS.with(|c| c.get()) |
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | +// lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/ | |
| 1201 | +// `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x64 | |
| 1202 | +// strip) fired. Real aomenc picks these at 64 even with | |
| 1203 | +// `--enable-ab-partitions=0` (lane-sbpart r2's own measurement), so this is | |
| 1204 | +// the counter the gate hard-asserts. | |
| 1205 | +thread_local! { | |
| 1206 | + static SB_AB_HITS: std::cell::Cell<[usize; 4]> = | |
| 1207 | + const { std::cell::Cell::new([0; 4]) }; | |
| 1208 | +} | |
| 1209 | + | |
| 1210 | +/// Current value of [`SB_AB_HITS`], summed over the four arms. | |
| 1211 | +pub(crate) fn sb_ab_hits() -> usize { | |
| 1212 | + SB_AB_HITS.with(|c| c.get().iter().sum()) | |
| 1213 | +} | |
| 1214 | + | |
| 1215 | +/// [`SB_AB_HITS`] split per arm, in `PARTITION_HORZ_A`, `_HORZ_B`, | |
| 1216 | +/// `_VERT_A`, `_VERT_B` order -- what the gate hard-asserts arm by arm, so a | |
| 1217 | +/// run where aomenc's RD only ever picked (say) `HORZ_A` cannot pass off as | |
| 1218 | +/// proof of all four. | |
| 1219 | +pub(crate) fn sb_ab_hits_by_arm() -> [usize; 4] { | |
| 1220 | + SB_AB_HITS.with(std::cell::Cell::get) | |
| 1221 | +} | |
| 1222 | + | |
| 1200 | 1223 | // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane |
| 1201 | 1224 | // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the |
| 1202 | 1225 | // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not |
| @@ -1226,6 +1249,38 @@ pub(crate) fn partab_hits() -> usize { | ||
| 1226 | 1249 | PARTAB_HITS.with(|c| c.get()) |
| 1227 | 1250 | } |
| 1228 | 1251 | |
| 1252 | +// lane-part32 r1: how many 32x32 quadrants decoded each INTRA AB/4-way arm, | |
| 1253 | +// one counter per arm rather than one shared total -- the gate hard-asserts | |
| 1254 | +// each of these individually nonzero so a recipe that only ever fires | |
| 1255 | +// HORZ_A can't silently stand in for the whole set. | |
| 1256 | +thread_local! { | |
| 1257 | + static INTRA_HORZ_A_HITS: std::cell::Cell<usize> = | |
| 1258 | + const { std::cell::Cell::new(0) }; | |
| 1259 | + static INTRA_HORZ_B_HITS: std::cell::Cell<usize> = | |
| 1260 | + const { std::cell::Cell::new(0) }; | |
| 1261 | + static INTRA_VERT_A_HITS: std::cell::Cell<usize> = | |
| 1262 | + const { std::cell::Cell::new(0) }; | |
| 1263 | + static INTRA_VERT_B_HITS: std::cell::Cell<usize> = | |
| 1264 | + const { std::cell::Cell::new(0) }; | |
| 1265 | +} | |
| 1266 | + | |
| 1267 | +/// Current value of [`INTRA_HORZ_A_HITS`]. | |
| 1268 | +pub(crate) fn intra_horz_a_hits() -> usize { | |
| 1269 | + INTRA_HORZ_A_HITS.with(|c| c.get()) | |
| 1270 | +} | |
| 1271 | +/// Current value of [`INTRA_HORZ_B_HITS`]. | |
| 1272 | +pub(crate) fn intra_horz_b_hits() -> usize { | |
| 1273 | + INTRA_HORZ_B_HITS.with(|c| c.get()) | |
| 1274 | +} | |
| 1275 | +/// Current value of [`INTRA_VERT_A_HITS`]. | |
| 1276 | +pub(crate) fn intra_vert_a_hits() -> usize { | |
| 1277 | + INTRA_VERT_A_HITS.with(|c| c.get()) | |
| 1278 | +} | |
| 1279 | +/// Current value of [`INTRA_VERT_B_HITS`]. | |
| 1280 | +pub(crate) fn intra_vert_b_hits() -> usize { | |
| 1281 | + INTRA_VERT_B_HITS.with(|c| c.get()) | |
| 1282 | +} | |
| 1283 | + | |
| 1229 | 1284 | // How many [`read_inter_compound_mode`] reads actually happened |
| 1230 | 1285 | // (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own |
| 1231 | 1286 | // `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound |
| @@ -1777,7 +1832,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) -> | ||
| 1777 | 1832 | (TxClass::TwoD, _) | (_, None) => coding.eob_pt, |
| 1778 | 1833 | (_, Some(class1)) => class1, |
| 1779 | 1834 | }; |
| 1780 | - if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() && eob_pt.len() == 12 { | |
| 1835 | + if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() { | |
| 1781 | 1836 | let (range, value) = dec.debug_state(); |
| 1782 | 1837 | eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}"); |
| 1783 | 1838 | } |
| @@ -2054,8 +2109,16 @@ fn read_coeffs_rect( | ||
| 2054 | 2109 | sign_ctx: usize, |
| 2055 | 2110 | default_tx_type: TxType, |
| 2056 | 2111 | ) -> Result<(Vec<i32>, TxType)> { |
| 2112 | + let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some(); | |
| 2057 | 2113 | let mut grid = vec![0i32; w * h]; |
| 2058 | 2114 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 2115 | + if ec_trace_coeff { | |
| 2116 | + let (rng, _) = dec.debug_state(); | |
| 2117 | + eprintln!( | |
| 2118 | + "EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero={} rng={rng}", | |
| 2119 | + all_zero as i32 | |
| 2120 | + ); | |
| 2121 | + } | |
| 2059 | 2122 | if all_zero { |
| 2060 | 2123 | return Ok((grid, TxType::DctDct)); |
| 2061 | 2124 | } |
| @@ -2071,16 +2134,35 @@ fn read_coeffs_rect( | ||
| 2071 | 2134 | )); |
| 2072 | 2135 | } |
| 2073 | 2136 | let eob = read_eob(dec, coding, TxClass::TwoD); |
| 2137 | + if ec_trace_coeff { | |
| 2138 | + let (rng, _) = dec.debug_state(); | |
| 2139 | + eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}"); | |
| 2140 | + } | |
| 2074 | 2141 | let mut levels = vec![0i32; w * h]; |
| 2075 | 2142 | for scan_idx in (0..eob).rev() { |
| 2076 | 2143 | let pos = scan[scan_idx] as usize; |
| 2077 | 2144 | let (row, col) = (pos / w, pos % w); |
| 2078 | 2145 | let level = if scan_idx == eob - 1 { |
| 2079 | 2146 | let ctx = eob_coeff_ctx(scan_idx, w * h); |
| 2080 | - dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1 | |
| 2147 | + let l = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1; | |
| 2148 | + if ec_trace_coeff { | |
| 2149 | + let (rng, _) = dec.debug_state(); | |
| 2150 | + eprintln!( | |
| 2151 | + "EC_COEFF_STEP tag=base_eob c={scan_idx} pos={pos} ctx={ctx} level={} rng={rng}", | |
| 2152 | + l - 1 | |
| 2153 | + ); | |
| 2154 | + } | |
| 2155 | + l | |
| 2081 | 2156 | } else { |
| 2082 | 2157 | let ctx = base_ctx_rect(&levels, w, h, row, col); |
| 2083 | - dec.symbol(&mut coding.base[ctx]) as i32 | |
| 2158 | + let l = dec.symbol(&mut coding.base[ctx]) as i32; | |
| 2159 | + if ec_trace_coeff { | |
| 2160 | + let (rng, _) = dec.debug_state(); | |
| 2161 | + eprintln!( | |
| 2162 | + "EC_COEFF_STEP tag=base c={scan_idx} pos={pos} ctx={ctx} level={l} rng={rng}" | |
| 2163 | + ); | |
| 2164 | + } | |
| 2165 | + l | |
| 2084 | 2166 | }; |
| 2085 | 2167 | let level = if level > NUM_BASE_LEVELS { |
| 2086 | 2168 | let ctx = br_ctx_rect(&levels, w, h, row, col); |
| @@ -2088,6 +2170,12 @@ fn read_coeffs_rect( | ||
| 2088 | 2170 | let mut sent = 0; |
| 2089 | 2171 | loop { |
| 2090 | 2172 | let k = dec.symbol(&mut coding.br[ctx]) as i32; |
| 2173 | + if ec_trace_coeff { | |
| 2174 | + let (rng, _) = dec.debug_state(); | |
| 2175 | + eprintln!( | |
| 2176 | + "EC_COEFF_STEP tag=br c={scan_idx} pos={pos} ctx={ctx} k={k} rng={rng}" | |
| 2177 | + ); | |
| 2178 | + } | |
| 2091 | 2179 | level += k; |
| 2092 | 2180 | sent += BR_STEP; |
| 2093 | 2181 | if k < BR_STEP || sent >= COEFF_BASE_RANGE { |
| @@ -2100,6 +2188,10 @@ fn read_coeffs_rect( | ||
| 2100 | 2188 | }; |
| 2101 | 2189 | levels[pos] = level; |
| 2102 | 2190 | } |
| 2191 | + if ec_trace_coeff { | |
| 2192 | + let (rng, _) = dec.debug_state(); | |
| 2193 | + eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}"); | |
| 2194 | + } | |
| 2103 | 2195 | for &pos in &scan[..eob] { |
| 2104 | 2196 | let level = levels[pos as usize]; |
| 2105 | 2197 | if level == 0 { |
| @@ -5270,6 +5362,15 @@ impl PlaneBuf { | ||
| 5270 | 5362 | smooth_neighbor: bool, |
| 5271 | 5363 | ) { |
| 5272 | 5364 | let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach); |
| 5365 | + if std::env::var_os("EC_DEBUG_EDGES").is_some() { | |
| 5366 | + eprintln!( | |
| 5367 | + "EDGES x={x} y={y} bw={bw} bh={bh} mode={mode} above={:?} left_len={:?} left0={:?} corner={corner:?} tx0={} ty0={} truew={} trueh={}", | |
| 5368 | + above.as_ref().map(|a| (a.len(), a[0])), | |
| 5369 | + left.as_ref().map(|l| l.len()), | |
| 5370 | + left.as_ref().map(|l| l[0]), | |
| 5371 | + self.tile_x0, self.tile_y0, self.true_width, self.true_height | |
| 5372 | + ); | |
| 5373 | + } | |
| 5273 | 5374 | let mut prediction = vec![0u16; bw * bh]; |
| 5274 | 5375 | if let Some(fi_mode) = filter_intra { |
| 5275 | 5376 | crate::intra::predict_filter_intra( |
| @@ -6507,6 +6608,11 @@ fn apply_deblock( | ||
| 6507 | 6608 | frame_width: usize, |
| 6508 | 6609 | frame_height: usize, |
| 6509 | 6610 | ) { |
| 6611 | + // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel | |
| 6612 | + // mismatch between the raw reconstruction and post-filter output. | |
| 6613 | + if std::env::var_os("EC_AV1_DEBUG_SKIP_DEBLOCK").is_some() { | |
| 6614 | + return; | |
| 6615 | + } | |
| 6510 | 6616 | if lf.level[0] != 0 || lf.level[1] != 0 { |
| 6511 | 6617 | deblock_plane(y, 0, lf, n, frame_width, frame_height); |
| 6512 | 6618 | } |
| @@ -7155,6 +7261,10 @@ fn apply_cdef( | ||
| 7155 | 7261 | cdef: &CdefParams, |
| 7156 | 7262 | skip_grid: &Neighbours, |
| 7157 | 7263 | ) { |
| 7264 | + // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling. | |
| 7265 | + if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() { | |
| 7266 | + return; | |
| 7267 | + } | |
| 7158 | 7268 | // `cdef.bits == 0` still means "no filtering at all" whenever the single |
| 7159 | 7269 | // (index 0) strength pair is all-zero -- the fast path every existing |
| 7160 | 7270 | // gate stream takes. A `bits > 0` frame can still be all-zero-strength |
| @@ -8181,6 +8291,307 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 8181 | 8291 | reduced_tx_set, |
| 8182 | 8292 | )?; |
| 8183 | 8293 | } |
| 8294 | + PARTITION_HORZ_A => { | |
| 8295 | + // lane-part32 r1: two 16x16 squares on top + | |
| 8296 | + // a true 32x16 strip below (mirrors | |
| 8297 | + // decode_inter_block's cd6cb6d HORZ_A: TL, | |
| 8298 | + // TR, bottom strip). | |
| 8299 | + INTRA_HORZ_A_HITS.with(|c| c.set(c.get() + 1)); | |
| 8300 | + decode_block( | |
| 8301 | + &mut dec, | |
| 8302 | + &mut cdfs, | |
| 8303 | + &mut neighbours, | |
| 8304 | + at32, | |
| 8305 | + SUB, | |
| 8306 | + TxbSet::Luma16, | |
| 8307 | + TxbSet::Chroma8, | |
| 8308 | + TX16, | |
| 8309 | + TX8, | |
| 8310 | + (&scan16, &scan8), | |
| 8311 | + true, | |
| 8312 | + &mut y, | |
| 8313 | + &mut u, | |
| 8314 | + &mut v, | |
| 8315 | + base_q_idx, | |
| 8316 | + enable_filter_intra, | |
| 8317 | + allow_screen_content_tools, | |
| 8318 | + allow_intrabc, | |
| 8319 | + &scan32, | |
| 8320 | + &scan16, | |
| 8321 | + &scan8, | |
| 8322 | + &scan4, | |
| 8323 | + tx_select, | |
| 8324 | + reduced_tx_set, | |
| 8325 | + )?; | |
| 8326 | + decode_block( | |
| 8327 | + &mut dec, | |
| 8328 | + &mut cdfs, | |
| 8329 | + &mut neighbours, | |
| 8330 | + (at32.0, at32.1 + 1), | |
| 8331 | + SUB, | |
| 8332 | + TxbSet::Luma16, | |
| 8333 | + TxbSet::Chroma8, | |
| 8334 | + TX16, | |
| 8335 | + TX8, | |
| 8336 | + (&scan16, &scan8), | |
| 8337 | + true, | |
| 8338 | + &mut y, | |
| 8339 | + &mut u, | |
| 8340 | + &mut v, | |
| 8341 | + base_q_idx, | |
| 8342 | + enable_filter_intra, | |
| 8343 | + allow_screen_content_tools, | |
| 8344 | + allow_intrabc, | |
| 8345 | + &scan32, | |
| 8346 | + &scan16, | |
| 8347 | + &scan8, | |
| 8348 | + &scan4, | |
| 8349 | + tx_select, | |
| 8350 | + reduced_tx_set, | |
| 8351 | + )?; | |
| 8352 | + decode_block_rect( | |
| 8353 | + &mut dec, | |
| 8354 | + &mut cdfs, | |
| 8355 | + &mut neighbours, | |
| 8356 | + (at32.0 + 1, at32.1), | |
| 8357 | + 32, | |
| 8358 | + 16, | |
| 8359 | + &mut y, | |
| 8360 | + &mut u, | |
| 8361 | + &mut v, | |
| 8362 | + enable_filter_intra, | |
| 8363 | + allow_screen_content_tools, | |
| 8364 | + base_q_idx, | |
| 8365 | + tx_select, | |
| 8366 | + reduced_tx_set, | |
| 8367 | + )?; | |
| 8368 | + } | |
| 8369 | + PARTITION_HORZ_B => { | |
| 8370 | + // lane-part32 r1: a true 32x16 strip on top + | |
| 8371 | + // two 16x16 squares below (mirrors HORZ_A | |
| 8372 | + // with the strip/squares order flipped, same | |
| 8373 | + // shape as libaom decode_partition's HORZ_B). | |
| 8374 | + INTRA_HORZ_B_HITS.with(|c| c.set(c.get() + 1)); | |
| 8375 | + decode_block_rect( | |
| 8376 | + &mut dec, | |
| 8377 | + &mut cdfs, | |
| 8378 | + &mut neighbours, | |
| 8379 | + at32, | |
| 8380 | + 32, | |
| 8381 | + 16, | |
| 8382 | + &mut y, | |
| 8383 | + &mut u, | |
| 8384 | + &mut v, | |
| 8385 | + enable_filter_intra, | |
| 8386 | + allow_screen_content_tools, | |
| 8387 | + base_q_idx, | |
| 8388 | + tx_select, | |
| 8389 | + reduced_tx_set, | |
| 8390 | + )?; | |
| 8391 | + decode_block( | |
| 8392 | + &mut dec, | |
| 8393 | + &mut cdfs, | |
| 8394 | + &mut neighbours, | |
| 8395 | + (at32.0 + 1, at32.1), | |
| 8396 | + SUB, | |
| 8397 | + TxbSet::Luma16, | |
| 8398 | + TxbSet::Chroma8, | |
| 8399 | + TX16, | |
| 8400 | + TX8, | |
| 8401 | + (&scan16, &scan8), | |
| 8402 | + true, | |
| 8403 | + &mut y, | |
| 8404 | + &mut u, | |
| 8405 | + &mut v, | |
| 8406 | + base_q_idx, | |
| 8407 | + enable_filter_intra, | |
| 8408 | + allow_screen_content_tools, | |
| 8409 | + allow_intrabc, | |
| 8410 | + &scan32, | |
| 8411 | + &scan16, | |
| 8412 | + &scan8, | |
| 8413 | + &scan4, | |
| 8414 | + tx_select, | |
| 8415 | + reduced_tx_set, | |
| 8416 | + )?; | |
| 8417 | + decode_block( | |
| 8418 | + &mut dec, | |
| 8419 | + &mut cdfs, | |
| 8420 | + &mut neighbours, | |
| 8421 | + (at32.0 + 1, at32.1 + 1), | |
| 8422 | + SUB, | |
| 8423 | + TxbSet::Luma16, | |
| 8424 | + TxbSet::Chroma8, | |
| 8425 | + TX16, | |
| 8426 | + TX8, | |
| 8427 | + (&scan16, &scan8), | |
| 8428 | + true, | |
| 8429 | + &mut y, | |
| 8430 | + &mut u, | |
| 8431 | + &mut v, | |
| 8432 | + base_q_idx, | |
| 8433 | + enable_filter_intra, | |
| 8434 | + allow_screen_content_tools, | |
| 8435 | + allow_intrabc, | |
| 8436 | + &scan32, | |
| 8437 | + &scan16, | |
| 8438 | + &scan8, | |
| 8439 | + &scan4, | |
| 8440 | + tx_select, | |
| 8441 | + reduced_tx_set, | |
| 8442 | + )?; | |
| 8443 | + } | |
| 8444 | + PARTITION_VERT_A => { | |
| 8445 | + // lane-part32 r1: mirror of HORZ_A with | |
| 8446 | + // width/height swapped (TL, BL, right 16x32 | |
| 8447 | + // strip). | |
| 8448 | + INTRA_VERT_A_HITS.with(|c| c.set(c.get() + 1)); | |
| 8449 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 8450 | + decode_block( | |
| 8451 | + &mut dec, | |
| 8452 | + &mut cdfs, | |
| 8453 | + &mut neighbours, | |
| 8454 | + at32, | |
| 8455 | + SUB, | |
| 8456 | + TxbSet::Luma16, | |
| 8457 | + TxbSet::Chroma8, | |
| 8458 | + TX16, | |
| 8459 | + TX8, | |
| 8460 | + (&scan16, &scan8), | |
| 8461 | + true, | |
| 8462 | + &mut y, | |
| 8463 | + &mut u, | |
| 8464 | + &mut v, | |
| 8465 | + base_q_idx, | |
| 8466 | + enable_filter_intra, | |
| 8467 | + allow_screen_content_tools, | |
| 8468 | + allow_intrabc, | |
| 8469 | + &scan32, | |
| 8470 | + &scan16, | |
| 8471 | + &scan8, | |
| 8472 | + &scan4, | |
| 8473 | + tx_select, | |
| 8474 | + reduced_tx_set, | |
| 8475 | + )?; | |
| 8476 | + decode_block( | |
| 8477 | + &mut dec, | |
| 8478 | + &mut cdfs, | |
| 8479 | + &mut neighbours, | |
| 8480 | + (at32.0 + 1, at32.1), | |
| 8481 | + SUB, | |
| 8482 | + TxbSet::Luma16, | |
| 8483 | + TxbSet::Chroma8, | |
| 8484 | + TX16, | |
| 8485 | + TX8, | |
| 8486 | + (&scan16, &scan8), | |
| 8487 | + true, | |
| 8488 | + &mut y, | |
| 8489 | + &mut u, | |
| 8490 | + &mut v, | |
| 8491 | + base_q_idx, | |
| 8492 | + enable_filter_intra, | |
| 8493 | + allow_screen_content_tools, | |
| 8494 | + allow_intrabc, | |
| 8495 | + &scan32, | |
| 8496 | + &scan16, | |
| 8497 | + &scan8, | |
| 8498 | + &scan4, | |
| 8499 | + tx_select, | |
| 8500 | + reduced_tx_set, | |
| 8501 | + )?; | |
| 8502 | + decode_block_rect( | |
| 8503 | + &mut dec, | |
| 8504 | + &mut cdfs, | |
| 8505 | + &mut neighbours, | |
| 8506 | + (at32.0, at32.1 + 1), | |
| 8507 | + 16, | |
| 8508 | + 32, | |
| 8509 | + &mut y, | |
| 8510 | + &mut u, | |
| 8511 | + &mut v, | |
| 8512 | + enable_filter_intra, | |
| 8513 | + allow_screen_content_tools, | |
| 8514 | + base_q_idx, | |
| 8515 | + tx_select, | |
| 8516 | + reduced_tx_set, | |
| 8517 | + )?; | |
| 8518 | + } | |
| 8519 | + PARTITION_VERT_B => { | |
| 8520 | + // lane-part32 r1: a true 16x32 strip on the | |
| 8521 | + // left + two 16x16 squares on the right | |
| 8522 | + // (libaom decode_partition VERT_B: left | |
| 8523 | + // strip, TR, BR). | |
| 8524 | + INTRA_VERT_B_HITS.with(|c| c.set(c.get() + 1)); | |
| 8525 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 8526 | + decode_block_rect( | |
| 8527 | + &mut dec, | |
| 8528 | + &mut cdfs, | |
| 8529 | + &mut neighbours, | |
| 8530 | + at32, | |
| 8531 | + 16, | |
| 8532 | + 32, | |
| 8533 | + &mut y, | |
| 8534 | + &mut u, | |
| 8535 | + &mut v, | |
| 8536 | + enable_filter_intra, | |
| 8537 | + allow_screen_content_tools, | |
| 8538 | + base_q_idx, | |
| 8539 | + tx_select, | |
| 8540 | + reduced_tx_set, | |
| 8541 | + )?; | |
| 8542 | + decode_block( | |
| 8543 | + &mut dec, | |
| 8544 | + &mut cdfs, | |
| 8545 | + &mut neighbours, | |
| 8546 | + (at32.0, at32.1 + 1), | |
| 8547 | + SUB, | |
| 8548 | + TxbSet::Luma16, | |
| 8549 | + TxbSet::Chroma8, | |
| 8550 | + TX16, | |
| 8551 | + TX8, | |
| 8552 | + (&scan16, &scan8), | |
| 8553 | + true, | |
| 8554 | + &mut y, | |
| 8555 | + &mut u, | |
| 8556 | + &mut v, | |
| 8557 | + base_q_idx, | |
| 8558 | + enable_filter_intra, | |
| 8559 | + allow_screen_content_tools, | |
| 8560 | + allow_intrabc, | |
| 8561 | + &scan32, | |
| 8562 | + &scan16, | |
| 8563 | + &scan8, | |
| 8564 | + &scan4, | |
| 8565 | + tx_select, | |
| 8566 | + reduced_tx_set, | |
| 8567 | + )?; | |
| 8568 | + decode_block( | |
| 8569 | + &mut dec, | |
| 8570 | + &mut cdfs, | |
| 8571 | + &mut neighbours, | |
| 8572 | + (at32.0 + 1, at32.1 + 1), | |
| 8573 | + SUB, | |
| 8574 | + TxbSet::Luma16, | |
| 8575 | + TxbSet::Chroma8, | |
| 8576 | + TX16, | |
| 8577 | + TX8, | |
| 8578 | + (&scan16, &scan8), | |
| 8579 | + true, | |
| 8580 | + &mut y, | |
| 8581 | + &mut u, | |
| 8582 | + &mut v, | |
| 8583 | + base_q_idx, | |
| 8584 | + enable_filter_intra, | |
| 8585 | + allow_screen_content_tools, | |
| 8586 | + allow_intrabc, | |
| 8587 | + &scan32, | |
| 8588 | + &scan16, | |
| 8589 | + &scan8, | |
| 8590 | + &scan4, | |
| 8591 | + tx_select, | |
| 8592 | + reduced_tx_set, | |
| 8593 | + )?; | |
| 8594 | + } | |
| 8184 | 8595 | _ => { |
| 8185 | 8596 | return Err(unsupported(format!( |
| 8186 | 8597 | "a 32x32 partition type this decoder does not code (value={part32})" |
| @@ -8260,10 +8671,103 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 8260 | 8671 | reduced_tx_set, |
| 8261 | 8672 | )?; |
| 8262 | 8673 | } |
| 8674 | + PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { | |
| 8675 | + // lane-part32 r4: the four superblock-level AB arms, each | |
| 8676 | + // two 32x32 squares plus one 64x32/32x64 strip, in | |
| 8677 | + // libaom's own `decode_partition` order (decodeframe.c: | |
| 8678 | + // HORZ_A = TL, TR, bottom strip; HORZ_B = top strip, BL, | |
| 8679 | + // BR; VERT_A = TL, BL, right strip; VERT_B = left strip, | |
| 8680 | + // TR, BR). The pieces are exactly the ones already proven | |
| 8681 | + // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and | |
| 8682 | + // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above. | |
| 8683 | + SB_AB_HITS.with(|c| { | |
| 8684 | + let mut h = c.get(); | |
| 8685 | + h[part - PARTITION_HORZ_A] += 1; | |
| 8686 | + c.set(h); | |
| 8687 | + }); | |
| 8688 | + // lane-part32 r5: only the two VERTICAL arms reorder the | |
| 8689 | + // square sub-blocks (TL, BL, TR, BR), so only they switch | |
| 8690 | + // libaom's `has_tr`/`has_bl` tables. | |
| 8691 | + let _vert_ab = (part == PARTITION_VERT_A || part == PARTITION_VERT_B) | |
| 8692 | + .then(crate::encode::Reach::vert_ab_partition); | |
| 8693 | + macro_rules! square32 { | |
| 8694 | + ($at:expr) => { | |
| 8695 | + decode_block( | |
| 8696 | + &mut dec, | |
| 8697 | + &mut cdfs, | |
| 8698 | + &mut neighbours, | |
| 8699 | + $at, | |
| 8700 | + BLOCK, | |
| 8701 | + TxbSet::Luma32, | |
| 8702 | + TxbSet::Chroma16, | |
| 8703 | + TX32, | |
| 8704 | + TX16, | |
| 8705 | + (&scan32, &scan16), | |
| 8706 | + true, | |
| 8707 | + &mut y, | |
| 8708 | + &mut u, | |
| 8709 | + &mut v, | |
| 8710 | + base_q_idx, | |
| 8711 | + enable_filter_intra, | |
| 8712 | + allow_screen_content_tools, | |
| 8713 | + allow_intrabc, | |
| 8714 | + &scan32, | |
| 8715 | + &scan16, | |
| 8716 | + &scan8, | |
| 8717 | + &scan4, | |
| 8718 | + tx_select, | |
| 8719 | + reduced_tx_set, | |
| 8720 | + )? | |
| 8721 | + }; | |
| 8722 | + } | |
| 8723 | + macro_rules! strip64 { | |
| 8724 | + ($at:expr, $bw:expr, $bh:expr) => { | |
| 8725 | + decode_block_rect64( | |
| 8726 | + &mut dec, | |
| 8727 | + &mut cdfs, | |
| 8728 | + &mut neighbours, | |
| 8729 | + $at, | |
| 8730 | + $bw, | |
| 8731 | + $bh, | |
| 8732 | + &mut y, | |
| 8733 | + &mut u, | |
| 8734 | + &mut v, | |
| 8735 | + enable_filter_intra, | |
| 8736 | + allow_screen_content_tools, | |
| 8737 | + base_q_idx, | |
| 8738 | + tx_select, | |
| 8739 | + reduced_tx_set, | |
| 8740 | + )? | |
| 8741 | + }; | |
| 8742 | + } | |
| 8743 | + let (br, bc) = (at.0 + 2, at.1 + 2); | |
| 8744 | + match part { | |
| 8745 | + PARTITION_HORZ_A => { | |
| 8746 | + square32!(at); | |
| 8747 | + square32!((at.0, bc)); | |
| 8748 | + strip64!((br, at.1), 64, 32); | |
| 8749 | + } | |
| 8750 | + PARTITION_HORZ_B => { | |
| 8751 | + strip64!(at, 64, 32); | |
| 8752 | + square32!((br, at.1)); | |
| 8753 | + square32!((br, bc)); | |
| 8754 | + } | |
| 8755 | + PARTITION_VERT_A => { | |
| 8756 | + square32!(at); | |
| 8757 | + square32!((br, at.1)); | |
| 8758 | + strip64!((at.0, bc), 32, 64); | |
| 8759 | + } | |
| 8760 | + _ => { | |
| 8761 | + strip64!(at, 32, 64); | |
| 8762 | + square32!((at.0, bc)); | |
| 8763 | + square32!((br, bc)); | |
| 8764 | + } | |
| 8765 | + } | |
| 8766 | + } | |
| 8263 | 8767 | _ => { |
| 8264 | 8768 | return Err(unsupported( |
| 8265 | - "a superblock-level partition type other than NONE or SPLIT (this \ | |
| 8266 | - decoder's intra tile path codes only those two at 64x64)", | |
| 8769 | + "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, \ | |
| 8770 | + four 64x16/16x64 strips)", | |
| 8267 | 8771 | )); |
| 8268 | 8772 | } |
| 8269 | 8773 | } |
| @@ -13922,6 +14426,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 13922 | 14426 | // lane-partab r1: mirror of PARTITION_HORZ_A with |
| 13923 | 14427 | // width/height swapped (TL, BL, right 16x32 strip). |
| 13924 | 14428 | PARTAB_HITS.with(|c| c.set(c.get() + 1)); |
| 14429 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 13925 | 14430 | decode_inter_block( |
| 13926 | 14431 | &mut dec, |
| 13927 | 14432 | &mut cdfs, |
| @@ -14083,6 +14588,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 14083 | 14588 | // 16x16 squares on the right (libaom decode_partition |
| 14084 | 14589 | // PARTITION_VERT_B: left strip, TR, BR). |
| 14085 | 14590 | PARTAB_HITS.with(|c| c.set(c.get() + 1)); |
| 14591 | + let _vert_ab = crate::encode::Reach::vert_ab_partition(); | |
| 14086 | 14592 | decode_inter_block( |
| 14087 | 14593 | &mut dec, |
| 14088 | 14594 | &mut cdfs, |
crates/ec-av1/src/encode.rsmodified+72 -2
| @@ -1043,6 +1043,59 @@ const HAS_BOTTOM_LEFT: [&[u8]; 3] = [ | ||
| 1043 | 1043 | ], |
| 1044 | 1044 | ]; |
| 1045 | 1045 | |
| 1046 | +/// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by | |
| 1047 | +/// [`Reach::table`] exactly like [`HAS_TOP_RIGHT`]: inside a | |
| 1048 | +/// `PARTITION_VERT_A`/`_B` the square sub-blocks are visited TL, BL, TR, BR | |
| 1049 | +/// rather than in raster order, so the bottom-left square's top-right | |
| 1050 | +/// neighbour is the partition's own right-hand rectangle -- not yet decoded. | |
| 1051 | +/// libaom switches tables on the partition type (`get_has_tr_table`); the | |
| 1052 | +/// ordinary table says 1 where this one says 0 (32x32 at row 1 col 0: | |
| 1053 | +/// `95` bit 4 = 1 vs `15` bit 4 = 0), which is exactly the case | |
| 1054 | +/// lane-part32 r5 caught reading undecoded samples. | |
| 1055 | +const HAS_TOP_RIGHT_VERT: [&[u8]; 3] = [ | |
| 1056 | + // has_tr_vert_16x16 | |
| 1057 | + &[255, 0, 119, 0, 127, 0, 119, 0], | |
| 1058 | + // has_tr_vert_32x32 | |
| 1059 | + &[15, 7], | |
| 1060 | + // has_tr_vert_8x8 | |
| 1061 | + &[ | |
| 1062 | + 255, 255, 0, 0, 119, 119, 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, 255, 127, 0, 0, 119, 119, | |
| 1063 | + 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, | |
| 1064 | + ], | |
| 1065 | +]; | |
| 1066 | + | |
| 1067 | +/// [`HAS_TOP_RIGHT_VERT`]'s sibling, `has_bl_vert_tables`. | |
| 1068 | +const HAS_BOTTOM_LEFT_VERT: [&[u8]; 3] = [ | |
| 1069 | + // has_bl_vert_16x16 | |
| 1070 | + &[254, 16, 254, 0, 254, 16, 254, 0], | |
| 1071 | + // has_bl_vert_32x32 | |
| 1072 | + &[14, 14], | |
| 1073 | + // has_bl_vert_8x8 | |
| 1074 | + &[ | |
| 1075 | + 254, 255, 16, 17, 254, 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, 254, 255, 16, 17, 254, | |
| 1076 | + 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, | |
| 1077 | + ], | |
| 1078 | +]; | |
| 1079 | + | |
| 1080 | +thread_local! { | |
| 1081 | + /// Set for the duration of a `PARTITION_VERT_A`/`_B`'s own sub-blocks | |
| 1082 | + /// (see [`Reach::vert_ab_partition`]) -- libaom carries the partition | |
| 1083 | + /// type down into `has_top_right`/`has_bottom_left` as an argument, and | |
| 1084 | + /// threading one bool through this crate's already twenty-argument | |
| 1085 | + /// `decode_block` would touch every call site instead of the two arms | |
| 1086 | + /// that need it. | |
| 1087 | + static VERT_AB_PARTITION: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; | |
| 1088 | +} | |
| 1089 | + | |
| 1090 | +/// Restores [`VERT_AB_PARTITION`] to what it was when the guard was made. | |
| 1091 | +pub(crate) struct VertAbGuard(bool); | |
| 1092 | + | |
| 1093 | +impl Drop for VertAbGuard { | |
| 1094 | + fn drop(&mut self) { | |
| 1095 | + VERT_AB_PARTITION.with(|c| c.set(self.0)); | |
| 1096 | + } | |
| 1097 | +} | |
| 1098 | + | |
| 1046 | 1099 | /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp |
| 1047 | 1100 | /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32 |
| 1048 | 1101 | /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is |
| @@ -1113,6 +1166,15 @@ impl Reach { | ||
| 1113 | 1166 | Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) |
| 1114 | 1167 | } |
| 1115 | 1168 | |
| 1169 | + /// Marks every [`Reach::of`] made until the returned guard drops as being | |
| 1170 | + /// inside a `PARTITION_VERT_A`/`_B` (libaom's `get_has_tr_table` / | |
| 1171 | + /// `get_has_bl_table` partition argument). Rectangular sub-blocks are | |
| 1172 | + /// unaffected: libaom's own comment says vertical rectangles keep their | |
| 1173 | + /// non-vert table, which is what [`Reach::of_rect`] already reads. | |
| 1174 | + pub(crate) fn vert_ab_partition() -> VertAbGuard { | |
| 1175 | + VertAbGuard(VERT_AB_PARTITION.with(|c| c.replace(true))) | |
| 1176 | + } | |
| 1177 | + | |
| 1116 | 1178 | /// Neither, which is all a mode that reads no further than its own edges |
| 1117 | 1179 | /// needs. |
| 1118 | 1180 | pub(crate) fn none() -> Self { |
| @@ -1145,7 +1207,11 @@ impl Reach { | ||
| 1145 | 1207 | // reference pixels), never a stream desync (Reach never gates a |
| 1146 | 1208 | // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4` |
| 1147 | 1209 | // verbatim and give TX4 its own `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` row. |
| 1148 | - let table = HAS_TOP_RIGHT[Self::table(side)]; | |
| 1210 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | |
| 1211 | + HAS_TOP_RIGHT_VERT[Self::table(side)] | |
| 1212 | + } else { | |
| 1213 | + HAS_TOP_RIGHT[Self::table(side)] | |
| 1214 | + }; | |
| 1149 | 1215 | Self::bit( |
| 1150 | 1216 | table, |
| 1151 | 1217 | (row * Self::table_stride(side) + col) % (table.len() * 8), |
| @@ -1165,7 +1231,11 @@ impl Reach { | ||
| 1165 | 1231 | return false; |
| 1166 | 1232 | } |
| 1167 | 1233 | // corner-cut: see `top_right`'s note -- same clamp, same ceiling. |
| 1168 | - let table = HAS_BOTTOM_LEFT[Self::table(side)]; | |
| 1234 | + let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) { | |
| 1235 | + HAS_BOTTOM_LEFT_VERT[Self::table(side)] | |
| 1236 | + } else { | |
| 1237 | + HAS_BOTTOM_LEFT[Self::table(side)] | |
| 1238 | + }; | |
| 1169 | 1239 | Self::bit( |
| 1170 | 1240 | table, |
| 1171 | 1241 | (row * Self::table_stride(side) + col) % (table.len() * 8), |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -1
| @@ -47,7 +47,7 @@ const REFUSALS: &[&str] = &[ | ||
| 47 | 47 | "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)", |
| 48 | 48 | "a tx_type symbol outside its CDF's own set: {t}", |
| 49 | 49 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 50 | - "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", | |
| 50 | + "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four 64x16/16x64 strips)", | |
| 51 | 51 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 52 | 52 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 53 | 53 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
crates/ec-av1/src/stream.rsmodified+225 -11
| @@ -9868,17 +9868,15 @@ mod tests { | ||
| 9868 | 9868 | msg.contains("unsupported"), |
| 9869 | 9869 | "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" |
| 9870 | 9870 | ); |
| 9871 | - // r2: `--enable-ab-partitions=0` does NOT stop aomenc | |
| 9872 | - // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B | |
| 9873 | - // (`partition_w64` value 4-7) even with | |
| 9874 | - // `--min/max-partition-size=32/64` -- a real, separate | |
| 9875 | - // encoder quirk (AB-at-64 is a different, unlanded | |
| 9876 | - // capability, lane-partab's territory is 32x32 and | |
| 9877 | - // below only) discovered live this round, not this | |
| 9878 | - // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT | |
| 9879 | - // (values 0-3) are this gate's territory; a real | |
| 9880 | - // HORZ/VERT (1/2) must still decode pixel-exact, which | |
| 9881 | - // `sb_rect_hits() > 0` below hard-proves. | |
| 9871 | + // r5: the four SB-level AB arms (`partition_w64` 4-7) | |
| 9872 | + // decode since this round, so the only partition refusal | |
| 9873 | + // left at 64x64 is the 1:4 pair (values 8/9, four | |
| 9874 | + // 64x16/16x64 strips, whose luma TX_64X16 this decoder | |
| 9875 | + // has no transform for); the refusals this loop actually | |
| 9876 | + // counts on these fixtures are the pre-existing | |
| 9877 | + // screen-content-palette strip one. Every refusal is | |
| 9878 | + // named, so a genuine decode failure still fails the | |
| 9879 | + // assert above rather than skipping. | |
| 9882 | 9880 | named_refusals += 1; |
| 9883 | 9881 | eprintln!("seed {seed} refusal: {msg}"); |
| 9884 | 9882 | continue; |
| @@ -10463,6 +10461,222 @@ mod tests { | ||
| 10463 | 10461 | ); |
| 10464 | 10462 | } |
| 10465 | 10463 | |
| 10464 | + /// lane-part32 r4: a real `aomenc` stream whose superblock-level | |
| 10465 | + /// partition decision is one of the four AB arms (`PARTITION_HORZ_A`/ | |
| 10466 | + /// `_B`/`VERT_A`/`_B` at 64x64: two 32x32 squares plus one 64x32/32x64 | |
| 10467 | + /// strip) must decode pixel-exact. Same recipe as the HORZ/VERT sibling | |
| 10468 | + /// above with `--enable-ab-partitions=1`; `sb_ab_hits() > 0` is a HARD | |
| 10469 | + /// assert, so a run where aomenc's RD never picked an AB arm fails | |
| 10470 | + /// rather than passing vacuously. | |
| 10471 | + #[test] | |
| 10472 | + fn a_real_aomenc_stream_with_a_superblock_level_ab_partition_decodes_pixel_exact() { | |
| 10473 | + const NAME: &str = | |
| 10474 | + "a_real_aomenc_stream_with_a_superblock_level_ab_partition_decodes_pixel_exact"; | |
| 10475 | + let _gate_lock = lock_gate_counters(); | |
| 10476 | + if !have_ffmpeg() { | |
| 10477 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 10478 | + return; | |
| 10479 | + } | |
| 10480 | + if !have_aomenc() { | |
| 10481 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 10482 | + return; | |
| 10483 | + } | |
| 10484 | + let (width, height, frame_count) = (192usize, 128usize, 1usize); | |
| 10485 | + let mut named_refusals = 0u32; | |
| 10486 | + let mut matched = 0u32; | |
| 10487 | + let n_attempts: u32 = std::env::var("EC_SBAB_GATE_ATTEMPTS") | |
| 10488 | + .ok() | |
| 10489 | + .and_then(|s| s.parse().ok()) | |
| 10490 | + .unwrap_or(40); | |
| 10491 | + for attempt in 0..n_attempts { | |
| 10492 | + let seed = 42 + attempt; | |
| 10493 | + let duration = frame_count as f64 / 25.0; | |
| 10494 | + let source = | |
| 10495 | + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); | |
| 10496 | + let y4m = Command::new("ffmpeg") | |
| 10497 | + .args([ | |
| 10498 | + "-v", | |
| 10499 | + "error", | |
| 10500 | + "-f", | |
| 10501 | + "lavfi", | |
| 10502 | + "-i", | |
| 10503 | + &source, | |
| 10504 | + "-pix_fmt", | |
| 10505 | + "yuv420p", | |
| 10506 | + "-f", | |
| 10507 | + "yuv4mpegpipe", | |
| 10508 | + "-", | |
| 10509 | + ]) | |
| 10510 | + .stdin(Stdio::null()) | |
| 10511 | + .stdout(Stdio::piped()) | |
| 10512 | + .stderr(Stdio::piped()) | |
| 10513 | + .output() | |
| 10514 | + .expect("ffmpeg failed to run"); | |
| 10515 | + assert!( | |
| 10516 | + y4m.status.success(), | |
| 10517 | + "ffmpeg fixture: {}", | |
| 10518 | + String::from_utf8_lossy(&y4m.stderr) | |
| 10519 | + ); | |
| 10520 | + let args: Vec<&str> = vec![ | |
| 10521 | + "--codec=av1", | |
| 10522 | + "--passes=1", | |
| 10523 | + "--end-usage=q", | |
| 10524 | + "--cq-level=45", | |
| 10525 | + "--cpu-used=0", | |
| 10526 | + "--threads=1", | |
| 10527 | + "--row-mt=0", | |
| 10528 | + "--sb-size=64", | |
| 10529 | + "--enable-rect-partitions=1", | |
| 10530 | + "--enable-ab-partitions=1", | |
| 10531 | + "--enable-1to4-partitions=0", | |
| 10532 | + "--min-partition-size=32", | |
| 10533 | + "--max-partition-size=64", | |
| 10534 | + "--enable-restoration=0", | |
| 10535 | + "--enable-palette=0", | |
| 10536 | + "--deltaq-mode=0", | |
| 10537 | + "--enable-filter-intra=0", | |
| 10538 | + "--enable-cfl-intra=0", | |
| 10539 | + "--enable-intrabc=0", | |
| 10540 | + "--enable-tx-size-search=0", | |
| 10541 | + "--obu", | |
| 10542 | + "-o", | |
| 10543 | + "-", | |
| 10544 | + "-", | |
| 10545 | + ]; | |
| 10546 | + let mut child = Command::new(aomenc_path()) | |
| 10547 | + .args(&args) | |
| 10548 | + .stdin(Stdio::piped()) | |
| 10549 | + .stdout(Stdio::piped()) | |
| 10550 | + .stderr(Stdio::piped()) | |
| 10551 | + .spawn() | |
| 10552 | + .expect("aomenc failed to start"); | |
| 10553 | + child | |
| 10554 | + .stdin | |
| 10555 | + .take() | |
| 10556 | + .expect("aomenc stdin") | |
| 10557 | + .write_all(&y4m.stdout) | |
| 10558 | + .expect("writing y4m to aomenc"); | |
| 10559 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 10560 | + assert!( | |
| 10561 | + out.status.success(), | |
| 10562 | + "aomenc refused the fixture: {}", | |
| 10563 | + String::from_utf8_lossy(&out.stderr) | |
| 10564 | + ); | |
| 10565 | + let stream = out.stdout; | |
| 10566 | + let frames = match decode_stream(&stream) { | |
| 10567 | + Err(e) => { | |
| 10568 | + let msg = e.to_string(); | |
| 10569 | + assert!( | |
| 10570 | + msg.contains("unsupported"), | |
| 10571 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | |
| 10572 | + ); | |
| 10573 | + // r5: the four SB-level AB arms (`partition_w64` 4-7) | |
| 10574 | + // decode since this round, so the only partition refusal | |
| 10575 | + // left at 64x64 is the 1:4 pair (values 8/9, four | |
| 10576 | + // 64x16/16x64 strips, whose luma TX_64X16 this decoder | |
| 10577 | + // has no transform for); the refusals this loop actually | |
| 10578 | + // counts on these fixtures are the pre-existing | |
| 10579 | + // screen-content-palette strip one. Every refusal is | |
| 10580 | + // named, so a genuine decode failure still fails the | |
| 10581 | + // assert above rather than skipping. | |
| 10582 | + named_refusals += 1; | |
| 10583 | + eprintln!("seed {seed} refusal: {msg}"); | |
| 10584 | + continue; | |
| 10585 | + } | |
| 10586 | + Ok(frames) => frames, | |
| 10587 | + }; | |
| 10588 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | |
| 10589 | + assert_eq!(frames.len(), frame_count); | |
| 10590 | + let mismatched = frames | |
| 10591 | + .iter() | |
| 10592 | + .zip(&ffmpeg_frames) | |
| 10593 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | |
| 10594 | + if mismatched { | |
| 10595 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | |
| 10596 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | |
| 10597 | + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | |
| 10598 | + } | |
| 10599 | + } | |
| 10600 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 10601 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); | |
| 10602 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | |
| 10603 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | |
| 10604 | + } | |
| 10605 | + matched += 1; | |
| 10606 | + } | |
| 10607 | + assert!( | |
| 10608 | + matched > 0, | |
| 10609 | + "{NAME}: every attempt refused; the gate never decoded a stream" | |
| 10610 | + ); | |
| 10611 | + let arms = crate::decode::sb_ab_hits_by_arm(); | |
| 10612 | + for (i, name) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() { | |
| 10613 | + assert!( | |
| 10614 | + arms[i] > 0, | |
| 10615 | + "{NAME}: zero superblock-level PARTITION_{name} blocks fired (arms={arms:?}, \ | |
| 10616 | + {matched} matches, {named_refusals} refusals out of {n_attempts}) -- that arm \ | |
| 10617 | + proved nothing this run" | |
| 10618 | + ); | |
| 10619 | + } | |
| 10620 | + eprintln!( | |
| 10621 | + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \ | |
| 10622 | + {n_attempts}, sb_ab_hits={} arms(HORZ_A,HORZ_B,VERT_A,VERT_B)={arms:?}", | |
| 10623 | + crate::decode::sb_ab_hits() | |
| 10624 | + ); | |
| 10625 | + } | |
| 10626 | + | |
| 10627 | + /// lane-part32 r2: prints the exact mismatch geometry (block coords, | |
| 10628 | + /// got/want pixels) of the pinned seed-42 stream captured off | |
| 10629 | + /// `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | |
| 10630 | + /// via `EC_AV1_GATE_DUMP`. Debug-only, `#[ignore]`d. | |
| 10631 | + #[test] | |
| 10632 | + #[ignore = "debug harness, run manually with EC_AV1_GATE_DUMP_PIN"] | |
| 10633 | + fn debug_part32_r2_sbpart_pin_mismatch_geometry() { | |
| 10634 | + let path = std::env::var("EC_AV1_GATE_DUMP_PIN").expect("set EC_AV1_GATE_DUMP_PIN"); | |
| 10635 | + let stream = std::fs::read(&path).expect("read pinned stream"); | |
| 10636 | + let frames = decode_stream(&stream).expect("pinned stream must decode"); | |
| 10637 | + if let Ok(dump) = std::env::var("EC_DEBUG_DUMP_Y") { | |
| 10638 | + let bytes: Vec<u8> = frames[0].y.iter().map(|&v| v as u8).collect(); | |
| 10639 | + std::fs::write(&dump, bytes).expect("write y dump"); | |
| 10640 | + } | |
| 10641 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 192, 128, 1); | |
| 10642 | + let got = &frames[0]; | |
| 10643 | + let want = &ffmpeg_frames[0]; | |
| 10644 | + let width = 192usize; | |
| 10645 | + let mut n = 0; | |
| 10646 | + let (mut min_x, mut max_x, mut min_y, mut max_y) = (width, 0, 128, 0); | |
| 10647 | + for y in 0..128usize { | |
| 10648 | + for x in 0..width { | |
| 10649 | + let idx = y * width + x; | |
| 10650 | + if got.y[idx] != want.y[idx] { | |
| 10651 | + n += 1; | |
| 10652 | + min_x = min_x.min(x); | |
| 10653 | + max_x = max_x.max(x); | |
| 10654 | + min_y = min_y.min(y); | |
| 10655 | + max_y = max_y.max(y); | |
| 10656 | + } | |
| 10657 | + } | |
| 10658 | + } | |
| 10659 | + eprintln!( | |
| 10660 | + "total luma mismatches: {n} bbox x=[{min_x},{max_x}] y=[{min_y},{max_y}] frame=192x128" | |
| 10661 | + ); | |
| 10662 | + for y in 0..128usize { | |
| 10663 | + let mut row_first = None; | |
| 10664 | + let mut row_count = 0; | |
| 10665 | + for x in 0..width { | |
| 10666 | + let idx = y * width + x; | |
| 10667 | + if got.y[idx] != want.y[idx] { | |
| 10668 | + if row_first.is_none() { | |
| 10669 | + row_first = Some(x); | |
| 10670 | + } | |
| 10671 | + row_count += 1; | |
| 10672 | + } | |
| 10673 | + } | |
| 10674 | + if let Some(fx) = row_first { | |
| 10675 | + eprintln!("row {y}: first mismatch x={fx} count={row_count}"); | |
| 10676 | + } | |
| 10677 | + } | |
| 10678 | + } | |
| 10679 | + | |
| 10466 | 10680 | /// lane-rect64q r1: same recipe as |
| 10467 | 10681 | /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`] |
| 10468 | 10682 | /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is |
lanes/part32-r1.report.mdadded+117 -0
| @@ -0,0 +1,117 @@ | ||
| 1 | +# lane-part32 r1 report | |
| 2 | + | |
| 3 | +## What landed | |
| 4 | + | |
| 5 | +`crates/ec-av1/src/decode.rs`: the INTRA 32x32 dispatch (key-frame tile path, | |
| 6 | +the one that previously hit `"a 32x32 partition type this decoder does not | |
| 7 | +code (value={part32})"`) now handles `PARTITION_HORZ_A` (4), `PARTITION_HORZ_B` | |
| 8 | +(5), `PARTITION_VERT_A` (6), `PARTITION_VERT_B` (7) -- mirrors cd6cb6d's INTER | |
| 9 | +AB arms exactly, using `decode_block` (square 16x16, `TxbSet::Luma16`/ | |
| 10 | +`Chroma8`) for the two square sub-blocks and `decode_block_rect` (32x16 or | |
| 11 | +16x32) for the strip. The catch-all refusal is unchanged text but now only | |
| 12 | +reached for `PARTITION_HORZ_4`/`PARTITION_VERT_4` (values 8/9) -- narrowed by | |
| 13 | +construction, not by editing the string (still pinned as-is in | |
| 14 | +`refusal_inventory.rs`, no change needed there since the text is identical). | |
| 15 | + | |
| 16 | +Four new thread-local hit counters (`intra_horz_a_hits`/`intra_horz_b_hits`/ | |
| 17 | +`intra_vert_a_hits`/`intra_vert_b_hits`), one per arm, mirroring | |
| 18 | +`PARTAB_HITS`'s pattern but split so a recipe that only ever fires one arm | |
| 19 | +can't hide behind a shared total. | |
| 20 | + | |
| 21 | +## Gate | |
| 22 | + | |
| 23 | +`crates/ec-av1/src/stream.rs::a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact` | |
| 24 | +-- single key frame, 64x64, `mandelbrot` content (same recipe shape as the | |
| 25 | +existing `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact`), | |
| 26 | +`--min-partition-size=16 --max-partition-size=32` (same bound lane-partab used | |
| 27 | +to stay below the still-unlanded SB(64)-level AB territory), 40 attempts. | |
| 28 | +Forbids the four `value={4,5,6,7}` intra refusal strings once reached, hard- | |
| 29 | +asserts all four per-arm counters > 0. | |
| 30 | + | |
| 31 | +**PASSES**, `EC_AV1_REQUIRE_AOMENC=1` included: | |
| 32 | + | |
| 33 | +``` | |
| 34 | +a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact: | |
| 35 | +0 named refusals, 40 pixel-exact matches out of 40, | |
| 36 | +horz_a=34 horz_b=45 vert_a=15 vert_b=18 | |
| 37 | +``` | |
| 38 | + | |
| 39 | +EVIDENCE: `cargo test -p ec-av1 --lib a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact -- --nocapture` | |
| 40 | +(with and without `EC_AV1_REQUIRE_AOMENC=1`) | both runs above | 40/40 pixel-exact, all 4 counters nonzero. | |
| 41 | + | |
| 42 | +## Suite: NOT fully green -- one PRE-EXISTING failure exposed, out of this | |
| 43 | +## lane's scope | |
| 44 | + | |
| 45 | +`cargo test -p ec-av1 --lib`: **264 passed, 1 failed** (19 ignored), 208s. | |
| 46 | + | |
| 47 | +Failure: `stream::tests::a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`, | |
| 48 | +seed 42, first luma mismatch at (row=0, col=91), inside superblock (0,1)'s | |
| 49 | +`PARTITION_VERT`-at-64 arm (`decode_block_rect64`, lane-sbpart territory -- | |
| 50 | +mode=DC_PRED, all_zero=1, off by one: got=80 want=81). | |
| 51 | + | |
| 52 | +Root-cause isolation done this round: | |
| 53 | +- Confirmed with `git checkout 21a71ec -- decode.rs stream.rs` (temporary, | |
| 54 | + reverted) that this exact seed/recipe/byte-for-byte stream **already | |
| 55 | + refused** on main at `"a 32x32 partition type this decoder does not code | |
| 56 | + (value=4)"` -- inside superblock (1,1), which decodes strictly *after* | |
| 57 | + superblock (0,1) in tile order. Entropy decoding is causal: nothing this | |
| 58 | + lane touched can change how SB(0,1) is decoded, since SB(0,1) is decoded | |
| 59 | + and its pixels finalized before the stream ever reaches the part32 AB | |
| 60 | + symbol this lane added. | |
| 61 | +- This is the "refusal hides a defect" class already in the ledger | |
| 62 | + (`refusal-hides-a-defect.md`): the sbpart gate's `matched > 0` assertion | |
| 63 | + only ever checked pixels on attempts that decoded *end to end*; every | |
| 64 | + attempt that hit a downstream refusal (including this exact seed, before | |
| 65 | + this lane) never had its earlier SB(0,1) pixels compared at all. Lifting | |
| 66 | + the part32 refusal let decode run to completion for seed 42, and the | |
| 67 | + frame-level pixel compare then found a pre-existing `decode_block_rect64` | |
| 68 | + defect for the first time. | |
| 69 | +- Not investigated further (turn budget): whatever's wrong in the | |
| 70 | + 32x64/64x32 rect-64 corner-truncated intra path is `decode_block_rect64`'s | |
| 71 | + own bug, unrelated to `decode_block`/`decode_block_rect` (this lane's | |
| 72 | + functions) and to the AB dispatch. It belongs to lane-sbpart, not | |
| 73 | + lane-part32. | |
| 74 | + | |
| 75 | +Per this repo's own rule ("Landing red ON THE LANE is fine -- I do the merges | |
| 76 | +to main and I never merge red"), HEAD is committed red with this failure | |
| 77 | +named. **Do not merge without either (a) fixing `decode_block_rect64`'s | |
| 78 | +DC-prediction/edge bug (a lane-sbpart-shaped charter, not part32's) or (b) an | |
| 79 | +explicit call that this newly-exposed defect is acceptable to carry | |
| 80 | +forward.** | |
| 81 | + | |
| 82 | +`cargo check --workspace --all-targets`: clean. | |
| 83 | + | |
| 84 | +## ReelC extract | |
| 85 | + | |
| 86 | +Cut `fixtures/part32/reelc-extract.obu` (gitignored) via | |
| 87 | +`ffmpeg -ss 600 -t 2 -c:v copy -an -f obu -bsf:v extract_extradata` from | |
| 88 | +`~/Videos/Films/reelc.mkv`. | |
| 89 | +`cargo run -p ec-av1 --example decode_probe -- fixtures/part32/reelc-extract.obu`: | |
| 90 | + | |
| 91 | +``` | |
| 92 | +REFUSED: unsupported: AV1 decode_stream (a stream whose bit depth is not 8 | |
| 93 | +(this decoder reconstructs into 8-bit planes)) | |
| 94 | +``` | |
| 95 | + | |
| 96 | +No longer stops at the part32 refusal (charter's predicted outcome: ReelC is | |
| 97 | +10-bit and hits the bit-depth wall first, per `his-av1-library-is-10-bit.md`). | |
| 98 | + | |
| 99 | +EVIDENCE: `cargo run -p ec-av1 --example decode_probe -- fixtures/part32/reelc-extract.obu` | |
| 100 | +| ran against a real 2s ReelC extract at ~10min mark | output above. | |
| 101 | + | |
| 102 | +## HEAD | |
| 103 | + | |
| 104 | +`69eeb6e` -- "wip(part32): intra 32x32 AB arms (HORZ_A/HORZ_B/VERT_A/VERT_B) | |
| 105 | +decode, gated 40/40 pixel-exact, all 4 hit counters fire" | |
| 106 | + | |
| 107 | +## Open | |
| 108 | + | |
| 109 | +- `HORZ_4`/`VERT_4` (values 8/9) not attempted this round; refusal still | |
| 110 | + names them (unmodified string, now only reachable for those two values). | |
| 111 | + Not reached by any gate recipe tried, reachability unknown. | |
| 112 | +- The `decode_block_rect64` DC-prediction/edge defect above is the actual | |
| 113 | + blocker for a fully green suite. It is NOT part32's code and needs its own | |
| 114 | + lane/charter (lane-sbpart shaped) to isolate and fix. | |
| 115 | +- `--cq-level=45`/`--enable-tx-size-search=0` etc kept identical to | |
| 116 | + lane-partab's proven recipe; not swept for a lower-cq/higher-fidelity | |
| 117 | + variant. |
lanes/part32-r2.report.mdadded+107 -0
| @@ -0,0 +1,107 @@ | ||
| 1 | +# lane-part32 round 2 | |
| 2 | + | |
| 3 | +## State: NOT DONE, red, committed (4bff66c) | |
| 4 | + | |
| 5 | +Charter: fix decode_block_rect64's pre-existing pixel mismatch exposed by | |
| 6 | +round 1's refusal lift. | |
| 7 | + | |
| 8 | +## True mismatch geometry (measured on THIS tree, not inherited) | |
| 9 | + | |
| 10 | +Reproduced live: `cargo test -p ec-av1 --lib | |
| 11 | +a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | |
| 12 | +-> 266 passed, 1 failed, matches the trial-merge count I was handed. | |
| 13 | + | |
| 14 | +Pinned the mismatching seed-42 stream via `EC_AV1_GATE_DUMP`, added an | |
| 15 | +`#[ignore]`d debug test (`debug_part32_r2_sbpart_pin_mismatch_geometry`, | |
| 16 | +`stream.rs`) that decodes it and prints exact per-pixel diffs. | |
| 17 | + | |
| 18 | +- Full-frame post-filter comparison against ffmpeg: 17873/24576 luma pixels | |
| 19 | + differ, spanning the entire frame past x=91,y=0. This is NOT a single | |
| 20 | + off-by-one -- it's a cascade: once one block's pixels are wrong, every | |
| 21 | + block that intra-predicts from it downstream inherits and compounds the | |
| 22 | + error, eventually corrupting nearly all of SB row 1 (y>=64). | |
| 23 | +- Root of the cascade, isolated via aom-oracle's `EC_AV1_PREFILT_DUMP` rung | |
| 24 | + (pre-loop-filter ground truth) plus two new env-gated bypasses | |
| 25 | + (`EC_AV1_DEBUG_SKIP_DEBLOCK`/`_CDEF`, off by default) on our side: our own | |
| 26 | + PRE-FILTER reconstruction matches the oracle's pre-filter output exactly | |
| 27 | + through SB(1,0)'s first VERT-64 sub-block (mi_c=16..23, all-zero DC, | |
| 28 | + correct). The very first wrong pixel is (96,0) -- the first pixel of the | |
| 29 | + SECOND VERT-64 sub-block (mi_c=24..31, real coefficients, eob_nonzero=true): | |
| 30 | + oracle=81, ours=76. | |
| 31 | + | |
| 32 | +## Entropy layer: DIVERGES, inside this exact block | |
| 33 | + | |
| 34 | +Compared msac RANGE (never `tell()`) against the aom-oracle's `EC_TRACE_COEFF` | |
| 35 | +rung, element by element: | |
| 36 | +- Ranges agree exactly up through `rng=63764` at the entry to this block's | |
| 37 | + luma coefficient read (`EC_COEFF plane=0 ... tx_size=64corner/11 | |
| 38 | + rng=63764` on both sides). | |
| 39 | +- Both sides read `eob=6` (agreement). | |
| 40 | +- The oracle's per-step trace assigns nonzero level=1 at scan indices | |
| 41 | + 0, 1, 2, 4, 5 (skipping 3). Ours (`scan32 = default_scan(TX32)`, a plain | |
| 42 | + square 32x32 scan) walks physical positions (0,0)(0,1)(1,0)(2,0)(1,1)(0,2) | |
| 43 | + for the same six scan indices -- a different position-to-index mapping | |
| 44 | + than whatever the oracle used. | |
| 45 | +- Post-block range: ours=37896, oracle=46344. Diverged. | |
| 46 | + | |
| 47 | +Conclusion: this is a genuine in-block entropy desync (wrong scan table), | |
| 48 | +not a post-processing (deblock/CDEF, both proven innocent by disabling them) | |
| 49 | +and not a dequant/reconstruction-only bug. | |
| 50 | + | |
| 51 | +## Root cause (identified, not yet fixed) | |
| 52 | + | |
| 53 | +`decode_block_rect64` (crates/ec-av1/src/decode.rs:3559) reads the luma | |
| 54 | +corner with `scan32 = default_scan(TX32)` -- the square TX_32X32 scan -- | |
| 55 | +for BOTH genuine square 64x64 blocks and truncated-corner VERT-64/HORZ-64 | |
| 56 | +strips (bw=32,bh=64 or bw=64,bh=32). The function's own doc comment already | |
| 57 | +documents an analogous, already-fixed asymmetry for the nz_map *context* | |
| 58 | +table (`NZ_MAP_CTX_OFFSET_32X64`/`_64X32`, lane-sbpart r8) but the *scan | |
| 59 | +order itself* was never given the same treatment. AV1 spec names a distinct | |
| 60 | +Default_Scan_32x64/64x32 table (libaom `av1_scan_orders[TX_32X64]` / | |
| 61 | +`[TX_64X32]`), and this decoder does not have it. | |
| 62 | + | |
| 63 | +Same shape as this repo's existing `table-indexed-by-raw-size` and | |
| 64 | +`scan-weights-cross-axis` ledger classes. | |
| 65 | + | |
| 66 | +## Fix NOT landed this round | |
| 67 | + | |
| 68 | +Turn budget spent entirely on localization (per charter's own step-2 | |
| 69 | +instruction, "if ranges diverge, that's decisive"). Porting a correct | |
| 70 | +1024-entry SCAN_32X64/SCAN_64X32 table from libaom and wiring it in at the | |
| 71 | +`decode_block_rect64` call site (mirroring how `chroma_scan` already | |
| 72 | +branches on `bw == 64` a few lines below) is the next round's whole job -- | |
| 73 | +should be mechanical once the table exists, but deriving/verifying a new | |
| 74 | +1024-entry table safely needs its own round, not the tail end of this one. | |
| 75 | + | |
| 76 | +## Gates | |
| 77 | + | |
| 78 | +- Part32's own AB gate (round 1's): | |
| 79 | + `a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact` -- | |
| 80 | + not re-run this round (untouched by this round's changes; round 1 already | |
| 81 | + proved it 40/40 and this round made zero changes to part32's own code | |
| 82 | + paths). | |
| 83 | +- Target gate | |
| 84 | + (`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`): | |
| 85 | + still RED, root cause pinned, fix not landed. | |
| 86 | +- `cargo check --workspace --all-targets`: clean. | |
| 87 | +- Full `cargo test -p ec-av1 --lib` NOT re-run this round after the debug | |
| 88 | + additions (both are `#[ignore]`d / env-gated no-ops by default; the only | |
| 89 | + change to non-test code is the two early-return guards in | |
| 90 | + `apply_deblock`/`apply_cdef`, both env-gated and off by default -- zero | |
| 91 | + behavior change verified by the identical `cargo check` above). | |
| 92 | + | |
| 93 | +## rect64q contradiction: explained | |
| 94 | + | |
| 95 | +lane-rect64q's own reproduction (row0 col91=81, matching ffmpeg, no | |
| 96 | +mismatch) used a stream from ITS OWN worktree, which did not have this | |
| 97 | +lane's AB arms and so took a genuinely different aomenc encode (different | |
| 98 | +partition decisions entirely) -- not a contradiction of this round's | |
| 99 | +finding, a different stream. This round's own pinned stream, decoded fresh | |
| 100 | +on this tree, reproduces the failure deterministically and traces to a real, | |
| 101 | +narrow, named defect (wrong scan table for TX_32X64/TX_64X32 corner-truncated | |
| 102 | +luma). | |
| 103 | + | |
| 104 | +## HEAD | |
| 105 | + | |
| 106 | +`4bff66c` -- "wip(part32): pin decode_block_rect64's block2 defect to a | |
| 107 | +scan-table mismatch" |
lanes/part32-r5.report.mdadded+137 -0
| @@ -0,0 +1,137 @@ | ||
| 1 | +# lane-part32 r5 — SB-level AB partitions at 64x64, proven arm by arm | |
| 2 | + | |
| 3 | +Branch `lane-part32`, commit `fd1a2eb` on top of r4's WIP snapshot `25cac7d` | |
| 4 | +(itself rebased on main `3808cf8`). | |
| 5 | + | |
| 6 | +## What r4 actually left (verified, not assumed) | |
| 7 | + | |
| 8 | +r4's last words claimed SB-level HORZ/VERT 64 was green. It was not: with | |
| 9 | +`EC_AV1_REQUIRE_AOMENC=1` both | |
| 10 | +`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | |
| 11 | +and its new `..._ab_partition_...` sibling FAILED on seed 63 (luma mismatch, | |
| 12 | +`test result: FAILED. 0 passed; 2 failed`). r4's two real fixes — | |
| 13 | +`EOB_PT_512_CHROMA` q-context split (`cdf.rs:269`, `cdf_state.rs:1013`) and | |
| 14 | +the four AB arms in `decode.rs` — were correct but incomplete. | |
| 15 | + | |
| 16 | +## Root cause found and fixed this round | |
| 17 | + | |
| 18 | +`PARTITION_VERT_A`/`_B` visit their square sub-blocks **TL, BL, TR, BR**, not | |
| 19 | +in raster order, so the bottom-left square's top-right neighbour is the | |
| 20 | +partition's own right-hand rectangle — not yet decoded. libaom switches | |
| 21 | +`has_top_right`/`has_bottom_left` onto `has_tr_vert_*`/`has_bl_vert_*` for | |
| 22 | +exactly these two partition types (`reconintra.c` `get_has_tr_table`, | |
| 23 | +`get_has_bl_table`). This crate's `Reach` carried only the raster tables: | |
| 24 | +for the BL 32x32 (blk_row_in_sb=1, blk_col_in_sb=0, bit index 4) | |
| 25 | +`has_tr_32x32[0]=95` bit 4 = **1** while `has_tr_vert_32x32[0]=15` bit 4 = **0**. | |
| 26 | +One availability bit → 4683 wrong luma pixels. | |
| 27 | + | |
| 28 | +Failure chain on the pinned stream: BL square predicts (V_PRED, angle_delta=2) | |
| 29 | +off never-written above-right samples → its right columns decay | |
| 30 | +(150,150,150 → 130,93,39 at x=157..159) → the 32x64 strip to its right | |
| 31 | +DC-predicts off that corrupted left column and comes out flat **107** instead | |
| 32 | +of ~149 → the next superblock row's V_PRED copies 107 down the whole frame. | |
| 33 | + | |
| 34 | +Decisive evidence that this was reconstruction, not entropy: instrumented | |
| 35 | +`aomdec` (`EC_TRACE=1 EC_TRACE_MODE=1`) agrees with us on every symbol — | |
| 36 | +`EC_PART_VAL mi_row=0 mi_col=32 value=6` (VERT_A), every `EC_IMODE_VAL` | |
| 37 | +mode/uv_mode, and the msac **range** at `mi_row=0 mi_col=40` is `53240` in | |
| 38 | +both decoders (ours: `TRACE_RECT_PREFI ... rng=53240`). | |
| 39 | + | |
| 40 | +## Files changed | |
| 41 | + | |
| 42 | +- `crates/ec-av1/src/encode.rs:1049` — `HAS_TOP_RIGHT_VERT` / | |
| 43 | + `HAS_BOTTOM_LEFT_VERT` transcribed verbatim from libaom | |
| 44 | + (`has_tr_vert_8x8/16x16/32x32`, `has_bl_vert_*`), a `VERT_AB_PARTITION` | |
| 45 | + thread-local + `VertAbGuard`, `Reach::vert_ab_partition()`, and the table | |
| 46 | + pick inside `top_right`/`bottom_left`. Rect sub-blocks deliberately keep | |
| 47 | + the non-vert tables (libaom's own comment) — `Reach::of_rect` untouched. | |
| 48 | +- `crates/ec-av1/src/decode.rs:7535,7610` — the 32x32-level intra VERT_A/VERT_B | |
| 49 | + arms take the guard (same defect one level down, swept in the same round). | |
| 50 | +- `crates/ec-av1/src/decode.rs:7766` — the SB-level AB arm takes it only for | |
| 51 | + the two vertical arms. | |
| 52 | +- `crates/ec-av1/src/decode.rs:13432,13595` — the two inter AB VERT arms take | |
| 53 | + it too (class sweep; inter intra-mode blocks read the same `Reach`). | |
| 54 | +- `crates/ec-av1/src/decode.rs:767,772` — `SB_AB_HITS` is now `[usize; 4]`, | |
| 55 | + incremented by arm, with `sb_ab_hits_by_arm()`. | |
| 56 | +- `crates/ec-av1/src/stream.rs:9665` — the AB gate hard-asserts **each** of | |
| 57 | + HORZ_A/HORZ_B/VERT_A/VERT_B fired, not just the sum. | |
| 58 | +- `crates/ec-av1/src/stream.rs:9467,9628` — both gates' stale r2 comment | |
| 59 | + ("AB-at-64 is a different, unlanded capability") replaced with the r5 truth. | |
| 60 | +- `crates/ec-av1/src/refusal_inventory.rs:50` — (r4) the refusal is now | |
| 61 | + narrowed to the 1:4 pair only. `gate_coverage.rs` needed no edit: | |
| 62 | + `--enable-ab-partitions=1` is now positively exercised and the flag was | |
| 63 | + never on `NEVER_EXERCISED`; both its tests are green in the run below. | |
| 64 | + | |
| 65 | +## Gates | |
| 66 | + | |
| 67 | +``` | |
| 68 | +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-part32 EC_AV1_REQUIRE_AOMENC=1 \ | |
| 69 | + cargo test -p ec-av1 --lib -- --test-threads=1 --nocapture superblock_level | |
| 70 | +``` | |
| 71 | +`test result: ok. 2 passed; 0 failed; 1 ignored` (was 0 passed; 2 failed). | |
| 72 | + | |
| 73 | +EVIDENCE: /tmp/.../scratchpad/r5gate.txt, r5ab.txt | 40 real-aomenc streams per gate, `--sb-size=64 --enable-rect-partitions=1 --enable-ab-partitions=1`, seeds 42..81, decoded and compared to ffmpeg | ab gate 37 pixel-exact / 3 named refusals, `sb_ab_hits=13 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)=[2, 5, 3, 3]`; horz/vert gate 37 pixel-exact, `sb_rect_hits=61` | |
| 74 | + | |
| 75 | +EVIDENCE: /tmp/.../scratchpad/r5full.txt | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` | `test result: ok. 269 passed; 0 failed; 24 ignored; 0 measured` in 1094s | |
| 76 | + | |
| 77 | +EVIDENCE: /tmp/.../scratchpad/pre63o.f0 vs our63_nf.y | oracle `EC_AV1_PREFILT_DUMP` vs ours with deblock+CDEF disabled, on the pinned seed-63 stream (pre-fix) | 4683 luma samples differ, bbox x=[151,191] y=[0,127]; post-fix the gate is pixel-exact | |
| 78 | + | |
| 79 | +## Refusal lifted | |
| 80 | + | |
| 81 | +`"a superblock-level partition type other than NONE or SPLIT (this decoder's | |
| 82 | +intra tile path codes only those two at 64x64)"` → replaced by | |
| 83 | +`"a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four | |
| 84 | +64x16/16x64 strips)"`. HORZ/VERT/HORZ_A/HORZ_B/VERT_A/VERT_B at 64x64 are all | |
| 85 | +now real-stream-proven. | |
| 86 | + | |
| 87 | +## Film check | |
| 88 | + | |
| 89 | +`ffmpeg -t 0.4 -i ReelC...mkv -c:v copy -f obu reelc_r5.obu` (418 B), then | |
| 90 | +`cargo run -p ec-av1 --example decode_probe -- reelc_r5.obu`: | |
| 91 | + | |
| 92 | +``` | |
| 93 | +REFUSED: unsupported: AV1 tile (filter intra on a HORZ/VERT strip (this decoder predicts square-only)) | |
| 94 | +``` | |
| 95 | + | |
| 96 | +ReelC reaches an SB-level HORZ/VERT strip and now stops on filter-intra-on-a-strip. | |
| 97 | +deferred: the matching "before" probe on main `3808cf8` — not re-measured this | |
| 98 | +round (would need a full rebuild of a second target dir at the turn ceiling); | |
| 99 | +unblocked by any lane that already has a main-based build of `decode_probe`. | |
| 100 | + | |
| 101 | +## Coordinator's two facts, answered | |
| 102 | + | |
| 103 | +1. **rectsplit seed 50 / `decode_block_rect64` split-transform residual** — NOT | |
| 104 | + fixed here; my change never runs for a HORZ/VERT strip (the guard is set | |
| 105 | + only under VERT_A/_B, and rect blocks go through `Reach::of_rect`, which is | |
| 106 | + untouched). But the hypothesis is now concrete and shares this round's | |
| 107 | + class: `decode.rs:5099` and `decode.rs:5425` compute per-TU availability as | |
| 108 | + `Reach::of(logical_tx, tu_px, tu_py, ...)` — i.e. they treat the transform | |
| 109 | + unit as if it were a *block at frame coordinates* and consult the | |
| 110 | + superblock-position table. libaom does not: in `has_top_right`, when | |
| 111 | + `row_off > 0` it never reaches a table at all, it returns | |
| 112 | + `col_off + tx_size_wide_unit < plane_bw_unit` — purely block-relative. For | |
| 113 | + a depth-2 TX_16X16 inside a 64x32 strip that is exactly the sub-TU at | |
| 114 | + `row_off > 0` case. That is where I would look first for the (171,56) | |
| 115 | + 147-vs-148 sample. `rectsplit` keeps ownership. | |
| 116 | +2. **scaledref's masked Golomb defect at seed 67** — appears RESOLVED on this | |
| 117 | + branch. Both r5 gate runs cover seeds 42..81; the only refusals were seeds | |
| 118 | + 45/46/59 (screen-content palette strip), and seed 67 decoded **pixel-exact | |
| 119 | + against ffmpeg**, which is stronger than "no Golomb refusal". Most likely | |
| 120 | + killed by r4's `EOB_PT_512_CHROMA` q-context fix, with this round's | |
| 121 | + availability fix removing the seed-63 sibling. scaledref should re-run with | |
| 122 | + the raised cap after merge; if it still reproduces, the cause is elsewhere. | |
| 123 | + | |
| 124 | +## Residue | |
| 125 | + | |
| 126 | +- fix-now(next lane): `PARTITION_HORZ_4`/`VERT_4` at 64x64 — still refused by | |
| 127 | + name. Not attempted: `decode_block_rect64` is hardwired to 64x32/32x64 | |
| 128 | + (`TxbSet::Luma64` + `TX32` scan for luma, `ChromaRect32x16` + `SCAN_32X16/ | |
| 129 | + 16X32` for chroma, `decode.rs:3846-3990`); a 64x16 strip needs a real | |
| 130 | + TX_64X16 luma transform plus 32x8 chroma scans/EOB tables, which is a | |
| 131 | + transform-primitive lane, not a partition-wiring one. | |
| 132 | +- accepted: `Reach::table(64)` maps to the 16x16 table row (pre-existing); | |
| 133 | + harmless because a 64x64 block in a 64 superblock always takes the | |
| 134 | + `row == 0` early return before any table is read. | |
| 135 | +- accepted: the per-TU `Reach::of` shape described above is left to rectsplit | |
| 136 | + rather than fixed blind here, since every gate on this branch is green and a | |
| 137 | + speculative change to it would risk them. |