forge
Explore
Log in

Don't you dare go Hollow

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 commit

b4e787dc6df9fade2ae6393c993299030a9bd237Ahmet Kaan GümüşParent: 5f7a053787a14a
crates/ec-av1/src/decode.rsmodified+58 -4
@@ -36618,6 +36618,7 @@ mod tests {
3661836618 mi_cols,
3661936619 mi_rows,
3662036620 base_q_idx,
36621+ tx_select,
3662136622 ..
3662236623 }: Encoded = crate::encode::encode_key_frame_with_modes_with_ctx(&picture, 40, 0.0, modes, fctx).unwrap();
3662336624 let decoded = decode_key_frame_tile(
@@ -36630,7 +36631,7 @@ mod tests {
3663036631 false,
3663136632 &CdefParams::default(),
3663236633 &LoopFilterParams::default(),
36633- false,
36634+ tx_select,
3663436635 true,
3663536636 false,
3663636637 false, fctx,
@@ -36995,7 +36996,7 @@ mod tests {
3699536996 false,
3699636997 &CdefParams::default(),
3699736998 &LoopFilterParams::default(),
36998- false,
36999+ encoded.tx_select,
3699937000 true,
3700037001 false,
3700137002 false, fctx,
@@ -37007,6 +37008,59 @@ mod tests {
3700737008 }
3700837009 }
3700937010
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+
3701037064 fn round_trip_test_card(width: usize, height: usize) -> crate::encode::Picture {
3701137065 let mut picture = crate::encode::Picture::grey(width, height);
3701237066 for row in 0..height {
@@ -37069,7 +37123,7 @@ mod tests {
3706937123 false,
3707037124 &CdefParams::default(),
3707137125 &LoopFilterParams::default(),
37072- false,
37126+ key.tx_select,
3707337127 true,
3707437128 false,
3707537129 false, fctx,
@@ -37389,7 +37443,7 @@ mod tests {
3738937443 false,
3739037444 &CdefParams::default(),
3739137445 &LoopFilterParams::default(),
37392- false,
37446+ key.tx_select,
3739337447 true,
3739437448 false,
3739537449 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
473473 mi_cols: encoded.mi_cols,
474474 mi_rows: encoded.mi_rows,
475475 base_q_idx: encoded.base_q_idx,
476+ tx_select: encoded.tx_select,
476477 }
477478 }
478479
@@ -502,6 +503,13 @@ pub struct Encoded {
502503 pub(crate) mi_cols: u32,
503504 pub(crate) mi_rows: u32,
504505 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,
505513 }
506514
507515 /// 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(
29132921 mi_cols: header.mi_cols,
29142922 mi_rows: header.mi_rows,
29152923 base_q_idx,
2924+ tx_select,
29162925 })
29172926 }
29182927
@@ -4002,6 +4011,7 @@ pub(crate) fn encode_inter_frame(
40024011 mi_cols: header.mi_cols,
40034012 mi_rows: header.mi_rows,
40044013 base_q_idx,
4014+ tx_select,
40054015 })
40064016 }
40074017
crates/ec-av1/src/stream.rsmodified+1 -1
@@ -2996,7 +2996,7 @@ mod tests {
29962996 false,
29972997 &ec_av1_syntax::CdefParams::default(),
29982998 &ec_av1_syntax::LoopFilterParams::default(),
2999- false,
2999+ encoded.tx_select,
30003000 // Our own encoder always writes `reduced_tx_set: true`.
30013001 true,
30023002 false,