Merge lane-rectsplit 4c3389a: per-attempt gate counters on the three rect-split gates, EC_NZOFF_DUMP/EC_SBPART_DUMP64 instruments, SB split-tx refusal kept (r2's nz_map transposition disproved by the merged SB HORZ/VERT gate); decode_probe dump kept main's version
Browse files at this commit3 changed files +294 -40
- crates/ec-av1/src/decode.rs +95 -11
- crates/ec-av1/src/stream.rs +110 -29
- lanes/rectsplit-r2.report.md +89 -0
crates/ec-av1/src/decode.rsmodified+95 -11
| @@ -807,6 +807,22 @@ pub(crate) fn rect_split_tx_hits() -> usize { | |||
| 807 | RECT_SPLIT_TX_HITS.with(|c| c.get()) | 807 | RECT_SPLIT_TX_HITS.with(|c| c.get()) |
| 808 | } | 808 | } |
| 809 | 809 | ||
| 810 | +// The subset of [`RECT_SPLIT_TX_HITS`] that is BOTH superblock-level (one | ||
| 811 | +// side 64) AND split past the first depth, i.e. tiled more than one unit in | ||
| 812 | +// each axis -- the only shape with a transform unit that has neighbours on | ||
| 813 | +// two sides inside its own strip (`row_off > 0 && col_off > 0`), and the one | ||
| 814 | +// no gate fired before lane-rectsplit r2 (the shared counter above also | ||
| 815 | +// counts 32x32-level and depth-1 strips, so it cannot prove this case). | ||
| 816 | +thread_local! { | ||
| 817 | + static RECT_SPLIT_SB_INTERIOR_TU_HITS: std::cell::Cell<usize> = | ||
| 818 | + const { std::cell::Cell::new(0) }; | ||
| 819 | +} | ||
| 820 | + | ||
| 821 | +/// Current value of [`RECT_SPLIT_SB_INTERIOR_TU_HITS`]. | ||
| 822 | +pub(crate) fn rect_split_sb_interior_tu_hits() -> usize { | ||
| 823 | + RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.get()) | ||
| 824 | +} | ||
| 825 | + | ||
| 810 | // How many HORZ/VERT intra strips actually predicted with filter intra | 826 | // How many HORZ/VERT intra strips actually predicted with filter intra |
| 811 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name | 827 | // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name |
| 812 | // ("this decoder predicts square-only") until `predict_filter_intra` took | 828 | // ("this decoder predicts square-only") until `predict_filter_intra` took |
| @@ -1674,11 +1690,32 @@ fn base_ctx( | |||
| 1674 | // (lane-sbpart r8 root cause: `(row=1, col=0)` reads ctx 2 under the | 1690 | // (lane-sbpart r8 root cause: `(row=1, col=0)` reads ctx 2 under the |
| 1675 | // square table vs the real ctx 13 the rect table gives). | 1691 | // square table vs the real ctx 13 the rect table gives). |
| 1676 | TxClass::TwoD => { | 1692 | TxClass::TwoD => { |
| 1693 | + // OPEN (lane-rectsplit r3, measured): the two rect | ||
| 1694 | + // transcriptions in [`cdf`] are packed `[col][row]` -- libaom's | ||
| 1695 | + // `av1_nz_map_ctx_offset_32x64` is a FLAT 1024-entry array whose | ||
| 1696 | + // `coeff_idx` is COLUMN-major with stride 32 (`TX_CLASS_HORIZ` | ||
| 1697 | + // reads its column back as `coeff_idx >> bhl`), and entries | ||
| 1698 | + // 0..5 / 32..35 match the generating rule (txb_common.h:199-209) | ||
| 1699 | + // only under `flat[col * 32 + row]`; | ||
| 1700 | + // `nz_map_ctx_offset_tables_match_the_rect_rule` pins that. | ||
| 1701 | + // Yet reading `[col][row]` here BREAKS | ||
| 1702 | + // `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` | ||
| 1703 | + // (seed 43) while `[row][col]` breaks the split-transform SB gate | ||
| 1704 | + // (seed 50); swapping the shape test as well fails BOTH ways. So | ||
| 1705 | + // this read is not the defect -- our (row, col) here come from a | ||
| 1706 | + // square 32x32-corner scan whose orientation relative to libaom's | ||
| 1707 | + // column-major `coeff_idx` is what is really unproven, and each | ||
| 1708 | + // "fix" only moves which rare corner position desyncs. Left at | ||
| 1709 | + // the r1 reading, the one every merged gate is green under. | ||
| 1710 | + // `EC_NZOFF_DUMP=1` prints every rect-shaped read. | ||
| 1677 | let table = match rect_shape { | 1711 | let table = match rect_shape { |
| 1678 | Some((w, h)) if w < h => &cdf::NZ_MAP_CTX_OFFSET_32X64, | 1712 | Some((w, h)) if w < h => &cdf::NZ_MAP_CTX_OFFSET_32X64, |
| 1679 | Some((w, h)) if w > h => &cdf::NZ_MAP_CTX_OFFSET_64X32, | 1713 | Some((w, h)) if w > h => &cdf::NZ_MAP_CTX_OFFSET_64X32, |
| 1680 | _ => &cdf::NZ_MAP_CTX_OFFSET_32, | 1714 | _ => &cdf::NZ_MAP_CTX_OFFSET_32, |
| 1681 | }; | 1715 | }; |
| 1716 | + if std::env::var_os("EC_NZOFF_DUMP").is_some() { | ||
| 1717 | + eprintln!("NZOFF side={side} shape={rect_shape:?} row={row} col={col}"); | ||
| 1718 | + } | ||
| 1682 | ctx + table[row.min(4)][col.min(4)] as usize | 1719 | ctx + table[row.min(4)][col.min(4)] as usize |
| 1683 | } | 1720 | } |
| 1684 | TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), | 1721 | TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)), |
| @@ -3880,12 +3917,22 @@ fn decode_rect_split( | |||
| 3880 | (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])), | 3917 | (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])), |
| 3881 | _ => None, | 3918 | _ => None, |
| 3882 | }; | 3919 | }; |
| 3920 | + // lane-rectsplit r2 (verifier finding): with both callers wired | ||
| 3921 | + // (`decode_block_rect`'s 32x16/16x32 and `decode_block_rect64`'s | ||
| 3922 | + // 64x32/32x64) every shape that reaches here has a table above, so this | ||
| 3923 | + // arm is UNREACHABLE today. It stays as the shape guard for the next | ||
| 3924 | + // caller -- a new strip size would otherwise hit the `expect` below and | ||
| 3925 | + // panic instead of refusing by name -- and so stays in | ||
| 3926 | + // `refusal_inventory::REFUSALS`. | ||
| 3883 | if !m.skip && chroma.is_none() { | 3927 | if !m.skip && chroma.is_none() { |
| 3884 | return Err(unsupported( | 3928 | return Err(unsupported( |
| 3885 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", | 3929 | "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here", |
| 3886 | )); | 3930 | )); |
| 3887 | } | 3931 | } |
| 3888 | RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | 3932 | RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); |
| 3933 | + if bw.max(bh) == 64 && bw / tx > 1 && bh / tx > 1 { | ||
| 3934 | + RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.set(c.get() + 1)); | ||
| 3935 | + } | ||
| 3889 | // LUMA: `bw/tx` x `bh/tx` square transform units, raster order. | 3936 | // LUMA: `bw/tx` x `bh/tx` square transform units, raster order. |
| 3890 | let luma_set = txbset_for(tx, reduced_tx_set); | 3937 | let luma_set = txbset_for(tx, reduced_tx_set); |
| 3891 | let luma_scan = default_scan(tx); | 3938 | let luma_scan = default_scan(tx); |
| @@ -4147,6 +4194,13 @@ fn decode_block_rect( | |||
| 4147 | // [`decode_rect_split`]. `depth_to_tx_size` of a 2:1 strip is square | 4194 | // [`decode_rect_split`]. `depth_to_tx_size` of a 2:1 strip is square |
| 4148 | // from the first step on, so `bw.min(bh) >> (depth - 1)` names it. | 4195 | // from the first step on, so `bw.min(bh) >> (depth - 1)` names it. |
| 4149 | let tx = bw.min(bh) >> (depth - 1); | 4196 | let tx = bw.min(bh) >> (depth - 1); |
| 4197 | + if std::env::var_os("EC_SBPART_DUMP64").is_some() { | ||
| 4198 | + eprintln!( | ||
| 4199 | + "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \ | ||
| 4200 | + depth={depth} tx={tx} mode={mode} uv={uv_predict_mode} skip={skip} \ | ||
| 4201 | + angle_y={angle_delta_y}" | ||
| 4202 | + ); | ||
| 4203 | + } | ||
| 4150 | let modes = RectStripModes { | 4204 | let modes = RectStripModes { |
| 4151 | skip, | 4205 | skip, |
| 4152 | mode, | 4206 | mode, |
| @@ -4669,18 +4723,16 @@ fn decode_block_rect64( | |||
| 4669 | }; | 4723 | }; |
| 4670 | if depth != 0 { | 4724 | if depth != 0 { |
| 4671 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 4725 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 4672 | - // lane-rectsplit r1: [`decode_rect_split`] handles this shape too | 4726 | + // lane-rectsplit r1/r3: [`decode_rect_split`] handles this shape too |
| 4673 | - // (`sub_tx_size_map[TX_64X32]` is `TX_32X32`, so a depth-1 unit here | 4727 | + // and the per-unit port is wired here, but the gate |
| 4674 | - // is a plain square 32x32) and its 32x32-level sibling arm in | ||
| 4675 | - // [`decode_block_rect`] is gated pixel-exact -- but at the SUPERBLOCK | ||
| 4676 | - // level the gate | ||
| 4677 | // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`, | 4728 | // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`, |
| 4678 | - // `#[ignore]`d with its measurement) still comes out ONE sample off | 4729 | + // `#[ignore]`d with its measurement) is still RED at seed 50 (luma |
| 4679 | - // (seed 50, luma (171,56) ours 147 vs ffmpeg 148, inside a 64x32 | 4730 | + // (171,56), ours 147 vs ffmpeg 148). r2 believed the cause was a |
| 4680 | - // strip whose transform resolved to depth 2 / TX_16X16). A refusal | 4731 | + // transposed `av1_nz_map_ctx_offset` read; r3 measured that |
| 4681 | - // this lane could not lift is not a refusal it may silently ship | 4732 | + // transposing it turns THIS gate green and the merged SB-level |
| 4682 | - // wrong pixels past, so the named refusal stays until that gate is | 4733 | + // HORZ/VERT partition gate RED (seed 43), so the cause is still |
| 4683 | - // green. | 4734 | + // open. A refusal this lane cannot lift is not one it may ship wrong |
| 4735 | + // pixels past. | ||
| 4684 | return Err(unsupported( | 4736 | return Err(unsupported( |
| 4685 | "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \ | 4737 | "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \ |
| 4686 | prediction is not ported)", | 4738 | prediction is not ported)", |
| @@ -15377,6 +15429,38 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 15377 | mod tests { | 15429 | mod tests { |
| 15378 | use super::*; | 15430 | use super::*; |
| 15379 | 15431 | ||
| 15432 | + /// lane-rectsplit r2: `av1_nz_map_ctx_offset` is packed COLUMN-major, so | ||
| 15433 | + /// the two rect transcriptions in [`cdf`] must be read `[col][row]`. | ||
| 15434 | + /// [`base_ctx_rect`] states libaom's generating rule | ||
| 15435 | + /// (`txb_common.h:199-209`) in display coordinates; this pins the tables | ||
| 15436 | + /// against it, which is what a transposed read would break. | ||
| 15437 | + #[test] | ||
| 15438 | + fn nz_map_ctx_offset_tables_match_the_rect_rule() { | ||
| 15439 | + for (w, h, table) in [ | ||
| 15440 | + (32usize, 64usize, &cdf::NZ_MAP_CTX_OFFSET_32X64), | ||
| 15441 | + (64, 32, &cdf::NZ_MAP_CTX_OFFSET_64X32), | ||
| 15442 | + ] { | ||
| 15443 | + for row in 0..5usize { | ||
| 15444 | + for col in 0..5usize { | ||
| 15445 | + let want = if row == 0 && col == 0 { | ||
| 15446 | + 0 | ||
| 15447 | + } else if w < h && row < 2 { | ||
| 15448 | + 11 | ||
| 15449 | + } else if w > h && col < 2 { | ||
| 15450 | + 16 | ||
| 15451 | + } else { | ||
| 15452 | + cdf::NZ_MAP_CTX_OFFSET_32[row][col] | ||
| 15453 | + }; | ||
| 15454 | + assert_eq!( | ||
| 15455 | + table[col][row], | ||
| 15456 | + want, | ||
| 15457 | + "{w}x{h} nz_map offset at display (row {row}, col {col})" | ||
| 15458 | + ); | ||
| 15459 | + } | ||
| 15460 | + } | ||
| 15461 | + } | ||
| 15462 | + } | ||
| 15463 | + | ||
| 15380 | // `crate::tile`'s `flat_key_frame_tile`/`dc_key_frame_tile_levels`/ | 15464 | // `crate::tile`'s `flat_key_frame_tile`/`dc_key_frame_tile_levels`/ |
| 15381 | // `split_dc_key_frame_tile` are not exercised here: they are synthetic | 15465 | // `split_dc_key_frame_tile` are not exercised here: they are synthetic |
| 15382 | // single-purpose writers with their own skip-context rule (keyed to | 15466 | // single-purpose writers with their own skip-context rule (keyed to |
crates/ec-av1/src/stream.rsmodified+110 -29
| @@ -11427,6 +11427,13 @@ mod tests { | |||
| 11427 | let before = crate::decode::rect_split_tx_hits(); | 11427 | let before = crate::decode::rect_split_tx_hits(); |
| 11428 | let mut named_refusals = 0u32; | 11428 | let mut named_refusals = 0u32; |
| 11429 | let mut matched = 0u32; | 11429 | let mut matched = 0u32; |
| 11430 | + // lane-rectsplit r2 (verifier finding): the feature counter is | ||
| 11431 | + // sampled PER ATTEMPT and folded in only after that attempt was | ||
| 11432 | + // decoded AND pixel-compared. One delta across the whole sweep | ||
| 11433 | + // counted strips decoded by attempts that went on to hit a named | ||
| 11434 | + // refusal, so the gate could pass with every COMPARED stream | ||
| 11435 | + // containing none of the feature at all. | ||
| 11436 | + let mut compared_hits = 0usize; | ||
| 11430 | let mut split_so_far = 0usize; | 11437 | let mut split_so_far = 0usize; |
| 11431 | // Bounded sweep: see this gate's own doc for the seed-77 residue and | 11438 | // Bounded sweep: see this gate's own doc for the seed-77 residue and |
| 11432 | // why extending it is a diagnosis knob, not a pass/fail one. | 11439 | // why extending it is a diagnosis knob, not a pass/fail one. |
| @@ -11509,6 +11516,7 @@ mod tests { | |||
| 11509 | ); | 11516 | ); |
| 11510 | let stream = out.stdout; | 11517 | let stream = out.stdout; |
| 11511 | assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); | 11518 | assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); |
| 11519 | + let attempt_before = crate::decode::rect_split_tx_hits(); | ||
| 11512 | let frames = match decode_stream(&stream) { | 11520 | let frames = match decode_stream(&stream) { |
| 11513 | Err(e) => { | 11521 | Err(e) => { |
| 11514 | let msg = e.to_string(); | 11522 | let msg = e.to_string(); |
| @@ -11535,20 +11543,36 @@ mod tests { | |||
| 11535 | .zip(&ffmpeg_frames[0].y) | 11543 | .zip(&ffmpeg_frames[0].y) |
| 11536 | .position(|(a, b)| a != b) | 11544 | .position(|(a, b)| a != b) |
| 11537 | { | 11545 | { |
| 11546 | + let diffs: Vec<usize> = frames[0] | ||
| 11547 | + .y | ||
| 11548 | + .iter() | ||
| 11549 | + .zip(&ffmpeg_frames[0].y) | ||
| 11550 | + .enumerate() | ||
| 11551 | + .filter(|(_, (a, b))| a != b) | ||
| 11552 | + .map(|(j, _)| j) | ||
| 11553 | + .collect(); | ||
| 11554 | + let (x0, x1) = ( | ||
| 11555 | + diffs.iter().map(|j| j % width).min().unwrap(), | ||
| 11556 | + diffs.iter().map(|j| j % width).max().unwrap(), | ||
| 11557 | + ); | ||
| 11558 | + let (y0, y1) = (diffs[0] / width, diffs[diffs.len() - 1] / width); | ||
| 11538 | eprintln!( | 11559 | eprintln!( |
| 11539 | - "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", | 11560 | + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={} \ |
| 11561 | + -- {} mismatching samples, bbox x {x0}..={x1} y {y0}..={y1}", | ||
| 11540 | i % width, | 11562 | i % width, |
| 11541 | i / width, | 11563 | i / width, |
| 11542 | frames[0].y[i], | 11564 | frames[0].y[i], |
| 11543 | - ffmpeg_frames[0].y[i] | 11565 | + ffmpeg_frames[0].y[i], |
| 11566 | + diffs.len(), | ||
| 11544 | ); | 11567 | ); |
| 11545 | } | 11568 | } |
| 11546 | assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | 11569 | assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); |
| 11547 | assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | 11570 | assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); |
| 11548 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | 11571 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); |
| 11572 | + compared_hits += crate::decode::rect_split_tx_hits() - attempt_before; | ||
| 11549 | matched += 1; | 11573 | matched += 1; |
| 11550 | } | 11574 | } |
| 11551 | - let split_hits = crate::decode::rect_split_tx_hits() - before; | 11575 | + let split_hits = compared_hits; |
| 11552 | assert!( | 11576 | assert!( |
| 11553 | matched > 0, | 11577 | matched > 0, |
| 11554 | "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" | 11578 | "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" |
| @@ -11588,11 +11612,17 @@ mod tests { | |||
| 11588 | return; | 11612 | return; |
| 11589 | } | 11613 | } |
| 11590 | let (width, height) = (192usize, 128usize); | 11614 | let (width, height) = (192usize, 128usize); |
| 11591 | - let before = crate::decode::filter_intra_rect_hits(); | ||
| 11592 | let rect_before = crate::decode::rect_partition_hits(); | 11615 | let rect_before = crate::decode::rect_partition_hits(); |
| 11593 | let fi_square_before = crate::decode::filter_intra_hits(); | 11616 | let fi_square_before = crate::decode::filter_intra_hits(); |
| 11594 | let mut named_refusals = 0u32; | 11617 | let mut named_refusals = 0u32; |
| 11595 | let mut matched = 0u32; | 11618 | let mut matched = 0u32; |
| 11619 | + // lane-rectsplit r2 (verifier finding): the feature counter is | ||
| 11620 | + // sampled PER ATTEMPT and folded in only after that attempt was | ||
| 11621 | + // decoded AND pixel-compared. One delta across the whole sweep | ||
| 11622 | + // counted strips decoded by attempts that went on to hit a named | ||
| 11623 | + // refusal, so the gate could pass with every COMPARED stream | ||
| 11624 | + // containing none of the feature at all. | ||
| 11625 | + let mut compared_hits = 0usize; | ||
| 11596 | let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS") | 11626 | let n_attempts: u32 = std::env::var("EC_RECTSPLIT_GATE_ATTEMPTS") |
| 11597 | .ok() | 11627 | .ok() |
| 11598 | .and_then(|s| s.parse().ok()) | 11628 | .and_then(|s| s.parse().ok()) |
| @@ -11656,13 +11686,15 @@ mod tests { | |||
| 11656 | "--deltaq-mode=0", | 11686 | "--deltaq-mode=0", |
| 11657 | // The point of this gate. | 11687 | // The point of this gate. |
| 11658 | "--enable-filter-intra=1", | 11688 | "--enable-filter-intra=1", |
| 11659 | - // The square filter-intra gate's own way of making RD reach | 11689 | + // NOTE (lane-rectsplit r2, verifier finding): every intra |
| 11660 | - // for filter intra at all: with the directional/smooth/paeth | 11690 | + // mode stays ON here. The square filter-intra gate reaches |
| 11661 | - // competitors off, DC_PRED + filter intra is what is left | 11691 | + // for filter intra by switching the directional/smooth/paeth |
| 11662 | - // (recipe borrowed from | 11692 | + // competitors off, and this gate CANNOT: with them off |
| 11663 | - // `a_real_aomenc_filter_intra_stream_decodes_pixel_exact`; | 11693 | + // aomenc stops picking rect partitions at all (rect |
| 11664 | - // without them 20/20 streams picked filter intra zero times | 11694 | + // strips 0/20 seeds, r1's table). What fires filter intra on |
| 11665 | - // on a strip -- measured this round). | 11695 | + // a strip here is the quantiser (`--cq-level=25`), not the |
| 11696 | + // mode set -- `EC_RECTSPLIT_OFF` below is the diagnosis knob | ||
| 11697 | + // that re-runs the subset search. | ||
| 11666 | "--enable-cfl-intra=0", | 11698 | "--enable-cfl-intra=0", |
| 11667 | "--enable-intrabc=0", | 11699 | "--enable-intrabc=0", |
| 11668 | "--obu", | 11700 | "--obu", |
| @@ -11708,6 +11740,7 @@ mod tests { | |||
| 11708 | ); | 11740 | ); |
| 11709 | let stream = out.stdout; | 11741 | let stream = out.stdout; |
| 11710 | assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); | 11742 | assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); |
| 11743 | + let attempt_before = crate::decode::filter_intra_rect_hits(); | ||
| 11711 | let frames = match decode_stream(&stream) { | 11744 | let frames = match decode_stream(&stream) { |
| 11712 | Err(e) => { | 11745 | Err(e) => { |
| 11713 | let msg = e.to_string(); | 11746 | let msg = e.to_string(); |
| @@ -11728,20 +11761,36 @@ mod tests { | |||
| 11728 | .zip(&ffmpeg_frames[0].y) | 11761 | .zip(&ffmpeg_frames[0].y) |
| 11729 | .position(|(a, b)| a != b) | 11762 | .position(|(a, b)| a != b) |
| 11730 | { | 11763 | { |
| 11764 | + let diffs: Vec<usize> = frames[0] | ||
| 11765 | + .y | ||
| 11766 | + .iter() | ||
| 11767 | + .zip(&ffmpeg_frames[0].y) | ||
| 11768 | + .enumerate() | ||
| 11769 | + .filter(|(_, (a, b))| a != b) | ||
| 11770 | + .map(|(j, _)| j) | ||
| 11771 | + .collect(); | ||
| 11772 | + let (x0, x1) = ( | ||
| 11773 | + diffs.iter().map(|j| j % width).min().unwrap(), | ||
| 11774 | + diffs.iter().map(|j| j % width).max().unwrap(), | ||
| 11775 | + ); | ||
| 11776 | + let (y0, y1) = (diffs[0] / width, diffs[diffs.len() - 1] / width); | ||
| 11731 | eprintln!( | 11777 | eprintln!( |
| 11732 | - "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", | 11778 | + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={} \ |
| 11779 | + -- {} mismatching samples, bbox x {x0}..={x1} y {y0}..={y1}", | ||
| 11733 | i % width, | 11780 | i % width, |
| 11734 | i / width, | 11781 | i / width, |
| 11735 | frames[0].y[i], | 11782 | frames[0].y[i], |
| 11736 | - ffmpeg_frames[0].y[i] | 11783 | + ffmpeg_frames[0].y[i], |
| 11784 | + diffs.len(), | ||
| 11737 | ); | 11785 | ); |
| 11738 | } | 11786 | } |
| 11739 | assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | 11787 | assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); |
| 11740 | assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | 11788 | assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); |
| 11741 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | 11789 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); |
| 11790 | + compared_hits += crate::decode::filter_intra_rect_hits() - attempt_before; | ||
| 11742 | matched += 1; | 11791 | matched += 1; |
| 11743 | } | 11792 | } |
| 11744 | - let fi_hits = crate::decode::filter_intra_rect_hits() - before; | 11793 | + let fi_hits = compared_hits; |
| 11745 | eprintln!( | 11794 | eprintln!( |
| 11746 | "{NAME}: rect strips this run={}, filter-intra blocks (any shape)={}", | 11795 | "{NAME}: rect strips this run={}, filter-intra blocks (any shape)={}", |
| 11747 | crate::decode::rect_partition_hits() - rect_before, | 11796 | crate::decode::rect_partition_hits() - rect_before, |
| @@ -11768,17 +11817,24 @@ mod tests { | |||
| 11768 | /// `--enable-tx-size-search=0` DROPPED: the 64x32/32x64 strips may then | 11817 | /// `--enable-tx-size-search=0` DROPPED: the 64x32/32x64 strips may then |
| 11769 | /// carry a split transform, which [`crate::decode::decode_block_rect64`] | 11818 | /// carry a split transform, which [`crate::decode::decode_block_rect64`] |
| 11770 | /// refused by name ("a superblock-level HORZ/VERT strip with a split | 11819 | /// refused by name ("a superblock-level HORZ/VERT strip with a split |
| 11771 | - /// transform") until this round. Same hard `rect_split_tx_hits()` delta | 11820 | + /// transform") until lane-rectsplit r2 lifted it. |
| 11772 | - /// assert as gate (a). | 11821 | + /// |
| 11773 | - /// lane-rectsplit r1 MEASURED RED, `#[ignore]`d with its number (the | 11822 | + /// The hard assert is on [`crate::decode::rect_split_sb_interior_tu_hits`], |
| 11774 | - /// `rect64q` gate's own precedent): with the per-transform-unit port | 11823 | + /// NOT the shared `rect_split_tx_hits()` gate (a) uses: that counter also |
| 11775 | - /// wired at the superblock level, seed 50 decodes one sample off -- | 11824 | + /// counts 32x32-level and depth-1 strips, whose units are all in the |
| 11776 | - /// luma (171, 56), ours 147 vs ffmpeg 148, inside the 64x32 strip at | 11825 | + /// first transform-unit row/column. Only a superblock-level strip split |
| 11777 | - /// mi=(8,32) whose transform resolved to depth 2 (TX_16X16). Seeds 42-49 | 11826 | + /// past depth 1 has an INTERIOR unit (`row_off > 0 && col_off > 0`), |
| 11778 | - /// with depth-1 (TX_32X32) units were pixel-exact. The refusal in | 11827 | + /// which is the per-unit availability rule this port exists for, and no |
| 11779 | - /// `decode_block_rect64` was therefore RESTORED rather than lifted; run | 11828 | + /// gate fired one before this round. |
| 11780 | - /// this gate (`--ignored`) after any fix to that arm. | 11829 | + /// |
| 11781 | - #[ignore = "lane-rectsplit r1: measured RED, seed 50 luma (171,56) off by one; refusal kept"] | 11830 | + /// This gate was `#[ignore]`d RED through r1 (seed 50 luma (171,56)). |
| 11831 | + /// Root cause, r2: not availability at all -- `av1_nz_map_ctx_offset` is | ||
| 11832 | + /// packed COLUMN-major, so [`crate::decode::base_ctx`] read the | ||
| 11833 | + /// `TX_32X64`/`TX_64X32` offset tables transposed and desynced the first | ||
| 11834 | + /// SB-level strip whose luma corner held a coefficient below row 1 (see | ||
| 11835 | + /// that function's comment). The strip's own per-unit prediction was | ||
| 11836 | + /// already exact. | ||
| 11837 | + #[ignore = "lane-rectsplit r3: RED at seed 50; the nz_map transposition r2 blamed turns the merged SB HORZ/VERT partition gate RED at seed 43, cause still open"] | ||
| 11782 | #[test] | 11838 | #[test] |
| 11783 | fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() { | 11839 | fn a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact() { |
| 11784 | const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact"; | 11840 | const NAME: &str = "a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact"; |
| @@ -11795,6 +11851,13 @@ mod tests { | |||
| 11795 | let before = crate::decode::rect_split_tx_hits(); | 11851 | let before = crate::decode::rect_split_tx_hits(); |
| 11796 | let mut named_refusals = 0u32; | 11852 | let mut named_refusals = 0u32; |
| 11797 | let mut matched = 0u32; | 11853 | let mut matched = 0u32; |
| 11854 | + // lane-rectsplit r2 (verifier finding): the feature counter is | ||
| 11855 | + // sampled PER ATTEMPT and folded in only after that attempt was | ||
| 11856 | + // decoded AND pixel-compared. One delta across the whole sweep | ||
| 11857 | + // counted strips decoded by attempts that went on to hit a named | ||
| 11858 | + // refusal, so the gate could pass with every COMPARED stream | ||
| 11859 | + // containing none of the feature at all. | ||
| 11860 | + let mut compared_hits = 0usize; | ||
| 11798 | let mut split_so_far = 0usize; | 11861 | let mut split_so_far = 0usize; |
| 11799 | // Bounded sweep: see this gate's own doc for the seed-77 residue and | 11862 | // Bounded sweep: see this gate's own doc for the seed-77 residue and |
| 11800 | // why extending it is a diagnosis knob, not a pass/fail one. | 11863 | // why extending it is a diagnosis knob, not a pass/fail one. |
| @@ -11877,6 +11940,7 @@ mod tests { | |||
| 11877 | ); | 11940 | ); |
| 11878 | let stream = out.stdout; | 11941 | let stream = out.stdout; |
| 11879 | assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); | 11942 | assert!(!stream.is_empty(), "{NAME}: aomenc wrote an empty stream (seed {seed})"); |
| 11943 | + let attempt_before = crate::decode::rect_split_sb_interior_tu_hits(); | ||
| 11880 | let frames = match decode_stream(&stream) { | 11944 | let frames = match decode_stream(&stream) { |
| 11881 | Err(e) => { | 11945 | Err(e) => { |
| 11882 | let msg = e.to_string(); | 11946 | let msg = e.to_string(); |
| @@ -11903,20 +11967,36 @@ mod tests { | |||
| 11903 | .zip(&ffmpeg_frames[0].y) | 11967 | .zip(&ffmpeg_frames[0].y) |
| 11904 | .position(|(a, b)| a != b) | 11968 | .position(|(a, b)| a != b) |
| 11905 | { | 11969 | { |
| 11970 | + let diffs: Vec<usize> = frames[0] | ||
| 11971 | + .y | ||
| 11972 | + .iter() | ||
| 11973 | + .zip(&ffmpeg_frames[0].y) | ||
| 11974 | + .enumerate() | ||
| 11975 | + .filter(|(_, (a, b))| a != b) | ||
| 11976 | + .map(|(j, _)| j) | ||
| 11977 | + .collect(); | ||
| 11978 | + let (x0, x1) = ( | ||
| 11979 | + diffs.iter().map(|j| j % width).min().unwrap(), | ||
| 11980 | + diffs.iter().map(|j| j % width).max().unwrap(), | ||
| 11981 | + ); | ||
| 11982 | + let (y0, y1) = (diffs[0] / width, diffs[diffs.len() - 1] / width); | ||
| 11906 | eprintln!( | 11983 | eprintln!( |
| 11907 | - "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={}", | 11984 | + "{NAME}: seed {seed} first luma mismatch at ({}, {}) ours={} ffmpeg={} \ |
| 11985 | + -- {} mismatching samples, bbox x {x0}..={x1} y {y0}..={y1}", | ||
| 11908 | i % width, | 11986 | i % width, |
| 11909 | i / width, | 11987 | i / width, |
| 11910 | frames[0].y[i], | 11988 | frames[0].y[i], |
| 11911 | - ffmpeg_frames[0].y[i] | 11989 | + ffmpeg_frames[0].y[i], |
| 11990 | + diffs.len(), | ||
| 11912 | ); | 11991 | ); |
| 11913 | } | 11992 | } |
| 11914 | assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | 11993 | assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); |
| 11915 | assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | 11994 | assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); |
| 11916 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | 11995 | assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); |
| 11996 | + compared_hits += crate::decode::rect_split_sb_interior_tu_hits() - attempt_before; | ||
| 11917 | matched += 1; | 11997 | matched += 1; |
| 11918 | } | 11998 | } |
| 11919 | - let split_hits = crate::decode::rect_split_tx_hits() - before; | 11999 | + let split_hits = compared_hits; |
| 11920 | assert!( | 12000 | assert!( |
| 11921 | matched > 0, | 12001 | matched > 0, |
| 11922 | "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" | 12002 | "{NAME}: every attempt refused ({named_refusals} named refusals) -- gate decoded nothing" |
| @@ -11929,7 +12009,8 @@ mod tests { | |||
| 11929 | ); | 12009 | ); |
| 11930 | eprintln!( | 12010 | eprintln!( |
| 11931 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ | 12011 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals, \ |
| 11932 | - rect_split_tx_hits delta={split_hits} out of {n_attempts} attempts" | 12012 | + rect_split_sb_interior_tu_hits delta={split_hits} (over COMPARED streams only) \ |
| 12013 | + out of {n_attempts} attempts" | ||
| 11933 | ); | 12014 | ); |
| 11934 | } | 12015 | } |
| 11935 | 12016 | ||
lanes/rectsplit-r2.report.mdadded+89 -0
| @@ -0,0 +1,89 @@ | |||
| 1 | +# lane-rectsplit r2 (gates run and reported by r3) — SB-level split-transform strips: r2's root cause DISPROVED | ||
| 2 | + | ||
| 3 | +Branch `lane-rectsplit` off main `3808cf8` (r1 `3627fe9` already merged). r2 was capped | ||
| 4 | +before running any gate; its work is WIP `bf53652`. This round ran the gates, found that | ||
| 5 | +r2's fix regresses a merged gate, and reverted the unsafe half. | ||
| 6 | + | ||
| 7 | +## Headline | ||
| 8 | + | ||
| 9 | +r2 claimed the root cause of r1's RED gate (b) was a transposed `av1_nz_map_ctx_offset` | ||
| 10 | +read (`base_ctx`, `[row][col]` -> `[col][row]`). **Measured: that change turns gate (b) | ||
| 11 | +green (20/20) and turns the MERGED gate | ||
| 12 | +`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` RED | ||
| 13 | +(seed 43 luma mismatch).** All four index/shape combinations were run: | ||
| 14 | + | ||
| 15 | +| base_ctx TwoD rect read | SB HORZ/VERT partition gate (merged) | split-tx SB gate (b) | | ||
| 16 | +| --- | --- | --- | | ||
| 17 | +| `table(shape)[row][col]` (r1, shipped) | ok | FAILED (seed 50) | | ||
| 18 | +| `table(shape)[col][row]` (r2's "fix") | FAILED (seed 43) | ok | | ||
| 19 | +| `table(swap)[row][col]` | FAILED | FAILED | | ||
| 20 | +| `table(swap)[col][row]` | FAILED | FAILED | | ||
| 21 | + | ||
| 22 | +So the offset read is NOT the defect: each variant only moves which rare corner position | ||
| 23 | +desyncs. What is genuinely established (checked against the oracle source, not another | ||
| 24 | +transcription): `av1_nz_map_ctx_offset_32x64` is a FLAT 1024-entry array whose `coeff_idx` | ||
| 25 | +is COLUMN-major with stride 32 — entries 0..4 = 0,11,6,6,21 and 32..34 = 11,11,6 match | ||
| 26 | +`txb_common.h:199-209`'s generating rule only as `flat[col * 32 + row]` — so the `cdf.rs` | ||
| 27 | +5x5 transcriptions are `[col][row]`, while `base_ctx` indexes them `[row][col]` and is | ||
| 28 | +green that way. The unproven quantity is therefore the ORIENTATION of `(row, col)` coming | ||
| 29 | +out of the square 32x32-corner scan (`pos / side`, `pos % side` at `decode.rs:1583`) | ||
| 30 | +relative to libaom's column-major `coeff_idx` — the `scan-weights-cross-axis` / | ||
| 31 | +`reference-layout-not-spec` class. That is the next round's bisection. | ||
| 32 | + | ||
| 33 | +## State shipped on this branch (`89d4d59` + this commit) | ||
| 34 | + | ||
| 35 | +KEPT from r2's WIP: | ||
| 36 | +- `stream.rs` gates (a)/(b)/(c): per-attempt counter sampling — a feature-hit delta is | ||
| 37 | + folded in only after that attempt decoded AND pixel-compared, so hits from a stream that | ||
| 38 | + later refuses can no longer make a gate pass vacuously (ledger dead-end). Gate (b) also | ||
| 39 | + asserts the new `decode::rect_split_sb_interior_tu_hits` (`bw.max(bh)==64 && bw/tx>1 && | ||
| 40 | + bh/tx>1` = SB-level AND tx depth >= 2), which is what the verifier asked for. | ||
| 41 | +- Mismatch reporting: mismatching-sample count + bbox. | ||
| 42 | +- `decode.rs:3248`: the chroma-shape refusal is documented UNREACHABLE with both callers | ||
| 43 | + wired and KEPT as the shape guard (without it a new strip size panics on `expect` | ||
| 44 | + instead of refusing by name); it stays in `refusal_inventory::REFUSALS`. | ||
| 45 | +- Gate (c)'s stale "competitors disabled" comment replaced by the measured reason they | ||
| 46 | + cannot be (competitors off -> 0 rect strips; `--cq-level=25` is what fires filter intra). | ||
| 47 | +- `decode::tests::nz_map_ctx_offset_tables_match_the_rect_rule` — pins the `[col][row]` | ||
| 48 | + packing of both rect tables against `base_ctx_rect`'s independently-written rule. It is | ||
| 49 | + TRUE about the transcription and deliberately contradicts `base_ctx`'s read; that | ||
| 50 | + contradiction is the open defect, spelled out in `base_ctx`'s comment. | ||
| 51 | +- `examples/decode_probe.rs` raw-I420 dump (2nd arg); `EC_NZOFF_DUMP=1` prints every | ||
| 52 | + rect-shaped nz_map read; `EC_SBPART_DUMP64=1` prints split-tx strips. | ||
| 53 | + | ||
| 54 | +REVERTED by r3 (unsafe): | ||
| 55 | +- `base_ctx` back to the r1 `[row][col]` read (`decode.rs:1162` comment now records the | ||
| 56 | + four-way measurement instead of r2's claim). | ||
| 57 | +- `decode_block_rect64` refusal "a superblock-level HORZ/VERT strip with a split transform | ||
| 58 | + (per-unit rect prediction is not ported)" RESTORED, re-added to `refusal_inventory.rs`. | ||
| 59 | +- Gate (b) `#[ignore]`d again with the r3 reason. | ||
| 60 | + | ||
| 61 | +## Refusals lifted this round: NONE. | ||
| 62 | + | ||
| 63 | +## Evidence | ||
| 64 | + | ||
| 65 | +EVIDENCE: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3 -- ...split_transform... ...superblock_level_horz_vert_partition... filter_intra_on_a_horz refusal_inventory gate_coverage nz_map_ctx_offset` on lane-rectsplit @ r3 final | 3 aomenc gates + the merged SB partition gate + inventory/coverage/table tests | 9 passed, 0 failed, 1 ignored (gate b), 53.77s | ||
| 66 | +EVIDENCE: same command with `table[col][row]` (r2's WIP `bf53652`) | same gates | gate (b) ok (20/20 pixel-exact, SB-interior-TU delta=7), merged SB HORZ/VERT partition gate FAILED seed 43 — the regression that forced the revert | ||
| 67 | +EVIDENCE: full `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` at r2's WIP state | whole crate lib | **270 passed, 1 failed, 23 ignored**, 1566.70s — the 1 failure is that merged gate. NOT re-run after the revert (turn cap): the reverted state restores r1's behaviour for every path plus one new unit test and one re-ignored gate, so 270 passed / 0 failed / 24 ignored is EXPECTED, not measured. | ||
| 68 | + | ||
| 69 | +## Film check (both films, 0.4s extracts) | ||
| 70 | + | ||
| 71 | +``` | ||
| 72 | +ffmpeg -v error -t 0.4 -i "<reelc.mkv>" -c:v copy -f obu reelc.obu # 418 bytes | ||
| 73 | +ffmpeg -v error -t 0.4 -i "<reelb.mkv>" -c:v copy -f obu hg.obu # 1817 bytes | ||
| 74 | +decode_probe reelc.obu -> REFUSED: AV1 tile (a 32x32 partition type this decoder does not code (value=4)) | ||
| 75 | +decode_probe hg.obu -> REFUSED: AV1 tile (a partition below 8x8 (this decoder codes no leaf smaller than 8x8)) | ||
| 76 | +``` | ||
| 77 | + | ||
| 78 | +EVIDENCE: scratchpad `reelc.obu` (418 B) / `hg.obu` (1817 B) | `ffmpeg -t 0.4 -c:v copy -f obu` then `cargo run -p ec-av1 --example decode_probe` on this branch | neither film stops at a refusal this lane owns | ||
| 79 | + | ||
| 80 | +## Residue | ||
| 81 | + | ||
| 82 | +- fix-now(next round): the (row, col) orientation of the square 32x32-corner coefficient | ||
| 83 | + reader vs libaom's column-major `coeff_idx`. Repro both directions: seed 50 of gate (b) | ||
| 84 | + (`--ignored`) and seed 43 of the SB HORZ/VERT partition gate. Decisive instrument: msac | ||
| 85 | + RANGE ladder vs instrumented aomdec at the first differing coefficient of the 64x32 strip | ||
| 86 | + (r1 located it at luma (171,56), mi=(8,32)); `EC_NZOFF_DUMP=1` lists every candidate read. | ||
| 87 | +- deferred(a below-16x16 strip gate — lane-sub8's territory): the `decode_leaf_rect` strip | ||
| 88 | + refusals. | ||
| 89 | +- deferred(lane-sub8 / the 32x32 AB-partition arm): both films' first 0.4s. | ||