forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'main' into lane-av1pal2

Browse files at this commit

f5fa526a8c9910e5eb5ee73c54a62910570883edAhmet Kaan GümüşParent: ace59f5fe25c8d
crates/ec-av1/src/encode.rsmodified+220 -33
@@ -3430,6 +3430,103 @@ where
34303430 Ok((out, stored))
34313431 }
34323432
3433+/// Runs `job(tile_index, ctx)` once per tile, on `EC_AV1_TILE_THREADS`
3434+/// workers, and returns the results in tile order. The counterpart of
3435+/// [`write_tiles`] for the RD/motion SEARCH: a tile's job owns every piece of
3436+/// state the search mutates (its own reconstruction planes, its own `MiGrid`,
3437+/// its own neighbour-mode bands and its own [`crate::decode::FrameCtx`]), and
3438+/// availability is already tile-relative (`clip_planes_to_tile`,
3439+/// `MiGrid::set_tile_bounds`), so what a tile decides cannot depend on which
3440+/// other tiles have run -- gated by
3441+/// `encoder::tests::tile_bytes_do_not_depend_on_the_thread_count`, which now
3442+/// covers the search as well as the write.
3443+///
3444+/// The `FrameCtx` copy is made on the calling thread (`&FrameCtx` is `!Sync`
3445+/// by design) and moved into the worker, exactly as [`crate::par::run_bands`]
3446+/// does it for the decoder's filter bands.
3447+fn search_tiles<T, F>(tiles: usize, fctx: &crate::decode::FrameCtx, job: F) -> Result<Vec<T>>
3448+where
3449+ T: Send,
3450+ F: Fn(usize, &crate::decode::FrameCtx) -> Result<T> + Sync,
3451+{
3452+ let threads = crate::par::tile_threads().min(tiles);
3453+ if threads <= 1 {
3454+ return (0..tiles).map(|index| job(index, fctx)).collect();
3455+ }
3456+ type Slot<T> = Option<Result<T>>;
3457+ let done: std::sync::Mutex<Vec<Slot<T>>> =
3458+ std::sync::Mutex::new((0..tiles).map(|_| None).collect());
3459+ {
3460+ let batch = crate::par::Batch::new("ec-av1-tile-search");
3461+ for (from, to) in crate::par::bands(tiles, threads) {
3462+ let done = &done;
3463+ let job = &job;
3464+ let ctx = crate::decode::filter_ctx_copy(fctx);
3465+ batch.submit(move || {
3466+ for index in from..to {
3467+ let searched = job(index, &ctx);
3468+ done.lock().expect("tile slots")[index] = Some(searched);
3469+ }
3470+ });
3471+ }
3472+ }
3473+ done.into_inner()
3474+ .expect("tile slots")
3475+ .into_iter()
3476+ .map(|slot| slot.expect("every tile was searched"))
3477+ .collect()
3478+}
3479+
3480+/// One tile job's own copy of a plane: the frame's source, a blank
3481+/// reconstruction of the frame's size, and the frame's own bounds -- narrowed
3482+/// to the tile by `clip_planes_to_tile` right after. Blank rather than a copy
3483+/// of the frame's reconstruction because a tile's prediction never reads a
3484+/// sample outside its own rectangle, and every sample inside it is written
3485+/// before it is read.
3486+fn fresh_plane(source: &[u8], width: usize, height: usize, true_width: usize, true_height: usize) -> Plane<'_> {
3487+ Plane {
3488+ source,
3489+ reconstruction: vec![128; source.len()],
3490+ width,
3491+ height,
3492+ true_width,
3493+ true_height,
3494+ tile_x0: 0,
3495+ tile_y0: 0,
3496+ tile_x1: width,
3497+ tile_y1: height,
3498+ }
3499+}
3500+
3501+/// Copies the rectangle `[x0, x1) x [y0, y1)` of a tile job's own plane into
3502+/// the frame's plane, through the [`crate::par::Shared`] every job holds.
3503+///
3504+/// corner-cut: the disjointness that makes the aliasing sound is the caller's
3505+/// -- `x0..x1`/`y0..y1` are the job's own `TileRect`, and a frame's tile
3506+/// rectangles partition it -- checked end-to-end by
3507+/// `tile_bytes_do_not_depend_on_the_thread_count` rather than by the borrow
3508+/// checker, exactly the contract `Shared`'s own doc names. Upgrade path is
3509+/// row-range `split_at_mut` plumbing through `Plane`, which would have to
3510+/// thread an origin offset through every prediction and transform call site
3511+/// for the same bytes.
3512+#[allow(unsafe_code)]
3513+fn copy_rect(
3514+ dst: crate::par::Shared<'_, Vec<u8>>,
3515+ src: &[u8],
3516+ stride: usize,
3517+ x0: usize,
3518+ y0: usize,
3519+ x1: usize,
3520+ y1: usize,
3521+) {
3522+ // SAFETY: this job touches only its own tile rectangle (see above).
3523+ let dst = unsafe { dst.get() };
3524+ for y in y0..y1 {
3525+ let (a, b) = (y * stride + x0, y * stride + x1);
3526+ dst[a..b].copy_from_slice(&src[a..b]);
3527+ }
3528+}
3529+
34333530 /// The frame header's `tile_info` (spec 5.9.15) for `layout`:
34343531 /// `context_update_tile_id` names the largest tile, whose end-of-tile CDF
34353532 /// tables the frame stores (spec 7.20), which is what
@@ -3697,8 +3794,6 @@ pub(crate) fn encode_key_frame_inner(
36973794 // symbol the writer will actually write.
36983795 // The bookkeeping is kept on the 16x16 grid the tile writer keeps it on,
36993796 // because a 32x32 block may be split into four 16x16 ones.
3700- let mut above_mode = vec![DC_PRED; cols * 2];
3701- let mut left_mode = vec![DC_PRED; rows * 2];
37023797 let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));
37033798 // This frame's tile grid (one tile unless the facade armed more).
37043799 let layout =
@@ -3709,15 +3804,36 @@ pub(crate) fn encode_key_frame_inner(
37093804 // `mi_row_starts`), which is what makes the writer's rects and the
37103805 // reader's the same rects.
37113806 let header_tile_info = header.tile_info.clone();
3712- let mut superblocks = Vec::with_capacity(sb_cols * sb_rows);
3713- let mut modes = Vec::with_capacity(cols * rows);
3714- for sb_row in 0..sb_rows {
3715- for sb_col in 0..sb_cols {
3716- clip_planes_to_tile(
3717- &mut luma,
3718- &mut chroma,
3719- layout.rect(layout.index_of_sb(sb_row as u32, sb_col as u32)),
3720- );
3807+ // lane-av1tsearch: the search runs once per TILE (`search_tiles`), not
3808+ // once over the whole frame. Each tile job builds its own reconstruction
3809+ // planes and its own `above_mode`/`left_mode` bands, which is also what
3810+ // the tile writer reads -- a tile resets its neighbour contexts (spec
3811+ // 5.11.1), so a block at a tile's left edge must cost its mode against
3812+ // the default context, not against whatever the tile to its west left in
3813+ // that row. At one tile the bands are the frame's, exactly as before.
3814+ let (frame_width, frame_height) = (picture.width, picture.height);
3815+ let luma_out = crate::par::Shared::new(&mut luma.reconstruction);
3816+ let [cb, cr] = &mut chroma;
3817+ let chroma_out = [
3818+ crate::par::Shared::new(&mut cb.reconstruction),
3819+ crate::par::Shared::new(&mut cr.reconstruction),
3820+ ];
3821+ let search_tile = |index: usize,
3822+ fctx: &crate::decode::FrameCtx|
3823+ -> Result<Vec<(usize, Superblock, Vec<u8>)>> {
3824+ let rect = layout.rect(index);
3825+ let mut luma = fresh_plane(&picture_y8, frame_width, frame_height, true_width, true_height);
3826+ let mut chroma = [
3827+ fresh_plane(&picture_u8, frame_width / 2, frame_height / 2, true_width / 2, true_height / 2),
3828+ fresh_plane(&picture_v8, frame_width / 2, frame_height / 2, true_width / 2, true_height / 2),
3829+ ];
3830+ clip_planes_to_tile(&mut luma, &mut chroma, rect);
3831+ let mut above_mode = vec![DC_PRED; cols * 2];
3832+ let mut left_mode = vec![DC_PRED; rows * 2];
3833+ let mut coded: Vec<(usize, Superblock, Vec<u8>)> = Vec::new();
3834+ for sb_row in rect.sb_row0 as usize..rect.sb_row1 as usize {
3835+ for sb_col in rect.sb_col0 as usize..rect.sb_col1 as usize {
3836+ let mut modes = Vec::with_capacity(4);
37213837 // The quadrants of a superblock are coded in the order the decoder
37223838 // walks them, which for a 64x64 split into 32x32 blocks is raster
37233839 // order among the quadrants that are inside the frame.
@@ -3901,8 +4017,39 @@ pub(crate) fn encode_key_frame_inner(
39014017 blocks.push(Quadrant::Whole(whole));
39024018 }
39034019 }
3904- superblocks.push(Superblock::Split(blocks));
4020+ coded.push((sb_row * sb_cols + sb_col, Superblock::Split(blocks), modes));
4021+ }
4022+ }
4023+ let (x0, y0) = (rect.mi_col0 as usize * 4, rect.mi_row0 as usize * 4);
4024+ let (x1, y1) = (rect.mi_col1 as usize * 4, rect.mi_row1 as usize * 4);
4025+ copy_rect(luma_out, &luma.reconstruction, frame_width, x0, y0, x1, y1);
4026+ for (&out, tile) in chroma_out.iter().zip(&chroma) {
4027+ copy_rect(
4028+ out,
4029+ &tile.reconstruction,
4030+ frame_width / 2,
4031+ x0 / 2,
4032+ y0 / 2,
4033+ x1.div_ceil(2),
4034+ y1.div_ceil(2),
4035+ );
39054036 }
4037+ Ok(coded)
4038+ };
4039+ let searched = search_tiles(layout.count(), fctx, search_tile)?;
4040+ // Back into frame raster order: the tile writer indexes `superblocks` by
4041+ // the frame's own superblock index, and `modes` is the coding order the
4042+ // ablation drivers read.
4043+ let mut in_order: Vec<Option<(Superblock, Vec<u8>)>> = (0..sb_cols * sb_rows).map(|_| None).collect();
4044+ for (at, superblock, block_modes) in searched.into_iter().flatten() {
4045+ in_order[at] = Some((superblock, block_modes));
4046+ }
4047+ let mut superblocks = Vec::with_capacity(sb_cols * sb_rows);
4048+ let mut modes = Vec::with_capacity(cols * rows);
4049+ for slot in in_order {
4050+ let (superblock, block_modes) = slot.expect("every superblock belongs to a tile");
4051+ superblocks.push(superblock);
4052+ modes.extend_from_slice(&block_modes);
39064053 }
39074054
39084055 #[cfg(test)]
@@ -5348,7 +5495,7 @@ pub(crate) fn encode_inter_frame(
53485495 // whenever the true size is not a 64x64 multiple.
53495496 let (cols, rows) = crate::tile::block_grid(header.mi_cols, header.mi_rows);
53505497 let (cols, rows) = (cols as usize, rows as usize);
5351- let (sb_cols, sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));
5498+ let (sb_cols, _sb_rows) = (cols.div_ceil(2), rows.div_ceil(2));
53525499 let (mi_cols, mi_rows) = (header.mi_cols as usize, header.mi_rows as usize);
53535500 // This frame's tile grid, as in `encode_key_frame_inner`.
53545501 let (tile_cols_log2, tile_rows_log2) = armed_tiles();
@@ -5360,24 +5507,42 @@ pub(crate) fn encode_inter_frame(
53605507 // integer-`u8`-scale), so the DPB reference plane is narrowed for it --
53615508 // once per frame (lane-av1rd2), not once per block, which is a whole
53625509 // plane's map per 32x32 block and now per leaf too.
5363- let mut grid = MiGrid::new(mi_cols, mi_rows);
5364- grid.set_sign_bias(sign_bias);
53655510 let mut blocks = vec![Quadrant::Whole(BlockCoeffs::default()); cols * rows];
5366-
5367- for sb_r in 0..sb_rows {
5368- for sb_c in 0..sb_cols {
5369- // Neighbour availability -- intra edges and the MV stack's
5370- // scans alike -- stops at this superblock's own tile, exactly
5371- // where the decoder stops it (`PlaneBuf::set_tile_origin`,
5372- // `MiGrid::set_tile_bounds`).
5373- let rect = layout.rect(layout.index_of_sb(sb_r as u32, sb_c as u32));
5374- clip_planes_to_tile(&mut luma, &mut chroma, rect);
5375- grid.set_tile_bounds(
5376- rect.mi_row0 as usize,
5377- rect.mi_col0 as usize,
5378- rect.mi_row1 as usize,
5379- rect.mi_col1 as usize,
5380- );
5511+ // lane-av1tsearch: one search job per TILE (`search_tiles`). Neighbour
5512+ // availability -- intra edges and the MV stack's scans alike -- already
5513+ // stopped at the superblock's own tile (`PlaneBuf::set_tile_origin`,
5514+ // `MiGrid::set_tile_bounds`), so a tile reads nothing another tile wrote;
5515+ // giving each job its own planes and its own `MiGrid` therefore leaves
5516+ // every decision, and so every coded bit, exactly where the whole-frame
5517+ // loop left it, at any tile count and any thread count.
5518+ let (frame_width, frame_height) = (picture.width, picture.height);
5519+ let luma_out = crate::par::Shared::new(&mut luma.reconstruction);
5520+ let [cb, cr] = &mut chroma;
5521+ let chroma_out = [
5522+ crate::par::Shared::new(&mut cb.reconstruction),
5523+ crate::par::Shared::new(&mut cr.reconstruction),
5524+ ];
5525+ let search_tile = |index: usize,
5526+ fctx: &crate::decode::FrameCtx|
5527+ -> Result<Vec<(usize, Quadrant)>> {
5528+ let rect = layout.rect(index);
5529+ let mut luma = fresh_plane(&picture_y8, frame_width, frame_height, true_width, true_height);
5530+ let mut chroma = [
5531+ fresh_plane(&picture_u8, frame_width / 2, frame_height / 2, true_width / 2, true_height / 2),
5532+ fresh_plane(&picture_v8, frame_width / 2, frame_height / 2, true_width / 2, true_height / 2),
5533+ ];
5534+ clip_planes_to_tile(&mut luma, &mut chroma, rect);
5535+ let mut grid = MiGrid::new(mi_cols, mi_rows);
5536+ grid.set_sign_bias(sign_bias);
5537+ grid.set_tile_bounds(
5538+ rect.mi_row0 as usize,
5539+ rect.mi_col0 as usize,
5540+ rect.mi_row1 as usize,
5541+ rect.mi_col1 as usize,
5542+ );
5543+ let mut blocks: Vec<(usize, Quadrant)> = Vec::new();
5544+ for sb_r in rect.sb_row0 as usize..rect.sb_row1 as usize {
5545+ for sb_c in rect.sb_col0 as usize..rect.sb_col1 as usize {
53815546 for quadrant in 0..4 {
53825547 let (r32, c32) = (sb_r * 2 + quadrant / 2, sb_c * 2 + quadrant % 2);
53835548 // Same filter as the tile writer's: a quadrant whose own mi
@@ -5602,14 +5767,14 @@ pub(crate) fn encode_inter_frame(
56025767 // grid, and their reconstruction is what the
56035768 // planes hold.
56045769 partition_hit(1);
5605- blocks[r32 * cols + c32] = Quadrant::Split(leaves);
5770+ blocks.push((r32 * cols + c32, Quadrant::Split(leaves)));
56065771 continue;
56075772 }
56085773 restore(&mut luma, &mut chroma, (x, y), BLOCK, &after_whole);
56095774 }
56105775 partition_hit(0);
56115776 record_mi(&mut grid, mi_row, mi_col, 8, block.inter);
5612- blocks[r32 * cols + c32] = Quadrant::Whole(block);
5777+ blocks.push((r32 * cols + c32, Quadrant::Whole(block)));
56135778 } else {
56145779 // The sub-positions actually inside the true frame, same
56155780 // filter as `sb_coeff_inter_frame_tile`'s `sub_positions`.
@@ -5774,11 +5939,33 @@ pub(crate) fn encode_inter_frame(
57745939 });
57755940 }
57765941 }
5777- blocks[r32 * cols + c32] = Quadrant::Split(leaves);
5942+ blocks.push((r32 * cols + c32, Quadrant::Split(leaves)));
57785943 }
57795944 }
57805945 }
57815946 }
5947+ let (x0, y0) = (rect.mi_col0 as usize * 4, rect.mi_row0 as usize * 4);
5948+ let (x1, y1) = (rect.mi_col1 as usize * 4, rect.mi_row1 as usize * 4);
5949+ copy_rect(luma_out, &luma.reconstruction, frame_width, x0, y0, x1, y1);
5950+ for (&out, tile) in chroma_out.iter().zip(&chroma) {
5951+ copy_rect(
5952+ out,
5953+ &tile.reconstruction,
5954+ frame_width / 2,
5955+ x0 / 2,
5956+ y0 / 2,
5957+ x1.div_ceil(2),
5958+ y1.div_ceil(2),
5959+ );
5960+ }
5961+ Ok(blocks)
5962+ };
5963+ for (at, quadrant) in search_tiles(layout.count(), fctx, search_tile)?
5964+ .into_iter()
5965+ .flatten()
5966+ {
5967+ blocks[at] = quadrant;
5968+ }
57825969
57835970 let modes = blocks
57845971 .iter()
crates/ec-av1/src/encoder.rsmodified+165 -0
@@ -1839,6 +1839,171 @@ mod tests {
18391839 crate::par::set_tile_threads(1);
18401840 }
18411841
1842+ /// What the per-tile search (lane-av1tsearch) is worth in wall and in
1843+ /// frames per second at the editor's own export sizes: every tile layout
1844+ /// crossed with every tile-thread count, plus librav1e at the matching
1845+ /// `tile_cols`/`tile_rows`/`threads` as the reference point. Two passes
1846+ /// over the whole table (A,B,A,B... rather than AA,BB) with the best of
1847+ /// the two kept, so a thermal drift cannot order the rows.
1848+ ///
1849+ /// Measurement, not a pass/fail gate: it asserts only that every cell
1850+ /// produced a stream.
1851+ #[test]
1852+ #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
1853+ fn tile_search_wall_1080p() {
1854+ tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]);
1855+ }
1856+
1857+ /// The same table at the 4K frame size the editor exports (3840x1608),
1858+ /// at the two layouts with enough tiles to fill this box.
1859+ #[test]
1860+ #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
1861+ fn tile_search_wall_4k() {
1862+ tile_search_wall(3840, 1608, 6, &[(2, 1), (3, 2)], &[1, 8, 12]);
1863+ }
1864+
1865+ fn tile_search_wall(
1866+ width: usize,
1867+ height: usize,
1868+ frames: usize,
1869+ layouts: &[(u32, u32)],
1870+ threads: &[usize],
1871+ ) {
1872+ let _gate_lock = crate::stream::tests::lock_gate_counters();
1873+ let Some(sources) = h264_clip_frames(width, height, frames) else {
1874+ eprintln!("SKIP the tile-search wall table: no fixture or no ffmpeg");
1875+ return;
1876+ };
1877+ let run = |cols_log2: u32, rows_log2: u32, t: usize| -> (std::time::Duration, usize) {
1878+ crate::par::set_tile_threads(t);
1879+ let config = EncoderConfig {
1880+ width,
1881+ height,
1882+ base_q_idx: 120,
1883+ gop: frames,
1884+ colour: Colour::Bt709Limited,
1885+ tile_cols_log2: cols_log2,
1886+ tile_rows_log2: rows_log2,
1887+ };
1888+ let mut enc = Av1Encoder::new(config).unwrap();
1889+ let start = std::time::Instant::now();
1890+ let mut bytes = 0usize;
1891+ for picture in &sources {
1892+ bytes += enc.encode(picture).unwrap().data.len();
1893+ }
1894+ (start.elapsed(), bytes)
1895+ };
1896+ let cells: Vec<((u32, u32), usize)> = layouts
1897+ .iter()
1898+ .flat_map(|&l| threads.iter().map(move |&t| (l, t)))
1899+ .collect();
1900+ let mut best: Vec<Option<(std::time::Duration, usize)>> = vec![None; cells.len()];
1901+ for _pass in 0..2 {
1902+ for (i, &((c, r), t)) in cells.iter().enumerate() {
1903+ let got = run(c, r, t);
1904+ assert!(got.1 > 0, "{}x{} tiles at {t} threads: empty stream", 1 << c, 1 << r);
1905+ if best[i].is_none_or(|(w, _)| got.0 < w) {
1906+ best[i] = Some(got);
1907+ }
1908+ }
1909+ }
1910+ crate::par::set_tile_threads(1);
1911+ eprintln!("\n{width}x{height}, {frames} frames, base_q_idx 120 -- best of two passes");
1912+ eprintln!("| layout | tiles | threads | wall | fps | speedup vs 1 tile 1 thread | bytes |");
1913+ let base = best[0].expect("the first cell ran").0.as_secs_f64();
1914+ for (i, &((c, r), t)) in cells.iter().enumerate() {
1915+ let (wall, bytes) = best[i].expect("every cell ran");
1916+ let secs = wall.as_secs_f64();
1917+ eprintln!(
1918+ "| {}x{} | {} | {t} | {secs:.2}s | {:.2} | {:.2}x | {bytes} |",
1919+ 1 << c,
1920+ 1 << r,
1921+ 1 << (c + r),
1922+ frames as f64 / secs,
1923+ base / secs,
1924+ );
1925+ }
1926+ // Parallel efficiency per layout: what the extra threads actually
1927+ // took off that layout's own single-threaded wall, and so what share
1928+ // of the added cores sat idle.
1929+ for &(c, r) in layouts {
1930+ let one = cells
1931+ .iter()
1932+ .position(|&(l, t)| l == (c, r) && t == threads[0])
1933+ .map(|i| best[i].expect("cell").0.as_secs_f64());
1934+ let Some(one) = one else { continue };
1935+ for &t in &threads[1..] {
1936+ let i = cells.iter().position(|&(l, tt)| l == (c, r) && tt == t).expect("cell");
1937+ let secs = best[i].expect("cell").0.as_secs_f64();
1938+ let workers = (t.min(1 << (c + r))) as f64 / threads[0] as f64;
1939+ let speedup = one / secs;
1940+ eprintln!(
1941+ "{}x{} tiles, {} -> {t} threads: {speedup:.2}x of a possible {workers:.2}x, \
1942+ idle share {:.0}%",
1943+ 1 << c,
1944+ 1 << r,
1945+ threads[0],
1946+ 100.0 * (1.0 - speedup / workers).max(0.0),
1947+ );
1948+ }
1949+ }
1950+ rav1e_wall_reference(width, height, frames, layouts, threads);
1951+ }
1952+
1953+ /// librav1e at the same sizes, layouts and thread counts, through ffmpeg
1954+ /// -- the reference the wall table is read against.
1955+ fn rav1e_wall_reference(
1956+ width: usize,
1957+ height: usize,
1958+ frames: usize,
1959+ layouts: &[(u32, u32)],
1960+ threads: &[usize],
1961+ ) {
1962+ let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
1963+ .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4");
1964+ let listed = Command::new("ffmpeg").args(["-hide_banner", "-encoders"]).output();
1965+ let has_rav1e = listed
1966+ .map(|o| String::from_utf8_lossy(&o.stdout).contains("librav1e"))
1967+ .unwrap_or(false);
1968+ if !has_rav1e || !clip.exists() {
1969+ eprintln!("SKIP the rav1e reference: no librav1e or no fixture");
1970+ return;
1971+ }
1972+ eprintln!("| rav1e layout | threads | wall | fps | bytes |");
1973+ for &(c, r) in layouts {
1974+ for &t in threads {
1975+ let out = std::env::temp_dir().join(format!("ec-av1-rav1e-{}.ivf", std::process::id()));
1976+ let params = format!(
1977+ "speed=6:quantizer=100:tile_cols={}:tile_rows={}:threads={t}",
1978+ 1 << c,
1979+ 1 << r
1980+ );
1981+ let start = std::time::Instant::now();
1982+ let status = Command::new("ffmpeg")
1983+ .args(["-v", "error", "-y", "-i", clip.to_str().unwrap()])
1984+ .args(["-frames:v", &frames.to_string()])
1985+ .args(["-vf", &format!("scale={width}:{height}")])
1986+ .args(["-c:v", "librav1e", "-rav1e-params", &params])
1987+ .arg(out.to_str().unwrap())
1988+ .output()
1989+ .expect("ffmpeg failed to run");
1990+ let secs = start.elapsed().as_secs_f64();
1991+ if !status.status.success() {
1992+ eprintln!("| {}x{} | {t} | FAILED: {} |", 1 << c, 1 << r, String::from_utf8_lossy(&status.stderr).lines().last().unwrap_or(""));
1993+ continue;
1994+ }
1995+ let bytes = std::fs::metadata(&out).map(|m| m.len()).unwrap_or(0);
1996+ let _ = std::fs::remove_file(&out);
1997+ eprintln!(
1998+ "| {}x{} | {t} | {secs:.2}s | {:.2} | {bytes} |",
1999+ 1 << c,
2000+ 1 << r,
2001+ frames as f64 / secs
2002+ );
2003+ }
2004+ }
2005+ }
2006+
18422007 /// The same round trip at a real 1920x1080 crop of the gate's own clip
18432008 /// -- the size the editor's export actually runs at, where a tile grid
18442009 /// is worth having. Ignored by default only for its wall (a 1080p
crates/ec-av1/src/par.rsmodified+14 -4
@@ -56,11 +56,21 @@ pub(crate) fn set_filter_threads(n: usize) {
5656 }
5757
5858 /// `EC_AV1_TILE_THREADS`, how many workers the ENCODER spreads a frame's
59-/// tiles across (default 1 = the shipped single-threaded write). Tiles are
60-/// entropy-independent by construction (each starts from the frame's own
61-/// tables and resets its own contexts), so the bytes a frame comes out as do
62-/// not depend on this -- `encoder::tests::tile_bytes_do_not_depend_on_the_
59+/// tiles across -- both the RD/motion SEARCH (`encode::search_tiles`) and the
60+/// entropy WRITE (`encode::write_tiles`); default 1 = the shipped
61+/// single-threaded encode. Tiles are independent by construction (each starts
62+/// from the frame's own tables, resets its own contexts, and reads no sample
63+/// and no mode outside its own rectangle), so the bytes a frame comes out as
64+/// do not depend on this -- `encoder::tests::tile_bytes_do_not_depend_on_the_
6365 /// thread_count` is the pin.
66+///
67+/// Measured (lane-av1tsearch, 12-core box, best of two interleaved passes):
68+/// 1920x1080, 12 frames -- 11.49 s at one tile (any thread count), 6.98 s at
69+/// 4x2 tiles and 8 threads (1.65x, 1.04 -> 1.72 fps); 3840x1608, 6 frames --
70+/// 17.12 s at 4x2 tiles and one thread, 8.64 s at 8 (1.98x, 0.35 -> 0.69
71+/// fps). Past ~8 tiles the extra tiles cost bytes without buying wall: what
72+/// is left is the per-frame serial tail (the filter search re-decodes the
73+/// whole frame), ~43% of an inter frame by Amdahl on those numbers.
6474 static TILE_THREADS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
6575
6676 pub(crate) fn tile_threads() -> usize {
crates/ec-av1/src/tile.rsmodified+0 -9
@@ -238,15 +238,6 @@ impl TileLayout {
238238 }
239239 }
240240
241- /// Which tile the superblock at `(sb_r, sb_c)` belongs to -- what the
242- /// encoder's frame-raster search consults to clip a block's neighbour
243- /// availability to its own tile.
244- pub(crate) fn index_of_sb(&self, sb_r: u32, sb_c: u32) -> usize {
245- let col = self.col_starts_sb[1..].partition_point(|&s| s <= sb_c);
246- let row = self.row_starts_sb[1..].partition_point(|&s| s <= sb_r);
247- row * self.cols() as usize + col
248- }
249-
250241 /// The largest tile by mi area, `context_update_tile_id`'s own rule
251242 /// (spec 6.8.14 leaves the choice to the encoder; libaom and rav1e both
252243 /// name the biggest tile, whose end-of-tile tables the frame stores).