Tile BD-cost knob for the gate and a 1080p tile/thread wall table
Browse files at this commitebca9e88c623a2b8ac427cae7486b40c8fcb8185Parent: bbd803c- test
- tile BD-cost knob for the gate and a 1080p tile/thread wall table
2 changed files +68 -1
- crates/ec-av1/src/encode.rs +17 -1
- crates/ec-av1/src/encoder.rs +51 -0
crates/ec-av1/src/encode.rsmodified+17 -1
| @@ -2990,7 +2990,23 @@ pub(crate) fn arm_tiles(cols_log2: u32, rows_log2: u32) { | |||
| 2990 | } | 2990 | } |
| 2991 | 2991 | ||
| 2992 | fn armed_tiles() -> (u32, u32) { | 2992 | fn armed_tiles() -> (u32, u32) { |
| 2993 | - TILE_LOG2.with(std::cell::Cell::get) | 2993 | + let armed = TILE_LOG2.with(std::cell::Cell::get); |
| 2994 | + if armed != (0, 0) { | ||
| 2995 | + return armed; | ||
| 2996 | + } | ||
| 2997 | + // `EC_AV1_TILES=<cols_log2>[:<rows_log2>]` in a TEST build, so the BD gate | ||
| 2998 | + // (which codes through `encode_sequence`, not the facade) can measure what | ||
| 2999 | + // a tile grid costs without a knob of its own -- same shape as | ||
| 3000 | + // `EC_AV1_LR`/`EC_AV1_PYRAMID`. | ||
| 3001 | + match std::env::var("EC_AV1_TILES").ok() { | ||
| 3002 | + Some(v) if cfg!(test) => { | ||
| 3003 | + let mut f = v.split(':'); | ||
| 3004 | + let cols = f.next().and_then(|c| c.parse().ok()).unwrap_or(0); | ||
| 3005 | + let rows = f.next().and_then(|r| r.parse().ok()).unwrap_or(0); | ||
| 3006 | + (cols, rows) | ||
| 3007 | + } | ||
| 3008 | + _ => armed, | ||
| 3009 | + } | ||
| 2994 | } | 3010 | } |
| 2995 | 3011 | ||
| 2996 | /// Codes a frame's `tiles` tiles, each entirely on its own (see | 3012 | /// Codes a frame's `tiles` tiles, each entirely on its own (see |
crates/ec-av1/src/encoder.rsmodified+51 -0
| @@ -1731,6 +1731,57 @@ mod tests { | |||
| 1731 | } | 1731 | } |
| 1732 | } | 1732 | } |
| 1733 | 1733 | ||
| 1734 | + /// What tiles and tile threads are worth at the size the editor exports | ||
| 1735 | + /// at: 1920x1080, eight real pictures, two passes per cell (ABAB), wall | ||
| 1736 | + /// per cell. Ignored by default (minutes). | ||
| 1737 | + #[test] | ||
| 1738 | + #[ignore = "1080p wall table: minutes, run it with --ignored"] | ||
| 1739 | + fn tile_wall_table_at_1080p() { | ||
| 1740 | + let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 1741 | + let (width, height) = (1920usize, 1080usize); | ||
| 1742 | + let Some(sources) = h264_clip_frames(width, height, 8) else { | ||
| 1743 | + eprintln!("SKIP tile_wall_table_at_1080p: no fixture"); | ||
| 1744 | + return; | ||
| 1745 | + }; | ||
| 1746 | + let layouts = [(0u32, 0u32), (1, 0), (1, 1), (2, 1)]; | ||
| 1747 | + let threadings = [1usize, 2, 4, 8]; | ||
| 1748 | + let mut table: Vec<(String, usize, f64, usize)> = Vec::new(); | ||
| 1749 | + for pass in 0..2 { | ||
| 1750 | + for &(cols_log2, rows_log2) in &layouts { | ||
| 1751 | + for &threads in &threadings { | ||
| 1752 | + crate::par::set_tile_threads(threads); | ||
| 1753 | + let config = EncoderConfig { | ||
| 1754 | + width, | ||
| 1755 | + height, | ||
| 1756 | + base_q_idx: 120, | ||
| 1757 | + gop: 8, | ||
| 1758 | + colour: Colour::Bt709Limited, | ||
| 1759 | + tile_cols_log2: cols_log2, | ||
| 1760 | + tile_rows_log2: rows_log2, | ||
| 1761 | + }; | ||
| 1762 | + let mut enc = Av1Encoder::new(config).unwrap(); | ||
| 1763 | + let start = std::time::Instant::now(); | ||
| 1764 | + let mut bytes = 0usize; | ||
| 1765 | + for picture in &sources { | ||
| 1766 | + bytes += enc.encode(picture).unwrap().data.len(); | ||
| 1767 | + } | ||
| 1768 | + let wall = start.elapsed().as_secs_f64(); | ||
| 1769 | + let name = format!("{}x{}", 1 << cols_log2, 1 << rows_log2); | ||
| 1770 | + match table.iter_mut().find(|r| r.0 == name && r.1 == threads) { | ||
| 1771 | + Some(row) => row.2 = row.2.min(wall), | ||
| 1772 | + None => table.push((name, threads, wall, bytes)), | ||
| 1773 | + } | ||
| 1774 | + let _ = pass; | ||
| 1775 | + } | ||
| 1776 | + } | ||
| 1777 | + } | ||
| 1778 | + crate::par::set_tile_threads(1); | ||
| 1779 | + eprintln!("| tiles | threads | wall (s, best of 2) | bytes |"); | ||
| 1780 | + for (name, threads, wall, bytes) in &table { | ||
| 1781 | + eprintln!("| {name} | {threads} | {wall:.2} | {bytes} |"); | ||
| 1782 | + } | ||
| 1783 | + } | ||
| 1784 | + | ||
| 1734 | /// The tiles of a frame are entropy-independent, so the bytes must not | 1785 | /// The tiles of a frame are entropy-independent, so the bytes must not |
| 1735 | /// depend on how many workers wrote them: the same stream at one tile | 1786 | /// depend on how many workers wrote them: the same stream at one tile |
| 1736 | /// thread and at four, per layout. | 1787 | /// thread and at four, per layout. |