An INTRA-coded 128x128 block inside an inter frame decodes
Browse files at this commit30842786f47d177ceac5ab4e30d54cbbba8e722eParent: f34521d- fix
- an INTRA-coded 128x128 block inside an inter frame decodes
- three 128-root defects
4 changed files +161 -25
- crates/ec-av1/src/decode.rs +138 -11
- crates/ec-av1/src/refusal_inventory.rs +0 -1
- crates/ec-av1/src/stream.rs +17 -13
- lanes/COMMON-20260901.md +6 -0
crates/ec-av1/src/decode.rsmodified+138 -11
| @@ -1912,6 +1912,18 @@ pub fn inter_sb128_none_hits() -> usize { | ||
| 1912 | 1912 | INTER_SB128_NONE_HITS.with(std::cell::Cell::get) |
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | +thread_local! { | |
| 1916 | + /// lane-sb128c r3: how many INTRA-coded 128x128 blocks inside an INTER | |
| 1917 | + /// frame this decoder reconstructed (mu-chunk chroma, four TX_64X64 luma | |
| 1918 | + /// units) -- the gate's witness that the lifted refusal's case fired. | |
| 1919 | + pub(crate) static INTRA_128_IN_INTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1920 | +} | |
| 1921 | + | |
| 1922 | +/// Current value of [`INTRA_128_IN_INTER_HITS`], for a gate's before/after delta. | |
| 1923 | +pub fn intra_128_in_inter_hits() -> usize { | |
| 1924 | + INTRA_128_IN_INTER_HITS.with(std::cell::Cell::get) | |
| 1925 | +} | |
| 1926 | + | |
| 1915 | 1927 | thread_local! { |
| 1916 | 1928 | static INTER_SB_NONE_HITS: std::cell::Cell<usize> = |
| 1917 | 1929 | const { std::cell::Cell::new(0) }; |
| @@ -5515,6 +5527,14 @@ fn read_intra_mode_rect( | ||
| 5515 | 5527 | 0 |
| 5516 | 5528 | }; |
| 5517 | 5529 | istep!("angle_y", angle_delta_y); |
| 5530 | + // lane-sb128c r3 (class sweep): libaom `read_intra_mode_uv(.., is_cfl_allowed(xd), ..)` | |
| 5531 | + // and `is_cfl_allowed` (blockd.h) is `block_size_wide[bsize] <= 32 && | |
| 5532 | + // block_size_high[bsize] <= 32` on the LUMA bsize. Deciding the alphabet | |
| 5533 | + // here, from the block's own size, is the single point every caller routes | |
| 5534 | + // through -- a caller passing `true` for a >32 strip used to pick the | |
| 5535 | + // 14-symbol CFL CDF, same value but a different range (class | |
| 5536 | + // wrong-alphabet-same-value). | |
| 5537 | + let cfl = cfl && bw <= 32 && bh <= 32; | |
| 5518 | 5538 | let uv_mode = if !has_chroma { |
| 5519 | 5539 | DC_PRED |
| 5520 | 5540 | } else if cfl { |
| @@ -8496,6 +8516,10 @@ fn read_intra_mode( | ||
| 8496 | 8516 | 0 |
| 8497 | 8517 | }; |
| 8498 | 8518 | istep!("angle_y", angle_delta_y); |
| 8519 | + // lane-sb128c r3 (class sweep): `is_cfl_allowed` on the luma bsize, decided | |
| 8520 | + // here so every `decode_block` caller (64x64 and 128x128 roots included) | |
| 8521 | + // picks the right alphabet -- see [`read_intra_mode_rect`]'s twin. | |
| 8522 | + let cfl = cfl && side <= 32; | |
| 8499 | 8523 | let uv_mode = if cfl { |
| 8500 | 8524 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 8501 | 8525 | } else { |
| @@ -11474,7 +11498,9 @@ fn read_block_tx_size( | ||
| 11474 | 11498 | // lane-sb128c r1: `max_txsize_rect_lookup[BLOCK_128X128]` is TX_64X64, |
| 11475 | 11499 | // so a 128x128 inter block is FOUR luma units even with `tx_mode == |
| 11476 | 11500 | // TX_MODE_LARGEST` -- the same leaf shape the var-tx tree hands back. |
| 11477 | - if is_inter && side > 64 { | |
| 11501 | + // lane-sb128c r3: intra too -- an INTRA 128x128 block under | |
| 11502 | + // `TX_MODE_LARGEST` also resolves to TX_64X64, i.e. four luma units. | |
| 11503 | + if side > 64 { | |
| 11478 | 11504 | let step = 64 / MI; |
| 11479 | 11505 | let mut leaves = Vec::new(); |
| 11480 | 11506 | for row in (0..side / MI).step_by(step) { |
| @@ -11531,7 +11557,10 @@ fn read_block_tx_size( | ||
| 11531 | 11557 | n, |
| 11532 | 11558 | at_mi, |
| 11533 | 11559 | side, |
| 11534 | - Some(tx_size_context_txfm(n, at_mi, side)), | |
| 11560 | + // lane-sb128c r3: `get_tx_size_context` compares the neighbour txfm | |
| 11561 | + // contexts against `tx_size_wide[max_txsize_rect_lookup[bsize]]`, | |
| 11562 | + // which is 64 for BLOCK_128X128 -- never the block's own 128 side. | |
| 11563 | + Some(tx_size_context_txfm(n, at_mi, side.min(64))), | |
| 11535 | 11564 | ) |
| 11536 | 11565 | }; |
| 11537 | 11566 | set_txfm_ctxs(n, at_mi, tx, side_mi, side_mi, skip && is_inter); |
| @@ -16392,11 +16421,6 @@ fn decode_inter_block( | ||
| 16392 | 16421 | // chunk). An INTRA block at that size inside an inter frame takes the |
| 16393 | 16422 | // intra tail below, which still codes one whole-block chroma unit and one |
| 16394 | 16423 | // `read_tx_size` at 128 -- refuse by name instead of mis-decoding it. |
| 16395 | - if side > 64 && !is_inter { | |
| 16396 | - return Err(unsupported( | |
| 16397 | - "an INTRA-coded 128x128 block inside an inter frame (only the inter half of a 128x128 root is decoded here)", | |
| 16398 | - )); | |
| 16399 | - } | |
| 16400 | 16424 | if std::env::var_os("EC_TRACE_MODE").is_some() { |
| 16401 | 16425 | eprintln!( |
| 16402 | 16426 | "EC_MODE mi_row={} mi_col={} rng={} is_inter={} skip={} side={side}", |
| @@ -18840,9 +18864,16 @@ fn decode_inter_block( | ||
| 18840 | 18864 | .1; |
| 18841 | 18865 | let reach = Reach::of(side, px, py, y.width, y.height); |
| 18842 | 18866 | let split_luma = vartx_leaves.is_some(); |
| 18867 | + // lane-sb128c r3: a 128x128 INTRA block inside an inter frame codes | |
| 18868 | + // its chroma per 64x64 mu chunk, exactly as the inter half above -- | |
| 18869 | + // `decode_token_recon_block` walks `mu_blocks_wide/high` and codes | |
| 18870 | + // every plane of a chunk before the next chunk's luma. These collect | |
| 18871 | + // the four TX_32X32 units per plane for the block-level write-back. | |
| 18872 | + let mut u_units = vec![0i32; chroma_side * chroma_side]; | |
| 18873 | + let mut v_units = vec![0i32; chroma_side * chroma_side]; | |
| 18843 | 18874 | if let Some(leaves) = vartx_leaves.clone() { |
| 18844 | 18875 | let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get); |
| 18845 | - for &(row, col, tx_px) in &leaves { | |
| 18876 | + for (idx, &(row, col, tx_px)) in leaves.iter().enumerate() { | |
| 18846 | 18877 | let tu_mi = (at_mi.0 + row, at_mi.1 + col); |
| 18847 | 18878 | let (tu_px, tu_py) = (px + col * MI, py + row * MI); |
| 18848 | 18879 | // A transform unit inside a block is not a block at that |
| @@ -18893,9 +18924,96 @@ fn decode_inter_block( | ||
| 18893 | 18924 | )? |
| 18894 | 18925 | }; |
| 18895 | 18926 | neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); |
| 18927 | + if side > 64 { | |
| 18928 | + let chunk = (row / 16, col / 16); | |
| 18929 | + let done = idx + 1 == leaves.len() | |
| 18930 | + || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk; | |
| 18931 | + if !done { | |
| 18932 | + continue; | |
| 18933 | + } | |
| 18934 | + let (cr, cc) = chunk; | |
| 18935 | + // `av1_get_max_uv_txsize(BLOCK_128X128)` = | |
| 18936 | + // `av1_get_adjusted_tx_size(TX_64X64)` = TX_32X32. | |
| 18937 | + let cu_tx = 32usize; | |
| 18938 | + let luma_span = cu_tx * 2; | |
| 18939 | + let cu_mi = (at_mi.0 + cr * 16, at_mi.1 + cc * 16); | |
| 18940 | + let cu_around = neighbours.around_mi(cu_mi, luma_span); | |
| 18941 | + let (cu_x, cu_y) = (cpx + cc * cu_tx, cpy + cr * cu_tx); | |
| 18942 | + let cu_reach = crate::decode::tu_reach( | |
| 18943 | + side, side, | |
| 18944 | + cc * luma_span, cr * luma_span, luma_span, | |
| 18945 | + reach, px, py, y.width, y.height, | |
| 18946 | + ); | |
| 18947 | + let cu_scan = default_scan(cu_tx); | |
| 18948 | + for plane_idx in 1..3 { | |
| 18949 | + let buf: &mut PlaneBuf = if plane_idx == 1 { &mut *u } else { &mut *v }; | |
| 18950 | + let cu_grid = if skip { | |
| 18951 | + buf.reconstruct( | |
| 18952 | + cu_x, | |
| 18953 | + cu_y, | |
| 18954 | + cu_tx, | |
| 18955 | + uv_predict_mode, | |
| 18956 | + angle_delta_uv, | |
| 18957 | + cu_reach, | |
| 18958 | + &vec![0i32; cu_tx * cu_tx], | |
| 18959 | + None, | |
| 18960 | + None, | |
| 18961 | + smooth_neighbor_uv, | |
| 18962 | + ); | |
| 18963 | + vec![0i32; cu_tx * cu_tx] | |
| 18964 | + } else { | |
| 18965 | + read_plane( | |
| 18966 | + dec, | |
| 18967 | + cdfs, | |
| 18968 | + chroma_set, | |
| 18969 | + &cu_scan, | |
| 18970 | + plane_idx, | |
| 18971 | + cu_around[plane_idx], | |
| 18972 | + mode, | |
| 18973 | + uv_predict_mode, | |
| 18974 | + angle_delta_uv, | |
| 18975 | + cu_reach, | |
| 18976 | + buf, | |
| 18977 | + cu_x, | |
| 18978 | + cu_y, | |
| 18979 | + cu_tx, | |
| 18980 | + cu_tx, | |
| 18981 | + base_q_idx, | |
| 18982 | + // CfL is refused above 32x32 | |
| 18983 | + // (`is_cfl_allowed`), so never here. | |
| 18984 | + None, | |
| 18985 | + None, | |
| 18986 | + // The uv plane block (64x64) is larger than | |
| 18987 | + // the unit (32x32): `get_txb_ctx`'s offset-10 | |
| 18988 | + // rows, +3 on the `txb_skip_chroma_32` table | |
| 18989 | + // (lane-sb128b r3). | |
| 18990 | + Some(3), | |
| 18991 | + smooth_neighbor_uv, | |
| 18992 | + )? | |
| 18993 | + }; | |
| 18994 | + // Immediately, so the NEXT chunk's unit reads this | |
| 18995 | + // one's coefficient context. | |
| 18996 | + neighbours.record_mi_chroma( | |
| 18997 | + cu_mi, luma_span, luma_span, plane_idx, &cu_grid, | |
| 18998 | + ); | |
| 18999 | + CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | |
| 19000 | + let dst = if plane_idx == 1 { &mut u_units } else { &mut v_units }; | |
| 19001 | + for rr in 0..cu_tx { | |
| 19002 | + let start = (cr * cu_tx + rr) * chroma_side + cc * cu_tx; | |
| 19003 | + dst[start..start + cu_tx] | |
| 19004 | + .copy_from_slice(&cu_grid[rr * cu_tx..][..cu_tx]); | |
| 19005 | + } | |
| 19006 | + } | |
| 19007 | + } | |
| 18896 | 19008 | } |
| 18897 | 19009 | } |
| 18898 | - if skip { | |
| 19010 | + if side > 64 { | |
| 19011 | + // Chroma is already coded and reconstructed per mu chunk above. | |
| 19012 | + luma_grid = vec![0i32; side * side]; | |
| 19013 | + u_grid = std::mem::take(&mut u_units); | |
| 19014 | + v_grid = std::mem::take(&mut v_units); | |
| 19015 | + INTRA_128_IN_INTER_HITS.with(|c| c.set(c.get() + 1)); | |
| 19016 | + } else if skip { | |
| 18899 | 19017 | if !split_luma { |
| 18900 | 19018 | y.reconstruct( |
| 18901 | 19019 | px, |
| @@ -21148,7 +21266,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 21148 | 21266 | skip_mode_frame, |
| 21149 | 21267 | switchable_motion_mode, |
| 21150 | 21268 | allow_warped_motion, |
| 21151 | - true, | |
| 21269 | + // lane-sb128c r3: `reject_residual` is about a | |
| 21270 | + // RECTANGULAR strip decoded with square dimensions -- | |
| 21271 | + // the 128x128 NONE root is square, and a hardcoded | |
| 21272 | + // `true` refused every one of them at its first | |
| 21273 | + // non-skip block. | |
| 21274 | + $ww != $side || $wh != $side, | |
| 21152 | 21275 | $ww, |
| 21153 | 21276 | $wh, |
| 21154 | 21277 | allow_screen_content_tools, |
| @@ -21159,8 +21282,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 21159 | 21282 | if sb128_none { |
| 21160 | 21283 | INTER_SB128_NONE_HITS.with(|c| c.set(c.get() + 1)); |
| 21161 | 21284 | let at128 = ((sb_r & !1) as usize * 4, (sb_c & !1) as usize * 4); |
| 21285 | + // lane-sb128c r3: `at128` is in SUB16 units like `sb_at`; | |
| 21286 | + // `decode_inter_block` takes MI. Unconverted it was (0,0) for | |
| 21287 | + // the first 128 root and a quarter-position for every other | |
| 21288 | + // one -- the whole-frame gate never got past superblock 1. | |
| 21162 | 21289 | inter_piece!( |
| 21163 | - at128, SB * 2, | |
| 21290 | + sub16_to_mi(at128), SB * 2, | |
| 21164 | 21291 | TxbSet::Luma64, TxbSet::Luma64, TxbSet::Chroma32, TX32, TX32, |
| 21165 | 21292 | &scan32, &scan32, 3, SB * 2, SB * 2 |
| 21166 | 21293 | ); |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
| @@ -43,7 +43,6 @@ const REFUSALS: &[&str] = &[ | ||
| 43 | 43 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 44 | 44 | "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", |
| 45 | 45 | "a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and NONE are decoded at the 128 root)", |
| 46 | - "an INTRA-coded 128x128 block inside an inter frame (only the inter half of a 128x128 root is decoded here)", | |
| 47 | 46 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", |
| 48 | 47 | "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)", |
| 49 | 48 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", |
crates/ec-av1/src/stream.rsmodified+17 -13
| @@ -18384,17 +18384,11 @@ mod tests { | ||
| 18384 | 18384 | /// films are 10-bit) with `tx-size-search=0` (TX_MODE_LARGEST, the block's |
| 18385 | 18385 | /// four TX_64X64 units come straight from `max_txsize_rect_lookup`) and an |
| 18386 | 18386 | /// 8-bit `tx-size-search=1` arm (the var-tx tree at 128). |
| 18387 | + // lane-sb128c r3: green. `--min-partition-size=32` let the RD search reach | |
| 18388 | + // 16x16-level AB / SB-level AB shapes that other lanes still refuse (two of | |
| 18389 | + // the three arms stopped there, measured); at 64 every arm decodes and the | |
| 18390 | + // 128 root still resolves NONE. | |
| 18387 | 18391 | #[test] |
| 18388 | - // lane-sb128c r1 leaves this gate RED: the recipe really fires the shape | |
| 18389 | - // (`partition_w128 value=0` four times, traced), the key frame alone | |
| 18390 | - // decodes, but the 8-frame stream stops on "a split intra strip whose | |
| 18391 | - // transform unit is 32x64" -- an intra rect strip aomenc cannot have coded | |
| 18392 | - // with `--enable-rect-partitions=0`, so our own 128 inter block desyncs | |
| 18393 | - // first (class refusal-from-own-desync). r2 owns the range ladder. | |
| 18394 | - #[ignore = "lane-sb128c r2: the 128 inter NONE block is now in sync (the uv_mode alphabet fix); \ | |
| 18395 | - this stream also carries ONE intra-coded 128x128 block inside an inter frame \ | |
| 18396 | - (aomdec EC_PART_VAL mi_row=32 mi_col=32 bsize=15 value=0 with no EC_MODE), which \ | |
| 18397 | - is still refused by name -- see lanes/sb128c-r2.report.md"] | |
| 18398 | 18392 | fn a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact() { |
| 18399 | 18393 | const NAME: &str = "a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact"; |
| 18400 | 18394 | let _gate_lock = lock_gate_counters(); |
| @@ -18403,6 +18397,7 @@ mod tests { | ||
| 18403 | 18397 | return; |
| 18404 | 18398 | } |
| 18405 | 18399 | let (width, height) = (256usize, 256usize); |
| 18400 | + let mut intra128_total = 0usize; | |
| 18406 | 18401 | for (ten_bit, tx_search, seed) in [(false, false, 61u32), (true, false, 61), (false, true, 62)] { |
| 18407 | 18402 | let pix = if ten_bit { "yuv420p10le" } else { "yuv420p" }; |
| 18408 | 18403 | let y4m = Command::new("ffmpeg") |
| @@ -18446,7 +18441,7 @@ mod tests { | ||
| 18446 | 18441 | "--row-mt=0", |
| 18447 | 18442 | "--sb-size=128", |
| 18448 | 18443 | "--max-partition-size=128", |
| 18449 | - "--min-partition-size=32", | |
| 18444 | + "--min-partition-size=64", | |
| 18450 | 18445 | "--enable-rect-partitions=0", |
| 18451 | 18446 | "--enable-ab-partitions=0", |
| 18452 | 18447 | "--enable-1to4-partitions=0", |
| @@ -18508,15 +18503,18 @@ mod tests { | ||
| 18508 | 18503 | let before = ( |
| 18509 | 18504 | crate::decode::inter_sb128_none_hits(), |
| 18510 | 18505 | crate::decode::chroma_split_tx_hits(), |
| 18506 | + crate::decode::intra_128_in_inter_hits(), | |
| 18511 | 18507 | ); |
| 18512 | 18508 | let (frames, hidden) = decode_all_frames_vs_oracle( |
| 18513 | 18509 | &stream, |
| 18514 | 18510 | &format!("sb128c-inter-none-{}-{}", if ten_bit { 10 } else { 8 }, tx_search), |
| 18515 | 18511 | ); |
| 18516 | - let (none128, chroma_units) = ( | |
| 18512 | + let (none128, chroma_units, intra128) = ( | |
| 18517 | 18513 | crate::decode::inter_sb128_none_hits() - before.0, |
| 18518 | 18514 | crate::decode::chroma_split_tx_hits() - before.1, |
| 18515 | + crate::decode::intra_128_in_inter_hits() - before.2, | |
| 18519 | 18516 | ); |
| 18517 | + intra128_total += intra128; | |
| 18520 | 18518 | assert!( |
| 18521 | 18519 | frames >= 6, |
| 18522 | 18520 | "{NAME} ({pix} tx_search={tx_search}): only {frames} decode-order frames" |
| @@ -18528,9 +18526,15 @@ mod tests { | ||
| 18528 | 18526 | ); |
| 18529 | 18527 | eprintln!( |
| 18530 | 18528 | "{NAME} ({pix} tx_search={tx_search}): {frames} decode-order frames pixel-exact \ |
| 18531 | - ({hidden} hidden), inter_sb128_none_hits={none128} chroma_units={chroma_units}" | |
| 18529 | + ({hidden} hidden), inter_sb128_none_hits={none128} chroma_units={chroma_units} \ | |
| 18530 | + intra_128_in_inter={intra128}" | |
| 18532 | 18531 | ); |
| 18533 | 18532 | } |
| 18533 | + assert!( | |
| 18534 | + intra128_total >= 1, | |
| 18535 | + "{NAME}: no INTRA-coded 128x128 block inside an inter frame across the three arms -- \ | |
| 18536 | + the refusal this round lifted is no longer exercised" | |
| 18537 | + ); | |
| 18534 | 18538 | } |
| 18535 | 18539 | |
| 18536 | 18540 | /// lane-sbpart r2: a real `aomenc` stream whose superblock-level |
lanes/COMMON-20260901.mdmodified+6 -0
| @@ -100,3 +100,9 @@ If you ran it: extract your own hunks, `git checkout -- crates/`, re-apply. | ||
| 100 | 100 | never two suites per lane; film extracts ≤2 s; a watchdog (`ec-memwatch` user unit, log |
| 101 | 101 | `$HOME/.cache/ec-memwatch.log`) SIGKILLs any codec/test process above 6 GiB RSS or the largest one |
| 102 | 102 | when MemAvailable < 3 GiB — a killed run means YOUR command exceeded the budget: bound it, do not retry as-is. |
| 103 | + | |
| 104 | +## WORKTREE SETUP (2026-09-02, three lanes lost a round to this) | |
| 105 | +A new worktree needs the TOP-LEVEL fixtures symlink: `ln -s /home/user/Documents/Code/Rust/edith_codecs/fixtures <worktree>/fixtures`. | |
| 106 | +Without it exactly one gate fails: a_real_aomenc_stream_with_film_grain_decodes_pixel_exact with Os NotFound — it is NOT a decode defect. | |
| 107 | +New files under crates/ec-av1/fixtures/ need `git add -f` (bare `fixtures` in .gitignore); verify with `git ls-files`. | |
| 108 | +Commit-msg hook rejects film titles / home paths: describe streams by codec/resolution/bit depth. |