Non-DC chroma modes on an 8x8 intra leaf inside an inter frame (UNGATED)
Browse files at this commit9e5cab18a8dc31a3d604bd8fbb8d16b394b63f1eParent: fcf808d- feat
- non-DC chroma modes on an 8x8 intra leaf inside an inter frame (UNGATED)
4 changed files +442 -25
- crates/ec-av1/src/decode.rs +105 -24
- crates/ec-av1/src/refusal_inventory.rs +0 -1
- crates/ec-av1/src/stream.rs +273 -0
- lanes/uv8-r1.handoff.md +64 -0
crates/ec-av1/src/decode.rsmodified+105 -24
| @@ -171,6 +171,26 @@ pub(crate) fn intra_in_inter_angle_delta_uv_hits() -> usize { | ||
| 171 | 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 | 194 | // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into |
| 175 | 195 | // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a |
| 176 | 196 | // frame-level flag through the recursive block decode -- `0` (the default) |
| @@ -19241,7 +19261,6 @@ fn decode_inter_block8( | ||
| 19241 | 19261 | const CHROMA_SIDE: usize = 4; |
| 19242 | 19262 | |
| 19243 | 19263 | let (r, c) = outer_at; |
| 19244 | - let _ = (r, c); | |
| 19245 | 19264 | // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's -- |
| 19246 | 19265 | // leaf (mi_r, mi_c + 2)'s left neighbour is leaf (mi_r, mi_c), and the |
| 19247 | 19266 | // left column of a 16x16's second leaf ROW is the previous 16x16 block's |
| @@ -19296,6 +19315,10 @@ fn decode_inter_block8( | ||
| 19296 | 19315 | } |
| 19297 | 19316 | |
| 19298 | 19317 | let mode_for_tx; |
| 19318 | + // lane-uv8 r1: this leaf's chroma prediction mode (`get_uv_mode` of the | |
| 19319 | + // coded `uv_mode`), for the neighbour bands at the tail. An INTER leaf | |
| 19320 | + // stores `UV_DC_PRED`, exactly as [`decode_inter_block`] one level up. | |
| 19321 | + let mut uv_predict_mode = DC_PRED; | |
| 19299 | 19322 | let (luma_grid, u_grid, v_grid); |
| 19300 | 19323 | let mut compound_ctx8: Option<(i8, i8, u8, u8)> = None; |
| 19301 | 19324 | // lane-inter8 r1: this leaf's own resolved references, handed back so the |
| @@ -20375,12 +20398,53 @@ fn decode_inter_block8( | ||
| 20375 | 20398 | this leaf with one; the >=16x16 arm decodes deltas)", |
| 20376 | 20399 | )); |
| 20377 | 20400 | } |
| 20401 | + // lane-uv8 r1: the delta'd angle decides the intra edge filter, and a | |
| 20402 | + // directional luma mode is already legal on this leaf -- the arm | |
| 20403 | + // passed a hardcoded `false` where [`decode_leaf8`] reads the | |
| 20404 | + // mi-exact neighbour modes (`get_intra_edge_filter_type`, spec | |
| 20405 | + // 7.11.2). | |
| 20406 | + let (above_mode, left_mode) = | |
| 20407 | + neighbours.modes_above_left_mi(leaf_mi.0, leaf_mi.1, neighbours.modes_above_left(r, c)); | |
| 20408 | + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); | |
| 20409 | + // lane-uv8 r1: libaom `read_intra_block_mode_info` (decodemv.c:1198-1207) | |
| 20410 | + // -- `uv_mode` over the CFL-allowed alphabet (`is_cfl_allowed`: a | |
| 20411 | + // BLOCK_8X8 leaf is inside the 32x32 bound), then `read_cfl_alphas` | |
| 20412 | + // for `UV_CFL_PRED`, then `angle_delta_uv` off the MAPPED uv mode's | |
| 20413 | + // row (`get_uv_mode`, identity over `V_PRED..=D67_PRED`). Every value | |
| 20414 | + // but `DC_PRED` was refused here, which is what blocked the low-cq | |
| 20415 | + // CDEF arms and the 10-bit gates. | |
| 20378 | 20416 | let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]); |
| 20379 | - if uv_mode != DC_PRED { | |
| 20380 | - return Err(unsupported( | |
| 20381 | - "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)", | |
| 20382 | - )); | |
| 20417 | + if (9..=12).contains(&uv_mode) { | |
| 20418 | + SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1)); | |
| 20419 | + INTRA_IN_INTER8_UV_SMOOTH_HITS.with(|c| c.set(c.get() + 1)); | |
| 20383 | 20420 | } |
| 20421 | + let alpha = if uv_mode == UV_CFL_PRED { | |
| 20422 | + INTRA_IN_INTER8_UV_CFL_HITS.with(|c| c.set(c.get() + 1)); | |
| 20423 | + Some(read_cfl_alphas(dec, cdfs)) | |
| 20424 | + } else { | |
| 20425 | + None | |
| 20426 | + }; | |
| 20427 | + let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) { | |
| 20428 | + DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1)); | |
| 20429 | + INTRA_IN_INTER8_UV_DIR_HITS.with(|c| c.set(c.get() + 1)); | |
| 20430 | + read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED]) | |
| 20431 | + } else { | |
| 20432 | + 0 | |
| 20433 | + }; | |
| 20434 | + if angle_delta_uv != 0 { | |
| 20435 | + UV_ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1)); | |
| 20436 | + INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|c| c.set(c.get() + 1)); | |
| 20437 | + } | |
| 20438 | + // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED`. | |
| 20439 | + uv_predict_mode = if uv_mode == UV_CFL_PRED { | |
| 20440 | + DC_PRED | |
| 20441 | + } else { | |
| 20442 | + uv_mode | |
| 20443 | + }; | |
| 20444 | + // The CHROMA neighbour's own `uv_mode` decides the chroma edge filter | |
| 20445 | + // strength (`get_intra_edge_filter_type`, reconintra.c:974), never the | |
| 20446 | + // luma one -- same read [`decode_leaf8`] does. | |
| 20447 | + let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c); | |
| 20384 | 20448 | // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/ |
| 20385 | 20449 | // `uv_mode` are both effectively `DC_PRED`-gated already on this |
| 20386 | 20450 | // leaf (a nonzero `mode` still passes, but `uv_mode` is forced |
| @@ -20392,7 +20456,10 @@ fn decode_inter_block8( | ||
| 20392 | 20456 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 20393 | 20457 | )); |
| 20394 | 20458 | } |
| 20395 | - if dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { | |
| 20459 | + // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only | |
| 20460 | + // when `uv_mode == UV_DC_PRED` (decodemv.c) -- unconditional here | |
| 20461 | + // while every non-DC uv_mode was refused a few lines above. | |
| 20462 | + if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { | |
| 20396 | 20463 | return Err(unsupported( |
| 20397 | 20464 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 20398 | 20465 | )); |
| @@ -20473,31 +20540,34 @@ fn decode_inter_block8( | ||
| 20473 | 20540 | &vec![0i32; SIDE * SIDE], |
| 20474 | 20541 | None, |
| 20475 | 20542 | filter_intra, |
| 20476 | - false, | |
| 20543 | + smooth_neighbor, | |
| 20477 | 20544 | ); |
| 20545 | + // CfL's AC contribution is the luma this leaf just reconstructed, | |
| 20546 | + // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5). | |
| 20547 | + let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); | |
| 20478 | 20548 | u.reconstruct( |
| 20479 | 20549 | cpx, |
| 20480 | 20550 | cpy, |
| 20481 | 20551 | CHROMA_SIDE, |
| 20482 | - DC_PRED, | |
| 20483 | - 0, | |
| 20552 | + uv_predict_mode, | |
| 20553 | + angle_delta_uv, | |
| 20484 | 20554 | reach, |
| 20485 | 20555 | &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], |
| 20556 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | |
| 20486 | 20557 | None, |
| 20487 | - None, | |
| 20488 | - false, | |
| 20558 | + smooth_neighbor_uv, | |
| 20489 | 20559 | ); |
| 20490 | 20560 | v.reconstruct( |
| 20491 | 20561 | cpx, |
| 20492 | 20562 | cpy, |
| 20493 | 20563 | CHROMA_SIDE, |
| 20494 | - DC_PRED, | |
| 20495 | - 0, | |
| 20564 | + uv_predict_mode, | |
| 20565 | + angle_delta_uv, | |
| 20496 | 20566 | reach, |
| 20497 | 20567 | &vec![0i32; CHROMA_SIDE * CHROMA_SIDE], |
| 20568 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | |
| 20498 | 20569 | None, |
| 20499 | - None, | |
| 20500 | - false, | |
| 20570 | + smooth_neighbor_uv, | |
| 20501 | 20571 | ); |
| 20502 | 20572 | luma_grid = vec![0i32; SIDE * SIDE]; |
| 20503 | 20573 | u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| @@ -20524,8 +20594,9 @@ fn decode_inter_block8( | ||
| 20524 | 20594 | None, |
| 20525 | 20595 | filter_intra, |
| 20526 | 20596 | None, |
| 20527 | - false, | |
| 20597 | + smooth_neighbor, | |
| 20528 | 20598 | )?; |
| 20599 | + let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); | |
| 20529 | 20600 | u_grid = read_plane( |
| 20530 | 20601 | dec, |
| 20531 | 20602 | cdfs, |
| @@ -20534,8 +20605,8 @@ fn decode_inter_block8( | ||
| 20534 | 20605 | 1, |
| 20535 | 20606 | around[1], |
| 20536 | 20607 | mode, |
| 20537 | - DC_PRED, | |
| 20538 | - 0, | |
| 20608 | + uv_predict_mode, | |
| 20609 | + angle_delta_uv, | |
| 20539 | 20610 | reach, |
| 20540 | 20611 | u, |
| 20541 | 20612 | cpx, |
| @@ -20543,10 +20614,10 @@ fn decode_inter_block8( | ||
| 20543 | 20614 | CHROMA_SIDE, |
| 20544 | 20615 | TX4, |
| 20545 | 20616 | base_q_idx, |
| 20617 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | |
| 20546 | 20618 | None, |
| 20547 | 20619 | None, |
| 20548 | - None, | |
| 20549 | - false, | |
| 20620 | + smooth_neighbor_uv, | |
| 20550 | 20621 | )?; |
| 20551 | 20622 | v_grid = read_plane( |
| 20552 | 20623 | dec, |
| @@ -20556,8 +20627,8 @@ fn decode_inter_block8( | ||
| 20556 | 20627 | 2, |
| 20557 | 20628 | around[2], |
| 20558 | 20629 | mode, |
| 20559 | - DC_PRED, | |
| 20560 | - 0, | |
| 20630 | + uv_predict_mode, | |
| 20631 | + angle_delta_uv, | |
| 20561 | 20632 | reach, |
| 20562 | 20633 | v, |
| 20563 | 20634 | cpx, |
| @@ -20565,10 +20636,10 @@ fn decode_inter_block8( | ||
| 20565 | 20636 | CHROMA_SIDE, |
| 20566 | 20637 | TX4, |
| 20567 | 20638 | base_q_idx, |
| 20639 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | |
| 20568 | 20640 | None, |
| 20569 | 20641 | None, |
| 20570 | - None, | |
| 20571 | - false, | |
| 20642 | + smooth_neighbor_uv, | |
| 20572 | 20643 | )?; |
| 20573 | 20644 | } |
| 20574 | 20645 | } |
| @@ -20590,6 +20661,16 @@ fn decode_inter_block8( | ||
| 20590 | 20661 | ) |
| 20591 | 20662 | }); |
| 20592 | 20663 | neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); |
| 20664 | + // lane-uv8 r1: this leaf never stamped a mode band at all, so the block | |
| 20665 | + // below/right of it read whatever block last wrote the coarse [`SUB`] | |
| 20666 | + // slot -- now that an intra leaf here can code a smooth/directional | |
| 20667 | + // `uv_mode`, its chroma neighbours must see it (and an inter leaf must | |
| 20668 | + // stamp `DC_PRED`, what libaom stores for a non-intra block). Same pair | |
| 20669 | + // [`decode_leaf8`] writes, plus the coarse fallback slots. | |
| 20670 | + neighbours.above_uv_mode[c] = uv_predict_mode; | |
| 20671 | + neighbours.left_uv_mode[r] = uv_predict_mode; | |
| 20672 | + neighbours.record_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, mode_for_tx); | |
| 20673 | + neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode); | |
| 20593 | 20674 | if let Some((left, above)) = saved_luma_ctx { |
| 20594 | 20675 | for (cell, state) in left.into_iter().enumerate() { |
| 20595 | 20676 | neighbours.left[leaf_mi.0 + cell][0] = state; |
crates/ec-av1/src/refusal_inventory.rsmodified+0 -1
| @@ -25,7 +25,6 @@ | ||
| 25 | 25 | #[cfg(test)] |
| 26 | 26 | const CAPABILITY_CLAIMS: &[&str] = &[ |
| 27 | 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 | 30 | #[cfg(test)] |
crates/ec-av1/src/stream.rsmodified+273 -0
| @@ -5685,6 +5685,279 @@ mod tests { | ||
| 5685 | 5685 | ); |
| 5686 | 5686 | } |
| 5687 | 5687 | |
| 5688 | + /// lane-uv8 r1 (classes [[refusal-strings-are-claims]] + | |
| 5689 | + /// [[tool-disabled-in-every-gate]]): a real aomenc inter sequence with | |
| 5690 | + /// 8x8 partitions and full chroma intra tooling | |
| 5691 | + /// (`--enable-cfl-intra=1 --enable-smooth-intra=1 --enable-paeth-intra=1 | |
| 5692 | + /// --enable-directional-intra=1`), in which the RD gives an INTRA 8x8 | |
| 5693 | + /// leaf inside an inter frame a NON-DC `uv_mode`. That leaf | |
| 5694 | + /// ([`decode::decode_inter_block8`]'s intra arm) read the `uv_mode` | |
| 5695 | + /// symbol and refused every value but `DC_PRED` -- "this encoder never | |
| 5696 | + /// writes one" was a claim, and this gate is what contradicts it. Hard- | |
| 5697 | + /// asserts `decode::intra_in_inter8_uv_hits` (directional, smooth/paeth, | |
| 5698 | + /// CfL, counted on THIS leaf only); an attempt that never produced one | |
| 5699 | + /// proves nothing, and exhausting every attempt is a FAILURE, not a SKIP. | |
| 5700 | + #[test] | |
| 5701 | + fn a_real_aomenc_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() { | |
| 5702 | + uv_mode_in_inter8_gate(8, 1); | |
| 5703 | + } | |
| 5704 | + | |
| 5705 | + /// The 10-bit arm (both of the user's films are `yuv420p10le`). | |
| 5706 | + #[test] | |
| 5707 | + fn a_real_aomenc_10bit_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() { | |
| 5708 | + uv_mode_in_inter8_gate(10, 1); | |
| 5709 | + } | |
| 5710 | + | |
| 5711 | + /// The multi-tile arm (class [[new-map-ignores-tile-edge]]): this round | |
| 5712 | + /// stamps a new `uv_mode` band from the 8x8 leaf, whose availability must | |
| 5713 | + /// be tile-relative. | |
| 5714 | + #[test] | |
| 5715 | + fn a_real_aomenc_two_tile_inter_sequence_with_a_non_dc_chroma_8x8_intra_leaf_decodes_pixel_exact() | |
| 5716 | + { | |
| 5717 | + uv_mode_in_inter8_gate(8, 2); | |
| 5718 | + } | |
| 5719 | + | |
| 5720 | + fn uv_mode_in_inter8_gate(bit_depth: u32, tile_columns: u32) { | |
| 5721 | + let name = format!("uv_mode_in_inter8_gate({bit_depth}, tiles={tile_columns})"); | |
| 5722 | + if !have_ffmpeg() { | |
| 5723 | + eprintln!("SKIP {name}: no ffmpeg"); | |
| 5724 | + return; | |
| 5725 | + } | |
| 5726 | + if !have_aomenc() { | |
| 5727 | + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | |
| 5728 | + return; | |
| 5729 | + } | |
| 5730 | + let (width, height, frame_count) = (192usize, 128usize, 8usize); | |
| 5731 | + let mut refusals = Vec::new(); | |
| 5732 | + let mut uncounted_exact = 0u32; | |
| 5733 | + let mut totals = (0usize, 0usize, 0usize); | |
| 5734 | + for attempt in 0..30u32 { | |
| 5735 | + let seed = 42 + attempt; | |
| 5736 | + // A zooming fractal with a hard CUT at frame 4 (`overlay` | |
| 5737 | + // switching a second, unrelated fractal on): after the cut a block | |
| 5738 | + // is unpredictable from the reference, which is what makes aomenc | |
| 5739 | + // code INTRA blocks inside an inter frame. Chroma is NOT | |
| 5740 | + // desaturated here (every sibling inter gate passes `hue=s=0`) -- | |
| 5741 | + // real chroma detail is exactly what pushes the chroma RD off | |
| 5742 | + // DC_PRED. `noise` carries its own explicit seed (lavfi | |
| 5743 | + // `gradients` ignores its seed; class [[seeded-fixture-not-reproducible]]). | |
| 5744 | + let source = format!( | |
| 5745 | + "mandelbrot=size={width}x{height}:start_scale={}:rate=25[a];\ | |
| 5746 | + mandelbrot=size={width}x{height}:start_scale={}:rate=25[b];\ | |
| 5747 | + [a][b]overlay=enable='gte(n,4)',noise=alls=12:allf=t+u:all_seed={seed}", | |
| 5748 | + 5.0 - f64::from(attempt) * 0.06, | |
| 5749 | + 0.9 + f64::from(attempt) * 0.11 | |
| 5750 | + ); | |
| 5751 | + let y4m = Command::new("ffmpeg") | |
| 5752 | + .args([ | |
| 5753 | + "-v", | |
| 5754 | + "error", | |
| 5755 | + "-f", | |
| 5756 | + "lavfi", | |
| 5757 | + "-i", | |
| 5758 | + &source, | |
| 5759 | + "-pix_fmt", | |
| 5760 | + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, | |
| 5761 | + "-strict", | |
| 5762 | + "-1", | |
| 5763 | + "-t", | |
| 5764 | + "0.32", | |
| 5765 | + "-f", | |
| 5766 | + "yuv4mpegpipe", | |
| 5767 | + "-strict", | |
| 5768 | + "-1", | |
| 5769 | + "-", | |
| 5770 | + ]) | |
| 5771 | + .stdin(Stdio::null()) | |
| 5772 | + .stdout(Stdio::piped()) | |
| 5773 | + .stderr(Stdio::piped()) | |
| 5774 | + .output() | |
| 5775 | + .expect("ffmpeg failed to run"); | |
| 5776 | + assert!( | |
| 5777 | + y4m.status.success(), | |
| 5778 | + "ffmpeg fixture: {}", | |
| 5779 | + String::from_utf8_lossy(&y4m.stderr) | |
| 5780 | + ); | |
| 5781 | + // A coarser quantiser is what pushes the chroma RD to a cheap | |
| 5782 | + // non-DC mode on a small block; sweep 12..40 (the low end is what | |
| 5783 | + // lane-cdef's cq12 arm needs). | |
| 5784 | + let cq = format!("--cq-level={}", 12 + (attempt % 5) * 7); | |
| 5785 | + let depth_args: &[&str] = if bit_depth == 10 { | |
| 5786 | + &["-b", "10", "--input-bit-depth=10"] | |
| 5787 | + } else { | |
| 5788 | + &[] | |
| 5789 | + }; | |
| 5790 | + let tiles = format!("--tile-columns={}", tile_columns - 1); | |
| 5791 | + // The y4m goes through a FILE, not aomenc's stdin: this gate's | |
| 5792 | + // stream is ~100 KB, bigger than a pipe buffer, so an aomenc that | |
| 5793 | + // is still being fed on stdin blocks writing its stdout and the | |
| 5794 | + // test blocks writing its stdin -- a hard deadlock (measured | |
| 5795 | + // here, 3 min into attempt 0, class [[gate-loader-slurps-whole-file]]). | |
| 5796 | + // The path is PID-keyed (class [[pid-keyed-temp-path]]). | |
| 5797 | + let y4m_path = std::env::temp_dir().join(format!( | |
| 5798 | + "ec-av1-uv8-{}-{bit_depth}-{tile_columns}-{seed}.y4m", | |
| 5799 | + std::process::id() | |
| 5800 | + )); | |
| 5801 | + std::fs::write(&y4m_path, &y4m.stdout).expect("writing the y4m fixture"); | |
| 5802 | + let child = Command::new(aomenc_path()) | |
| 5803 | + .args(depth_args) | |
| 5804 | + .args([ | |
| 5805 | + "--codec=av1", | |
| 5806 | + "--passes=1", | |
| 5807 | + "--end-usage=q", | |
| 5808 | + &cq, | |
| 5809 | + "--cpu-used=0", | |
| 5810 | + "--lag-in-frames=0", | |
| 5811 | + "--auto-alt-ref=0", | |
| 5812 | + "--kf-max-dist=9999", | |
| 5813 | + "--kf-min-dist=9999", | |
| 5814 | + "--threads=1", | |
| 5815 | + "--row-mt=0", | |
| 5816 | + &tiles, | |
| 5817 | + "--enable-order-hint=0", | |
| 5818 | + "--enable-warped-motion=0", | |
| 5819 | + "--enable-obmc=0", | |
| 5820 | + "--enable-masked-comp=0", | |
| 5821 | + "--enable-interintra-comp=0", | |
| 5822 | + "--enable-dist-wtd-comp=0", | |
| 5823 | + "--enable-diff-wtd-comp=0", | |
| 5824 | + "--enable-onesided-comp=0", | |
| 5825 | + "--enable-interintra-wedge=0", | |
| 5826 | + "--enable-smooth-interintra=0", | |
| 5827 | + "--enable-ab-partitions=0", | |
| 5828 | + "--enable-1to4-partitions=0", | |
| 5829 | + "--enable-cdef=0", | |
| 5830 | + "--enable-restoration=0", | |
| 5831 | + "--enable-palette=0", | |
| 5832 | + "--enable-intrabc=0", | |
| 5833 | + "--enable-ref-frame-mvs=0", | |
| 5834 | + // Per-arm overrides go LAST (aomenc keeps the LAST | |
| 5835 | + // occurrence of a repeated --enable-* flag). The three | |
| 5836 | + // chroma intra tools this gate is about, plus the fences | |
| 5837 | + // that keep the leaf's SIBLING refusals (its TX_4X4 | |
| 5838 | + // split, a nonzero angle delta, sub-16 rect inter leaves) | |
| 5839 | + // out of the way. | |
| 5840 | + "--enable-cfl-intra=1", | |
| 5841 | + "--enable-smooth-intra=1", | |
| 5842 | + "--enable-paeth-intra=1", | |
| 5843 | + "--enable-directional-intra=1", | |
| 5844 | + "--enable-angle-delta=0", | |
| 5845 | + "--enable-tx-size-search=0", | |
| 5846 | + "--enable-rect-partitions=0", | |
| 5847 | + "--min-partition-size=8", | |
| 5848 | + "--max-partition-size=32", | |
| 5849 | + "--obu", | |
| 5850 | + "-o", | |
| 5851 | + "-", | |
| 5852 | + ]) | |
| 5853 | + .arg(&y4m_path) | |
| 5854 | + .stdin(Stdio::null()) | |
| 5855 | + .stdout(Stdio::piped()) | |
| 5856 | + .stderr(Stdio::piped()) | |
| 5857 | + .spawn() | |
| 5858 | + .expect("aomenc failed to start"); | |
| 5859 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 5860 | + let _ = std::fs::remove_file(&y4m_path); | |
| 5861 | + assert!( | |
| 5862 | + out.status.success(), | |
| 5863 | + "aomenc refused the fixture: {}", | |
| 5864 | + String::from_utf8_lossy(&out.stderr) | |
| 5865 | + ); | |
| 5866 | + let stream = out.stdout; | |
| 5867 | + let before = decode::intra_in_inter8_uv_hits(); | |
| 5868 | + let frames = match decode_stream(&stream) { | |
| 5869 | + Ok(frames) => frames, | |
| 5870 | + Err(e) => { | |
| 5871 | + let msg = e.to_string(); | |
| 5872 | + assert!( | |
| 5873 | + msg.contains("unsupported"), | |
| 5874 | + "{name} decode failed outright (seed {seed}): {msg}" | |
| 5875 | + ); | |
| 5876 | + refusals.push(format!("seed {seed}: {msg}")); | |
| 5877 | + continue; | |
| 5878 | + } | |
| 5879 | + }; | |
| 5880 | + let now = decode::intra_in_inter8_uv_hits(); | |
| 5881 | + // class [[counter-from-refused-stream]]: per-attempt deltas, and | |
| 5882 | + // only for an attempt that decoded to the end and is pixel- | |
| 5883 | + // compared below. | |
| 5884 | + let fired = (now.0 - before.0, now.1 - before.1, now.2 - before.2); | |
| 5885 | + totals = ( | |
| 5886 | + totals.0 + fired.0, | |
| 5887 | + totals.1 + fired.1, | |
| 5888 | + totals.2 + fired.2, | |
| 5889 | + ); | |
| 5890 | + // class [[gate-skips-on-its-own-failure]]: a decode that succeeded | |
| 5891 | + // is ALWAYS pixel-compared; the counter only decides whether the | |
| 5892 | + // attempt counts as firing. | |
| 5893 | + let counted = fired.0 + fired.1 + fired.2 != 0; | |
| 5894 | + if !counted { | |
| 5895 | + uncounted_exact += 1; | |
| 5896 | + refusals.push(format!( | |
| 5897 | + "seed {seed}: decoded and pixel-compared, but no 8x8 intra leaf in an inter \ | |
| 5898 | + frame carried a non-DC uv_mode" | |
| 5899 | + )); | |
| 5900 | + } | |
| 5901 | + let ffmpeg_frames = if bit_depth == 10 { | |
| 5902 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | |
| 5903 | + } else { | |
| 5904 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | |
| 5905 | + }; | |
| 5906 | + assert_eq!(frames.len(), frame_count); | |
| 5907 | + eprintln!( | |
| 5908 | + "{name} seed={seed} {cq}: 8x8 intra-in-inter leaves with a non-DC uv_mode -- \ | |
| 5909 | + directional {}, smooth/paeth {}, CfL {}", | |
| 5910 | + fired.0, fired.1, fired.2 | |
| 5911 | + ); | |
| 5912 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 5913 | + for (plane, (g, w)) in [ | |
| 5914 | + ("Y", (&got.y, &want.y)), | |
| 5915 | + ("U", (&got.u, &want.u)), | |
| 5916 | + ("V", (&got.v, &want.v)), | |
| 5917 | + ] { | |
| 5918 | + let stride = if plane == "Y" { width } else { width / 2 }; | |
| 5919 | + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | |
| 5920 | + eprintln!( | |
| 5921 | + "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | |
| 5922 | + want {} ({} samples differ)", | |
| 5923 | + at % stride, | |
| 5924 | + at / stride, | |
| 5925 | + g[at], | |
| 5926 | + w[at], | |
| 5927 | + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | |
| 5928 | + ); | |
| 5929 | + } | |
| 5930 | + } | |
| 5931 | + } | |
| 5932 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 5933 | + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | |
| 5934 | + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | |
| 5935 | + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | |
| 5936 | + } | |
| 5937 | + if counted { | |
| 5938 | + gate_buckets( | |
| 5939 | + &name, | |
| 5940 | + 1, | |
| 5941 | + uncounted_exact, | |
| 5942 | + refusals.len() - uncounted_exact as usize, | |
| 5943 | + ); | |
| 5944 | + return; | |
| 5945 | + } | |
| 5946 | + } | |
| 5947 | + gate_buckets( | |
| 5948 | + &name, | |
| 5949 | + 0, | |
| 5950 | + uncounted_exact, | |
| 5951 | + refusals.len() - uncounted_exact as usize, | |
| 5952 | + ); | |
| 5953 | + panic!( | |
| 5954 | + "{name} never observed a non-DC uv_mode on an 8x8 intra leaf in an inter frame \ | |
| 5955 | + (totals dir/smooth/cfl {totals:?}):\n{}", | |
| 5956 | + refusals.join("\n") | |
| 5957 | + ); | |
| 5958 | + } | |
| 5959 | + | |
| 5960 | + | |
| 5688 | 5961 | /// lane-chroma r2 stage 1: a real aomenc key frame with |
| 5689 | 5962 | /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) |
| 5690 | 5963 | /// 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]`. |