measure(av1): intrabc ships behind EC_AV1_INTRABC, default OFF -- it loses the key frame's in-loop filters for nothing on the real screen capture
Browse files at this commit331a966b622ea65b84c16ccbb82375452d21cac8Parent: b42af301 changed file +79 -3
- crates/ec-av1/src/encode.rs +79 -3
crates/ec-av1/src/encode.rsmodified+79 -3
| @@ -2486,11 +2486,33 @@ fn palette_candidates(block: &[u8]) -> Vec<crate::tile::PaletteY> { | ||
| 2486 | 2486 | // gives up. `EC_AV1_INTRABC=0` turns the whole arm off. |
| 2487 | 2487 | // --------------------------------------------------------------------------- |
| 2488 | 2488 | |
| 2489 | -/// Whether intra block copy is offered at all. On by default; off on a frame | |
| 2490 | -/// that detected no screen content, and off entirely under `EC_AV1_INTRABC=0`. | |
| 2489 | +/// Whether intra block copy is offered at all. **Off by default** -- | |
| 2490 | +/// `EC_AV1_INTRABC=1` turns it on. The syntax is complete and proven against | |
| 2491 | +/// ffmpeg (`a_repeated_pattern_key_frame_codes_intrabc_blocks_ffmpeg_decodes_exactly`), | |
| 2492 | +/// but on the gate's real screen capture it MEASURED WORSE: setting | |
| 2493 | +/// `allow_intrabc` costs the key frame its deblocking, CDEF and loop | |
| 2494 | +/// restoration (spec 5.9.11/5.9.19/5.9.20) and the copied blocks do not pay | |
| 2495 | +/// that back -- screen BD +59.1/+5.1 against the +54.5/+1.1 base (lane-av1ibc, | |
| 2496 | +/// `probe_intrabc_key_frame` has the per-key-frame table). Also off on a frame | |
| 2497 | +/// that detected no screen content. | |
| 2491 | 2498 | fn intrabc_enabled() -> bool { |
| 2499 | + if let Some(forced) = INTRABC_FORCE.with(std::cell::Cell::get) { | |
| 2500 | + return forced; | |
| 2501 | + } | |
| 2492 | 2502 | static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); |
| 2493 | - *ON.get_or_init(|| std::env::var("EC_AV1_INTRABC").ok().as_deref() != Some("0")) | |
| 2503 | + *ON.get_or_init(|| std::env::var("EC_AV1_INTRABC").ok().as_deref() == Some("1")) | |
| 2504 | +} | |
| 2505 | + | |
| 2506 | +thread_local! { | |
| 2507 | + /// Overrides [`intrabc_enabled`] for the calling thread -- the ablation | |
| 2508 | + /// probe runs both arms in one process, and the suite is one process, so | |
| 2509 | + /// an environment variable cannot separate them (same reason | |
| 2510 | + /// [`SCREEN_FORCE`] exists). | |
| 2511 | + static INTRABC_FORCE: std::cell::Cell<Option<bool>> = const { std::cell::Cell::new(None) }; | |
| 2512 | +} | |
| 2513 | + | |
| 2514 | +pub(crate) fn force_intrabc(value: Option<bool>) { | |
| 2515 | + INTRABC_FORCE.with(|c| c.set(value)); | |
| 2494 | 2516 | } |
| 2495 | 2517 | |
| 2496 | 2518 | /// How many of a screen frame's 16x16 blocks must have an exact repeat |
| @@ -7552,6 +7574,55 @@ mod tests { | ||
| 7552 | 7574 | assert!(!film.screen, "the detector fired on the film-shaped test card"); |
| 7553 | 7575 | } |
| 7554 | 7576 | |
| 7577 | + /// The lane's keep-rule measurement: the gate's own screen capture, one | |
| 7578 | + /// KEY FRAME, coded with and without `allow_intrabc` at four quantizers. | |
| 7579 | + /// Setting the bit forces deblocking, CDEF and loop restoration off for | |
| 7580 | + /// that frame, so the table is exactly the filter loss against the bytes | |
| 7581 | + /// the copied blocks save. | |
| 7582 | + #[test] | |
| 7583 | + #[ignore = "needs the real-library manifest and ffmpeg"] | |
| 7584 | + fn probe_intrabc_key_frame() { | |
| 7585 | + let fctx = &crate::decode::FrameCtx::new(); | |
| 7586 | + let fixtures = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 7587 | + .join("../../fixtures"); | |
| 7588 | + let Ok(manifest) = std::fs::read_to_string(fixtures.join("real-library-manifest.tsv")) else { | |
| 7589 | + eprintln!("SKIP probe_intrabc_key_frame: no real-library manifest"); | |
| 7590 | + return; | |
| 7591 | + }; | |
| 7592 | + let Some(clip) = manifest | |
| 7593 | + .lines() | |
| 7594 | + .skip(1) | |
| 7595 | + .filter_map(|l| l.split('\t').next()) | |
| 7596 | + .find(|p| p.contains("/OBS/") && p.ends_with(".mkv") && std::path::Path::new(p).exists()) | |
| 7597 | + else { | |
| 7598 | + eprintln!("SKIP probe_intrabc_key_frame: no OBS recording"); | |
| 7599 | + return; | |
| 7600 | + }; | |
| 7601 | + let (width, height) = (640usize, 384usize); | |
| 7602 | + let picture = clip_frame(clip, "0", width, height); | |
| 7603 | + eprintln!("| base_q_idx | intrabc | bytes | PSNR | blocks | searches/found/won |"); | |
| 7604 | + for q in [5u8, 20, 35, 45] { | |
| 7605 | + for on in [false, true] { | |
| 7606 | + force_intrabc(Some(on)); | |
| 7607 | + let _ = crate::tile::take_intrabc_hits(); | |
| 7608 | + let _ = take_intrabc_search(); | |
| 7609 | + let encoded = encode_key_frame_with_ctx(&picture, q, 0.5, fctx).unwrap(); | |
| 7610 | + let hits = crate::tile::take_intrabc_hits(); | |
| 7611 | + let search = take_intrabc_search(); | |
| 7612 | + eprintln!( | |
| 7613 | + "| {q} | {} | {} | {:.2} dB | {} (dv hist {:?}) | {}/{}/{} |", | |
| 7614 | + if encoded.allow_intrabc { "on" } else { "off" }, | |
| 7615 | + encoded.stream.len(), | |
| 7616 | + psnr_all(&encoded.reconstruction, &picture), | |
| 7617 | + hits[0], | |
| 7618 | + &hits[1..], | |
| 7619 | + search[0], search[1], search[2], | |
| 7620 | + ); | |
| 7621 | + } | |
| 7622 | + } | |
| 7623 | + force_intrabc(None); | |
| 7624 | + } | |
| 7625 | + | |
| 7555 | 7626 | /// lane-av1ibc's own end-to-end check: a repeated-pattern screen card |
| 7556 | 7627 | /// sets `allow_intrabc` (so every in-loop filter is off), blocks really |
| 7557 | 7628 | /// take a block vector (fire count + DV histogram, class |
| @@ -7567,7 +7638,12 @@ mod tests { | ||
| 7567 | 7638 | let (width, height) = (512usize, 256usize); |
| 7568 | 7639 | let picture = screen_card(width, height); |
| 7569 | 7640 | let _ = crate::tile::take_intrabc_hits(); |
| 7641 | + // The default is OFF (it measured worse on the real screen capture -- | |
| 7642 | + // see [`intrabc_enabled`]); this gate proves the SYNTAX, so it turns | |
| 7643 | + // the arm on for its own encode and puts it back straight after. | |
| 7644 | + force_intrabc(Some(true)); | |
| 7570 | 7645 | let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); |
| 7646 | + force_intrabc(None); | |
| 7571 | 7647 | assert!( |
| 7572 | 7648 | encoded.allow_intrabc, |
| 7573 | 7649 | "allow_intrabc was not set on a fully periodic screen card (source repeat share {:.1}%)", |