forge
Explore
Log in

Don't you dare go Hollow

The superblock size travels with a FrameCtx copy

Browse files at this commit

ab4ff0c5ff3647c931b95a7c77a0bcecf3081762Ahmet Kaan GümüşParent: 2dc9fc2
  • fix
    • the superblock size travels with a FrameCtx copy
    • two reach gates pin 64
Show full message
fix(av1): the superblock size travels with a FrameCtx copy; two reach gates pin 64

filter_ctx_copy dropped sb128_flag/reach_sb_px, so a tile SEARCH worker
searched at 64 while the calling thread searched at 128: the coded bytes
depended on EC_AV1_TILE_THREADS under EC_AV1_SB128
(tile_bytes_do_not_depend_on_the_thread_count, 1x2 tiles, 9251 vs 9239).

every_tile_layout: the spec's uniform spacing derives the tile count from
the superblock grid, so a 128-superblock frame with 5 SB columns codes 3
tiles for tile_cols_log2=2; the test now expects the encoder's own grid.
The two reach gates transcribe libaom's 64-superblock tables, so they pin
a 64 context instead of following the process knob.
crates/ec-av1/src/decode.rsmodified+7 -0
@@ -275,6 +275,13 @@ pub(crate) fn filter_ctx_copy(fctx: &FrameCtx) -> FrameCtx {
275275 out.seg_mi_dims.set(fctx.seg_mi_dims.get());
276276 out.seg.replace(fctx.seg.borrow().clone());
277277 out.seg_ids.replace(fctx.seg_ids.borrow().clone());
278+ // lane-b128m: the superblock size travels with the copy. A tile SEARCH
279+ // worker (`encode::search_tiles`) gets its context from here, so dropping
280+ // it made every worker search at 64 while the calling thread searched at
281+ // 128 -- the bytes a frame came out as then depended on the tile thread
282+ // count under `EC_AV1_SB128`.
283+ out.sb128_flag.set(fctx.sb128_flag.get());
284+ out.reach_sb_px.set(fctx.reach_sb_px.get());
278285 out
279286 }
280287
crates/ec-av1/src/encode.rsmodified+10 -2
@@ -13510,7 +13510,11 @@ mod tests {
1351013510 /// (the horizontal shapes, which those partitions never produce).
1351113511 #[test]
1351213512 fn every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock() {
13513- let fctx = &crate::decode::FrameCtx::for_encoder();
13513+ // lane-b128m: this test's oracle is libaom's 64-SUPERBLOCK table, so
13514+ // it pins the 64 reach explicitly instead of following the process's
13515+ // own superblock knob (`for_encoder`), which made it red under
13516+ // `EC_AV1_SB128=1` for no defect of the code under test.
13517+ let fctx = &crate::decode::FrameCtx::new();
1351413518 // (bw, bh, has_tr len, has_tr byte sum, has_bl len, has_bl byte sum).
1351513519 const SHAPES: [(usize, usize, usize, u32, usize, u32); 14] = [
1351613520 (4, 8, 64, 9280, 64, 550),
@@ -14437,7 +14441,11 @@ mod tests {
1443714441 /// wrong for one block size while looking plausible for the other.
1443814442 #[test]
1443914443 fn reach_matches_libaom_has_top_right_and_has_bottom_left() {
14440- let fctx = &crate::decode::FrameCtx::for_encoder();
14444+ // lane-b128m: this test's oracle is libaom's 64-SUPERBLOCK table, so
14445+ // it pins the 64 reach explicitly instead of following the process's
14446+ // own superblock knob (`for_encoder`), which made it red under
14447+ // `EC_AV1_SB128=1` for no defect of the code under test.
14448+ let fctx = &crate::decode::FrameCtx::new();
1444114449 // Transcribed from has_top_right/has_bottom_left's row_off==0,
1444214450 // col_off==0 (whole-transform) path, with MAX_MIB_SIZE_LOG2 = 5 (a
1444314451 // 128px reference grid) pinned as libaom pins it, independent of the
crates/ec-av1/src/encoder.rsmodified+15 -2
@@ -3675,6 +3675,19 @@ mod tests {
36753675 tile_rows_log2: rows_log2,
36763676 };
36773677 let layout = format!("{}x{} tiles", 1 << cols_log2, 1 << rows_log2);
3678+ // lane-b128m: the SPEC's uniform spacing derives the tile count
3679+ // from the superblock grid (`tileWidthSb = ceil(sbCols >> log2)`),
3680+ // so a frame with fewer superblock columns than the requested
3681+ // count codes fewer tiles -- which is what a 128-superblock
3682+ // sequence does here. The grid the encoder itself computes is the
3683+ // expectation; at 64 superblocks it is `1 << log2` exactly.
3684+ let grid = crate::tile::TileLayout::new(
3685+ (width as u32).div_ceil(4),
3686+ (height as u32).div_ceil(4),
3687+ cols_log2,
3688+ rows_log2,
3689+ );
3690+ let (want_cols, want_rows) = (grid.cols(), grid.rows());
36783691 let mut enc = Av1Encoder::new(config).unwrap();
36793692 let mut stream = Vec::new();
36803693 for packet in encode_all(&mut enc, &sources) {
@@ -3693,12 +3706,12 @@ mod tests {
36933706 if let ec_av1_syntax::ObuKind::Frame(parsed, tiles) = &obu.kind {
36943707 assert_eq!(
36953708 (parsed.tile_info.cols, parsed.tile_info.rows),
3696- (1 << cols_log2, 1 << rows_log2),
3709+ (want_cols, want_rows),
36973710 "{layout}: the header's own tile grid"
36983711 );
36993712 assert_eq!(
37003713 tiles.len(),
3701- 1 << (cols_log2 + rows_log2),
3714+ (want_cols * want_rows) as usize,
37023715 "{layout}: tile payloads located in the tile group"
37033716 );
37043717 frames += 1;