Merge branch 'lane-superres': key-frame superres decodes pixel-exact (3/3 frames, superres_hits=3)
Browse files at this commit19 changed files +1739 -17
- crates/ec-av1/src/decode.rs +133 -11
- crates/ec-av1/src/gate_coverage.rs +26 -6
- crates/ec-av1/src/lib.rs +1 -0
- crates/ec-av1/src/refusal_inventory.rs +1 -0
- crates/ec-av1/src/stream.rs +258 -0
- crates/ec-av1/src/superres.rs +285 -0
- lanes/superres-r2.charter.md +86 -0
- lanes/superres-r3.charter.md +71 -0
- lanes/superres-r4.charter.md +35 -0
- lanes/superres-r4.report.md +93 -0
- lanes/superres-r5.charter.md +50 -0
- lanes/superres-r6.charter.md +32 -0
- lanes/superres-r6.report.md +87 -0
- lanes/superres-r7.charter.md +65 -0
- lanes/superres-r7.report.md +89 -0
- lanes/superres.charter.md +91 -0
- lanes/superres.report.md +78 -0
- scripts/instrument-aom-oracle.sh +114 -0
- scripts/superres-pin-harness.c +144 -0
crates/ec-av1/src/decode.rsmodified+133 -11
| @@ -4199,15 +4199,17 @@ fn apply_deblock( | |||
| 4199 | v: &mut PlaneBuf, | 4199 | v: &mut PlaneBuf, |
| 4200 | lf: &LoopFilterParams, | 4200 | lf: &LoopFilterParams, |
| 4201 | n: &Neighbours, | 4201 | n: &Neighbours, |
| 4202 | + frame_width: usize, | ||
| 4203 | + frame_height: usize, | ||
| 4202 | ) { | 4204 | ) { |
| 4203 | if lf.level[0] != 0 || lf.level[1] != 0 { | 4205 | if lf.level[0] != 0 || lf.level[1] != 0 { |
| 4204 | - deblock_plane(y, 0, lf, n); | 4206 | + deblock_plane(y, 0, lf, n, frame_width, frame_height); |
| 4205 | } | 4207 | } |
| 4206 | if lf.level[2] != 0 { | 4208 | if lf.level[2] != 0 { |
| 4207 | - deblock_plane(u, 1, lf, n); | 4209 | + deblock_plane(u, 1, lf, n, frame_width, frame_height); |
| 4208 | } | 4210 | } |
| 4209 | if lf.level[3] != 0 { | 4211 | if lf.level[3] != 0 { |
| 4210 | - deblock_plane(v, 2, lf, n); | 4212 | + deblock_plane(v, 2, lf, n, frame_width, frame_height); |
| 4211 | } | 4213 | } |
| 4212 | } | 4214 | } |
| 4213 | 4215 | ||
| @@ -4716,9 +4718,33 @@ fn filter_edge( | |||
| 4716 | 4718 | ||
| 4717 | /// One plane's worth of spec 7.14: every vertical edge across the plane, | 4719 | /// One plane's worth of spec 7.14: every vertical edge across the plane, |
| 4718 | /// then every horizontal edge (the order the spec and libaom both use). | 4720 | /// then every horizontal edge (the order the spec and libaom both use). |
| 4719 | -fn deblock_plane(plane: &mut PlaneBuf, plane_idx: usize, lf: &LoopFilterParams, n: &Neighbours) { | 4721 | +fn deblock_plane( |
| 4722 | + plane: &mut PlaneBuf, | ||
| 4723 | + plane_idx: usize, | ||
| 4724 | + lf: &LoopFilterParams, | ||
| 4725 | + n: &Neighbours, | ||
| 4726 | + frame_width: usize, | ||
| 4727 | + frame_height: usize, | ||
| 4728 | +) { | ||
| 4720 | let chroma = plane_idx != 0; | 4729 | let chroma = plane_idx != 0; |
| 4721 | - let (tw, th, stride) = (plane.true_width, plane.true_height, plane.width); | 4730 | + // r7: libaom clips the deblock loop to the CODED frame's own |
| 4731 | + // width/height, not the mi-aligned `true_width`/`true_height` margin | ||
| 4732 | + // (the padding up to the next 8-pixel/superblock boundary that | ||
| 4733 | + // reconstruction still fills in but the loop filter never visits). | ||
| 4734 | + // Confirmed against the superres gate: with the margin included, the | ||
| 4735 | + // last coded mi column's horizontal edges were filtered when libaom's | ||
| 4736 | + // real output leaves them untouched (r6's post-deblock diff, 37 px, all | ||
| 4737 | + // in columns 44-47); clipping here closes it (3/3 frames pixel-exact). | ||
| 4738 | + let (cw, ch) = if chroma { | ||
| 4739 | + (frame_width.div_ceil(2), frame_height.div_ceil(2)) | ||
| 4740 | + } else { | ||
| 4741 | + (frame_width, frame_height) | ||
| 4742 | + }; | ||
| 4743 | + let (tw, th, stride) = ( | ||
| 4744 | + plane.true_width.min(cw), | ||
| 4745 | + plane.true_height.min(ch), | ||
| 4746 | + plane.width, | ||
| 4747 | + ); | ||
| 4722 | let mut y0 = 0usize; | 4748 | let mut y0 = 0usize; |
| 4723 | while y0 < th { | 4749 | while y0 < th { |
| 4724 | let mut x0 = 4usize; | 4750 | let mut x0 = 4usize; |
| @@ -4743,6 +4769,15 @@ fn deblock_plane(plane: &mut PlaneBuf, plane_idx: usize, lf: &LoopFilterParams, | |||
| 4743 | let mut y0 = 4usize; | 4769 | let mut y0 = 4usize; |
| 4744 | while y0 < th { | 4770 | while y0 < th { |
| 4745 | if let Some((len, level)) = edge_params(lf, n, plane_idx, 1, chroma, x0, y0) { | 4771 | if let Some((len, level)) = edge_params(lf, n, plane_idx, 1, chroma, x0, y0) { |
| 4772 | + if std::env::var_os("EC_AV1_DEBLOCK_TRACE").is_some() | ||
| 4773 | + && plane_idx == 0 | ||
| 4774 | + && x0 == 44 | ||
| 4775 | + { | ||
| 4776 | + eprintln!( | ||
| 4777 | + "HEDGE x0={x0} y0={y0} len={len} level={level} sharpness={}", | ||
| 4778 | + lf.sharpness | ||
| 4779 | + ); | ||
| 4780 | + } | ||
| 4746 | filter_edge( | 4781 | filter_edge( |
| 4747 | &mut plane.data, | 4782 | &mut plane.data, |
| 4748 | y0 * stride + x0, | 4783 | y0 * stride + x0, |
| @@ -4946,6 +4981,23 @@ pub fn decode_key_frame_tile( | |||
| 4946 | .map(|(picture, _)| picture) | 4981 | .map(|(picture, _)| picture) |
| 4947 | } | 4982 | } |
| 4948 | 4983 | ||
| 4984 | +thread_local! { | ||
| 4985 | + /// lane-superres r3: the real decoded margin beyond `frame_width` up to | ||
| 4986 | + /// the mi-aligned `true_width`, set by the most recent | ||
| 4987 | + /// [`decode_key_frame_tile_with_cdfs`] call. See that function's own | ||
| 4988 | + /// comment at the write site. `None` when there was no margin to save. | ||
| 4989 | + static LAST_KEY_FRAME_WIDE_MARGIN: std::cell::RefCell<Option<Picture>> = | ||
| 4990 | + const { std::cell::RefCell::new(None) }; | ||
| 4991 | +} | ||
| 4992 | + | ||
| 4993 | +/// The margin [`decode_key_frame_tile_with_cdfs`] most recently stashed | ||
| 4994 | +/// (see [`LAST_KEY_FRAME_WIDE_MARGIN`]) -- `stream.rs`'s superres path | ||
| 4995 | +/// reads this immediately after the call, before any other key frame | ||
| 4996 | +/// decode can overwrite it. | ||
| 4997 | +pub(crate) fn take_last_key_frame_wide_margin() -> Option<Picture> { | ||
| 4998 | + LAST_KEY_FRAME_WIDE_MARGIN.with(|m| m.borrow_mut().take()) | ||
| 4999 | +} | ||
| 5000 | + | ||
| 4949 | /// [`decode_key_frame_tile`], threading a cross-frame CDF forward (spec | 5001 | /// [`decode_key_frame_tile`], threading a cross-frame CDF forward (spec |
| 4950 | /// 7.20's `load_cdfs`): `initial_cdfs` is the caller's forwarded state (from | 5002 | /// 7.20's `load_cdfs`): `initial_cdfs` is the caller's forwarded state (from |
| 4951 | /// a prior frame's saved reference slot) when set, or the spec 8.4 defaults | 5003 | /// a prior frame's saved reference slot) when set, or the spec 8.4 defaults |
| @@ -5529,11 +5581,37 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5529 | } else { | 5581 | } else { |
| 5530 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 5582 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 5531 | } | 5583 | } |
| 5532 | - apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | 5584 | + if let Ok(path) = std::env::var("EC_AV1_PREFILT_WIDE_DUMP") { |
| 5585 | + use std::io::Write; | ||
| 5586 | + static IDX2: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 5587 | + let idx = IDX2.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | ||
| 5588 | + let crop_wide = |plane: &PlaneBuf| -> Vec<u8> { | ||
| 5589 | + let mut out = Vec::with_capacity(plane.true_width * plane.true_height); | ||
| 5590 | + for row in 0..plane.true_height { | ||
| 5591 | + out.extend_from_slice(&plane.data[row * plane.width..][..plane.true_width]); | ||
| 5592 | + } | ||
| 5593 | + out | ||
| 5594 | + }; | ||
| 5595 | + if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | ||
| 5596 | + let _ = f.write_all(&crop_wide(&y)); | ||
| 5597 | + let _ = f.write_all(&crop_wide(&u)); | ||
| 5598 | + let _ = f.write_all(&crop_wide(&v)); | ||
| 5599 | + } | ||
| 5600 | + } | ||
| 5601 | + apply_deblock( | ||
| 5602 | + &mut y, | ||
| 5603 | + &mut u, | ||
| 5604 | + &mut v, | ||
| 5605 | + loop_filter, | ||
| 5606 | + &neighbours, | ||
| 5607 | + frame_width as usize, | ||
| 5608 | + frame_height as usize, | ||
| 5609 | + ); | ||
| 5533 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); | 5610 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 5534 | 5611 | ||
| 5535 | let (fw, fh) = (frame_width as usize, frame_height as usize); | 5612 | let (fw, fh) = (frame_width as usize, frame_height as usize); |
| 5536 | if fw == width && fh == height { | 5613 | if fw == width && fh == height { |
| 5614 | + LAST_KEY_FRAME_WIDE_MARGIN.with(|m| *m.borrow_mut() = None); | ||
| 5537 | return Ok(( | 5615 | return Ok(( |
| 5538 | Picture { | 5616 | Picture { |
| 5539 | width, | 5617 | width, |
| @@ -5552,13 +5630,49 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 5552 | } | 5630 | } |
| 5553 | out | 5631 | out |
| 5554 | }; | 5632 | }; |
| 5633 | + // lane-superres r3: `true_width`/`true_height` (`mi_cols`/`mi_rows` * 4) | ||
| 5634 | + // is the real reconstructed extent -- columns `[fw, true_width)` hold | ||
| 5635 | + // genuine decoded samples (the last coding block straddles the frame | ||
| 5636 | + // edge whenever `frame_width` isn't 8-sample aligned), not padding. | ||
| 5637 | + // libaom's superres upscale runs on that buffer's own border-extended | ||
| 5638 | + // margin, so it reads those real columns, not a synthetic replicate of | ||
| 5639 | + // column `fw - 1`. Stash them for `stream.rs`'s superres path (a real | ||
| 5640 | + // aomenc 43->64 stream pinned column-by-column against libaom's own | ||
| 5641 | + // `av1_convolve_horiz_rs_c` via `scripts/superres-pin-harness.c` -- | ||
| 5642 | + // `row6-realedgeval` proved the replicate-of-`fw-1` padding this | ||
| 5643 | + // decoder used before was off by 1 at the columns the tap window | ||
| 5644 | + // reaches into that real margin; `None` when there is no margin (this | ||
| 5645 | + // frame's `true_width`/`true_height` already equal `fw`/`fh`, e.g. a | ||
| 5646 | + // non-superres frame whose width just isn't 32-block aligned). | ||
| 5647 | + LAST_KEY_FRAME_WIDE_MARGIN.with(|m| { | ||
| 5648 | + *m.borrow_mut() = if true_width > fw || true_height > fh { | ||
| 5649 | + let yc = crop(&y, true_width, true_height); | ||
| 5650 | + if let Ok(path) = std::env::var("EC_AV1_MARGIN_DUMP") { | ||
| 5651 | + use std::io::Write; | ||
| 5652 | + static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 5653 | + let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | ||
| 5654 | + if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { | ||
| 5655 | + let _ = f.write_all(&yc); | ||
| 5656 | + } | ||
| 5657 | + } | ||
| 5658 | + Some(Picture { | ||
| 5659 | + width: true_width, | ||
| 5660 | + height: true_height, | ||
| 5661 | + y: yc, | ||
| 5662 | + u: crop(&u, true_width.div_ceil(2), true_height.div_ceil(2)), | ||
| 5663 | + v: crop(&v, true_width.div_ceil(2), true_height.div_ceil(2)), | ||
| 5664 | + }) | ||
| 5665 | + } else { | ||
| 5666 | + None | ||
| 5667 | + } | ||
| 5668 | + }); | ||
| 5555 | Ok(( | 5669 | Ok(( |
| 5556 | Picture { | 5670 | Picture { |
| 5557 | width: fw, | 5671 | width: fw, |
| 5558 | height: fh, | 5672 | height: fh, |
| 5559 | y: crop(&y, fw, fh), | 5673 | y: crop(&y, fw, fh), |
| 5560 | - u: crop(&u, fw / 2, fh / 2), | 5674 | + u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)), |
| 5561 | - v: crop(&v, fw / 2, fh / 2), | 5675 | + v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)), |
| 5562 | }, | 5676 | }, |
| 5563 | result_cdfs, | 5677 | result_cdfs, |
| 5564 | )) | 5678 | )) |
| @@ -11227,7 +11341,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 11227 | } else { | 11341 | } else { |
| 11228 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 11342 | PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 11229 | } | 11343 | } |
| 11230 | - apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | 11344 | + apply_deblock( |
| 11345 | + &mut y, | ||
| 11346 | + &mut u, | ||
| 11347 | + &mut v, | ||
| 11348 | + loop_filter, | ||
| 11349 | + &neighbours, | ||
| 11350 | + frame_width as usize, | ||
| 11351 | + frame_height as usize, | ||
| 11352 | + ); | ||
| 11231 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); | 11353 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 11232 | 11354 | ||
| 11233 | let motion_field = build_motion_field( | 11355 | let motion_field = build_motion_field( |
| @@ -11264,8 +11386,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 11264 | width: fw, | 11386 | width: fw, |
| 11265 | height: fh, | 11387 | height: fh, |
| 11266 | y: crop(&y, fw, fh), | 11388 | y: crop(&y, fw, fh), |
| 11267 | - u: crop(&u, fw / 2, fh / 2), | 11389 | + u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)), |
| 11268 | - v: crop(&v, fw / 2, fh / 2), | 11390 | + v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)), |
| 11269 | }, | 11391 | }, |
| 11270 | result_cdfs, | 11392 | result_cdfs, |
| 11271 | motion_field, | 11393 | motion_field, |
crates/ec-av1/src/gate_coverage.rsmodified+26 -6
| @@ -18,8 +18,16 @@ | |||
| 18 | //! feature's gate, which shrinks the derived set and fails this test until the | 18 | //! feature's gate, which shrinks the derived set and fails this test until the |
| 19 | //! list is updated -- the point being that the shrink is noticed. | 19 | //! list is updated -- the point being that the shrink is noticed. |
| 20 | 20 | ||
| 21 | -/// aomenc coding tools that no real-`aomenc` gate exercises: switched off in | 21 | +/// aomenc coding tools that no real-`aomenc` gate is proven to exercise: |
| 22 | -/// every gate that names them, on in none, defaulted in none. | 22 | +/// switched off in every gate that names them, and on in none. |
| 23 | +/// | ||
| 24 | +/// A gate that simply leaves the flag off its command line does NOT close the | ||
| 25 | +/// hole. aomenc's default for these is content-dependent -- palette and | ||
| 26 | +/// intrabc only come on for screen content -- so "defaulted" means "unknown", | ||
| 27 | +/// not "exercised", and treating it as coverage would retire the entry | ||
| 28 | +/// without a single stream proving the decoder ever saw the tool. Only an | ||
| 29 | +/// explicit `--enable-<tool>=1` in a gate that then asserts the feature fired | ||
| 30 | +/// closes one. | ||
| 23 | /// | 31 | /// |
| 24 | /// Each entry is `(flag, why)`. Removing an entry is how a lane records that | 32 | /// Each entry is `(flag, why)`. Removing an entry is how a lane records that |
| 25 | /// its tool is now covered by a real stream. | 33 | /// its tool is now covered by a real stream. |
| @@ -72,11 +80,23 @@ mod tests { | |||
| 72 | #[test] | 80 | #[test] |
| 73 | fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() { | 81 | fn every_gate_disabling_a_tool_is_a_listed_coverage_hole() { |
| 74 | let (gate_count, per_tool) = tool_settings(); | 82 | let (gate_count, per_tool) = tool_settings(); |
| 83 | + // A hole OPENS when every gate names the flag and every one of them | ||
| 84 | + // says 0 -- then no real stream can exercise the tool. | ||
| 75 | let derived: BTreeSet<&str> = per_tool | 85 | let derived: BTreeSet<&str> = per_tool |
| 76 | .iter() | 86 | .iter() |
| 77 | .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0) | 87 | .filter(|&(_, &(off, on, defaulted))| off == gate_count && on == 0 && defaulted == 0) |
| 78 | .map(|(name, _)| name.as_str()) | 88 | .map(|(name, _)| name.as_str()) |
| 79 | .collect(); | 89 | .collect(); |
| 90 | + // A hole CLOSES only on positive evidence: some gate passes `=1`. | ||
| 91 | + // A gate that merely leaves the flag off its command line proves | ||
| 92 | + // nothing -- aomenc's default for palette and intrabc is content- | ||
| 93 | + // dependent -- so "defaulted" must not retire an entry, or a listing | ||
| 94 | + // would disappear the moment an unrelated gate is added. | ||
| 95 | + let exercised: BTreeSet<&str> = per_tool | ||
| 96 | + .iter() | ||
| 97 | + .filter(|&(_, &(_, on, _))| on > 0) | ||
| 98 | + .map(|(name, _)| name.as_str()) | ||
| 99 | + .collect(); | ||
| 80 | let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect(); | 100 | let listed: BTreeSet<&str> = NEVER_EXERCISED.iter().map(|&(flag, _)| flag).collect(); |
| 81 | 101 | ||
| 82 | let unlisted: Vec<&&str> = derived.difference(&listed).collect(); | 102 | let unlisted: Vec<&&str> = derived.difference(&listed).collect(); |
| @@ -84,13 +104,13 @@ mod tests { | |||
| 84 | unlisted.is_empty(), | 104 | unlisted.is_empty(), |
| 85 | "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \ | 105 | "these aomenc tools are switched off in all {gate_count} real-aomenc gates and on in \ |
| 86 | none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \ | 106 | none, so no real stream exercises them, and they are not listed in NEVER_EXERCISED: \ |
| 87 | - {unlisted:?} -- either enable the tool in its own gate or add it to the list with a \ | 107 | + {unlisted:?} -- either enable the tool with `=1` in its own gate or add it to the \ |
| 88 | - reason" | 108 | + list with a reason" |
| 89 | ); | 109 | ); |
| 90 | - let stale: Vec<&&str> = listed.difference(&derived).collect(); | 110 | + let stale: Vec<&&str> = listed.intersection(&exercised).collect(); |
| 91 | assert!( | 111 | assert!( |
| 92 | stale.is_empty(), | 112 | stale.is_empty(), |
| 93 | - "NEVER_EXERCISED lists {stale:?}, but a gate now enables or defaults them -- delete \ | 113 | + "NEVER_EXERCISED lists {stale:?}, but a gate now passes `=1` for them -- delete \ |
| 94 | those entries, the coverage hole is closed" | 114 | those entries, the coverage hole is closed" |
| 95 | ); | 115 | ); |
| 96 | } | 116 | } |
crates/ec-av1/src/lib.rsmodified+1 -0
| @@ -32,6 +32,7 @@ pub mod obu; | |||
| 32 | pub mod quant; | 32 | pub mod quant; |
| 33 | mod refusal_inventory; | 33 | mod refusal_inventory; |
| 34 | pub mod sequence; | 34 | pub mod sequence; |
| 35 | +mod superres; | ||
| 35 | pub mod stream; | 36 | pub mod stream; |
| 36 | pub mod tile; | 37 | pub mod tile; |
| 37 | pub mod transform; | 38 | pub mod transform; |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -0
| @@ -42,6 +42,7 @@ const REFUSALS: &[&str] = &[ | |||
| 42 | "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", | 42 | "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", |
| 43 | "a tx_type symbol outside its CDF's own set: {t}", | 43 | "a tx_type symbol outside its CDF's own set: {t}", |
| 44 | "an INTER 32x32 partition type this decoder does not code (value={part32})", | 44 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 45 | + "an inter frame with use_superres set (this decoder never scales its motion-compensated reference to match the current frame's downscaled size, spec 7.11.3.3)", | ||
| 45 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", | 46 | "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", |
| 46 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", | 47 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 47 | "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", | 48 | "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", |
crates/ec-av1/src/stream.rsmodified+258 -0
| @@ -200,6 +200,26 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 200 | "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", | 200 | "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", |
| 201 | )); | 201 | )); |
| 202 | } | 202 | } |
| 203 | + // lane-superres stage 2/3: `use_superres` adds/removes no per-block | ||
| 204 | + // symbol (spec 7.16's upscaling is a pixel-domain post-process | ||
| 205 | + // libaom's `decodeframe.c` runs between CDEF and loop restoration, | ||
| 206 | + // `av1_upscale_normative_*` in `resize.c`), so a key frame's tile | ||
| 207 | + // reads stay bit-exact in sync and `crate::superres::upscale_picture` | ||
| 208 | + // (below, after decode) makes its `Picture` the spec-correct | ||
| 209 | + // `upscaled_width` instead of silently staying at `frame_width`. | ||
| 210 | + // An INTER frame under `use_superres` still refuses: its reference | ||
| 211 | + // is stored upscaled while the current frame decodes at the | ||
| 212 | + // downscaled `frame_width`, so `decode_inter_frame_tile_with_cdfs`'s | ||
| 213 | + // motion compensation would sample a reference at the wrong scale | ||
| 214 | + // (spec 7.11.3.3's scaled-reference path is not ported) -- | ||
| 215 | + // SILENT WRONGNESS, not a desync, same as the key-frame case used | ||
| 216 | + // to be. Left for a later stage of this lane. | ||
| 217 | + if header.use_superres && header.frame_type != FrameType::Key { | ||
| 218 | + return Err(Error::unsupported( | ||
| 219 | + "AV1 decode_stream", | ||
| 220 | + "an inter frame with use_superres set (this decoder never scales its motion-compensated reference to match the current frame's downscaled size, spec 7.11.3.3)", | ||
| 221 | + )); | ||
| 222 | + } | ||
| 203 | // Loop restoration carries per-restoration-unit symbols in the tile | 223 | // Loop restoration carries per-restoration-unit symbols in the tile |
| 204 | // (spec 5.11.57 `read_lr`, one group per LR unit reached from the | 224 | // (spec 5.11.57 `read_lr`, one group per LR unit reached from the |
| 205 | // superblock walk) that this decoder never reads -- same | 225 | // superblock walk) that this decoder never reads -- same |
| @@ -416,6 +436,24 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 416 | header.allow_intrabc, | 436 | header.allow_intrabc, |
| 417 | header.delta, | 437 | header.delta, |
| 418 | )?; | 438 | )?; |
| 439 | + // lane-superres stage 3, spec 7.16: upscale AFTER deblock+CDEF | ||
| 440 | + // (both already applied inside `decode_key_frame_tile_with_cdfs`) | ||
| 441 | + // and BEFORE this picture is stored as a reference or handed to | ||
| 442 | + // the caller -- loop restoration is not yet ported, so there is | ||
| 443 | + // no LR step here for the upscale to precede. | ||
| 444 | + // r3: the real decoded margin beyond `frame_width` (set by the | ||
| 445 | + // call above, right before anything else can overwrite it) -- | ||
| 446 | + // see `decode::take_last_key_frame_wide_margin`'s doc. | ||
| 447 | + let wide_margin = crate::decode::take_last_key_frame_wide_margin(); | ||
| 448 | + let picture = if header.use_superres { | ||
| 449 | + crate::superres::upscale_picture( | ||
| 450 | + &picture, | ||
| 451 | + header.upscaled_width as usize, | ||
| 452 | + wide_margin.as_ref(), | ||
| 453 | + ) | ||
| 454 | + } else { | ||
| 455 | + picture | ||
| 456 | + }; | ||
| 419 | // A key frame codes no inter blocks -- its own saved motion | 457 | // A key frame codes no inter blocks -- its own saved motion |
| 420 | // field has no cells set, matching libaom's own "intra frame | 458 | // field has no cells set, matching libaom's own "intra frame |
| 421 | // contributes nothing to a later projection" behaviour, but | 459 | // contributes nothing to a later projection" behaviour, but |
| @@ -3991,6 +4029,226 @@ mod tests { | |||
| 3991 | ); | 4029 | ); |
| 3992 | } | 4030 | } |
| 3993 | 4031 | ||
| 4032 | + /// lane-superres Step 0/stage 1: a real aomenc `--superres-mode=1` | ||
| 4033 | + /// stream must refuse BY NAME (`use_superres`), never desync into a | ||
| 4034 | + /// different error and never silently decode a wrong-sized picture. | ||
| 4035 | + /// `use_superres` adds no per-block symbol (spec 7.16's upscaler is a | ||
| 4036 | + /// pixel-domain post-process), so before the stream.rs refusal landed | ||
| 4037 | + /// this crate's tile readers stayed bit-exact in sync but stored the | ||
| 4038 | + /// `Picture` at the downscaled `frame_width` instead of | ||
| 4039 | + /// `upscaled_width` -- exactly the SILENT WRONGNESS the charter's Step 0 | ||
| 4040 | + /// called for turning into an explicit refusal first. | ||
| 4041 | + #[test] | ||
| 4042 | + fn a_real_aomenc_stream_with_superres_refuses_by_name() { | ||
| 4043 | + const NAME: &str = "a_real_aomenc_stream_with_superres_refuses_by_name"; | ||
| 4044 | + let _gate_lock = lock_gate_counters(); | ||
| 4045 | + if !have_ffmpeg() { | ||
| 4046 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 4047 | + return; | ||
| 4048 | + } | ||
| 4049 | + if !have_aomenc() { | ||
| 4050 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 4051 | + return; | ||
| 4052 | + } | ||
| 4053 | + let (width, height, frame_count) = (64usize, 64usize, 4usize); | ||
| 4054 | + let duration = frame_count as f64 / 25.0; | ||
| 4055 | + let source = gradients_source(42, width, height, &format!("duration={duration}:rate=25")); | ||
| 4056 | + let y4m = Command::new("ffmpeg") | ||
| 4057 | + .args([ | ||
| 4058 | + "-v", | ||
| 4059 | + "error", | ||
| 4060 | + "-f", | ||
| 4061 | + "lavfi", | ||
| 4062 | + "-i", | ||
| 4063 | + &source, | ||
| 4064 | + "-pix_fmt", | ||
| 4065 | + "yuv420p", | ||
| 4066 | + "-f", | ||
| 4067 | + "yuv4mpegpipe", | ||
| 4068 | + "-", | ||
| 4069 | + ]) | ||
| 4070 | + .stdin(Stdio::null()) | ||
| 4071 | + .stdout(Stdio::piped()) | ||
| 4072 | + .stderr(Stdio::piped()) | ||
| 4073 | + .output() | ||
| 4074 | + .expect("ffmpeg failed to run"); | ||
| 4075 | + assert!( | ||
| 4076 | + y4m.status.success(), | ||
| 4077 | + "ffmpeg fixture: {}", | ||
| 4078 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 4079 | + ); | ||
| 4080 | + let args: Vec<&str> = vec![ | ||
| 4081 | + "--codec=av1", | ||
| 4082 | + "--passes=1", | ||
| 4083 | + "--end-usage=q", | ||
| 4084 | + "--cq-level=32", | ||
| 4085 | + "--cpu-used=0", | ||
| 4086 | + "--kf-max-dist=1000", | ||
| 4087 | + "--threads=1", | ||
| 4088 | + "--row-mt=0", | ||
| 4089 | + "--superres-mode=1", | ||
| 4090 | + "--superres-denominator=12", | ||
| 4091 | + "--obu", | ||
| 4092 | + "-o", | ||
| 4093 | + "-", | ||
| 4094 | + "-", | ||
| 4095 | + ]; | ||
| 4096 | + let mut child = Command::new(aomenc_path()) | ||
| 4097 | + .args(&args) | ||
| 4098 | + .stdin(Stdio::piped()) | ||
| 4099 | + .stdout(Stdio::piped()) | ||
| 4100 | + .stderr(Stdio::piped()) | ||
| 4101 | + .spawn() | ||
| 4102 | + .expect("aomenc failed to start"); | ||
| 4103 | + child | ||
| 4104 | + .stdin | ||
| 4105 | + .take() | ||
| 4106 | + .expect("aomenc stdin") | ||
| 4107 | + .write_all(&y4m.stdout) | ||
| 4108 | + .expect("writing y4m to aomenc"); | ||
| 4109 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 4110 | + assert!( | ||
| 4111 | + out.status.success(), | ||
| 4112 | + "aomenc refused the fixture: {}", | ||
| 4113 | + String::from_utf8_lossy(&out.stderr) | ||
| 4114 | + ); | ||
| 4115 | + let stream = out.stdout; | ||
| 4116 | + let err = decode_stream(&stream).expect_err( | ||
| 4117 | + "a real --superres-mode=1 stream must refuse -- superres decode is not implemented \ | ||
| 4118 | + and silently produces a wrong-sized picture otherwise", | ||
| 4119 | + ); | ||
| 4120 | + let msg = err.to_string(); | ||
| 4121 | + assert!( | ||
| 4122 | + msg.contains("use_superres"), | ||
| 4123 | + "{NAME}: refused, but not by the superres name -- this stream desynced into a \ | ||
| 4124 | + different refusal instead: {msg}" | ||
| 4125 | + ); | ||
| 4126 | + eprintln!("{NAME}: refused by name: {msg}"); | ||
| 4127 | + } | ||
| 4128 | + | ||
| 4129 | + /// lane-superres stage 3: a real aomenc `--superres-mode=1` key-frame | ||
| 4130 | + /// sequence must decode pixel-exact vs ffmpeg/dav1d's own upscaled | ||
| 4131 | + /// output, and must actually run [`crate::superres::upscale_picture`] | ||
| 4132 | + /// (`superres_hits > 0`) -- a decoder that silently stopped upscaling | ||
| 4133 | + /// would otherwise pass vacuously (class `gate-blind-to-feature`). | ||
| 4134 | + /// `--kf-max-dist` set to the frame count keeps every frame a key | ||
| 4135 | + /// frame: inter-frame superres (a differently-scaled reference) is a | ||
| 4136 | + /// later stage of this lane, refused by name today. | ||
| 4137 | + #[test] | ||
| 4138 | + fn a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact() { | ||
| 4139 | + const NAME: &str = "a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact"; | ||
| 4140 | + let _gate_lock = lock_gate_counters(); | ||
| 4141 | + if !have_ffmpeg() { | ||
| 4142 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 4143 | + return; | ||
| 4144 | + } | ||
| 4145 | + if !have_aomenc() { | ||
| 4146 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 4147 | + return; | ||
| 4148 | + } | ||
| 4149 | + let (width, height, frame_count) = (64usize, 64usize, 3usize); | ||
| 4150 | + let duration = frame_count as f64 / 25.0; | ||
| 4151 | + let source = gradients_source(7, width, height, &format!("duration={duration}:rate=25")); | ||
| 4152 | + let y4m = Command::new("ffmpeg") | ||
| 4153 | + .args([ | ||
| 4154 | + "-v", | ||
| 4155 | + "error", | ||
| 4156 | + "-f", | ||
| 4157 | + "lavfi", | ||
| 4158 | + "-i", | ||
| 4159 | + &source, | ||
| 4160 | + "-pix_fmt", | ||
| 4161 | + "yuv420p", | ||
| 4162 | + "-f", | ||
| 4163 | + "yuv4mpegpipe", | ||
| 4164 | + "-", | ||
| 4165 | + ]) | ||
| 4166 | + .stdin(Stdio::null()) | ||
| 4167 | + .stdout(Stdio::piped()) | ||
| 4168 | + .stderr(Stdio::piped()) | ||
| 4169 | + .output() | ||
| 4170 | + .expect("ffmpeg failed to run"); | ||
| 4171 | + assert!( | ||
| 4172 | + y4m.status.success(), | ||
| 4173 | + "ffmpeg fixture: {}", | ||
| 4174 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 4175 | + ); | ||
| 4176 | + let args: Vec<&str> = vec![ | ||
| 4177 | + "--codec=av1", | ||
| 4178 | + "--passes=1", | ||
| 4179 | + "--end-usage=q", | ||
| 4180 | + "--cq-level=32", | ||
| 4181 | + "--cpu-used=0", | ||
| 4182 | + "--kf-max-dist=0", | ||
| 4183 | + "--threads=1", | ||
| 4184 | + "--row-mt=0", | ||
| 4185 | + "--superres-mode=1", | ||
| 4186 | + "--superres-denominator=12", | ||
| 4187 | + "--superres-kf-denominator=12", | ||
| 4188 | + "--enable-rect-partitions=0", | ||
| 4189 | + "--enable-ab-partitions=0", | ||
| 4190 | + "--enable-1to4-partitions=0", | ||
| 4191 | + "--enable-filter-intra=0", | ||
| 4192 | + "--enable-smooth-intra=0", | ||
| 4193 | + "--enable-paeth-intra=0", | ||
| 4194 | + "--enable-directional-intra=0", | ||
| 4195 | + "--enable-angle-delta=0", | ||
| 4196 | + "--enable-tx-size-search=0", | ||
| 4197 | + "--enable-cdef=0", | ||
| 4198 | + "--enable-restoration=0", | ||
| 4199 | + "--max-partition-size=32", | ||
| 4200 | + "--min-partition-size=32", | ||
| 4201 | + "--enable-palette=0", | ||
| 4202 | + "--enable-intrabc=0", | ||
| 4203 | + "--enable-cfl-intra=0", | ||
| 4204 | + "--obu", | ||
| 4205 | + "-o", | ||
| 4206 | + "-", | ||
| 4207 | + "-", | ||
| 4208 | + ]; | ||
| 4209 | + let mut child = Command::new(aomenc_path()) | ||
| 4210 | + .args(&args) | ||
| 4211 | + .stdin(Stdio::piped()) | ||
| 4212 | + .stdout(Stdio::piped()) | ||
| 4213 | + .stderr(Stdio::piped()) | ||
| 4214 | + .spawn() | ||
| 4215 | + .expect("aomenc failed to start"); | ||
| 4216 | + child | ||
| 4217 | + .stdin | ||
| 4218 | + .take() | ||
| 4219 | + .expect("aomenc stdin") | ||
| 4220 | + .write_all(&y4m.stdout) | ||
| 4221 | + .expect("writing y4m to aomenc"); | ||
| 4222 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 4223 | + assert!( | ||
| 4224 | + out.status.success(), | ||
| 4225 | + "aomenc refused the fixture: {}", | ||
| 4226 | + String::from_utf8_lossy(&out.stderr) | ||
| 4227 | + ); | ||
| 4228 | + let stream = out.stdout; | ||
| 4229 | + if let Ok(path) = std::env::var("EC_SUPERRES_STREAM_DUMP") { | ||
| 4230 | + std::fs::write(path, &stream).expect("dump stream"); | ||
| 4231 | + } | ||
| 4232 | + let frames = | ||
| 4233 | + decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); | ||
| 4234 | + assert_eq!(frames.len(), frame_count); | ||
| 4235 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | ||
| 4236 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 4237 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg"); | ||
| 4238 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg"); | ||
| 4239 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg"); | ||
| 4240 | + } | ||
| 4241 | + assert!( | ||
| 4242 | + crate::superres::superres_hits() > 0, | ||
| 4243 | + "{NAME}: matched but zero superres_hits -- the gate never actually exercised the \ | ||
| 4244 | + upscaler, it proves nothing" | ||
| 4245 | + ); | ||
| 4246 | + eprintln!( | ||
| 4247 | + "{NAME}: {frame_count} frames pixel-exact, superres_hits={}", | ||
| 4248 | + crate::superres::superres_hits() | ||
| 4249 | + ); | ||
| 4250 | + } | ||
| 4251 | + | ||
| 3994 | /// lane-interintra r1: `--enable-interintra-comp=1` streams must DECODE | 4252 | /// lane-interintra r1: `--enable-interintra-comp=1` streams must DECODE |
| 3995 | /// pixel-exact -- the interintra flag/mode/wedge-flag syntax and the | 4253 | /// pixel-exact -- the interintra flag/mode/wedge-flag syntax and the |
| 3996 | /// non-wedge smooth blend are ported. A refusal naming interintra fails | 4254 | /// non-wedge smooth blend are ported. A refusal naming interintra fails |
crates/ec-av1/src/superres.rsadded+285 -0
| @@ -0,0 +1,285 @@ | |||
| 1 | +//! AV1 spec 7.16 upscaling process (`av1_upscale_normative_rows` in | ||
| 2 | +//! libaom's `av1/common/resize.c`) -- the horizontal-only linear-filter | ||
| 3 | +//! upscale that runs on the decoded frame after deblocking and CDEF (and, | ||
| 4 | +//! once this crate supports loop restoration, BEFORE it -- libaom's | ||
| 5 | +//! `decodeframe.c` calls `superres_post_decode()` between `av1_cdef_frame` | ||
| 6 | +//! and `av1_loop_restoration_filter_frame`, not after LR; the charter's | ||
| 7 | +//! anchor note that superres runs "after loop restoration" does not match | ||
| 8 | +//! the source and is corrected here). | ||
| 9 | +//! | ||
| 10 | +//! Every constant and the 64x8 `av1_resize_filter_normative` coefficient | ||
| 11 | +//! table below is copied verbatim from libaom `aom_dsp/aom_filter.h` and | ||
| 12 | +//! `av1/common/resize.c` (`AOM_VERSION=v3.13.3`, `~/.cache/aom-oracle`). | ||
| 13 | + | ||
| 14 | +/// `RS_SUBPEL_BITS`. | ||
| 15 | +const RS_SUBPEL_BITS: u32 = 6; | ||
| 16 | +/// `RS_SCALE_SUBPEL_BITS`. | ||
| 17 | +const RS_SCALE_SUBPEL_BITS: u32 = 14; | ||
| 18 | +/// `RS_SCALE_SUBPEL_MASK`. | ||
| 19 | +const RS_SCALE_SUBPEL_MASK: i64 = (1i64 << RS_SCALE_SUBPEL_BITS) - 1; | ||
| 20 | +/// `RS_SCALE_EXTRA_BITS`. | ||
| 21 | +const RS_SCALE_EXTRA_BITS: u32 = RS_SCALE_SUBPEL_BITS - RS_SUBPEL_BITS; | ||
| 22 | +/// `RS_SCALE_EXTRA_OFF`. | ||
| 23 | +const RS_SCALE_EXTRA_OFF: i64 = 1i64 << (RS_SCALE_EXTRA_BITS - 1); | ||
| 24 | +/// `UPSCALE_NORMATIVE_TAPS`. | ||
| 25 | +const UPSCALE_NORMATIVE_TAPS: usize = 8; | ||
| 26 | +/// `FILTER_BITS`. | ||
| 27 | +const FILTER_BITS: u32 = 7; | ||
| 28 | + | ||
| 29 | +/// `av1_resize_filter_normative`, libaom `av1/common/resize.c`. 64 subpel | ||
| 30 | +/// phases x 8 taps. | ||
| 31 | +#[rustfmt::skip] | ||
| 32 | +const RESIZE_FILTER_NORMATIVE: [[i16; UPSCALE_NORMATIVE_TAPS]; 1 << RS_SUBPEL_BITS] = [ | ||
| 33 | + [0, 0, 0, 128, 0, 0, 0, 0], [0, 0, -1, 128, 2, -1, 0, 0], | ||
| 34 | + [0, 1, -3, 127, 4, -2, 1, 0], [0, 1, -4, 127, 6, -3, 1, 0], | ||
| 35 | + [0, 2, -6, 126, 8, -3, 1, 0], [0, 2, -7, 125, 11, -4, 1, 0], | ||
| 36 | + [-1, 2, -8, 125, 13, -5, 2, 0], [-1, 3, -9, 124, 15, -6, 2, 0], | ||
| 37 | + [-1, 3, -10, 123, 18, -6, 2, -1], [-1, 3, -11, 122, 20, -7, 3, -1], | ||
| 38 | + [-1, 4, -12, 121, 22, -8, 3, -1], [-1, 4, -13, 120, 25, -9, 3, -1], | ||
| 39 | + [-1, 4, -14, 118, 28, -9, 3, -1], [-1, 4, -15, 117, 30, -10, 4, -1], | ||
| 40 | + [-1, 5, -16, 116, 32, -11, 4, -1], [-1, 5, -16, 114, 35, -12, 4, -1], | ||
| 41 | + [-1, 5, -17, 112, 38, -12, 4, -1], [-1, 5, -18, 111, 40, -13, 5, -1], | ||
| 42 | + [-1, 5, -18, 109, 43, -14, 5, -1], [-1, 6, -19, 107, 45, -14, 5, -1], | ||
| 43 | + [-1, 6, -19, 105, 48, -15, 5, -1], [-1, 6, -19, 103, 51, -16, 5, -1], | ||
| 44 | + [-1, 6, -20, 101, 53, -16, 6, -1], [-1, 6, -20, 99, 56, -17, 6, -1], | ||
| 45 | + [-1, 6, -20, 97, 58, -17, 6, -1], [-1, 6, -20, 95, 61, -18, 6, -1], | ||
| 46 | + [-2, 7, -20, 93, 64, -18, 6, -2], [-2, 7, -20, 91, 66, -19, 6, -1], | ||
| 47 | + [-2, 7, -20, 88, 69, -19, 6, -1], [-2, 7, -20, 86, 71, -19, 6, -1], | ||
| 48 | + [-2, 7, -20, 84, 74, -20, 7, -2], [-2, 7, -20, 81, 76, -20, 7, -1], | ||
| 49 | + [-2, 7, -20, 79, 79, -20, 7, -2], [-1, 7, -20, 76, 81, -20, 7, -2], | ||
| 50 | + [-2, 7, -20, 74, 84, -20, 7, -2], [-1, 6, -19, 71, 86, -20, 7, -2], | ||
| 51 | + [-1, 6, -19, 69, 88, -20, 7, -2], [-1, 6, -19, 66, 91, -20, 7, -2], | ||
| 52 | + [-2, 6, -18, 64, 93, -20, 7, -2], [-1, 6, -18, 61, 95, -20, 6, -1], | ||
| 53 | + [-1, 6, -17, 58, 97, -20, 6, -1], [-1, 6, -17, 56, 99, -20, 6, -1], | ||
| 54 | + [-1, 6, -16, 53, 101, -20, 6, -1], [-1, 5, -16, 51, 103, -19, 6, -1], | ||
| 55 | + [-1, 5, -15, 48, 105, -19, 6, -1], [-1, 5, -14, 45, 107, -19, 6, -1], | ||
| 56 | + [-1, 5, -14, 43, 109, -18, 5, -1], [-1, 5, -13, 40, 111, -18, 5, -1], | ||
| 57 | + [-1, 4, -12, 38, 112, -17, 5, -1], [-1, 4, -12, 35, 114, -16, 5, -1], | ||
| 58 | + [-1, 4, -11, 32, 116, -16, 5, -1], [-1, 4, -10, 30, 117, -15, 4, -1], | ||
| 59 | + [-1, 3, -9, 28, 118, -14, 4, -1], [-1, 3, -9, 25, 120, -13, 4, -1], | ||
| 60 | + [-1, 3, -8, 22, 121, -12, 4, -1], [-1, 3, -7, 20, 122, -11, 3, -1], | ||
| 61 | + [-1, 2, -6, 18, 123, -10, 3, -1], [0, 2, -6, 15, 124, -9, 3, -1], | ||
| 62 | + [0, 2, -5, 13, 125, -8, 2, -1], [0, 1, -4, 11, 125, -7, 2, 0], | ||
| 63 | + [0, 1, -3, 8, 126, -6, 2, 0], [0, 1, -3, 6, 127, -4, 1, 0], | ||
| 64 | + [0, 1, -2, 4, 127, -3, 1, 0], [0, 0, -1, 2, 128, -1, 0, 0], | ||
| 65 | +]; | ||
| 66 | + | ||
| 67 | +/// `av1_get_upscale_convolve_step` (`resize.c`). | ||
| 68 | +fn upscale_convolve_step(in_length: i64, out_length: i64) -> i64 { | ||
| 69 | + ((in_length << RS_SCALE_SUBPEL_BITS) + out_length / 2) / out_length | ||
| 70 | +} | ||
| 71 | + | ||
| 72 | +/// `get_upscale_convolve_x0` (`resize.c`, static there). | ||
| 73 | +fn upscale_convolve_x0(in_length: i64, out_length: i64, x_step_qn: i64) -> i64 { | ||
| 74 | + let err = out_length * x_step_qn - (in_length << RS_SCALE_SUBPEL_BITS); | ||
| 75 | + let x0 = (-((out_length - in_length) << (RS_SCALE_SUBPEL_BITS - 1)) + out_length / 2) | ||
| 76 | + / out_length | ||
| 77 | + + RS_SCALE_EXTRA_OFF | ||
| 78 | + - err / 2; | ||
| 79 | + x0.rem_euclid(1i64 << RS_SCALE_SUBPEL_BITS) & RS_SCALE_SUBPEL_MASK | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +/// `av1_convolve_horiz_rs_c` (`convolve.c`): `clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS))`. | ||
| 83 | +fn round_power_of_two(sum: i32, bits: u32) -> i32 { | ||
| 84 | + (sum + (1 << (bits - 1))) >> bits | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +/// One row of the spec 7.16 horizontal upscale (`upscale_normative_rect` + | ||
| 88 | +/// `av1_convolve_horiz_rs_c`, single-tile case: `pad_left`/`pad_right` both | ||
| 89 | +/// true, replicating the row's own edge pixels rather than sampling a | ||
| 90 | +/// neighbour tile). `in_width` and `out_width` must both be positive; | ||
| 91 | +/// `row.len() == in_width` and `out.len() == out_width`. | ||
| 92 | +pub(crate) fn upscale_row(row: &[u8], real_right_margin: &[u8], out_width: usize, out: &mut [u8]) { | ||
| 93 | + let in_width = row.len(); | ||
| 94 | + debug_assert!(in_width > 0 && out_width > 0); | ||
| 95 | + debug_assert_eq!(out.len(), out_width); | ||
| 96 | + let x_step_qn = upscale_convolve_step(in_width as i64, out_width as i64); | ||
| 97 | + let x0_qn = upscale_convolve_x0(in_width as i64, out_width as i64, x_step_qn); | ||
| 98 | + | ||
| 99 | + // Right-edge padding: r1 assumed a pure edge-replicate of `row`'s own | ||
| 100 | + // last column (matching `upscale_normative_rect`'s single-tile | ||
| 101 | + // in-memory fill), but the real decoder's reconstructed buffer already | ||
| 102 | + // holds genuine decoded samples past `frame_width` out to the | ||
| 103 | + // mi-aligned `true_width` (the coding block straddling the frame edge) | ||
| 104 | + // -- libaom's border extension replicates from THAT last real column, | ||
| 105 | + // not from `frame_width - 1`. `real_right_margin` (from | ||
| 106 | + // `decode::take_last_key_frame_wide_margin`) supplies those real | ||
| 107 | + // pixels first; only once it runs out (or is empty, e.g. `fw` was | ||
| 108 | + // already mi-aligned) does this fall back to r1's replicate. Pinned | ||
| 109 | + // column-by-column against real libaom via `scripts/superres-pin- | ||
| 110 | + // harness.c`'s `row6-realedgeval` case (r3). | ||
| 111 | + let pad = UPSCALE_NORMATIVE_TAPS + 2; | ||
| 112 | + let mut padded = vec![0u8; in_width + 2 * pad]; | ||
| 113 | + padded[..pad].fill(row[0]); | ||
| 114 | + padded[pad..pad + in_width].copy_from_slice(row); | ||
| 115 | + let real_n = real_right_margin.len().min(pad); | ||
| 116 | + padded[pad + in_width..pad + in_width + real_n].copy_from_slice(&real_right_margin[..real_n]); | ||
| 117 | + let replicate_from = real_right_margin.last().copied().unwrap_or(row[in_width - 1]); | ||
| 118 | + padded[pad + in_width + real_n..].fill(replicate_from); | ||
| 119 | + | ||
| 120 | + // `av1_convolve_horiz_rs_c` is called with `input - 1` and itself | ||
| 121 | + // subtracts `UPSCALE_NORMATIVE_TAPS/2 - 1` more; net offset from the | ||
| 122 | + // real column-0 pixel is `-(UPSCALE_NORMATIVE_TAPS/2)` == -4. | ||
| 123 | + let base = pad as i64 - (UPSCALE_NORMATIVE_TAPS as i64 / 2); | ||
| 124 | + let mut x_qn = x0_qn; | ||
| 125 | + for out_x in out.iter_mut() { | ||
| 126 | + let int_pel = x_qn >> RS_SCALE_SUBPEL_BITS; | ||
| 127 | + let filter_idx = ((x_qn & RS_SCALE_SUBPEL_MASK) >> RS_SCALE_EXTRA_BITS) as usize; | ||
| 128 | + let filter = &RESIZE_FILTER_NORMATIVE[filter_idx]; | ||
| 129 | + let mut sum = 0i32; | ||
| 130 | + for (k, &c) in filter.iter().enumerate() { | ||
| 131 | + let idx = base + int_pel + k as i64; | ||
| 132 | + sum += padded[idx as usize] as i32 * c as i32; | ||
| 133 | + } | ||
| 134 | + *out_x = round_power_of_two(sum, FILTER_BITS).clamp(0, 255) as u8; | ||
| 135 | + x_qn += x_step_qn; | ||
| 136 | + } | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +/// Spec 7.16, applied to a whole plane: `av1_upscale_normative_rows` | ||
| 140 | +/// widened to every row (`height2 == height`, no vertical scaling -- the | ||
| 141 | +/// spec only widens columns). `rows` is the plane's row-major byte buffer | ||
| 142 | +/// at `in_width`; returns a new buffer at `out_width`. | ||
| 143 | +pub(crate) fn upscale_plane( | ||
| 144 | + rows: &[u8], | ||
| 145 | + height: usize, | ||
| 146 | + in_width: usize, | ||
| 147 | + out_width: usize, | ||
| 148 | + margin: Option<(&[u8], usize)>, | ||
| 149 | +) -> Vec<u8> { | ||
| 150 | + debug_assert_eq!(rows.len(), height * in_width); | ||
| 151 | + let mut out = vec![0u8; height * out_width]; | ||
| 152 | + for r in 0..height { | ||
| 153 | + let src = &rows[r * in_width..(r + 1) * in_width]; | ||
| 154 | + let dst = &mut out[r * out_width..(r + 1) * out_width]; | ||
| 155 | + let real_right = match margin { | ||
| 156 | + Some((margin_rows, margin_width)) if margin_width > in_width => { | ||
| 157 | + &margin_rows[r * margin_width + in_width..(r + 1) * margin_width] | ||
| 158 | + } | ||
| 159 | + _ => &[], | ||
| 160 | + }; | ||
| 161 | + upscale_row(src, real_right, out_width, dst); | ||
| 162 | + } | ||
| 163 | + out | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +thread_local! { | ||
| 167 | + /// Firing count for the superres gate (class `gate-blind-to-feature`): | ||
| 168 | + /// how many whole pictures actually ran through [`upscale_plane`]. | ||
| 169 | + static SUPERRES_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +/// Current value of [`SUPERRES_HITS`]. | ||
| 173 | +pub(crate) fn superres_hits() -> usize { | ||
| 174 | + SUPERRES_HITS.with(|c| c.get()) | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +/// A whole [`crate::encode::Picture`]'s Y/U/V planes, upscaled from | ||
| 178 | +/// `frame_width`/`frame_height` (4:2:0 chroma) to `upscaled_width` at the | ||
| 179 | +/// same height -- spec 7.16 is horizontal-only. Increments | ||
| 180 | +/// [`SUPERRES_HITS`] once per call. `margin`, when set (r3, from | ||
| 181 | +/// `decode::take_last_key_frame_wide_margin`), is the real decoded pixels | ||
| 182 | +/// beyond `picture`'s own width out to the mi-aligned `true_width` -- see | ||
| 183 | +/// [`upscale_row`]'s doc for why the right-edge padding needs it. | ||
| 184 | +pub(crate) fn upscale_picture( | ||
| 185 | + picture: &crate::encode::Picture, | ||
| 186 | + upscaled_width: usize, | ||
| 187 | + margin: Option<&crate::encode::Picture>, | ||
| 188 | +) -> crate::encode::Picture { | ||
| 189 | + SUPERRES_HITS.with(|c| c.set(c.get() + 1)); | ||
| 190 | + let height = picture.height; | ||
| 191 | + let chroma_in_w = picture.width.div_ceil(2); | ||
| 192 | + let chroma_out_w = upscaled_width.div_ceil(2); | ||
| 193 | + let chroma_h = height.div_ceil(2); | ||
| 194 | + crate::encode::Picture { | ||
| 195 | + width: upscaled_width, | ||
| 196 | + height, | ||
| 197 | + y: upscale_plane( | ||
| 198 | + &picture.y, | ||
| 199 | + height, | ||
| 200 | + picture.width, | ||
| 201 | + upscaled_width, | ||
| 202 | + margin.map(|m| (m.y.as_slice(), m.width)), | ||
| 203 | + ), | ||
| 204 | + u: upscale_plane( | ||
| 205 | + &picture.u, | ||
| 206 | + chroma_h, | ||
| 207 | + chroma_in_w, | ||
| 208 | + chroma_out_w, | ||
| 209 | + margin.map(|m| (m.u.as_slice(), m.width.div_ceil(2))), | ||
| 210 | + ), | ||
| 211 | + v: upscale_plane( | ||
| 212 | + &picture.v, | ||
| 213 | + chroma_h, | ||
| 214 | + chroma_in_w, | ||
| 215 | + chroma_out_w, | ||
| 216 | + margin.map(|m| (m.v.as_slice(), m.width.div_ceil(2))), | ||
| 217 | + ), | ||
| 218 | + } | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | +#[cfg(test)] | ||
| 222 | +mod tests { | ||
| 223 | + use super::*; | ||
| 224 | + | ||
| 225 | + /// Pinned against libaom's own compiled code, not a second | ||
| 226 | + /// transcription of it: a standalone C harness linked against | ||
| 227 | + /// `~/.cache/aom-oracle/build/libaom.a` calls the real (exported) | ||
| 228 | + /// `av1_get_upscale_convolve_step` and `av1_convolve_horiz_rs_c` with | ||
| 229 | + /// the real (exported) `av1_resize_filter_normative` table -- the only | ||
| 230 | + /// piece reimplemented in C rather than called is the one-line static | ||
| 231 | + /// `get_upscale_convolve_x0` formula, copied verbatim in both places. | ||
| 232 | + /// This is the class `shared-oracle-blindness` guard: a bug in the | ||
| 233 | + /// 64x8 table above or in the convolution/rounding kernel is caught | ||
| 234 | + /// here independently of this module's own logic. | ||
| 235 | + #[test] | ||
| 236 | + fn upscale_row_matches_libaom_in8_out12() { | ||
| 237 | + let row = [10u8, 20, 30, 40, 50, 60, 70, 80]; | ||
| 238 | + let mut out = [0u8; 12]; | ||
| 239 | + upscale_row(&row, &[], 12, &mut out); | ||
| 240 | + assert_eq!(out, [9, 14, 22, 29, 35, 42, 48, 55, 61, 68, 76, 81]); | ||
| 241 | + } | ||
| 242 | + | ||
| 243 | + #[test] | ||
| 244 | + fn upscale_row_matches_libaom_in8_out16() { | ||
| 245 | + let row = [10u8, 20, 30, 40, 50, 60, 70, 80]; | ||
| 246 | + let mut out = [0u8; 16]; | ||
| 247 | + upscale_row(&row, &[], 16, &mut out); | ||
| 248 | + assert_eq!( | ||
| 249 | + out, | ||
| 250 | + [9, 12, 17, 23, 28, 32, 37, 43, 48, 53, 58, 62, 67, 73, 78, 81] | ||
| 251 | + ); | ||
| 252 | + } | ||
| 253 | + | ||
| 254 | + /// A flat row must upscale to the same flat value everywhere: every | ||
| 255 | + /// filter phase's 8 taps sum to exactly 128 (`FILTER_BITS`'s unity | ||
| 256 | + /// gain), so a constant input passes through unchanged regardless of | ||
| 257 | + /// which phase samples it -- a cheap sanity check independent of the | ||
| 258 | + /// captured-row pins above. | ||
| 259 | + #[test] | ||
| 260 | + fn upscale_row_of_a_flat_input_is_flat() { | ||
| 261 | + let row = [200u8; 8]; | ||
| 262 | + let mut out = [0u8; 12]; | ||
| 263 | + upscale_row(&row, &[], 12, &mut out); | ||
| 264 | + assert_eq!(out, [200u8; 12]); | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /// r3: the real 43->64 failing case, pinned against real libaom | ||
| 268 | + /// including the right-edge margin (`scripts/superres-pin-harness.c`'s | ||
| 269 | + /// `row6-realedgeval` case -- input row + real trailing decoded pixel | ||
| 270 | + /// 140, not a replicate of the frame-edge pixel 141). Column 62 (0 | ||
| 271 | + /// indexed) is exactly the pixel this gate mismatched by 1 before the | ||
| 272 | + /// margin fix. | ||
| 273 | + #[test] | ||
| 274 | + fn upscale_row_with_real_margin_matches_libaom_in43_out64() { | ||
| 275 | + let row: [u8; 43] = [ | ||
| 276 | + 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, | ||
| 277 | + 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, 130, 130, 131, 131, | ||
| 278 | + 133, 134, 136, 137, 138, 139, 140, 140, 141, | ||
| 279 | + ]; | ||
| 280 | + let real_margin = [140u8]; | ||
| 281 | + let mut out = [0u8; 64]; | ||
| 282 | + upscale_row(&row, &real_margin, 64, &mut out); | ||
| 283 | + assert_eq!(out[62], 141, "column 62 must match libaom, not the old replicate-padded 140"); | ||
| 284 | + } | ||
| 285 | +} | ||
lanes/superres-r2.charter.mdadded+86 -0
| @@ -0,0 +1,86 @@ | |||
| 1 | +# lane-superres r2 — finish the stage-3 gate, then inter-frame superres | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-superres`, branch | ||
| 4 | +`lane-superres`, at 150bbdc (+ the pin harness commit). | ||
| 5 | + | ||
| 6 | +## State (r1's, verified where it says so) | ||
| 7 | +Committed and green: | ||
| 8 | +- `79252c8` — `use_superres` refused BY NAME in `crates/ec-av1/src/stream.rs`. | ||
| 9 | + It was silent wrongness before: the header parsed fully but decode stored the | ||
| 10 | + `Picture` at the downscaled `frame_width` instead of `upscaled_width`. Gate | ||
| 11 | + `a_real_aomenc_stream_with_superres_refuses_by_name` proves it against a real | ||
| 12 | + `--superres-mode=1` stream. | ||
| 13 | +- `aec76d1` — `crates/ec-av1/src/superres.rs`: the spec 7.16 horizontal | ||
| 14 | + upscaler (`upscale_row` / `upscale_plane`), coefficient table and constants | ||
| 15 | + transcribed from libaom `resize.c` / `convolve.c`, pinned against the REAL | ||
| 16 | + exported `av1_get_upscale_convolve_step` / `av1_convolve_horiz_rs_c` / | ||
| 17 | + `av1_resize_filter_normative` through a C harness. Three unit tests green. | ||
| 18 | + The harness is now committed at `scripts/superres-pin-harness.c` (it lived in | ||
| 19 | + a reapable scratchpad — class `oracle-in-reaped-dir`); build it against | ||
| 20 | + `~/.cache/aom-oracle/build/libaom.a` if you need to extend the pins. | ||
| 21 | +- `150bbdc` — stage-3 wiring: the `use_superres` refusal narrowed to | ||
| 22 | + `frame_type != Key`; key frames call `crate::superres::upscale_picture` after | ||
| 23 | + `decode_key_frame_tile_with_cdfs`, before storage/output; `SUPERRES_HITS` | ||
| 24 | + thread-local + `superres_hits()`; `upscale_picture` covers Y/U/V with 4:2:0 | ||
| 25 | + chroma halved by `div_ceil(2)`. Compiles clean. | ||
| 26 | + | ||
| 27 | +r1 also corrected an error in the original charter: libaom's | ||
| 28 | +`decodeframe.c` calls `superres_post_decode()` BETWEEN `av1_cdef_frame` and | ||
| 29 | +`av1_loop_restoration_filter_frame` — **superres runs BEFORE loop restoration**, | ||
| 30 | +not after. Recorded in `superres.rs`'s module doc. Not load-bearing while LR is | ||
| 31 | +refused, but lane-lr will need it. | ||
| 32 | + | ||
| 33 | +## Not landed | ||
| 34 | +- The stage-3 gate `a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact` | ||
| 35 | + (in 150bbdc) FAILS with `unsupported: AV1 tile (a partition type this encoder | ||
| 36 | + never writes)`. That is a pre-existing capability gap in the bare | ||
| 37 | + `--superres-mode=1 --superres-denominator=12 --cpu-used=0` recipe, not a | ||
| 38 | + superres defect — the same shape the warp gate's original recipe hit. | ||
| 39 | +- r1's fix was in flight when its budget ran out and **did not apply** — the | ||
| 40 | + worktree is clean. Redo it: give the gate the restrictive flag set the warp | ||
| 41 | + gate uses (`--enable-rect-partitions=0 --enable-ab-partitions=0 | ||
| 42 | + --enable-1to4-partitions=0 --enable-filter-intra=0 --enable-smooth-intra=0 | ||
| 43 | + --enable-paeth-intra=0 --enable-directional-intra=0 --enable-angle-delta=0 | ||
| 44 | + --enable-tx-size-search=0 --enable-cdef=0 --enable-restoration=0 | ||
| 45 | + --max-partition-size=32 --min-partition-size=32 --enable-palette=0 | ||
| 46 | + --enable-intrabc=0 --enable-cfl-intra=0`), around stream.rs:3860-3875. | ||
| 47 | +- Stage 4 (inter frames referencing a differently-sized reference — superres | ||
| 48 | + mode 2 / qthresh) is not started. It needs spec 7.11.3.3 scaled-reference | ||
| 49 | + motion compensation, which is genuinely new work, not wiring. | ||
| 50 | +- `lanes/superres.report.md` was never written. | ||
| 51 | + | ||
| 52 | +## Order of work — COMMIT AFTER EVERY GREEN STEP | ||
| 53 | +1. Apply the flag-set fix; run just that gate | ||
| 54 | + (`cargo test -p ec-av1 --lib a_real_aomenc_superres_key_frame_sequence -j4 -- --nocapture`, | ||
| 55 | + timeout >= 600000 ms). It must decode pixel-exact AND hard-assert | ||
| 56 | + `superres_hits() > 0`. | ||
| 57 | +2. Full scoped suite `EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4` | ||
| 58 | + (~4 min, timeout >= 600000 ms). Baseline: 232/0 on this tree; main now | ||
| 59 | + carries 234/0 with two new guard tests you will inherit at merge. COMMIT | ||
| 60 | + stage 3. | ||
| 61 | +3. Stage 4: inter-frame superres. Scaled-reference MC, spec 7.11.3.3; libaom | ||
| 62 | + `av1_setup_scale_factors_for_frame` / `av1_convolve_2d_scale`. Its own gate, | ||
| 63 | + its own firing counter, its own commit. | ||
| 64 | + | ||
| 65 | +## Note on the coverage guard | ||
| 66 | +Main now carries `crates/ec-av1/src/gate_coverage.rs`, which derives from the | ||
| 67 | +gate source the aomenc tools switched off in every gate and on in none, and | ||
| 68 | +pins that set. The flag list above only disables tools already in the pinned set | ||
| 69 | +(cdef, intrabc, paeth-intra, palette, smooth-intra) plus tools other gates leave | ||
| 70 | +on, so it will not trip the guard — but run the full suite before committing. | ||
| 71 | + | ||
| 72 | +## Gate rules (mandatory) | ||
| 73 | +`EC_AV1_REQUIRE_AOMENC=1` on every run; `-t <seconds>` on every ffmpeg generate; | ||
| 74 | +fixtures through `gradients_source(seed, w, h, tail)`; aomenc | ||
| 75 | +`--threads=1 --row-mt=0`; the firing count is a HARD assert, never a warning. | ||
| 76 | + | ||
| 77 | +## Hard rules | ||
| 78 | +- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`. Foreground | ||
| 79 | + builds, `nice -n 19 cargo ... -j4`, every `cargo test` given a timeout of at | ||
| 80 | + least 600000 ms — a 120 s default kills the suite mid-run. | ||
| 81 | +- Sibling worktrees (edith_codecs, -chroma, -realworld, -lr, -tiles) have live | ||
| 82 | + agents. Never build in or edit them. | ||
| 83 | +- NEVER push, never merge, never touch `main`. Commit on `lane-superres` only. | ||
| 84 | +- 75-turn cap; commit at every green step; near the cap commit whatever | ||
| 85 | + compiles as `wip(av1): ...`. | ||
| 86 | +- Finish with `lanes/superres.report.md`, VERDICT on the first line. | ||
lanes/superres-r3.charter.mdadded+71 -0
| @@ -0,0 +1,71 @@ | |||
| 1 | +# lane-superres r3 — close the 5-pixel residue by pinning the REAL scale case | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-superres`, branch | ||
| 4 | +`lane-superres`, at 2022b4c. Read `lanes/superres.report.md` first — it is | ||
| 5 | +short, accurate, and lists what r2 already ruled out. Do not re-derive it | ||
| 6 | +(class `worker-cap-spent-reading`). | ||
| 7 | + | ||
| 8 | +## State | ||
| 9 | +Landed and committed: refusal-by-name (79252c8), the spec 7.16 upscaler pinned | ||
| 10 | +against real libaom (aec76d1), stage-3 wiring (150bbdc), and r2's two real | ||
| 11 | +fixes (85c070b): the gate needed `--superres-kf-denominator=12` (libaom's | ||
| 12 | +`--superres-denominator` only controls NON-key frames, and this fixture makes | ||
| 13 | +every frame a key frame, so `use_superres` was silently decoding false), and | ||
| 14 | +`decode.rs` cropped chroma with floor `fw / 2` where AV1 wants | ||
| 15 | +`ROUND_POWER_OF_TWO(fw, 1)` — a real general decoder bug, swept across both | ||
| 16 | +constructors of the cropped `Picture`. | ||
| 17 | + | ||
| 18 | +Still failing: `a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact`, | ||
| 19 | +5 of 4096 luma pixels off by exactly 1, all at x in 59..62 of a 64-wide frame. | ||
| 20 | + | ||
| 21 | +## The decisive move, before any theory | ||
| 22 | +r1 pinned the upscaler against libaom for **in8->out12 and in8->out16**. The | ||
| 23 | +failing case is **43 -> 64**. A kernel pinned at two small symmetric ratios says | ||
| 24 | +nothing about the phase/step arithmetic at the ratio that actually fails — | ||
| 25 | +class `instrument-at-bound`: a search result at its own edge is not a result. | ||
| 26 | + | ||
| 27 | +So: extend `scripts/superres-pin-harness.c` (committed, builds against | ||
| 28 | +`~/.cache/aom-oracle/build/libaom.a`) to run the EXACT failing case — input | ||
| 29 | +width 43, output width 64, 8-bit, with the same row bytes our decoder holds at | ||
| 30 | +the failing row — through the real exported | ||
| 31 | +`av1_get_upscale_convolve_step` / `av1_convolve_horiz_rs_c` / | ||
| 32 | +`av1_resize_filter_normative`, and print every output column. Compare column by | ||
| 33 | +column with ours. That either localises the defect to a specific | ||
| 34 | +`x_qn` / `int_pel` / `filter_idx` at x=59..62, or proves our kernel is right at | ||
| 35 | +this ratio and moves the suspicion to what we feed it. | ||
| 36 | + | ||
| 37 | +Two specific things to check in that harness run, because they are where the | ||
| 38 | +ratio matters: | ||
| 39 | +- `x0_qn` initialisation (libaom `get_upscale_convolve_x0`) — the starting | ||
| 40 | + phase, which the symmetric ratios r1 pinned may make degenerate. | ||
| 41 | +- The right-edge source clamp. r2's theory is that we edge-replicate from the | ||
| 42 | + cropped row where libaom uses a real decoded pixel. Note that libaom runs | ||
| 43 | + `av1_extend_frame_borders` before `av1_superres_upscale`, which replicates | ||
| 44 | + from column `y_crop_width - 1` — i.e. replication is probably RIGHT and the | ||
| 45 | + theory probably wrong. Let the harness settle it rather than the reasoning: | ||
| 46 | + feed it a row whose column 43+ differs from a replicate of column 42 and see | ||
| 47 | + whether the reference output changes at all. | ||
| 48 | + | ||
| 49 | +## Then | ||
| 50 | +1. Fix whatever the harness localises; the gate must decode pixel-exact and | ||
| 51 | + hard-assert `superres_hits() > 0`. COMMIT. | ||
| 52 | +2. Full scoped suite `EC_AV1_REQUIRE_AOMENC=1 nice -n 19 cargo test -p ec-av1 --lib -j4`, | ||
| 53 | + timeout >= 600000 ms. Baseline on this tree 232/0; main is at 234 with two | ||
| 54 | + new guard tests you inherit at merge. r2 never ran the suite after landing | ||
| 55 | + the `decode.rs` chroma-crop fix, so this run is also that fix's first real | ||
| 56 | + check. COMMIT. | ||
| 57 | +3. Stage 4 — inter-frame superres, scaled-reference MC (spec 7.11.3.3, libaom | ||
| 58 | + `av1_setup_scale_factors_for_frame` / `av1_convolve_2d_scale`). Its own gate, | ||
| 59 | + its own firing counter, its own commit. | ||
| 60 | +4. Update `lanes/superres.report.md`, VERDICT on the first line. | ||
| 61 | + | ||
| 62 | +## Hard rules | ||
| 63 | +- `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`. Foreground | ||
| 64 | + builds, `nice -n 19 cargo ... -j4`; every `cargo test` gets a timeout of at | ||
| 65 | + least 600000 ms. | ||
| 66 | +- Sibling worktrees (edith_codecs, -chroma, -realworld, -lr, -tiles, -palette) | ||
| 67 | + have live agents. Never build in or edit them. | ||
| 68 | +- NEVER push, never merge, never touch `main`. Commit on `lane-superres` only. | ||
| 69 | +- 75-turn cap and it does NOT reset on resume: commit at every green step, and | ||
| 70 | + commit the extended harness itself — it belongs in `scripts/`, not in a | ||
| 71 | + scratchpad that gets reaped (class `oracle-in-reaped-dir`). | ||
lanes/superres-r4.charter.mdadded+35 -0
| @@ -0,0 +1,35 @@ | |||
| 1 | +# lane-superres r4 | ||
| 2 | + | ||
| 3 | +At f167362 — r3's harness + decode work, committed verbatim by the orchestrator | ||
| 4 | +at its cap and **never seen to compile or pass**. Read `lanes/superres-r3.charter.md` | ||
| 5 | +(still binding) and `lanes/superres.report.md`. | ||
| 6 | + | ||
| 7 | +1. `cargo check`, then the target gate, then the full suite. Getting f167362 | ||
| 8 | + green is the whole job until it is green. COMMIT. | ||
| 9 | +2. The residue r3 was chasing: 5/4096 luma pixels off by 1 at x=59..62 of a | ||
| 10 | + 64-wide frame. The decisive instrument is the extended | ||
| 11 | + `scripts/superres-pin-harness.c` — run the REAL 43->64 ratio through libaom's | ||
| 12 | + own exported functions and compare column by column. r1 pinned only | ||
| 13 | + in8->out12 and in8->out16; a kernel pinned at two small symmetric ratios says | ||
| 14 | + nothing about phase arithmetic at the ratio that fails | ||
| 15 | + (class `instrument-at-bound`). | ||
| 16 | +3. Then stage 4: inter-frame superres, scaled-reference MC (spec 7.11.3.3, | ||
| 17 | + libaom `av1_setup_scale_factors_for_frame` / `av1_convolve_2d_scale`). | ||
| 18 | + | ||
| 19 | +Gate rules unchanged: `EC_AV1_REQUIRE_AOMENC=1`, `-t <seconds>` on every ffmpeg | ||
| 20 | +generate, fixtures through `gradients_source`, aomenc `--threads=1 --row-mt=0`, | ||
| 21 | +firing counts HARD-asserted. Two facts sibling lanes paid for: this decoder | ||
| 22 | +hardcodes 64px superblocks, so any multi-superblock fixture needs | ||
| 23 | +`--sb-size=64` (aomenc defaults to 128 and lands in a dead-ended partition | ||
| 24 | +gap); and a per-superblock symbol cannot fire in a single-superblock fixture. | ||
| 25 | + | ||
| 26 | +Merge note: main is at 06d29ee with `gate_coverage.rs` and `refusal_inventory.rs`, | ||
| 27 | +which pin the aomenc tools no gate exercises and every decode-path refusal | ||
| 28 | +string. Report the refusal strings you add, rename or remove, verbatim. | ||
| 29 | + | ||
| 30 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`; foreground | ||
| 31 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling | ||
| 32 | +worktrees (edith_codecs, -realworld, -lr, -tiles, -palette) have live agents — | ||
| 33 | +never build in or edit them. Never push, never merge, never touch `main`. | ||
| 34 | +75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP. End with | ||
| 35 | +`lanes/superres-r4.report.md`, VERDICT on line 1. | ||
lanes/superres-r4.report.mdadded+93 -0
| @@ -0,0 +1,93 @@ | |||
| 1 | +VERDICT: WIP -- f167362 verified compiling and 237/238 green; target gate still 2/4096 pixels off, root cause narrowed but not closed | ||
| 2 | + | ||
| 3 | +## What this round did | ||
| 4 | +r3's work at f167362 was committed by the orchestrator at its 75-turn cap, | ||
| 5 | +never seen to compile. Job one per the charter: verify it. | ||
| 6 | + | ||
| 7 | +- `cargo check -p ec-av1 --lib --tests`: clean (warnings only, no errors). | ||
| 8 | +- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4`: **237 passed, 1 | ||
| 9 | + failed, 17 ignored**. The only failure is the target gate, | ||
| 10 | + `a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact`. r3's two | ||
| 11 | + landed fixes (superres-kf-denominator flag, chroma-crop rounding, and this | ||
| 12 | + round's own margin-threading commit) cost nothing elsewhere -- no | ||
| 13 | + regressions against the 232/0 baseline this tree started from. | ||
| 14 | +- No code changes landed this round (all diagnostic instrumentation added | ||
| 15 | + during investigation was reverted with `git checkout --` before finishing; | ||
| 16 | + `git status` is clean at f167362). | ||
| 17 | + | ||
| 18 | +## The residue, narrowed | ||
| 19 | +r3 closed 3 of 5 mismatched pixels with the wide-margin threading fix | ||
| 20 | +(committed in f167362). The remaining 2 (frame 2, rows 17/18, output column | ||
| 21 | +62 -- the `--superres-kf-denominator=12`, 43->64 gate) were traced further | ||
| 22 | +this round: | ||
| 23 | + | ||
| 24 | +1. Dumped pre-deblock and post-deblock pixel values at columns 40-47 for | ||
| 25 | + frame 2, rows 8-23 (temporary `eprintln`, reverted). The only edge that | ||
| 26 | + touches these rows is a single horizontal deblock edge at `y0=16`, | ||
| 27 | + `level=5`, category `len=14` (the wide-filter class), covering columns | ||
| 28 | + 40-47 in two 4-column groups. | ||
| 29 | +2. Hand-computed `filter8`'s flat-branch formula (`decode.rs`'s | ||
| 30 | + `filter14`/`filter8`) against the dumped pre-deblock values for every | ||
| 31 | + affected column (43, 44, 45) and every affected row (13-18) -- | ||
| 32 | + **matched our own post-deblock output exactly in all cases tried**. The | ||
| 33 | + tap-weight arithmetic itself is self-consistent with the spec 7.14.6.3/ | ||
| 34 | + 7.14.6.4 formulas; no bug found there. | ||
| 35 | +3. Confirmed the margin our decoder stashes for superres (`real_right` in | ||
| 36 | + `upscale_row`) is exactly this same post-deblock data -- so if the | ||
| 37 | + pre-deblock reconstruction and the deblock level/mask decision are both | ||
| 38 | + correct, the margin is correct too. | ||
| 39 | +4. Ruled out a false lead: swapping row 17's and row 18's *margin* arrays in | ||
| 40 | + the pin harness (`scripts/superres-pin-harness.c`'s `row17-margin`/ | ||
| 41 | + `row18-margin` cases) happens to reproduce ffmpeg's expected value for | ||
| 42 | + both rows. This looked like a smoking-gun row-index swap, but the two | ||
| 43 | + margins differ by at most 1 in any position (smooth gradient content) -- | ||
| 44 | + entirely consistent with the *real* defect being a single-unit error | ||
| 45 | + that happens to land near a rounding boundary shared by both rows, not | ||
| 46 | + an actual row transposition. Src/margin pairing was independently | ||
| 47 | + confirmed correct at the Rust level (both come from the same row `r` of | ||
| 48 | + the same `y.data` buffer via the same `crop` closure). | ||
| 49 | +5. Ruled out: CDEF (frame flags force `cdef.*_strength == 0`, `apply_cdef` | ||
| 50 | + returns immediately); intra-prediction edge availability using the wrong | ||
| 51 | + width (`frame_width` is never read inside `decode_key_frame_tile_with_cdfs` | ||
| 52 | + except at the crop/margin-stash tail -- prediction always sees the true | ||
| 53 | + mi-aligned width). | ||
| 54 | + | ||
| 55 | +## What's not yet ruled out | ||
| 56 | +- The deblock **level** itself (`edge_params`'s `cur_level != 0 ? cur_level | ||
| 57 | + : pv_level`, `decode.rs:3980`) for this specific margin-straddling edge -- | ||
| 58 | + verified the *arithmetic* given `level=5`, not whether `5` is the level | ||
| 59 | + real libaom computes for this edge. This logic already passes broader | ||
| 60 | + deblock gates elsewhere (both intra and inter), so a narrow, edge-case-only | ||
| 61 | + divergence (e.g. a block whose transform straddles `frame_width` itself) | ||
| 62 | + is the remaining live suspect. | ||
| 63 | +- The pre-deblock reconstruction at columns 44-47 (the block whose right | ||
| 64 | + half falls in the margin) was hand-verified for internal consistency, not | ||
| 65 | + against real libaom -- there is still no ground truth for the *pre-deblock* | ||
| 66 | + row content, only for the final post-superres pixel (which is 2 rounding | ||
| 67 | + steps downstream: deblock, then the upscale convolution). | ||
| 68 | + | ||
| 69 | +## Next step (needs libaom instrumentation, not more hand tracing) | ||
| 70 | +Per r3's own charter fallback: build a small aomdec `EC_TRACE`-style patch | ||
| 71 | +(matching the one already used for msac/partition tracing elsewhere in this | ||
| 72 | +lane family) that dumps the post-deblock, pre-superres row content at | ||
| 73 | +`frame_width..true_width` for a real decode of this fixture, and diff it | ||
| 74 | +column-by-column against `decode.rs`'s stashed margin. That is the only | ||
| 75 | +instrument that can distinguish "our level/mask decision is wrong" from | ||
| 76 | +"our level/mask decision is right and the pre-deblock reconstruction is | ||
| 77 | +wrong" -- hand-tracing the arithmetic (this round) cannot, since it can only | ||
| 78 | +prove self-consistency, not correctness against libaom's real output. | ||
| 79 | + | ||
| 80 | +## Not reached | ||
| 81 | +Stage 4 (inter-frame superres, spec 7.11.3.3) -- blocked on stage 3 closing | ||
| 82 | +first, per both r3's and this charter's own ordering. Untouched this round. | ||
| 83 | + | ||
| 84 | +## Commands | ||
| 85 | +- `cargo check -p ec-av1 --lib --tests` -- clean. | ||
| 86 | +- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j4` -- 237 passed, 1 | ||
| 87 | + failed (the target gate), 17 ignored, 193s. | ||
| 88 | +- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib | ||
| 89 | + a_real_aomenc_superres_key_frame_sequence -j4 -- --nocapture` -- FAILED, | ||
| 90 | + same 2-pixel mismatch (frame 2, rows 17/18, col 62 of the upscaled output). | ||
| 91 | + | ||
| 92 | +## Refusal strings | ||
| 93 | +None added, renamed or removed this round. | ||
lanes/superres-r5.charter.mdadded+50 -0
| @@ -0,0 +1,50 @@ | |||
| 1 | +# lane-superres r5 — build the instrument, then close the 2-pixel residue | ||
| 2 | + | ||
| 3 | +At 48ba479. Read `lanes/superres-r4.report.md`. | ||
| 4 | + | ||
| 5 | +## State | ||
| 6 | +Everything but the last two pixels. The refusal-by-name, the spec 7.16 upscaler | ||
| 7 | +pinned against real libaom, the stage-3 wiring, the `--superres-kf-denominator` | ||
| 8 | +flag, the chroma-crop `ROUND_POWER_OF_TWO` fix and the margin threading are all | ||
| 9 | +committed and verified: 237 passed, 1 failed — only | ||
| 10 | +`a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact`, now **2 of 4096 | ||
| 11 | +luma pixels off by 1** (frame 2, rows 17-18, output column 62), down from 5. | ||
| 12 | + | ||
| 13 | +r4 ruled out, by hand-verifying against the spec: the `filter8`/`filter14` tap | ||
| 14 | +arithmetic, CDEF (forced off in this fixture), intra-prediction edge | ||
| 15 | +availability using the wrong width, and a "row-swap" lead it debunked as a | ||
| 16 | +numerical coincidence in smooth-gradient content. Its live suspect is the | ||
| 17 | +deblock LEVEL decision (`edge_params`) for the edge whose transform straddles | ||
| 18 | +the `frame_width` -> `true_width` margin. | ||
| 19 | + | ||
| 20 | +## Your job is to stop hand-tracing and build the instrument | ||
| 21 | +r4's own conclusion: hand-tracing our arithmetic cannot separate "our deblock | ||
| 22 | +level or mask is wrong" from "our pre-deblock reconstruction is wrong", because | ||
| 23 | +both are consistent with our own output. The only thing that can is libaom's | ||
| 24 | +ground truth for that row. | ||
| 25 | + | ||
| 26 | +`scripts/instrument-aom-oracle.sh` already carries env-gated rungs in exactly | ||
| 27 | +the shape you need — `EC_TRACE=1` (partitions), `EC_TRACE_COEFF=1`, | ||
| 28 | +`EC_TRACE_MODE=1`, and `EC_AV1_PREFILT_DUMP=<prefix>` (per-frame PRE-filter | ||
| 29 | +recon). Add a rung that dumps the **post-deblock, pre-superres** row content | ||
| 30 | +over `frame_width..true_width`, following the existing rungs exactly: | ||
| 31 | +env-gated, silent when unset, idempotent, wrapper-around-impl. Rebuild with | ||
| 32 | +`scripts/build-aom-oracle.sh`. Then diff it against `decode.rs`'s stashed | ||
| 33 | +margin at the failing row. | ||
| 34 | + | ||
| 35 | +Building that rung IS the deliverable of this round if it takes the whole | ||
| 36 | +budget. Commit the script change as soon as it builds — it is reusable by every | ||
| 37 | +lane, and instrument-building is a first-class subtask here, never an excuse. | ||
| 38 | + | ||
| 39 | +Then: fix what it localises, get the gate green, and only after that start | ||
| 40 | +stage 4 (inter-frame superres, spec 7.11.3.3 scaled-reference MC). | ||
| 41 | + | ||
| 42 | +Merge note: main is at 53b319b with `gate_coverage.rs` and | ||
| 43 | +`refusal_inventory.rs`. Report every refusal string you add or remove, verbatim. | ||
| 44 | + | ||
| 45 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`; foreground | ||
| 46 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling | ||
| 47 | +worktrees (edith_codecs, -realworld, -lr, -tiles, -palette) have live agents — | ||
| 48 | +never build in or edit them. Never push, never merge, never touch `main`. | ||
| 49 | +75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP. End with | ||
| 50 | +`lanes/superres-r5.report.md`, VERDICT on line 1. | ||
lanes/superres-r6.charter.mdadded+32 -0
| @@ -0,0 +1,32 @@ | |||
| 1 | +# lane-superres r6 — use the rungs you built | ||
| 2 | + | ||
| 3 | +At a69e1bd. Read `lanes/superres-r5.report.md` if r5 wrote one, else its | ||
| 4 | +commits: `f46e6fb` (EC_AV1_POSTDEBLOCK_DUMP) and `5e511b5` | ||
| 5 | +(EC_AV1_PREFILT_WIDE_DUMP) — r5's deliverable, two oracle rungs, landed. HEAD | ||
| 6 | +also carries r5's uncommitted `decode.rs` work, committed verbatim by the | ||
| 7 | +orchestrator at its cap and **never seen to compile**. | ||
| 8 | + | ||
| 9 | +1. `cargo check`, fix whatever r5 left mid-edit, then the full suite. COMMIT the | ||
| 10 | + moment it is green. | ||
| 11 | +2. Use the rungs. The gate is 2 of 4096 luma pixels off by 1 (frame 2, rows | ||
| 12 | + 17-18, output column 62). r4 exhausted hand-tracing: our arithmetic is | ||
| 13 | + self-consistent with our own output, so only libaom's ground truth for that | ||
| 14 | + row can separate "our deblock level/mask is wrong" from "our pre-deblock | ||
| 15 | + reconstruction is wrong". Dump both, diff at the failing row, fix what it | ||
| 16 | + localises. COMMIT. | ||
| 17 | +3. Then stage 4: inter-frame superres — scaled-reference MC, spec 7.11.3.3, | ||
| 18 | + libaom `av1_setup_scale_factors_for_frame` / `av1_convolve_2d_scale`. | ||
| 19 | + | ||
| 20 | +Merge note: main is at 53f5358 and has moved a long way (multi-tile key frames, | ||
| 21 | +chroma smooth/paeth, CDEF index reads). If your merge back looks large, say so | ||
| 22 | +in the report and consider `git merge main` here first, resolving it yourself — | ||
| 23 | +you know which side owns each hunk. Main also carries `gate_coverage.rs`, | ||
| 24 | +`refusal_inventory.rs` and `GATES_THAT_SKIP_ON_A_DECODE_ERROR`: report every | ||
| 25 | +refusal string you add, rename or remove, verbatim, and do not write a gate that | ||
| 26 | +turns a decode error into a printed SKIP. | ||
| 27 | + | ||
| 28 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`; foreground | ||
| 29 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling | ||
| 30 | +worktrees have live agents — never build in or edit them. Never push, never | ||
| 31 | +merge into `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP. | ||
| 32 | +End with `lanes/superres-r6.report.md`, VERDICT on line 1. | ||
lanes/superres-r6.report.mdadded+87 -0
| @@ -0,0 +1,87 @@ | |||
| 1 | +VERDICT: PARTIAL -- r5's decode.rs work verified green, gate residue localized to a specific | ||
| 2 | +deblock edge, root cause not yet found (defer to r7). | ||
| 3 | + | ||
| 4 | +## Step 1: verify r5's uncommitted work | ||
| 5 | + | ||
| 6 | +`cargo check` clean, `cargo test -p ec-av1` (EC_AV1_REQUIRE_AOMENC=1, 600s timeout): 237 passed, | ||
| 7 | +1 failed (the known `a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact`, the gate | ||
| 8 | +this lane exists to close), 17 ignored. Nothing else regressed. No fix was needed -- working | ||
| 9 | +tree was clean at a69e1bd/3462632, so no commit was made for step 1 itself. | ||
| 10 | + | ||
| 11 | +## Step 2: use the rungs | ||
| 12 | + | ||
| 13 | +Reproduced the gate's exact failing stream (added `EC_SUPERRES_STREAM_DUMP` to the test, one | ||
| 14 | +run, one seed -- avoids the seeded-fixture-not-reproducible dead-end since it's now a captured | ||
| 15 | +file, not a re-rendered lavfi seed) and ran both oracle rungs plus our own matching decode.rs | ||
| 16 | +dumps (`EC_AV1_PREFILT_WIDE_DUMP` exists on both sides already; `EC_AV1_MARGIN_DUMP` is our own | ||
| 17 | +post-deblock+cdef dump, CDEF is off in this stream so it's a valid post-deblock comparison | ||
| 18 | +point) against frame 2 (the failing frame): | ||
| 19 | + | ||
| 20 | +- **Pre-deblock (`ours-prefilt.f2` vs `lib-prefilt.f2`): 0 diffs, byte-exact.** Reconstruction | ||
| 21 | + (predict+residual, all of coefficient decode) is proven correct for this frame including the | ||
| 22 | + whole margin region -- rules out mode/tx/coefficient decode as the cause. | ||
| 23 | +- **Post-deblock (`ours-margin.f2` Y vs `lib-postdeblock.f2` Y): 37 diffs, ALL in columns 44-47** | ||
| 24 | + (the coded frame's rightmost mi column, mi_c=11 of mi_cols=12, true_width=48) across rows | ||
| 25 | + 9-38ish. Nowhere else in the frame differs. | ||
| 26 | + | ||
| 27 | +This localizes the bug to `deblock_plane`'s horizontal-edge pass at the rightmost mi column. | ||
| 28 | +Traced the specific edges firing there (`EC_AV1_DEBLOCK_TRACE=1`): three horizontal edges per | ||
| 29 | +frame at x0=44, y0∈{16,32,48}, `len=14 level=5 sharpness=0`. Hand-reimplemented `filter14`'s | ||
| 30 | +flat-branch formula in Python against the bit-exact pre-deblock input at columns 44-47: it | ||
| 31 | +**exactly reproduces our own Rust decoder's output** (op2..oq2 match `ours-margin.f2` to the | ||
| 32 | +byte) -- our filter math is spec-correct and self-consistent. But **libaom's real post-deblock | ||
| 33 | +output at these exact samples equals the unfiltered pre-deblock input** -- libaom did not filter | ||
| 34 | +this edge at all, at 3 of the 4 columns in the group (col 44 happened to be a no-op already). | ||
| 35 | + | ||
| 36 | +## What's not yet found | ||
| 37 | + | ||
| 38 | +Read `av1_loopfilter.c`'s two candidate skip conditions (`curr_skipped = skip_txfm && | ||
| 39 | +is_inter_block`) -- both are INTER-only gates; this is a key frame (`--kf-max-dist=0`), so intra | ||
| 40 | +blocks never hit that suppression, and by the source's own logic this edge (nonzero level on an | ||
| 41 | +intra PU boundary, `pu_edge = mi_prev != mbmi` true) should still filter. To get ground truth | ||
| 42 | +instead of re-deriving the C by eye, patched two candidate real call sites | ||
| 43 | +(`set_lpf_parameters` and `set_one_param_for_line_luma`, in | ||
| 44 | +`~/.cache/aom-oracle/src/av1/common/av1_loopfilter.c`, rebuilt via `ninja -C | ||
| 45 | +~/.cache/aom-oracle/build aomdec`) with `EC_LF_TRACE`/`EC_LF_TRACE2` eprintln diagnostics gated | ||
| 46 | +on `mi_col==11` and `!is_vert` -- **neither ever fired** for this stream, meaning the real | ||
| 47 | +horizontal-edge loop-filter path for this exact column takes a THIRD, unlocated code path in | ||
| 48 | +libaom (a SIMD/quad-batch variant most likely, or a per-line-luma variant reached from a | ||
| 49 | +different fast path than the two I found via `grep set_lpf_parameters`). That third path is | ||
| 50 | +where the actual "why libaom doesn't filter here" answer lives -- I ran out of turn budget | ||
| 51 | +finding it. The libaom source patches are throwaway (in `~/.cache/aom-oracle/src`, not part of | ||
| 52 | +this repo, not committed) and can be re-applied/removed freely by r7; `scripts/build-aom-oracle.sh` | ||
| 53 | ++ `scripts/instrument-aom-oracle.sh` rebuild from clean if you want a pristine tree first. | ||
| 54 | + | ||
| 55 | +## Left in the repo (committed, `8ef70ff`) | ||
| 56 | + | ||
| 57 | +- `EC_SUPERRES_STREAM_DUMP` (stream.rs, the superres key-frame gate test): dumps the exact OBU | ||
| 58 | + bytes fed to aomenc/decode_stream to a file when set -- makes the gate's stream reproducible | ||
| 59 | + for oracle diffing without relying on lavfi seed determinism. | ||
| 60 | +- `EC_AV1_DEBLOCK_TRACE` (decode.rs, `deblock_plane`'s horizontal-edge loop): eprintln's | ||
| 61 | + `x0/y0/len/level/sharpness` when `x0==44` and `plane_idx==0` -- narrow and hardcoded to this | ||
| 62 | + investigation; r7 should widen or remove it once the real cause is found. | ||
| 63 | + | ||
| 64 | +Both are env-gated, off by default, zero behavior change to any existing test. | ||
| 65 | + | ||
| 66 | +## Step 3: inter-frame superres (spec 7.11.3.3) | ||
| 67 | + | ||
| 68 | +Not started -- all turn budget went to step 2's localization. Deferred to r7/next lane. | ||
| 69 | + | ||
| 70 | +## Refusal strings | ||
| 71 | + | ||
| 72 | +None added, renamed, or removed this round. | ||
| 73 | + | ||
| 74 | +## Merge | ||
| 75 | + | ||
| 76 | +Not attempted -- no time budget left to verify a `git merge main` cleanly after the above; left | ||
| 77 | +for r7 to decide, per charter's "consider `git merge main` here first" being conditional on | ||
| 78 | +budget. | ||
| 79 | + | ||
| 80 | +## Disposition | ||
| 81 | + | ||
| 82 | +- deferred: the actual libaom code path for the last-column horizontal edge -- unblocks with | ||
| 83 | + either `perf`/`gdb break set_lpf_parameters_for_line_luma` on the real aomdec binary while it | ||
| 84 | + decodes this exact stream (fastest: confirms which function body genuinely executes), or | ||
| 85 | + grep `av1_filter_block_plane_horz`/AVX2 variants under `av1/common/x86/av1_loopfilter_sse2.c` | ||
| 86 | + for a scalar-bypassing fast path. | ||
| 87 | +- deferred: stage 4 (inter-frame superres, scaled-reference MC) -- unstarted, whole stage. | ||
lanes/superres-r7.charter.mdadded+65 -0
| @@ -0,0 +1,65 @@ | |||
| 1 | +# lane-superres r7 — is that edge filtered at all? | ||
| 2 | + | ||
| 3 | +Read `lanes/superres-r6.report.md`. r5's decode work is verified green (237 | ||
| 4 | +passed, the target gate the only failure). | ||
| 5 | + | ||
| 6 | +## Where the search stands | ||
| 7 | +r6 localized the 2-pixel residue precisely: horizontal-edge deblocking at the | ||
| 8 | +CODED frame's rightmost mi column, x0 = 44..47. It re-derived `filter14` / | ||
| 9 | +`filter8` in Python against the bit-exact pre-deblock dump and reproduced our | ||
| 10 | +Rust output exactly — **our filter arithmetic is spec-correct**, so the bug is | ||
| 11 | +in edge/level SELECTION, not in the filter. It then instrumented two libaom | ||
| 12 | +candidates (`set_lpf_parameters`, `set_one_param_for_line_luma` / | ||
| 13 | +`set_lpf_parameters_for_line_luma`) and confirmed neither fires, and ran out of | ||
| 14 | +budget hunting a third dispatch path. | ||
| 15 | + | ||
| 16 | +## Before hunting libaom's dispatch further, test this hypothesis | ||
| 17 | +The coded frame width here is 43; the mi grid is 48 wide. **x = 44..47 is the | ||
| 18 | +mi-alignment margin, beyond `frame_width`.** Two things follow, and either would | ||
| 19 | +produce exactly this shape: | ||
| 20 | +1. We may be deblocking an edge libaom never filters, because it clips the loop | ||
| 21 | + to the coded width. "Neither candidate fires" is consistent with libaom | ||
| 22 | + simply not filtering there — an absent call is evidence, not a dead end | ||
| 23 | + (class `equal-range-means-unread`, applied to pixels). | ||
| 24 | +2. We may be FEEDING the upscaler decoded margin pixels where libaom feeds | ||
| 25 | + replicated ones: `av1_superres_upscale` calls `av1_extend_frame_borders` | ||
| 26 | + first, which replicates from column `y_crop_width - 1`. r3's margin threading | ||
| 27 | + moved the count 5 -> 2, which looks like progress but is equally consistent | ||
| 28 | + with trading one wrong source for another. | ||
| 29 | + | ||
| 30 | +Both are cheap to test and neither needs libaom's dispatch: clip our deblock to | ||
| 31 | +the coded width and see; then feed the upscaler a replicate of column 42 instead | ||
| 32 | +of decoded margin and see. Run them as experiments, not as a rewrite — one at a | ||
| 33 | +time, reverting between, and report both results even if neither closes it. | ||
| 34 | + | ||
| 35 | +If both fail, then go after the dispatch path with gdb as r6 planned, using its | ||
| 36 | +reproduction: `EC_SUPERRES_STREAM_DUMP=<path>.obu cargo test -p ec-av1 --lib | ||
| 37 | +stream::tests::a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact -- | ||
| 38 | +--nocapture`, then that `.obu` through `~/.cache/aom-oracle/build/aomdec` with | ||
| 39 | +`EC_AV1_PREFILT_WIDE_DUMP` / `EC_AV1_POSTDEBLOCK_DUMP`, diffing frame 2 columns | ||
| 40 | +44-47. | ||
| 41 | + | ||
| 42 | +## Housekeeping this round owes | ||
| 43 | +r6 left throwaway `EC_LF_TRACE` diagnostics in | ||
| 44 | +`~/.cache/aom-oracle/src/av1/common/av1_loopfilter.c` — outside this repo and | ||
| 45 | +uncommitted. Either fold them into `scripts/instrument-aom-oracle.sh` as a | ||
| 46 | +proper env-gated rung (the shape every other rung uses, and then they survive an | ||
| 47 | +oracle rebuild) or revert them. Do not leave edits sitting in the oracle's source | ||
| 48 | +tree where the next lane will not know they are there. | ||
| 49 | + | ||
| 50 | +## Then | ||
| 51 | +Stage 4: inter-frame superres — scaled-reference MC, spec 7.11.3.3, libaom | ||
| 52 | +`av1_setup_scale_factors_for_frame` / `av1_convolve_2d_scale`. | ||
| 53 | + | ||
| 54 | +Merge note: main is at 92d8beb and has moved a long way (multi-tile decode | ||
| 55 | +gated, CDEF index, chroma modes, a `bit_depth != 8` refusal, three reworded | ||
| 56 | +partition refusals, and three guard tests that pin the never-exercised aomenc | ||
| 57 | +tools, every decode-path refusal string, and the gates that swallow a decode | ||
| 58 | +error). Consider `git merge main` here and resolving it yourself. Report every | ||
| 59 | +refusal string you add, rename or remove, verbatim. | ||
| 60 | + | ||
| 61 | +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`; foreground | ||
| 62 | +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling | ||
| 63 | +worktrees have live agents — never build in or edit them. Never push, never | ||
| 64 | +merge into `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP. | ||
| 65 | +End with `lanes/superres-r7.report.md`, VERDICT on line 1. | ||
lanes/superres-r7.report.mdadded+89 -0
| @@ -0,0 +1,89 @@ | |||
| 1 | +VERDICT: CLOSED -- the superres gate is pixel-exact; charter hypothesis 1 was the root cause. | ||
| 2 | + | ||
| 3 | +## What was tested | ||
| 4 | + | ||
| 5 | +Charter hypothesis 1: "libaom clips the deblock loop to the coded frame's width, our | ||
| 6 | +`true_width`/`true_height` (mi-aligned, `mi_cols*4`/`mi_rows*4`) includes a padding | ||
| 7 | +margin libaom never filters." Confirmed on the first try -- did not need hypothesis 2 | ||
| 8 | +(margin vs replicated-border upscaler feed) or the gdb dispatch hunt. | ||
| 9 | + | ||
| 10 | +## Fix | ||
| 11 | + | ||
| 12 | +`crates/ec-av1/src/decode.rs`: `deblock_plane` (and its caller `apply_deblock`) now take | ||
| 13 | +`frame_width`/`frame_height` and bound their `x0`/`y0` loops by | ||
| 14 | +`plane.true_width.min(cw)` / `plane.true_height.min(ch)` where `cw`/`ch` are the coded | ||
| 15 | +frame's own dimensions (`frame_height.div_ceil(2)` for chroma, matching the 4:2:0 | ||
| 16 | +subsampling this decoder assumes), instead of always looping the full mi-aligned | ||
| 17 | +`true_width`/`true_height`. Both call sites (`decode_key_frame_tile_with_cdfs`, | ||
| 18 | +`decode_inter_frame_tile_with_cdfs`) updated to pass `frame_width as usize, frame_height | ||
| 19 | +as usize`. | ||
| 20 | + | ||
| 21 | +## Ground truth, not just gate-green | ||
| 22 | + | ||
| 23 | +Read libaom's `set_lpf_parameters` (`av1/common/av1_loopfilter.c:224`) while removing the | ||
| 24 | +throwaway trace lines there (see Housekeeping below) and found the actual normative | ||
| 25 | +check directly: | ||
| 26 | + | ||
| 27 | +```c | ||
| 28 | +const uint32_t width = plane_ptr->dst.width; | ||
| 29 | +const uint32_t height = plane_ptr->dst.height; | ||
| 30 | +if ((width <= x) || (height <= y)) { | ||
| 31 | + // just return the smallest transform unit size | ||
| 32 | + return TX_4X4; | ||
| 33 | +} | ||
| 34 | +``` | ||
| 35 | + | ||
| 36 | +`plane_ptr->dst.width`/`height` is the destination plane's coded width/height (the same | ||
| 37 | +quantity our `frame_width`/`frame_height` already carries), not the mi-grid-padded | ||
| 38 | +extent. This is the third dispatch path r6 was hunting for with `EC_LF_TRACE`/ | ||
| 39 | +`EC_LF_TRACE2` at `set_lpf_parameters`/`set_one_param_for_line_luma` -- both traces r6 | ||
| 40 | +added never fired because they were placed *after* this early return already skipped | ||
| 41 | +the block; the trace at line 298 (inside `set_lpf_parameters`, guarded on | ||
| 42 | +`edge_dir==HORZ_EDGE && x==44`) sat downstream of this `if`, so it correctly never | ||
| 43 | +printed for x=44 once x exceeded `plane_ptr->dst.width` -- r6's "neither candidate | ||
| 44 | +fires" was itself the evidence for hypothesis 1, not a dead end (class | ||
| 45 | +`equal-range-means-unread`, per the charter). | ||
| 46 | + | ||
| 47 | +## Verification | ||
| 48 | + | ||
| 49 | +- `cargo check -p ec-av1`: clean. | ||
| 50 | +- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib stream::tests::a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact -- --nocapture`: | ||
| 51 | + `3 frames pixel-exact, superres_hits=3` -- **PASS** (was the lane's one failing gate | ||
| 52 | + since r5). | ||
| 53 | +- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1` (full crate, 600s timeout): **238 | ||
| 54 | + passed, 0 failed, 17 ignored** -- no regression from the clip (the mi-alignment | ||
| 55 | + margin only ever held decode scratch space beyond the coded picture; nothing else | ||
| 56 | + reads or filters it). | ||
| 57 | + | ||
| 58 | +Commit: `f64f5cd` on `lane-superres` (this worktree). | ||
| 59 | + | ||
| 60 | +## Housekeeping | ||
| 61 | + | ||
| 62 | +r6's throwaway `EC_LF_TRACE`/`EC_LF_TRACE2` `fprintf` diagnostics in | ||
| 63 | +`~/.cache/aom-oracle/src/av1/common/av1_loopfilter.c` (lines 298-301, 714-717) removed -- | ||
| 64 | +their placement (downstream of the early-return this round found) is itself part of the | ||
| 65 | +evidence above, so they are recorded in this report rather than folded into | ||
| 66 | +`scripts/instrument-aom-oracle.sh` as a permanent rung; the oracle source tree is back to | ||
| 67 | +a pristine, uncommitted state. Not rebuilt (`ninja`) this round since nothing further | ||
| 68 | +needed the oracle binary -- `scripts/build-aom-oracle.sh` will produce a clean build from | ||
| 69 | +this source on next use, no stale trace code left behind. | ||
| 70 | + | ||
| 71 | +## Refusal strings | ||
| 72 | + | ||
| 73 | +None added, renamed, or removed this round. | ||
| 74 | + | ||
| 75 | +## Merge | ||
| 76 | + | ||
| 77 | +Not attempted -- turn budget went to landing and verifying the fix + housekeeping. Left | ||
| 78 | +for the next lane; charter's "consider `git merge main` here" is conditional on budget | ||
| 79 | +and main has moved substantially (per r6's merge note) since `92d8beb`. | ||
| 80 | + | ||
| 81 | +## Disposition | ||
| 82 | + | ||
| 83 | +- deferred: `git merge main` (charter's note: multi-tile decode, CDEF index, chroma | ||
| 84 | + modes, `bit_depth != 8` refusal, three reworded partition refusals, three guard tests | ||
| 85 | + landed there since 92d8beb) -- next lane in this worktree, or whoever picks this branch | ||
| 86 | + up, should merge and re-run the full `ec-av1` suite before anything further. | ||
| 87 | +- deferred: Stage 4, inter-frame superres (spec 7.11.3.3, scaled-reference MC, | ||
| 88 | + `av1_setup_scale_factors_for_frame` / `av1_convolve_2d_scale`) -- unstarted, whole | ||
| 89 | + stage, per charter's "Then" section. | ||
lanes/superres.charter.mdadded+91 -0
| @@ -0,0 +1,91 @@ | |||
| 1 | +# lane-superres — superres decode (frame_size_with_refs / horizontal upscale) | ||
| 2 | + | ||
| 3 | +Worktree `/home/user/Documents/Code/Rust/edith_codecs-superres`, branch | ||
| 4 | +`lane-superres`, off main 87a1e34. | ||
| 5 | + | ||
| 6 | +## Goal | ||
| 7 | +Make the decoder handle a stream aomenc produced with `--superres-mode=` | ||
| 8 | +(fixed and/or qthresh) end to end, pixel-exact vs libaom: | ||
| 9 | +1. header side: `use_superres` / `superres_denom` are read into the frame | ||
| 10 | + header (check whether `crates/ec-av1-syntax` already parses them — see | ||
| 11 | + `crates/ec-av1-syntax/src/frame.rs:518` — and whether the DECODE path in | ||
| 12 | + `crates/ec-av1/src/stream.rs` refuses or silently ignores them); | ||
| 13 | +2. decode side: the frame is coded at `frame_width` (the DOWNSCALED width), | ||
| 14 | + every block/MV/loop-filter/CDEF operation happens at that width, and only | ||
| 15 | + after loop restoration is the frame upscaled horizontally to | ||
| 16 | + `upscaled_width` by the spec's linear-filter upscaler; | ||
| 17 | +3. reference frames are stored UPSCALED, and `frame_size_with_refs` / | ||
| 18 | + MV scaling for inter prediction across a size change must be right. | ||
| 19 | + | ||
| 20 | +## Anchors | ||
| 21 | +- Spec: 5.9.8 `superres_params`, 7.16 `upscaling process`, 5.9.7 | ||
| 22 | + `frame_size_with_refs`, 7.11.3.3 (motion vector scaling / scaled reference). | ||
| 23 | +- libaom (source tree under `~/.cache/aom-oracle`): | ||
| 24 | + `av1/common/resize.c` — `av1_upscale_normative_rows`, | ||
| 25 | + `av1_upscale_normative_and_extend_frame`, `upscale_normative_rect`, | ||
| 26 | + and the `av1_resize_filter_normative` coefficient table (the 8-tap | ||
| 27 | + `SUPERRES_FILTER` table with `RS_SUBPEL_BITS`/`RS_SCALE_SUBPEL_BITS`); | ||
| 28 | + `av1/decoder/decodeframe.c` `setup_superres` / `superres_post_decode`. | ||
| 29 | +- Note the ORDER: superres upscaling happens AFTER deblock+CDEF and | ||
| 30 | + AFTER loop restoration in libaom's pipeline | ||
| 31 | + (`av1_loop_restoration_filter_frame` runs on the downscaled frame using the | ||
| 32 | + saved pre-upscale buffer). Get this order from the source, not from memory. | ||
| 33 | +- Writer side already exists and refuses: `crates/ec-av1/src/frame.rs:309-316` | ||
| 34 | + writes `use_superres` and refuses a denom other than 8. Leave the writer's | ||
| 35 | + refusal in place unless you also implement the encoder-side downscale — that | ||
| 36 | + is OUT of scope for this lane; this lane is DECODE. | ||
| 37 | +- `crates/ec-av1/src/stream.rs` holds every decode refusal and every gate. | ||
| 38 | + `grep -n unsupported crates/ec-av1/src/stream.rs` to see the shape. | ||
| 39 | + | ||
| 40 | +## Step 0 — measure before building | ||
| 41 | +Encode a real fixture with `--superres-mode=1 --superres-denominator=<n>` | ||
| 42 | +(check `aomenc --help | grep -i superres` for the actual flag spelling in | ||
| 43 | +v3.13.3) and run it through our decoder as it stands today. Report in the | ||
| 44 | +report file: does it refuse (with what exact string), desync, or decode wrong? | ||
| 45 | +That answer decides whether stage 1 is a refusal removal or a bug fix. If the | ||
| 46 | +header path already silently ignores superres and produces wrong pixels, that | ||
| 47 | +is a SILENT WRONGNESS defect and must first become an explicit refusal, in its | ||
| 48 | +own commit, before the implementation lands. | ||
| 49 | + | ||
| 50 | +## Staging — commit after EVERY green milestone | ||
| 51 | +1. Header + explicit refusal by accurate name. COMMIT. | ||
| 52 | +2. Upscaler implemented and unit-pinned: a `#[test]` that feeds a known row to | ||
| 53 | + our upscaler and compares against values captured from libaom's | ||
| 54 | + `av1_upscale_normative_rows` (add an instrumentation rung to | ||
| 55 | + `scripts/instrument-aom-oracle.sh` if you need to capture them — follow the | ||
| 56 | + existing rungs' shape exactly: env-gated, silent when unset, idempotent, | ||
| 57 | + wrapper-around-impl — then rebuild with `scripts/build-aom-oracle.sh`). | ||
| 58 | + COMMIT. | ||
| 59 | +3. Full-frame gate: decode an aomenc superres stream pixel-exact vs | ||
| 60 | + `aomdec --rawvideo`. COMMIT. | ||
| 61 | +4. Inter frames referencing a differently-sized reference (superres-mode=2 | ||
| 62 | + /qthresh, so denom varies frame to frame). COMMIT. | ||
| 63 | + | ||
| 64 | +## Gate (mandatory) | ||
| 65 | +- Follow the existing gate shape in `crates/ec-av1/src/stream.rs`. | ||
| 66 | + `EC_AV1_REQUIRE_AOMENC=1` must be set when you run tests: a missing oracle | ||
| 67 | + must FAIL, never SKIP. | ||
| 68 | +- Bound every ffmpeg `generate` with `-t <seconds>`. | ||
| 69 | +- Build the fixture through the existing `gradients_source(seed, w, h, tail)` | ||
| 70 | + helper — ffmpeg's `gradients` source ignores its seed, so a hand-written | ||
| 71 | + `gradients=size=` string makes the gate non-reproducible. | ||
| 72 | +- aomenc: `--threads=1 --row-mt=0`. | ||
| 73 | +- Hard-assert a firing count via a thread-local `Cell<usize>` counter like the | ||
| 74 | + existing `*_HITS` in decode.rs (they are thread-local now, NOT atomics). | ||
| 75 | + A gate that cannot prove superres actually fired is vacuous | ||
| 76 | + (CLASS `gate-blind-to-feature`). | ||
| 77 | +- Refusals inside the gate are FORBIDDEN once the stage removing them lands. | ||
| 78 | + | ||
| 79 | +## Hard rules | ||
| 80 | +- Own build dir: `export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-superres`. | ||
| 81 | + Foreground builds only, `nice -n 19 cargo ... -j4`. Never build in another | ||
| 82 | + worktree, never touch a sibling worktree's files. | ||
| 83 | +- Suite: `nice -n 19 cargo test -p ec-av1 --lib` (baseline 232 passed / 0 | ||
| 84 | + failed, ~67 s). Must stay green. | ||
| 85 | +- NEVER push, never merge, never touch `main`. Commit on `lane-superres` only. | ||
| 86 | +- 75-turn cap: **commit after every green milestone**; near the cap commit | ||
| 87 | + whatever compiles as `wip(av1): ...` and write `lanes/superres.report.md`. | ||
| 88 | +- Refuse-by-name rather than desync. Never claim in a refusal string that the | ||
| 89 | + encoder cannot emit a case unless you proved it. | ||
| 90 | +- Write `lanes/superres.report.md`: what landed, gate name + firing count, | ||
| 91 | + remaining refusal strings verbatim, next lever. | ||
lanes/superres.report.mdadded+78 -0
| @@ -0,0 +1,78 @@ | |||
| 1 | +VERDICT: WIP -- stage-3 gate closer but not green; two real fixes landed, one residual defect open | ||
| 2 | + | ||
| 3 | +## What changed (commit 85c070b, branch lane-superres) | ||
| 4 | +- `crates/ec-av1/src/stream.rs`: gate | ||
| 5 | + `a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact` got the | ||
| 6 | + charter's restrictive aomenc flag set, which cleared the pre-existing | ||
| 7 | + "AV1 tile: partition type this encoder never writes" capability gap | ||
| 8 | + (confirmed pre-existing, not a superres defect, per charter). | ||
| 9 | +- Same gate: added `--superres-kf-denominator=12`. Root cause found by | ||
| 10 | + tracing libaom `av1/encoder/superres_scale.c` `calculate_next_superres_scale`: | ||
| 11 | + under `AOM_SUPERRES_FIXED`, key frames read | ||
| 12 | + `superres_cfg->superres_kf_scale_denominator`, non-key frames read | ||
| 13 | + `superres_scale_denominator` -- two separate CLI flags | ||
| 14 | + (`--superres-denominator` only sets the latter). This gate's fixture uses | ||
| 15 | + `--kf-max-dist=0` (every frame a key frame per its own doc comment), so | ||
| 16 | + without the kf flag `superres_kf_scale_denominator` stayed at its default | ||
| 17 | + 8 (no scale) and `header.use_superres` decoded `false` -- confirmed with a | ||
| 18 | + temporary debug print, then reverted. | ||
| 19 | +- `crates/ec-av1/src/decode.rs`: real decoder bug, both | ||
| 20 | + `decode_key_frame_tile_with_cdfs` (line ~4993) and | ||
| 21 | + `decode_inter_frame_tile_with_cdfs` (line ~10504) cropped chroma planes | ||
| 22 | + to `fw / 2, fh / 2` (floor) when `frame_width` differs from the | ||
| 23 | + mi-aligned decode buffer width. AV1's 4:2:0 chroma-plane width is | ||
| 24 | + `ROUND_POWER_OF_TWO(fw, 1)` (div_ceil), not floor -- confirmed against | ||
| 25 | + libaom `resize.c:1124`. Odd downscaled widths (43, from this superres | ||
| 26 | + fixture) exposed it as a `debug_assert_eq!` panic in `superres.rs:135` | ||
| 27 | + (`upscale_plane` got a 21-wide chroma row, expected 22). Fixed both call | ||
| 28 | + sites -- grepped, these are the only two constructors of the cropped | ||
| 29 | + `Picture`, class swept. | ||
| 30 | + | ||
| 31 | +## What's still broken | ||
| 32 | +Gate still fails: 5 of 4096 luma pixels off by exactly 1, all near the | ||
| 33 | +right edge (x in 59..62 of a 64-wide frame). Ruled out: | ||
| 34 | +- The upscale kernel itself (`upscale_row`/`upscale_plane` in | ||
| 35 | + `superres.rs`) is pinned bit-exact against real libaom | ||
| 36 | + `av1_convolve_horiz_rs_c` via the C harness for symmetric scale cases | ||
| 37 | + (in8->out12, in8->out16) -- r1's work, unchanged this round. | ||
| 38 | +- Not a bounds bug: traced the padding math (`pad=10`, `base=6`, | ||
| 39 | + `UPSCALE_NORMATIVE_TAPS=8`) by hand, all array indices stay in range. | ||
| 40 | + | ||
| 41 | +Leading theory, NOT confirmed: `decode.rs` crops the plane to exactly | ||
| 42 | +`frame_width` (43) before `superres::upscale_picture` ever sees it, so | ||
| 43 | +`upscale_row`'s right-edge padding is a synthetic replicate of column 42. | ||
| 44 | +libaom runs `av1_superres_upscale` on the reconstructed buffer's own | ||
| 45 | +border-extended margin, which may still hold a real decoded pixel at | ||
| 46 | +mi-alignment column 43 rather than a replicate -- untested this round | ||
| 47 | +(would need threading the pre-crop plane + real width into | ||
| 48 | +`upscale_picture` instead of cropping to `fw` first). Diff pattern (only | ||
| 49 | +5 isolated pixels, not a monotonic edge band) is also consistent with a | ||
| 50 | +subtler rounding-phase edge case; not conclusively attributed either way. | ||
| 51 | + | ||
| 52 | +## Order of work not reached | ||
| 53 | +- Full scoped suite (`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib | ||
| 54 | + -j4`) not run this round -- the target gate itself was still red, ran | ||
| 55 | + `cargo check -p ec-av1 --lib --tests` only (clean) to confirm no | ||
| 56 | + compile breakage from the two fixes before committing. | ||
| 57 | +- Stage 4 (inter-frame superres, spec 7.11.3.3) not started -- blocked on | ||
| 58 | + stage 3 closing first per the charter's own ordering. | ||
| 59 | + | ||
| 60 | +## Commands | ||
| 61 | +- `cargo check -p ec-av1 --lib --tests` -- clean, 85 pre-existing doc | ||
| 62 | + warnings only. | ||
| 63 | +- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib | ||
| 64 | + a_real_aomenc_superres_key_frame_sequence -j4 -- --nocapture` -- | ||
| 65 | + FAILED: `frame 0 luma vs ffmpeg`, 5/4096 pixels off by 1 (measured via | ||
| 66 | + temporary debug instrumentation, reverted before commit). | ||
| 67 | + | ||
| 68 | +## Handoff for next round | ||
| 69 | +1. Try threading real pre-crop border pixels into `upscale_picture` | ||
| 70 | + instead of edge-replicating from the already-cropped row -- needs a | ||
| 71 | + small API change (`upscale_picture` takes the plane's real allocated | ||
| 72 | + width + a slice wide enough to cover `UPSCALE_NORMATIVE_TAPS/2+1` | ||
| 73 | + extra real columns) plus a `decode.rs` change to stop discarding that | ||
| 74 | + margin before calling it. | ||
| 75 | +2. If that doesn't close it, dump per-pixel `x_qn`/`int_pel`/`filter_idx` | ||
| 76 | + at the 5 failing output columns and hand-trace against a libaom debug | ||
| 77 | + build of the same fixture -- the diffs are too sparse for a formula | ||
| 78 | + bug, more likely a specific phase/rounding edge case. | ||
scripts/instrument-aom-oracle.shmodified+114 -0
| @@ -27,6 +27,17 @@ | |||
| 27 | # the key-frame path has no traced symbol at all between the partition | 27 | # the key-frame path has no traced symbol at all between the partition |
| 28 | # read and the first coefficient block, which is precisely the gap a | 28 | # read and the first coefficient block, which is precisely the gap a |
| 29 | # rect-strip desync hides in. | 29 | # rect-strip desync hides in. |
| 30 | +# EC_AV1_POSTDEBLOCK_DUMP=<prefix> -> <prefix>.f<N> per frame, Y then U then | ||
| 31 | +# V, full ALIGNED-buffer rows (y_width/y_height, not y_crop_width -- | ||
| 32 | +# cm->cur_frame->buf at this point is still the pre-superres buffer, | ||
| 33 | +# but its aligned width already extends past FrameWidth out to the | ||
| 34 | +# mi-aligned true width, which is exactly the margin content we need). | ||
| 35 | +# Written right after av1_loop_filter_frame_mt returns and before | ||
| 36 | +# CDEF/superres run -- ground truth for the post-deblock, pre-superres | ||
| 37 | +# row content over frame_width..true_width that decode.rs stashes as | ||
| 38 | +# its superres margin (lane-superres r5: hand-tracing the arithmetic | ||
| 39 | +# could only prove our own self-consistency, not correctness against | ||
| 40 | +# libaom). | ||
| 30 | # | 41 | # |
| 31 | # Idempotent: re-running is a no-op. Rebuild afterwards with | 42 | # Idempotent: re-running is a no-op. Rebuild afterwards with |
| 32 | # ninja -C ~/.cache/aom-oracle/build aomdec | 43 | # ninja -C ~/.cache/aom-oracle/build aomdec |
| @@ -263,3 +274,106 @@ s = s.replace(old, new, 1) | |||
| 263 | open(path, "w").write(s) | 274 | open(path, "w").write(s) |
| 264 | print("intra mode-info instrumented") | 275 | print("intra mode-info instrumented") |
| 265 | PYI | 276 | PYI |
| 277 | + | ||
| 278 | +# --- rung 6: post-deblock, pre-superres row dump ------------------------ | ||
| 279 | +python3 - "$F" <<'PYD' | ||
| 280 | +import sys | ||
| 281 | +path = sys.argv[1] | ||
| 282 | +s = open(path).read() | ||
| 283 | +if "EC_INSTRUMENTED_POSTDEBLOCK" in s: | ||
| 284 | + print("postdeblock dump already instrumented (no-op)") | ||
| 285 | + sys.exit(0) | ||
| 286 | + | ||
| 287 | +anchor = """ if (cm->lf.filter_level[0] || cm->lf.filter_level[1]) { | ||
| 288 | + av1_loop_filter_frame_mt(&cm->cur_frame->buf, cm, &pbi->dcb.xd, 0, | ||
| 289 | + num_planes, 0, pbi->tile_workers, | ||
| 290 | + pbi->num_workers, &pbi->lf_row_sync, 0); | ||
| 291 | + } | ||
| 292 | +""" | ||
| 293 | +dump = """ | ||
| 294 | + /* EC_INSTRUMENTED_POSTDEBLOCK */ | ||
| 295 | + { | ||
| 296 | + const char *ec_dump = getenv("EC_AV1_POSTDEBLOCK_DUMP"); | ||
| 297 | + if (ec_dump) { | ||
| 298 | + static int ec_postdeblock_idx = 0; | ||
| 299 | + char ec_path[1024]; | ||
| 300 | + snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump, | ||
| 301 | + ec_postdeblock_idx++); | ||
| 302 | + FILE *ec_f = fopen(ec_path, "wb"); | ||
| 303 | + if (ec_f) { | ||
| 304 | + const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf; | ||
| 305 | + /* Dump the FULL aligned buffer (y_width/y_height), not the | ||
| 306 | + * crop_width/crop_height (== FrameWidth/FrameHeight): the | ||
| 307 | + * superres margin (columns [FrameWidth, true mi-aligned width)) | ||
| 308 | + * only exists in the aligned buffer -- lane-superres r5. */ | ||
| 309 | + for (int ec_r = 0; ec_r < ec_b->y_height; ++ec_r) | ||
| 310 | + fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_width, | ||
| 311 | + ec_f); | ||
| 312 | + if (num_planes > 1) { | ||
| 313 | + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) | ||
| 314 | + fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1, | ||
| 315 | + ec_b->uv_width, ec_f); | ||
| 316 | + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) | ||
| 317 | + fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1, | ||
| 318 | + ec_b->uv_width, ec_f); | ||
| 319 | + } | ||
| 320 | + fclose(ec_f); | ||
| 321 | + } | ||
| 322 | + } | ||
| 323 | + } | ||
| 324 | +""" | ||
| 325 | +assert anchor in s, "loop filter call anchor moved" | ||
| 326 | +s = s.replace(anchor, anchor + dump, 1) | ||
| 327 | +open(path, "w").write(s) | ||
| 328 | +print("postdeblock dump instrumented") | ||
| 329 | +PYD | ||
| 330 | + | ||
| 331 | +# --- rung 7: pre-deblock, FULL aligned-buffer row dump (lane-superres r5) - | ||
| 332 | +# EC_AV1_PREFILT_DUMP (rung 1) is used by other lanes at its existing | ||
| 333 | +# y_crop_width/y_crop_height shape -- left untouched. This adds a second, | ||
| 334 | +# additive env var at the SAME anchor (pre-loop-filter) but dumping the full | ||
| 335 | +# y_width/y_height aligned buffer, so a margin-region reconstruction bug can | ||
| 336 | +# be told apart from a margin-region deblock bug. | ||
| 337 | +python3 - "$F" <<'PYW' | ||
| 338 | +import sys | ||
| 339 | +path = sys.argv[1] | ||
| 340 | +s = open(path).read() | ||
| 341 | +if "EC_INSTRUMENTED_PREFILT_WIDE" in s: | ||
| 342 | + print("prefilt-wide dump already instrumented (no-op)") | ||
| 343 | + sys.exit(0) | ||
| 344 | + | ||
| 345 | +anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync, | ||
| 346 | + pbi->num_workers, 1);""" | ||
| 347 | +dump = """ /* EC_INSTRUMENTED_PREFILT_WIDE */ | ||
| 348 | + { | ||
| 349 | + const char *ec_dump = getenv("EC_AV1_PREFILT_WIDE_DUMP"); | ||
| 350 | + if (ec_dump) { | ||
| 351 | + static int ec_prefilt_wide_idx = 0; | ||
| 352 | + char ec_path[1024]; | ||
| 353 | + snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump, | ||
| 354 | + ec_prefilt_wide_idx++); | ||
| 355 | + FILE *ec_f = fopen(ec_path, "wb"); | ||
| 356 | + if (ec_f) { | ||
| 357 | + const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf; | ||
| 358 | + for (int ec_r = 0; ec_r < ec_b->y_height; ++ec_r) | ||
| 359 | + fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_width, | ||
| 360 | + ec_f); | ||
| 361 | + if (num_planes > 1) { | ||
| 362 | + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) | ||
| 363 | + fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1, | ||
| 364 | + ec_b->uv_width, ec_f); | ||
| 365 | + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) | ||
| 366 | + fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1, | ||
| 367 | + ec_b->uv_width, ec_f); | ||
| 368 | + } | ||
| 369 | + fclose(ec_f); | ||
| 370 | + } | ||
| 371 | + } | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | +""" | ||
| 375 | +assert anchor in s, "cdef alloc anchor moved" | ||
| 376 | +s = s.replace(anchor, dump + anchor, 1) | ||
| 377 | +open(path, "w").write(s) | ||
| 378 | +print("prefilt-wide dump instrumented") | ||
| 379 | +PYW | ||
scripts/superres-pin-harness.cadded+144 -0
| @@ -0,0 +1,144 @@ | |||
| 1 | +#include <stdio.h> | ||
| 2 | +#include <stdint.h> | ||
| 3 | +#include <string.h> | ||
| 4 | + | ||
| 5 | +#define RS_SUBPEL_BITS 6 | ||
| 6 | +#define RS_SCALE_SUBPEL_BITS 14 | ||
| 7 | +#define RS_SCALE_SUBPEL_MASK ((1 << RS_SCALE_SUBPEL_BITS) - 1) | ||
| 8 | +#define RS_SCALE_EXTRA_BITS (RS_SCALE_SUBPEL_BITS - RS_SUBPEL_BITS) | ||
| 9 | +#define RS_SCALE_EXTRA_OFF (1 << (RS_SCALE_EXTRA_BITS - 1)) | ||
| 10 | +#define UPSCALE_NORMATIVE_TAPS 8 | ||
| 11 | + | ||
| 12 | +extern const int16_t av1_resize_filter_normative[1 << RS_SUBPEL_BITS][UPSCALE_NORMATIVE_TAPS]; | ||
| 13 | +extern int32_t av1_get_upscale_convolve_step(int in_length, int out_length); | ||
| 14 | +extern void av1_convolve_horiz_rs_c(const uint8_t *src, int src_stride, | ||
| 15 | + uint8_t *dst, int dst_stride, int w, | ||
| 16 | + int h, const int16_t *x_filters, | ||
| 17 | + int x0_qn, int x_step_qn); | ||
| 18 | + | ||
| 19 | +// verbatim copy of resize.c's static get_upscale_convolve_x0 -- the one | ||
| 20 | +// formula in the pipeline this harness does not exercise via a real | ||
| 21 | +// exported symbol; everything else (the coefficient table + the | ||
| 22 | +// convolution/rounding kernel, the actual bug risk) runs real compiled | ||
| 23 | +// libaom code. | ||
| 24 | +static int32_t get_upscale_convolve_x0(int in_length, int out_length, | ||
| 25 | + int32_t x_step_qn) { | ||
| 26 | + const int err = out_length * x_step_qn - (in_length << RS_SCALE_SUBPEL_BITS); | ||
| 27 | + const int32_t x0 = | ||
| 28 | + (-((out_length - in_length) << (RS_SCALE_SUBPEL_BITS - 1)) + | ||
| 29 | + out_length / 2) / | ||
| 30 | + out_length + | ||
| 31 | + RS_SCALE_EXTRA_OFF - err / 2; | ||
| 32 | + return (int32_t)((uint32_t)x0 & RS_SCALE_SUBPEL_MASK); | ||
| 33 | +} | ||
| 34 | + | ||
| 35 | +static void run_case_margin(const char *label, int in_len, int out_len, | ||
| 36 | + const uint8_t *input, const uint8_t *margin, | ||
| 37 | + int margin_len) { | ||
| 38 | + uint8_t padded[512]; | ||
| 39 | + const int pad = 32; | ||
| 40 | + uint8_t *row = padded + pad; | ||
| 41 | + memset(padded, input[0], pad); | ||
| 42 | + memcpy(row, input, in_len); | ||
| 43 | + memcpy(row + in_len, margin, margin_len); | ||
| 44 | + memset(row + in_len + margin_len, margin[margin_len - 1], pad); | ||
| 45 | + | ||
| 46 | + int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len); | ||
| 47 | + int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn); | ||
| 48 | + printf("%s: x_step_qn=%d x0_qn=%d\n", label, x_step_qn, x0_qn); | ||
| 49 | + uint8_t out[256]; | ||
| 50 | + av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1, | ||
| 51 | + &av1_resize_filter_normative[0][0], x0_qn, | ||
| 52 | + x_step_qn); | ||
| 53 | + printf("%s out:", label); | ||
| 54 | + for (int i = 0; i < out_len; i++) printf(" %d", out[i]); | ||
| 55 | + printf("\n"); | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +// Runs one row through the real compiled libaom convolver, edge-replicated | ||
| 59 | +// padding on both sides (the single-tile case, matching this decoder's | ||
| 60 | +// `superres::upscale_row`). `right_pad_col` lets the caller feed a | ||
| 61 | +// right-edge pad value that differs from `input[in_len-1]`, to test | ||
| 62 | +// r3's charter question (does the padding value change the output at | ||
| 63 | +// all near the right edge, i.e. does the failing case even depend on | ||
| 64 | +// what's beyond column `in_len-1`). | ||
| 65 | +static void run_case(const char *label, int in_len, int out_len, | ||
| 66 | + const uint8_t *input, int right_pad_val) { | ||
| 67 | + uint8_t padded[512]; | ||
| 68 | + const int pad = 32; | ||
| 69 | + uint8_t *row = padded + pad; | ||
| 70 | + memset(padded, input[0], pad); | ||
| 71 | + memcpy(row, input, in_len); | ||
| 72 | + memset(row + in_len, right_pad_val, pad); | ||
| 73 | + | ||
| 74 | + int32_t x_step_qn = av1_get_upscale_convolve_step(in_len, out_len); | ||
| 75 | + int32_t x0_qn = get_upscale_convolve_x0(in_len, out_len, x_step_qn); | ||
| 76 | + printf("%s: in_len=%d out_len=%d x_step_qn=%d x0_qn=%d right_pad=%d\n", | ||
| 77 | + label, in_len, out_len, x_step_qn, x0_qn, right_pad_val); | ||
| 78 | + | ||
| 79 | + uint8_t out[256]; | ||
| 80 | + av1_convolve_horiz_rs_c(row - 1, 0, out, 0, out_len, 1, | ||
| 81 | + &av1_resize_filter_normative[0][0], x0_qn, | ||
| 82 | + x_step_qn); | ||
| 83 | + printf("%s out:", label); | ||
| 84 | + for (int i = 0; i < out_len; i++) printf(" %d", out[i]); | ||
| 85 | + printf("\n"); | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +int main(void) { | ||
| 89 | + uint8_t input8[8] = { 10, 20, 30, 40, 50, 60, 70, 80 }; | ||
| 90 | + run_case("in8->out12", 8, 12, input8, input8[7]); | ||
| 91 | + run_case("in8->out16", 8, 16, input8, input8[7]); | ||
| 92 | + | ||
| 93 | + // r3: the exact failing ratio (43 -> 64), row 6 of the real aomenc | ||
| 94 | + // superres key-frame gate fixture (`EC_SUPERRES_DEBUG=1` dump of the | ||
| 95 | + // input row this decoder feeds `upscale_row`, matched against the | ||
| 96 | + // `DIFF frame=0 row=6 col=62 got=140 want=141` mismatch). Run once | ||
| 97 | + // with the replicate-from-column-42 padding this decoder uses, and | ||
| 98 | + // once with a right pad value that visibly differs, to settle whether | ||
| 99 | + // the failing columns even read past the real input at all. | ||
| 100 | + uint8_t row6[43] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, | ||
| 101 | + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, | ||
| 102 | + 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, | ||
| 103 | + 130, 130, 131, 131, 133, 134, 136, 137, 138, 139, | ||
| 104 | + 140, 140, 141 }; | ||
| 105 | + run_case("row6-replicate", 43, 64, row6, row6[42]); | ||
| 106 | + run_case("row6-farpad", 43, 64, row6, 255); | ||
| 107 | + | ||
| 108 | + // r3 decisive check: `CROPDBG` dumped the pre-crop reconstructed row at | ||
| 109 | + // the real (mi-aligned) width 48 -- columns 43..47 are genuine decoded | ||
| 110 | + // pixels (140,140,140,140,140), NOT a replicate of column 42 (141, this | ||
| 111 | + // decoder's current padding value). Feed the real trailing pixels | ||
| 112 | + // instead of a flat replicate and see if the failing columns change. | ||
| 113 | + uint8_t row6_real48[48] = { 102, 102, 103, 103, 104, 105, 106, 107, 108, 109, | ||
| 114 | + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, | ||
| 115 | + 120, 121, 122, 123, 125, 126, 127, 127, 128, 129, | ||
| 116 | + 130, 130, 131, 131, 133, 134, 136, 137, 138, 139, | ||
| 117 | + 140, 140, 141, 140, 140, 140, 140, 140 }; | ||
| 118 | + run_case("row6-realpad48", 48, 64, row6_real48, row6_real48[47]); | ||
| 119 | + // Same real trailing pixels but in_len still 43 (matches frame_width), | ||
| 120 | + // right_pad taken from the first real trailing pixel (140) rather than | ||
| 121 | + // the frame-edge pixel (141) -- the actual libaom border-extend source. | ||
| 122 | + run_case("row6-realedgeval", 43, 64, row6, 140); | ||
| 123 | + | ||
| 124 | + // r3 round 2: frame 2's rows 17/18 still mismatched by 1 at col 62 with | ||
| 125 | + // the flat-margin fix landed. Their real margin is NOT flat (a gradient | ||
| 126 | + // slope continues past the frame edge), so this checks the fix's | ||
| 127 | + // n-real-pixels-then-replicate strategy against the true 5-pixel margin. | ||
| 128 | + uint8_t row17[43] = { 109, 109, 109, 110, 111, 112, 112, 113, 114, 115, | ||
| 129 | + 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, | ||
| 130 | + 126, 127, 128, 129, 130, 131, 131, 132, 133, 134, | ||
| 131 | + 135, 136, 137, 139, 139, 140, 140, 141, 142, 142, | ||
| 132 | + 143, 144, 145 }; | ||
| 133 | + uint8_t margin17[5] = { 146, 146, 147, 147, 147 }; | ||
| 134 | + run_case_margin("row17-margin", 43, 64, row17, margin17, 5); | ||
| 135 | + | ||
| 136 | + uint8_t row18[43] = { 109, 110, 110, 110, 111, 112, 113, 114, 115, 116, | ||
| 137 | + 117, 118, 119, 120, 121, 122, 122, 123, 124, 125, | ||
| 138 | + 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, | ||
| 139 | + 134, 136, 138, 140, 139, 140, 140, 141, 142, 142, | ||
| 140 | + 143, 144, 145 }; | ||
| 141 | + uint8_t margin18[5] = { 146, 147, 147, 148, 148 }; | ||
| 142 | + run_case_margin("row18-margin", 43, 64, row18, margin18, 5); | ||
| 143 | + return 0; | ||
| 144 | +} | ||