Merge branch 'lane-av1txfix' (e4821479): re-land key-frame TxMode::Select (tx_depth search, per-transform-unit intra) with the fix -- the encoder-driven decode tests fed decode_key_frame_tile a hard-coded tx_select=false, so Encoded now carries the header's tx_select and the five sites pass it (class: test asserts against a stale header; regression test pins the bit); no decoder change; film hashes unchanged; BD-rate vs rav1e screen +141% -> +73%
Browse files at this commit3 changed files +69 -5
- crates/ec-av1/src/decode.rs +58 -4
- crates/ec-av1/src/encode.rs +10 -0
- crates/ec-av1/src/stream.rs +1 -1
crates/ec-av1/src/decode.rsmodified+58 -4
| @@ -36618,6 +36618,7 @@ mod tests { | |||
| 36618 | mi_cols, | 36618 | mi_cols, |
| 36619 | mi_rows, | 36619 | mi_rows, |
| 36620 | base_q_idx, | 36620 | base_q_idx, |
| 36621 | + tx_select, | ||
| 36621 | .. | 36622 | .. |
| 36622 | }: Encoded = crate::encode::encode_key_frame_with_modes_with_ctx(&picture, 40, 0.0, modes, fctx).unwrap(); | 36623 | }: Encoded = crate::encode::encode_key_frame_with_modes_with_ctx(&picture, 40, 0.0, modes, fctx).unwrap(); |
| 36623 | let decoded = decode_key_frame_tile( | 36624 | let decoded = decode_key_frame_tile( |
| @@ -36630,7 +36631,7 @@ mod tests { | |||
| 36630 | false, | 36631 | false, |
| 36631 | &CdefParams::default(), | 36632 | &CdefParams::default(), |
| 36632 | &LoopFilterParams::default(), | 36633 | &LoopFilterParams::default(), |
| 36633 | - false, | 36634 | + tx_select, |
| 36634 | true, | 36635 | true, |
| 36635 | false, | 36636 | false, |
| 36636 | false, fctx, | 36637 | false, fctx, |
| @@ -36995,7 +36996,7 @@ mod tests { | |||
| 36995 | false, | 36996 | false, |
| 36996 | &CdefParams::default(), | 36997 | &CdefParams::default(), |
| 36997 | &LoopFilterParams::default(), | 36998 | &LoopFilterParams::default(), |
| 36998 | - false, | 36999 | + encoded.tx_select, |
| 36999 | true, | 37000 | true, |
| 37000 | false, | 37001 | false, |
| 37001 | false, fctx, | 37002 | false, fctx, |
| @@ -37007,6 +37008,59 @@ mod tests { | |||
| 37007 | } | 37008 | } |
| 37008 | } | 37009 | } |
| 37009 | 37010 | ||
| 37011 | + /// The key frame the encoder writes carries `tx_mode == TxMode::Select`, | ||
| 37012 | + /// and that header bit is load-bearing for a decode of its tile: read as a | ||
| 37013 | + /// `TxMode::Largest` frame the very first block misses its `tx_depth` | ||
| 37014 | + /// symbol and the whole tile desyncs. Pins the shape that broke nine gates | ||
| 37015 | + /// when `Encoded` had no `tx_select` for them to pass along — a test that | ||
| 37016 | + /// hardcoded the bit was decoding a different frame header than the one | ||
| 37017 | + /// the encoder wrote (and than the one `decode_stream`/ffmpeg read off the | ||
| 37018 | + /// wire). | ||
| 37019 | + #[test] | ||
| 37020 | + fn a_key_frames_tile_needs_the_headers_own_tx_select_bit() { | ||
| 37021 | + let fctx = &crate::decode::FrameCtx::new(); | ||
| 37022 | + use crate::encode::encode_key_frame_with_ctx; | ||
| 37023 | + let (width, height) = (64usize, 64usize); | ||
| 37024 | + let picture = round_trip_test_card(width, height); | ||
| 37025 | + let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap(); | ||
| 37026 | + assert!( | ||
| 37027 | + encoded.tx_select, | ||
| 37028 | + "the encoder's key frame no longer codes TxMode::Select -- this \ | ||
| 37029 | + gate's premise moved, not the decoder" | ||
| 37030 | + ); | ||
| 37031 | + let decode = |tx_select: bool| { | ||
| 37032 | + decode_key_frame_tile( | ||
| 37033 | + &encoded.tile, | ||
| 37034 | + encoded.mi_cols, | ||
| 37035 | + encoded.mi_rows, | ||
| 37036 | + encoded.base_q_idx, | ||
| 37037 | + width as u32, | ||
| 37038 | + height as u32, | ||
| 37039 | + false, | ||
| 37040 | + &CdefParams::default(), | ||
| 37041 | + &LoopFilterParams::default(), | ||
| 37042 | + tx_select, | ||
| 37043 | + true, | ||
| 37044 | + false, | ||
| 37045 | + false, | ||
| 37046 | + fctx, | ||
| 37047 | + ) | ||
| 37048 | + }; | ||
| 37049 | + let right = decode(true).expect("the header's own tx_mode decodes"); | ||
| 37050 | + assert_eq!(right.y, encoded.reconstruction.y, "luma under tx_select"); | ||
| 37051 | + assert_eq!(right.u, encoded.reconstruction.u, "U under tx_select"); | ||
| 37052 | + assert_eq!(right.v, encoded.reconstruction.v, "V under tx_select"); | ||
| 37053 | + // The wrong bit either refuses or reconstructs something else; what it | ||
| 37054 | + // must never do is agree, which would mean the bit codes nothing. | ||
| 37055 | + if let Ok(wrong) = decode(false) { | ||
| 37056 | + assert_ne!( | ||
| 37057 | + wrong.y, encoded.reconstruction.y, | ||
| 37058 | + "reading a TxMode::Select tile as Largest agreed -- the \ | ||
| 37059 | + tx_depth symbols are not being coded" | ||
| 37060 | + ); | ||
| 37061 | + } | ||
| 37062 | + } | ||
| 37063 | + | ||
| 37010 | fn round_trip_test_card(width: usize, height: usize) -> crate::encode::Picture { | 37064 | fn round_trip_test_card(width: usize, height: usize) -> crate::encode::Picture { |
| 37011 | let mut picture = crate::encode::Picture::grey(width, height); | 37065 | let mut picture = crate::encode::Picture::grey(width, height); |
| 37012 | for row in 0..height { | 37066 | for row in 0..height { |
| @@ -37069,7 +37123,7 @@ mod tests { | |||
| 37069 | false, | 37123 | false, |
| 37070 | &CdefParams::default(), | 37124 | &CdefParams::default(), |
| 37071 | &LoopFilterParams::default(), | 37125 | &LoopFilterParams::default(), |
| 37072 | - false, | 37126 | + key.tx_select, |
| 37073 | true, | 37127 | true, |
| 37074 | false, | 37128 | false, |
| 37075 | false, fctx, | 37129 | false, fctx, |
| @@ -37389,7 +37443,7 @@ mod tests { | |||
| 37389 | false, | 37443 | false, |
| 37390 | &CdefParams::default(), | 37444 | &CdefParams::default(), |
| 37391 | &LoopFilterParams::default(), | 37445 | &LoopFilterParams::default(), |
| 37392 | - false, | 37446 | + key.tx_select, |
| 37393 | true, | 37447 | true, |
| 37394 | false, | 37448 | false, |
| 37395 | false, fctx, | 37449 | false, fctx, |
crates/ec-av1/src/encode.rsmodified+10 -0
| @@ -473,6 +473,7 @@ pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> En | |||
| 473 | mi_cols: encoded.mi_cols, | 473 | mi_cols: encoded.mi_cols, |
| 474 | mi_rows: encoded.mi_rows, | 474 | mi_rows: encoded.mi_rows, |
| 475 | base_q_idx: encoded.base_q_idx, | 475 | base_q_idx: encoded.base_q_idx, |
| 476 | + tx_select: encoded.tx_select, | ||
| 476 | } | 477 | } |
| 477 | } | 478 | } |
| 478 | 479 | ||
| @@ -502,6 +503,13 @@ pub struct Encoded { | |||
| 502 | pub(crate) mi_cols: u32, | 503 | pub(crate) mi_cols: u32, |
| 503 | pub(crate) mi_rows: u32, | 504 | pub(crate) mi_rows: u32, |
| 504 | pub(crate) base_q_idx: u8, | 505 | pub(crate) base_q_idx: u8, |
| 506 | + /// This frame header's `tx_mode == TxMode::Select` ([`tx_select`], and | ||
| 507 | + /// [`tx_select_inter`] on an inter frame) — a decoder of `tile` needs it, | ||
| 508 | + /// and reading it off `stream`'s header is what `decode_stream` does. A | ||
| 509 | + /// test that decodes `tile` directly must pass this one along, or it reads | ||
| 510 | + /// a `tx_depth` frame as a `TxMode::Largest` one and desyncs at the first | ||
| 511 | + /// block. | ||
| 512 | + pub(crate) tx_select: bool, | ||
| 505 | } | 513 | } |
| 506 | 514 | ||
| 507 | /// The sequence and frame headers a picture of this size is coded under: one | 515 | /// The sequence and frame headers a picture of this size is coded under: one |
| @@ -2913,6 +2921,7 @@ pub(crate) fn encode_key_frame_inner( | |||
| 2913 | mi_cols: header.mi_cols, | 2921 | mi_cols: header.mi_cols, |
| 2914 | mi_rows: header.mi_rows, | 2922 | mi_rows: header.mi_rows, |
| 2915 | base_q_idx, | 2923 | base_q_idx, |
| 2924 | + tx_select, | ||
| 2916 | }) | 2925 | }) |
| 2917 | } | 2926 | } |
| 2918 | 2927 | ||
| @@ -4002,6 +4011,7 @@ pub(crate) fn encode_inter_frame( | |||
| 4002 | mi_cols: header.mi_cols, | 4011 | mi_cols: header.mi_cols, |
| 4003 | mi_rows: header.mi_rows, | 4012 | mi_rows: header.mi_rows, |
| 4004 | base_q_idx, | 4013 | base_q_idx, |
| 4014 | + tx_select, | ||
| 4005 | }) | 4015 | }) |
| 4006 | } | 4016 | } |
| 4007 | 4017 | ||
crates/ec-av1/src/stream.rsmodified+1 -1
| @@ -2996,7 +2996,7 @@ mod tests { | |||
| 2996 | false, | 2996 | false, |
| 2997 | &ec_av1_syntax::CdefParams::default(), | 2997 | &ec_av1_syntax::CdefParams::default(), |
| 2998 | &ec_av1_syntax::LoopFilterParams::default(), | 2998 | &ec_av1_syntax::LoopFilterParams::default(), |
| 2999 | - false, | 2999 | + encoded.tx_select, |
| 3000 | // Our own encoder always writes `reduced_tx_set: true`. | 3000 | // Our own encoder always writes `reduced_tx_set: true`. |
| 3001 | true, | 3001 | true, |
| 3002 | false, | 3002 | false, |