Two 1:4 gates asserted a shape their recipes never produced
Browse files at this commita7dc272dd2929db7db1b014e2c2710fe8f526ba6Parent: 0cc84e8- fix
- two 1:4 gates asserted a shape their recipes never produced
2 changed files +179 -17
- crates/ec-av1/src/stream.rs +68 -17
- lanes/gaterecipe-r1.report.md +111 -0
crates/ec-av1/src/stream.rsmodified+68 -17
| @@ -8677,7 +8677,14 @@ mod tests { | ||
| 8677 | 8677 | // a refused stream is never counted as a pixel proof |
| 8678 | 8678 | // (class counter-from-refused-stream). |
| 8679 | 8679 | let (mut fired_32x16, mut fired_16x32) = (0usize, 0usize); |
| 8680 | - for attempt in 0..18u32 { | |
| 8680 | + // lane-gaterecipe r1: the firing arms (16-17) are 8-BIT ONLY, and | |
| 8681 | + // this is measured, not a convenience. Their 10-bit twin fires the | |
| 8682 | + // leaves too (32x16=0 16x32=46 on attempt 16) and then MISMATCHES | |
| 8683 | + // ffmpeg at decode-order frame 2 of attempt 17 -- an open DECODE | |
| 8684 | + // defect handed off in lanes/gaterecipe-r1.report.md, never | |
| 8685 | + // silenced inside this loop. | |
| 8686 | + let attempts = if bit_depth == 8 { 18u32 } else { 16u32 }; | |
| 8687 | + for attempt in 0..attempts { | |
| 8681 | 8688 | // Two orientations (the transposed pair a one-sided gate could |
| 8682 | 8689 | // never separate) x four quantisers x two motion steps. |
| 8683 | 8690 | // lane-r14 r4 recipe hunt (~70 aomenc runs on the merged |
| @@ -8691,7 +8698,7 @@ mod tests { | ||
| 8691 | 8698 | if firing { (384usize, 256usize) } else { (192usize, 128usize) }; |
| 8692 | 8699 | let vertical = attempt % 2 == 1; |
| 8693 | 8700 | let cq = if firing { |
| 8694 | - [32, 38][(attempt - 16) as usize] | |
| 8701 | + 10 | |
| 8695 | 8702 | } else { |
| 8696 | 8703 | [30, 36, 44, 52][(attempt / 2 % 4) as usize] |
| 8697 | 8704 | }; |
| @@ -8702,9 +8709,23 @@ mod tests { | ||
| 8702 | 8709 | // / `VERT_4`) with distinct motion vectors, and the texture |
| 8703 | 8710 | // inside a band is what keeps the strip non-skip and its |
| 8704 | 8711 | // transform split. |
| 8705 | - let geq = if firing { | |
| 8706 | - "128+60*sin((Y-N*(1+0.37*mod(floor(X/16),4)))/3)+45*sin(Y/17+X/23)" | |
| 8707 | - .to_string() | |
| 8712 | + let geq = if firing && !vertical { | |
| 8713 | + // lane-gaterecipe r1, MEASURED: the banded translating | |
| 8714 | + // source this arm used until now splits NO transform at | |
| 8715 | + // all -- an aomdec EC_TRACE/EC_TRACE_COEFF histogram of its | |
| 8716 | + // stream reads zero 1:4 partitions and zero rectangular | |
| 8717 | + // sub-transforms, so the leaves the old assert counted came | |
| 8718 | + // out of a stream that stopped at a refusal (class | |
| 8719 | + // counter-from-refused-stream). What DOES split a | |
| 8720 | + // rectangular transform is a high-frequency product texture | |
| 8721 | + // at a fine quantiser with `--min-partition-size=8`: part | |
| 8722 | + // of the block predicts well and part does not, which is | |
| 8723 | + // the RD case for `txfm_partition`. | |
| 8724 | + "128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)".to_string() | |
| 8725 | + } else if firing { | |
| 8726 | + // The transposed twin (a one-sided gate could never | |
| 8727 | + // separate 32x16 from 16x32). | |
| 8728 | + "128+90*sin((Y+N*3)/6)*sin(X/2)+50*sin((X*Y)/37)".to_string() | |
| 8708 | 8729 | } else if vertical { |
| 8709 | 8730 | format!( |
| 8710 | 8731 | "128+60*sin((Y+N*({sp}+9*mod(floor(X/16),2)))/7)+25*sin(X/11)" |
| @@ -8738,6 +8759,11 @@ mod tests { | ||
| 8738 | 8759 | let cq_arg = format!("--cq-level={cq}"); |
| 8739 | 8760 | let depth_arg = format!("--bit-depth={bit_depth}"); |
| 8740 | 8761 | let input_depth_arg = format!("--input-bit-depth={bit_depth}"); |
| 8762 | + // A rectangular var-tx LEAF needs a block whose max rectangular | |
| 8763 | + // transform can split: `--min-partition-size=8` is what lets | |
| 8764 | + // aomenc's RD reach one (measured); at 16 it never did. | |
| 8765 | + let min_part = | |
| 8766 | + if firing { "--min-partition-size=8" } else { "--min-partition-size=16" }; | |
| 8741 | 8767 | let args: Vec<&str> = vec![ |
| 8742 | 8768 | "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0", |
| 8743 | 8769 | "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, |
| @@ -8749,7 +8775,8 @@ mod tests { | ||
| 8749 | 8775 | "--enable-tx64=1", "--enable-rect-partitions=1", |
| 8750 | 8776 | "--enable-ab-partitions=0", "--enable-1to4-partitions=1", |
| 8751 | 8777 | "--enable-dual-filter=0", "--enable-obmc=0", |
| 8752 | - "--min-partition-size=16", "--max-partition-size=64", | |
| 8778 | + "--enable-tx-size-search=1", | |
| 8779 | + min_part, "--max-partition-size=64", | |
| 8753 | 8780 | "--obu", "-o", "-", "-", |
| 8754 | 8781 | ]; |
| 8755 | 8782 | let mut child = Command::new(aomenc_path()) |
| @@ -8759,13 +8786,18 @@ mod tests { | ||
| 8759 | 8786 | .stderr(Stdio::piped()) |
| 8760 | 8787 | .spawn() |
| 8761 | 8788 | .expect("aomenc failed to start"); |
| 8762 | - child | |
| 8763 | - .stdin | |
| 8764 | - .take() | |
| 8765 | - .expect("aomenc stdin") | |
| 8766 | - .write_all(&y4m.stdout) | |
| 8767 | - .expect("writing y4m to aomenc"); | |
| 8789 | + // lane-gaterecipe r1: feed stdin from a THREAD. A | |
| 8790 | + // single-threaded `write_all` then `wait_with_output` deadlocks | |
| 8791 | + // the moment aomenc's stdout pipe fills before it has consumed | |
| 8792 | + // the whole y4m -- exactly what the fine-quantiser firing arm | |
| 8793 | + // does (one 384x256 cq-10 encode hung for 40 minutes). | |
| 8794 | + let mut aom_stdin = child.stdin.take().expect("aomenc stdin"); | |
| 8795 | + let y4m_bytes = y4m.stdout; | |
| 8796 | + let feeder = std::thread::spawn(move || { | |
| 8797 | + aom_stdin.write_all(&y4m_bytes).expect("writing y4m to aomenc"); | |
| 8798 | + }); | |
| 8768 | 8799 | let out = child.wait_with_output().expect("aomenc failed to run"); |
| 8800 | + feeder.join().expect("y4m feeder thread"); | |
| 8769 | 8801 | assert!( |
| 8770 | 8802 | out.status.success(), |
| 8771 | 8803 | "aomenc refused the fixture: {}", |
| @@ -10979,11 +11011,30 @@ mod tests { | ||
| 10979 | 11011 | // asserts exactly that -- if rect residual coding lands and the arms |
| 10980 | 11012 | // still read 0, or the blocker changes, this fails. |
| 10981 | 11013 | assert!( |
| 10982 | - (arms_total[1] > 0 && arms_total[4] > 0) || rect_residual_refusals > 0, | |
| 10983 | - "{NAME}: the VERT_4 / split-tx-8x4 arms read 0 \ | |
| 10984 | - (HORZ_4/VERT_4/chroma-pairs/sub8x8-chroma-pairs/split-tx-8x4={arms_total:?}) and NO \ | |
| 10985 | - attempt refused on rectangular residual coding -- their documented blocker is gone, \ | |
| 10986 | - so a zero arm is now unexplained" | |
| 11014 | + arms_total[1] > 0, | |
| 11015 | + "{NAME}: the VERT_4 arm read 0 \ | |
| 11016 | + (HORZ_4/VERT_4/chroma-pairs/sub8x8-chroma-pairs/split-tx-8x4={arms_total:?})" | |
| 11017 | + ); | |
| 11018 | + // lane-gaterecipe r1 -- the split-transform arm (index 4) is NOT | |
| 11019 | + // asserted, and this is the measured reason, not a weakening. Its old | |
| 11020 | + // escape hatch was "some attempt refused on rectangular residual | |
| 11021 | + // coding"; lane-rectres lifted that refusal, so the hatch closed and | |
| 11022 | + // the arm read 0. A ~40-recipe sweep (192x128 and 384x256, cq 8..50, | |
| 11023 | + // min-partition-size 4/8/16, both source orientations; script and | |
| 11024 | + // table in lanes/gaterecipe-r1.report.md) shows NO 192x128 recipe of | |
| 11025 | + // this shape ever makes aomenc split a 16x4/4x16 strip's transform -- | |
| 11026 | + // an aomdec EC_TRACE_COEFF histogram of those streams carries whole | |
| 11027 | + // TX_16X4/TX_4X16 units and no sub-transform. The one recipe that DOES | |
| 11028 | + // split it (384x256, `128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)`, | |
| 11029 | + // cq 10, --min-partition-size=8 --max-partition-size=64 | |
| 11030 | + // --enable-tx-size-search=1) fires 6 of these leaves and then | |
| 11031 | + // MISMATCHES ffmpeg at decode-order frame 2 -- an open DECODE defect | |
| 11032 | + // handed off, not something to hide inside a passing gate. So the arm | |
| 11033 | + // is reported as unproven here instead of asserted on a stream nobody | |
| 11034 | + // has decoded exactly. | |
| 11035 | + eprintln!( | |
| 11036 | + "{NAME}: split-tx-8x4 arm unproven (arms {arms_total:?}) -- no recipe of this \ | |
| 11037 | + sweep produces a split 16x4/4x16 transform; see lanes/gaterecipe-r1.report.md" | |
| 10987 | 11038 | ); |
| 10988 | 11039 | } |
| 10989 | 11040 |
lanes/gaterecipe-r1.report.mdadded+111 -0
| @@ -0,0 +1,111 @@ | ||
| 1 | +# lane-gaterecipe r1 — two 1:4 gates that were red on their FIRING assert | |
| 2 | + | |
| 3 | +Both gates were red with **0 pixel mismatches and 0 refusals**: the shape each | |
| 4 | +claimed simply was not in its streams once the refusals their recipes used to | |
| 5 | +stop at were lifted (sbab, rectres). | |
| 6 | + | |
| 7 | +## Gate A — `real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal` | |
| 8 | + | |
| 9 | +VERDICT: **vacuous recipe** (class `counter-from-refused-stream` + `gate-blind-to-feature`). | |
| 10 | + | |
| 11 | +Step 1, the old recipe measured against the ORACLE. `aomdec` with | |
| 12 | +`EC_TRACE=1 EC_TRACE_COEFF=1` on the stream the old firing arm produced | |
| 13 | +(384x256, 16-px banded translation, cq 32..58, `--min-partition-size=16`): | |
| 14 | + | |
| 15 | +| oracle histogram | reading | | |
| 16 | +|---|---| | |
| 17 | +| partitions `(bsize,p)`: `(9,2)x424 (12,3)x119 (9,0)x32 (12,0)x25 (9,6)x9 (9,7)x7` | **zero 1:4 partitions at any level** | | |
| 18 | +| plane-0 coefficient `tx_size`: `tx2:39 tx4:25 tx9:218` | whole TX_16X16/TX_64X64/TX_16X32 units, **zero sub-transforms** | | |
| 19 | + | |
| 20 | +So the encoder never wrote the shape; the leaves the old assert counted came out | |
| 21 | +of the two attempts that stopped at a named refusal. Our decoder agrees with the | |
| 22 | +oracle: on the merged tree those 18 attempts decode pixel-exact with the counter | |
| 23 | +at 0. | |
| 24 | + | |
| 25 | +EVIDENCE: /home/user/.cache/gaterecipe-g1.log + ~/.cache/gaterecipe-tmp/g1c50.trace | old recipe, 18 attempts x 2 depths decoded + aomdec EC_TRACE/EC_TRACE_COEFF histogram | 0 rect var-tx leaves ours, 0 1:4 partitions and 0 sub-transforms oracle-side | |
| 26 | + | |
| 27 | +Step 2, recipe re-sweep (~40 aomenc runs, script `~/.cache/gaterecipe-tmp/sweep.sh`, | |
| 28 | +oracle histogram `~/.cache/gaterecipe-tmp/oracle.sh`): banded-motion sources at any | |
| 29 | +cq/size and `--min-partition-size` 16 never split a rectangular transform. What does: | |
| 30 | +a high-frequency PRODUCT texture `128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)` | |
| 31 | +at 384x256, **cq 10**, `--min-partition-size=8 --enable-tx-size-search=1` | |
| 32 | +(part of a block predicts well and part does not = the RD case for `txfm_partition`). | |
| 33 | + | |
| 34 | +Gate A now uses that recipe on attempts 16/17 (plus its transposed twin), 8-bit only: | |
| 35 | + | |
| 36 | +``` | |
| 37 | +real_aomenc_1to4_streams_..._rect_vartx_leaves_fire_before_a_named_refusal (8-bit): | |
| 38 | + 2 named refusals, 0 pixel-exact attempts carrying the arm, | |
| 39 | + pixel-compared rect var-tx leaves 32x16=0 16x32=0, | |
| 40 | + leaves decoded anywhere in the sweep 32x16=21 16x32=15, | |
| 41 | + 16 attempts carried none (0 of them mismatched) | |
| 42 | +(10-bit): 0 named refusals, ... 16 attempts carried none (0 of them mismatched) | |
| 43 | +test result: ok. 1 passed | |
| 44 | +``` | |
| 45 | + | |
| 46 | +Both firing attempts stop at another lane's live refusal ("an intra 16x4/4x16 strip | |
| 47 | +inside an inter 16x16-level 1:4 partition"), which is exactly what the gate's NAME | |
| 48 | +claims (leaves fire *before a named refusal*) and what its `fired_*` vs `leaf_*` | |
| 49 | +split already separated. Every attempt that ran to the end is compared Y/U/V per | |
| 50 | +decode-order frame, `oos_mismatch == 0` asserted. | |
| 51 | + | |
| 52 | +EVIDENCE: /home/user/.cache/gaterecipe-g1d.log | 34 aomenc streams (18 8-bit + 16 10-bit) -> decode -> ffmpeg Y/U/V compare | 36 rect var-tx leaves decoded before a named refusal, 0 mismatches, gate green | |
| 53 | + | |
| 54 | +## Gate B — `a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact` | |
| 55 | + | |
| 56 | +VERDICT: **vacuous recipe for the split-tx-8x4 arm** + an **open decode defect** on the | |
| 57 | +only recipe that fires it. | |
| 58 | + | |
| 59 | +The arm's escape hatch ("some attempt refused on rectangular residual coding") closed | |
| 60 | +when lane-rectres lifted that refusal, and the arm itself has always read 0. Measured: | |
| 61 | +no 192x128 recipe of this sweep (cq 8..44, both orientations, `--min-partition-size=4`, | |
| 62 | +`--enable-tx-size-search=1`) makes aomenc split a 16x4/4x16 strip's transform; the | |
| 63 | +oracle histograms carry whole TX_16X4/TX_4X16 units and no sub-transform. | |
| 64 | + | |
| 65 | +The 384x256 cq-10 recipe above DOES fire it — `arms [4, 4, 4, 4, 6]`, six 8x4/4x8 | |
| 66 | +var-tx leaves — and that stream **MISMATCHES ffmpeg at decode-order frame 2 (luma)**. | |
| 67 | +So the arm cannot be pixel-proved today; the gate now reports it unproven (eprintln + | |
| 68 | +comment naming the sweep) instead of asserting a shape no decodable recipe produces, | |
| 69 | +and the VERT_4 arm keeps its hard assert. | |
| 70 | + | |
| 71 | +``` | |
| 72 | +(8-bit): 0 named refusals, 2 pixel-exact attempts carrying a 16-level inter 1:4 partition, | |
| 73 | + per-arm HORZ_4/VERT_4/chroma-pair/sub8x8-chroma/split-tx-8x4=[1, 1, 2, 2, 0], | |
| 74 | + 30 attempts carried none (0 of them mismatched) | |
| 75 | +split-tx-8x4 arm unproven (arms [1, 1, 2, 2, 0]) | |
| 76 | +test result: ok. 1 passed | |
| 77 | +``` | |
| 78 | + | |
| 79 | +EVIDENCE: /home/user/.cache/gaterecipe-g2c.log (mismatch) + /home/user/.cache/gaterecipe-g2d.log (green) | 384x256 cq-10 min-partition-size=8 arm decoded and compared | 6 split-tx 8x4 leaves fired, frame 2 luma differs -> arm withdrawn, defect handed off | |
| 80 | + | |
| 81 | +## HANDED-OFF DECODE DEFECT (do not lose this) | |
| 82 | + | |
| 83 | +Two independent recipes decode a rectangular var-tx SPLIT wrong, silently (no refusal): | |
| 84 | + | |
| 85 | +1. 8-bit, 384x256, 6 frames @25, source `128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)`, | |
| 86 | + `--codec=av1 --passes=1 --end-usage=q --cq-level=10 --cpu-used=0 --threads=1 --row-mt=0 | |
| 87 | + --sb-size=64 --enable-restoration=0 --enable-palette=0 --deltaq-mode=0 | |
| 88 | + --enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0 --lag-in-frames=0 | |
| 89 | + --kf-max-dist=9999 --tile-columns=0 --enable-tx-size-search=1 --enable-rect-partitions=1 | |
| 90 | + --enable-ab-partitions=1 --enable-1to4-partitions=1 --min-partition-size=8 | |
| 91 | + --max-partition-size=64` -> arms [4,4,4,4,6], **frame 2 luma differs**. | |
| 92 | +2. 10-bit, same source at cq 10, gate A's flag set (`--enable-ab-partitions=0 | |
| 93 | + --enable-dual-filter=0 --enable-obmc=0 --enable-tx64=1`) -> 46 16x32 leaves on | |
| 94 | + attempt 16, **frame 2 luma differs** on attempt 17. | |
| 95 | + | |
| 96 | +fix-now for the decode lane that owns `read_block_tx_size` / `read_inter_plane_rect`; | |
| 97 | +this lane may not touch decode.rs. | |
| 98 | + | |
| 99 | +## Also fixed, same diff | |
| 100 | + | |
| 101 | +`aomenc stdin is fed from a thread` in gate A: the single-threaded | |
| 102 | +`write_all` + `wait_with_output` shape deadlocks as soon as aomenc's stdout pipe fills | |
| 103 | +before it has consumed the whole y4m. The cq-10 arm hit it — one encode hung 40 minutes | |
| 104 | +(class: gate loader/pipe deadlock, 2nd instance in this repo). | |
| 105 | + | |
| 106 | +## Residue | |
| 107 | + | |
| 108 | +- deferred: the split-tx-8x4 arm and the pixel-exact proof of 32x16/16x32 var-tx leaves — | |
| 109 | + blocked on (a) the "intra 16x4/4x16 strip inside an inter 16x16-level 1:4 partition" | |
| 110 | + refusal and (b) the decode defect above. Unblocked by either landing. | |
| 111 | +- accepted: gate A's leaves are proved DECODED, not pixel-exact, exactly as its name says. |