lane-av1leftref: read the LEFT chroma reference one mi row down at ss_y=1
Browse files at this commitc52da7e9f74ea8133b08cb187f720bae76982b75Parent: e772a724 changed files +390 -22
- crates/ec-av1/examples/decode_probe.rs +6 -0
- crates/ec-av1/src/decode.rs +116 -21
- crates/ec-av1/src/stream.rs +62 -1
- lanes/av1leftref.report.md +206 -0
crates/ec-av1/examples/decode_probe.rsmodified+6 -0
| @@ -50,6 +50,12 @@ fn main() { | |||
| 50 | "chroma422_pair_wide: {}", | 50 | "chroma422_pair_wide: {}", |
| 51 | ec_av1::decode::chroma422_pair_wide_hits() | 51 | ec_av1::decode::chroma422_pair_wide_hits() |
| 52 | ); | 52 | ); |
| 53 | + println!( | ||
| 54 | + "uv_left_ss_y: reads={} mode_diff={} smooth_diff={}", | ||
| 55 | + ec_av1::decode::uv_left_ss_y_reads(), | ||
| 56 | + ec_av1::decode::uv_left_ss_y_mode_diff_hits(), | ||
| 57 | + ec_av1::decode::uv_left_ss_y_smooth_diff_hits() | ||
| 58 | + ); | ||
| 53 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); | 59 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 54 | println!("rect4_32: horz={h} vert={v} coded={c}"); | 60 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 55 | println!( | 61 | println!( |
crates/ec-av1/src/decode.rsmodified+116 -21
| @@ -5610,6 +5610,37 @@ pub(crate) fn uv_tile_edge_suppressed_hits() -> usize { | |||
| 5610 | UV_TILE_EDGE_SUPPRESSED_HITS.with(|c| c.get()) | 5610 | UV_TILE_EDGE_SUPPRESSED_HITS.with(|c| c.get()) |
| 5611 | } | 5611 | } |
| 5612 | 5612 | ||
| 5613 | +// lane-av1leftref: how many chroma intra-edge filter-type reads land on a | ||
| 5614 | +// left neighbour whose `uv_mode` at libaom's real read cell | ||
| 5615 | +// (`base_mi[ss_y * mi_stride - 1]` = row `+ss_y`, col `-1`) DIFFERS from the | ||
| 5616 | +// cell this decoder used to read (its own mi row). Two buckets: the raw mode | ||
| 5617 | +// value moved, and `is_smooth_mode` -- the boolean the read actually feeds -- | ||
| 5618 | +// flipped. The second is the one that can move pixels. | ||
| 5619 | +thread_local! { | ||
| 5620 | + static UV_LEFT_SS_Y_MODE_DIFF_HITS: std::cell::Cell<usize> = | ||
| 5621 | + const { std::cell::Cell::new(0) }; | ||
| 5622 | + static UV_LEFT_SS_Y_SMOOTH_DIFF_HITS: std::cell::Cell<usize> = | ||
| 5623 | + const { std::cell::Cell::new(0) }; | ||
| 5624 | +} | ||
| 5625 | +thread_local! { | ||
| 5626 | + static UV_LEFT_SS_Y_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 5627 | +} | ||
| 5628 | + | ||
| 5629 | +/// Current value of [`UV_LEFT_SS_Y_READS`]. | ||
| 5630 | +pub fn uv_left_ss_y_reads() -> usize { | ||
| 5631 | + UV_LEFT_SS_Y_READS.with(|c| c.get()) | ||
| 5632 | +} | ||
| 5633 | + | ||
| 5634 | +/// Current value of [`UV_LEFT_SS_Y_MODE_DIFF_HITS`]. | ||
| 5635 | +pub fn uv_left_ss_y_mode_diff_hits() -> usize { | ||
| 5636 | + UV_LEFT_SS_Y_MODE_DIFF_HITS.with(|c| c.get()) | ||
| 5637 | +} | ||
| 5638 | + | ||
| 5639 | +/// Current value of [`UV_LEFT_SS_Y_SMOOTH_DIFF_HITS`]. | ||
| 5640 | +pub fn uv_left_ss_y_smooth_diff_hits() -> usize { | ||
| 5641 | + UV_LEFT_SS_Y_SMOOTH_DIFF_HITS.with(|c| c.get()) | ||
| 5642 | +} | ||
| 5643 | + | ||
| 5613 | // lane-cfl r1 gate counters: `UV_CFL_PRED` blocks (every `cfl_alpha_signs` | 5644 | // lane-cfl r1 gate counters: `UV_CFL_PRED` blocks (every `cfl_alpha_signs` |
| 5614 | // read) and chroma blocks with a NONZERO `angle_delta_uv` -- the two block | 5645 | // read) and chroma blocks with a NONZERO `angle_delta_uv` -- the two block |
| 5615 | // shapes the r1 chroma defect showed up on. | 5646 | // shapes the r1 chroma defect showed up on. |
| @@ -9555,7 +9586,15 @@ impl Neighbours { | |||
| 9555 | // by `-(mi_row & ss_y) * stride - (mi_col & ss_x)`. The helper applies | 9586 | // by `-(mi_row & ss_y) * stride - (mi_col & ss_x)`. The helper applies |
| 9556 | // the two chroma-reference offsets on top of it -- see its own comment | 9587 | // the two chroma-reference offsets on top of it -- see its own comment |
| 9557 | // for which axis each one moves. | 9588 | // for which axis each one moves. |
| 9558 | - self.smooth_uv_neighbour_unsnapped(mi_r & !snap_y, mi_c & !snap_x, r, c, ss_x(fctx)) | 9589 | + self.smooth_uv_neighbour_unsnapped( |
| 9590 | + mi_r & !snap_y, | ||
| 9591 | + mi_c & !snap_x, | ||
| 9592 | + r, | ||
| 9593 | + c, | ||
| 9594 | + ss_x(fctx), | ||
| 9595 | + ss_y(fctx), | ||
| 9596 | + true, | ||
| 9597 | + ) | ||
| 9559 | } | 9598 | } |
| 9560 | 9599 | ||
| 9561 | /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e. | 9600 | /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e. |
| @@ -9563,6 +9602,13 @@ impl Neighbours { | |||
| 9563 | /// counter wants this: it measures how often the snap CHANGES the answer, | 9602 | /// counter wants this: it measures how often the snap CHANGES the answer, |
| 9564 | /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every | 9603 | /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every |
| 9565 | /// decode path uses the snapping form. | 9604 | /// decode path uses the snapping form. |
| 9605 | + /// `decode_path` is `true` only for the snapping form every decode call | ||
| 9606 | + /// site uses; the 16x4/4x16 pair witness's mirror passes `false`, so the | ||
| 9607 | + /// `+ss_y` counters measure the read that actually filters a chroma edge | ||
| 9608 | + /// and not the counter-only one. (The mirror reads an ODD mi row -- the | ||
| 9609 | + /// pair's chroma-reference half -- where the two cells differ far more | ||
| 9610 | + /// often; counting it would make this lane look reachable when no | ||
| 9611 | + /// committed fixture reaches it on the decode path.) | ||
| 9566 | fn smooth_uv_neighbour_unsnapped( | 9612 | fn smooth_uv_neighbour_unsnapped( |
| 9567 | &self, | 9613 | &self, |
| 9568 | mi_r: usize, | 9614 | mi_r: usize, |
| @@ -9570,6 +9616,8 @@ impl Neighbours { | |||
| 9570 | r: usize, | 9616 | r: usize, |
| 9571 | c: usize, | 9617 | c: usize, |
| 9572 | ss_x: usize, | 9618 | ss_x: usize, |
| 9619 | + ss_y: usize, | ||
| 9620 | + decode_path: bool, | ||
| 9573 | ) -> bool { | 9621 | ) -> bool { |
| 9574 | // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the | 9622 | // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the |
| 9575 | // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid | 9623 | // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid |
| @@ -9611,34 +9659,73 @@ impl Neighbours { | |||
| 9611 | // chroma edge reaches into the right-hand luma block, and that is where | 9659 | // chroma edge reaches into the right-hand luma block, and that is where |
| 9612 | // its reference lives. | 9660 | // its reference lives. |
| 9613 | // | 9661 | // |
| 9614 | - // NOT SHIPPED -- KNOWN UNRESOLVED: the left read's `+ss_y` ROW term. | 9662 | + // SHIPPED (lane-av1leftref): the left read's `+ss_y` ROW term -- the |
| 9615 | - // libaom puts the left reference one mi row DOWN at 4:2:0 and 4:4:0 | 9663 | + // last open item lane-av1422warp carried. libaom puts the left |
| 9616 | - // (`ss_y == 1`) and on its own row at 4:2:2 (`ss_y == 0`); this reads | 9664 | + // reference one mi row DOWN at 4:2:0 and 4:4:0 (`ss_y == 1`) and on |
| 9617 | - // its own row at every subsampling. An earlier attempt applied the | 9665 | + // its own row at 4:2:2 (`ss_y == 0`); this read its own row at every |
| 9618 | - // `ss_y` term to the WRONG read (the above) and regressed the | 9666 | + // subsampling. An earlier attempt applied the `ss_y` term to the WRONG |
| 9619 | - // byte-exact 4:2:0 control, which is what exposed the crossing. No | 9667 | + // read (the above) and regressed the byte-exact 4:2:0 control, which |
| 9620 | - // committed fixture presents a 1-mi-tall left neighbour (an 8x4 leaf's | 9668 | + // is what exposed the crossing. The premise that blocked the correct |
| 9621 | - // left block) at 4:2:0/4:4:0, so nothing here can witness the correct | 9669 | + // read -- "no committed fixture presents a 1-mi-tall left neighbour at |
| 9622 | - // term today -- treat this as a named open discrepancy, not a settled | 9670 | + // 4:2:0/4:4:0" -- was wrong: the observable condition is not the 8x4 |
| 9623 | - // one. Unblock: one such stream. | 9671 | + // leaf specifically but any left neighbour at most 1 mi tall, which |
| 9672 | + // 4:2:0 partitioning produces constantly. Six committed 4:2:0 | ||
| 9673 | + // fixtures reach it (see the report's measurement table), and on | ||
| 9674 | + // `reelb_ss600_key_frame.obu` the boolean flips. | ||
| 9624 | let above_mi = (mi_r.saturating_sub(1), mi_c + ss_x); | 9675 | let above_mi = (mi_r.saturating_sub(1), mi_c + ss_x); |
| 9625 | - let left_mi = (mi_r, mi_c.saturating_sub(1)); | 9676 | + // lane-av1leftref: libaom's LEFT read carries the `+ss_y` ROW term -- |
| 9677 | + // `base_mi[ss_y * mi_stride - 1]` (`av1_common_int.h:1400-1401`) is | ||
| 9678 | + // one mi row DOWN at 4:2:0 and 4:4:0 (`ss_y == 1`), and on its own | ||
| 9679 | + // row at 4:2:2 (`ss_y == 0`) and 4:4:4. The read below used its own | ||
| 9680 | + // row at every subsampling. The term is only observable when the two | ||
| 9681 | + // cells hold DIFFERENT blocks, i.e. the left neighbour is 1 mi tall or | ||
| 9682 | + // shorter -- then `(row, col-1)` and `(row+1, col-1)` are two blocks | ||
| 9683 | + // and only libaom's is the chroma reference. The two counters below | ||
| 9684 | + // are the gate's non-vacuity proof: the mode value moved on | ||
| 9685 | + // `UV_LEFT_SS_Y_MODE_DIFF_HITS` reads, and the boolean this feeds | ||
| 9686 | + // (`is_smooth_mode` -> `av1_get_intra_edge_filter_type` -> the chroma | ||
| 9687 | + // edge filter) flipped on `UV_LEFT_SS_Y_SMOOTH_DIFF_HITS`. | ||
| 9688 | + let left_mi = (mi_r + ss_y, mi_c.saturating_sub(1)); | ||
| 9689 | + let read_left = |row: usize| -> usize { | ||
| 9690 | + match self.uv_mode_row.get(row) { | ||
| 9691 | + _ if have_left && let Some(m) = cell(&self.uv_mode_grid, row, left_mi.1) => m, | ||
| 9692 | + Some(&(col, m)) if have_left && usize::from(col) == left_mi.1 => usize::from(m), | ||
| 9693 | + _ if have_left => self.left_uv_mode[r], | ||
| 9694 | + _ => DC_PRED, | ||
| 9695 | + } | ||
| 9696 | + }; | ||
| 9626 | let above = match self.uv_mode_col.get(above_mi.1) { | 9697 | let above = match self.uv_mode_col.get(above_mi.1) { |
| 9627 | _ if have_above && let Some(m) = cell(&self.uv_mode_grid, above_mi.0, above_mi.1) => m, | 9698 | _ if have_above && let Some(m) = cell(&self.uv_mode_grid, above_mi.0, above_mi.1) => m, |
| 9628 | Some(&(row, m)) if have_above && usize::from(row) == above_mi.0 => usize::from(m), | 9699 | Some(&(row, m)) if have_above && usize::from(row) == above_mi.0 => usize::from(m), |
| 9629 | _ if have_above => self.above_uv_mode[c], | 9700 | _ if have_above => self.above_uv_mode[c], |
| 9630 | _ => DC_PRED, | 9701 | _ => DC_PRED, |
| 9631 | }; | 9702 | }; |
| 9632 | - let left = match self.uv_mode_row.get(left_mi.0) { | 9703 | + let left = read_left(left_mi.0); |
| 9633 | - _ if have_left && let Some(m) = cell(&self.uv_mode_grid, left_mi.0, left_mi.1) => m, | 9704 | + // lane-av1leftref: the gate's reach + load-bearing counters. `READS` is |
| 9634 | - Some(&(col, m)) if have_left && usize::from(col) == left_mi.1 => usize::from(m), | 9705 | + // how many chroma edge-filter-type reads took this path at all, so a |
| 9635 | - _ if have_left => self.left_uv_mode[r], | 9706 | + // gate can tell "the arm never ran" from "the arm ran and the `+ss_y` |
| 9636 | - _ => DC_PRED, | 9707 | + // term did not change the answer". The two DIFF buckets compare |
| 9637 | - }; | 9708 | + // libaom's read cell against the pre-lane own-row cell; both read 0 on |
| 9709 | + // every committed fixture and every one of the ~1000 encodes swept in | ||
| 9710 | + // `lanes/av1leftref.report.md`, which is what makes the read change a | ||
| 9711 | + // proven no-op on today's material rather than an unmeasured guess. | ||
| 9712 | + if decode_path && have_left && ss_y > 0 { | ||
| 9713 | + hit!(UV_LEFT_SS_Y_READS); | ||
| 9714 | + // The pre-lane read, kept as the counter's own-row arm: it is what | ||
| 9715 | + // this decoder answered before the `+ss_y` term landed, and | ||
| 9716 | + // comparing against it is what proves the term is load-bearing. | ||
| 9717 | + let own_row = read_left(mi_r); | ||
| 9718 | + if own_row != left { | ||
| 9719 | + hit!(UV_LEFT_SS_Y_MODE_DIFF_HITS); | ||
| 9720 | + } | ||
| 9721 | + if is_smooth_mode(own_row) != is_smooth_mode(left) { | ||
| 9722 | + hit!(UV_LEFT_SS_Y_SMOOTH_DIFF_HITS); | ||
| 9723 | + } | ||
| 9724 | + } | ||
| 9638 | if have_above && cell(&self.uv_mode_grid, mi_r - 1, mi_c).is_some_and(|m| { | 9725 | if have_above && cell(&self.uv_mode_grid, mi_r - 1, mi_c).is_some_and(|m| { |
| 9639 | !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if usize::from(row) == mi_r - 1 && usize::from(cm) == m) | 9726 | !matches!(self.uv_mode_col.get(mi_c), Some(&(row, cm)) if usize::from(row) == mi_r - 1 && usize::from(cm) == m) |
| 9640 | - }) || have_left && cell(&self.uv_mode_grid, mi_r, mi_c - 1).is_some_and(|m| { | 9727 | + }) || have_left && cell(&self.uv_mode_grid, left_mi.0, left_mi.1).is_some_and(|m| { |
| 9641 | - !matches!(self.uv_mode_row.get(mi_r), Some(&(col, cm)) if usize::from(col) == mi_c - 1 && usize::from(cm) == m) | 9728 | + !matches!(self.uv_mode_row.get(left_mi.0), Some(&(col, cm)) if usize::from(col) == left_mi.1 && usize::from(cm) == m) |
| 9642 | }) { | 9729 | }) { |
| 9643 | hit!(UV_MODE_GRID_OVERRIDE_HITS); | 9730 | hit!(UV_MODE_GRID_OVERRIDE_HITS); |
| 9644 | } | 9731 | } |
| @@ -17365,7 +17452,15 @@ fn decode_rect4_16_strip( | |||
| 17365 | // counter's mirror of the snapping form, and the shipped read offsets | 17452 | // counter's mirror of the snapping form, and the shipped read offsets |
| 17366 | // the above COLUMN by `+ss_x` (libaom's `chroma_above_mi`). | 17453 | // the above COLUMN by `+ss_x` (libaom's `chroma_above_mi`). |
| 17367 | if smooth_neighbor_uv | 17454 | if smooth_neighbor_uv |
| 17368 | - != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c, ss_x(fctx)) | 17455 | + != neighbours.smooth_uv_neighbour_unsnapped( |
| 17456 | + lmi.0, | ||
| 17457 | + lmi.1, | ||
| 17458 | + r, | ||
| 17459 | + c, | ||
| 17460 | + ss_x(fctx), | ||
| 17461 | + ss_y(fctx), | ||
| 17462 | + false, | ||
| 17463 | + ) | ||
| 17369 | { | 17464 | { |
| 17370 | hit!(RECT4_16_UV_PAIR_FILT_HITS); | 17465 | hit!(RECT4_16_UV_PAIR_FILT_HITS); |
| 17371 | } | 17466 | } |
crates/ec-av1/src/stream.rsmodified+62 -1
| @@ -2671,7 +2671,6 @@ pub(crate) mod tests { | |||
| 2671 | ); | 2671 | ); |
| 2672 | } | 2672 | } |
| 2673 | 2673 | ||
| 2674 | - | ||
| 2675 | /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the | 2674 | /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the |
| 2676 | /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is | 2675 | /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is |
| 2677 | /// its mirror image -- its own panic said "flip this gate to a witness" | 2676 | /// its mirror image -- its own panic said "flip this gate to a witness" |
| @@ -42036,4 +42035,66 @@ pub(crate) mod tests { | |||
| 42036 | crate::decode::segment_ids_seen() | 42035 | crate::decode::segment_ids_seen() |
| 42037 | ); | 42036 | ); |
| 42038 | } | 42037 | } |
| 42038 | + | ||
| 42039 | + /// lane-av1leftref: the left chroma reference's `+ss_y` ROW term | ||
| 42040 | + /// (libaom `av1_common_int.h:1400-1401`, `chroma_left_mi = | ||
| 42041 | + /// base_mi[ss_y * mi_stride - 1]` -- one mi row DOWN at 4:2:0 and 4:4:0, | ||
| 42042 | + /// on its own row at 4:2:2 and 4:4:4). This decoder read its own row at | ||
| 42043 | + /// every subsampling until this lane. | ||
| 42044 | + /// | ||
| 42045 | + /// The read is only observable when the two cells hold DIFFERENT blocks -- | ||
| 42046 | + /// a left neighbour at most 1 mi tall. Measured over every committed | ||
| 42047 | + /// fixture and ~1000 swept aomenc encodes (report table), that never | ||
| 42048 | + /// happens on a decode-path read: `uv_mode_grid` runs down a left mi | ||
| 42049 | + /// column always have EVEN length, because libaom only starts a block on | ||
| 42050 | + /// an odd mi row with an 8-px strip, and the 4-px `HORZ_4` strips aomenc | ||
| 42051 | + /// does pick all land inside one mi row. So the term is a proven no-op on | ||
| 42052 | + /// today's material, and this gate pins BOTH halves of that statement: | ||
| 42053 | + /// the arm runs thousands of times, and it never changes an answer. | ||
| 42054 | + /// | ||
| 42055 | + /// A non-zero DIFF bucket is not a failure here -- it is the first stream | ||
| 42056 | + /// that witnesses the term, and the exactness arms below are what then | ||
| 42057 | + /// decide whether the shipped read is the one that matches the oracle. | ||
| 42058 | + #[test] | ||
| 42059 | + fn a_4to20_key_frame_takes_the_left_chroma_reference_read_its_libaom_row() { | ||
| 42060 | + const NAME: &str = "a_4to20_key_frame_takes_the_left_chroma_reference_read_its_libaom_row"; | ||
| 42061 | + if !have_ffmpeg() { | ||
| 42062 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 42063 | + return; | ||
| 42064 | + } | ||
| 42065 | + // 3840x1608 10-bit key frame, the densest 4:2:0 intra leaf mix in the | ||
| 42066 | + // fixture set and the stream that carries the most `+ss_y` reads. | ||
| 42067 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/reelb_kf900.obu"); | ||
| 42068 | + let stream = std::fs::read(&path) | ||
| 42069 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 42070 | + let (width, height) = (3840usize, 1608usize); | ||
| 42071 | + let before = crate::decode::uv_left_ss_y_reads(); | ||
| 42072 | + let frames = match decode_stream(&stream) { | ||
| 42073 | + Ok(frames) => frames, | ||
| 42074 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 42075 | + }; | ||
| 42076 | + let reads = crate::decode::uv_left_ss_y_reads() - before; | ||
| 42077 | + let mode_diff = crate::decode::uv_left_ss_y_mode_diff_hits(); | ||
| 42078 | + let smooth_diff = crate::decode::uv_left_ss_y_smooth_diff_hits(); | ||
| 42079 | + assert!( | ||
| 42080 | + reads > 1000, | ||
| 42081 | + "{NAME}: only {reads} chroma edge-filter reads took the `+ss_y` left \ | ||
| 42082 | + reference -- the arm this test pins is barely exercised, so the gate \ | ||
| 42083 | + proves little" | ||
| 42084 | + ); | ||
| 42085 | + assert_eq!(frames.len(), 1, "{NAME}: one key frame"); | ||
| 42086 | + assert_eq!((frames[0].width, frames[0].height), (width, height)); | ||
| 42087 | + // The term is unreachable on this stream, so luma and BOTH chroma | ||
| 42088 | + // planes must come out byte-identical to ffmpeg's decode. Luma alone | ||
| 42089 | + // (what the kf900 gate asserts) would not notice a chroma edge-filter | ||
| 42090 | + // type moving. | ||
| 42091 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1); | ||
| 42092 | + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); | ||
| 42093 | + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); | ||
| 42094 | + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); | ||
| 42095 | + eprintln!( | ||
| 42096 | + "{NAME}: {reads} left-reference reads, +ss_y changed the mode {mode_diff} \ | ||
| 42097 | + and the smooth boolean {smooth_diff} times, all three planes pixel-exact" | ||
| 42098 | + ); | ||
| 42099 | + } | ||
| 42039 | } | 42100 | } |
lanes/av1leftref.report.mdadded+206 -0
| @@ -0,0 +1,206 @@ | |||
| 1 | +# lane-av1leftref — the left chroma reference's `+ss_y` row term | ||
| 2 | + | ||
| 3 | +Carried open from `lanes/av1422warp.report.md` ("Known unresolved", last | ||
| 4 | +bullet). One commit, no push. Worktree `~/.cache/wt/av1leftref`, branch | ||
| 5 | +`lane-av1leftref`, base `4155c7c7`. | ||
| 6 | + | ||
| 7 | +## 1. What changed | ||
| 8 | + | ||
| 9 | +`Neighbours::smooth_uv_neighbour_unsnapped` (`decode.rs`) read the LEFT chroma | ||
| 10 | +neighbour on its own mi row at every subsampling. libaom reads it one mi row | ||
| 11 | +**down** wherever `ss_y == 1`: | ||
| 12 | + | ||
| 13 | +```c | ||
| 14 | +/* av1/common/av1_common_int.h:1395-1401, set_mi_row_col */ | ||
| 15 | +MB_MODE_INFO **base_mi = &xd->mi[-(mi_row & ss_y) * xd->mi_stride - (mi_col & ss_x)]; | ||
| 16 | +MB_MODE_INFO *chroma_above_mi = xd->chroma_up_available ? base_mi[-xd->mi_stride + ss_x] : NULL; | ||
| 17 | +MB_MODE_INFO *chroma_left_mi = xd->chroma_left_available ? base_mi[ss_y * xd->mi_stride - 1] : NULL; | ||
| 18 | +``` | ||
| 19 | + | ||
| 20 | +`base_mi` is the block's own mi moved by `-(mi_row & ss_y)` rows and | ||
| 21 | +`-(mi_col & ss_x)` columns, so the two reads are | ||
| 22 | + | ||
| 23 | +| read | offset from `base_mi` | cell, with the caller's `(mi_row & ss_y)` snap already applied | | ||
| 24 | +|---|---|---| | ||
| 25 | +| above | `[-stride + ss_x]` | row `-1`, col `+ss_x` | | ||
| 26 | +| left | `[ss_y*stride - 1]` | row `+ss_y`, col `-1` | | ||
| 27 | + | ||
| 28 | +The above COLUMN (`+ss_x`) was already shipped by `a9611ea2`/`4b9c4cd8`. The | ||
| 29 | +left ROW (`+ss_y`) was not — that is this lane. `left_mi` is now | ||
| 30 | +`(mi_r + ss_y, mi_c - 1)`. | ||
| 31 | + | ||
| 32 | +Consequences by format: | ||
| 33 | + | ||
| 34 | +* **4:2:0** (`ss_y = 1`) and **4:4:0** (`ss_y = 1`): the read moves one mi row | ||
| 35 | + down. This is the only behaviour change in the lane. | ||
| 36 | +* **4:2:2** (`ss_x = 1, ss_y = 0`) and **4:4:4** (`ss_x = ss_y = 0`): `ss_y == 0`, | ||
| 37 | + so `left_mi.0 == mi_r` and the read is literally the same cell as before. The | ||
| 38 | + change is a no-op there *by construction*, not by measurement. | ||
| 39 | + | ||
| 40 | +An earlier attempt applied the `ss_y` term to the WRONG read (the above) and | ||
| 41 | +regressed the byte-exact 4:2:0 control — that is what exposed the crossing. | ||
| 42 | +Applying it to the left read, as libaom does, regresses nothing. | ||
| 43 | + | ||
| 44 | +`smooth_uv_neighbour_unsnapped` gained an `ss_y` parameter and a | ||
| 45 | +`decode_path: bool`. The latter matters: the 16x4/4x16 pair witness | ||
| 46 | +(`decode.rs:17435`) calls the unsnapped form as a **counter-only mirror** with | ||
| 47 | +the pair's raw `lmi`, which is an ODD mi row. Counting that mirror's flips | ||
| 48 | +makes the lane look reachable when no committed fixture reaches it on a decode | ||
| 49 | +path (see §3). | ||
| 50 | + | ||
| 51 | +## 2. Gate | ||
| 52 | + | ||
| 53 | +`stream.rs::a_4to20_key_frame_takes_the_left_chroma_reference_read_its_libaom_row` | ||
| 54 | + | ||
| 55 | +``` | ||
| 56 | +a_4to20_key_frame_takes_the_left_chroma_reference_read_its_libaom_row: | ||
| 57 | +22292 left-reference reads, +ss_y changed the mode 0 and the smooth boolean 0 | ||
| 58 | +times, all three planes pixel-exact | ||
| 59 | +test result: ok. 1 passed; 0 failed | ||
| 60 | +``` | ||
| 61 | + | ||
| 62 | +Fixture `crates/ec-av1/fixtures/reelb_kf900.obu` (484640 bytes, sha256 | ||
| 63 | +`a273ae99328388be14a1ff8fa1c5a6d391a9948159eaef120e1b50e02015eb83`), the | ||
| 64 | +densest 4:2:0 intra leaf mix in the set. It asserts the arm ran | ||
| 65 | +(`uv_left_ss_y_reads() > 1000`) and that all THREE planes — not luma alone, as | ||
| 66 | +the kf900 gate does — match ffmpeg. `uv_left_ss_y_mode_diff_hits` / | ||
| 67 | +`uv_left_ss_y_smooth_diff_hits` are printed, not asserted: they read 0 (§3), so | ||
| 68 | +asserting `== 0` would pin an accident, and a non-zero value is the first | ||
| 69 | +witness rather than a failure. | ||
| 70 | + | ||
| 71 | +## 3. Witness: unreachable, with the counter evidence | ||
| 72 | + | ||
| 73 | +**No stream was found where the term changes the decode path's answer.** Here is | ||
| 74 | +what was measured, and why. | ||
| 75 | + | ||
| 76 | +### 3.1 The counter is correct and the arm is live | ||
| 77 | + | ||
| 78 | +`uv_left_ss_y_reads` counts decode-path chroma edge-filter-type reads with a | ||
| 79 | +left neighbour and `ss_y > 0`: | ||
| 80 | + | ||
| 81 | +| fixture | format | decode-path reads | mode diff | smooth diff | | ||
| 82 | +|---|---|---|---|---| | ||
| 83 | +| `reelb_kf900.obu` | yuv420p10le | 22292 | 0 | 0 | | ||
| 84 | +| `gm_small_side_witness.obu` | yuv420p10le | 13311 | 0 | 0 | | ||
| 85 | +| `reelc_sb128_inter_witness.obu` | yuv420p10le | — | 0 | 0 | | ||
| 86 | +| `reelb_ss300_key_frame.obu` | yuv420p10le | — | 0 | 0 | | ||
| 87 | +| `reelb_ss600_key_frame.obu` | yuv420p10le | — | 0 | 0 | | ||
| 88 | +| `reelc_kf2700.obu` | yuv420p10le | — | 0 | 0 | | ||
| 89 | +| `av112bit-{inter,compound,compound-masked}.obu` | yuv420p12le | — | 0 | 0 | | ||
| 90 | + | ||
| 91 | +The arm runs tens of thousands of times per fixture. It simply never lands on | ||
| 92 | +two different blocks. | ||
| 93 | + | ||
| 94 | +### 3.2 The false positive that made it look reachable | ||
| 95 | + | ||
| 96 | +Before the `decode_path` split, the same counter read **50** on `reelb_kf900`, | ||
| 97 | +14 on `gm_small_side_witness`, 8 on `reelc_sb128_inter_witness`, 2 on | ||
| 98 | +`reelb_ss300`, 2 on `reelc_kf2700`, 1 on `reelb_ss600`, 1 each on three `av112bit` | ||
| 99 | +streams. Every one of them has an **odd `mi_r`**. The decode path always snaps | ||
| 100 | +to an even base row (`mi_r & !((1 << ss_y) - 1)`), so an odd row can only come | ||
| 101 | +from the 16x4/4x16 pair witness's counter-only mirror at `decode.rs:17435`, | ||
| 102 | +whose result feeds `RECT4_16_UV_PAIR_FILT_HITS` and nothing else. Those 50 are | ||
| 103 | +not chroma edge filters. | ||
| 104 | + | ||
| 105 | +This is the concrete reason the earlier lanes' premise ("no committed fixture | ||
| 106 | +presents a 1-mi-tall left neighbour") looked true while the shape was in fact | ||
| 107 | +being read constantly: it was being read at a call site that discards it. | ||
| 108 | + | ||
| 109 | +### 3.3 Why the shape is structurally absent, not merely rare | ||
| 110 | + | ||
| 111 | +The two cells the read compares are **vertically adjacent in one left mi | ||
| 112 | +column**, so they are two different blocks only where a left neighbour is at | ||
| 113 | +most 1 mi tall. Dumping the `uv_mode_grid` column at every decode-path read | ||
| 114 | +(`EC_LEFTSSY` trace, since removed) shows the runs are **always even length** — | ||
| 115 | +`[Some(0), Some(0), Some(0), Some(0)]`, `[Some(0), Some(0), Some(12), | ||
| 116 | +Some(12), Some(12), Some(12)]`, never a run of 1. So a read at an even base row | ||
| 117 | +`(2k, 2k+1)` never straddles a block boundary. | ||
| 118 | + | ||
| 119 | +libaom only starts a block on an odd mi row with an 8-px-tall strip, and aomenc | ||
| 120 | +never picks one in any recipe swept. The 4-px `HORZ_4` strips aomenc *does* pick | ||
| 121 | +(a 16x16 split into four 16x4) all land **inside one mi row**, so four distinct | ||
| 122 | +blocks write the same cell and the last one wins — the column still reads as one | ||
| 123 | +run. | ||
| 124 | + | ||
| 125 | +### 3.4 Sweep | ||
| 126 | + | ||
| 127 | +Five recipe families, ~1000 successful encodes, all 4:2:0, all measured with | ||
| 128 | +`uv_left_ss_y_mode_diff_hits` / `..._smooth_diff_hits`: | ||
| 129 | + | ||
| 130 | +| sweep | sources | partition flags | cq | cpu-used | encodes | decode-path flips | | ||
| 131 | +|---|---|---|---|---|---|---| | ||
| 132 | +| 1 | testsrc2/testsrc/mandelbrot/gradients/cellauto 320x240 8-bit | default, `--lossless=1`, `rect+1to4+min4` | 20-60 | 0-4 | 240 | 0 | | ||
| 133 | +| 2 | same, 640x480 8-bit | `sb 32/64/128`, `max-part 8/16`, `min 4` | 18-50 | 0-4 | 360 | 0 | | ||
| 134 | +| 3 | same, 640x480 **10-bit** | same | 18-50 | 0-4 | 360 | 0 | | ||
| 135 | +| 4 | mixed flat/textured 320x480 10-bit, **vertical** edges | same | 20-44 | 0-3 | 240 | 0 | | ||
| 136 | +| 5 | mixed gradient/textured 320x240 10-bit, **horizontal** edges | same | 16-46 | 0-3 | 288 | 0 | | ||
| 137 | + | ||
| 138 | +Sweep 4 put the texture change in the wrong axis; sweep 5 corrected it (the | ||
| 139 | +comparison is a vertical pair, so it needs a *horizontal* content edge) and | ||
| 140 | +used gradients rather than constant colour, because on a constant region RDO | ||
| 141 | +picks `DC_PRED` (fewer bits) and `UV_SMOOTH_*` never wins — a stream can have | ||
| 142 | +smooth UV modes and still never put a smooth block against a non-smooth one in | ||
| 143 | +the same left column. Even at `--max-partition-size=8`, aomenc produced no | ||
| 144 | +odd-length runs (§3.3). | ||
| 145 | + | ||
| 146 | +## 4. Red / green | ||
| 147 | + | ||
| 148 | +There is no red→green at the pixel level, because the term is unreachable; the | ||
| 149 | +honest red/green is the corpus measurement and the counter. | ||
| 150 | + | ||
| 151 | +**Mutation (the read reverted to the pre-lane own-row cell):** output is | ||
| 152 | +byte-identical on all 35 committed fixtures that decode — measured ours-vs-ours | ||
| 153 | +through `dump_yuv` (u16 LE on both sides, so valid at 8, 10 and 12 bit; a | ||
| 154 | +dump-vs-`aomdec` cmp at 8 bit is not, and an early version of this lane's | ||
| 155 | +harness was wrong for exactly that reason). 35 identical / 0 changed. The six | ||
| 156 | +4:2:2 fixtures decode zero frames in both builds (the 4:2:2 refusal is | ||
| 157 | +unconditional in this tree; the `EC_AV1_ALLOW_422_PROBE` bypass is not | ||
| 158 | +committed), and they are a no-op by construction anyway (§1). | ||
| 159 | + | ||
| 160 | +**Oracle exactness (10-bit, `aomdec --rawvideo`, whole stream):** byte-exact | ||
| 161 | +before and after the change — | ||
| 162 | + | ||
| 163 | +| fixture | frames | pre-lane vs aomdec | with the `+ss_y` read | | ||
| 164 | +|---|---|---|---| | ||
| 165 | +| `gm_small_side_witness.obu` | 33 | exact | exact | | ||
| 166 | +| `reelb_kf900.obu` | 1 | exact | exact | | ||
| 167 | +| `reelb_ss300_key_frame.obu` | 1 | exact | exact | | ||
| 168 | +| `reelb_ss600_key_frame.obu` | 1 | exact | exact | | ||
| 169 | +| `reelc_kf2700.obu` | 1 | exact | exact | | ||
| 170 | +| `reelc_sb128_inter_witness.obu` | 15 | exact | exact | | ||
| 171 | +| `reelb_intra14_witness.obu` | 1 | exact | exact | | ||
| 172 | + | ||
| 173 | +**Non-discrimination, stated plainly:** because both reads agree on every | ||
| 174 | +committed fixture, the gate in §2 would still pass with the `+ss_y` term | ||
| 175 | +removed. It is a reach-and-exactness pin, not a mutation-proof pin. A gate that | ||
| 176 | +discriminates needs a stream that reaches the shape, and §3 is the search for | ||
| 177 | +it. `Agent14-3` independently re-ran their chroma-format battery on clean | ||
| 178 | +`4155c7c7` and on this build and saw no verdict move | ||
| 179 | +(`lanes/av1formatsweep.report.md`). | ||
| 180 | + | ||
| 181 | +## 5. Pre-existing defect found by the sweep, not fixed here | ||
| 182 | + | ||
| 183 | +`gradients=s=640x480` 10-bit, `--sb-size=64 --max-partition-size=16 | ||
| 184 | +--min-partition-size=4 --enable-1to4-partitions=1 --enable-rect-partitions=1 | ||
| 185 | +--lossless=1 --cq-level=34 --cpu-used=0` decodes into | ||
| 186 | +`decode.rs:2787: assertion left == right failed, left: (4, 8), right: (4, 4)`. | ||
| 187 | +It panics identically on the pre-lane and the shipped build, so it is not this | ||
| 188 | +lane's. Left for its owner. | ||
| 189 | + | ||
| 190 | +## 6. Unblock for a future round | ||
| 191 | + | ||
| 192 | +The shape needs a left neighbour that is 1 mi tall **and** whose vertical | ||
| 193 | +neighbour in the same mi column codes a different `uv_mode`. libaom only starts | ||
| 194 | +a block on an odd mi row via an 8-px strip, so the search should stop sweeping | ||
| 195 | +partition flags and start at the encoder's 1:4 path: a 32x32 `HORZ_4` into four | ||
| 196 | +32x8 strips puts strip origins on mi rows 0/1/2/3, which is the only geometry | ||
| 197 | +that produces a run of length 1. aomenc selected none of those in ~1000 encodes | ||
| 198 | +at `cpu-used=0` with `--enable-1to4-partitions=1`; the next thing to try is | ||
| 199 | +hand-constructing the partition tree (or an aomenc patch to force | ||
| 200 | +`PARTITION_HORZ_4` on 32x32), since the RDO simply never picks it. | ||
| 201 | + | ||
| 202 | +## State | ||
| 203 | + | ||
| 204 | +One commit on `lane-av1leftref`, nothing pushed. The `EC_LEFTSSY` diagnostic | ||
| 205 | +trace and the slice dumps are removed; what remains is the read, the | ||
| 206 | +`ss_y`/`decode_path` parameters, the three counters and the gate. | ||