Merge branch 'lane-uv8' (7f372b9): non-DC chroma modes on 8x8 intra leaves in inter frames
Browse files at this commit7 changed files +654 -30
- crates/ec-av1/src/decode.rs +152 -29
- crates/ec-av1/src/refusal_inventory.rs +0 -1
- crates/ec-av1/src/stream.rs +277 -0
- lanes/uv8-r1.handoff.md +64 -0
- lanes/uv8-r2.handoff.md +65 -0
- lanes/uv8-r3.handoff.md +54 -0
- lanes/uv8-r3.report.md +42 -0
crates/ec-av1/src/decode.rsmodified+152 -29
| @@ -171,6 +171,26 @@ pub(crate) fn intra_in_inter_angle_delta_uv_hits() -> usize { | |||
| 171 | INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.get()) | 171 | INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.get()) |
| 172 | } | 172 | } |
| 173 | 173 | ||
| 174 | +// lane-uv8 r1: the three non-DC chroma mode classes an INTRA 8x8 leaf inside | ||
| 175 | +// an INTER frame ([`decode_inter_block8`]'s intra arm) can carry -- the arm | ||
| 176 | +// read `uv_mode` and then refused everything but `DC_PRED`. Counted here and | ||
| 177 | +// nowhere else so the gate's assert cannot be satisfied by a >=16x16 block. | ||
| 178 | +thread_local! { | ||
| 179 | + static INTRA_IN_INTER8_UV_DIR_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 180 | + static INTRA_IN_INTER8_UV_SMOOTH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 181 | + static INTRA_IN_INTER8_UV_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 182 | +} | ||
| 183 | + | ||
| 184 | +/// `(directional, smooth/paeth, CfL)` chroma modes coded by an intra 8x8 leaf | ||
| 185 | +/// inside an inter frame -- see [`INTRA_IN_INTER8_UV_DIR_HITS`]. | ||
| 186 | +pub(crate) fn intra_in_inter8_uv_hits() -> (usize, usize, usize) { | ||
| 187 | + ( | ||
| 188 | + INTRA_IN_INTER8_UV_DIR_HITS.with(|c| c.get()), | ||
| 189 | + INTRA_IN_INTER8_UV_SMOOTH_HITS.with(|c| c.get()), | ||
| 190 | + INTRA_IN_INTER8_UV_CFL_HITS.with(|c| c.get()), | ||
| 191 | + ) | ||
| 192 | +} | ||
| 193 | + | ||
| 174 | // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into | 194 | // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into |
| 175 | // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a | 195 | // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a |
| 176 | // frame-level flag through the recursive block decode -- `0` (the default) | 196 | // frame-level flag through the recursive block decode -- `0` (the default) |
| @@ -22065,7 +22085,6 @@ fn decode_inter_block8( | |||
| 22065 | const CHROMA_SIDE: usize = 4; | 22085 | const CHROMA_SIDE: usize = 4; |
| 22066 | 22086 | ||
| 22067 | let (r, c) = outer_at; | 22087 | let (r, c) = outer_at; |
| 22068 | - let _ = (r, c); | ||
| 22069 | // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's -- | 22088 | // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's -- |
| 22070 | // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the | 22089 | // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the |
| 22071 | // left column of a 16x16's second leaf ROW is the previous 16x16 block's | 22090 | // left column of a 16x16's second leaf ROW is the previous 16x16 block's |
| @@ -22120,6 +22139,10 @@ fn decode_inter_block8( | |||
| 22120 | } | 22139 | } |
| 22121 | 22140 | ||
| 22122 | let mode_for_tx; | 22141 | let mode_for_tx; |
| 22142 | + // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the | ||
| 22143 | + // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf | ||
| 22144 | + // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up. | ||
| 22145 | + let mut uv_predict_mode = DC_PRED; | ||
| 22123 | let (luma_grid, u_grid, v_grid); | 22146 | let (luma_grid, u_grid, v_grid); |
| 22124 | let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; | 22147 | let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; |
| 22125 | // lane-inter8 r1: this leaf's own resolved references, handed back so the | 22148 | // lane-inter8 r1: this leaf's own resolved references, handed back so the |
| @@ -23330,12 +23353,62 @@ fn decode_inter_block8( | |||
| 23330 | this leaf with one; the >=16x16 arm decodes deltas)", | 23353 | this leaf with one; the >=16x16 arm decodes deltas)", |
| 23331 | )); | 23354 | )); |
| 23332 | } | 23355 | } |
| 23356 | + // lane-uv8 r1: the delta'd angle decides the intra edge filter, and a | ||
| 23357 | + // directional luma mode is already legal on this leaf -- the arm | ||
| 23358 | + // passed a hardcoded `false` where [`decode_leaf8`] reads the | ||
| 23359 | + // mi-exact neighbour modes (`get_intra_edge_filter_type`, spec | ||
| 23360 | + // 7.11.2). | ||
| 23361 | + let (above_mode, left_mode) = | ||
| 23362 | + neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, neighbours.modes_above_left(r, c)); | ||
| 23363 | + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); | ||
| 23364 | + // lane-uv8 r1: libaom `read_intra_block_mode_info` (decodemv.c:1198-1207) | ||
| 23365 | + // -- `uv_mode` over the CFL-allowed alphabet (`is_cfl_allowed`: a | ||
| 23366 | + // BLOCK_8X8 leaf is inside the 32x32 bound), then `read_cfl_alphas` | ||
| 23367 | + // for `UV_CFL_PRED`, then `angle_delta_uv` off the MAPPED uv mode's | ||
| 23368 | + // row (`get_uv_mode`, identity over `V_PRED..=D67_PRED`). Every value | ||
| 23369 | + // but `DC_PRED` was refused here, which is what blocked the low-cq | ||
| 23370 | + // CDEF arms and the 10-bit gates. | ||
| 23333 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); | 23371 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); |
| 23334 | - if uv_mode != DC_PRED { | 23372 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { |
| 23335 | - return Err(unsupported( | 23373 | + eprintln!( |
| 23336 | - "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", | 23374 | + "EC_ISTEP8 mi_row={} mi_col={} name=modes y={mode} uv={uv_mode} fi_enabled={} rng={}", |
| 23337 | - )); | 23375 | + leaf_mi.0, |
| 23376 | + leaf_mi.1, | ||
| 23377 | + ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get), | ||
| 23378 | + dec.debug_state().0 | ||
| 23379 | + ); | ||
| 23338 | } | 23380 | } |
| 23381 | + if (9..=12).contains(&uv_mode) { | ||
| 23382 | + SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23383 | + INTRA_IN_INTER8_UV_SMOOTH_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23384 | + } | ||
| 23385 | + let alpha = if uv_mode == UV_CFL_PRED { | ||
| 23386 | + INTRA_IN_INTER8_UV_CFL_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23387 | + Some(read_cfl_alphas(dec, cdfs)) | ||
| 23388 | + } else { | ||
| 23389 | + None | ||
| 23390 | + }; | ||
| 23391 | + let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) { | ||
| 23392 | + DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23393 | + INTRA_IN_INTER8_UV_DIR_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23394 | + read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) | ||
| 23395 | + } else { | ||
| 23396 | + 0 | ||
| 23397 | + }; | ||
| 23398 | + if angle_delta_uv != 0 { | ||
| 23399 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23400 | + INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23401 | + } | ||
| 23402 | + // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED`. | ||
| 23403 | + uv_predict_mode = if uv_mode == UV_CFL_PRED { | ||
| 23404 | + DC_PRED | ||
| 23405 | + } else { | ||
| 23406 | + uv_mode | ||
| 23407 | + }; | ||
| 23408 | + // The CHROMA neighbour's own `uv_mode` decides the chroma edge filter | ||
| 23409 | + // strength (`get_intra_edge_filter_type`, reconintra.c:974), never the | ||
| 23410 | + // luma one -- same read [`decode_leaf8`] does. | ||
| 23411 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | ||
| 23339 | // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/ | 23412 | // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/ |
| 23340 | // `uv_mode` are both effectively `DC_PRED`-gated already on this | 23413 | // `uv_mode` are both effectively `DC_PRED`-gated already on this |
| 23341 | // leaf (a nonzero `mode` still passes, but `uv_mode` is forced | 23414 | // leaf (a nonzero `mode` still passes, but `uv_mode` is forced |
| @@ -23347,7 +23420,10 @@ fn decode_inter_block8( | |||
| 23347 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 23420 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 23348 | )); | 23421 | )); |
| 23349 | } | 23422 | } |
| 23350 | - if dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { | 23423 | + // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only |
| 23424 | + // when `uv_mode == UV_DC_PRED` (decodemv.c) -- unconditional here | ||
| 23425 | + // while every non-DC uv_mode was refused a few lines above. | ||
| 23426 | + if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { | ||
| 23351 | return Err(unsupported( | 23427 | return Err(unsupported( |
| 23352 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 23428 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 23353 | )); | 23429 | )); |
| @@ -23362,14 +23438,39 @@ fn decode_inter_block8( | |||
| 23362 | // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied: | 23438 | // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied: |
| 23363 | // a real palette-Y block already returned above. | 23439 | // a real palette-Y block already returned above. |
| 23364 | let mut filter_intra = None; | 23440 | let mut filter_intra = None; |
| 23441 | + // lane-uv8 r2: the oracle's `EC_ISTEP` ladder (`EC_TRACE_MODE_STEP`) | ||
| 23442 | + // prints `use_filter_intra` for an intra block inside an INTER frame | ||
| 23443 | + // and nothing else, so this leaf needs the same two lines for a | ||
| 23444 | + // range-ladder diff against it. | ||
| 23445 | + let ec_istep8 = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); | ||
| 23365 | if mode == DC_PRED | 23446 | if mode == DC_PRED |
| 23366 | && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) | 23447 | && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) |
| 23367 | && let Some(class) = filter_intra_size_class(SIDE) | 23448 | && let Some(class) = filter_intra_size_class(SIDE) |
| 23368 | - && dec.symbol(&mut cdfs.filter_intra[class]) != 0 | ||
| 23369 | { | 23449 | { |
| 23370 | - FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | 23450 | + let use_fi = dec.symbol(&mut cdfs.filter_intra[class]) != 0; |
| 23371 | - INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | 23451 | + if ec_istep8 { |
| 23372 | - filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); | 23452 | + eprintln!( |
| 23453 | + "EC_ISTEP mi_row={} mi_col={} name=use_filter_intra val={} rng={}", | ||
| 23454 | + leaf_mi.0, | ||
| 23455 | + leaf_mi.1, | ||
| 23456 | + u8::from(use_fi), | ||
| 23457 | + dec.debug_state().0 | ||
| 23458 | + ); | ||
| 23459 | + } | ||
| 23460 | + if use_fi { | ||
| 23461 | + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23462 | + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23463 | + let fi = dec.symbol(&mut cdfs.filter_intra_mode); | ||
| 23464 | + if ec_istep8 { | ||
| 23465 | + eprintln!( | ||
| 23466 | + "EC_ISTEP mi_row={} mi_col={} name=filter_intra_mode val={fi} rng={}", | ||
| 23467 | + leaf_mi.0, | ||
| 23468 | + leaf_mi.1, | ||
| 23469 | + dec.debug_state().0 | ||
| 23470 | + ); | ||
| 23471 | + } | ||
| 23472 | + filter_intra = Some(fi); | ||
| 23473 | + } | ||
| 23373 | } | 23474 | } |
| 23374 | mode_for_tx = mode; | 23475 | mode_for_tx = mode; |
| 23375 | let (mi_row, mi_col) = leaf_mi; | 23476 | let (mi_row, mi_col) = leaf_mi; |
| @@ -23428,31 +23529,34 @@ fn decode_inter_block8( | |||
| 23428 | &vec![0i32; SIDE * SIDE], | 23529 | &vec![0i32; SIDE * SIDE], |
| 23429 | None, | 23530 | None, |
| 23430 | filter_intra, | 23531 | filter_intra, |
| 23431 | - false, | 23532 | + smooth_neighbor, |
| 23432 | ); | 23533 | ); |
| 23534 | + // CfL's AC contribution is the luma this leaf just reconstructed, | ||
| 23535 | + // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5). | ||
| 23536 | + let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); | ||
| 23433 | u.reconstruct( | 23537 | u.reconstruct( |
| 23434 | cpx, | 23538 | cpx, |
| 23435 | cpy, | 23539 | cpy, |
| 23436 | CHROMA_SIDE, | 23540 | CHROMA_SIDE, |
| 23437 | - DC_PRED, | 23541 | + uv_predict_mode, |
| 23438 | - 0, | 23542 | + angle_delta_uv, |
| 23439 | reach, | 23543 | reach, |
| 23440 | &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], | 23544 | &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], |
| 23545 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 23441 | None, | 23546 | None, |
| 23442 | - None, | 23547 | + smooth_neighbor_uv, |
| 23443 | - false, | ||
| 23444 | ); | 23548 | ); |
| 23445 | v.reconstruct( | 23549 | v.reconstruct( |
| 23446 | cpx, | 23550 | cpx, |
| 23447 | cpy, | 23551 | cpy, |
| 23448 | CHROMA_SIDE, | 23552 | CHROMA_SIDE, |
| 23449 | - DC_PRED, | 23553 | + uv_predict_mode, |
| 23450 | - 0, | 23554 | + angle_delta_uv, |
| 23451 | reach, | 23555 | reach, |
| 23452 | &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], | 23556 | &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], |
| 23557 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 23453 | None, | 23558 | None, |
| 23454 | - None, | 23559 | + smooth_neighbor_uv, |
| 23455 | - false, | ||
| 23456 | ); | 23560 | ); |
| 23457 | luma_grid = vec![0i32; SIDE * SIDE]; | 23561 | luma_grid = vec![0i32; SIDE * SIDE]; |
| 23458 | u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | 23562 | u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| @@ -23462,7 +23566,15 @@ fn decode_inter_block8( | |||
| 23462 | luma_grid = read_plane( | 23566 | luma_grid = read_plane( |
| 23463 | dec, | 23567 | dec, |
| 23464 | cdfs, | 23568 | cdfs, |
| 23465 | - TxbSet::Luma8, | 23569 | + // lane-uv8 r3: an intra leaf inside an inter frame is |
| 23570 | + // `is_inter == 0` in `av1_get_ext_tx_set_type`, so its 8x8 | ||
| 23571 | + // luma reads the INTRA set -- seven-type | ||
| 23572 | + // `EXT_TX_SET_DTT4_IDTX_1DDCT` when `reduced_tx_set == 0`, | ||
| 23573 | + // five-type `EXT_TX_SET_DTT4_IDTX` when it is 1. Hardcoding | ||
| 23574 | + // the reduced set read the wrong ALPHABET (class | ||
| 23575 | + // [[wrong-alphabet-same-value]]) and desynced at the leaf's | ||
| 23576 | + // first `tx_type`. | ||
| 23577 | + txbset_for(8, reduced_tx_set), | ||
| 23466 | scan8, | 23578 | scan8, |
| 23467 | 0, | 23579 | 0, |
| 23468 | around[0], | 23580 | around[0], |
| @@ -23479,8 +23591,9 @@ fn decode_inter_block8( | |||
| 23479 | None, | 23591 | None, |
| 23480 | filter_intra, | 23592 | filter_intra, |
| 23481 | None, | 23593 | None, |
| 23482 | - false, | 23594 | + smooth_neighbor, |
| 23483 | )?; | 23595 | )?; |
| 23596 | + let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); | ||
| 23484 | u_grid = read_plane( | 23597 | u_grid = read_plane( |
| 23485 | dec, | 23598 | dec, |
| 23486 | cdfs, | 23599 | cdfs, |
| @@ -23489,8 +23602,8 @@ fn decode_inter_block8( | |||
| 23489 | 1, | 23602 | 1, |
| 23490 | around[1], | 23603 | around[1], |
| 23491 | mode, | 23604 | mode, |
| 23492 | - DC_PRED, | 23605 | + uv_predict_mode, |
| 23493 | - 0, | 23606 | + angle_delta_uv, |
| 23494 | reach, | 23607 | reach, |
| 23495 | u, | 23608 | u, |
| 23496 | cpx, | 23609 | cpx, |
| @@ -23498,10 +23611,10 @@ fn decode_inter_block8( | |||
| 23498 | CHROMA_SIDE, | 23611 | CHROMA_SIDE, |
| 23499 | TX4, | 23612 | TX4, |
| 23500 | base_q_idx, | 23613 | base_q_idx, |
| 23614 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 23501 | None, | 23615 | None, |
| 23502 | None, | 23616 | None, |
| 23503 | - None, | 23617 | + smooth_neighbor_uv, |
| 23504 | - false, | ||
| 23505 | )?; | 23618 | )?; |
| 23506 | v_grid = read_plane( | 23619 | v_grid = read_plane( |
| 23507 | dec, | 23620 | dec, |
| @@ -23511,8 +23624,8 @@ fn decode_inter_block8( | |||
| 23511 | 2, | 23624 | 2, |
| 23512 | around[2], | 23625 | around[2], |
| 23513 | mode, | 23626 | mode, |
| 23514 | - DC_PRED, | 23627 | + uv_predict_mode, |
| 23515 | - 0, | 23628 | + angle_delta_uv, |
| 23516 | reach, | 23629 | reach, |
| 23517 | v, | 23630 | v, |
| 23518 | cpx, | 23631 | cpx, |
| @@ -23520,10 +23633,10 @@ fn decode_inter_block8( | |||
| 23520 | CHROMA_SIDE, | 23633 | CHROMA_SIDE, |
| 23521 | TX4, | 23634 | TX4, |
| 23522 | base_q_idx, | 23635 | base_q_idx, |
| 23636 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 23523 | None, | 23637 | None, |
| 23524 | None, | 23638 | None, |
| 23525 | - None, | 23639 | + smooth_neighbor_uv, |
| 23526 | - false, | ||
| 23527 | )?; | 23640 | )?; |
| 23528 | } | 23641 | } |
| 23529 | } | 23642 | } |
| @@ -23545,6 +23658,16 @@ fn decode_inter_block8( | |||
| 23545 | ) | 23658 | ) |
| 23546 | }); | 23659 | }); |
| 23547 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); | 23660 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 23661 | + // lane-uv8 r1: this leaf never stamped a mode band at all, so the block | ||
| 23662 | + // below/right of it read whatever block last wrote the coarse [`SUB`] | ||
| 23663 | + // slot -- now that an intra leaf here can code a smooth/directional | ||
| 23664 | + // `uv_mode`, its chroma neighbours must see it (and an inter leaf must | ||
| 23665 | + // stamp `DC_PRED`, what libaom stores for a non-intra block). Same pair | ||
| 23666 | + // [`decode_leaf8`] writes, plus the coarse fallback slots. | ||
| 23667 | + neighbours.above_uv_mode[c] = uv_predict_mode; | ||
| 23668 | + neighbours.left_uv_mode[r] = uv_predict_mode; | ||
| 23669 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode_for_tx); | ||
| 23670 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | ||
| 23548 | if let Some((left, above)) = saved_luma_ctx { | 23671 | if let Some((left, above)) = saved_luma_ctx { |
| 23549 | for (cell, state) in left.into_iter().enumerate() { | 23672 | for (cell, state) in left.into_iter().enumerate() { |
| 23550 | neighbours.left[leaf_mi.0 + cell][0] = state; | 23673 | neighbours.left[leaf_mi.0 + cell][0] = state; |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
| @@ -25,7 +25,6 @@ | |||
| 25 | #[cfg(test)] | 25 | #[cfg(test)] |
| 26 | const CAPABILITY_CLAIMS: &[&str] = &[ | 26 | const CAPABILITY_CLAIMS: &[&str] = &[ |
| 27 | "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", | 27 | "filter intra on a superblock-level HORZ/VERT strip (never expected -- av1_filter_intra_allowed_bsize caps at 32x32)", |
| 28 | - "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", | ||
| 29 | ]; | 28 | ]; |
| 30 | 29 | ||
| 31 | #[cfg(test)] | 30 | #[cfg(test)] |
crates/ec-av1/src/stream.rsmodified+277 -0
| @@ -6488,6 +6488,283 @@ mod tests { | |||
| 6488 | ); | 6488 | ); |
| 6489 | } | 6489 | } |
| 6490 | 6490 | ||
| 6491 | + /// lane-uv8 r1 (classes [[refusal-strings-are-claims]] + | ||
| 6492 | + /// [[tool-disabled-in-every-gate]]): a real aomenc inter sequence with | ||
| 6493 | + /// 8x8 partitions and full chroma intra tooling | ||
| 6494 | + /// (`--enable-cfl-intra=1 --enable-smooth-intra=1 --enable-paeth-intra=1 | ||
| 6495 | + /// --enable-directional-intra=1`), in which the RD gives an INTRA 8x8 | ||
| 6496 | + /// leaf inside an inter frame a NON-DC `uv_mode`. That leaf | ||
| 6497 | + /// ([`decode::decode_inter_block8`]'s intra arm) read the `uv_mode` | ||
| 6498 | + /// symbol and refused every value but `DC_PRED` -- "this encoder never | ||
| 6499 | + /// writes one" was a claim, and this gate is what contradicts it. Hard- | ||
| 6500 | + /// asserts `decode::intra_in_inter8_uv_hits` (directional, smooth/paeth, | ||
| 6501 | + /// CfL, counted on THIS leaf only); an attempt that never produced one | ||
| 6502 | + /// proves nothing, and exhausting every attempt is a FAILURE, not a SKIP. | ||
| 6503 | + #[test] | ||
| 6504 | + fn a_real_aomenc_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() { | ||
| 6505 | + uv_mode_in_inter8_gate(8, 1); | ||
| 6506 | + } | ||
| 6507 | + | ||
| 6508 | + /// The 10-bit arm (both of the user's films are `yuv420p10le`). | ||
| 6509 | + #[test] | ||
| 6510 | + fn a_real_aomenc_10bit_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() { | ||
| 6511 | + uv_mode_in_inter8_gate(10, 1); | ||
| 6512 | + } | ||
| 6513 | + | ||
| 6514 | + /// The multi-tile arm (class [[new-map-ignores-tile-edge]]): this round | ||
| 6515 | + /// stamps a new `uv_mode` band from the 8x8 leaf, whose availability must | ||
| 6516 | + /// be tile-relative. | ||
| 6517 | + #[test] | ||
| 6518 | + fn a_real_aomenc_two_tile_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() | ||
| 6519 | + { | ||
| 6520 | + uv_mode_in_inter8_gate(8, 2); | ||
| 6521 | + } | ||
| 6522 | + | ||
| 6523 | + fn uv_mode_in_inter8_gate(bit_depth: u32, tile_columns: u32) { | ||
| 6524 | + let name = format!("uv_mode_in_inter8_gate({bit_depth}, tiles={tile_columns})"); | ||
| 6525 | + if !have_ffmpeg() { | ||
| 6526 | + eprintln!("SKIP {name}: no ffmpeg"); | ||
| 6527 | + return; | ||
| 6528 | + } | ||
| 6529 | + if !have_aomenc() { | ||
| 6530 | + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | ||
| 6531 | + return; | ||
| 6532 | + } | ||
| 6533 | + let (width, height, frame_count) = (192usize, 128usize, 8usize); | ||
| 6534 | + let mut refusals = Vec::new(); | ||
| 6535 | + let mut uncounted_exact = 0u32; | ||
| 6536 | + let mut totals = (0usize, 0usize, 0usize); | ||
| 6537 | + for attempt in 0..30u32 { | ||
| 6538 | + let seed = 42 + attempt; | ||
| 6539 | + // A zooming fractal with a hard CUT at frame 4 (`overlay` | ||
| 6540 | + // switching a second, unrelated fractal on): after the cut a block | ||
| 6541 | + // is unpredictable from the reference, which is what makes aomenc | ||
| 6542 | + // code INTRA blocks inside an inter frame. Chroma is NOT | ||
| 6543 | + // desaturated here (every sibling inter gate passes `hue=s=0`) -- | ||
| 6544 | + // real chroma detail is exactly what pushes the chroma RD off | ||
| 6545 | + // DC_PRED. `noise` carries its own explicit seed (lavfi | ||
| 6546 | + // `gradients` ignores its seed; class [[seeded-fixture-not-reproducible]]). | ||
| 6547 | + let source = format!( | ||
| 6548 | + "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\ | ||
| 6549 | + mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\ | ||
| 6550 | + [a][b]overlay=enable='gte(n,4)',noise=alls=12:allf=t+u:all_seed={seed}", | ||
| 6551 | + 5.0 - f64::from(attempt) * 0.06, | ||
| 6552 | + 0.9 + f64::from(attempt) * 0.11 | ||
| 6553 | + ); | ||
| 6554 | + let y4m = Command::new("ffmpeg") | ||
| 6555 | + .args([ | ||
| 6556 | + "-v", | ||
| 6557 | + "error", | ||
| 6558 | + "-f", | ||
| 6559 | + "lavfi", | ||
| 6560 | + "-i", | ||
| 6561 | + &source, | ||
| 6562 | + "-pix_fmt", | ||
| 6563 | + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, | ||
| 6564 | + "-strict", | ||
| 6565 | + "-1", | ||
| 6566 | + "-t", | ||
| 6567 | + "0.32", | ||
| 6568 | + "-f", | ||
| 6569 | + "yuv4mpegpipe", | ||
| 6570 | + "-strict", | ||
| 6571 | + "-1", | ||
| 6572 | + "-", | ||
| 6573 | + ]) | ||
| 6574 | + .stdin(Stdio::null()) | ||
| 6575 | + .stdout(Stdio::piped()) | ||
| 6576 | + .stderr(Stdio::piped()) | ||
| 6577 | + .output() | ||
| 6578 | + .expect("ffmpeg failed to run"); | ||
| 6579 | + assert!( | ||
| 6580 | + y4m.status.success(), | ||
| 6581 | + "ffmpeg fixture: {}", | ||
| 6582 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 6583 | + ); | ||
| 6584 | + // A coarser quantiser is what pushes the chroma RD to a cheap | ||
| 6585 | + // non-DC mode on a small block; sweep 12..40 (the low end is what | ||
| 6586 | + // lane-cdef's cq12 arm needs). | ||
| 6587 | + let cq = format!("--cq-level={}", 12 + (attempt % 5) * 7); | ||
| 6588 | + let depth_args: &[&str] = if bit_depth == 10 { | ||
| 6589 | + &["-b", "10", "--input-bit-depth=10"] | ||
| 6590 | + } else { | ||
| 6591 | + &[] | ||
| 6592 | + }; | ||
| 6593 | + let tiles = format!("--tile-columns={}", tile_columns - 1); | ||
| 6594 | + // The y4m goes through a FILE, not aomenc's stdin: this gate's | ||
| 6595 | + // stream is ~100 KB, bigger than a pipe buffer, so an aomenc that | ||
| 6596 | + // is still being fed on stdin blocks writing its stdout and the | ||
| 6597 | + // test blocks writing its stdin -- a hard deadlock (measured | ||
| 6598 | + // here, 3 min into attempt 0, class [[gate-loader-slurps-whole-file]]). | ||
| 6599 | + // The path is PID-keyed (class [[pid-keyed-temp-path]]). | ||
| 6600 | + let y4m_path = std::env::temp_dir().join(format!( | ||
| 6601 | + "ec-av1-uv8-{}-{bit_depth}-{tile_columns}-{seed}.y4m", | ||
| 6602 | + std::process::id() | ||
| 6603 | + )); | ||
| 6604 | + std::fs::write(&y4m_path, &y4m.stdout).expect("writing the y4m fixture"); | ||
| 6605 | + let child = Command::new(aomenc_path()) | ||
| 6606 | + .args(depth_args) | ||
| 6607 | + .args([ | ||
| 6608 | + "--codec=av1", | ||
| 6609 | + "--passes=1", | ||
| 6610 | + "--end-usage=q", | ||
| 6611 | + &cq, | ||
| 6612 | + "--cpu-used=0", | ||
| 6613 | + "--lag-in-frames=0", | ||
| 6614 | + "--auto-alt-ref=0", | ||
| 6615 | + "--kf-max-dist=9999", | ||
| 6616 | + "--kf-min-dist=9999", | ||
| 6617 | + "--threads=1", | ||
| 6618 | + "--row-mt=0", | ||
| 6619 | + &tiles, | ||
| 6620 | + "--enable-order-hint=0", | ||
| 6621 | + "--enable-warped-motion=0", | ||
| 6622 | + "--enable-obmc=0", | ||
| 6623 | + "--enable-masked-comp=0", | ||
| 6624 | + "--enable-interintra-comp=0", | ||
| 6625 | + "--enable-dist-wtd-comp=0", | ||
| 6626 | + "--enable-diff-wtd-comp=0", | ||
| 6627 | + "--enable-onesided-comp=0", | ||
| 6628 | + "--enable-interintra-wedge=0", | ||
| 6629 | + "--enable-smooth-interintra=0", | ||
| 6630 | + "--enable-ab-partitions=0", | ||
| 6631 | + "--enable-1to4-partitions=0", | ||
| 6632 | + "--enable-cdef=0", | ||
| 6633 | + "--enable-restoration=0", | ||
| 6634 | + "--enable-palette=0", | ||
| 6635 | + "--enable-intrabc=0", | ||
| 6636 | + "--enable-ref-frame-mvs=0", | ||
| 6637 | + // Per-arm overrides go LAST (aomenc keeps the LAST | ||
| 6638 | + // occurrence of a repeated --enable-* flag). The three | ||
| 6639 | + // chroma intra tools this gate is about, plus the fences | ||
| 6640 | + // that keep the leaf's SIBLING refusals (its TX_4X4 | ||
| 6641 | + // split, a nonzero angle delta, sub-16 rect inter leaves) | ||
| 6642 | + // out of the way. | ||
| 6643 | + "--enable-cfl-intra=1", | ||
| 6644 | + "--enable-smooth-intra=1", | ||
| 6645 | + "--enable-paeth-intra=1", | ||
| 6646 | + "--enable-directional-intra=1", | ||
| 6647 | + "--enable-angle-delta=0", | ||
| 6648 | + "--enable-tx-size-search=0", | ||
| 6649 | + "--enable-rect-partitions=0", | ||
| 6650 | + "--min-partition-size=8", | ||
| 6651 | + "--max-partition-size=32", | ||
| 6652 | + "--obu", | ||
| 6653 | + "-o", | ||
| 6654 | + "-", | ||
| 6655 | + ]) | ||
| 6656 | + .arg(&y4m_path) | ||
| 6657 | + .stdin(Stdio::null()) | ||
| 6658 | + .stdout(Stdio::piped()) | ||
| 6659 | + .stderr(Stdio::piped()) | ||
| 6660 | + .spawn() | ||
| 6661 | + .expect("aomenc failed to start"); | ||
| 6662 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6663 | + let _ = std::fs::remove_file(&y4m_path); | ||
| 6664 | + assert!( | ||
| 6665 | + out.status.success(), | ||
| 6666 | + "aomenc refused the fixture: {}", | ||
| 6667 | + String::from_utf8_lossy(&out.stderr) | ||
| 6668 | + ); | ||
| 6669 | + let stream = out.stdout; | ||
| 6670 | + let before = decode::intra_in_inter8_uv_hits(); | ||
| 6671 | + let frames = match decode_stream(&stream) { | ||
| 6672 | + Ok(frames) => frames, | ||
| 6673 | + Err(e) => { | ||
| 6674 | + let msg = e.to_string(); | ||
| 6675 | + assert!( | ||
| 6676 | + msg.contains("unsupported"), | ||
| 6677 | + "{name} decode failed outright (seed {seed}): {msg}" | ||
| 6678 | + ); | ||
| 6679 | + refusals.push(format!("seed {seed}: {msg}")); | ||
| 6680 | + continue; | ||
| 6681 | + } | ||
| 6682 | + }; | ||
| 6683 | + let now = decode::intra_in_inter8_uv_hits(); | ||
| 6684 | + // class [[counter-from-refused-stream]]: per-attempt deltas, and | ||
| 6685 | + // only for an attempt that decoded to the end and is pixel- | ||
| 6686 | + // compared below. | ||
| 6687 | + let fired = (now.0 - before.0, now.1 - before.1, now.2 - before.2); | ||
| 6688 | + totals = ( | ||
| 6689 | + totals.0 + fired.0, | ||
| 6690 | + totals.1 + fired.1, | ||
| 6691 | + totals.2 + fired.2, | ||
| 6692 | + ); | ||
| 6693 | + // class [[gate-skips-on-its-own-failure]]: a decode that succeeded | ||
| 6694 | + // is ALWAYS pixel-compared; the counter only decides whether the | ||
| 6695 | + // attempt counts as firing. | ||
| 6696 | + // lane-uv8 r3: every one of the three chroma classes this gate | ||
| 6697 | + // exists for (directional, smooth/paeth, CfL) must fire on the | ||
| 6698 | + // SAME pixel-compared attempt -- a sum-nonzero predicate would | ||
| 6699 | + // pass on an attempt that only ever hit DC-adjacent CfL. | ||
| 6700 | + let counted = fired.0 > 0 && fired.1 > 0 && fired.2 > 0; | ||
| 6701 | + if !counted { | ||
| 6702 | + uncounted_exact += 1; | ||
| 6703 | + refusals.push(format!( | ||
| 6704 | + "seed {seed}: decoded and pixel-compared, but no 8x8 intra leaf in an inter \ | ||
| 6705 | + frame carried a non-DC uv_mode" | ||
| 6706 | + )); | ||
| 6707 | + } | ||
| 6708 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 6709 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 6710 | + } else { | ||
| 6711 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 6712 | + }; | ||
| 6713 | + assert_eq!(frames.len(), frame_count); | ||
| 6714 | + eprintln!( | ||
| 6715 | + "{name} seed={seed} {cq}: 8x8 intra-in-inter leaves with a non-DC uv_mode -- \ | ||
| 6716 | + directional {}, smooth/paeth {}, CfL {}", | ||
| 6717 | + fired.0, fired.1, fired.2 | ||
| 6718 | + ); | ||
| 6719 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 6720 | + for (plane, (g, w)) in [ | ||
| 6721 | + ("Y", (&got.y, &want.y)), | ||
| 6722 | + ("U", (&got.u, &want.u)), | ||
| 6723 | + ("V", (&got.v, &want.v)), | ||
| 6724 | + ] { | ||
| 6725 | + let stride = if plane == "Y" { width } else { width / 2 }; | ||
| 6726 | + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | ||
| 6727 | + eprintln!( | ||
| 6728 | + "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | ||
| 6729 | + want {} ({} samples differ)", | ||
| 6730 | + at % stride, | ||
| 6731 | + at / stride, | ||
| 6732 | + g[at], | ||
| 6733 | + w[at], | ||
| 6734 | + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | ||
| 6735 | + ); | ||
| 6736 | + } | ||
| 6737 | + } | ||
| 6738 | + } | ||
| 6739 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 6740 | + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | ||
| 6741 | + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | ||
| 6742 | + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | ||
| 6743 | + } | ||
| 6744 | + if counted { | ||
| 6745 | + gate_buckets( | ||
| 6746 | + &name, | ||
| 6747 | + 1, | ||
| 6748 | + uncounted_exact, | ||
| 6749 | + refusals.len() - uncounted_exact as usize, | ||
| 6750 | + ); | ||
| 6751 | + return; | ||
| 6752 | + } | ||
| 6753 | + } | ||
| 6754 | + gate_buckets( | ||
| 6755 | + &name, | ||
| 6756 | + 0, | ||
| 6757 | + uncounted_exact, | ||
| 6758 | + refusals.len() - uncounted_exact as usize, | ||
| 6759 | + ); | ||
| 6760 | + panic!( | ||
| 6761 | + "{name} never observed a non-DC uv_mode on an 8x8 intra leaf in an inter frame \ | ||
| 6762 | + (totals dir/smooth/cfl {totals:?}):\n{}", | ||
| 6763 | + refusals.join("\n") | ||
| 6764 | + ); | ||
| 6765 | + } | ||
| 6766 | + | ||
| 6767 | + | ||
| 6491 | /// lane-chroma r2 stage 1: a real aomenc key frame with | 6768 | /// lane-chroma r2 stage 1: a real aomenc key frame with |
| 6492 | /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) | 6769 | /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) |
| 6493 | /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still- | 6770 | /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still- |
lanes/uv8-r1.handoff.mdadded+64 -0
| @@ -0,0 +1,64 @@ | |||
| 1 | +# lane-uv8 r1 — HANDOFF (RED: implemented, NOT gated) | ||
| 2 | + | ||
| 3 | +## What is implemented (`crates/ec-av1/src/decode.rs`, `decode_inter_block8`'s intra arm) | ||
| 4 | +Mirrors libaom `read_intra_block_mode_info` (`av1/decoder/decodemv.c:1178-1220`, read from | ||
| 5 | +`~/.cache/aom-oracle/src`) for an INTRA 8x8 leaf inside an INTER frame: | ||
| 6 | + | ||
| 7 | +- `uv_mode` over the CFL-allowed alphabet (`cdfs.uv_mode_cfl[mode]`; BLOCK_8X8 is inside | ||
| 8 | + `is_cfl_allowed`'s 32x32 bound), then `read_cfl_alphas` when `UV_CFL_PRED`, then | ||
| 9 | + `angle_delta_uv` off `angle_delta[uv_mode - V_PRED]` (`get_uv_mode` is the identity over | ||
| 10 | + `V_PRED..=D67_PRED`) — the exact order libaom reads them in. | ||
| 11 | +- `uv_predict_mode = get_uv_mode(uv_mode)`; chroma prediction, chroma `default_tx_type` | ||
| 12 | + (`read_plane`'s `predict_mode` arg → `default_intra_tx_type`, DCT for CfL) and the CfL AC | ||
| 13 | + (`cfl_ac_q3(y, px, py, 8)` over the leaf's 4x4 chroma) all take it. | ||
| 14 | +- `smooth_neighbor_uv` from `Neighbours::smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c)` | ||
| 15 | + (chroma edge filter reads the CHROMA neighbour's uv_mode — reconintra.c:974), and the leaf's | ||
| 16 | + LUMA `smooth_neighbor` from `modes_above_left_mi` (it passed a hardcoded `false` before). | ||
| 17 | +- `palette_uv_mode` is now read only when `uv_mode == DC_PRED` (`read_palette_mode_info`); | ||
| 18 | + it was read unconditionally, harmless only because every non-DC uv_mode was refused. | ||
| 19 | +- Tail: the leaf now stamps its mode bands (`above_uv_mode[c]`/`left_uv_mode[r]`, | ||
| 20 | + `record_mode_mi`, `record_uv_mode_mi`, 2x2 mi) — it stamped none at all, so a neighbour read | ||
| 21 | + a stale coarse SUB slot. An inter leaf stamps `DC_PRED`, what libaom stores. | ||
| 22 | +- New per-leaf counters `decode::intra_in_inter8_uv_hits() -> (dir, smooth/paeth, cfl)`. | ||
| 23 | + | ||
| 24 | +## Refusal state | ||
| 25 | +`"a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)"` is REMOVED | ||
| 26 | +from decode.rs and from `refusal_inventory.rs::CAPABILITY_CLAIMS`. **This lift is NOT gated** — | ||
| 27 | +see below. If the next round cannot gate it, restoring both lines is the honest move. | ||
| 28 | + | ||
| 29 | +## Gate (written, never observed a firing attempt) | ||
| 30 | +`stream.rs::uv_mode_in_inter8_gate(bit_depth, tile_columns)` + 3 tests (8-bit, 10-bit, 2-tile): | ||
| 31 | +192x128, 8 frames, mandelbrot zoom + hard cut at frame 4 + seeded `noise`, chroma NOT | ||
| 32 | +desaturated, 30 attempts, cq 12..40, `--min-partition-size=8 --max-partition-size=32 | ||
| 33 | +--sb-size=64 --enable-cfl-intra=1 --enable-smooth-intra=1 --enable-paeth-intra=1 | ||
| 34 | +--enable-directional-intra=1`, per-attempt counter deltas, every decode-order frame compared, | ||
| 35 | +no SKIP on decode error. The y4m goes through a temp FILE: feeding aomenc on stdin while its | ||
| 36 | +~100 KB OBU fills the stdout pipe DEADLOCKS (measured, 3 min into attempt 0). | ||
| 37 | + | ||
| 38 | +RESULT: 8-bit arm ran, 30/30 attempts REFUSED, 0 compared → the gate fails as designed. | ||
| 39 | + | ||
| 40 | +## The blocker (pre-existing, NOT this round's change) | ||
| 41 | +Every `--min-partition-size=8` inter stream refuses. `--min-partition-size=16` on the same | ||
| 42 | +recipe decodes 8/8 frames. The refusals name tools the encoder was explicitly told to disable: | ||
| 43 | +`--enable-rect-partitions=0 --enable-ab-partitions=0 --enable-1to4-partitions=0` yet we refuse | ||
| 44 | +"an inter 16x16-level AB or 1:4 partition" / "a non-skip rectangular strip"; and | ||
| 45 | +`--enable-angle-delta=0` yet we refuse "a nonzero angle delta on an 8x8 intra leaf". Class | ||
| 46 | +[[refusal-from-own-desync]]: those are our own desync, not encoder output. | ||
| 47 | +Ablation: the same refusals appear with `--enable-cfl-intra=0 --enable-smooth-intra=0 | ||
| 48 | +--enable-paeth-intra=0 --enable-directional-intra=0`, where this round's code is inert → | ||
| 49 | +the desync is INDEPENDENT of this round. | ||
| 50 | +The KEY frame of the same recipe (`--limit=1`, min8) decodes PIXEL-EXACT vs aomdec | ||
| 51 | +(md5 860b50e830271fa57fb60e4a76eb83ec both) — so the 8x8 leaf's key-frame path is fine and the | ||
| 52 | +divergence is in an INTER frame. | ||
| 53 | + | ||
| 54 | +## Exact next step | ||
| 55 | +Bisect the first inter-frame divergence with the oracle mode ladder. Note the trace semantics | ||
| 56 | +(cost this round an hour): oracle `EC_IMODE` = KEY-frame blocks only, oracle `EC_MODE` = | ||
| 57 | +INTER blocks only (an intra block inside an inter frame prints NEITHER), while ours prints | ||
| 58 | +`EC_MODE` for EVERY block of an inter frame. So the oracle's `EC_MODE` (mi_row, mi_col) | ||
| 59 | +sequence must be an ordered SUBSEQUENCE of ours; the first ref entry that ours never produces | ||
| 60 | +is the first structurally divergent block. On `~/.cache/uv8-tmp/o.obu` (recipe above, cq 26, | ||
| 61 | +cpu-used 0) that subsequence match stops after 79 of the ref's frame-1 entries, with ref next | ||
| 62 | +at mi (12,8) — start there with a range ladder (compare RANGE, never tell()). | ||
| 63 | +Scripts: `~/.cache/uv8-tmp/{in.y4m,sweep.sh,sweep2.sh,sweep3.sh}`; probe | ||
| 64 | +`$HOME/.cache/cargo-target-uv8/debug/examples/decode_probe <obu> [out.yuv]`. | ||
lanes/uv8-r2.handoff.mdadded+65 -0
| @@ -0,0 +1,65 @@ | |||
| 1 | +# lane-uv8 r2 — HANDOFF (merge done, root cause NARROWED to one block, gate still RED) | ||
| 2 | + | ||
| 3 | +## Merged into lane-uv8 (tip f5c8dbf) | ||
| 4 | +- `a9b4468` main aa83400 (clean). | ||
| 5 | +- `5dc9707` lane-interp3 `10b801a` (clean). | ||
| 6 | +- `c3ead8c`/prev `af47324` lane-intersub8 — CONFLICTS resolved: | ||
| 7 | + * `decode_inter_block8` compound-leaf interp read: kept **interp3's** copy (it adds the | ||
| 8 | + `gm_nontrans_c || skip_mode` suppression and the COMPOUND8_FILTER_HITS counter); dropped | ||
| 9 | + intersub8's duplicate read (two reads = one extra symbol). | ||
| 10 | + * `resolve_interp_filter` tail: kept BOTH (interp3's DUAL_FILTER_DIFF_HITS + intersub8's EC_IF trace). | ||
| 11 | + * `refusal_inventory.rs`: union of both lists, then deleted | ||
| 12 | + "an inter partition below 8x8 (...lane-sub8 scoped to intra)" — intersub8 landed that capability | ||
| 13 | + (the `the_decode_path_refuses_exactly_the_listed_cases` test named it). | ||
| 14 | +- `6561ec4` lane-cdef `8c6065e` (clean). | ||
| 15 | +- `c3ead8c` lane-sqdrift `7d498c0` — stream.rs conflict was two whole appended test fns interleaved; | ||
| 16 | + resolved by `git checkout --ours stream.rs` + `patch -p1` of `git diff 85887c7 7d498c0 -- stream.rs` | ||
| 17 | + (both new tests present: `..._reads_the_no_cfl_uv_alphabet`, `..._square_only_inter_sequence...`). | ||
| 18 | +- `crates/ec-av1/src/cdf.rs` byte-identical to main (`git diff --stat main -- cdf.rs` empty). | ||
| 19 | +- `f5c8dbf` adds EC_TRACE_MODE_STEP ladder prints in the 8x8 intra-in-inter arm | ||
| 20 | + (`EC_ISTEP ... name=use_filter_intra` in the oracle's exact format, plus `EC_ISTEP8 name=modes`). | ||
| 21 | + | ||
| 22 | +## Gate result on the merged tree (RED, same shape as r1) | ||
| 23 | +`uv8-gate-r2.log` (unit uv8-gate-r2-1788332583, before the trace commit): all three arms | ||
| 24 | +30/30 named refusals, counted-exact=0, uncounted-exact=0. Re-armed after the merge as unit | ||
| 25 | +**uv8-gate-r2b** → `$HOME/.cache/uv8-gate-r2.log`, then the full suite in the SAME unit → | ||
| 26 | +`$HOME/.cache/uv8-suite-r2.log`. | ||
| 27 | +Refusal histogram over the 90 attempts: 31x inter 16x16-level 1:4, 21x nonzero angle delta on an | ||
| 28 | +8x8 intra leaf, 13x inter 8x8 HORZ, 10x non-skip rect strip, 5x intra 1:4 rect strip, 3x inter SB AB, | ||
| 29 | +3x 128x128 SB HORZ/VERT/AB, 2x intra 4x4 in sub-8x8 split, 1x 32x64 split TU, 1x intra 8x4/4x8. | ||
| 30 | +All still class [[refusal-from-own-desync]] — proven below. | ||
| 31 | + | ||
| 32 | +## ROOT CAUSE LOCALISED (this is the round's real result) | ||
| 33 | +Stream `~/.cache/uv8-tmp/a0.obu` (regenerate: `~/.cache/uv8-tmp/g2.sh 42 12 a0.obu`, exact gate | ||
| 34 | +recipe, 8-bit, seed 42, cq 12; note it is a **128x128 superblock** stream — the gate recipe has no | ||
| 35 | +`--sb-size=64`). | ||
| 36 | +1. `EC_TRACE=1 aomdec` partition histogram (`ref_part.txt`): the reference codes **only** NONE and | ||
| 37 | + SPLIT (bsize 15/12/9 value=3, bsize 6 value 0|3, bsize 3 value 0). There is no rect/AB/1:4 | ||
| 38 | + partition anywhere in the stream → every refusal above is our own desync. | ||
| 39 | +2. Partition range ladder (ours `EC_TRACE_PART=1` vs ref, ignoring the ctx print convention: | ||
| 40 | + ref prints `4*bsl + ctx`): decode-order frame 1 matches 138/138; frame 2 first range divergence | ||
| 41 | + at element 119 — ref `(0,36,bsize=6,rng=48648)` vs ours `rng=38664`. The previous element, | ||
| 42 | + the 8x8 partition at **mi (2,34)**, still matches (rng 44040). | ||
| 43 | +3. `EC_MODE` subsequence: ref's entries are consumed in order up to `(2,32)`; ours' next block | ||
| 44 | + `(0,36)` starts at rng 57984 vs ref 32884. Ref prints no EC_MODE for `(2,34)` → that block is an | ||
| 45 | + **INTRA 8x8 leaf inside inter frame 2**. | ||
| 46 | +4. `EC_TRACE_MODE_STEP` ladder at that block: ours reads `use_filter_intra val=1 rng=64248` and | ||
| 47 | + `filter_intra_mode val=0 rng=43964` — **bit-identical to the oracle**. Our decoded modes there are | ||
| 48 | + `y=DC_PRED, uv=13 (UV_CFL_PRED)` (`EC_ISTEP8` line). | ||
| 49 | + => the whole mode-info half of this leaf, including the new non-DC/CfL uv path, is IN SYNC. | ||
| 50 | + The desync is in what follows: `read_block_tx_size` or the leaf's COEFFICIENTS. | ||
| 51 | + | ||
| 52 | +## EXACT NEXT STEP | ||
| 53 | +Both coefficient traces are already dumped: `~/.cache/uv8-tmp/ref_co.txt` (761992 lines) and | ||
| 54 | +`ours_co.txt` (260655). Formats: ref `EC_COEFF plane=.. row=.. col=.. tx_size=.. rng=..` + | ||
| 55 | +`EC_COEFF_STEP tag=all_zero|tx_type|base|br ...`; ours prints the STEP lines only (no EC_COEFF | ||
| 56 | +header with plane/row/col). Align the two `EC_COEFF_STEP` streams and find the first `rng` | ||
| 57 | +divergence — it must be inside the block at mi (2,34) of decode-order frame 2, i.e. the FIRST | ||
| 58 | +filter-intra + CfL 8x8 intra leaf of an inter frame. Prime suspects, in order: | ||
| 59 | + (a) the CfL AC / chroma `TxbSet::Chroma4` txb ctx on a leaf whose luma is filter-intra; | ||
| 60 | + (b) `read_block_tx_size` for an intra block in an inter frame at 8x8 (`--enable-tx-size-search=0` | ||
| 61 | + here, so check whether a symbol should be read at all); | ||
| 62 | + (c) the luma `intra_ext_tx` row: `read_plane` gets `filter_intra` and applies `fi_tx_row`, but the | ||
| 63 | + CHROMA calls pass `mode` (raw luma mode) as the tx-row arg with `filter_intra=None` — verify | ||
| 64 | + against libaom `av1_read_tx_type` (chroma tx type is inferred, so this should be inert; prove it). | ||
| 65 | +Do NOT re-do steps 1-4; they are pinned above with their artifacts. | ||
lanes/uv8-r3.handoff.mdadded+54 -0
| @@ -0,0 +1,54 @@ | |||
| 1 | +# lane-uv8 r3 — HANDOFF (GREEN gate; suite still running at the turn cap) | ||
| 2 | + | ||
| 3 | +## ROOT CAUSE (fixed, committed) | ||
| 4 | +`decode_inter_block8`'s INTRA arm passed a hardcoded `TxbSet::Luma8` to `read_plane` for the | ||
| 5 | +8x8 leaf's LUMA transform. `TxbSet::Luma8` is the `reduced_tx_set == 1` alphabet | ||
| 6 | +(`EXT_TX_SET_DTT4_IDTX`, FIVE types). libaom `av1_get_ext_tx_set_type` (`av1/common/blockd.h`) | ||
| 7 | +returns `EXT_TX_SET_DTT4_IDTX_1DDCT` (SEVEN types, `TxbSet::Luma8Set1`) for `is_inter == 0`, | ||
| 8 | +`tx_size_sqr == TX_8X8`, `use_reduced_set == 0` — and an INTRA leaf inside an INTER frame is | ||
| 9 | +`is_inter == 0`. Same symbol value, different narrowing (class [[wrong-alphabet-same-value]]); | ||
| 10 | +the msac range diverged at the leaf's first `tx_type` and desynced the rest of the tile, which | ||
| 11 | +manufactured the 30/30 "named refusals" of r1/r2 (class [[refusal-from-own-desync]]). | ||
| 12 | +FIX: `crates/ec-av1/src/decode.rs:22057` -> `txbset_for(8, reduced_tx_set)` (the parameter was | ||
| 13 | +already in scope). Charter suspects (1) `fimode_to_intradir` and (2) `tx_depth` were BOTH already | ||
| 14 | +correct: `fi_tx_row` is applied at every luma txb call site, `fimode_to_intradir[0] == DC_PRED` | ||
| 15 | +equals this block's y_mode anyway, and `read_block_tx_size` returns depth 0 here. | ||
| 16 | + | ||
| 17 | +## GATE AFTER THE FIX — GREEN (unit uv8-gate-r3, log $HOME/.cache/uv8-gate-r3.log) | ||
| 18 | +`cargo test -p ec-av1 --lib -- --test-threads=1 --nocapture non_dc_chroma_8x8_intra_leaf` | ||
| 19 | +-> 3 passed / 0 failed, 5.53s. Every arm exact on ATTEMPT 0 with all three chroma classes | ||
| 20 | +firing (directional / smooth-paeth / CfL): | ||
| 21 | + 8-bit 1-tile seed42 cq12: 159 / 172 / 211 | ||
| 22 | + 10-bit 1-tile seed42 cq12: 112 / 126 / 120 | ||
| 23 | + 8-bit 2-tile seed42 cq12: 83 / 66 / 80 | ||
| 24 | +buckets on each arm: counted-exact=1 uncounted-exact=0 named-refusals=0 (attempts 1). | ||
| 25 | +All 8 frames of each stream pixel-compared vs ffmpeg (Y/U/V), no mismatch. | ||
| 26 | +`stream.rs:5897` tightened: `counted` now requires ALL THREE classes on the same compared | ||
| 27 | +attempt (was sum-nonzero) — this stricter predicate is what the green run above satisfies. | ||
| 28 | + | ||
| 29 | +## REFUSAL STATE | ||
| 30 | +The lifted non-DC-uv_mode refusal STAYS LIFTED (gate green). Still refused by name and NOT part | ||
| 31 | +of this lane: "an 8x8 intra leaf in an inter frame whose tx_depth splits it into 4x4 transform | ||
| 32 | +units" (decode.rs ~21996) and "a nonzero angle delta on an 8x8 intra leaf in an inter frame". | ||
| 33 | + | ||
| 34 | +## SWEEP (class: hardcoded reduced-set TxbSet) | ||
| 35 | +`grep -n 'TxbSet::Luma\(4\|8\|16\|32\),' crates/ec-av1/src/decode.rs` — after the fix there are | ||
| 36 | +ZERO reduced-sensitive hardcodes outside `txbset_for`/`txbset_for_inter`; every remaining | ||
| 37 | +`Luma16`/`Luma32` literal is alphabet-invariant to `reduced_tx_set`. The rect-strip and >=16 | ||
| 38 | +square intra-in-inter arms already route through `txbset_for` (decode.rs 6053, 7167, 7777, | ||
| 39 | +7857, 9594, 11075). | ||
| 40 | + | ||
| 41 | +## SUITE — RUNNING, NOT VERIFIED | ||
| 42 | +Unit `uv8-gate-r3.service` (still active at the turn cap) is now in its suite phase: | ||
| 43 | +log `$HOME/.cache/uv8-suite-r3.log`. At hand-off: 233 tests `ok`, 0 FAILED, 0 `failures:` lines | ||
| 44 | +(of ~425). NO green suite claim. | ||
| 45 | + | ||
| 46 | +## EXACT NEXT STEP | ||
| 47 | +1. `grep -E "^test result|FAILED|^failures:" $HOME/.cache/uv8-suite-r3.log` once the unit goes | ||
| 48 | + inactive; expect N/0. If a gate reddens, it is a SIBLING of this alphabet fix — re-run it | ||
| 49 | + before touching the fix. | ||
| 50 | +2. Then the lane is mergeable at its tip. | ||
| 51 | + | ||
| 52 | +## EVIDENCE | ||
| 53 | +EVIDENCE: ~/.cache/uv8-tmp/ref.tu + ours3.tu | instrumented aomdec EC_TRACE_COEFF vs our EC_TRACE_COEFF on ~/.cache/uv8-tmp/a0.obu, per-TU (all_zero,eob) msac RANGE ladder | before: first divergence at TU-line 3392 (ref eob rng=32776 vs ours 34568; the preceding tx_type read ref rng=33532 vs ours 35240 at plane=0 tx_size=1, the mi(2,34) filter-intra leaf of decode-order frame 2) — after: 13986/13986 identical over the whole stream, decode_probe rc=0, no refusal | ||
| 54 | +EVIDENCE: $HOME/.cache/uv8-gate-r3.log | the three-arm gate command above | 3 passed / 0 failed, counted-exact=1 named-refusals=0 per arm, counts as listed | ||
lanes/uv8-r3.report.mdadded+42 -0
| @@ -0,0 +1,42 @@ | |||
| 1 | +# lane-uv8 r3 — GREEN (root cause: wrong tx_type ALPHABET on the 8x8 intra-in-inter leaf) | ||
| 2 | + | ||
| 3 | +## Root cause | ||
| 4 | +`decode_inter_block8`'s INTRA arm passed a hardcoded `TxbSet::Luma8` to `read_plane` for the | ||
| 5 | +leaf's 8x8 luma transform. `TxbSet::Luma8` is the `reduced_tx_set == 1` set | ||
| 6 | +(`EXT_TX_SET_DTT4_IDTX`, FIVE types); with `reduced_tx_set == 0` libaom's | ||
| 7 | +`av1_get_ext_tx_set_type` (`av1/common/blockd.h`) returns, for `is_inter == 0` and | ||
| 8 | +`tx_size_sqr == TX_8X8`, `EXT_TX_SET_DTT4_IDTX_1DDCT` — SEVEN types | ||
| 9 | +(`TxbSet::Luma8Set1`). Same symbol, different alphabet: the CDF narrowing differed, so the | ||
| 10 | +msac range diverged at the leaf's first `tx_type` and every following block desynced. The | ||
| 11 | +desync manufactured the 30/30 "named refusals" the r1/r2 gate logs showed | ||
| 12 | +(class [[refusal-from-own-desync]] + [[wrong-alphabet-same-value]]). | ||
| 13 | + | ||
| 14 | +Charter suspect (1) (the `fimode_to_intradir` row) was already correct: `fi_tx_row` is applied | ||
| 15 | +at every luma `txb` call site including this one, and `fimode_to_intradir[0] == DC_PRED` | ||
| 16 | +equals this block's `y_mode` anyway, so that row was inert here. | ||
| 17 | + | ||
| 18 | +## Change | ||
| 19 | +- `crates/ec-av1/src/decode.rs:22057` — `TxbSet::Luma8` -> `txbset_for(8, reduced_tx_set)` | ||
| 20 | + (`reduced_tx_set` was already a parameter of `decode_inter_block8`). | ||
| 21 | +- `crates/ec-av1/src/stream.rs:5897` — gate `counted` predicate tightened from | ||
| 22 | + "sum nonzero" to "all three uv classes fired on the same pixel-compared attempt". | ||
| 23 | + | ||
| 24 | +## Sweep (class: hardcoded reduced-set TxbSet) | ||
| 25 | +`grep -n 'TxbSet::Luma\(4\|8\|16\|32\),' decode.rs` — the only reduced-sensitive hardcodes are | ||
| 26 | +sizes 8 and 4; after this fix there are ZERO outside `txbset_for`/`txbset_for_inter`. Every | ||
| 27 | +`Luma16`/`Luma32` literal is alphabet-invariant to `reduced_tx_set` (`txbset_for` maps 16 and | ||
| 28 | +32 identically for both values). The rect-strip and >=16 square intra-in-inter arms already go | ||
| 29 | +through `txbset_for`/`txbset_for_inter` (decode.rs:6053, 7167, 7777, 7857, 9594, 11075). | ||
| 30 | + | ||
| 31 | +## EVIDENCE | ||
| 32 | +EVIDENCE: ~/.cache/uv8-tmp/ref.tu + ours3.tu | aomdec EC_TRACE_COEFF vs our EC_TRACE_COEFF on ~/.cache/uv8-tmp/a0.obu, per-TU (all_zero,eob) msac range ladder | before: first divergence at TU-line 3392 (ref eob rng=32776, ours 34568; the preceding tx_type read was ref rng=33532 vs ours 35240 at plane=0 tx_size=1, the mi(2,34) filter-intra leaf of decode-order frame 2) — after: 13986/13986 lines identical, whole stream, decode_probe rc=0 with no refusal | ||
| 33 | +EVIDENCE: $HOME/.cache/uv8-gate-r3.log | `cargo test -p ec-av1 --lib -- --test-threads=1 --nocapture non_dc_chroma_8x8_intra_leaf` | 3 passed / 0 failed; every arm exact on attempt 0 with all three classes firing — 8bit/1tile dir 159 smooth-paeth 172 cfl 211; 10bit/1tile 112/126/120; 8bit/2tile 83/66/80; buckets counted-exact=1 uncounted-exact=0 named-refusals=0 on each | ||
| 34 | + | ||
| 35 | +## Residue | ||
| 36 | +- deferred: the 8x8 intra-in-inter leaf whose `tx_depth` splits to four TX_4X4 units is still | ||
| 37 | + refused by name (decode.rs ~21996). Unblocked by an arm with `--enable-tx-size-search=1` | ||
| 38 | + plus a 4x4-TU prediction loop in this leaf path — out of this lane's charter, which fixed the | ||
| 39 | + depth-0 alphabet. Its refusal string stays in refusal_inventory.rs. | ||
| 40 | +- accepted: `frames` from `decode_stream` is decode order; the gate recipe has | ||
| 41 | + `--lag-in-frames=0 --auto-alt-ref=0`, so decode order == display order and all 8 frames are | ||
| 42 | + compared (class [[gate-blind-to-hidden-frames]] does not apply). | ||