Merge branch 'lane-cfl': chroma intra-edge filter reads the neighbour's uv_mode below 16x16 (was a literal false; coarse 16px uv map never written by sub-16 blocks)
Browse files at this commit3 changed files +326 -10
- crates/ec-av1/src/decode.rs +69 -10
- crates/ec-av1/src/stream.rs +170 -0
- lanes/cfl-r1.report.md +87 -0
crates/ec-av1/src/decode.rsmodified+69 -10
| @@ -1426,6 +1426,38 @@ pub(crate) fn mode_mi_override_hits() -> usize { | ||
| 1426 | 1426 | MODE_MI_OVERRIDE_HITS.with(|c| c.get()) |
| 1427 | 1427 | } |
| 1428 | 1428 | |
| 1429 | +// lane-cfl r1: how many times a chroma intra-edge filter-type read | |
| 1430 | +// (`get_filt_type`, libaom reconintra.c) took an above/left UV mode from the | |
| 1431 | +// mi-exact map that DIFFERS from its coarse 16x16 slot -- i.e. how often the | |
| 1432 | +// r1 defect would have filtered a chroma edge with the wrong strength. | |
| 1433 | +thread_local! { | |
| 1434 | + static UV_MODE_MI_OVERRIDE_HITS: std::cell::Cell<usize> = | |
| 1435 | + const { std::cell::Cell::new(0) }; | |
| 1436 | +} | |
| 1437 | + | |
| 1438 | +/// Current value of [`UV_MODE_MI_OVERRIDE_HITS`]. | |
| 1439 | +pub(crate) fn uv_mode_mi_override_hits() -> usize { | |
| 1440 | + UV_MODE_MI_OVERRIDE_HITS.with(|c| c.get()) | |
| 1441 | +} | |
| 1442 | + | |
| 1443 | +// lane-cfl r1 gate counters: `UV_CFL_PRED` blocks (every `cfl_alpha_signs` | |
| 1444 | +// read) and chroma blocks with a NONZERO `angle_delta_uv` -- the two block | |
| 1445 | +// shapes the r1 chroma defect showed up on. | |
| 1446 | +thread_local! { | |
| 1447 | + static CFL_BLOCK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1448 | + static UV_ANGLE_DELTA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1449 | +} | |
| 1450 | + | |
| 1451 | +/// Current value of [`CFL_BLOCK_HITS`]. | |
| 1452 | +pub(crate) fn cfl_block_hits() -> usize { | |
| 1453 | + CFL_BLOCK_HITS.with(|c| c.get()) | |
| 1454 | +} | |
| 1455 | + | |
| 1456 | +/// Current value of [`UV_ANGLE_DELTA_HITS`]. | |
| 1457 | +pub(crate) fn uv_angle_delta_hits() -> usize { | |
| 1458 | + UV_ANGLE_DELTA_HITS.with(|c| c.get()) | |
| 1459 | +} | |
| 1460 | + | |
| 1429 | 1461 | // lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT` |
| 1430 | 1462 | // blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the |
| 1431 | 1463 | // gate's proof this round's arms actually reached a real block, not just |
| @@ -3671,7 +3703,14 @@ impl Neighbours { | ||
| 3671 | 3703 | /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves |
| 3672 | 3704 | /// read these back, and only when the recorded position is exactly their |
| 3673 | 3705 | /// own neighbour -- see [`Self::sub8_mode_col`]'s doc. |
| 3674 | - fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) { | |
| 3706 | + fn record_mode_mi( | |
| 3707 | + &mut self, | |
| 3708 | + mi_r: usize, | |
| 3709 | + mi_c: usize, | |
| 3710 | + mi_w: usize, | |
| 3711 | + mi_h: usize, | |
| 3712 | + mode: usize, | |
| 3713 | + ) { | |
| 3675 | 3714 | let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1); |
| 3676 | 3715 | for cell in 0..mi_w { |
| 3677 | 3716 | if let Some(slot) = self.sub8_mode_col.get_mut(mi_c + cell) { |
| @@ -3739,6 +3778,12 @@ impl Neighbours { | ||
| 3739 | 3778 | Some(&(col, m)) if mi_c > self.tile_col0_mi && col == mi_c - 1 => m, |
| 3740 | 3779 | _ => self.left_uv_mode[r], |
| 3741 | 3780 | }; |
| 3781 | + // lane-cfl r1 counter: how often the mi-exact chroma neighbour differs | |
| 3782 | + // from the coarse [`SUB`] slot -- i.e. how often a chroma edge would | |
| 3783 | + // have been filtered at the wrong strength by the coarse map alone. | |
| 3784 | + if above != self.above_uv_mode[c] || left != self.left_uv_mode[r] { | |
| 3785 | + UV_MODE_MI_OVERRIDE_HITS.with(|h| h.set(h.get() + 1)); | |
| 3786 | + } | |
| 3742 | 3787 | is_smooth_mode(above) || is_smooth_mode(left) |
| 3743 | 3788 | } |
| 3744 | 3789 | |
| @@ -4390,6 +4435,9 @@ fn read_intra_mode_rect( | ||
| 4390 | 4435 | 0 |
| 4391 | 4436 | }; |
| 4392 | 4437 | istep!("angle_uv", angle_delta_uv); |
| 4438 | + if angle_delta_uv != 0 { | |
| 4439 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | |
| 4440 | + } | |
| 4393 | 4441 | let mut filter_intra = None; |
| 4394 | 4442 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 4395 | 4443 | let (rng, _) = dec.debug_state(); |
| @@ -4777,7 +4825,7 @@ fn decode_block_rect( | ||
| 4777 | 4825 | // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's |
| 4778 | 4826 | // `uv_mode`, not the luma one. |
| 4779 | 4827 | let smooth_neighbor_uv = |
| 4780 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 4828 | + neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c); | |
| 4781 | 4829 | // lane-rectsplit r1: `predict_filter_intra` now takes the block's own |
| 4782 | 4830 | // `bw`x`bh` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a |
| 4783 | 4831 | // rectangle just as happily), so a `use_filter_intra` strip at this level |
| @@ -5193,6 +5241,10 @@ fn decode_leaf_rect( | ||
| 5193 | 5241 | FILTER_INTRA_RECT_SUB16_HITS.with(|c| c.set(c.get() + 1)); |
| 5194 | 5242 | } |
| 5195 | 5243 | let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; |
| 5244 | + // lane-cfl r1, same defect as [`decode_leaf_8x8`]: chroma's intra-edge | |
| 5245 | + // filter type is the NEIGHBOUR's `uv_mode` (libaom `get_filt_type`), not | |
| 5246 | + // a constant `false`. | |
| 5247 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | |
| 5196 | 5248 | let depth = if tx_select { |
| 5197 | 5249 | let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh); |
| 5198 | 5250 | dec.symbol(&mut cdfs.tx_size_cat2[ctx]) |
| @@ -5221,11 +5273,11 @@ fn decode_leaf_rect( | ||
| 5221 | 5273 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 5222 | 5274 | u.reconstruct_rect( |
| 5223 | 5275 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_levels, |
| 5224 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false, | |
| 5276 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, | |
| 5225 | 5277 | ); |
| 5226 | 5278 | v.reconstruct_rect( |
| 5227 | 5279 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_levels, |
| 5228 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false, | |
| 5280 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, | |
| 5229 | 5281 | ); |
| 5230 | 5282 | } else { |
| 5231 | 5283 | // lane-rectx: a genuine 16x8/8x16 luma transform (`TxbSet::LumaRect16x8`, |
| @@ -5277,7 +5329,7 @@ fn decode_leaf_rect( | ||
| 5277 | 5329 | ); |
| 5278 | 5330 | u.reconstruct_rect( |
| 5279 | 5331 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &u_residual, |
| 5280 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, false, | |
| 5332 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, | |
| 5281 | 5333 | ); |
| 5282 | 5334 | let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); |
| 5283 | 5335 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); |
| @@ -5293,7 +5345,7 @@ fn decode_leaf_rect( | ||
| 5293 | 5345 | ); |
| 5294 | 5346 | v.reconstruct_rect( |
| 5295 | 5347 | cpx, cpy, chroma_w, chroma_h, uv_predict_mode, angle_delta_uv, reach, &v_residual, |
| 5296 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, false, | |
| 5348 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, | |
| 5297 | 5349 | ); |
| 5298 | 5350 | RECT_LEAF_COEFF_HITS.with(|c| c.set(c.get() + 1)); |
| 5299 | 5351 | } |
| @@ -5377,7 +5429,7 @@ fn decode_block_rect4( | ||
| 5377 | 5429 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 5378 | 5430 | } |
| 5379 | 5431 | let smooth_neighbor_uv = |
| 5380 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 5432 | + neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c); | |
| 5381 | 5433 | if filter_intra.is_some() { |
| 5382 | 5434 | FILTER_INTRA_RECT_HITS.with(|c| c.set(c.get() + 1)); |
| 5383 | 5435 | } |
| @@ -5651,7 +5703,7 @@ fn decode_block_rect64( | ||
| 5651 | 5703 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 5652 | 5704 | } |
| 5653 | 5705 | let smooth_neighbor_uv = |
| 5654 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 5706 | + neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c); | |
| 5655 | 5707 | if filter_intra.is_some() { |
| 5656 | 5708 | // `filter_intra_size_class_rect` already returns `None` for both |
| 5657 | 5709 | // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at |
| @@ -6191,6 +6243,9 @@ fn read_intra_mode( | ||
| 6191 | 6243 | 0 |
| 6192 | 6244 | }; |
| 6193 | 6245 | istep!("angle_uv", angle_delta_uv); |
| 6246 | + if angle_delta_uv != 0 { | |
| 6247 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | |
| 6248 | + } | |
| 6194 | 6249 | // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called |
| 6195 | 6250 | // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`): |
| 6196 | 6251 | // gated by `av1_allow_palette` (blockd.h -- size bound only, |
| @@ -6342,6 +6397,7 @@ const UV_CFL_PRED: usize = 13; | ||
| 6342 | 6397 | /// joint sign the same way. Returns each plane's final signed `alpha_q3` |
| 6343 | 6398 | /// (`cfl_idx_to_alpha`, cfl.c): magnitude `idx + 1`, sign-zero collapsing to 0. |
| 6344 | 6399 | fn read_cfl_alphas(dec: &mut SymbolDecoder, cdfs: &mut Cdfs) -> (i32, i32) { |
| 6400 | + CFL_BLOCK_HITS.with(|c| c.set(c.get() + 1)); | |
| 6345 | 6401 | let joint_sign = dec.symbol(&mut cdfs.cfl_sign) as i32; |
| 6346 | 6402 | let sign_u = ((joint_sign + 1) * 11) >> 5; |
| 6347 | 6403 | let sign_v = (joint_sign + 1) - 3 * sign_u; |
| @@ -6904,7 +6960,7 @@ fn decode_block( | ||
| 6904 | 6960 | SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); |
| 6905 | 6961 | } |
| 6906 | 6962 | let smooth_neighbor_uv = |
| 6907 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 6963 | + neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c); | |
| 6908 | 6964 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 6909 | 6965 | eprintln!( |
| 6910 | 6966 | "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \ |
| @@ -14693,6 +14749,9 @@ fn decode_inter_block( | ||
| 14693 | 14749 | } else { |
| 14694 | 14750 | 0 |
| 14695 | 14751 | }; |
| 14752 | + if angle_delta_uv != 0 { | |
| 14753 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | |
| 14754 | + } | |
| 14696 | 14755 | uv_predict_mode = if uv_mode == UV_CFL_PRED { |
| 14697 | 14756 | DC_PRED |
| 14698 | 14757 | } else { |
| @@ -14702,7 +14761,7 @@ fn decode_inter_block( | ||
| 14702 | 14761 | // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA |
| 14703 | 14762 | // neighbour's own `uv_mode`, not the luma one. |
| 14704 | 14763 | let smooth_neighbor_uv = |
| 14705 | - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); | |
| 14764 | + neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c); | |
| 14706 | 14765 | // `read_palette_mode_info` (decodemv.c:567, called from |
| 14707 | 14766 | // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same |
| 14708 | 14767 | // gating and same corner-cut as `read_intra_mode`'s own copy above |
crates/ec-av1/src/stream.rsmodified+170 -0
| @@ -8178,6 +8178,176 @@ mod tests { | ||
| 8178 | 8178 | eprintln!("{NAME}: pixel-exact, mode_mi_override_hits={total_overrides}"); |
| 8179 | 8179 | } |
| 8180 | 8180 | |
| 8181 | + /// lane-cfl r1: the chroma intra-edge FILTER TYPE is the neighbour's | |
| 8182 | + /// `uv_mode` (libaom `get_filt_type`, reconintra.c: `chroma_above_mbmi`/ | |
| 8183 | + /// `chroma_left_mbmi` -> `is_smooth` on `uv_mode`), and two whole decode | |
| 8184 | + /// paths passed a hardcoded `false` for it -- `decode_leaf_8x8` (every | |
| 8185 | + /// 8x8 leaf of a SPLIT) and `decode_leaf_rect` (every rect strip below | |
| 8186 | + /// 16x16), on a stale "chroma stays false (exact) until a smooth/paeth | |
| 8187 | + /// uv_mode can reach decode at all" comment. On top of that the coarse | |
| 8188 | + /// `above_uv_mode`/`left_uv_mode` cells are 16px-granular and their | |
| 8189 | + /// `for cell in 0..w / SUB` write runs ZERO times for any block below | |
| 8190 | + /// 16x16, so even the paths that DID read them saw whatever a | |
| 8191 | + /// 16x16-or-larger block had left there (class: context read from one | |
| 8192 | + /// cell / neighbour map at the wrong granularity). Result on this | |
| 8193 | + /// recipe: luma byte-exact, entropy ladder identical, and 40 U + 86 V | |
| 8194 | + /// chroma bytes wrong -- every one of them downstream of one 4x4 chroma | |
| 8195 | + /// block at mi(8,12) whose D135 + `angle_delta_uv=-3` left edge was | |
| 8196 | + /// filtered at the wrong strength (`ft=0` where the instrumented aomdec | |
| 8197 | + /// prints `ft=1`, left edge `95,59,30,28` vs `90,61,37,29`). | |
| 8198 | + /// | |
| 8199 | + /// Both arms hard-assert per-attempt counters for the two chroma block | |
| 8200 | + /// shapes involved (`UV_CFL_PRED` blocks, nonzero `angle_delta_uv` | |
| 8201 | + /// blocks) plus the mi-exact UV-neighbour override, and are counted only | |
| 8202 | + /// on an attempt that decoded AND is pixel-compared. | |
| 8203 | + #[test] | |
| 8204 | + fn a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact() | |
| 8205 | + { | |
| 8206 | + const NAME: &str = "a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact"; | |
| 8207 | + let _gate_lock = lock_gate_counters(); | |
| 8208 | + if !have_ffmpeg() { | |
| 8209 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 8210 | + return; | |
| 8211 | + } | |
| 8212 | + if !have_aomenc() { | |
| 8213 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 8214 | + return; | |
| 8215 | + } | |
| 8216 | + let mut compared = 0usize; | |
| 8217 | + let (width, height) = (64usize, 64usize); | |
| 8218 | + // 8-bit arm = the r5 residue cell ("mandfi161"); 10-bit arm = its | |
| 8219 | + // twin through the same recipe at `--bit-depth=10`. | |
| 8220 | + for depth in [8usize, 10] { | |
| 8221 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 8222 | + let y4m = Command::new("ffmpeg") | |
| 8223 | + .args([ | |
| 8224 | + "-v", "error", "-f", "lavfi", "-i", | |
| 8225 | + &format!("mandelbrot=size={width}x{height}:start_x=-0.6"), | |
| 8226 | + "-pix_fmt", pix, "-strict", "-1", "-t", "1", "-vframes", "1", | |
| 8227 | + "-f", "yuv4mpegpipe", "-", | |
| 8228 | + ]) | |
| 8229 | + .stdin(Stdio::null()) | |
| 8230 | + .stdout(Stdio::piped()) | |
| 8231 | + .stderr(Stdio::piped()) | |
| 8232 | + .output() | |
| 8233 | + .expect("ffmpeg failed to run"); | |
| 8234 | + assert!( | |
| 8235 | + y4m.status.success(), | |
| 8236 | + "{NAME}: ffmpeg fixture (depth={depth}): {}", | |
| 8237 | + String::from_utf8_lossy(&y4m.stderr) | |
| 8238 | + ); | |
| 8239 | + let encode = || { | |
| 8240 | + let mut child = Command::new(aomenc_path()) | |
| 8241 | + .args([ | |
| 8242 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=16", | |
| 8243 | + "--cpu-used=4", "--threads=1", "--row-mt=0", "--sb-size=64", | |
| 8244 | + "--kf-max-dist=0", "--enable-rect-partitions=1", | |
| 8245 | + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", | |
| 8246 | + "--enable-tx-size-search=0", "--enable-filter-intra=1", | |
| 8247 | + "--reduced-tx-type-set=1", "--min-partition-size=8", | |
| 8248 | + "--max-partition-size=32", | |
| 8249 | + &format!("--input-bit-depth={depth}"), | |
| 8250 | + &format!("--bit-depth={depth}"), | |
| 8251 | + "--obu", "-o", "-", "-", | |
| 8252 | + ]) | |
| 8253 | + .stdin(Stdio::piped()) | |
| 8254 | + .stdout(Stdio::piped()) | |
| 8255 | + .stderr(Stdio::piped()) | |
| 8256 | + .spawn() | |
| 8257 | + .expect("aomenc failed to start"); | |
| 8258 | + child | |
| 8259 | + .stdin | |
| 8260 | + .take() | |
| 8261 | + .expect("aomenc stdin") | |
| 8262 | + .write_all(&y4m.stdout) | |
| 8263 | + .expect("writing y4m to aomenc"); | |
| 8264 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 8265 | + assert!( | |
| 8266 | + out.status.success(), | |
| 8267 | + "aomenc refused the fixture (depth={depth}): {}", | |
| 8268 | + String::from_utf8_lossy(&out.stderr) | |
| 8269 | + ); | |
| 8270 | + out.stdout | |
| 8271 | + }; | |
| 8272 | + let stream = encode(); | |
| 8273 | + assert_eq!( | |
| 8274 | + stream, | |
| 8275 | + encode(), | |
| 8276 | + "{NAME}: aomenc output is not reproducible (depth={depth})" | |
| 8277 | + ); | |
| 8278 | + let before_cfl = crate::decode::cfl_block_hits(); | |
| 8279 | + let before_angle = crate::decode::uv_angle_delta_hits(); | |
| 8280 | + let before_uv = crate::decode::uv_mode_mi_override_hits(); | |
| 8281 | + let frames = match decode_stream(&stream) { | |
| 8282 | + Ok(frames) => frames, | |
| 8283 | + // Only a NAMED refusal is tolerated (COMMON rule): the 10-bit | |
| 8284 | + // twin of this recipe still stops at another lane's open | |
| 8285 | + // sub-16 AB-partition / strip-filter-intra refusals, so it | |
| 8286 | + // cannot be compared yet. Any other error is a failure, and | |
| 8287 | + // `compared` below keeps the test from passing vacuously. | |
| 8288 | + Err(e) => { | |
| 8289 | + let msg = e.to_string(); | |
| 8290 | + assert!( | |
| 8291 | + msg.contains("unsupported"), | |
| 8292 | + "{NAME}: decode failed (depth={depth}): {msg}" | |
| 8293 | + ); | |
| 8294 | + eprintln!("{NAME}: depth={depth} arm refused (not compared): {msg}"); | |
| 8295 | + continue; | |
| 8296 | + } | |
| 8297 | + }; | |
| 8298 | + compared += 1; | |
| 8299 | + // Read only on an attempt that decoded AND is compared below. | |
| 8300 | + let cfl_blocks = crate::decode::cfl_block_hits() - before_cfl; | |
| 8301 | + let angle_blocks = crate::decode::uv_angle_delta_hits() - before_angle; | |
| 8302 | + let uv_overrides = crate::decode::uv_mode_mi_override_hits() - before_uv; | |
| 8303 | + let ffmpeg_frames = if depth == 10 { | |
| 8304 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | |
| 8305 | + } else { | |
| 8306 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | |
| 8307 | + }; | |
| 8308 | + assert_eq!(frames.len(), 1, "{NAME}: expected one key frame (depth={depth})"); | |
| 8309 | + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); | |
| 8310 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 8311 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (depth={depth})"); | |
| 8312 | + assert_eq!( | |
| 8313 | + got.u, want.u, | |
| 8314 | + "{NAME} frame {i} U vs ffmpeg (depth={depth}, {cfl_blocks} CFL blocks, \ | |
| 8315 | + {angle_blocks} nonzero-angle_delta_uv blocks, {uv_overrides} mi-exact UV \ | |
| 8316 | + neighbour overrides)" | |
| 8317 | + ); | |
| 8318 | + assert_eq!( | |
| 8319 | + got.v, want.v, | |
| 8320 | + "{NAME} frame {i} V vs ffmpeg (depth={depth}, {cfl_blocks} CFL blocks, \ | |
| 8321 | + {angle_blocks} nonzero-angle_delta_uv blocks, {uv_overrides} mi-exact UV \ | |
| 8322 | + neighbour overrides)" | |
| 8323 | + ); | |
| 8324 | + } | |
| 8325 | + assert!( | |
| 8326 | + cfl_blocks > 0, | |
| 8327 | + "{NAME}: no UV_CFL_PRED block decoded (depth={depth}) -- the gate proves nothing" | |
| 8328 | + ); | |
| 8329 | + assert!( | |
| 8330 | + angle_blocks > 0, | |
| 8331 | + "{NAME}: no nonzero angle_delta_uv chroma block decoded (depth={depth}) -- \ | |
| 8332 | + the chroma intra-edge filter path never ran" | |
| 8333 | + ); | |
| 8334 | + assert!( | |
| 8335 | + uv_overrides > 0, | |
| 8336 | + "{NAME}: no chroma edge-filter read ever took a mi-exact UV neighbour that \ | |
| 8337 | + disagreed with its coarse 16x16 slot (depth={depth}) -- the r1 defect is \ | |
| 8338 | + not exercised" | |
| 8339 | + ); | |
| 8340 | + eprintln!( | |
| 8341 | + "{NAME}: pixel-exact at {depth}-bit, cfl_blocks={cfl_blocks} \ | |
| 8342 | + angle_delta_uv_blocks={angle_blocks} uv_mi_overrides={uv_overrides}" | |
| 8343 | + ); | |
| 8344 | + } | |
| 8345 | + assert!( | |
| 8346 | + compared > 0, | |
| 8347 | + "{NAME}: every arm refused -- the gate compared no pixels at all" | |
| 8348 | + ); | |
| 8349 | + } | |
| 8350 | + | |
| 8181 | 8351 | #[test] |
| 8182 | 8352 | #[ignore = "lane-rectx r3 scratch sweep"] |
| 8183 | 8353 | fn sweep_rectx_recipes() { |
lanes/cfl-r1.report.mdadded+87 -0
| @@ -0,0 +1,87 @@ | ||
| 1 | +# lane-cfl r1+r2 report — chroma intra-edge filter type below 16x16 | |
| 2 | + | |
| 3 | +Branch `lane-cfl` @ `7148dba` (off `lane-rectx` bb41f82; not rebased, per charter). | |
| 4 | +r1 and r2 were both killed at their turn/session cap; their work was preserved as WIP | |
| 5 | +commits 38d096e + 455a142 and is squashed into `7148dba` by this round. | |
| 6 | + | |
| 7 | +## Root cause | |
| 8 | + | |
| 9 | +libaom `get_filt_type` (reconintra.c) chooses the chroma intra-edge filter STRENGTH from | |
| 10 | +`chroma_above_mbmi`/`chroma_left_mbmi`'s `uv_mode` (smooth-family neighbour => filtered | |
| 11 | +edge). Two defects stacked on the sub-16x16 path: | |
| 12 | + | |
| 13 | +1. **Constant `false`.** `decode_leaf_rect` and `decode_leaf_8x8` passed a literal `false` | |
| 14 | + as `smooth_neighbor_uv` into every chroma `reconstruct_rect` call, so a chroma edge was | |
| 15 | + never smooth-filtered below 16x16 regardless of the neighbour. | |
| 16 | +2. **Neighbour map coarser than the block.** `above_uv_mode`/`left_uv_mode` are written in | |
| 17 | + `SUB` (16px) cells by `for cell in 0..w / SUB`, which iterates ZERO times for a block | |
| 18 | + narrower/shorter than 16. A sub-16 block therefore never *wrote* its uv_mode, and every | |
| 19 | + reader (including the 16x16-and-up ones) saw whatever the last 16x16-or-larger block had | |
| 20 | + left in that slot. Class: *context read from one cell* / neighbour map coarser than the | |
| 21 | + block, the chroma twin of lane-rectx r5's luma `mode_above_mi`/`mode_left_mi`. | |
| 22 | + | |
| 23 | +Observed symptom before the fix: the mandelbrot cq16 cell filtered a chroma left edge at | |
| 24 | +`ft=0` where the instrumented aomdec prints `ft=1` (left edge `95,59,30,28` vs `90,61,37,29`). | |
| 25 | + | |
| 26 | +## Files changed | |
| 27 | + | |
| 28 | +- `crates/ec-av1/src/decode.rs:1886,2015,2089,2349,2595` — `Neighbours::sub8_mode_col/row` | |
| 29 | + widened from `(pos, mode)` to `(pos, mode, uv_mode)`; every reset/init site updated. | |
| 30 | +- `crates/ec-av1/src/decode.rs:2622-2680` — `uv_mode_above_mi`/`uv_mode_left_mi` and | |
| 31 | + `uv_modes_above_left{,_mi}`: mi-exact chroma neighbour with the coarse `SUB` slot as | |
| 32 | + fallback; tile-edge guards (`mi_r > tile_row0_mi` / `mi_c > tile_col0_mi`) inherited from | |
| 33 | + the luma twin, per the COMMON neighbour-map rule. | |
| 34 | +- `crates/ec-av1/src/decode.rs:3422,3825,4001,5122,5552` — every `smooth_neighbor_uv` | |
| 35 | + derivation now goes through `uv_modes_above_left{,_mi}`; `decode_leaf_rect` (3825) and | |
| 36 | + `decode_leaf_8x8` (5552) previously had none at all. | |
| 37 | +- `crates/ec-av1/src/decode.rs:3854,3858,3910,3926, 5216..5428` — chroma reconstruct call | |
| 38 | + sites take the derived flag. **Sweep: `grep -c "None, false," decode.rs` = 0** — no | |
| 39 | + constant-false chroma edge-filter site remains. | |
| 40 | +- `crates/ec-av1/src/decode.rs:775-805,3294` — gate counters `uv_mode_mi_override_hits`, | |
| 41 | + `cfl_block_hits`, `uv_angle_delta_hits`. | |
| 42 | +- `crates/ec-av1/src/stream.rs:5597-5742` — the gate (below). | |
| 43 | + | |
| 44 | +No refusal string was lifted this lane (none in `refusal_inventory.rs` covered this path); | |
| 45 | +`gate_coverage.rs` unchanged. | |
| 46 | + | |
| 47 | +## Gate | |
| 48 | + | |
| 49 | +`a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact` | |
| 50 | +— real aomenc, `mandelbrot=size=64x64:start_x=-0.6`, `--cq-level=16 --cpu-used=4 | |
| 51 | +--sb-size=64 --enable-rect-partitions=1 --enable-filter-intra=1 --reduced-tx-type-set=1 | |
| 52 | +--min-partition-size=8 --max-partition-size=32`, aomenc output hashed twice for | |
| 53 | +reproducibility, pixel-compared against ffmpeg. Hard asserts `cfl_blocks > 0`, | |
| 54 | +`angle_blocks > 0`, `uv_overrides > 0`, and `compared > 0` (no vacuous pass). The 10-bit | |
| 55 | +arm is tolerated ONLY on a message containing "unsupported" and is then not compared. | |
| 56 | + | |
| 57 | +``` | |
| 58 | +EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib chroma_edge_filter_reads_a_sub16 -- --nocapture | |
| 59 | +``` | |
| 60 | + | |
| 61 | +EVIDENCE: $HOME/.cache/cfl-suite.log (gate line) | aomenc mandelbrot -0.6 64x64 cq16 rtx=1 filter-intra=1, decode_stream vs ffmpeg_decode_sequence, all three planes | pixel-exact at 8-bit, cfl_blocks=15 angle_delta_uv_blocks=19 uv_mi_overrides=52; test result ok 1 passed | |
| 62 | + | |
| 63 | +EVIDENCE: scratchpad/ours.yuv vs scratchpad/ff.yuv | `cargo run -p ec-av1 --example decode_probe -- cfl.obu ours.yuv` on the same aomenc stream; `ffmpeg -i cfl.obu -pix_fmt yuv420p -f rawvideo ff.yuv`; `cmp` | byte-identical, 6144 bytes, sha256 c8cfa9b332f9c6e8... | |
| 64 | + | |
| 65 | +## Suite | |
| 66 | + | |
| 67 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (log `$HOME/.cache/cfl-suite.log`): | |
| 68 | +**273 passed; 0 failed; 24 ignored; 0 filtered out** (963.81s), exit 0. | |
| 69 | + | |
| 70 | +Siblings re-run green in that suite (COMMON sibling-gate rule): `a_real_libaom_cfl_stream_decodes_pixel_exact`, | |
| 71 | +`a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact`, | |
| 72 | +`a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact`, | |
| 73 | +`a_rect_strip_below_16x16_reads_its_own_filter_intra_cdf_row`, | |
| 74 | +`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`, | |
| 75 | +`a_real_aomenc_stream_with_smooth_luma_neighbour_decodes_pixel_exact`, | |
| 76 | +`a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact`, | |
| 77 | +`a_real_aomenc_stream_with_directional_chroma_decodes_pixel_exact`, | |
| 78 | +`rect_reach_tables_are_indexed_with_a_32_mi_row_stride`, plus all three | |
| 79 | +`refusal_inventory::tests::*` and both `gate_coverage::tests::*`. | |
| 80 | + | |
| 81 | +## Residue | |
| 82 | + | |
| 83 | +- deferred(lane owning sub-16 AB partitions): the 10-bit twin of this recipe stops at | |
| 84 | + `a HORZ_A/HORZ_B/VERT_A partition below 16x16` and is therefore never pixel-compared. | |
| 85 | + The gate records this explicitly rather than passing silently. | |
| 86 | +- accepted: no refusal string lifted — this round is a correctness fix behind existing | |
| 87 | + capability, not a capability claim. |