The superblock size travels with a FrameCtx copy
Browse files at this commitab4ff0c5ff3647c931b95a7c77a0bcecf3081762Parent: 2dc9fc2- fix
- the superblock size travels with a FrameCtx copy
- two reach gates pin 64
3 changed files +32 -4
- crates/ec-av1/src/decode.rs +7 -0
- crates/ec-av1/src/encode.rs +10 -2
- crates/ec-av1/src/encoder.rs +15 -2
crates/ec-av1/src/decode.rsmodified+7 -0
| @@ -275,6 +275,13 @@ pub(crate) fn filter_ctx_copy(fctx: &FrameCtx) -> FrameCtx { | |||
| 275 | out.seg_mi_dims.set(fctx.seg_mi_dims.get()); | 275 | out.seg_mi_dims.set(fctx.seg_mi_dims.get()); |
| 276 | out.seg.replace(fctx.seg.borrow().clone()); | 276 | out.seg.replace(fctx.seg.borrow().clone()); |
| 277 | out.seg_ids.replace(fctx.seg_ids.borrow().clone()); | 277 | 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()); | ||
| 278 | out | 285 | out |
| 279 | } | 286 | } |
| 280 | 287 | ||
crates/ec-av1/src/encode.rsmodified+10 -2
| @@ -13510,7 +13510,11 @@ mod tests { | |||
| 13510 | /// (the horizontal shapes, which those partitions never produce). | 13510 | /// (the horizontal shapes, which those partitions never produce). |
| 13511 | #[test] | 13511 | #[test] |
| 13512 | fn every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock() { | 13512 | 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(); | ||
| 13514 | // (bw, bh, has_tr len, has_tr byte sum, has_bl len, has_bl byte sum). | 13518 | // (bw, bh, has_tr len, has_tr byte sum, has_bl len, has_bl byte sum). |
| 13515 | const SHAPES: [(usize, usize, usize, u32, usize, u32); 14] = [ | 13519 | const SHAPES: [(usize, usize, usize, u32, usize, u32); 14] = [ |
| 13516 | (4, 8, 64, 9280, 64, 550), | 13520 | (4, 8, 64, 9280, 64, 550), |
| @@ -14437,7 +14441,11 @@ mod tests { | |||
| 14437 | /// wrong for one block size while looking plausible for the other. | 14441 | /// wrong for one block size while looking plausible for the other. |
| 14438 | #[test] | 14442 | #[test] |
| 14439 | fn reach_matches_libaom_has_top_right_and_has_bottom_left() { | 14443 | 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(); | ||
| 14441 | // Transcribed from has_top_right/has_bottom_left's row_off==0, | 14449 | // Transcribed from has_top_right/has_bottom_left's row_off==0, |
| 14442 | // col_off==0 (whole-transform) path, with MAX_MIB_SIZE_LOG2 = 5 (a | 14450 | // col_off==0 (whole-transform) path, with MAX_MIB_SIZE_LOG2 = 5 (a |
| 14443 | // 128px reference grid) pinned as libaom pins it, independent of the | 14451 | // 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 { | |||
| 3675 | tile_rows_log2: rows_log2, | 3675 | tile_rows_log2: rows_log2, |
| 3676 | }; | 3676 | }; |
| 3677 | let layout = format!("{}x{} tiles", 1 << cols_log2, 1 << rows_log2); | 3677 | 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()); | ||
| 3678 | let mut enc = Av1Encoder::new(config).unwrap(); | 3691 | let mut enc = Av1Encoder::new(config).unwrap(); |
| 3679 | let mut stream = Vec::new(); | 3692 | let mut stream = Vec::new(); |
| 3680 | for packet in encode_all(&mut enc, &sources) { | 3693 | for packet in encode_all(&mut enc, &sources) { |
| @@ -3693,12 +3706,12 @@ mod tests { | |||
| 3693 | if let ec_av1_syntax::ObuKind::Frame(parsed, tiles) = &obu.kind { | 3706 | if let ec_av1_syntax::ObuKind::Frame(parsed, tiles) = &obu.kind { |
| 3694 | assert_eq!( | 3707 | assert_eq!( |
| 3695 | (parsed.tile_info.cols, parsed.tile_info.rows), | 3708 | (parsed.tile_info.cols, parsed.tile_info.rows), |
| 3696 | - (1 << cols_log2, 1 << rows_log2), | 3709 | + (want_cols, want_rows), |
| 3697 | "{layout}: the header's own tile grid" | 3710 | "{layout}: the header's own tile grid" |
| 3698 | ); | 3711 | ); |
| 3699 | assert_eq!( | 3712 | assert_eq!( |
| 3700 | tiles.len(), | 3713 | tiles.len(), |
| 3701 | - 1 << (cols_log2 + rows_log2), | 3714 | + (want_cols * want_rows) as usize, |
| 3702 | "{layout}: tile payloads located in the tile group" | 3715 | "{layout}: tile payloads located in the tile group" |
| 3703 | ); | 3716 | ); |
| 3704 | frames += 1; | 3717 | frames += 1; |