diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 1b63b092..73921411 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1107,6 +1107,9 @@ pub(crate) fn vartx_rect_leaf4_hits() -> [usize; 2] { /// Records one rectangular var-tx leaf. fn vartx_rect_leaf_hit(tw: usize, th: usize) { + if std::env::var_os("EC_VARTXLEAF").is_some() { + eprintln!("EC_VARTXLEAF tw={tw} th={th}"); + } let cell = if tw.min(th) == 4 { &VARTX_RECT_LEAF4_HITS } else { &VARTX_RECT_LEAF_HITS }; cell.with(|c| { let mut h = c.get(); @@ -4338,7 +4341,7 @@ fn read_coeffs_rect( }; if rect_trace { let (rng, _) = dec.debug_state(); - eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} rng={rng}", u8::from(negative)); + eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}", u8::from(negative)); } let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { let g = read_golomb(dec)?; @@ -5398,6 +5401,15 @@ impl Neighbours { left_coded |= left.level != 0; vote += dc_vote(left.dc); } + if plane == 0 && std::env::var_os("EC_DCDUMP").is_some() { + let ab: Vec = (0..w_mi) + .map(|k| format!("{:?}/{}", self.above[mi_c + k][0].dc, self.above[mi_c + k][0].level)) + .collect(); + let lf: Vec = (0..h_mi) + .map(|k| format!("{:?}/{}", self.left[mi_r + k][0].dc, self.left[mi_r + k][0].level)) + .collect(); + eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); + } (above_coded, left_coded, vote) }) } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index e912567b..19870506 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -8797,8 +8797,18 @@ mod tests { let (width, height) = if firing { (384usize, 256usize) } else { (192usize, 128usize) }; let vertical = attempt % 2 == 1; + // lane-vartxsplit r2, MEASURED against the oracle + // (`EC_VARTX` histogram, ~40 aomenc runs): at cq 10 this + // source splits NO rectangular transform at all -- aomdec + // reads only TX_8X8/TX_16X16/TX_8X16/TX_16X8 split symbols, + // so the leaves gaterecipe r1 counted here came out of a + // stream our decoder was already desynced on (class + // counter-from-refused-stream). cq 44 and 46 are the two + // quantisers of that sweep whose stream really carries + // `TX_32X8`/`TX_8X32` splits (16x8 and 8x16 rectangular + // var-tx leaves) AND decodes pixel-exact on all six frames. let cq = if firing { - 10 + if attempt == 16 { 44 } else { 46 } } else { [30, 36, 44, 52][(attempt / 2 % 4) as usize] }; @@ -8823,9 +8833,17 @@ mod tests { // the RD case for `txfm_partition`. "128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)".to_string() } else if firing { - // The transposed twin (a one-sided gate could never - // separate 32x16 from 16x32). - "128+90*sin((Y+N*3)/6)*sin(X/2)+50*sin((X*Y)/37)".to_string() + // lane-vartxsplit r2: BOTH leaf orientations come out of + // this one source (three 16x8 leaves and one 8x16 on + // attempt 16), so the firing pair is the same texture at + // two quantisers. Its transposed twin was measured over + // cq 40..56 and splits no rectangular transform at all; + // at cq 56 it also mismatches ffmpeg from decode-order + // frame 2 with ZERO rect var-tx leaves in it -- an open + // reconstruction defect (8-pixel-wide luma column, see + // lanes/vartxsplit-r2.report.md), not something to hide + // inside this gate's attempt list. + "128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)".to_string() } else if vertical { format!( "128+60*sin((Y+N*({sp}+9*mod(floor(X/16),2)))/7)+25*sin(X/11)" @@ -8979,24 +8997,27 @@ mod tests { compared + out_of_scope > 0, "{NAME} ({bit_depth}-bit): every attempt refused -- the gate compared no pixels" ); - // The firing half. MEASURED on the merged tree (lane-r14 r4, ~70 - // aomenc runs): the 8-bit 384x256 banded recipe codes BOTH - // orientations of the split -- cq 38 gives four 32x16 leaves (out - // of four 64x16 strips), cq 32 one 16x32 leaf (out of four 16x64 - // strips). Those two streams stop LATER on another lane's live - // refusal ("an inter 16x16-level AB or 1:4 partition", "a non-skip - // rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual - // coding"), so the leaves are proved DECODED, not proved - // pixel-exact; every attempt that ran to the end is compared - // frame by frame above. At 10 bits the same sweep fires nothing - // (aomenc picks other shapes), so the firing assert is 8-bit only - // -- and it is a hard assert, never a print. + // The firing half. lane-vartxsplit r2 re-measured it against + // the oracle: attempts 16/17 (384x256 product texture, cq 44/46, + // `--min-partition-size=8 --enable-tx-size-search=1`) are the only + // recipes of a ~40-run sweep whose stream carries `TX_32X8` / + // `TX_8X32` split symbols, i.e. RECTANGULAR var-tx leaves (16x8 + // and 8x16, both orientations out of the same stream). They now + // decode PIXEL-EXACT on all six frames, so the assert is on the + // pixel-compared tally, not on the "decoded anywhere" one -- + // `fired_*` stays only to separate a refused stream's leaves from + // a proved one (class counter-from-refused-stream). At 10 bits + // the same sweep either fires nothing or mismatches on a + // reconstruction defect of another shape (report), so the firing + // assert stays 8-bit -- and it is a hard assert, never a print. if bit_depth == 8 { assert!( - fired_32x16 > 0 && fired_16x32 > 0, - "{NAME}: the rectangular var-tx leaf arm never fired (32x16={fired_32x16}, \ - 16x32={fired_16x32}, {named_refusals} refusals, {compared} compared) -- \ - `sub_tx_size_map[TX_64X16] == TX_32X16` is unproved by this gate" + leaf_32x16 > 0 && leaf_16x32 > 0, + "{NAME}: the rectangular var-tx leaf arm never fired on a pixel-exact \ + attempt (pixel-compared 32x16={leaf_32x16}, 16x32={leaf_16x32}, decoded \ + anywhere 32x16={fired_32x16} 16x32={fired_16x32}, {named_refusals} \ + refusals, {compared} compared) -- the rectangular sub-transform path is \ + unproved by this gate" ); } } @@ -11125,13 +11146,22 @@ mod tests { // this shape ever makes aomenc split a 16x4/4x16 strip's transform -- // an aomdec EC_TRACE_COEFF histogram of those streams carries whole // TX_16X4/TX_4X16 units and no sub-transform. The one recipe that DOES - // split it (384x256, `128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)`, - // cq 10, --min-partition-size=8 --max-partition-size=64 - // --enable-tx-size-search=1) fires 6 of these leaves and then - // MISMATCHES ffmpeg at decode-order frame 2 -- an open DECODE defect - // handed off, not something to hide inside a passing gate. So the arm - // is reported as unproven here instead of asserted on a stream nobody - // has decoded exactly. + // split it (384x256 product texture, cq 10, --min-partition-size=8) + // was RE-MEASURED by lane-vartxsplit r2 on the merged tree: that + // stream now decodes PIXEL-EXACT on all six frames and fires ZERO + // rectangular var-tx leaves of any size -- the "6 split-tx 8x4 leaves" + // were counted out of an already-desynced decode (the desync is what + // lane-sub8x4 fixed). r2 also swept THIS gate's own source family at + // cq 46/56/63 (12 streams, both orientations, both motion steps, + // --min-partition-size=4 --enable-tx-size-search=1): zero + // TX_16X4/TX_4X16 split symbols in aomdec's EC_VARTX histogram, all 12 + // pixel-exact. What does split a 16x4/4x16 transform is the product + // texture at --min-partition-size=4 (140 + 238 splits at cq 44), and + // every such stream either stops at a refusal our own desync raises or + // mismatches ffmpeg from decode-order frame 1 -- an open defect handed + // off in lanes/vartxsplit-r2.report.md. So the arm stays + // reported-unproven instead of asserted on a stream nobody has decoded + // exactly. eprintln!( "{NAME}: split-tx-8x4 arm unproven (arms {arms_total:?}) -- no recipe of this \ sweep produces a split 16x4/4x16 transform; see lanes/gaterecipe-r1.report.md" diff --git a/lanes/vartxsplit-r1.handoff.md b/lanes/vartxsplit-r1.handoff.md new file mode 100644 index 00000000..2e3735ce --- /dev/null +++ b/lanes/vartxsplit-r1.handoff.md @@ -0,0 +1,57 @@ +# lane-vartxsplit r1 — handoff (root cause FOUND and FIXED; gate work not done) + +## Pinned stream (reproducible: two runs, identical md5) +`~/.cache/vartxsplit-tmp/s8.obu`, md5 `842355ef494455ead0352f62f84f2c56` +(generator `~/.cache/vartxsplit-tmp/gen.sh`), 8-bit 384x256 6 frames @25, +source `128+90*sin((X+N*3)/6)*sin(Y/2)+50*sin((X*Y)/37)`, oracle aomenc: +`--codec=av1 --passes=1 --end-usage=q --cq-level=10 --cpu-used=0 --threads=1 --row-mt=0 + --sb-size=64 --bit-depth=8 --input-bit-depth=8 --enable-restoration=0 --enable-palette=0 + --deltaq-mode=0 --enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0 + --lag-in-frames=0 --kf-max-dist=9999 --tile-columns=0 --enable-tx-size-search=1 + --enable-rect-partitions=1 --enable-ab-partitions=1 --enable-1to4-partitions=1 + --min-partition-size=8 --max-partition-size=64 --obu` +(gaterecipe r1's recipe 1; the 10-bit 16x32 twin was NOT re-measured this round.) + +## First diverging element (before the fix) +Decode-order frame 2, luma, block mi(8,16) (8x16, TX_8X16), the FIRST DC-sign symbol +of its plane-0 transform unit: +- entry range 43680 in both decoders; +- aomdec `EC_COEFF_STEP tag=sign c=0 sign=1 dcctx=0 rng=41828` +- ours `EC_COEFF_STEP tag=sign_rect pos=0 sign=1 dcctx=1 rng=41148` +i.e. same value, wrong CDF row: our DC-sign context was 1 (negative vote) where libaom's +is 0. Everything before it — partitions, var-tx `txfm_split` ladder (1362 lines of frame 1 +byte-identical; 92 lines of frame 2), coefficients — matched. + +## Root cause (fixed, decode.rs) +`EC_DCDUMP mi=(8,16) wh=(8,16) vote=-2 above=[Some(true)/7,Some(false)/7] +left=[None/0,None/0,Some(true)/7,Some(true)/7]`: the two left cells at mi rows 8-9 were +EMPTY. They belong to the compound 8x8 leaf at mi(8,14) whose transform SPLIT into four +4x4 TUs. `read_inter_luma8` returns an all-zero placeholder `luma_grid` in the split case +because each 4x4 TU already wrote its own plane-0 state via `record_mi_luma`; the compound +leaf arm then called `neighbours.record_mi(leaf_mi, 8, ...)`, which rewrites all three +planes of those cells and erased the four per-TU cul_level/DC-sign records. The +single-ref twin (`decode_leaf8`, decode.rs:25091) already had the `saved_luma_ctx` +save/restore around exactly this call; the compound arm never got it (class: +twin-functions-drift / mvstack-compound-tpl-extension). + +Fix: same save/restore around `record_mi` in the compound arm (decode.rs, the +`neighbours.record_mi(leaf_mi, 8, ...)` at the end of the compound 8x8 leaf). + +## Result +`dump_yuv s8.obu` vs `ffmpeg -pix_fmt yuv420p`: all 6 frames byte-identical +(was: frames 2-5 differ, 91201 luma samples on frame 2). + +## NOT done (next steps, in order) +1. Full suite (`systemd-run --user --unit=vartxsplit-suite-... cargo test -p ec-av1 --lib`). +2. Re-measure the 10-bit 16x32 arm (gaterecipe recipe 2: gate A's flag set, + `--enable-ab-partitions=0 --enable-dual-filter=0 --enable-obmc=0 --enable-tx64=1`, + attempt 16/17) — it may be the same defect or a second one; recipe 1's compound leaf + only exists because THIS recipe leaves `--enable-obmc`/dual-filter on. +3. Turn the gate B `split-tx-8x4` arm (stream.rs ~11036, marked unproven by gaterecipe r1) + back into a hard assert, and add the 10-bit 16x32 arm to + `real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal`. +4. refusal_inventory + gate_coverage untouched this round (no refusal lifted). + +## Instrumentation left in the tree (env-gated, cheap) +- `EC_DCDUMP=1`: `around_mi_rect` prints per-cell above/left DC state + vote (plane 0). +- `EC_TRACE_COEFF` rect sign line now carries `dcctx=`. diff --git a/lanes/vartxsplit-r2.report.md b/lanes/vartxsplit-r2.report.md new file mode 100644 index 00000000..864a20b8 --- /dev/null +++ b/lanes/vartxsplit-r2.report.md @@ -0,0 +1,122 @@ +# lane-vartxsplit r2 — the 10-bit case was stale; the gate's firing recipe was vacuous + +Branch `lane-vartxsplit`, merged with main (beecb64) at `335ccdc` (the r1 compound-8x8 +`saved_luma_ctx` fix landed independently on main via lane-sub8x4; the merge kept main's +copy — same semantics, same call site). + +## (1) The 10-bit 16x32 case (gaterecipe recipe 2) — VERDICT: already fixed by the merge + +Streams (each hashed twice, identical): `~/.cache/vartxsplit-tmp/s10.obu` +md5 `99980afd5945c61621d38c4e5c104db9`, transposed twin `s10v.obu` +md5 `93890af7b420886beb5394bf30f6f805` (384x256, 6 frames @25, yuv420p10le, cq 10, +gate A's flag set, `--min-partition-size=8 --max-partition-size=64`, generator +`~/.cache/vartxsplit-tmp/gen10.sh` / `gen10v.sh`). + +- At `cba81e6` (pre-merge): `s10` differed from ffmpeg at decode-order frames 4-5, + `s10v` at frames 2-5. +- At `335ccdc` (post-merge): **all six frames of both streams are byte-identical to + `ffmpeg -pix_fmt yuv420p10le`, Y/U/V** — no new fix was needed. The premise expired + with lane-sub8x4 (class stale-premise-lanes). +- The recipe also carries **no 16x32 var-tx leaf at all**: aomdec's `EC_VARTX` histogram + of both streams reads only tx_size 1/2/7/8 split symbols — zero `TX_16X64`/`TX_64X16` + (and zero `TX_8X32`/`TX_32X8`). The "46 16x32 leaves" gaterecipe r1 recorded were + counted inside an already-desynced decode. + +EVIDENCE: ~/.cache/vartxsplit-tmp/s10.obu + s10v.obu | aomenc (twice, equal md5) -> dump_yuv -> ffmpeg yuv420p10le rawvideo compare, 6 frames x 3 planes | 12/12 frames byte-identical, oracle EC_VARTX 16x32/32x16 split symbols = 0 + +Same-shape sweep asked for in the charter (`record_mi` with a placeholder grid after a +split): `grep -n "saved_luma_ctx"` in decode.rs shows both 8x8 leaf arms (single-ref +`decode_leaf8` and the compound arm) now save/restore, and they are the only +`record_mi(..., 8, ...)` call sites that follow a `split8` transform; the rect strip and +sub8 rect2/split4 arms publish their own per-TU state and never rewrite a placeholder +grid over it. + +## (2) Gate A — `real_aomenc_1to4_streams_..._rect_vartx_leaves_fire_before_a_named_refusal` + +RED on the merged tree with "leaves decoded anywhere 32x16=0 16x32=0". Root cause is the +RECIPE, not a counter placement: the firing attempts' cq-10 stream contains **no +rectangular sub-transform** (oracle `EC_VARTX`, above), so the counter is right and the +old 21/15 reading came from a desynced decode (class counter-from-refused-stream, second +instance in this gate). + +Re-measured (`~/.cache/vartxsplit-tmp/sweep2.sh`, `sweep3.sh`, ~40 aomenc runs; oracle +histogram of tx_size 15/16/17/18 with val=1): the same product texture at **cq 44 and 46** +is what splits a rectangular transform — `TX_32X8`/`TX_8X32` splits giving **16x8 and 8x16 +rect var-tx leaves**, both orientations out of one stream — and both streams decode +pixel-exact. So attempts 16/17 now run cq 44 / cq 46 on the horizontal source, and the +firing assert was **strengthened**: it asserts the PIXEL-COMPARED tally +(`leaf_32x16 > 0 && leaf_16x32 > 0`), not "decoded anywhere". + +EVIDENCE: ~/.cache/vartxsplit-tmp/p_44.obu, p_46.obu | aomenc -> EC_VARTXLEAF decode -> ffmpeg yuv420p compare | ours 3x 16x8 + 1x 8x16 leaves each, 6/6 frames exact (oracle: tx15/1=1 tx16/1=3 at cq 44) + +## (3) Gate B — the split-tx-8x4 arm stays reported-unproven (DEVIATION from the charter) + +The charter asked for a hard assert. It cannot be honest today, and this is measured, not +assumed: +- gate B's own source family never splits a 16x4/4x16 transform at ANY quantiser: 12 fresh + streams (both orientations, both motion steps, cq 46/56/63, `--min-partition-size=4 + --max-partition-size=16 --enable-tx-size-search=1`) carry **zero** TX_16X4/TX_4X16 split + symbols in aomdec's `EC_VARTX` histogram, and all 12 decode pixel-exact; +- the recipe gaterecipe r1 credited with 6 split-tx 8x4 leaves (`s8.obu`, md5 + `842355ef494455ead0352f62f84f2c56`) now decodes **pixel-exact on all six frames with + ZERO rect var-tx leaves** — those 6 were read out of the desync lane-sub8x4 fixed; +- the product texture at `--min-partition-size=4` DOES split it heavily (140 TX_16X4 + + 238 TX_4X16 at cq 44), but every one of those streams either raises a refusal our own + desync produces ("an OBMC neighbour whose switchable interp filter…", "a Golomb tail + longer than this decoder reads" — both with `--enable-obmc=0 --enable-dual-filter=0` on + the command line, i.e. class refusal-from-own-desync) or mismatches ffmpeg from + decode-order frame 1. + +EVIDENCE: ~/.cache/vartxsplit-tmp/sweep5.sh + sweep6.sh logs | 24 aomenc streams -> aomdec EC_VARTX histogram + our decode + ffmpeg compare | gate-B family 12/12 exact with 0 TX_16X4 splits; product-texture min-part-4 family 0/12 exact + +The gate's comment now carries this measurement instead of gaterecipe's stale one. + +## (4) Open defect handed off (not mine to close this round) + +384x256 product texture, `--min-partition-size=8 --max-partition-size=64`, transposed +source at cq 56 (`pv_56.obu`) — 8-bit, mismatches ffmpeg from decode-order frame 2 with +ZERO rect var-tx leaves. Triaged: +- **entropy is EXACT**: the deduped msac range sequence of frames 0-2 vs instrumented + aomdec has 243696 insertions (our extra `br` prints after `base_eob`) and **0 deletions** + — we read exactly the symbols the reference wrote. It is a RECONSTRUCTION defect. +- shape: luma columns **8..15** (one 8-pixel-wide strip), rows 124..224, 241 samples, + delta -17..+2, plus one 8x4 chroma unit at (108,88) in both U and V, delta -16. +The 10-bit twins behave the same way (`t10_46`, `t10v_48`, `t10v_52`: mismatch with zero +rect leaves; `t10v_40` fires 2+2 leaves and mismatches only on frame 5). This is why no +10-bit firing arm was added to gate A — deferred(the 8-wide-strip reconstruction defect +above), it would make the gate's own `oos_mismatch` assert red. + +## Instrumentation added +`EC_VARTXLEAF=1` (decode.rs `vartx_rect_leaf_hit`): prints `tw=`/`th=` per rectangular +var-tx leaf — this is what separated "our counter moved" from "the recipe never coded the +shape" in one run. + +## Gate + suite results (merged tree, `335ccdc` + this lane's two commits) + +``` +real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal + (8-bit): 0 named refusals, 2 pixel-exact attempts carrying the arm, + pixel-compared rect var-tx leaves 32x16=6 16x32=2, leaves decoded anywhere 32x16=6 16x32=2, + 16 attempts carried none (0 of them mismatched) + (10-bit): 0 named refusals, ... 16 attempts carried none (0 of them mismatched) +a_real_aomenc_inter_sequence_with_16x16_level_1to4_partitions_decodes_pixel_exact + (8-bit): 0 named refusals, 2 pixel-exact attempts, per-arm + HORZ_4/VERT_4/chroma-pair/sub8x8-chroma/split-tx-8x4=[1, 1, 2, 2, 0], 30 carried none (0 mismatched) + split-tx-8x4 arm unproven (arms [1, 1, 2, 2, 0]) +named gates + refusal_inventory + gate_coverage + sub8 + obmc: + test result: ok. 26 passed; 0 failed; 0 ignored; 435 filtered out; 135.30s +full suite: test result: ok. 424 passed; 0 failed; 37 ignored; 0 measured; 855.00s +``` + +EVIDENCE: /home/user/.cache/vartxsplit-gates.log + /home/user/.cache/vartxsplit-suite.log | cargo test -p ec-av1 --lib (named gates, then whole lib, both as systemd user units) | 26/26 named green, suite 424 passed 0 failed 37 ignored + +## Residue +- deferred: the 8-pixel-wide-column reconstruction defect (section 4) — entropy proved + exact, so it is a prediction/filter-stage bug — unblocked by a lane that owns the + 8xN inter reconstruction path; it is what keeps a 10-bit firing arm out of gate A. +- deferred: the split-tx-8x4 hard assert — unblocked by that same defect (it is what + makes every `--min-partition-size=4` product-texture stream red). +- accepted: gate A's leaves are 16x8/8x16 (`TX_32X8`/`TX_8X32` splits), not the 32x16/16x32 + its variable names say; no `TX_64X16`/`TX_16X64` split exists in any recipe measured in + ~70 aomenc runs across r1+r2. The counter is one generic "rect var-tx leaf with both + sides >= 8" pair; renaming it is churn this lane did not spend.