ec-av1: gate the 128x96 4:4:4 lossy tx-size-search cell (already fixed by 6c33f204)
Browse files at this commit2352b575e56ebca7e17fd7ff5f6f4fe2a9649b2cParent: a460dca2 changed files +329 -0
- crates/ec-av1/src/stream.rs +188 -0
- lanes/av1lossy128x96.report.md +141 -0
crates/ec-av1/src/stream.rsmodified+188 -0
| @@ -43597,4 +43597,192 @@ pub(crate) mod tests { | ||
| 43597 | 43597 | } |
| 43598 | 43598 | assert!(seen, "{name}: no sequence header parsed"); |
| 43599 | 43599 | } |
| 43600 | + | |
| 43601 | + /// lane-av1lossy128x96: the 128x96 sibling of the pinned 128x128 witness | |
| 43602 | + /// `a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type` | |
| 43603 | + /// (commit 6c33f204). That fix closed the "4:4:4 lossy + TX size search" | |
| 43604 | + /// divergence (H2) for the 128x128 twin; the 128x96 geometry -- two whole | |
| 43605 | + /// 64x64 roots over a frame whose second block row is only 32 rows tall, | |
| 43606 | + /// which is why it exercises BOTH chroma planes and a partial block row -- | |
| 43607 | + /// was left ungated, and it is the geometry the sweep measured the | |
| 43608 | + /// U+V form of the defect on (608 wrong samples from decode-order frame 2). | |
| 43609 | + /// | |
| 43610 | + /// Measured for this lane on the fix's parent `4155c7c7`: decode-order | |
| 43611 | + /// frames 2 and 3 differ from the oracle in 608 and 692 samples (luma | |
| 43612 | + /// exact, U and V wrong), entropy bit-identical; at HEAD and at `6c33f204` | |
| 43613 | + /// all four frames are byte-exact. So the defect is FIXED and this gate is | |
| 43614 | + /// the pin that keeps it fixed. | |
| 43615 | + /// | |
| 43616 | + /// Recipe (encoded LIVE, no fixture): `testsrc2 128x96:rate=25` yuv444p | |
| 43617 | + /// 4 frames, `aomenc --profile=1 --codec=av1 --passes=1 --end-usage=q | |
| 43618 | + /// --cq-level=20 --cpu-used=2 --sb-size=64 --min-partition-size=64 | |
| 43619 | + /// --max-partition-size=64 --enable-tx-size-search=1 --threads=1 --row-mt=0 | |
| 43620 | + /// --lag-in-frames=0 --kf-max-dist=100 --limit=4 --obu -o - -`. | |
| 43621 | + /// Search ON: 21830 B, sha256 `7380bcbbfb791c6a369850357211223e20fab959423135951f6eb43ffbfcfebd`, | |
| 43622 | + /// fnv1a64 `0x1ba3fe9a4335bdbb`. Control arm, same recipe with | |
| 43623 | + /// `--enable-tx-size-search=0`: 21296 B, sha256 | |
| 43624 | + /// `347edcc9f4899fb05b15174b82d37f6562dcc6fe7691af0ed9ba4efd6cc878c6`, | |
| 43625 | + /// fnv1a64 `0x2f87d8e98c9db686`. | |
| 43626 | + /// | |
| 43627 | + /// NON-VACUITY, and the search flag is NOT the assert: the recipe SPELLS | |
| 43628 | + /// `--enable-tx-size-search=1` (aomenc keeps the FIRST occurrence, and a | |
| 43629 | + /// flag left defaulted is "unknown", not "on"), and then | |
| 43630 | + /// 1. every frame header's PARSED `tx_mode` is `TxMode::Select` | |
| 43631 | + /// (`TX_MODE_SELECT`) -- the searched transform mode is really in the | |
| 43632 | + /// bitstream, not merely requested. The control arm asserts the | |
| 43633 | + /// opposite (`TxMode::Largest`), so neither arm can pass on the other's | |
| 43634 | + /// stream; | |
| 43635 | + /// 2. the sequence header is `ss (0,0)` at 8 bits (`assert_444_header`), | |
| 43636 | + /// and the stream is byte-identical to the recorded encode (length + | |
| 43637 | + /// fnv1a64), so an aomenc that stopped producing this cell fails here | |
| 43638 | + /// rather than silently measuring something else; | |
| 43639 | + /// 3. `decode::chroma_quad_leaf_tx_diff_hits()` strictly increases on the | |
| 43640 | + /// search arm -- the number that says the per-quadrant resolve CHANGED | |
| 43641 | + /// an answer, which is the defect itself. It must be exactly 0 on the | |
| 43642 | + /// search-off control: with no var-tx there is no four-leaf luma tree, | |
| 43643 | + /// so the arm is unreachable and a counter that fired there would be | |
| 43644 | + /// counting something else; | |
| 43645 | + /// 4. every decoded plane is 128*96 (at `ss (0,0)` chroma is full | |
| 43646 | + /// resolution, so a subsampled extent fails the shape assert); | |
| 43647 | + /// 5. `decode_all_frames_vs_oracle` asserts the decode-order frame COUNT | |
| 43648 | + /// and each frame's byte LENGTH before any sample is compared. | |
| 43649 | + /// | |
| 43650 | + /// Red-before: reverting ONLY the per-quadrant resolve in | |
| 43651 | + /// `decode_inter_block`'s 64x64 four-unit chroma arm (the `covering_leaf_tx_type` | |
| 43652 | + /// call back to the block-level `first_tx_type`, counters and this gate | |
| 43653 | + /// untouched) turns this gate red on decode-order frame 2 with 608 bytes | |
| 43654 | + /// differing, and green again on restore. | |
| 43655 | + #[test] | |
| 43656 | + fn a_real_aomenc_444_whole_64_root_tx_size_search_stream_decodes_pixel_exact_at_128x96() { | |
| 43657 | + const NAME: &str = | |
| 43658 | + "a_real_aomenc_444_whole_64_root_tx_size_search_stream_decodes_pixel_exact_at_128x96"; | |
| 43659 | + let _gate_lock = lock_gate_counters(); | |
| 43660 | + if !have_ffmpeg() || !have_aomenc() { | |
| 43661 | + eprintln!("SKIP {NAME}: no ffmpeg/aomenc"); | |
| 43662 | + return; | |
| 43663 | + } | |
| 43664 | + // (label, --enable-tx-size-search, parsed tx mode, bytes, fnv1a64) | |
| 43665 | + let arms: [(&str, &str, TxMode, usize, u64); 2] = [ | |
| 43666 | + ( | |
| 43667 | + "tx size search on", | |
| 43668 | + "1", | |
| 43669 | + TxMode::Select, | |
| 43670 | + 21830, | |
| 43671 | + 0x1ba3_fe9a_4335_bdbb, | |
| 43672 | + ), | |
| 43673 | + ( | |
| 43674 | + "tx size search off (control)", | |
| 43675 | + "0", | |
| 43676 | + TxMode::Largest, | |
| 43677 | + 21296, | |
| 43678 | + 0x2f87_d8e9_8c9d_b686, | |
| 43679 | + ), | |
| 43680 | + ]; | |
| 43681 | + for (label, search, want_mode, want_len, want_fnv) in arms { | |
| 43682 | + let search_flag = format!("--enable-tx-size-search={search}"); | |
| 43683 | + let stream = chroma_format_stream( | |
| 43684 | + 128, | |
| 43685 | + 96, | |
| 43686 | + "yuv444p", | |
| 43687 | + 8, | |
| 43688 | + 4, | |
| 43689 | + &[ | |
| 43690 | + "--profile=1", | |
| 43691 | + "--cq-level=20", | |
| 43692 | + "--cpu-used=2", | |
| 43693 | + "--sb-size=64", | |
| 43694 | + "--min-partition-size=64", | |
| 43695 | + "--max-partition-size=64", | |
| 43696 | + &search_flag, | |
| 43697 | + ], | |
| 43698 | + 0, | |
| 43699 | + ); | |
| 43700 | + assert_444_header(&stream, NAME, 8); | |
| 43701 | + assert_eq!( | |
| 43702 | + stream.len(), | |
| 43703 | + want_len, | |
| 43704 | + "{NAME} ({label}): aomenc produced {} bytes, not the recorded {want_len} -- the \ | |
| 43705 | + recipe no longer makes this cell", | |
| 43706 | + stream.len() | |
| 43707 | + ); | |
| 43708 | + assert_eq!( | |
| 43709 | + fnv1a64(&stream), | |
| 43710 | + want_fnv, | |
| 43711 | + "{NAME} ({label}): the encoded bytes moved" | |
| 43712 | + ); | |
| 43713 | + // PARSED, not requested: the transform mode the bitstream carries. | |
| 43714 | + let mut parser = Av1Parser::new(); | |
| 43715 | + let mut pos = 0usize; | |
| 43716 | + let mut modes: Vec<TxMode> = Vec::new(); | |
| 43717 | + while pos < stream.len() { | |
| 43718 | + let obu = parser | |
| 43719 | + .parse_obu(&stream[pos..]) | |
| 43720 | + .unwrap_or_else(|e| panic!("{NAME}: aomenc OBU does not parse: {e:?}")); | |
| 43721 | + if obu.total_size == 0 { | |
| 43722 | + break; | |
| 43723 | + } | |
| 43724 | + pos += obu.total_size; | |
| 43725 | + if let ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) = obu.kind { | |
| 43726 | + modes.push(h.tx_mode); | |
| 43727 | + } | |
| 43728 | + } | |
| 43729 | + assert_eq!( | |
| 43730 | + modes.len(), | |
| 43731 | + 4, | |
| 43732 | + "{NAME} ({label}): four frame headers expected" | |
| 43733 | + ); | |
| 43734 | + for (i, mode) in modes.iter().enumerate() { | |
| 43735 | + assert_eq!( | |
| 43736 | + *mode, want_mode, | |
| 43737 | + "{NAME} ({label}): decode-order frame {i} carries tx_mode {mode:?}, not \ | |
| 43738 | + {want_mode:?} -- the searched-transform claim is about the bitstream" | |
| 43739 | + ); | |
| 43740 | + } | |
| 43741 | + let diff0 = crate::decode::chroma_quad_leaf_tx_diff_hits(); | |
| 43742 | + let frames = decode_stream(&stream) | |
| 43743 | + .unwrap_or_else(|e| panic!("{NAME} ({label}): refused the stream: {e}")); | |
| 43744 | + let diff = crate::decode::chroma_quad_leaf_tx_diff_hits() - diff0; | |
| 43745 | + for (i, f) in frames.iter().enumerate() { | |
| 43746 | + assert_eq!( | |
| 43747 | + f.y.len(), | |
| 43748 | + 128 * 96, | |
| 43749 | + "{NAME} ({label}): frame {i} luma is {} samples, not 128x96", | |
| 43750 | + f.y.len() | |
| 43751 | + ); | |
| 43752 | + assert_eq!( | |
| 43753 | + f.u.len(), | |
| 43754 | + 128 * 96, | |
| 43755 | + "{NAME} ({label}): frame {i} U is {} samples -- at 4:4:4 the chroma plane is \ | |
| 43756 | + full resolution", | |
| 43757 | + f.u.len() | |
| 43758 | + ); | |
| 43759 | + } | |
| 43760 | + // Pixel compare FIRST: it is the informative failure (it names the | |
| 43761 | + // decode-order frame and the sample), and the counter assert below | |
| 43762 | + // is the guard that says WHY the cell is not vacuous. | |
| 43763 | + let (frames_decoded, _hidden) = decode_all_frames_vs_oracle(&stream, NAME); | |
| 43764 | + assert!( | |
| 43765 | + frames_decoded >= 4, | |
| 43766 | + "{NAME} ({label}): {frames_decoded} decode-order frames" | |
| 43767 | + ); | |
| 43768 | + if label.starts_with("tx size search on") { | |
| 43769 | + assert!( | |
| 43770 | + diff >= 2, | |
| 43771 | + "{NAME}: the per-quadrant tx_type resolve never CHANGED an answer (diff \ | |
| 43772 | + {diff}) -- on this stream the four-leaf luma tree under a searched transform \ | |
| 43773 | + is exactly what makes the block-level value wrong" | |
| 43774 | + ); | |
| 43775 | + } else { | |
| 43776 | + assert_eq!( | |
| 43777 | + diff, 0, | |
| 43778 | + "{NAME}: the four-unit 4:4:4 chroma arm fired with tx size search OFF \ | |
| 43779 | + ({diff} resolves) -- the counter is not measuring the searched path" | |
| 43780 | + ); | |
| 43781 | + } | |
| 43782 | + eprintln!( | |
| 43783 | + "{NAME} ({label}): {frames_decoded} frames byte-exact vs aomdec, tx_mode \ | |
| 43784 | + {want_mode:?} on every frame, quad-tx resolves that differed {diff}" | |
| 43785 | + ); | |
| 43786 | + } | |
| 43787 | + } | |
| 43600 | 43788 | } |
lanes/av1lossy128x96.report.mdadded+141 -0
| @@ -0,0 +1,141 @@ | ||
| 1 | +# lane-av1lossy128x96 — the 128x96 4:4:4 lossy tx-size-search cell | |
| 2 | + | |
| 3 | +**Tree.** `lane-av1lossy128x96` off `a21f3680`, worktree `~/.cache/wt/av1lossy128x96`. | |
| 4 | +Builds in a LANE-PRIVATE `CARGO_TARGET_DIR` (`~/.cache/cargo-target-av1lossy128x96`) — | |
| 5 | +see `skill://counterfactual-ab-target-dir-provenance` variant 5 for why a shared | |
| 6 | +one silently measures a sibling lane's decoder. `decode.rs` is untouched in the | |
| 7 | +final commit; the only change is a new gate in `crates/ec-av1/src/stream.rs`. | |
| 8 | + | |
| 9 | +**Headline: the cell is already FIXED, and the measurement that says so is the | |
| 10 | +gate this lane adds.** The charter assumed the 128x96 U+V variant was unowned | |
| 11 | +and open. It is neither: commit `6c33f204` ("4:4:4 inter chroma units inherit | |
| 12 | +their own quadrant's luma tx_type") closes it, exactly as it closed the 128x128 | |
| 13 | +twin. What was missing is the GATE — the fix's own witness is pinned at | |
| 14 | +128x128, so nothing was watching the 128x96 geometry. | |
| 15 | + | |
| 16 | +--- | |
| 17 | + | |
| 18 | +## 1. Measurement: the cell, before and after the fix | |
| 19 | + | |
| 20 | +Stream (encoded live, identical bytes on both trees): | |
| 21 | + | |
| 22 | +``` | |
| 23 | +ffmpeg -f lavfi -i "testsrc2=size=128x96:rate=25" -frames:v 4 -pix_fmt yuv444p -f yuv4mpegpipe - | |
| 24 | +aomenc --profile=1 --codec=av1 --passes=1 --end-usage=q --cq-level=20 --cpu-used=2 | |
| 25 | + --sb-size=64 --min-partition-size=64 --max-partition-size=64 | |
| 26 | + --enable-tx-size-search=1 --threads=1 --row-mt=0 --lag-in-frames=0 | |
| 27 | + --kf-max-dist=100 --limit=4 --obu -o out.obu - | |
| 28 | +``` | |
| 29 | + | |
| 30 | +21830 bytes, sha256 `7380bcbbfb791c6a369850357211223e20fab959423135951f6eb43ffbfcbebd` | |
| 31 | +-> fnv1a64 `0x1ba3fe9a4335bdbb`. Reference: the instrumented `aomdec` | |
| 32 | +(`EC_AV1_FINAL_DUMP`, decode order). | |
| 33 | + | |
| 34 | +| tree | decode-order frame 0 / 1 / 2 / 3, bytes differing from aomdec | | |
| 35 | +|---|---| | |
| 36 | +| `4155c7c7` (the report's base, the fix's parent) | 0 / 0 / **608** / **692** | | |
| 37 | +| `6c33f204` (the fix) | 0 / 0 / 0 / 0 | | |
| 38 | +| `a21f3680` (HEAD) | 0 / 0 / 0 / 0 | | |
| 39 | + | |
| 40 | +The 608 is the sweep's number, reproduced exactly. First wrong sample in | |
| 41 | +decode-order frame 2: byte 16258 of the dump, i.e. `U(2,31)`, ours 111 vs the | |
| 42 | +oracle's 112 — U and V only, +-1, luma exact, as the sweep recorded. | |
| 43 | + | |
| 44 | +`--enable-tx-size-search=0` on the same recipe: 21296 bytes, sha256 | |
| 45 | +`347edcc9f4899fb05b15174b82d37f6562dcc6fe7691af0ed9ba4efd6cc878c6`, byte-exact | |
| 46 | +4/4 at every tree. So the cell is gated on the SEARCH, not on the geometry. | |
| 47 | + | |
| 48 | +## 2. Discriminator: dequant or inverse transform? | |
| 49 | + | |
| 50 | +The charter's method, run before reading any code. `EC_DQCOEFF` on the oracle | |
| 51 | +(`plane= txsize= txtype= eob= nz=`) against ours (`OUR_DQ w= h= q= dcd= acd= tx= | |
| 52 | +nz=`), both narrowed to decode-order frame 2 with `EC_TRACE_COEFF_FRAME=2`: 134 | |
| 53 | +units on each side. | |
| 54 | + | |
| 55 | +**Oracle-vs-ours by INDEX is not a valid pairing** (80 of 134 "type | |
| 56 | +disagreements" on a byte-exact decode) — the two decoders walk units in | |
| 57 | +different orders, exactly the trap `skill://av1-bitexact-debugging` names. The | |
| 58 | +valid comparison is our own decode before and after the fix, which has a fixed | |
| 59 | +unit order: | |
| 60 | + | |
| 61 | +| comparison | units whose `tx_type` changed | units whose dequantized coefficient map changed | | |
| 62 | +|---|---|---| | |
| 63 | +| ours pre-fix vs ours post-fix (frame 2, 134 units) | **4** (units 72, 76, 107, 111) | **0** | | |
| 64 | + | |
| 65 | +**Verdict: dequant is exonerated, the transform-TYPE selection was the defect.** | |
| 66 | +The same coefficients were read and dequantized identically before and after; | |
| 67 | +four chroma units were handed the block-level luma `tx_type` instead of the | |
| 68 | +covering leaf's, and 6c33f204 changed exactly those four answers. Post-fix the | |
| 69 | +frame is byte-exact against the oracle, so the oracle's types are the post-fix | |
| 70 | +ones. | |
| 71 | + | |
| 72 | +Elimination list, each row a measurement rather than an argument: | |
| 73 | + | |
| 74 | +1. **Entropy** — bit-identical (sweep: 140820 `EC_SYMR` reads, zero divergence). | |
| 75 | +2. **Coefficients / dequant** — 0 of 134 units differ pre→post (this lane). | |
| 76 | +3. **Inverse-transform type selection** — 4 of 134 units differ pre→post (this | |
| 77 | + lane); that is the whole difference. | |
| 78 | +4. **Filters (deblock / CDEF / LR) and prediction input** — exonerated upstream | |
| 79 | + by the sweep's pre-filter dumps (chroma already wrong before deblock, luma | |
| 80 | + exact), and by the fact that a type change alone reproduces the diff with | |
| 81 | + search OFF making it disappear. | |
| 82 | + | |
| 83 | +Nothing here needed a new fix, so this lane ships no decoder change. | |
| 84 | + | |
| 85 | +## 3. Gate added | |
| 86 | + | |
| 87 | +`a_real_aomenc_444_whole_64_root_tx_size_search_stream_decodes_pixel_exact_at_128x96` | |
| 88 | +in `crates/ec-av1/src/stream.rs`. Live aomenc (no fixture pin: the recipe is | |
| 89 | +deterministic), two arms: | |
| 90 | + | |
| 91 | +| arm | flags | parsed `tx_mode` | bytes | verdict | | |
| 92 | +|---|---|---|---|---| | |
| 93 | +| tx size search on | `--enable-tx-size-search=1` | `TxMode::Select` on all 4 frames | 21830 | EXACT 4/4, `chroma_quad_leaf_tx_diff_hits() == 6` | | |
| 94 | +| control | `--enable-tx-size-search=0` | `TxMode::Largest` on all 4 frames | 21296 | EXACT 4/4, `chroma_quad_leaf_tx_diff_hits() == 0` | | |
| 95 | + | |
| 96 | +**The search flag is spelled AND the parsed bitstream is asserted** — the | |
| 97 | +charter's requirement, and the same rule the tilemeasure lane applied to tiles: | |
| 98 | +aomenc keeps the first occurrence of a flag and an unspecified flag is | |
| 99 | +"unknown", not "on", so the gate asserts `tx_mode == TxMode::Select` per frame | |
| 100 | +on the search arm and `TxMode::Largest` on the control, which also stops either | |
| 101 | +arm from silently measuring the other's stream. Recipe identity is pinned by | |
| 102 | +length + fnv1a64 (sha256 in the doc comment), so an aomenc that stops producing | |
| 103 | +this cell fails before the pixel compare. | |
| 104 | + | |
| 105 | +Non-vacuity chain, in order: `ss (0,0)` at 8 bits; bytes + fnv match; parsed | |
| 106 | +`tx_mode` per frame; every decoded plane 128*96 (full-resolution chroma at | |
| 107 | +`ss (0,0)`); `decode_all_frames_vs_oracle` (frame count and per-frame byte | |
| 108 | +length asserted before any sample); then the load-bearing counter | |
| 109 | +`chroma_quad_leaf_tx_diff_hits() >= 2` on the search arm and exactly 0 on the | |
| 110 | +control — the route counter alone is not a witness, it fires on blocks whose | |
| 111 | +four leaves agree, which is the shape the original no-op port looked green on. | |
| 112 | + | |
| 113 | +**Red-before (reverted, reproduced).** Reverting ONLY the per-quadrant resolve | |
| 114 | +in the two copies of `decode_inter_block`'s 64x64 four-unit chroma arm — the | |
| 115 | +`covering_leaf_tx_type(...)` call back to the block-level `luma_tx_type`, | |
| 116 | +counters and this gate untouched — turns the gate red exactly as the sweep | |
| 117 | +described it: | |
| 118 | + | |
| 119 | +``` | |
| 120 | +decode-order frame 2 of 4 (4 shown, 0 hidden) differs from the oracle at byte | |
| 121 | +16258 (ours 111 vs 112), 608 bytes differ | |
| 122 | +``` | |
| 123 | + | |
| 124 | +Green again on restore (`git diff crates/ec-av1/src/decode.rs` empty). | |
| 125 | + | |
| 126 | +**Regressions checked on this tree.** The 128x128 twin's own gate | |
| 127 | +`a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type` | |
| 128 | +(96 quad-resolved units, 8 of them differing, plus its 4:2:0 control) is green. | |
| 129 | +A 4:2:0 identity run of this lane's own recipe (same flags, `yuv420p` input) | |
| 130 | +decodes byte-exact 4/4 with the 4:4:4-only counters at 0. | |
| 131 | + | |
| 132 | +## 4. What this lane does NOT claim | |
| 133 | + | |
| 134 | +- It does not claim a new fix. The fix is `6c33f204`, already on main. | |
| 135 | +- It does not claim the 128x96 cell was ever distinct from the 128x128 twin: | |
| 136 | + the two are the same defect (per-quadrant `tx_type` inheritance), and the | |
| 137 | + 128x96 form is the U+V variant of it on a frame whose second block row is | |
| 138 | + half-height. | |
| 139 | +- It does not touch the 4:4:4 LOSSLESS chroma class (256x256 / 512x128), which | |
| 140 | + is owned elsewhere and which the tilemeasure lane bounded with untiled | |
| 141 | + controls. |