An intra block inside an inter frame never read use_filter_intra -- silent desync on every aomenc-default stream
Browse files at this commitc98870cb9b7f22a9bca3a5888c0e4d482bdc4a2cParent: 3bbde5d- fix
- an intra block inside an inter frame never read use_filter_intra -- silent desync on every aomenc-default stream
3 changed files +426 -9
- crates/ec-av1/src/decode.rs +79 -9
- crates/ec-av1/src/stream.rs +252 -0
- lanes/fiinter-r1.report.md +95 -0
crates/ec-av1/src/decode.rsmodified+79 -9
| @@ -71,6 +71,20 @@ pub(crate) fn filter_intra_hits() -> usize { | ||
| 71 | 71 | FILTER_INTRA_HITS.with(|c| c.get()) |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | +// lane-fiinter r1: how many of those `use_filter_intra == 1` symbols belonged | |
| 75 | +// to an INTRA block inside an INTER frame (`read_intra_block_mode_info`'s own | |
| 76 | +// `read_filter_intra_mode_info` call), which no gate exercised before this | |
| 77 | +// round -- every inter gate recipe passed `--enable-filter-intra=0`. | |
| 78 | +thread_local! { | |
| 79 | + static INTRA_IN_INTER_FILTER_INTRA_HITS: std::cell::Cell<usize> = | |
| 80 | + const { std::cell::Cell::new(0) }; | |
| 81 | +} | |
| 82 | + | |
| 83 | +/// Current value of [`INTRA_IN_INTER_FILTER_INTRA_HITS`]. | |
| 84 | +pub(crate) fn intra_in_inter_filter_intra_hits() -> usize { | |
| 85 | + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.get()) | |
| 86 | +} | |
| 87 | + | |
| 74 | 88 | // lane-realworld r1: this frame's `cdef.bits` (spec 5.9.19), threaded into |
| 75 | 89 | // [`maybe_read_cdef_idx`] the same way [`ENABLE_EDGE_FILTER`] threads a |
| 76 | 90 | // frame-level flag through the recursive block decode -- `0` (the default) |
| @@ -825,6 +839,11 @@ thread_local! { | ||
| 825 | 839 | // frame-constant. |
| 826 | 840 | static TX_SELECT_INTER: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; |
| 827 | 841 | static REDUCED_TX_SET_INTER: std::cell::Cell<bool> = const { std::cell::Cell::new(true) }; |
| 842 | + // lane-fiinter r1: this sequence header's own `enable_filter_intra` bit, | |
| 843 | + // frame-constant like the two above and stashed the same way -- an intra | |
| 844 | + // block inside an inter frame reads `use_filter_intra` under it. | |
| 845 | + static ENABLE_FILTER_INTRA_INTER: std::cell::Cell<bool> = | |
| 846 | + const { std::cell::Cell::new(false) }; | |
| 828 | 847 | } |
| 829 | 848 | |
| 830 | 849 | /// Current value of [`TXFM_SPLIT_READS`]. |
| @@ -837,10 +856,16 @@ pub(crate) fn txfm_split_hits() -> usize { | ||
| 837 | 856 | TXFM_SPLIT_HITS.with(|c| c.get()) |
| 838 | 857 | } |
| 839 | 858 | |
| 840 | -/// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]. | |
| 841 | -pub(crate) fn set_inter_tx_mode(tx_select: bool, reduced_tx_set: bool) { | |
| 859 | +/// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`]/ | |
| 860 | +/// [`ENABLE_FILTER_INTRA_INTER`]. | |
| 861 | +pub(crate) fn set_inter_tx_mode( | |
| 862 | + tx_select: bool, | |
| 863 | + reduced_tx_set: bool, | |
| 864 | + enable_filter_intra: bool, | |
| 865 | +) { | |
| 842 | 866 | TX_SELECT_INTER.with(|c| c.set(tx_select)); |
| 843 | 867 | REDUCED_TX_SET_INTER.with(|c| c.set(reduced_tx_set)); |
| 868 | + ENABLE_FILTER_INTRA_INTER.with(|c| c.set(enable_filter_intra)); | |
| 844 | 869 | } |
| 845 | 870 | |
| 846 | 871 | // How many `partition_w16` reads (a 16x16 block's own partition symbol, key |
| @@ -15547,6 +15572,24 @@ fn decode_inter_block( | ||
| 15547 | 15572 | )); |
| 15548 | 15573 | } |
| 15549 | 15574 | } |
| 15575 | + // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`, | |
| 15576 | + // the tail of `read_intra_block_mode_info`) -- an intra block inside | |
| 15577 | + // an INTER frame reads `use_filter_intra` in exactly the same place a | |
| 15578 | + // key-frame block does, right after the palette syntax. Nothing read | |
| 15579 | + // it here before this round, and aomenc enables filter intra by | |
| 15580 | + // default, so every inter frame carrying one desynced at this symbol. | |
| 15581 | + // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied: | |
| 15582 | + // a real palette-Y block already returned above. | |
| 15583 | + let mut filter_intra = None; | |
| 15584 | + if mode == DC_PRED | |
| 15585 | + && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) | |
| 15586 | + && let Some(class) = filter_intra_size_class(side) | |
| 15587 | + && dec.symbol(&mut cdfs.filter_intra[class]) != 0 | |
| 15588 | + { | |
| 15589 | + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | |
| 15590 | + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | |
| 15591 | + filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); | |
| 15592 | + } | |
| 15550 | 15593 | mode_for_tx = mode; |
| 15551 | 15594 | block_filter = [3, 3]; |
| 15552 | 15595 | ref_frame_for_lf = 0; |
| @@ -15613,7 +15656,7 @@ fn decode_inter_block( | ||
| 15613 | 15656 | tu_reach, |
| 15614 | 15657 | &vec![0i32; tx_px * tx_px], |
| 15615 | 15658 | None, |
| 15616 | - None, | |
| 15659 | + filter_intra, | |
| 15617 | 15660 | false, |
| 15618 | 15661 | ); |
| 15619 | 15662 | vec![0i32; tx_px * tx_px] |
| @@ -15640,7 +15683,7 @@ fn decode_inter_block( | ||
| 15640 | 15683 | tx_px, |
| 15641 | 15684 | base_q_idx, |
| 15642 | 15685 | None, |
| 15643 | - None, | |
| 15686 | + filter_intra, | |
| 15644 | 15687 | Some(tu_skip_ctx), |
| 15645 | 15688 | false, |
| 15646 | 15689 | )? |
| @@ -15659,7 +15702,7 @@ fn decode_inter_block( | ||
| 15659 | 15702 | reach, |
| 15660 | 15703 | &vec![0i32; side * side], |
| 15661 | 15704 | None, |
| 15662 | - None, | |
| 15705 | + filter_intra, | |
| 15663 | 15706 | false, |
| 15664 | 15707 | ); |
| 15665 | 15708 | } |
| @@ -15717,7 +15760,7 @@ fn decode_inter_block( | ||
| 15717 | 15760 | luma_tx, |
| 15718 | 15761 | base_q_idx, |
| 15719 | 15762 | None, |
| 15720 | - None, | |
| 15763 | + filter_intra, | |
| 15721 | 15764 | None, |
| 15722 | 15765 | false, |
| 15723 | 15766 | )? |
| @@ -17139,6 +17182,24 @@ fn decode_inter_block8( | ||
| 17139 | 17182 | )); |
| 17140 | 17183 | } |
| 17141 | 17184 | } |
| 17185 | + // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`, | |
| 17186 | + // the tail of `read_intra_block_mode_info`) -- an intra block inside | |
| 17187 | + // an INTER frame reads `use_filter_intra` in exactly the same place a | |
| 17188 | + // key-frame block does, right after the palette syntax. Nothing read | |
| 17189 | + // it here before this round, and aomenc enables filter intra by | |
| 17190 | + // default, so every inter frame carrying one desynced at this symbol. | |
| 17191 | + // `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied: | |
| 17192 | + // a real palette-Y block already returned above. | |
| 17193 | + let mut filter_intra = None; | |
| 17194 | + if mode == DC_PRED | |
| 17195 | + && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) | |
| 17196 | + && let Some(class) = filter_intra_size_class(SIDE) | |
| 17197 | + && dec.symbol(&mut cdfs.filter_intra[class]) != 0 | |
| 17198 | + { | |
| 17199 | + FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | |
| 17200 | + INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | |
| 17201 | + filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); | |
| 17202 | + } | |
| 17142 | 17203 | mode_for_tx = mode; |
| 17143 | 17204 | let (mi_row, mi_col) = leaf_mi; |
| 17144 | 17205 | for dr in 0..2 { |
| @@ -17195,7 +17256,7 @@ fn decode_inter_block8( | ||
| 17195 | 17256 | reach, |
| 17196 | 17257 | &vec![0i32; SIDE * SIDE], |
| 17197 | 17258 | None, |
| 17198 | - None, | |
| 17259 | + filter_intra, | |
| 17199 | 17260 | false, |
| 17200 | 17261 | ); |
| 17201 | 17262 | u.reconstruct( |
| @@ -17245,7 +17306,7 @@ fn decode_inter_block8( | ||
| 17245 | 17306 | TX8, |
| 17246 | 17307 | base_q_idx, |
| 17247 | 17308 | None, |
| 17248 | - None, | |
| 17309 | + filter_intra, | |
| 17249 | 17310 | None, |
| 17250 | 17311 | false, |
| 17251 | 17312 | )?; |
| @@ -17414,6 +17475,10 @@ pub fn decode_inter_frame_tile( | ||
| 17414 | 17475 | false, |
| 17415 | 17476 | false, |
| 17416 | 17477 | DeltaParams::default(), |
| 17478 | + // `enable_filter_intra`: this crate's own encoder never writes the | |
| 17479 | + // sequence bit (`encode.rs`), so no intra-in-inter block of a stream | |
| 17480 | + // reaching this entry point reads a `use_filter_intra` symbol. | |
| 17481 | + false, | |
| 17417 | 17482 | ) |
| 17418 | 17483 | .map(|(picture, _, _)| picture) |
| 17419 | 17484 | } |
| @@ -17497,8 +17562,13 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 17497 | 17562 | // same contract as [`decode_key_frame_tile_with_cdfs`]'s own `delta` |
| 17498 | 17563 | // param -- only `q_present`/`q_res` are read. |
| 17499 | 17564 | delta: DeltaParams, |
| 17565 | + // lane-fiinter r1: this sequence header's own `enable_filter_intra` bit | |
| 17566 | + // (spec 5.5.2), stashed in a thread-local with `tx_select` rather than | |
| 17567 | + // threaded through `decode_inter_block`'s fifty parameters -- read by the | |
| 17568 | + // intra-in-inter arms' `read_filter_intra_mode_info`. | |
| 17569 | + enable_filter_intra: bool, | |
| 17500 | 17570 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { |
| 17501 | - set_inter_tx_mode(tx_select, reduced_tx_set); | |
| 17571 | + set_inter_tx_mode(tx_select, reduced_tx_set, enable_filter_intra); | |
| 17502 | 17572 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { |
| 17503 | 17573 | field, |
| 17504 | 17574 | order_hint_bits, |
crates/ec-av1/src/stream.rsmodified+252 -0
| @@ -691,6 +691,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 691 | 691 | header.allow_warped_motion, |
| 692 | 692 | header.allow_screen_content_tools, |
| 693 | 693 | header.delta, |
| 694 | + enable_filter_intra, | |
| 694 | 695 | )?; |
| 695 | 696 | // lane-superres r10: mirrors the key-frame branch above -- |
| 696 | 697 | // `decode_inter_frame_tile_with_cdfs` decodes at the downscaled |
| @@ -4434,6 +4435,257 @@ mod tests { | ||
| 4434 | 4435 | ); |
| 4435 | 4436 | } |
| 4436 | 4437 | |
| 4438 | + /// lane-fiinter r1 (class [[symbol-consumption-gap]] + | |
| 4439 | + /// [[tool-disabled-in-every-gate]]): a real aomenc inter sequence with | |
| 4440 | + /// `--enable-filter-intra=1` (aomenc's own default -- every inter gate | |
| 4441 | + /// recipe before this one pinned it OFF, so nothing ever exercised it) in | |
| 4442 | + /// which the RD picks an INTRA block inside an inter frame and gives it | |
| 4443 | + /// filter intra. `read_intra_block_mode_info` reads `use_filter_intra` | |
| 4444 | + /// there exactly as a key frame does; this decoder read no such symbol at | |
| 4445 | + /// all until this round, so such a stream desynced at that symbol and | |
| 4446 | + /// decoded silently wrong. Hard-asserts | |
| 4447 | + /// [`decode::intra_in_inter_filter_intra_hits`]: an attempt that never | |
| 4448 | + /// produced one proves nothing, and exhausting every attempt is a | |
| 4449 | + /// FAILURE, not a SKIP. | |
| 4450 | + #[test] | |
| 4451 | + fn a_real_aomenc_inter_sequence_with_filter_intra_on_an_intra_block_decodes_pixel_exact() { | |
| 4452 | + filter_intra_in_inter_gate(8); | |
| 4453 | + } | |
| 4454 | + | |
| 4455 | + /// The 10-bit arm (both of the user's films are `yuv420p10le`). | |
| 4456 | + #[test] | |
| 4457 | + fn a_real_aomenc_10bit_inter_sequence_with_filter_intra_on_an_intra_block_decodes_pixel_exact() | |
| 4458 | + { | |
| 4459 | + filter_intra_in_inter_gate(10); | |
| 4460 | + } | |
| 4461 | + | |
| 4462 | + fn filter_intra_in_inter_gate(bit_depth: u32) { | |
| 4463 | + let name = format!("filter_intra_in_inter_gate({bit_depth})"); | |
| 4464 | + if !have_ffmpeg() { | |
| 4465 | + eprintln!("SKIP {name}: no ffmpeg"); | |
| 4466 | + return; | |
| 4467 | + } | |
| 4468 | + if !have_aomenc() { | |
| 4469 | + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); | |
| 4470 | + return; | |
| 4471 | + } | |
| 4472 | + let (width, height, frame_count) = (64usize, 64usize, 8usize); | |
| 4473 | + let mut refusals = Vec::new(); | |
| 4474 | + let mut uncounted_exact = 0u32; | |
| 4475 | + for attempt in 0..40u32 { | |
| 4476 | + let seed = 42 + attempt; | |
| 4477 | + // A zooming fractal: every frame moves (so the sequence is | |
| 4478 | + // genuinely inter-coded) and keeps sharp new detail entering at | |
| 4479 | + // the borders, which is what makes aomenc's RD choose an INTRA | |
| 4480 | + // block inside an inter frame -- and then split its transform. | |
| 4481 | + // A zooming fractal with a hard CUT halfway (`overlay` switching | |
| 4482 | + // a second, unrelated fractal on at frame 4): after the cut every | |
| 4483 | + // block is unpredictable from the reference, which is what makes | |
| 4484 | + // aomenc code INTRA blocks inside an inter frame -- and at this | |
| 4485 | + // cq the RD then splits their transforms. | |
| 4486 | + let source = format!( | |
| 4487 | + "mandelbrot=size=64x64:start_scale={}:rate=25[a];\ | |
| 4488 | + mandelbrot=size=64x64:start_scale={}:rate=25[b];\ | |
| 4489 | + [a][b]overlay=enable='gte(n,4)'", | |
| 4490 | + 5.0 - f64::from(attempt) * 0.06, | |
| 4491 | + 0.9 + f64::from(attempt) * 0.11 | |
| 4492 | + ); | |
| 4493 | + let y4m = Command::new("ffmpeg") | |
| 4494 | + .args([ | |
| 4495 | + "-v", | |
| 4496 | + "error", | |
| 4497 | + "-f", | |
| 4498 | + "lavfi", | |
| 4499 | + "-i", | |
| 4500 | + &source, | |
| 4501 | + // Desaturated chroma keeps `uv_mode` on DC_PRED, so the | |
| 4502 | + // still-refused directional-chroma gaps never fire and | |
| 4503 | + // luma detail alone drives the transform split. | |
| 4504 | + "-vf", | |
| 4505 | + "hue=s=0", | |
| 4506 | + "-pix_fmt", | |
| 4507 | + if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }, | |
| 4508 | + "-strict", | |
| 4509 | + "-1", | |
| 4510 | + "-t", | |
| 4511 | + "0.32", | |
| 4512 | + "-f", | |
| 4513 | + "yuv4mpegpipe", | |
| 4514 | + "-strict", | |
| 4515 | + "-1", | |
| 4516 | + "-", | |
| 4517 | + ]) | |
| 4518 | + .stdin(Stdio::null()) | |
| 4519 | + .stdout(Stdio::piped()) | |
| 4520 | + .stderr(Stdio::piped()) | |
| 4521 | + .output() | |
| 4522 | + .expect("ffmpeg failed to run"); | |
| 4523 | + assert!( | |
| 4524 | + y4m.status.success(), | |
| 4525 | + "ffmpeg fixture: {}", | |
| 4526 | + String::from_utf8_lossy(&y4m.stderr) | |
| 4527 | + ); | |
| 4528 | + let depth_args: &[&str] = if bit_depth == 10 { | |
| 4529 | + &["-b", "10", "--input-bit-depth=10"] | |
| 4530 | + } else { | |
| 4531 | + &[] | |
| 4532 | + }; | |
| 4533 | + let mut child = Command::new(aomenc_path()) | |
| 4534 | + .args(depth_args) | |
| 4535 | + .args([ | |
| 4536 | + "--codec=av1", | |
| 4537 | + "--passes=1", | |
| 4538 | + "--end-usage=q", | |
| 4539 | + "--cq-level=30", | |
| 4540 | + "--cpu-used=0", | |
| 4541 | + "--lag-in-frames=0", | |
| 4542 | + "--auto-alt-ref=0", | |
| 4543 | + // One key frame only: every later frame is an inter frame, | |
| 4544 | + // which is where this gate's intra blocks must sit. The | |
| 4545 | + // MIN distance is what stops aomenc's scene-cut detector | |
| 4546 | + // from inserting a second key frame at the cut this gate's | |
| 4547 | + // source deliberately contains. | |
| 4548 | + "--kf-max-dist=1000", | |
| 4549 | + "--kf-min-dist=1000", | |
| 4550 | + "--threads=1", | |
| 4551 | + "--row-mt=0", | |
| 4552 | + "--enable-order-hint=0", | |
| 4553 | + "--enable-warped-motion=0", | |
| 4554 | + "--enable-obmc=0", | |
| 4555 | + "--enable-masked-comp=0", | |
| 4556 | + "--enable-interintra-comp=0", | |
| 4557 | + "--enable-dist-wtd-comp=0", | |
| 4558 | + "--enable-diff-wtd-comp=0", | |
| 4559 | + "--enable-onesided-comp=0", | |
| 4560 | + "--enable-interintra-wedge=0", | |
| 4561 | + "--enable-smooth-interintra=0", | |
| 4562 | + "--enable-ab-partitions=0", | |
| 4563 | + "--enable-1to4-partitions=0", | |
| 4564 | + "--enable-smooth-intra=0", | |
| 4565 | + "--enable-paeth-intra=0", | |
| 4566 | + "--enable-directional-intra=0", | |
| 4567 | + "--enable-angle-delta=0", | |
| 4568 | + "--enable-cdef=0", | |
| 4569 | + "--enable-restoration=0", | |
| 4570 | + "--enable-palette=0", | |
| 4571 | + "--enable-intrabc=0", | |
| 4572 | + "--enable-cfl-intra=0", | |
| 4573 | + "--enable-ref-frame-mvs=0", | |
| 4574 | + // Per-arm overrides go LAST (aomenc keeps the last | |
| 4575 | + // occurrence of a repeated --enable-* flag): the intra | |
| 4576 | + // tx_depth symbol only exists under TX_MODE_SELECT, and | |
| 4577 | + // rect partitions are a separate named refusal. | |
| 4578 | + "--enable-filter-intra=1", | |
| 4579 | + "--enable-tx-size-search=1", | |
| 4580 | + "--enable-rect-partitions=0", | |
| 4581 | + "--max-partition-size=32", | |
| 4582 | + // Sub-16 inter partitions are a separate named refusal, | |
| 4583 | + // as is the 8x8 intra leaf's own TX_4X4 split. | |
| 4584 | + "--min-partition-size=16", | |
| 4585 | + "--obu", | |
| 4586 | + "-o", | |
| 4587 | + "-", | |
| 4588 | + "-", | |
| 4589 | + ]) | |
| 4590 | + .stdin(Stdio::piped()) | |
| 4591 | + .stdout(Stdio::piped()) | |
| 4592 | + .stderr(Stdio::piped()) | |
| 4593 | + .spawn() | |
| 4594 | + .expect("aomenc failed to start"); | |
| 4595 | + child | |
| 4596 | + .stdin | |
| 4597 | + .take() | |
| 4598 | + .expect("aomenc stdin") | |
| 4599 | + .write_all(&y4m.stdout) | |
| 4600 | + .expect("writing y4m to aomenc"); | |
| 4601 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 4602 | + assert!( | |
| 4603 | + out.status.success(), | |
| 4604 | + "aomenc refused the fixture: {}", | |
| 4605 | + String::from_utf8_lossy(&out.stderr) | |
| 4606 | + ); | |
| 4607 | + let stream = out.stdout; | |
| 4608 | + let before = decode::intra_in_inter_filter_intra_hits(); | |
| 4609 | + let frames = match decode_stream(&stream) { | |
| 4610 | + Ok(frames) => frames, | |
| 4611 | + Err(e) => { | |
| 4612 | + let msg = e.to_string(); | |
| 4613 | + assert!( | |
| 4614 | + msg.contains("unsupported"), | |
| 4615 | + "{name} decode failed outright (seed {seed}): {msg}" | |
| 4616 | + ); | |
| 4617 | + refusals.push(format!("seed {seed}: {msg}")); | |
| 4618 | + continue; | |
| 4619 | + } | |
| 4620 | + }; | |
| 4621 | + let fired = decode::intra_in_inter_filter_intra_hits() - before; | |
| 4622 | + // class [[gate-skips-on-its-own-failure]]: a decode that | |
| 4623 | + // succeeded is ALWAYS pixel-compared below; the counter only | |
| 4624 | + // decides whether the attempt counts as firing. | |
| 4625 | + let counted = fired != 0; | |
| 4626 | + if !counted { | |
| 4627 | + uncounted_exact += 1; | |
| 4628 | + refusals.push(format!( | |
| 4629 | + "seed {seed}: decoded and pixel-compared, but no intra block in an inter \ | |
| 4630 | + frame used filter intra" | |
| 4631 | + )); | |
| 4632 | + } | |
| 4633 | + let ffmpeg_frames = if bit_depth == 10 { | |
| 4634 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | |
| 4635 | + } else { | |
| 4636 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | |
| 4637 | + }; | |
| 4638 | + assert_eq!(frames.len(), frame_count); | |
| 4639 | + eprintln!( | |
| 4640 | + "{name} seed={seed}: filter-intra blocks inside inter frames = {fired}" | |
| 4641 | + ); | |
| 4642 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 4643 | + for (plane, (g, w)) in [ | |
| 4644 | + ("Y", (&got.y, &want.y)), | |
| 4645 | + ("U", (&got.u, &want.u)), | |
| 4646 | + ("V", (&got.v, &want.v)), | |
| 4647 | + ] { | |
| 4648 | + let stride = if plane == "Y" { width } else { width / 2 }; | |
| 4649 | + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { | |
| 4650 | + eprintln!( | |
| 4651 | + "{name} seed={seed}: frame {i} {plane} first diff at ({}, {}) got {} \ | |
| 4652 | + want {} ({} samples differ)", | |
| 4653 | + at % stride, | |
| 4654 | + at / stride, | |
| 4655 | + g[at], | |
| 4656 | + w[at], | |
| 4657 | + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), | |
| 4658 | + ); | |
| 4659 | + } | |
| 4660 | + } | |
| 4661 | + } | |
| 4662 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 4663 | + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); | |
| 4664 | + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); | |
| 4665 | + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); | |
| 4666 | + } | |
| 4667 | + if counted { | |
| 4668 | + gate_buckets( | |
| 4669 | + &name, | |
| 4670 | + 1, | |
| 4671 | + uncounted_exact, | |
| 4672 | + refusals.len() - uncounted_exact as usize, | |
| 4673 | + ); | |
| 4674 | + return; | |
| 4675 | + } | |
| 4676 | + } | |
| 4677 | + gate_buckets( | |
| 4678 | + &name, | |
| 4679 | + 0, | |
| 4680 | + uncounted_exact, | |
| 4681 | + refusals.len() - uncounted_exact as usize, | |
| 4682 | + ); | |
| 4683 | + panic!( | |
| 4684 | + "{name} never observed a filter-intra intra block in an inter frame:\n{}", | |
| 4685 | + refusals.join("\n") | |
| 4686 | + ); | |
| 4687 | + } | |
| 4688 | + | |
| 4437 | 4689 | /// lane-chroma r2 stage 1: a real aomenc key frame with |
| 4438 | 4690 | /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) |
| 4439 | 4691 | /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still- |
lanes/fiinter-r1.report.mdadded+95 -0
| @@ -0,0 +1,95 @@ | ||
| 1 | +# lane-fiinter r1 -- `use_filter_intra` on an intra block inside an inter frame | |
| 2 | + | |
| 3 | +Branch `lane-fiinter`, rebased onto main `eebf24e` (charter's base `lane-intrainter e841b2a` | |
| 4 | +replayed onto main; no conflicts). | |
| 5 | + | |
| 6 | +## Premise, re-measured | |
| 7 | + | |
| 8 | +`decode_inter_block`'s INTRA arm and `decode_inter_block8`'s 8x8 INTRA arm read | |
| 9 | +`y_mode` -> `angle_delta_y` -> `uv_mode` (+cfl/angle) -> palette and then went straight to | |
| 10 | +`read_block_tx_size` -- no `use_filter_intra` symbol at all, while libaom's | |
| 11 | +`read_intra_block_mode_info` (decodemv.c) ends with `read_filter_intra_mode_info` in exactly | |
| 12 | +that place, key frame or inter frame alike. Every inter gate recipe in `stream.rs` spelled | |
| 13 | +`--enable-filter-intra=0` (69 occurrences), so nothing had ever exercised it; aomenc's own | |
| 14 | +default is ON, so his films' inter frames desynced silently at the first such block. | |
| 15 | +Classes: [[symbol-consumption-gap]] + [[tool-disabled-in-every-gate]]. | |
| 16 | + | |
| 17 | +## What changed | |
| 18 | + | |
| 19 | +- `crates/ec-av1/src/decode.rs:64-80` -- `INTRA_IN_INTER_FILTER_INTRA_HITS` counter + | |
| 20 | + `intra_in_inter_filter_intra_hits()`, the gate's firing proof (the existing | |
| 21 | + `FILTER_INTRA_HITS` is also incremented, so the key-frame gates' deltas stay meaningful). | |
| 22 | +- `crates/ec-av1/src/decode.rs:830-856` -- `ENABLE_FILTER_INTRA_INTER` thread-local, set by | |
| 23 | + `set_inter_tx_mode(tx_select, reduced_tx_set, enable_filter_intra)`; same frame-constant | |
| 24 | + stash `TX_SELECT_INTER`/`REDUCED_TX_SET_INTER` already use rather than a 51st | |
| 25 | + `decode_inter_block` parameter. | |
| 26 | +- `crates/ec-av1/src/decode.rs:17497+` -- `decode_inter_frame_tile_with_cdfs` takes | |
| 27 | + `enable_filter_intra` (last param); `decode_inter_frame_tile` passes `false` (this crate's | |
| 28 | + encoder never writes the sequence bit), `stream.rs:694` passes the sequence header's bit. | |
| 29 | +- `crates/ec-av1/src/decode.rs:15578-15594` (>=16x16 square intra-in-inter arm) and | |
| 30 | + `:17188-17204` (8x8 leaf arm) -- `use_filter_intra` read via | |
| 31 | + `cdfs.filter_intra[filter_intra_size_class(side)]` right after the palette syntax, then | |
| 32 | + `filter_intra_mode`. `av1_filter_intra_allowed`'s `palette_size[0] == 0` term is implied (a | |
| 33 | + real palette-Y block already returned by refusal); `filter_intra_size_class` returns `None` | |
| 34 | + at 64x64, so no symbol is read there, matching `av1_filter_intra_allowed_bsize`. | |
| 35 | +- Same arms: `filter_intra` now threaded into every LUMA prediction/coefficient call -- | |
| 36 | + the per-TU split path (`y.reconstruct` and `read_plane` inside the `vartx_leaves` loop, | |
| 37 | + i.e. lane-intrainter's split-tx path), the whole-block skip `reconstruct`, and the | |
| 38 | + whole-block `read_plane`. Chroma keeps `None`, exactly as the key-frame square arm does. | |
| 39 | + `read_plane`'s own `FIMODE_TO_INTRADIR` mapping (decode.rs:7445) supplies the tx_type CDF | |
| 40 | + row per TU, so lane-tiny's filter-intra tx_type row fix applies here unchanged. | |
| 41 | + | |
| 42 | +## Gate | |
| 43 | + | |
| 44 | +`stream.rs:4438-4700`: | |
| 45 | +`a_real_aomenc_inter_sequence_with_filter_intra_on_an_intra_block_decodes_pixel_exact` (8-bit) | |
| 46 | +and `..._10bit_...` (10-bit), driven by `filter_intra_in_inter_gate(bit_depth)` -- the | |
| 47 | +intrainter recipe (mandelbrot + hard overlay cut at frame 4, cq30, `--kf-min-dist=1000`, | |
| 48 | +`--enable-tx-size-search=1`, `--max/min-partition-size=32/16`) with `--enable-filter-intra=1`. | |
| 49 | +The flag is spelled ONCE (the base `=0` deleted) so no aomenc precedence question arises; | |
| 50 | +arrival is proved decoder-side by the counter, per COMMON. Every decoded frame's Y/U/V is | |
| 51 | +compared against ffmpeg; a decode error is only accepted when its message contains | |
| 52 | +"unsupported"; running out of attempts panics (no SKIP). | |
| 53 | + | |
| 54 | +``` | |
| 55 | +CARGO_TARGET_DIR=$HOME/.cache/cargo-target-fiinter EC_NOMEMGUARD=1 EC_AV1_REQUIRE_AOMENC=1 \ | |
| 56 | + cargo test -p ec-av1 --lib filter_intra_on_an_intra_block -- --nocapture | |
| 57 | +``` | |
| 58 | + | |
| 59 | +EVIDENCE: $HOME/.cache/fiinter-suite.log | cargo test -p ec-av1 --lib filter_intra_on_an_intra_block | 8-bit seed 42: 11 filter-intra intra-in-inter blocks, 8 frames Y/U/V exact; 10-bit seed 47: 8 blocks, 8 frames exact; buckets counted-exact=1 uncounted-exact=0 | |
| 60 | + | |
| 61 | +EVIDENCE: negative control (`&& false` in front of both new reads, decode.rs restored after) | same gate command | 8-bit: 40/40 attempts, 0 firings, 33 named refusals + 7 decoded-uncounted -> PANIC. The gate is not vacuous: without the read the stream desyncs. | |
| 62 | + | |
| 63 | +EVIDENCE: mutation sweep (`sed 's/--enable-filter-intra=0/=1/g' stream.rs`, restored after) | `cargo test -p ec-av1 --lib inter_sequence` | 15 passed / 0 failed / 2 ignored (both pre-existing `#[ignore]`s: the 10-bit 8x8-leaf-split twin and the tile-column 8x8 gate) -- every inter gate that passed with filter intra OFF still passes with it ON, including `..._split_transform_intra_block_...` at both depths. | |
| 64 | + | |
| 65 | +## Refusals | |
| 66 | + | |
| 67 | +None lifted -- there was no refusal here, only an unread symbol (which is the worse shape: | |
| 68 | +`refusal_inventory.rs` is unchanged and stays green). `gate_coverage.rs` needs no edit: its | |
| 69 | +coverage is derived from the `--enable-*` spellings in the gate source, and the two new tests | |
| 70 | +spell `--enable-filter-intra=1` at 8 and 10 bit. | |
| 71 | + | |
| 72 | +## Residue | |
| 73 | + | |
| 74 | +- deferred(a directional-intra-in-inter gate): the `"a nonzero angle delta (this encoder never | |
| 75 | + writes one)"` refusal in both intra-in-inter arms stays. The symbol read itself is correct | |
| 76 | + (`cdfs.angle_delta[mode - V_PRED]`, compared to `ANGLE_DELTA_ZERO`), so lifting it is | |
| 77 | + mechanical -- but lifting a refusal without a gate that fires it is forbidden by COMMON, and | |
| 78 | + this lane's recipe pins `--enable-angle-delta=0`/`--enable-directional-intra=0` (a nonzero | |
| 79 | + delta would need its own source family). Unblocked by: an aomenc recipe that puts a | |
| 80 | + directional intra block with a nonzero delta inside an inter frame. | |
| 81 | +- accepted: the 8x8-leaf arm's read is size-generic and compiles/decodes, but no gate proves it | |
| 82 | + FIRED -- this gate pins `--min-partition-size=16`. The mutation sweep ran the 8x8-leaf-split | |
| 83 | + gates with filter intra ON and they stayed pixel-exact, which bounds the risk but does not | |
| 84 | + prove the symbol fired at 8x8. | |
| 85 | +- accepted: CfL/palette parity is unchanged from the key-frame arm -- a real palette-Y/UV block | |
| 86 | + still refuses by name before the filter-intra read, and `UV_CFL_PRED` chroma alphas are read | |
| 87 | + as before (filter intra is luma-only). | |
| 88 | + | |
| 89 | +## Suite + film | |
| 90 | + | |
| 91 | +`cargo test -p ec-av1 --lib` (systemd unit, log `$HOME/.cache/fiinter-suite.log`): **346 passed / 0 failed / 32 ignored**, 739 s. | |
| 92 | + | |
| 93 | +EVIDENCE: $HOME/.cache/fiinter-suite.log | systemd-run --user --unit=fiinter-suite ... cargo test -p ec-av1 --lib -j3 | test result: ok. 346 passed; 0 failed; 32 ignored | |
| 94 | + | |
| 95 | +EVIDENCE: scratchpad/hg-head.obu | cargo run -p ec-av1 --example decode_probe -- hg-head.obu | 18 frame headers parsed, now stops at `unsupported: AV1 tile (filter intra on a HORZ/VERT strip (this decoder predicts square-only))` -- i.e. his film really does carry filter intra, and the next blocker is the rect-strip filter-intra predictor (another lane), not the unread inter symbol this lane fixed. |