forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1lossy128x96 @ 9ecb36de — gate the 128x96 4:4:4 lossy tx-size-search cell

Browse files at this commit

6f07b449bf28757c8fcc1d599c22e95556f2108fAhmet Kaan GümüşParent: cc8c6ee2352b57
# Conflicts:
#	crates/ec-av1/src/stream.rs
crates/ec-av1/src/stream.rsmodified+191 -6
@@ -45060,7 +45060,8 @@ pub(crate) mod tests {
45060 /// set can decide (the kf900 gate above owns the exactness side).45060 /// set can decide (the kf900 gate above owns the exactness side).
45061 #[test]45061 #[test]
45062 fn a_committed_4to20_stream_presents_a_one_mi_left_neighbour_to_a_decode_path_read() {45062 fn a_committed_4to20_stream_presents_a_one_mi_left_neighbour_to_a_decode_path_read() {
45063- const NAME: &str = "a_committed_4to20_stream_presents_a_one_mi_left_neighbour_to_a_decode_path_read";45063+ const NAME: &str =
45064+ "a_committed_4to20_stream_presents_a_one_mi_left_neighbour_to_a_decode_path_read";
45064 // (fixture, frames, width, height, measured split-owner reads)45065 // (fixture, frames, width, height, measured split-owner reads)
45065 let arms: [(&str, usize, usize, usize, usize); 2] = [45066 let arms: [(&str, usize, usize, usize, usize); 2] = [
45066 ("gm_small_side_witness.obu", 33, 1920, 792, 5),45067 ("gm_small_side_witness.obu", 33, 1920, 792, 5),
@@ -45081,11 +45082,7 @@ pub(crate) mod tests {
45081 Err(e) => panic!("{NAME}: {fixture} refused: {e}"),45082 Err(e) => panic!("{NAME}: {fixture} refused: {e}"),
45082 };45083 };
45083 let split = crate::decode::uv_left_1mi_split_hits() - before_split;45084 let split = crate::decode::uv_left_1mi_split_hits() - before_split;
45084- assert_eq!(45085+ assert_eq!(frames.len(), want_frames, "{NAME}: {fixture} frame count");
45085- frames.len(),
45086- want_frames,
45087- "{NAME}: {fixture} frame count"
45088- );
45089 assert!(45086 assert!(
45090 frames45087 frames
45091 .iter()45088 .iter()
@@ -47283,4 +47280,192 @@ pub(crate) mod tests {
47283 heads.iter().map(|h| h.superres_denom).collect::<Vec<_>>()47280 heads.iter().map(|h| h.superres_denom).collect::<Vec<_>>()
47284 );47281 );
47285 }47282 }
47283+
47284+ /// lane-av1lossy128x96: the 128x96 sibling of the pinned 128x128 witness
47285+ /// `a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type`
47286+ /// (commit 6c33f204). That fix closed the "4:4:4 lossy + TX size search"
47287+ /// divergence (H2) for the 128x128 twin; the 128x96 geometry -- two whole
47288+ /// 64x64 roots over a frame whose second block row is only 32 rows tall,
47289+ /// which is why it exercises BOTH chroma planes and a partial block row --
47290+ /// was left ungated, and it is the geometry the sweep measured the
47291+ /// U+V form of the defect on (608 wrong samples from decode-order frame 2).
47292+ ///
47293+ /// Measured for this lane on the fix's parent `4155c7c7`: decode-order
47294+ /// frames 2 and 3 differ from the oracle in 608 and 692 samples (luma
47295+ /// exact, U and V wrong), entropy bit-identical; at HEAD and at `6c33f204`
47296+ /// all four frames are byte-exact. So the defect is FIXED and this gate is
47297+ /// the pin that keeps it fixed.
47298+ ///
47299+ /// Recipe (encoded LIVE, no fixture): `testsrc2 128x96:rate=25` yuv444p
47300+ /// 4 frames, `aomenc --profile=1 --codec=av1 --passes=1 --end-usage=q
47301+ /// --cq-level=20 --cpu-used=2 --sb-size=64 --min-partition-size=64
47302+ /// --max-partition-size=64 --enable-tx-size-search=1 --threads=1 --row-mt=0
47303+ /// --lag-in-frames=0 --kf-max-dist=100 --limit=4 --obu -o - -`.
47304+ /// Search ON: 21830 B, sha256 `7380bcbbfb791c6a369850357211223e20fab959423135951f6eb43ffbfcfebd`,
47305+ /// fnv1a64 `0x1ba3fe9a4335bdbb`. Control arm, same recipe with
47306+ /// `--enable-tx-size-search=0`: 21296 B, sha256
47307+ /// `347edcc9f4899fb05b15174b82d37f6562dcc6fe7691af0ed9ba4efd6cc878c6`,
47308+ /// fnv1a64 `0x2f87d8e98c9db686`.
47309+ ///
47310+ /// NON-VACUITY, and the search flag is NOT the assert: the recipe SPELLS
47311+ /// `--enable-tx-size-search=1` (aomenc keeps the FIRST occurrence, and a
47312+ /// flag left defaulted is "unknown", not "on"), and then
47313+ /// 1. every frame header's PARSED `tx_mode` is `TxMode::Select`
47314+ /// (`TX_MODE_SELECT`) -- the searched transform mode is really in the
47315+ /// bitstream, not merely requested. The control arm asserts the
47316+ /// opposite (`TxMode::Largest`), so neither arm can pass on the other's
47317+ /// stream;
47318+ /// 2. the sequence header is `ss (0,0)` at 8 bits (`assert_444_header`),
47319+ /// and the stream is byte-identical to the recorded encode (length +
47320+ /// fnv1a64), so an aomenc that stopped producing this cell fails here
47321+ /// rather than silently measuring something else;
47322+ /// 3. `decode::chroma_quad_leaf_tx_diff_hits()` strictly increases on the
47323+ /// search arm -- the number that says the per-quadrant resolve CHANGED
47324+ /// an answer, which is the defect itself. It must be exactly 0 on the
47325+ /// search-off control: with no var-tx there is no four-leaf luma tree,
47326+ /// so the arm is unreachable and a counter that fired there would be
47327+ /// counting something else;
47328+ /// 4. every decoded plane is 128*96 (at `ss (0,0)` chroma is full
47329+ /// resolution, so a subsampled extent fails the shape assert);
47330+ /// 5. `decode_all_frames_vs_oracle` asserts the decode-order frame COUNT
47331+ /// and each frame's byte LENGTH before any sample is compared.
47332+ ///
47333+ /// Red-before: reverting ONLY the per-quadrant resolve in
47334+ /// `decode_inter_block`'s 64x64 four-unit chroma arm (the `covering_leaf_tx_type`
47335+ /// call back to the block-level `first_tx_type`, counters and this gate
47336+ /// untouched) turns this gate red on decode-order frame 2 with 608 bytes
47337+ /// differing, and green again on restore.
47338+ #[test]
47339+ fn a_real_aomenc_444_whole_64_root_tx_size_search_stream_decodes_pixel_exact_at_128x96() {
47340+ const NAME: &str =
47341+ "a_real_aomenc_444_whole_64_root_tx_size_search_stream_decodes_pixel_exact_at_128x96";
47342+ let _gate_lock = lock_gate_counters();
47343+ if !have_ffmpeg() || !have_aomenc() {
47344+ eprintln!("SKIP {NAME}: no ffmpeg/aomenc");
47345+ return;
47346+ }
47347+ // (label, --enable-tx-size-search, parsed tx mode, bytes, fnv1a64)
47348+ let arms: [(&str, &str, TxMode, usize, u64); 2] = [
47349+ (
47350+ "tx size search on",
47351+ "1",
47352+ TxMode::Select,
47353+ 21830,
47354+ 0x1ba3_fe9a_4335_bdbb,
47355+ ),
47356+ (
47357+ "tx size search off (control)",
47358+ "0",
47359+ TxMode::Largest,
47360+ 21296,
47361+ 0x2f87_d8e9_8c9d_b686,
47362+ ),
47363+ ];
47364+ for (label, search, want_mode, want_len, want_fnv) in arms {
47365+ let search_flag = format!("--enable-tx-size-search={search}");
47366+ let stream = chroma_format_stream(
47367+ 128,
47368+ 96,
47369+ "yuv444p",
47370+ 8,
47371+ 4,
47372+ &[
47373+ "--profile=1",
47374+ "--cq-level=20",
47375+ "--cpu-used=2",
47376+ "--sb-size=64",
47377+ "--min-partition-size=64",
47378+ "--max-partition-size=64",
47379+ &search_flag,
47380+ ],
47381+ 0,
47382+ );
47383+ assert_444_header(&stream, NAME, 8);
47384+ assert_eq!(
47385+ stream.len(),
47386+ want_len,
47387+ "{NAME} ({label}): aomenc produced {} bytes, not the recorded {want_len} -- the \
47388+ recipe no longer makes this cell",
47389+ stream.len()
47390+ );
47391+ assert_eq!(
47392+ fnv1a64(&stream),
47393+ want_fnv,
47394+ "{NAME} ({label}): the encoded bytes moved"
47395+ );
47396+ // PARSED, not requested: the transform mode the bitstream carries.
47397+ let mut parser = Av1Parser::new();
47398+ let mut pos = 0usize;
47399+ let mut modes: Vec<TxMode> = Vec::new();
47400+ while pos < stream.len() {
47401+ let obu = parser
47402+ .parse_obu(&stream[pos..])
47403+ .unwrap_or_else(|e| panic!("{NAME}: aomenc OBU does not parse: {e:?}"));
47404+ if obu.total_size == 0 {
47405+ break;
47406+ }
47407+ pos += obu.total_size;
47408+ if let ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) = obu.kind {
47409+ modes.push(h.tx_mode);
47410+ }
47411+ }
47412+ assert_eq!(
47413+ modes.len(),
47414+ 4,
47415+ "{NAME} ({label}): four frame headers expected"
47416+ );
47417+ for (i, mode) in modes.iter().enumerate() {
47418+ assert_eq!(
47419+ *mode, want_mode,
47420+ "{NAME} ({label}): decode-order frame {i} carries tx_mode {mode:?}, not \
47421+ {want_mode:?} -- the searched-transform claim is about the bitstream"
47422+ );
47423+ }
47424+ let diff0 = crate::decode::chroma_quad_leaf_tx_diff_hits();
47425+ let frames = decode_stream(&stream)
47426+ .unwrap_or_else(|e| panic!("{NAME} ({label}): refused the stream: {e}"));
47427+ let diff = crate::decode::chroma_quad_leaf_tx_diff_hits() - diff0;
47428+ for (i, f) in frames.iter().enumerate() {
47429+ assert_eq!(
47430+ f.y.len(),
47431+ 128 * 96,
47432+ "{NAME} ({label}): frame {i} luma is {} samples, not 128x96",
47433+ f.y.len()
47434+ );
47435+ assert_eq!(
47436+ f.u.len(),
47437+ 128 * 96,
47438+ "{NAME} ({label}): frame {i} U is {} samples -- at 4:4:4 the chroma plane is \
47439+ full resolution",
47440+ f.u.len()
47441+ );
47442+ }
47443+ // Pixel compare FIRST: it is the informative failure (it names the
47444+ // decode-order frame and the sample), and the counter assert below
47445+ // is the guard that says WHY the cell is not vacuous.
47446+ let (frames_decoded, _hidden) = decode_all_frames_vs_oracle(&stream, NAME);
47447+ assert!(
47448+ frames_decoded >= 4,
47449+ "{NAME} ({label}): {frames_decoded} decode-order frames"
47450+ );
47451+ if label.starts_with("tx size search on") {
47452+ assert!(
47453+ diff >= 2,
47454+ "{NAME}: the per-quadrant tx_type resolve never CHANGED an answer (diff \
47455+ {diff}) -- on this stream the four-leaf luma tree under a searched transform \
47456+ is exactly what makes the block-level value wrong"
47457+ );
47458+ } else {
47459+ assert_eq!(
47460+ diff, 0,
47461+ "{NAME}: the four-unit 4:4:4 chroma arm fired with tx size search OFF \
47462+ ({diff} resolves) -- the counter is not measuring the searched path"
47463+ );
47464+ }
47465+ eprintln!(
47466+ "{NAME} ({label}): {frames_decoded} frames byte-exact vs aomdec, tx_mode \
47467+ {want_mode:?} on every frame, quad-tx resolves that differed {diff}"
47468+ );
47469+ }
47470+ }
47286 }47471 }
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.