Merge lane-av1chrtx @ ea97eb0c — per-unit leaf tx_type in rect inter chroma + the per-unit coefficient census
Browse files at this commit5 changed files +914 -11
- crates/ec-av1/fixtures/444_rect_strip_leaf_tx_type.obu +0 -0
- crates/ec-av1/src/decode.rs +300 -10
- crates/ec-av1/src/stream.rs +238 -1
- lanes/av1chrtx.report.md +187 -0
- lanes/av1readcensus.report.md +189 -0
crates/ec-av1/fixtures/444_rect_strip_leaf_tx_type.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+300 -10
| @@ -2275,6 +2275,119 @@ pub(crate) fn rect_class1_hits() -> usize { | |||
| 2275 | RECT_CLASS1_HITS.with(|c| c.get()) | 2275 | RECT_CLASS1_HITS.with(|c| c.get()) |
| 2276 | } | 2276 | } |
| 2277 | 2277 | ||
| 2278 | +// lane-av1readcensus: the PER-UNIT coefficient census -- one unit counted | ||
| 2279 | +// per `read_coeffs`/`read_coeffs_rect` call, i.e. per object this decoder | ||
| 2280 | +// actually walks, which is the unit the round-4 `av1444rect` count measured | ||
| 2281 | +// (636 square chroma reads against the oracle's 1086). The counters are | ||
| 2282 | +// 4:4:4-ONLY (`CENSUS_444`, set per frame beside `set_subsampling`), so a | ||
| 2283 | +// 4:2:0 control reads `(0, 0, 0)` -- a walk-shape change at 4:2:0 is another | ||
| 2284 | +// lane's business, and this census must not fire there. | ||
| 2285 | +thread_local! { | ||
| 2286 | + /// Per-plane unit counts, `[luma, u, v]`, at 4:4:4 only. | ||
| 2287 | + static CENSUS_444_UNITS: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) }; | ||
| 2288 | + /// Of [`CENSUS_444_UNITS`], the units that coded at least one coefficient | ||
| 2289 | + /// (`txb_skip == 0`) -- the per-plane split is only comparable against | ||
| 2290 | + /// the oracle's when both sides count all-zero units the same way. | ||
| 2291 | + static CENSUS_444_CODED: std::cell::Cell<[usize; 3]> = const { std::cell::Cell::new([0; 3]) }; | ||
| 2292 | + /// Sequential unit index, so a trace line names its own position in the | ||
| 2293 | + /// frame's walk rather than relying on line order alone. | ||
| 2294 | + static CENSUS_UNIT_N: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2295 | + /// The plane the units read from here on belong to. A thread-local rather | ||
| 2296 | + /// than a `read_coeffs` parameter because the three luma call sites | ||
| 2297 | + /// (`decode_rect_split`, `decode_block_rect64`, `read_inter_plane_rect`) | ||
| 2298 | + /// are not this lane's to edit and would each grow an argument; the | ||
| 2299 | + /// plane-owning readers stamp it once on entry instead. | ||
| 2300 | + static CENSUS_PLANE: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 2301 | + /// 4:4:4 (`subsampling_x == 0 && subsampling_y == 0`) for the frame being | ||
| 2302 | + /// decoded, set per frame from [`crate::stream`]. | ||
| 2303 | + static CENSUS_444: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; | ||
| 2304 | +} | ||
| 2305 | + | ||
| 2306 | +/// Current `[luma, u, v]` 4:4:4 coefficient-unit counts. | ||
| 2307 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 2308 | +pub(crate) fn census_444_units() -> [usize; 3] { | ||
| 2309 | + CENSUS_444_UNITS.with(|c| c.get()) | ||
| 2310 | +} | ||
| 2311 | + | ||
| 2312 | +/// Current `[luma, u, v]` 4:4:4 counts of units that coded coefficients. | ||
| 2313 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 2314 | +pub(crate) fn census_444_coded() -> [usize; 3] { | ||
| 2315 | + CENSUS_444_CODED.with(|c| c.get()) | ||
| 2316 | +} | ||
| 2317 | + | ||
| 2318 | +/// lane-av1readcensus: arms the 4:4:4 census for the frame about to decode, | ||
| 2319 | +/// called once per frame from [`crate::stream`]'s decode loop beside | ||
| 2320 | +/// [`set_subsampling`]. At 4:2:0 (or 4:2:2) every census counter stays zero -- | ||
| 2321 | +/// the walk-shape question this census answers is a 4:4:4 one. | ||
| 2322 | +pub(crate) fn set_census_444(ss_x: u8, ss_y: u8) { | ||
| 2323 | + CENSUS_444.with(|c| c.set(ss_x == 0 && ss_y == 0)); | ||
| 2324 | +} | ||
| 2325 | + | ||
| 2326 | +/// lane-av1readcensus: the plane the units read from here on belong to, | ||
| 2327 | +/// stamped by the plane-owning readers ([`read_plane`], [`read_inter_plane`], | ||
| 2328 | +/// [`read_inter_plane_rect`]) on entry. | ||
| 2329 | +pub(crate) fn set_census_plane(plane: usize) { | ||
| 2330 | + CENSUS_PLANE.with(|c| c.set(plane)); | ||
| 2331 | +} | ||
| 2332 | + | ||
| 2333 | +/// lane-av1readcensus: is the per-unit census trace on? Shares | ||
| 2334 | +/// [`coeff_trace_on`]'s per-frame narrowing so one frame's walk can be | ||
| 2335 | +/// dumped without the rest of the stream. | ||
| 2336 | +fn census_trace_on() -> bool { | ||
| 2337 | + if !crate::envflags::env_flag!("EC_CENSUS_UNIT") { | ||
| 2338 | + return false; | ||
| 2339 | + } | ||
| 2340 | + match COEFF_TRACE_FRAME.with(|c| c.get()) { | ||
| 2341 | + None => true, | ||
| 2342 | + Some(w) if w >= usize::MAX - 1 => true, | ||
| 2343 | + Some(w) => COEFF_TRACE_CUR.with(|c| c.get()) == w, | ||
| 2344 | + } | ||
| 2345 | +} | ||
| 2346 | + | ||
| 2347 | +/// lane-av1readcensus: one line per coefficient unit this decoder walks, the | ||
| 2348 | +/// twin of the oracle's `EC_COEFF` / `EC_COEFF_VAL` bracket around each | ||
| 2349 | +/// `av1_read_coeffs_txb` call. Pair the two sides by `post_rng` (or by `n`), | ||
| 2350 | +/// never by plane label or by walk position -- the walk order is exactly what | ||
| 2351 | +/// the census is measuring. | ||
| 2352 | +fn census_unit( | ||
| 2353 | + w: usize, | ||
| 2354 | + h: usize, | ||
| 2355 | + tx_type: TxType, | ||
| 2356 | + eob: usize, | ||
| 2357 | + all_zero: bool, | ||
| 2358 | + entry_rng: u32, | ||
| 2359 | + dec: &SymbolDecoder, | ||
| 2360 | +) { | ||
| 2361 | + let plane = CENSUS_PLANE.with(|c| c.get()).min(2); | ||
| 2362 | + let coded = usize::from(!all_zero); | ||
| 2363 | + CENSUS_UNIT_N.with(|c| c.set(c.get() + 1)); | ||
| 2364 | + hit_do! { | ||
| 2365 | + CENSUS_444_UNITS.with(|c| { | ||
| 2366 | + if CENSUS_444.with(|on| on.get()) { | ||
| 2367 | + let mut v = c.get(); | ||
| 2368 | + v[plane] += 1; | ||
| 2369 | + c.set(v); | ||
| 2370 | + } | ||
| 2371 | + }); | ||
| 2372 | + CENSUS_444_CODED.with(|c| { | ||
| 2373 | + if CENSUS_444.with(|on| on.get()) { | ||
| 2374 | + let mut v = c.get(); | ||
| 2375 | + v[plane] += coded; | ||
| 2376 | + c.set(v); | ||
| 2377 | + } | ||
| 2378 | + }); | ||
| 2379 | + } | ||
| 2380 | + if !census_trace_on() { | ||
| 2381 | + return; | ||
| 2382 | + } | ||
| 2383 | + let n = CENSUS_UNIT_N.with(|c| c.get()) - 1; | ||
| 2384 | + let post_rng = dec.debug_state().0; | ||
| 2385 | + eprintln!( | ||
| 2386 | + "EC_CENSUS_UNIT side=ours n={n} plane={plane} w={w} h={h} tx={tx_type:?} eob={eob} \ | ||
| 2387 | + all_zero={all_zero} entry_rng={entry_rng} post_rng={post_rng}" | ||
| 2388 | + ); | ||
| 2389 | +} | ||
| 2390 | + | ||
| 2278 | // As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16 | 2391 | // As [`FILTER_INTRA_RECT_HITS`], counting only the strips BELOW 16x16 |
| 2279 | // (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the | 2392 | // (8x16/16x8 leaves of a 16x16 HORZ/VERT partition, lane-fistrip r1) -- the |
| 2280 | // shapes whose `use_filter_intra` symbol had no CDF class before this round. | 2393 | // shapes whose `use_filter_intra` symbol had no CDF class before this round. |
| @@ -7561,6 +7674,11 @@ fn read_coeffs( | |||
| 7561 | ) -> Result<(Grid, TxType)> { | 7674 | ) -> Result<(Grid, TxType)> { |
| 7562 | let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); | 7675 | let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); |
| 7563 | let side = coding.side; | 7676 | let side = coding.side; |
| 7677 | + // lane-av1readcensus: this unit's own entry state, so the census line | ||
| 7678 | + // carries the pre-read rng and pairs against the oracle's `EC_COEFF` | ||
| 7679 | + // (which prints `r->ec.rng` before the same `txb_skip` read). | ||
| 7680 | + let census_entry_rng = dec.debug_state().0; | ||
| 7681 | + let (census_w, census_h) = rect_shape.unwrap_or((side, side)); | ||
| 7564 | if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") { | 7682 | if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") { |
| 7565 | let (range, value) = dec.debug_state(); | 7683 | let (range, value) = dec.debug_state(); |
| 7566 | eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}"); | 7684 | eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}"); |
| @@ -7603,6 +7721,15 @@ fn read_coeffs( | |||
| 7603 | if all_zero { | 7721 | if all_zero { |
| 7604 | // lane-coefgrid: the all-zero unit (60% of the 4K segment's) names the | 7722 | // lane-coefgrid: the all-zero unit (60% of the 4K segment's) names the |
| 7605 | // shared zero grid instead of allocating and zeroing its own. | 7723 | // shared zero grid instead of allocating and zeroing its own. |
| 7724 | + census_unit( | ||
| 7725 | + census_w, | ||
| 7726 | + census_h, | ||
| 7727 | + TxType::DctDct, | ||
| 7728 | + 0, | ||
| 7729 | + true, | ||
| 7730 | + census_entry_rng, | ||
| 7731 | + dec, | ||
| 7732 | + ); | ||
| 7606 | return Ok((Grid::Zero(side * side), TxType::DctDct)); | 7733 | return Ok((Grid::Zero(side * side), TxType::DctDct)); |
| 7607 | } | 7734 | } |
| 7608 | let mut grid = vec![0i32; side * side]; | 7735 | let mut grid = vec![0i32; side * side]; |
| @@ -7811,6 +7938,15 @@ fn read_coeffs( | |||
| 7811 | } | 7938 | } |
| 7812 | grid[pos] = if negative { -level } else { level }; | 7939 | grid[pos] = if negative { -level } else { level }; |
| 7813 | } | 7940 | } |
| 7941 | + census_unit( | ||
| 7942 | + census_w, | ||
| 7943 | + census_h, | ||
| 7944 | + tx_type, | ||
| 7945 | + eob, | ||
| 7946 | + false, | ||
| 7947 | + census_entry_rng, | ||
| 7948 | + dec, | ||
| 7949 | + ); | ||
| 7814 | Ok((Grid::Own(grid), tx_type)) | 7950 | Ok((Grid::Own(grid), tx_type)) |
| 7815 | } | 7951 | } |
| 7816 | 7952 | ||
| @@ -7832,18 +7968,31 @@ fn read_coeffs_rect( | |||
| 7832 | skip_ctx: usize, | 7968 | skip_ctx: usize, |
| 7833 | sign_ctx: usize, | 7969 | sign_ctx: usize, |
| 7834 | default_tx_type: TxType, | 7970 | default_tx_type: TxType, |
| 7971 | + // lane-av1chrtx: the plane this unit belongs to (0 luma, 1 U, 2 V) -- | ||
| 7972 | + // printed by the two `EC_COEFF_STEP` traces below, which hardcoded | ||
| 7973 | + // `plane=0` and so mis-attributed a CHROMA read as a luma one in two | ||
| 7974 | + // independent lane reports. | ||
| 7975 | + plane: usize, | ||
| 7835 | ) -> Result<(Grid, TxType)> { | 7976 | ) -> Result<(Grid, TxType)> { |
| 7836 | let rect_trace = coeff_trace_on(); | 7977 | let rect_trace = coeff_trace_on(); |
| 7837 | let entry_rng = dec.debug_state().0; | 7978 | let entry_rng = dec.debug_state().0; |
| 7979 | + // lane-av1readcensus: this reader is handed the real plane (lane-av1chrtx | ||
| 7980 | + // threaded it in for the `EC_COEFF_STEP` traces), so it stamps the census | ||
| 7981 | + // plane itself rather than inheriting whichever reader did last. The | ||
| 7982 | + // luma-only readers (`decode_rect_split`, `decode_block_rect64`, | ||
| 7983 | + // `read_inter_plane_rect`'s corner) are all plane 0 -- the stamp's initial | ||
| 7984 | + // value -- and the other plane-owning readers stamp on entry. | ||
| 7985 | + set_census_plane(plane); | ||
| 7838 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; | 7986 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 7839 | if rect_trace { | 7987 | if rect_trace { |
| 7840 | eprintln!( | 7988 | eprintln!( |
| 7841 | - "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}", | 7989 | + "EC_COEFF_STEP tag=all_zero plane={plane} ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}", |
| 7842 | all_zero as i32, | 7990 | all_zero as i32, |
| 7843 | dec.debug_state().0 | 7991 | dec.debug_state().0 |
| 7844 | ); | 7992 | ); |
| 7845 | } | 7993 | } |
| 7846 | if all_zero { | 7994 | if all_zero { |
| 7995 | + census_unit(w, h, TxType::DctDct, 0, true, entry_rng, dec); | ||
| 7847 | return Ok((Grid::Zero(w * h), TxType::DctDct)); | 7996 | return Ok((Grid::Zero(w * h), TxType::DctDct)); |
| 7848 | } | 7997 | } |
| 7849 | let mut grid = vec![0i32; w * h]; | 7998 | let mut grid = vec![0i32; w * h]; |
| @@ -7864,7 +8013,7 @@ fn read_coeffs_rect( | |||
| 7864 | })?; | 8013 | })?; |
| 7865 | if rect_trace { | 8014 | if rect_trace { |
| 7866 | eprintln!( | 8015 | eprintln!( |
| 7867 | - "EC_COEFF_STEP tag=tx_type plane=0 rng={}", | 8016 | + "EC_COEFF_STEP tag=tx_type plane={plane} rng={}", |
| 7868 | dec.debug_state().0 | 8017 | dec.debug_state().0 |
| 7869 | ); | 8018 | ); |
| 7870 | } | 8019 | } |
| @@ -8047,6 +8196,7 @@ fn read_coeffs_rect( | |||
| 8047 | nz.join(",") | 8196 | nz.join(",") |
| 8048 | ); | 8197 | ); |
| 8049 | } | 8198 | } |
| 8199 | + census_unit(w, h, tx_type, eob, false, entry_rng, dec); | ||
| 8050 | Ok((Grid::Own(grid), tx_type)) | 8200 | Ok((Grid::Own(grid), tx_type)) |
| 8051 | } | 8201 | } |
| 8052 | 8202 | ||
| @@ -8076,11 +8226,25 @@ fn read_chroma_coeffs_rect( | |||
| 8076 | sign_ctx: usize, | 8226 | sign_ctx: usize, |
| 8077 | default_tx_type: TxType, | 8227 | default_tx_type: TxType, |
| 8078 | fctx: &crate::decode::FrameCtx, | 8228 | fctx: &crate::decode::FrameCtx, |
| 8229 | + // lane-av1chrtx: the plane index, threaded to `read_coeffs_rect`'s | ||
| 8230 | + // `EC_COEFF_STEP` traces (they used to print a hardcoded `plane=0`, so a | ||
| 8231 | + // V-plane read was indistinguishable from a luma one in the log). | ||
| 8232 | + plane: usize, | ||
| 8079 | ) -> Result<(Grid, TxType)> { | 8233 | ) -> Result<(Grid, TxType)> { |
| 8080 | if mono(fctx) { | 8234 | if mono(fctx) { |
| 8081 | return Ok((Grid::Zero(w * h), TxType::DctDct)); | 8235 | return Ok((Grid::Zero(w * h), TxType::DctDct)); |
| 8082 | } | 8236 | } |
| 8083 | - read_coeffs_rect(dec, coding, scan, w, h, skip_ctx, sign_ctx, default_tx_type) | 8237 | + read_coeffs_rect( |
| 8238 | + dec, | ||
| 8239 | + coding, | ||
| 8240 | + scan, | ||
| 8241 | + w, | ||
| 8242 | + h, | ||
| 8243 | + skip_ctx, | ||
| 8244 | + sign_ctx, | ||
| 8245 | + default_tx_type, | ||
| 8246 | + plane, | ||
| 8247 | + ) | ||
| 8084 | } | 8248 | } |
| 8085 | 8249 | ||
| 8086 | /// What one coded block leaves behind for the blocks that read it as a | 8250 | /// What one coded block leaves behind for the blocks that read it as a |
| @@ -11537,6 +11701,7 @@ fn decode_rect_split( | |||
| 11537 | tu_skip_ctx, | 11701 | tu_skip_ctx, |
| 11538 | dc_sign_ctx(tu_around.2), | 11702 | dc_sign_ctx(tu_around.2), |
| 11539 | TxType::DctDct, | 11703 | TxType::DctDct, |
| 11704 | + 0, | ||
| 11540 | )?; | 11705 | )?; |
| 11541 | let residual = dequant_and_inverse_typed_wh( | 11706 | let residual = dequant_and_inverse_typed_wh( |
| 11542 | &tu_grid, | 11707 | &tu_grid, |
| @@ -11962,6 +12127,7 @@ fn decode_rect_split( | |||
| 11962 | skip_ctx, | 12127 | skip_ctx, |
| 11963 | dc_sign_ctx(cu_around[plane_idx].2), | 12128 | dc_sign_ctx(cu_around[plane_idx].2), |
| 11964 | default_tx, | 12129 | default_tx, |
| 12130 | + plane_idx, | ||
| 11965 | )?; | 12131 | )?; |
| 11966 | let residual = dequant_and_inverse_typed_wh( | 12132 | let residual = dequant_and_inverse_typed_wh( |
| 11967 | &levels, | 12133 | &levels, |
| @@ -12046,6 +12212,7 @@ fn decode_rect_split( | |||
| 12046 | skip_ctx, | 12212 | skip_ctx, |
| 12047 | dc_sign_ctx(around[plane_idx].2), | 12213 | dc_sign_ctx(around[plane_idx].2), |
| 12048 | default_tx, | 12214 | default_tx, |
| 12215 | + plane_idx, | ||
| 12049 | )?; | 12216 | )?; |
| 12050 | // The same delta_q proof the unsplit rect64 path records | 12217 | // The same delta_q proof the unsplit rect64 path records |
| 12051 | // (lane-rectsplit r4: lifting the split-transform refusal moved | 12218 | // (lane-rectsplit r4: lifting the split-transform refusal moved |
| @@ -14510,6 +14677,7 @@ fn decode_block_rect( | |||
| 14510 | 0, | 14677 | 0, |
| 14511 | dc_sign_ctx(around[0].2), | 14678 | dc_sign_ctx(around[0].2), |
| 14512 | TxType::DctDct, | 14679 | TxType::DctDct, |
| 14680 | + 0, | ||
| 14513 | )?; | 14681 | )?; |
| 14514 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 14682 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 14515 | let (rng, _) = dec.debug_state(); | 14683 | let (rng, _) = dec.debug_state(); |
| @@ -14558,6 +14726,7 @@ fn decode_block_rect( | |||
| 14558 | dc_sign_ctx(around[1].2), | 14726 | dc_sign_ctx(around[1].2), |
| 14559 | u_default_tx, | 14727 | u_default_tx, |
| 14560 | fctx, | 14728 | fctx, |
| 14729 | + 1, | ||
| 14561 | )?; | 14730 | )?; |
| 14562 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 14731 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 14563 | let (rng, _) = dec.debug_state(); | 14732 | let (rng, _) = dec.debug_state(); |
| @@ -14605,6 +14774,7 @@ fn decode_block_rect( | |||
| 14605 | dc_sign_ctx(around[2].2), | 14774 | dc_sign_ctx(around[2].2), |
| 14606 | v_default_tx, | 14775 | v_default_tx, |
| 14607 | fctx, | 14776 | fctx, |
| 14777 | + 2, | ||
| 14608 | )?; | 14778 | )?; |
| 14609 | if crate::envflags::env_flag!("EC_AV1_TRACE") { | 14779 | if crate::envflags::env_flag!("EC_AV1_TRACE") { |
| 14610 | let (rng, _) = dec.debug_state(); | 14780 | let (rng, _) = dec.debug_state(); |
| @@ -15087,6 +15257,7 @@ fn decode_leaf_rect( | |||
| 15087 | 0, | 15257 | 0, |
| 15088 | dc_sign_ctx(around[0].2), | 15258 | dc_sign_ctx(around[0].2), |
| 15089 | TxType::DctDct, | 15259 | TxType::DctDct, |
| 15260 | + 0, | ||
| 15090 | )?; | 15261 | )?; |
| 15091 | if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") { | 15262 | if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") { |
| 15092 | let nz: Vec<(usize, i32)> = l_levels | 15263 | let nz: Vec<(usize, i32)> = l_levels |
| @@ -15141,6 +15312,7 @@ fn decode_leaf_rect( | |||
| 15141 | dc_sign_ctx(around[1].2), | 15312 | dc_sign_ctx(around[1].2), |
| 15142 | u_default_tx, | 15313 | u_default_tx, |
| 15143 | fctx, | 15314 | fctx, |
| 15315 | + 1, | ||
| 15144 | )?; | 15316 | )?; |
| 15145 | u_levels = u_l; | 15317 | u_levels = u_l; |
| 15146 | let u_residual = dequant_and_inverse_typed_wh( | 15318 | let u_residual = dequant_and_inverse_typed_wh( |
| @@ -15185,6 +15357,7 @@ fn decode_leaf_rect( | |||
| 15185 | dc_sign_ctx(around[2].2), | 15357 | dc_sign_ctx(around[2].2), |
| 15186 | v_default_tx, | 15358 | v_default_tx, |
| 15187 | fctx, | 15359 | fctx, |
| 15360 | + 2, | ||
| 15188 | )?; | 15361 | )?; |
| 15189 | v_levels = v_l; | 15362 | v_levels = v_l; |
| 15190 | let v_residual = dequant_and_inverse_typed_wh( | 15363 | let v_residual = dequant_and_inverse_typed_wh( |
| @@ -15608,6 +15781,7 @@ fn decode_block_rect4( | |||
| 15608 | 0, | 15781 | 0, |
| 15609 | dc_sign_ctx(around[0].2), | 15782 | dc_sign_ctx(around[0].2), |
| 15610 | TxType::DctDct, | 15783 | TxType::DctDct, |
| 15784 | + 0, | ||
| 15611 | )?; | 15785 | )?; |
| 15612 | hit!(RECT4_COEFF_HITS); | 15786 | hit!(RECT4_COEFF_HITS); |
| 15613 | let luma_residual = dequant_and_inverse_typed_wh( | 15787 | let luma_residual = dequant_and_inverse_typed_wh( |
| @@ -15758,6 +15932,7 @@ fn decode_block_rect4( | |||
| 15758 | 0, | 15932 | 0, |
| 15759 | dc_sign_ctx(around[0].2), | 15933 | dc_sign_ctx(around[0].2), |
| 15760 | TxType::DctDct, | 15934 | TxType::DctDct, |
| 15935 | + 0, | ||
| 15761 | )?; | 15936 | )?; |
| 15762 | let mut planes = Vec::with_capacity(2); | 15937 | let mut planes = Vec::with_capacity(2); |
| 15763 | for plane in 1..3 { | 15938 | for plane in 1..3 { |
| @@ -15783,6 +15958,7 @@ fn decode_block_rect4( | |||
| 15783 | dc_sign_ctx(around[plane].2), | 15958 | dc_sign_ctx(around[plane].2), |
| 15784 | default_tx, | 15959 | default_tx, |
| 15785 | fctx, | 15960 | fctx, |
| 15961 | + plane, | ||
| 15786 | )?; | 15962 | )?; |
| 15787 | planes.push((levels, tx_type)); | 15963 | planes.push((levels, tx_type)); |
| 15788 | } | 15964 | } |
| @@ -17313,6 +17489,7 @@ fn decode_rect4_16_strip( | |||
| 17313 | tu_skip_ctx, | 17489 | tu_skip_ctx, |
| 17314 | dc_sign_ctx(tu_around.2), | 17490 | dc_sign_ctx(tu_around.2), |
| 17315 | TxType::DctDct, | 17491 | TxType::DctDct, |
| 17492 | + 0, | ||
| 17316 | )?; | 17493 | )?; |
| 17317 | let residual = dequant_and_inverse_typed_wh( | 17494 | let residual = dequant_and_inverse_typed_wh( |
| 17318 | &tu_grid, | 17495 | &tu_grid, |
| @@ -17419,6 +17596,7 @@ fn decode_rect4_16_strip( | |||
| 17419 | 0, | 17596 | 0, |
| 17420 | dc_sign_ctx(around.2), | 17597 | dc_sign_ctx(around.2), |
| 17421 | TxType::DctDct, | 17598 | TxType::DctDct, |
| 17599 | + 0, | ||
| 17422 | )?; | 17600 | )?; |
| 17423 | let residual = dequant_and_inverse_typed_wh( | 17601 | let residual = dequant_and_inverse_typed_wh( |
| 17424 | &levels, | 17602 | &levels, |
| @@ -17935,6 +18113,7 @@ fn decode_rect4_16_strip( | |||
| 17935 | dc_sign_ctx(around[plane].2), | 18113 | dc_sign_ctx(around[plane].2), |
| 17936 | default_tx, | 18114 | default_tx, |
| 17937 | fctx, | 18115 | fctx, |
| 18116 | + plane, | ||
| 17938 | )?; | 18117 | )?; |
| 17939 | planes.push((levels, tx_type)); | 18118 | planes.push((levels, tx_type)); |
| 17940 | } | 18119 | } |
| @@ -18441,6 +18620,7 @@ fn decode_block_rect64( | |||
| 18441 | 0, | 18620 | 0, |
| 18442 | dc_sign_ctx(around[0].2), | 18621 | dc_sign_ctx(around[0].2), |
| 18443 | TxType::DctDct, | 18622 | TxType::DctDct, |
| 18623 | + 0, | ||
| 18444 | )? | 18624 | )? |
| 18445 | }; | 18625 | }; |
| 18446 | if coeff_trace_on() { | 18626 | if coeff_trace_on() { |
| @@ -18596,6 +18776,7 @@ fn decode_block_rect64( | |||
| 18596 | dc_sign_ctx(cu_around[plane_idx].2), | 18776 | dc_sign_ctx(cu_around[plane_idx].2), |
| 18597 | TxType::DctDct, | 18777 | TxType::DctDct, |
| 18598 | fctx, | 18778 | fctx, |
| 18779 | + plane_idx, | ||
| 18599 | )?; | 18780 | )?; |
| 18600 | let residual = dequant_and_inverse_typed_wh( | 18781 | let residual = dequant_and_inverse_typed_wh( |
| 18601 | &levels, | 18782 | &levels, |
| @@ -19822,6 +20003,8 @@ fn read_plane( | |||
| 19822 | if plane_idx > 0 && mono(fctx) { | 20003 | if plane_idx > 0 && mono(fctx) { |
| 19823 | return Ok(Grid::Zero(side * side)); | 20004 | return Ok(Grid::Zero(side * side)); |
| 19824 | } | 20005 | } |
| 20006 | + // lane-av1readcensus: the units read from here on are this plane's. | ||
| 20007 | + set_census_plane(plane_idx); | ||
| 19825 | let skip_ctx = if plane_idx == 0 { | 20008 | let skip_ctx = if plane_idx == 0 { |
| 19826 | luma_skip_ctx.unwrap_or(0) | 20009 | luma_skip_ctx.unwrap_or(0) |
| 19827 | } else { | 20010 | } else { |
| @@ -20074,6 +20257,7 @@ fn read_rect_chroma_unit( | |||
| 20074 | usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0), | 20257 | usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0), |
| 20075 | dc_sign_ctx(around.2), | 20258 | dc_sign_ctx(around.2), |
| 20076 | default_tx, | 20259 | default_tx, |
| 20260 | + plane_idx, | ||
| 20077 | )?; | 20261 | )?; |
| 20078 | let residual = dequant_and_inverse_typed_wh( | 20262 | let residual = dequant_and_inverse_typed_wh( |
| 20079 | &levels, | 20263 | &levels, |
| @@ -23125,6 +23309,7 @@ fn leaf8_chroma422_unit( | |||
| 23125 | usize::from(around.0) + usize::from(around.1), | 23309 | usize::from(around.0) + usize::from(around.1), |
| 23126 | dc_sign_ctx(around.2), | 23310 | dc_sign_ctx(around.2), |
| 23127 | default_tx, | 23311 | default_tx, |
| 23312 | + plane_idx, | ||
| 23128 | )?; | 23313 | )?; |
| 23129 | let residual = dequant_and_inverse_typed_wh( | 23314 | let residual = dequant_and_inverse_typed_wh( |
| 23130 | &levels, | 23315 | &levels, |
| @@ -23775,6 +23960,7 @@ fn sub8_leaf_chroma444( | |||
| 23775 | skip_ctx, | 23960 | skip_ctx, |
| 23776 | dc_sign_ctx(around[plane_idx].2), | 23961 | dc_sign_ctx(around[plane_idx].2), |
| 23777 | default_tx, | 23962 | default_tx, |
| 23963 | + plane_idx, | ||
| 23778 | )?; | 23964 | )?; |
| 23779 | let residual = dequant_and_inverse_typed_wh( | 23965 | let residual = dequant_and_inverse_typed_wh( |
| 23780 | &levels, | 23966 | &levels, |
| @@ -23954,6 +24140,7 @@ fn sub8_leaf_chroma444( | |||
| 23954 | skip_ctx, | 24140 | skip_ctx, |
| 23955 | dc_sign_ctx(around[plane_idx].2), | 24141 | dc_sign_ctx(around[plane_idx].2), |
| 23956 | default_tx, | 24142 | default_tx, |
| 24143 | + plane_idx, | ||
| 23957 | )?; | 24144 | )?; |
| 23958 | let residual = dequant_and_inverse_typed_wh( | 24145 | let residual = dequant_and_inverse_typed_wh( |
| 23959 | &levels, | 24146 | &levels, |
| @@ -25337,6 +25524,7 @@ fn decode_leaf_rect8( | |||
| 25337 | skip_ctx, | 25524 | skip_ctx, |
| 25338 | dc_sign_ctx(around.2), | 25525 | dc_sign_ctx(around.2), |
| 25339 | TxType::DctDct, | 25526 | TxType::DctDct, |
| 25527 | + 0, | ||
| 25340 | )?; | 25528 | )?; |
| 25341 | if li == 0 { | 25529 | if li == 0 { |
| 25342 | chroma_tx = tx_type; | 25530 | chroma_tx = tx_type; |
| @@ -25748,6 +25936,7 @@ fn decode_leaf_rect8( | |||
| 25748 | 0, | 25936 | 0, |
| 25749 | dc_sign_ctx(around.2), | 25937 | dc_sign_ctx(around.2), |
| 25750 | TxType::DctDct, | 25938 | TxType::DctDct, |
| 25939 | + 0, | ||
| 25751 | )?; | 25940 | )?; |
| 25752 | if levels.iter().any(|&l| l != 0) { | 25941 | if levels.iter().any(|&l| l != 0) { |
| 25753 | if vert { | 25942 | if vert { |
| @@ -28200,6 +28389,13 @@ fn read_inter_rect_chroma( | |||
| 28200 | (write_chroma_w, write_chroma_h): (usize, usize), | 28389 | (write_chroma_w, write_chroma_h): (usize, usize), |
| 28201 | chroma_side: usize, | 28390 | chroma_side: usize, |
| 28202 | mode_for_tx: usize, | 28391 | mode_for_tx: usize, |
| 28392 | + // lane-av1chrtx: this block's coded luma transform leaves, `(row, col, | ||
| 28393 | + // tw, th, tx_type)` -- the same list the 4:4:4 four-unit arms resolve | ||
| 28394 | + // through `covering_leaf_tx_type`. This sibling used to hand EVERY unit | ||
| 28395 | + // the block-level `luma_tx_type` (the top-left leaf's type), so a rect | ||
| 28396 | + // inter block whose chroma plane splits (`nx*ny > 1`) over MIXED var-tx | ||
| 28397 | + // leaves read the wrong type per unit. | ||
| 28398 | + leaf_tx_types: &[(usize, usize, usize, usize, TxType)], | ||
| 28203 | luma_tx_type: TxType, | 28399 | luma_tx_type: TxType, |
| 28204 | fctx: &crate::decode::FrameCtx, | 28400 | fctx: &crate::decode::FrameCtx, |
| 28205 | ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { | 28401 | ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { |
| @@ -28225,7 +28421,12 @@ fn read_inter_rect_chroma( | |||
| 28225 | let invalid_ss_plane = | 28421 | let invalid_ss_plane = |
| 28226 | ss_x(fctx) == 1 && ss_y(fctx) == 0 && (write_chroma_w, write_chroma_h) == (4, 32); | 28422 | ss_x(fctx) == 1 && ss_y(fctx) == 0 && (write_chroma_w, write_chroma_h) == (4, 32); |
| 28227 | let (uw, uh) = if invalid_ss_plane { (4, 8) } else { (uw, uh) }; | 28423 | let (uw, uh) = if invalid_ss_plane { (4, 8) } else { (uw, uh) }; |
| 28228 | - let inherit_tx_type = Some(luma_tx_type); | 28424 | + // lane-av1chrtx: `inherit_tx_type` is resolved PER UNIT below, not once |
| 28425 | + // for the block -- `av1_get_tx_type` (blockd.h:1287-1297) reads | ||
| 28426 | + // `xd->tx_type_map` at the chroma unit's own position scaled back to | ||
| 28427 | + // luma, so a unit sitting over a luma leaf that coded NOTHING takes that | ||
| 28428 | + // leaf's `DCT_DCT` stamp (`decodetxb.c:199-203`), not the block-level | ||
| 28429 | + // (top-left leaf) type. | ||
| 28229 | let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); | 28430 | let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); |
| 28230 | let multi = nx * ny > 1; | 28431 | let multi = nx * ny > 1; |
| 28231 | let set = rect_inter_chroma_set(uw, uh)?; | 28432 | let set = rect_inter_chroma_set(uw, uh)?; |
| @@ -28263,6 +28464,7 @@ fn read_inter_rect_chroma( | |||
| 28263 | at_mi.0 + cu_row * (span_y / MI), | 28464 | at_mi.0 + cu_row * (span_y / MI), |
| 28264 | at_mi.1 + cu_col * (span_x / MI), | 28465 | at_mi.1 + cu_col * (span_x / MI), |
| 28265 | ); | 28466 | ); |
| 28467 | + let unit_rel_mi = (cu_mi.0 - at_mi.0, cu_mi.1 - at_mi.1); | ||
| 28266 | let cu_around = if multi { | 28468 | let cu_around = if multi { |
| 28267 | // lane-av1422ctxgather: at ss (1,0) the unit's above | 28469 | // lane-av1422ctxgather: at ss (1,0) the unit's above |
| 28268 | // span covers `uw` chroma px = `2*uw` luma mi columns, | 28470 | // span covers `uw` chroma px = `2*uw` luma mi columns, |
| @@ -28282,6 +28484,16 @@ fn read_inter_rect_chroma( | |||
| 28282 | }; | 28484 | }; |
| 28283 | let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); | 28485 | let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); |
| 28284 | let cu_pred = src.offset(cu_row * uh * chroma_side + cu_col * uw); | 28486 | let cu_pred = src.offset(cu_row * uh * chroma_side + cu_col * uw); |
| 28487 | + let inherit_tx_type = | ||
| 28488 | + if let Some(t) = covering_leaf_tx_type(leaf_tx_types, unit_rel_mi) { | ||
| 28489 | + hit!(CHROMA_RECT_LEAF_TX_HITS); | ||
| 28490 | + if Some(t) != Some(luma_tx_type) { | ||
| 28491 | + hit!(CHROMA_RECT_LEAF_TX_DIFF_HITS); | ||
| 28492 | + } | ||
| 28493 | + Some(t) | ||
| 28494 | + } else { | ||
| 28495 | + Some(luma_tx_type) | ||
| 28496 | + }; | ||
| 28285 | let cu_grid = read_inter_plane_rect( | 28497 | let cu_grid = read_inter_plane_rect( |
| 28286 | dec, | 28498 | dec, |
| 28287 | cdfs, | 28499 | cdfs, |
| @@ -28366,6 +28578,8 @@ fn read_inter_plane_rect( | |||
| 28366 | if plane_idx > 0 && mono(fctx) { | 28578 | if plane_idx > 0 && mono(fctx) { |
| 28367 | return Ok((Grid::Zero(w * h), TxType::DctDct)); | 28579 | return Ok((Grid::Zero(w * h), TxType::DctDct)); |
| 28368 | } | 28580 | } |
| 28581 | + // lane-av1readcensus: the units read from here on are this plane's. | ||
| 28582 | + set_census_plane(plane_idx); | ||
| 28369 | let skip_ctx = if plane_idx == 0 { | 28583 | let skip_ctx = if plane_idx == 0 { |
| 28370 | // `get_txb_ctx_general`: 0 only when this unit IS the whole plane | 28584 | // `get_txb_ctx_general`: 0 only when this unit IS the whole plane |
| 28371 | // block; a var-tx leaf passes its own neighbour-table context. | 28585 | // block; a var-tx leaf passes its own neighbour-table context. |
| @@ -28442,6 +28656,7 @@ fn read_inter_plane_rect( | |||
| 28442 | skip_ctx, | 28656 | skip_ctx, |
| 28443 | dc_sign_ctx(around.2), | 28657 | dc_sign_ctx(around.2), |
| 28444 | default_tx_type, | 28658 | default_tx_type, |
| 28659 | + plane_idx, | ||
| 28445 | )? | 28660 | )? |
| 28446 | }; | 28661 | }; |
| 28447 | let grid = extend_corner(corner, cw, ch, w, h); | 28662 | let grid = extend_corner(corner, cw, ch, w, h); |
| @@ -35435,6 +35650,8 @@ fn read_inter_plane( | |||
| 35435 | if plane_idx > 0 && mono(fctx) { | 35650 | if plane_idx > 0 && mono(fctx) { |
| 35436 | return Ok((Grid::Zero(side * side), TxType::DctDct)); | 35651 | return Ok((Grid::Zero(side * side), TxType::DctDct)); |
| 35437 | } | 35652 | } |
| 35653 | + // lane-av1readcensus: the units read from here on are this plane's. | ||
| 35654 | + set_census_plane(plane_idx); | ||
| 35438 | let skip_ctx = if plane_idx == 0 { | 35655 | let skip_ctx = if plane_idx == 0 { |
| 35439 | luma_skip_ctx.unwrap_or(0) | 35656 | luma_skip_ctx.unwrap_or(0) |
| 35440 | } else { | 35657 | } else { |
| @@ -35661,10 +35878,7 @@ fn read_intra_chroma_lossless( | |||
| 35661 | /// skipped (the returned order is the identity). `changed` is `true` only | 35878 | /// skipped (the returned order is the identity). `changed` is `true` only |
| 35662 | /// when the sort actually permutes the list, so a no-op ordering reads zero | 35879 | /// when the sort actually permutes the list, so a no-op ordering reads zero |
| 35663 | /// on [`MU_CHUNK_ORDER_HITS`] and cannot make a gate look armed. | 35880 | /// on [`MU_CHUNK_ORDER_HITS`] and cannot make a gate look armed. |
| 35664 | -fn mu_chunk_order( | 35881 | +fn mu_chunk_order(leaves: &[(usize, usize, usize, usize)], side: usize) -> (Vec<usize>, bool) { |
| 35665 | - leaves: &[(usize, usize, usize, usize)], | ||
| 35666 | - side: usize, | ||
| 35667 | -) -> (Vec<usize>, bool) { | ||
| 35668 | let identity: Vec<usize> = (0..leaves.len()).collect(); | 35882 | let identity: Vec<usize> = (0..leaves.len()).collect(); |
| 35669 | if side <= 64 { | 35883 | if side <= 64 { |
| 35670 | return (identity, false); | 35884 | return (identity, false); |
| @@ -37943,6 +38157,39 @@ pub(crate) fn chroma_quad_leaf_tx_diff_hits() -> usize { | |||
| 37943 | CHROMA_QUAD_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get) | 38157 | CHROMA_QUAD_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get) |
| 37944 | } | 38158 | } |
| 37945 | 38159 | ||
| 38160 | +thread_local! { | ||
| 38161 | + /// lane-av1chrtx: chroma units of a RECT inter block | ||
| 38162 | + /// ([`read_inter_rect_chroma`], the sibling of the 4:4:4 four-unit arms) | ||
| 38163 | + /// that resolved their `tx_type` from the luma leaf covering their OWN | ||
| 38164 | + /// quadrant instead of the block-level one. A SEPARATE counter from | ||
| 38165 | + /// [`CHROMA_QUAD_LEAF_TX_HITS`] on purpose: that one gates a 4:2:0 control | ||
| 38166 | + /// that must stay at exactly 0, and this route IS reachable at 4:2:0, so | ||
| 38167 | + /// sharing the counter would destroy that control's meaning. | ||
| 38168 | + pub(crate) static CHROMA_RECT_LEAF_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 38169 | +} | ||
| 38170 | + | ||
| 38171 | +thread_local! { | ||
| 38172 | + /// Of those, how many resolved a type that DIFFERS from the block-level | ||
| 38173 | + /// one -- the condition that changes pixels. A route counter alone fires | ||
| 38174 | + /// on every multi-unit rect chroma read, including the blocks whose | ||
| 38175 | + /// leaves all agree (the exact shape a no-op fix looks green on). | ||
| 38176 | + pub(crate) static CHROMA_RECT_LEAF_TX_DIFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 38177 | +} | ||
| 38178 | + | ||
| 38179 | +/// [`CHROMA_RECT_LEAF_TX_HITS`]: rect chroma units that took their type from | ||
| 38180 | +/// the covering luma leaf. | ||
| 38181 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 38182 | +pub(crate) fn chroma_rect_leaf_tx_hits() -> usize { | ||
| 38183 | + CHROMA_RECT_LEAF_TX_HITS.with(std::cell::Cell::get) | ||
| 38184 | +} | ||
| 38185 | + | ||
| 38186 | +/// [`CHROMA_RECT_LEAF_TX_DIFF_HITS`]: of those, the units whose covering | ||
| 38187 | +/// leaf's type differs from the block-level one. | ||
| 38188 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 38189 | +pub(crate) fn chroma_rect_leaf_tx_diff_hits() -> usize { | ||
| 38190 | + CHROMA_RECT_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get) | ||
| 38191 | +} | ||
| 38192 | + | ||
| 37946 | fn decode_inter_block( | 38193 | fn decode_inter_block( |
| 37947 | dec: &mut SymbolDecoder, | 38194 | dec: &mut SymbolDecoder, |
| 37948 | cdfs: &mut Cdfs, | 38195 | cdfs: &mut Cdfs, |
| @@ -39874,6 +40121,7 @@ fn decode_inter_block( | |||
| 39874 | (write_chroma_w, write_chroma_h), | 40121 | (write_chroma_w, write_chroma_h), |
| 39875 | chroma_stride, | 40122 | chroma_stride, |
| 39876 | mode_for_tx, | 40123 | mode_for_tx, |
| 40124 | + &leaf_tx_types, | ||
| 39877 | luma_tx_type, | 40125 | luma_tx_type, |
| 39878 | fctx, | 40126 | fctx, |
| 39879 | )?; | 40127 | )?; |
| @@ -41666,6 +41914,7 @@ fn decode_inter_block( | |||
| 41666 | (write_chroma_w, write_chroma_h), | 41914 | (write_chroma_w, write_chroma_h), |
| 41667 | chroma_stride, | 41915 | chroma_stride, |
| 41668 | mode_for_tx, | 41916 | mode_for_tx, |
| 41917 | + &leaf_tx_types, | ||
| 41669 | luma_tx_type, | 41918 | luma_tx_type, |
| 41670 | fctx, | 41919 | fctx, |
| 41671 | )?; | 41920 | )?; |
| @@ -42316,8 +42565,7 @@ fn decode_inter_block( | |||
| 42316 | if side > 64 { | 42565 | if side > 64 { |
| 42317 | let chunk = (row / 16, col / 16); | 42566 | let chunk = (row / 16, col / 16); |
| 42318 | let done = pos + 1 == order.len() | 42567 | let done = pos + 1 == order.len() |
| 42319 | - || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16) | 42568 | + || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16) != chunk; |
| 42320 | - != chunk; | ||
| 42321 | if !done { | 42569 | if !done { |
| 42322 | continue; | 42570 | continue; |
| 42323 | } | 42571 | } |
| @@ -44693,6 +44941,7 @@ fn decode_intra_sub8_leaf( | |||
| 44693 | 0, | 44941 | 0, |
| 44694 | dc_sign_ctx(around.2), | 44942 | dc_sign_ctx(around.2), |
| 44695 | TxType::DctDct, | 44943 | TxType::DctDct, |
| 44944 | + 0, | ||
| 44696 | )?; | 44945 | )?; |
| 44697 | let residual = dequant_and_inverse_typed_wh( | 44946 | let residual = dequant_and_inverse_typed_wh( |
| 44698 | &levels, | 44947 | &levels, |
| @@ -45078,6 +45327,7 @@ fn decode_intra_sub8_leaf( | |||
| 45078 | skip_ctx, | 45327 | skip_ctx, |
| 45079 | dc_sign_ctx(around.2), | 45328 | dc_sign_ctx(around.2), |
| 45080 | uv_tx, | 45329 | uv_tx, |
| 45330 | + plane, | ||
| 45081 | )?; | 45331 | )?; |
| 45082 | let residual = dequant_and_inverse_typed_wh( | 45332 | let residual = dequant_and_inverse_typed_wh( |
| 45083 | &levels, | 45333 | &levels, |
| @@ -52761,6 +53011,46 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 52761 | 53011 | ||
| 52762 | #[cfg(test)] | 53012 | #[cfg(test)] |
| 52763 | mod tests { | 53013 | mod tests { |
| 53014 | + /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's | ||
| 53015 | + /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and | ||
| 53016 | + /// reports "no leaf there" as `None` so the caller can fall back to the | ||
| 53017 | + /// block-level type. Both halves are load-bearing: the 128 mu-chunk tail, | ||
| 53018 | + /// the 4:4:4 four-unit arms and `read_inter_rect_chroma` all read the | ||
| 53019 | + /// `None` arm as "this block coded a single luma unit". | ||
| 53020 | + #[test] | ||
| 53021 | + fn covering_leaf_tx_type_picks_the_leaf_under_the_unit_or_reports_none() { | ||
| 53022 | + use TxType::*; | ||
| 53023 | + // A 32x64 strip's five-leaf tree, in decode order: one 32x32 leaf | ||
| 53024 | + // over mi rows 0..8, then 16x16 leaves. (row, col) are MI relative | ||
| 53025 | + // to the block, (tw, th) are PIXELS, MI == 4. | ||
| 53026 | + let leaves = [ | ||
| 53027 | + (0usize, 0usize, 32usize, 32usize, Idtx), | ||
| 53028 | + (8, 0, 16, 16, VDct), | ||
| 53029 | + (8, 4, 16, 16, DctDct), | ||
| 53030 | + (12, 0, 16, 16, HDct), | ||
| 53031 | + (12, 4, 16, 16, VDct), | ||
| 53032 | + ]; | ||
| 53033 | + // The TOP chroma unit (its own mi cell (0,0)) sits over the 32x32 | ||
| 53034 | + // leaf; the LOWER one (mi (8,0)) over the first 16x16 leaf. The | ||
| 53035 | + // block-level type is the first leaf's, so only the second read | ||
| 53036 | + // differs -- exactly the condition the gate's DIFF counter counts. | ||
| 53037 | + assert_eq!(covering_leaf_tx_type(&leaves, (0, 0)), Some(Idtx)); | ||
| 53038 | + assert_eq!(covering_leaf_tx_type(&leaves, (8, 0)), Some(VDct)); | ||
| 53039 | + // Interior cells resolve the same leaf as the cell's top-left: the | ||
| 53040 | + // lookup is a rectangle containment test, not a raster position. | ||
| 53041 | + assert_eq!(covering_leaf_tx_type(&leaves, (11, 3)), Some(VDct)); | ||
| 53042 | + assert_eq!(covering_leaf_tx_type(&leaves, (12, 4)), Some(VDct)); | ||
| 53043 | + // The bottom-right corner of the last leaf, and the mi cell just | ||
| 53044 | + // past the block's own extent, must not fall into a neighbour. | ||
| 53045 | + assert_eq!(covering_leaf_tx_type(&leaves, (15, 7)), Some(VDct)); | ||
| 53046 | + assert_eq!(covering_leaf_tx_type(&leaves, (16, 0)), None); | ||
| 53047 | + assert_eq!(covering_leaf_tx_type(&leaves, (0, 8)), None); | ||
| 53048 | + // A block with no var-tx tree (one coded luma unit) has no leaves at | ||
| 53049 | + // all: the caller's block-level fallback is the answer, and the | ||
| 53050 | + // resolver must say so rather than guess. | ||
| 53051 | + assert_eq!(covering_leaf_tx_type(&[], (0, 0)), None); | ||
| 53052 | + } | ||
| 53053 | + | ||
| 52764 | /// lane-av1422warp r33: the OBMC pair-merge snap must move the READ to | 53054 | /// lane-av1422warp r33: the OBMC pair-merge snap must move the READ to |
| 52765 | /// libaom's position, not the reported offset. | 53055 | /// libaom's position, not the reported offset. |
| 52766 | /// | 53056 | /// |
crates/ec-av1/src/stream.rsmodified+238 -1
| @@ -1837,6 +1837,10 @@ fn decode_frame( | |||
| 1837 | // 4:2:0 one never inherits the wrong plane count. | 1837 | // 4:2:0 one never inherits the wrong plane count. |
| 1838 | crate::decode::set_mono(seq.mono_chrome, fctx); | 1838 | crate::decode::set_mono(seq.mono_chrome, fctx); |
| 1839 | crate::decode::set_subsampling(seq.subsampling_x, seq.subsampling_y, fctx); | 1839 | crate::decode::set_subsampling(seq.subsampling_x, seq.subsampling_y, fctx); |
| 1840 | + // lane-av1readcensus: the 4:4:4 coefficient-unit census is armed here, | ||
| 1841 | + // off the same sequence-header subsampling -- at 4:2:0/4:2:2 every census | ||
| 1842 | + // counter reads zero, so a 4:2:0 control can assert exactly that. | ||
| 1843 | + crate::decode::set_census_444(seq.subsampling_x, seq.subsampling_y); | ||
| 1840 | // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it | 1844 | // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it |
| 1841 | // codes every tile symbol against the CDFs it started with, so the tile | 1845 | // codes every tile symbol against the CDFs it started with, so the tile |
| 1842 | // readers must not adapt (libaom `decodeframe.c:2909`: | 1846 | // readers must not adapt (libaom `decodeframe.c:2909`: |
| @@ -19270,6 +19274,240 @@ pub(crate) mod tests { | |||
| 19270 | ); | 19274 | ); |
| 19271 | } | 19275 | } |
| 19272 | 19276 | ||
| 19277 | + /// lane-av1chrtx: the SIBLING of lane-av1444chr's four-unit arm -- a RECT | ||
| 19278 | + /// inter block's chroma plane, read by `read_inter_rect_chroma`. That | ||
| 19279 | + /// helper was left handing every unit the block-level `luma_tx_type` | ||
| 19280 | + /// (the top-left leaf's type) after the four-unit arms were pointed at | ||
| 19281 | + /// `covering_leaf_tx_type`, so a rect block whose chroma plane splits | ||
| 19282 | + /// (`nx*ny > 1`) over MIXED var-tx leaves read the wrong type per unit. | ||
| 19283 | + /// | ||
| 19284 | + /// The witness is pinned into `fixtures/`: `testsrc2 256x256` yuv444p 3 | ||
| 19285 | + /// frames, aomenc `--profile=1 --cq-level=30 --cpu-used=0 --sb-size=64 | ||
| 19286 | + /// --min-partition-size=32 --max-partition-size=64 --enable-tx-size-search=1 | ||
| 19287 | + /// --passes=1 --end-usage=q --threads=1 --row-mt=0 --lag-in-frames=0 | ||
| 19288 | + /// --kf-max-dist=100 --limit=3 --obu`; 26839 bytes, sha256 | ||
| 19289 | + /// `06174a66e92aaeb751a8e86db59711fcb1f18d74bde2d77e1ef1be7983eb7c80`. | ||
| 19290 | + /// Its one qualifying block is the 32x64 inter strip at mi(32,48): a | ||
| 19291 | + /// 4:4:4 chroma plane of (32,64) = TWO TX_32X32 units, over a luma tree | ||
| 19292 | + /// of five leaves -- `Idtx` (32x32) on top, then `VDct`/`DctDct`/`HDct`/ | ||
| 19293 | + /// `VDct` 16x16 leaves. The lower chroma unit therefore inherits `VDct` | ||
| 19294 | + /// where the block-level value is `Idtx`. | ||
| 19295 | + /// | ||
| 19296 | + /// Getting a witness at all took a bounded hunt (200+ encodes): `multi` | ||
| 19297 | + /// is false by construction at 4:2:0 (a `side <= 64` block's chroma plane | ||
| 19298 | + /// is at most 32x32 = one unit), so the arm needs 4:4:4 AND a rect block | ||
| 19299 | + /// that keeps a 64-px axis, AND `--cpu-used=0` with `--min-partition-size=32` | ||
| 19300 | + /// to make aomenc actually pick the 32x64 strip. | ||
| 19301 | + /// | ||
| 19302 | + /// The non-vacuity bar is the DIFFERS counter, not the route counter: the | ||
| 19303 | + /// control below is a committed 4:4:4 rect stream where the route fires | ||
| 19304 | + /// and still changes nothing, because that block's leaves agree. | ||
| 19305 | + #[test] | ||
| 19306 | + fn a_pinned_444_rect_inter_stream_resolves_each_chroma_unit_from_its_own_luma_leaf() { | ||
| 19307 | + const NAME: &str = | ||
| 19308 | + "a_pinned_444_rect_inter_stream_resolves_each_chroma_unit_from_its_own_luma_leaf"; | ||
| 19309 | + const FIXTURE_LEN: usize = 26839; | ||
| 19310 | + const FIXTURE_FNV: u64 = 0xc77f_310c_036d_ff73; | ||
| 19311 | + let _gate_lock = lock_gate_counters(); | ||
| 19312 | + if !have_aomenc() { | ||
| 19313 | + eprintln!( | ||
| 19314 | + "SKIP {NAME}: no aomenc/aomdec oracle at {}", | ||
| 19315 | + aomenc_path().display() | ||
| 19316 | + ); | ||
| 19317 | + return; | ||
| 19318 | + } | ||
| 19319 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19320 | + .join("fixtures/444_rect_strip_leaf_tx_type.obu"); | ||
| 19321 | + let stream = std::fs::read(&path) | ||
| 19322 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 19323 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | ||
| 19324 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | ||
| 19325 | + | ||
| 19326 | + let hits0 = crate::decode::chroma_rect_leaf_tx_hits(); | ||
| 19327 | + let diff0 = crate::decode::chroma_rect_leaf_tx_diff_hits(); | ||
| 19328 | + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, NAME); | ||
| 19329 | + let hits = crate::decode::chroma_rect_leaf_tx_hits() - hits0; | ||
| 19330 | + let diff = crate::decode::chroma_rect_leaf_tx_diff_hits() - diff0; | ||
| 19331 | + assert_eq!( | ||
| 19332 | + frames, 3, | ||
| 19333 | + "{NAME}: expected 3 decode-order frames ({hidden} hidden)" | ||
| 19334 | + ); | ||
| 19335 | + assert!( | ||
| 19336 | + hits >= 2 * diff && hits > 0, | ||
| 19337 | + "{NAME}: no rect chroma unit took its type from the covering luma leaf (hits {hits}, \ | ||
| 19338 | + differs {diff}) -- the corrected route never ran" | ||
| 19339 | + ); | ||
| 19340 | + assert!( | ||
| 19341 | + diff >= 2, | ||
| 19342 | + "{NAME}: the per-unit resolve never CHANGED an answer (diff {diff}; measured 2 on this \ | ||
| 19343 | + stream, one per chroma plane). A route counter alone is not a witness: the control \ | ||
| 19344 | + below fires it and changes nothing." | ||
| 19345 | + ); | ||
| 19346 | + eprintln!( | ||
| 19347 | + "{NAME}: rect chroma units resolved from their own leaf {hits}, of which {diff} differed" | ||
| 19348 | + ); | ||
| 19349 | + | ||
| 19350 | + // Control: a committed 4:4:4 rect stream where the SAME route fires | ||
| 19351 | + // and every resolved type equals the block-level one -- the shape a | ||
| 19352 | + // no-op fix would also be green on. | ||
| 19353 | + let control = std::fs::read( | ||
| 19354 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19355 | + .join("fixtures/444_sb128rect_lr_witness.obu"), | ||
| 19356 | + ) | ||
| 19357 | + .unwrap_or_else(|e| panic!("{NAME}: reading the rect-strip control: {e}")); | ||
| 19358 | + let c_hits0 = crate::decode::chroma_rect_leaf_tx_hits(); | ||
| 19359 | + let c_diff0 = crate::decode::chroma_rect_leaf_tx_diff_hits(); | ||
| 19360 | + let c_frames = decode_stream(&control) | ||
| 19361 | + .unwrap_or_else(|e| panic!("{NAME}: the rect-strip control no longer decodes: {e}")) | ||
| 19362 | + .len(); | ||
| 19363 | + let c_hits = crate::decode::chroma_rect_leaf_tx_hits() - c_hits0; | ||
| 19364 | + let c_diff = crate::decode::chroma_rect_leaf_tx_diff_hits() - c_diff0; | ||
| 19365 | + assert!( | ||
| 19366 | + c_frames > 0, | ||
| 19367 | + "{NAME}: the rect-strip control decoded no frames" | ||
| 19368 | + ); | ||
| 19369 | + assert!( | ||
| 19370 | + c_hits > 0 && c_diff == 0, | ||
| 19371 | + "{NAME}: the rect-strip control fired the route {c_hits} times with {c_diff} differing \ | ||
| 19372 | + types -- expected the single-unit/same-type shape (route fires, nothing changes)" | ||
| 19373 | + ); | ||
| 19374 | + } | ||
| 19375 | + | ||
| 19376 | + /// lane-av1readcensus: the 4:4:4 coefficient-UNIT census, pinned. | ||
| 19377 | + /// | ||
| 19378 | + /// The lane report `av1444rect` round 4 left an unexplained signal: 636 | ||
| 19379 | + /// square chroma reads against the oracle's 1086, and 2052 luma reads | ||
| 19380 | + /// against its 1309, recorded as "most likely a counting-shape difference" | ||
| 19381 | + /// with no evidence either way. This gate is that evidence. | ||
| 19382 | + /// | ||
| 19383 | + /// Measured on this arm (`ll444_minp8_inter`, pixel-exact against aomdec | ||
| 19384 | + /// on every plane of every frame -- see | ||
| 19385 | + /// `a_lossless_444_min_partition8_inter_stream_decodes_sample_exact`), | ||
| 19386 | + /// pairing each of our 11292 walked units with the oracle's | ||
| 19387 | + /// `av1_read_coeffs_txb` call BY `post_rng` (the msac state after the | ||
| 19388 | + /// unit) rather than by plane label or walk position: EVERY unit pairs, | ||
| 19389 | + /// and no unit's plane, shape, eob or all-zero flag differs. The per-plane | ||
| 19390 | + /// split is equal too -- 3764 units per plane on both sides, of which | ||
| 19391 | + /// 975 / 1793 / 1859 coded coefficients. So on a pixel-exact arm there is | ||
| 19392 | + /// no asymmetry to explain at all; the round-4 numbers came from | ||
| 19393 | + /// `444_intrabc_rect4_witness`, an arm that DIVERGES (390380 of 921600 | ||
| 19394 | + /// samples wrong), where our surplus is the divergence itself. | ||
| 19395 | + /// | ||
| 19396 | + /// What this gate pins is the walk's OBJECT SHAPE on the pixel-exact arm: | ||
| 19397 | + /// a change to the number or plane split of coefficient units this decoder | ||
| 19398 | + /// walks shows up here as an intentional diff, not as the next lane's | ||
| 19399 | + /// mystery signal. The 4:2:0 control asserts the census is inert there. | ||
| 19400 | + #[test] | ||
| 19401 | + fn a_pixel_exact_444_stream_walks_the_same_coefficient_units_the_oracle_does() { | ||
| 19402 | + const NAME: &str = | ||
| 19403 | + "a_pixel_exact_444_stream_walks_the_same_coefficient_units_the_oracle_does"; | ||
| 19404 | + const FIXTURE_LEN: usize = 34037; | ||
| 19405 | + const FIXTURE_FNV: u64 = 0x2c8f_4a2c_c025_52da; | ||
| 19406 | + let _gate_lock = lock_gate_counters(); | ||
| 19407 | + if !have_aomenc() { | ||
| 19408 | + eprintln!( | ||
| 19409 | + "SKIP {NAME}: no aomenc/aomdec oracle at {}", | ||
| 19410 | + aomenc_path().display() | ||
| 19411 | + ); | ||
| 19412 | + return; | ||
| 19413 | + } | ||
| 19414 | + let path = | ||
| 19415 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/ll444_minp8_inter.obu"); | ||
| 19416 | + let stream = std::fs::read(&path) | ||
| 19417 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 19418 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | ||
| 19419 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | ||
| 19420 | + let delta = |now: [usize; 3], before: [usize; 3]| { | ||
| 19421 | + [now[0] - before[0], now[1] - before[1], now[2] - before[2]] | ||
| 19422 | + }; | ||
| 19423 | + | ||
| 19424 | + let u0 = crate::decode::census_444_units(); | ||
| 19425 | + let c0 = crate::decode::census_444_coded(); | ||
| 19426 | + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, NAME); | ||
| 19427 | + assert_eq!( | ||
| 19428 | + frames + hidden, | ||
| 19429 | + 8, | ||
| 19430 | + "{NAME}: expected 8 decode-order frames (6 shown + 2 hidden)" | ||
| 19431 | + ); | ||
| 19432 | + let walked = delta(crate::decode::census_444_units(), u0); | ||
| 19433 | + let coded = delta(crate::decode::census_444_coded(), c0); | ||
| 19434 | + | ||
| 19435 | + // The oracle's own census on the same stream, paired by post_rng: | ||
| 19436 | + // 3764 units per plane, 975 / 1793 / 1859 of them coded. | ||
| 19437 | + assert_eq!( | ||
| 19438 | + walked, | ||
| 19439 | + [3764, 3764, 3764], | ||
| 19440 | + "{NAME}: the 4:4:4 unit walk changed -- {walked:?} against the oracle's \ | ||
| 19441 | + [3764, 3764, 3764] (measured by post_rng pairing, every unit matching). A change \ | ||
| 19442 | + here is a WALK-SHAPE change: re-measure against aomdec before assuming it is a bug" | ||
| 19443 | + ); | ||
| 19444 | + assert_eq!( | ||
| 19445 | + coded, | ||
| 19446 | + [975, 1793, 1859], | ||
| 19447 | + "{NAME}: the coded-unit split changed -- {coded:?} against the oracle's [975, 1793, 1859]" | ||
| 19448 | + ); | ||
| 19449 | + assert!( | ||
| 19450 | + walked.iter().all(|&v| v > 0) && coded.iter().all(|&v| v > 0), | ||
| 19451 | + "{NAME}: an all-zero plane split means the census did not run, not that the walk is empty" | ||
| 19452 | + ); | ||
| 19453 | + | ||
| 19454 | + // A SECOND pixel-exact arm, with a MIXED unit-shape mix -- the pinned | ||
| 19455 | + // lossless stream above is all TX_4X4 (min-partition-8), so on its own | ||
| 19456 | + // it would not notice a var-tx walk that started folding 8x8/4x8 | ||
| 19457 | + // leaves. This one walks 4x4/8x8/8x4/4x8/4x16/16x4/8x16/16x16, and | ||
| 19458 | + // the oracle's census on it pairs unit-for-unit by post_rng with no | ||
| 19459 | + // shape, plane, eob or all-zero difference: 1373 units, 629 luma and | ||
| 19460 | + // 372 per chroma plane, of which 130 / 253 / 278 coded. | ||
| 19461 | + let path2 = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19462 | + .join("fixtures/444_lossy_rect4_inter_witness.obu"); | ||
| 19463 | + let stream2 = std::fs::read(&path2) | ||
| 19464 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path2.display())); | ||
| 19465 | + let m0 = crate::decode::census_444_units(); | ||
| 19466 | + let mc0 = crate::decode::census_444_coded(); | ||
| 19467 | + let (frames2, hidden2) = decode_all_frames_vs_oracle(&stream2, NAME); | ||
| 19468 | + assert!( | ||
| 19469 | + frames2 + hidden2 > 0, | ||
| 19470 | + "{NAME}: the mixed-shape 4:4:4 arm decoded no frames" | ||
| 19471 | + ); | ||
| 19472 | + let walked2 = delta(crate::decode::census_444_units(), m0); | ||
| 19473 | + let coded2 = delta(crate::decode::census_444_coded(), mc0); | ||
| 19474 | + assert_eq!( | ||
| 19475 | + walked2, | ||
| 19476 | + [629, 372, 372], | ||
| 19477 | + "{NAME}: the mixed-shape 4:4:4 walk changed -- {walked2:?} against the oracle's \ | ||
| 19478 | + [629, 372, 372]. The all-4x4 arm above cannot see a var-tx fold; this one can" | ||
| 19479 | + ); | ||
| 19480 | + assert_eq!( | ||
| 19481 | + coded2, | ||
| 19482 | + [130, 253, 278], | ||
| 19483 | + "{NAME}: the mixed-shape coded-unit split changed -- {coded2:?} against the oracle's \ | ||
| 19484 | + [130, 253, 278]" | ||
| 19485 | + ); | ||
| 19486 | + | ||
| 19487 | + // 4:2:0 control: the census is a 4:4:4 question and must not fire. | ||
| 19488 | + let control = std::fs::read( | ||
| 19489 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19490 | + .join("fixtures/av1_192x128_8bit_intra64_in_inter.obu"), | ||
| 19491 | + ) | ||
| 19492 | + .unwrap_or_else(|e| panic!("{NAME}: reading the 4:2:0 control: {e}")); | ||
| 19493 | + let k0 = crate::decode::census_444_units(); | ||
| 19494 | + let kc0 = crate::decode::census_444_coded(); | ||
| 19495 | + let k_frames = decode_stream(&control) | ||
| 19496 | + .unwrap_or_else(|e| panic!("{NAME}: the 4:2:0 control no longer decodes: {e}")) | ||
| 19497 | + .len(); | ||
| 19498 | + assert!(k_frames > 0, "{NAME}: the 4:2:0 control decoded no frames"); | ||
| 19499 | + assert_eq!( | ||
| 19500 | + delta(crate::decode::census_444_units(), k0), | ||
| 19501 | + [0, 0, 0], | ||
| 19502 | + "{NAME}: the 4:4:4 census fired on the 4:2:0 control" | ||
| 19503 | + ); | ||
| 19504 | + assert_eq!( | ||
| 19505 | + delta(crate::decode::census_444_coded(), kc0), | ||
| 19506 | + [0, 0, 0], | ||
| 19507 | + "{NAME}: the 4:4:4 coded-unit census fired on the 4:2:0 control" | ||
| 19508 | + ); | ||
| 19509 | + } | ||
| 19510 | + | ||
| 19273 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` | 19511 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` |
| 19274 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 | 19512 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 |
| 19275 | /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs | 19513 | /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs |
| @@ -39529,7 +39767,6 @@ pub(crate) mod tests { | |||
| 39529 | "{NAME}: no attempt decoded a depth-1 1:4 split strip -- the recipe no longer \ | 39767 | "{NAME}: no attempt decoded a depth-1 1:4 split strip -- the recipe no longer \ |
| 39530 | covers the shape this round fixed" | 39768 | covers the shape this round fixed" |
| 39531 | ); | 39769 | ); |
| 39532 | - eprintln!("{NAME}: {depth1_decoded} depth-1 1:4 split strips decoded pixel-exact"); | ||
| 39533 | } | 39770 | } |
| 39534 | 39771 | ||
| 39535 | /// The chroma-rect gate's fixture + aomenc recipe for one attempt, shared | 39772 | /// The chroma-rect gate's fixture + aomenc recipe for one attempt, shared |
lanes/av1chrtx.report.mdadded+187 -0
| @@ -0,0 +1,187 @@ | |||
| 1 | +# lane-av1chrtx — rect inter chroma per-unit tx_type (H1) + rect coeff-trace plane tag (H2) | ||
| 2 | + | ||
| 3 | +Branch `lane-av1chrtx` (worktree `~/.cache/wt/av1chrtx`), base `a21f3680`. | ||
| 4 | +Oracle `~/.cache/aom-oracle/build/{aomdec,aomenc}` (instrumented). | ||
| 5 | +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1chrtx`. | ||
| 6 | + | ||
| 7 | +Commits: `d791c464` (H2), `2142d2cf` (H1) — one per defect, as chartered. | ||
| 8 | + | ||
| 9 | +--- | ||
| 10 | + | ||
| 11 | +## H1 — FIXED. `read_inter_rect_chroma` handed every chroma unit the BLOCK-level `tx_type` | ||
| 12 | + | ||
| 13 | +### The defect | ||
| 14 | + | ||
| 15 | +`read_inter_rect_chroma` is the sibling of the two 4:4:4 four-unit arms. | ||
| 16 | +lane-av1444chr extracted `covering_leaf_tx_type` and re-pointed both | ||
| 17 | +four-unit arms at it, but left this sibling passing the block-level | ||
| 18 | +`luma_tx_type` (the top-left leaf's type) to **every** unit of the plane: | ||
| 19 | + | ||
| 20 | +```rust | ||
| 21 | +let inherit_tx_type = Some(luma_tx_type); // before | ||
| 22 | +``` | ||
| 23 | + | ||
| 24 | +`av1_get_tx_type` (`blockd.h:1287-1297`) reads `xd->tx_type_map` at the | ||
| 25 | +chroma unit's own position scaled back to luma, and `read_coeffs`'s | ||
| 26 | +`all_zero` arm stamps `DCT_DCT` into that leaf's map cell | ||
| 27 | +(`decodetxb.c:199-203`) — so a unit sitting over a luma leaf that coded | ||
| 28 | +**nothing** inherits `DctDct`, not the block-level type. With | ||
| 29 | +`nx*ny > 1` over mixed var-tx leaves that is a per-unit wrong answer. | ||
| 30 | + | ||
| 31 | +### The witness hunt (bounded, then found) | ||
| 32 | + | ||
| 33 | +lane-av1444chr's report recorded the route as unreachable on five | ||
| 34 | +4:4:4 rect recipes (`multi` = 0 on every one). Two facts explain why, | ||
| 35 | +and they shape the hunt: | ||
| 36 | + | ||
| 37 | +1. **`multi` is false by construction at 4:2:0.** The arm is only reached | ||
| 38 | + for `side <= 64` blocks (the `side > 64` mu-chunk path runs first), and | ||
| 39 | + a `side <= 64` block's 4:2:0 chroma plane is at most 32x32 — exactly | ||
| 40 | + one `uw x uh` unit, so `nx*ny == 1` always. The earlier hunt's | ||
| 41 | + recipes were 4:4:4 but used partition settings that never produced a | ||
| 42 | + block keeping a 64-px axis. | ||
| 43 | +2. So the arm needs **4:4:4 AND a rect block with a 64-px luma axis** | ||
| 44 | + (32x64 / 64x32 / 64x16 / 16x64) — a 4:4:4 chroma plane then exceeds | ||
| 45 | + the 32 cap on one axis and splits. | ||
| 46 | + | ||
| 47 | +Hunt: 200+ encodes, three 4:4:4 sources (testsrc2 128/192/256, mandelbrot | ||
| 48 | +128/256, testsrc2 192x256), swept over `--min-partition-size` 8/16/32, | ||
| 49 | +`--max-partition-size` 32/64/128, `--enable-tx-size-search` 0/1, | ||
| 50 | +`--enable-rect-partitions`, `cq-level` 18-44, `--cpu-used` 0/2/3/5/7, | ||
| 51 | +sizes 128x128 through 256x256. Instrumented with a temporary | ||
| 52 | +`EC_AV1_CHRTX_PROBE` eprintln in the arm printing `(nx, ny, multi, leaves)` | ||
| 53 | +(removed before the commit). | ||
| 54 | + | ||
| 55 | +Result: the arm's `multi` is 0 on every 4:2:0 recipe and on every 4:4:4 | ||
| 56 | +recipe whose rect strips keep a 32-px axis. It first fires with | ||
| 57 | +**`--cpu-used=0 --min-partition-size=32 --max-partition-size=64` on a | ||
| 58 | +256x256 source** — the slow encoder is what actually picks a 32x64 strip | ||
| 59 | +over two 32x32 blocks. | ||
| 60 | + | ||
| 61 | +### The witness (pinned) | ||
| 62 | + | ||
| 63 | +`crates/ec-av1/fixtures/444_rect_strip_leaf_tx_type.obu`, 26839 bytes, | ||
| 64 | +sha256 `06174a66e92aaeb751a8e86db59711fcb1f18d74bde2d77e1ef1be7983eb7c80`, | ||
| 65 | +fnv1a64 `0xc77f310c036dff73`. | ||
| 66 | + | ||
| 67 | +``` | ||
| 68 | +ffmpeg -f lavfi -i "testsrc2=size=256x256:rate=25" -frames:v 3 -pix_fmt yuv444p \ | ||
| 69 | + -f yuv4mpegpipe ts256.y4m | ||
| 70 | +aomenc --codec=av1 --profile=1 --cq-level=30 --cpu-used=0 --sb-size=64 \ | ||
| 71 | + --min-partition-size=32 --max-partition-size=64 --enable-tx-size-search=1 \ | ||
| 72 | + --passes=1 --end-usage=q --threads=1 --row-mt=0 --lag-in-frames=0 \ | ||
| 73 | + --kf-max-dist=100 --limit=3 --obu -o w.obu ts256.y4m | ||
| 74 | +``` | ||
| 75 | + | ||
| 76 | +The qualifying block is the **32x64 inter strip at mi(32,48)**: | ||
| 77 | +a 4:4:4 chroma plane of `(32, 64)` = **two** TX_32X32 units, over a | ||
| 78 | +five-leaf luma tree | ||
| 79 | + | ||
| 80 | +| leaf (row, col, tw, th, tx_type) | covering mi rows | | ||
| 81 | +|---|---| | ||
| 82 | +| `(0, 0, 32, 32, Idtx)` | 0..8 | | ||
| 83 | +| `(8, 0, 16, 16, VDct)` | 8..12 | | ||
| 84 | +| `(8, 4, 16, 16, DctDct)` | 8..12 | | ||
| 85 | +| `(12, 0, 16, 16, HDct)` | 12..16 | | ||
| 86 | +| `(12, 4, 16, 16, VDct)` | 12..16 | | ||
| 87 | + | ||
| 88 | +The **lower** chroma unit (its own mi cell `(8, 0)`) therefore resolves | ||
| 89 | +`VDct` where the block-level value is `Idtx` — once per chroma plane, so | ||
| 90 | +`diff = 2`. The upper unit resolves `Idtx`, i.e. the same as the | ||
| 91 | +block-level value: the defect is strictly per-unit. | ||
| 92 | + | ||
| 93 | +### The fix | ||
| 94 | + | ||
| 95 | +- `read_inter_rect_chroma` takes the block's `leaf_tx_types` and resolves | ||
| 96 | + `inherit_tx_type` **per unit** through the shared | ||
| 97 | + `covering_leaf_tx_type(leaf_tx_types, unit_rel_mi)`, with | ||
| 98 | + `.unwrap_or(luma_tx_type)` as the fallback for a block that coded a | ||
| 99 | + single luma unit (no vartx tree, so `leaves` is empty). Both call sites | ||
| 100 | + (the compound and single-reference copies of `decode_inter_block`) | ||
| 101 | + pass their `&leaf_tx_types` — the same list the four-unit arms read. | ||
| 102 | +- Two new gate counters, `CHROMA_RECT_LEAF_TX_HITS` / | ||
| 103 | + `CHROMA_RECT_LEAF_TX_DIFF_HITS`, deliberately **separate** from | ||
| 104 | + `CHROMA_QUAD_LEAF_TX_HITS` / `_DIFF_HITS`: the latter pair gates a | ||
| 105 | + 4:2:0 control asserting exactly `(0, 0)`, and this route **is** | ||
| 106 | + reachable at 4:2:0, so sharing the counter would destroy that | ||
| 107 | + control's meaning. | ||
| 108 | + | ||
| 109 | +### Bar | ||
| 110 | + | ||
| 111 | +- **Red-before by mutation** (revert only the resolve to the block-level | ||
| 112 | + type; everything else intact): | ||
| 113 | + `decode-order frame 1 of 3 (3 shown, 0 hidden) differs from the oracle | ||
| 114 | + at byte 105949 (ours 166 vs 167), 1998 bytes differ`. | ||
| 115 | + Restored: green. (A first mutation attempt used `.or(None::<TxType>)`, | ||
| 116 | + which is the identity on `Option` and therefore did **not** bite — the | ||
| 117 | + red run above uses `.and(None::<TxType>)`, the real removal.) | ||
| 118 | +- **New gate** `stream::tests::a_pinned_444_rect_inter_stream_resolves_each_chroma_unit_from_its_own_luma_leaf`: | ||
| 119 | + fixture length + fnv pinned, `decode_all_frames_vs_oracle` (length- | ||
| 120 | + asserting, byte-exact, 3 frames, 0 hidden), asserts `hits >= 2*diff && | ||
| 121 | + hits > 0` and **`diff >= 2`**. | ||
| 122 | + Measured: `rect chroma units resolved from their own leaf 4, of which 2 differed`. | ||
| 123 | +- **In-gate control**: the committed | ||
| 124 | + `fixtures/444_sb128rect_lr_witness.obu` fires the same route (2 units | ||
| 125 | + resolved) with **0** differing types — the exact shape a no-op fix | ||
| 126 | + looks green on, which is why the DIFF counter and not the route counter | ||
| 127 | + is the non-vacuity bar. | ||
| 128 | +- **Resolver unit test** `decode::tests::covering_leaf_tx_type_picks_the_leaf_under_the_unit_or_reports_none`: | ||
| 129 | + mixed-leaf lookup on the witness's own five-leaf tree, interior cells | ||
| 130 | + (containment, not raster position), the mi cell just past the block's | ||
| 131 | + extent → `None`, and the empty leaf list → `None`. | ||
| 132 | + Mutation-proven red: turning the containment `<` into `<=` → | ||
| 133 | + `panicked at crates/ec-av1/src/decode.rs:52883, left: Some(Idtx), right: Some(VDct)`. | ||
| 134 | + Restored: green. | ||
| 135 | +- **Identity green** (13 tests, one binary, `--test-threads=4`, no SKIP | ||
| 136 | + lines): the new gate, the resolver unit test, the av1444chr gate | ||
| 137 | + (`quad-resolved chroma units 96, of which 8 differed` — unchanged), plus | ||
| 138 | + `a_444_lossy_rect4_inter_stream_decodes_pixel_exact`, | ||
| 139 | + `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`, | ||
| 140 | + `a_lossless_444_defaultp_inter_strip_stream_decodes_byte_exact`, | ||
| 141 | + `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact`, | ||
| 142 | + `a_lossless_444_min_partition8_inter_stream_decodes_sample_exact`, | ||
| 143 | + `a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact`, | ||
| 144 | + `a_real_aomenc_rect_strip_palette_decodes_pixel_exact`, | ||
| 145 | + `a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact`, | ||
| 146 | + `a_444_intrabc_rect4_reads_its_own_chroma_plane_block`, | ||
| 147 | + `a_lossless_444_rect16x4_chroma_reach_is_ss_aware` — **13 passed, 0 failed**. | ||
| 148 | + | ||
| 149 | +--- | ||
| 150 | + | ||
| 151 | +## H2 — FIXED. `read_coeffs_rect`'s `EC_COEFF_STEP` traces hardcoded `plane=0` | ||
| 152 | + | ||
| 153 | +`read_coeffs_rect` printed `plane=0` on both tagged lines | ||
| 154 | +(`tag=all_zero`, `tag=tx_type`), so every **chroma** rect coefficient | ||
| 155 | +read was logged as a luma one. Two independent lane reports mis-read a | ||
| 156 | +chroma unit's `txb_skip` / `tx_type` symbol on those lines and followed | ||
| 157 | +the luma arm — the log could not tell them apart. | ||
| 158 | + | ||
| 159 | +Fix: a `plane: usize` parameter on `read_coeffs_rect`, with each of the | ||
| 160 | +twenty call sites passing its own plane (`0` for the luma readers, | ||
| 161 | +`plane_idx` / `plane` where the enclosing reader already has one). | ||
| 162 | +`read_chroma_coeffs_rect` takes the same parameter and passes it | ||
| 163 | +through, so the U and V call sites in `decode_block_rect`, | ||
| 164 | +`decode_leaf_rect`, `decode_block_rect4`, `decode_rect4_16_strip` and | ||
| 165 | +`decode_block_rect64` stop collapsing into one tag. | ||
| 166 | + | ||
| 167 | +**Measurement** (`EC_TRACE_COEFF=1` on | ||
| 168 | +`a_444_lossy_rect4_inter_stream_decodes_pixel_exact`): | ||
| 169 | + | ||
| 170 | +| line | before | after | | ||
| 171 | +|---|---|---| | ||
| 172 | +| `tag=all_zero` | 932 lines, all `plane=0` | 312 `plane=0` / 310 `plane=1` / 310 `plane=2` | | ||
| 173 | +| `tag=tx_type` | 110 lines, all `plane=0` | 110 `plane=0` (this set's units are luma-only on this fixture) | | ||
| 174 | + | ||
| 175 | +No trace output changes in a default build: both lines are behind | ||
| 176 | +`coeff_trace_on()`, i.e. the env-gated `EC_TRACE_COEFF`. No gate output | ||
| 177 | +changes — the counter and assert set is untouched by this commit. | ||
| 178 | + | ||
| 179 | +--- | ||
| 180 | + | ||
| 181 | +## Not run here (Main's validation) | ||
| 182 | + | ||
| 183 | +Full crate suite, the multi-encode sweeps | ||
| 184 | +(`a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact` | ||
| 185 | +was run as a single named test only), the 4:2:0/10-bit/12-bit sweep | ||
| 186 | +families, and the server stages. Local runs were single named tests / one | ||
| 187 | +named-test batch, per the lane's local-scope rule. | ||
lanes/av1readcensus.report.mdadded+189 -0
| @@ -0,0 +1,189 @@ | |||
| 1 | +# lane-av1readcensus — the 4:4:4 coefficient-read count asymmetry, settled | ||
| 2 | + | ||
| 3 | +**Branch:** `lane-av1readcensus`, worktree `~/.cache/wt/av1readcensus`, stacked on | ||
| 4 | +`lane-av1chrtx` (`ff7cf47c`, whose `d791c464` threaded the real plane index into | ||
| 5 | +`read_coeffs_rect`'s traces — the census pairs on that). | ||
| 6 | + | ||
| 7 | +**Verdict: COUNTING SHAPE — and not even that. On every pixel-exact 4:4:4 arm | ||
| 8 | +there is no asymmetry at all: both sides walk the same number of units, in the | ||
| 9 | +same order, with the same plane, shape, eob and all-zero flag. The recorded | ||
| 10 | +636-vs-1086 / 2052-vs-1309 signal came from an arm that DIVERGES, where the | ||
| 11 | +surplus is the divergence itself, not a counting-shape difference.** | ||
| 12 | + | ||
| 13 | +## 1. The signal, and why the census was admissible only on a pixel-exact arm | ||
| 14 | + | ||
| 15 | +`av1444rect` round 4 recorded 636 square chroma reads against the oracle's 1086, | ||
| 16 | +and 2052 luma reads against its 1309, on `444_intrabc_rect4_witness`, and filed | ||
| 17 | +it as "most likely a counting-shape difference … it is NOT established either | ||
| 18 | +way". Two things had to be settled before counting anything: | ||
| 19 | + | ||
| 20 | +- the arm must be **pixel-exact**. On a diverging arm the counts are polluted by | ||
| 21 | + the divergence: a decoder reading the wrong coefficients also walks a different | ||
| 22 | + number of units, so the count difference is a *symptom*, and the count cannot | ||
| 23 | + distinguish cause from effect. Measured: `444_intrabc_rect4_witness` is wrong in | ||
| 24 | + 390380 of 921600 samples, and `444_leaf8_oob` in 281306 of 737280. | ||
| 25 | +- the pairing must not assume either side's own labels. | ||
| 26 | + | ||
| 27 | +Measured exactness of every 4:4:4 fixture in the crate (ours vs `aomdec | ||
| 28 | +--rawvideo`, plane-concatenated, u16→u8): | ||
| 29 | + | ||
| 30 | +| fixture | pixels | pixel-exact? | | ||
| 31 | +|---|---|---| | ||
| 32 | +| `ll444_minp8_inter` | 6 frames | **yes** | | ||
| 33 | +| `444_quad_leaf_tx_type` | 4 frames | **yes** | | ||
| 34 | +| `444_lossy_rect4_inter_witness` | 2 frames | **yes** | | ||
| 35 | +| `444_rect_strip_leaf_tx_type` | 3 frames | **yes** | | ||
| 36 | +| `444_sb128rect_lr_witness` | 3 frames | **yes** | | ||
| 37 | +| `444_intrabc_rect4_witness` | 1 frame | no (390380 / 921600 wrong) | | ||
| 38 | +| `444_leaf8_oob` | 3 frames | no (281306 / 737280 wrong) | | ||
| 39 | + | ||
| 40 | +## 2. Method — the census, both sides, same frame | ||
| 41 | + | ||
| 42 | +**Ours.** A new env-gated rung `EC_CENSUS_UNIT` (`EC_CENSUS_UNIT=1`), one line | ||
| 43 | +per coefficient unit **this decoder walks** — one per `read_coeffs` / | ||
| 44 | +`read_coeffs_rect` call, which is exactly the object the round-4 count measured. | ||
| 45 | +Fields: `n` (sequential index), `plane`, `w`, `h`, `tx`, `eob`, `all_zero`, | ||
| 46 | +`entry_rng` (msac `range` before the unit's `txb_skip` read), `post_rng` (after | ||
| 47 | +the unit). The plane comes from a thread-local stamped by the plane-owning | ||
| 48 | +readers (`read_plane`, `read_inter_plane`, `read_inter_plane_rect`) and by | ||
| 49 | +`read_coeffs_rect` from the real `plane` argument lane-av1chrtx already threads | ||
| 50 | +in — a thread-local rather than a `read_coeffs` parameter because the three | ||
| 51 | +luma-only call sites (`decode_rect_split`, `decode_block_rect64`, | ||
| 52 | +`read_inter_plane_rect`'s corner) belong to other lanes. | ||
| 53 | + | ||
| 54 | +**Oracle.** No rebuild needed: the instrumented aomdec already brackets every | ||
| 55 | +`av1_read_coeffs_txb` call with `EC_COEFF …rng=<pre>` on entry and | ||
| 56 | +`EC_COEFF_VAL …rng=<post>` on exit (`EC_TRACE_COEFF=1`), with | ||
| 57 | +`EC_COEFF_STEP tag=all_zero` / `tag=eob` inside the bracket. That is the same | ||
| 58 | +five fields. | ||
| 59 | + | ||
| 60 | +**Pairing: by `post_rng`, never by plane label and never by walk position or | ||
| 61 | +`n`.** `post_rng` is the msac state after the unit, so two units that consumed | ||
| 62 | +the same bits end at the same state. This matters concretely here: pairing by | ||
| 63 | +`n`/position invents matches the moment the two walks order a U and a V unit | ||
| 64 | +differently, and pairing by plane label invents them whenever a walk's plane | ||
| 65 | +attribution is what is in question. The walk is a two-pointer merge on `post_rng`; | ||
| 66 | +a unit is emitted only when the two sides agree on the pairing key. | ||
| 67 | + | ||
| 68 | +**Buckets** (each difference lands in exactly one): | ||
| 69 | + | ||
| 70 | +- **(i) SAME UNIT** — the two sides' units pair, and plane/shape/eob/all-zero agree. | ||
| 71 | +- **(ii) OUR-ONLY** — we walk a unit the oracle does not, at that bit position. | ||
| 72 | +- **(iii) ORACLE-ONLY** — the oracle walks one we do not. | ||
| 73 | +- **(iv) SIZE/ORDER** — the units pair but disagree on shape, plane label, eob | ||
| 74 | + or all-zero. | ||
| 75 | + | ||
| 76 | +## 3. Per-bucket table (whole stream, paired by `post_rng`) | ||
| 77 | + | ||
| 78 | +| arm | pixels | units ours / oracle | (i) | (ii) | (iii) | (iv) | | ||
| 79 | +|---|---|---|---|---|---|---| | ||
| 80 | +| `ll444_minp8_inter` (6 frames) | exact | **11292 / 11292** | **11292** | 0 | 0 | 0 | | ||
| 81 | +| `444_lossy_rect4_inter_witness` (mixed shapes) | exact | **1373 / 1373** | **1373** | 0 | 0 | 0 | | ||
| 82 | +| `444_quad_leaf_tx_type` | exact | **192 / 192** | **192** | 0 | 0 | 0 | | ||
| 83 | +| `444_rect_strip_leaf_tx_type` | exact | 591 / 591 | 587 | 0 | 0 | 4 | | ||
| 84 | +| `444_sb128rect_lr_witness` | exact | 467 / 467 | 463 | 0 | 0 | 4 | | ||
| 85 | +| `444_intrabc_rect4_witness` | **diverges** | 2740 / 2395 | 1909 | 823 | 478 | 8 | | ||
| 86 | +| `444_leaf8_oob` | **diverges** | 1778 / 1678 | 1027 | 751 | 651 | 0 | | ||
| 87 | + | ||
| 88 | +Per-plane split on the primary arm, both sides identical: | ||
| 89 | + | ||
| 90 | +| | luma | u | v | | ||
| 91 | +|---|---|---|---| | ||
| 92 | +| units (ours) | 3764 | 3764 | 3764 | | ||
| 93 | +| units (oracle) | 3764 | 3764 | 3764 | | ||
| 94 | +| of which coded (`txb_skip == 0`) | 975 | 1793 | 1859 | | ||
| 95 | + | ||
| 96 | +So the round-4 asymmetry does not survive on an arm whose pixels are right. | ||
| 97 | +Reproduced exactly on the diverging arm: `444_intrabc_rect4_witness` reads 1518 | ||
| 98 | +luma / 611 / 611 against the oracle's 1309 / 543 / 543 — the luma 1309 and the | ||
| 99 | +per-plane 543/543 are *the round-4 oracle numbers*, so the count was never a | ||
| 100 | +counting artefact. It was a real count, taken on an arm that does not decode. | ||
| 101 | + | ||
| 102 | +## 4. The eight (iv) entries on the exact arms are a tracing artefact, not a defect | ||
| 103 | + | ||
| 104 | +On `444_rect_strip_leaf_tx_type` and `444_sb128rect_lr_witness`, 4 units each | ||
| 105 | +bucket as (iv). All four have **identical `entry_rng`, `post_rng`, `eob` and | ||
| 106 | +all-zero flag on both sides** and differ only in the reported extent: | ||
| 107 | + | ||
| 108 | +``` | ||
| 109 | +idx 202: ours plane=0 32x32 eob=0 az=true | oracle plane=0 txsz=TX_64X64 eob=0 az=true | post=41441 | ||
| 110 | +idx 498: ours plane=0 32x32 eob=0 az=true | oracle plane=0 txsz=TX_64X64 eob=0 az=true | post=33499 | ||
| 111 | +``` | ||
| 112 | + | ||
| 113 | +Both sides read exactly one `txb_skip` symbol and consumed the same bits; ours | ||
| 114 | +reports the *corner* it decoded (the 32×32 low-frequency corner of a 64×64 | ||
| 115 | +luma block — `read_coeffs`' `rect_shape` path, spec 5.11.40) while libaom's | ||
| 116 | +`EC_COEFF` prints the `TX_64X64` it was called with. A shape **label** | ||
| 117 | +difference on an otherwise identical unit, not a walk difference. Two of the | ||
| 118 | +four also carry a plane-label difference with the same entry/post rng — the same | ||
| 119 | +class. Under the ticket's own rule ("a real divergence requires a unit in (i) or | ||
| 120 | +(iv) whose **eob/values** differ") these are neither: no eob and no value | ||
| 121 | +differs anywhere on any pixel-exact arm. | ||
| 122 | + | ||
| 123 | +## 5. Gate | ||
| 124 | + | ||
| 125 | +`a_pixel_exact_444_stream_walks_the_same_coefficient_units_the_oracle_does` | ||
| 126 | +(`crates/ec-av1/src/stream.rs`) pins the walk's object shape on two | ||
| 127 | +pixel-exact 4:4:4 arms: | ||
| 128 | + | ||
| 129 | +- `ll444_minp8_inter` — all-TX_4X4 (min-partition-8 lossless): `[3764, 3764, | ||
| 130 | + 3764]` units, `[975, 1793, 1859]` coded; | ||
| 131 | +- `444_lossy_rect4_inter_witness` — **mixed shapes** (4×4, 8×8, 8×4, 4×8, 4×16, | ||
| 132 | + 16×4, 8×16, 16×16): `[629, 372, 372]` units, `[130, 253, 278]` coded. | ||
| 133 | + | ||
| 134 | +The second arm is not redundant: the first is uniformly 4×4 and would not notice | ||
| 135 | +a var-tx walk that started folding 8×8 leaves. Both numbers are the oracle's own | ||
| 136 | +census on the same stream. | ||
| 137 | + | ||
| 138 | +**Mutation-proven.** Dropping 8×8 units from the walk turns it red by name: | ||
| 139 | + | ||
| 140 | +``` | ||
| 141 | +the mixed-shape 4:4:4 walk changed -- [571, 313, 313] against the oracle's [629, 372, 372] | ||
| 142 | + left: [571, 313, 313] right: [629, 372, 372] | ||
| 143 | +``` | ||
| 144 | + | ||
| 145 | +and the all-4×4 arm is untouched by that mutation — which is exactly why both | ||
| 146 | +arms are pinned. | ||
| 147 | + | ||
| 148 | +**4:2:0 control.** The census is armed per frame from the sequence header's | ||
| 149 | +subsampling (`set_census_444(ss_x, ss_y)` in `stream.rs`, beside | ||
| 150 | +`set_mono`/`set_subsampling`), so at 4:2:0/4:2:2 every counter stays zero; the | ||
| 151 | +gate asserts exactly `(0, 0, 0)` for both the unit and coded-unit counters on a | ||
| 152 | +committed 4:2:0 stream that decodes. The accounting is separate from the sibling | ||
| 153 | +counter pair the ticket mentions. | ||
| 154 | + | ||
| 155 | +## 6. What this settles for the next lane | ||
| 156 | + | ||
| 157 | +- The 636-vs-1086 / 2052-vs-1309 signal is **retracted**: it was measured on | ||
| 158 | + `444_intrabc_rect4_witness`, which is wrong in 390380 of 921600 samples. Do not | ||
| 159 | + carry it forward as a walk-shape hypothesis. | ||
| 160 | +- Counting the coefficient units on a **pixel-exact 4:4:4** arm reproduces the | ||
| 161 | + oracle exactly, per plane, per unit. The census is now a one-command check: | ||
| 162 | + `EC_CENSUS_UNIT=1 cargo run -p ec-av1 --example decode_probe -- <arm>.obu` | ||
| 163 | + against `EC_TRACE_COEFF=1 aomdec`, paired by `post_rng`. | ||
| 164 | +- If a future lane sees a count asymmetry, the first question is whether the arm | ||
| 165 | + decodes — not whether the walk shape differs. That check is now the gate. | ||
| 166 | + | ||
| 167 | +## 7. Not fixed here, by design | ||
| 168 | + | ||
| 169 | +The 4:4:4 intra-BC chroma divergence (`444_intrabc_rect4_witness`, 390380 / | ||
| 170 | +921600) is untouched: this lane's deliverable is the census. Per §4 there is no | ||
| 171 | +value-level divergence on any pixel-exact arm for this census to point at, so the | ||
| 172 | +remaining fork is not a coefficient-read-count problem and needs a fresh charter. | ||
| 173 | + | ||
| 174 | +## 8. Method notes for whoever repeats this | ||
| 175 | + | ||
| 176 | +- **Pair by `post_rng`.** Position/`n` pairing invents matches when a walk | ||
| 177 | + orders U and V differently; plane-label pairing invents them when plane | ||
| 178 | + attribution is the thing in question. | ||
| 179 | +- **A pixel-exact arm is mandatory.** On `444_intrabc_rect4_witness` the counts | ||
| 180 | + diverge by 823/478 units *because* the decode does; the count difference is a | ||
| 181 | + symptom, not a cause. | ||
| 182 | +- **`EC_SYMR` is still the right rung for symbol-level work**; `EC_COEFF_STEP` | ||
| 183 | + is filtered (the oracle prints `tag=tx_type` for all three planes but reads it | ||
| 184 | + only for Y), so it is not a per-unit bracket. `EC_COEFF`/`EC_COEFF_VAL` are | ||
| 185 | + the per-unit bracket and were already in the oracle build — no rebuild needed. | ||
| 186 | +- Our own rung must carry the real plane: `read_coeffs` had no plane parameter, | ||
| 187 | + and a stamp inherited from whichever reader ran last mis-attributes chroma as | ||
| 188 | + luma (this bit the census's first run and is the same trap `d791c464` fixed for | ||
| 189 | + the rect trace). | ||