forge
Explore
Log in

Don't you dare go Hollow

wip(av1): lane-chroma r3 smooth-intra gate green path + chroma work, committed at the 75-turn cap

Browse files at this commit

f4a11cdc7ac6b8c010f3110174713978e5915235Ahmet Kaan GümüşParent: d627fbc
Committed verbatim by the orchestrator so the work survives the cap; state
unverified by me.
crates/ec-av1/src/decode.rsmodified+76 -23
@@ -81,6 +81,21 @@ pub(crate) fn smooth_luma_hits() -> usize {
8181 SMOOTH_LUMA_HITS.with(|c| c.get())
8282 }
8383
84+/// How many `uv_mode` reads resolved to `SMOOTH_PRED..=PAETH_PRED` (9..=12),
85+/// across every call in the process -- lane-chroma r3's own before/after
86+/// counter, proving a stream actually exercised chroma's smooth/paeth
87+/// predictor (the previously-refused round-2 gap) rather than every block
88+/// landing on DC/CFL/directional.
89+thread_local! {
90+ static SMOOTH_UV_HITS: std::cell::Cell<usize> =
91+ const { std::cell::Cell::new(0) };
92+}
93+
94+/// Current value of [`SMOOTH_UV_HITS`].
95+pub(crate) fn smooth_uv_hits() -> usize {
96+ SMOOTH_UV_HITS.with(|c| c.get())
97+}
98+
8499 /// How many 4-pixel deblocking edge groups [`edge_params`] has actually
85100 /// selected for filtering, across every call in the process -- the same
86101 /// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
@@ -1263,6 +1278,17 @@ struct Neighbours {
12631278 left: Vec<[Neighbour; 3]>,
12641279 above_mode: Vec<usize>,
12651280 left_mode: Vec<usize>,
1281+ /// Chroma's own `uv_mode` companion to `above_mode`/`left_mode` (lane-chroma
1282+ /// r3): a smooth/paeth `uv_mode`'s edge-filter strength (spec
1283+ /// `get_intra_edge_filter_type`) reads the CHROMA neighbour's mode, not the
1284+ /// luma one -- the same block can (and often does) code a different
1285+ /// `uv_mode` than its own `mode`. Coarse [`SUB`]-grid like `above_mode`;
1286+ /// [`Self::decode_leaf8`]'s per-leaf `prev_leaf` override (a real
1287+ /// within-block neighbour finer than this grid) is luma-only -- a known,
1288+ /// unexercised-by-gate corner-cut (every real-encoder gate in `stream.rs`
1289+ /// uses `--min-partition-size=16`, so no leaf8 8x8 split ever reaches this).
1290+ above_uv_mode: Vec<usize>,
1291+ left_uv_mode: Vec<usize>,
12661292 above_side: Vec<usize>,
12671293 left_side: Vec<usize>,
12681294 /// The same as `above_side`/`left_side`, but kept at the finer mi (4x4)
@@ -1362,6 +1388,8 @@ impl Neighbours {
13621388 left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)],
13631389 above_mode: vec![DC_PRED; cols],
13641390 left_mode: vec![DC_PRED; rows],
1391+ above_uv_mode: vec![DC_PRED; cols],
1392+ left_uv_mode: vec![DC_PRED; rows],
13651393 above_side: vec![SB; cols],
13661394 left_side: vec![SB; rows],
13671395 above_side_mi: vec![SB; cols * (SUB / MI)],
@@ -1495,6 +1523,7 @@ impl Neighbours {
14951523 fn start_row(&mut self) {
14961524 self.left.iter_mut().for_each(|l| *l = Default::default());
14971525 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
1526+ self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED);
14981527 self.left_side.iter_mut().for_each(|s| *s = SB);
14991528 self.left_side_mi.iter_mut().for_each(|s| *s = SB);
15001529 self.left_skip.iter_mut().for_each(|s| *s = false);
@@ -1726,8 +1755,15 @@ impl Neighbours {
17261755 /// `record` leaves them (spec `av1_set_entropy_contexts`, which clamps to
17271756 /// `blocks_wide`/`blocks_high` derived from the true `mi_cols`/`mi_rows`,
17281757 /// not from this block's own side).
1729- fn record(&mut self, at: (usize, usize), side: usize, mode: usize, grids: &[Vec<i32>; 3]) {
1730- self.record_rect(at, side, side, mode, grids);
1758+ fn record(
1759+ &mut self,
1760+ at: (usize, usize),
1761+ side: usize,
1762+ mode: usize,
1763+ uv_mode: usize,
1764+ grids: &[Vec<i32>; 3],
1765+ ) {
1766+ self.record_rect(at, side, side, mode, uv_mode, grids);
17311767 }
17321768
17331769 /// [`Self::record`] with independent above (`w`)/left (`h`) extents, in
@@ -1741,15 +1777,18 @@ impl Neighbours {
17411777 w: usize,
17421778 h: usize,
17431779 mode: usize,
1780+ uv_mode: usize,
17441781 grids: &[Vec<i32>; 3],
17451782 ) {
17461783 let (r, c) = at;
17471784 for cell in 0..w / SUB {
17481785 self.above_mode[c + cell] = mode;
1786+ self.above_uv_mode[c + cell] = uv_mode;
17491787 self.above_side[c + cell] = w;
17501788 }
17511789 for cell in 0..h / SUB {
17521790 self.left_mode[r + cell] = mode;
1791+ self.left_uv_mode[r + cell] = uv_mode;
17531792 self.left_side[r + cell] = h;
17541793 }
17551794 self.record_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h, grids);
@@ -1848,12 +1887,15 @@ impl Neighbours {
18481887 at: (usize, usize),
18491888 side: usize,
18501889 mode: usize,
1890+ uv_mode: usize,
18511891 chroma_grids: [&[i32]; 2],
18521892 ) {
18531893 let (r, c) = at;
18541894 for cell in 0..side / SUB {
18551895 self.above_mode[c + cell] = mode;
18561896 self.left_mode[r + cell] = mode;
1897+ self.above_uv_mode[c + cell] = uv_mode;
1898+ self.left_uv_mode[r + cell] = uv_mode;
18571899 self.above_side[c + cell] = side;
18581900 self.left_side[r + cell] = side;
18591901 }
@@ -1989,7 +2031,7 @@ fn read_intra_mode_rect(
19892031 None
19902032 };
19912033 if (9..=12).contains(&uv_mode) {
1992- return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
2034+ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
19932035 }
19942036 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
19952037 DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
@@ -2112,13 +2154,16 @@ fn decode_block_rect(
21122154 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
21132155 allow_screen_content_tools,
21142156 )?;
2115- // See [`PlaneBuf::reconstruct`]'s doc: chroma stays `false` (exact) until
2116- // a smooth/paeth `uv_mode` can reach decode at all.
21172157 let smooth_neighbor =
21182158 is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
21192159 if smooth_neighbor {
21202160 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
21212161 }
2162+ // lane-chroma r3: chroma's own edge-filter-strength neighbour check
2163+ // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's
2164+ // `uv_mode`, not the luma one.
2165+ let smooth_neighbor_uv =
2166+ is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]);
21222167 if filter_intra.is_some() {
21232168 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
21242169 // decoder (`assert_eq!(dst.len(), side*side)`) -- a real symbol was
@@ -2198,7 +2243,7 @@ fn decode_block_rect(
21982243 &vec![0i32; chroma_w * chroma_h],
21992244 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
22002245 None,
2201- false,
2246+ smooth_neighbor_uv,
22022247 );
22032248 v.reconstruct_rect(
22042249 cpx,
@@ -2211,13 +2256,14 @@ fn decode_block_rect(
22112256 &vec![0i32; chroma_w * chroma_h],
22122257 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
22132258 None,
2214- false,
2259+ smooth_neighbor_uv,
22152260 );
22162261 neighbours.record_rect(
22172262 at,
22182263 bw,
22192264 bh,
22202265 mode,
2266+ uv_predict_mode,
22212267 &[
22222268 vec![0i32; bw * bh],
22232269 vec![0i32; chroma_w * chroma_h],
@@ -2344,7 +2390,7 @@ fn decode_block_rect(
23442390 &u_residual,
23452391 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
23462392 None,
2347- false,
2393+ smooth_neighbor_uv,
23482394 );
23492395 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
23502396 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
@@ -2382,9 +2428,9 @@ fn decode_block_rect(
23822428 &v_residual,
23832429 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
23842430 None,
2385- false,
2431+ smooth_neighbor_uv,
23862432 );
2387- neighbours.record_rect(at, bw, bh, mode, &[luma_levels, u_levels, v_levels]);
2433+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]);
23882434 RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
23892435 }
23902436 }
@@ -2490,7 +2536,7 @@ fn read_intra_mode(
24902536 // bug in that fallback this lane's own scope does not cover. Keep it
24912537 // refused here rather than ship a silently-wrong decode.
24922538 if (9..=12).contains(&uv_mode) {
2493- return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
2539+ SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
24942540 }
24952541 // `get_uv_mode` (spec 9.3): `UV_CFL_PRED` predicts as `DC_PRED` for the
24962542 // angle-delta question -- libaom's own `read_intra_frame_mode_info` reads
@@ -3032,13 +3078,13 @@ fn decode_block(
30323078 } else {
30333079 uv_mode
30343080 };
3035- // See [`PlaneBuf::reconstruct`]'s doc: chroma stays `false` (exact) until
3036- // a smooth/paeth `uv_mode` can reach decode at all.
30373081 let smooth_neighbor =
30383082 is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
30393083 if smooth_neighbor {
30403084 SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
30413085 }
3086+ let smooth_neighbor_uv =
3087+ is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]);
30423088 if std::env::var_os("EC_AV1_TRACE").is_some() {
30433089 eprintln!(
30443090 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
@@ -3093,7 +3139,7 @@ fn decode_block(
30933139 &vec![0i32; chroma_side * chroma_side],
30943140 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
30953141 None,
3096- false,
3142+ smooth_neighbor_uv,
30973143 );
30983144 v.reconstruct(
30993145 cpx,
@@ -3105,12 +3151,12 @@ fn decode_block(
31053151 &vec![0i32; chroma_side * chroma_side],
31063152 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
31073153 None,
3108- false,
3154+ smooth_neighbor_uv,
31093155 );
31103156 let luma_grid = vec![0i32; side * side];
31113157 let u_grid = vec![0i32; chroma_side * chroma_side];
31123158 let v_grid = vec![0i32; chroma_side * chroma_side];
3113- neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);
3159+ neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);
31143160 } else if !tx_select || logical_tx == side {
31153161 // A single luma transform unit -- the old path, unchanged (including
31163162 // the 64x64 corner case, `logical_tx == side == 64` with
@@ -3159,7 +3205,7 @@ fn decode_block(
31593205 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
31603206 None,
31613207 None,
3162- false,
3208+ smooth_neighbor_uv,
31633209 )?;
31643210 if std::env::var_os("EC_AV1_TRACE").is_some() {
31653211 eprintln!(
@@ -3187,9 +3233,9 @@ fn decode_block(
31873233 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
31883234 None,
31893235 None,
3190- false,
3236+ smooth_neighbor_uv,
31913237 )?;
3192- neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);
3238+ neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]);
31933239 } else {
31943240 // Several luma transform units, raster order (spec
31953241 // `transform_block`'s loop): the block's resolved transform is
@@ -3268,7 +3314,7 @@ fn decode_block(
32683314 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
32693315 None,
32703316 None,
3271- false,
3317+ smooth_neighbor_uv,
32723318 )?;
32733319 let v_grid = read_plane(
32743320 dec,
@@ -3290,9 +3336,9 @@ fn decode_block(
32903336 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
32913337 None,
32923338 None,
3293- false,
3339+ smooth_neighbor_uv,
32943340 )?;
3295- neighbours.record_split_luma(at, side, mode, [&u_grid, &v_grid]);
3341+ neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&u_grid, &v_grid]);
32963342 }
32973343 neighbours.fill_skip_grid((r * (SUB / MI), c * (SUB / MI)), side / MI, skip);
32983344 neighbours.fill_lf_grid(
@@ -8029,7 +8075,14 @@ fn decode_inter_block(
80298075 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0
80308076 );
80318077 }
8032- neighbours.record_rect(at, write_w, write_h, mode_for_tx, &[luma_grid, u_grid, v_grid]);
8078+ neighbours.record_rect(
8079+ at,
8080+ write_w,
8081+ write_h,
8082+ mode_for_tx,
8083+ DC_PRED,
8084+ &[luma_grid, u_grid, v_grid],
8085+ );
80338086 neighbours.record_inter_rect(
80348087 at,
80358088 write_w,
crates/ec-av1/src/stream.rsmodified+126 -0
@@ -1846,6 +1846,132 @@ mod tests {
18461846 );
18471847 }
18481848
1849+ /// The smooth/paeth-chroma gate (lane-chroma r1/r3): a real aomenc key
1850+ /// frame with `--enable-smooth-intra=1 --enable-paeth-intra=1` (the
1851+ /// opposite of the directional-chroma gate below, which turns these OFF
1852+ /// to keep this gap from firing while directional chroma is under test).
1853+ /// Some seeds won't pick smooth/paeth for chroma at all -- retry like
1854+ /// every other real-encoder gate here, but the first attempt that
1855+ /// actually fires [`decode::smooth_uv_hits`] must decode pixel-exact.
1856+ #[test]
1857+ fn a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact() {
1858+ if !have_ffmpeg() {
1859+ eprintln!(
1860+ "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no ffmpeg"
1861+ );
1862+ return;
1863+ }
1864+ if !have_aomenc() {
1865+ eprintln!(
1866+ "SKIP a_real_aomenc_stream_with_smooth_paeth_chroma_decodes_pixel_exact: no aomenc at {}",
1867+ aomenc_path().display()
1868+ );
1869+ return;
1870+ }
1871+ let (width, height) = (64usize, 64usize);
1872+ let mut refusals = Vec::new();
1873+ let mut fired_runs = 0u32;
1874+ for attempt in 0..40u32 {
1875+ let seed = 42 + attempt;
1876+ let source = format!(
1877+ "mandelbrot=size=64x64:start_scale={}:rate=25",
1878+ 5.0 - f64::from(attempt) * 0.06
1879+ );
1880+ let y4m = Command::new("ffmpeg")
1881+ .args([
1882+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-t",
1883+ "0.04", "-f", "yuv4mpegpipe", "-",
1884+ ])
1885+ .stdin(Stdio::null())
1886+ .stdout(Stdio::piped())
1887+ .stderr(Stdio::piped())
1888+ .output()
1889+ .expect("ffmpeg failed to run");
1890+ assert!(
1891+ y4m.status.success(),
1892+ "ffmpeg fixture: {}",
1893+ String::from_utf8_lossy(&y4m.stderr)
1894+ );
1895+ let mut child = Command::new(aomenc_path())
1896+ .args([
1897+ "--codec=av1",
1898+ "--passes=1",
1899+ "--end-usage=q",
1900+ "--cq-level=45",
1901+ "--cpu-used=0",
1902+ "--enable-rect-partitions=0",
1903+ "--enable-ab-partitions=0",
1904+ "--enable-1to4-partitions=0",
1905+ "--enable-filter-intra=0",
1906+ "--enable-smooth-intra=1",
1907+ "--enable-paeth-intra=1",
1908+ "--enable-tx-size-search=0",
1909+ "--enable-cdef=0",
1910+ "--enable-restoration=0",
1911+ "--enable-intra-edge-filter=1",
1912+ "--max-partition-size=32",
1913+ // 8x8/leaf8 splits are a separate, already-named refusal.
1914+ "--min-partition-size=16",
1915+ "--enable-palette=0",
1916+ "--enable-intrabc=0",
1917+ "--enable-cfl-intra=0",
1918+ "--enable-ref-frame-mvs=0",
1919+ "--obu",
1920+ "-o",
1921+ "-",
1922+ "-",
1923+ ])
1924+ .stdin(Stdio::piped())
1925+ .stdout(Stdio::piped())
1926+ .stderr(Stdio::piped())
1927+ .spawn()
1928+ .expect("aomenc failed to start");
1929+ child
1930+ .stdin
1931+ .take()
1932+ .expect("aomenc stdin")
1933+ .write_all(&y4m.stdout)
1934+ .expect("writing y4m to aomenc");
1935+ let out = child.wait_with_output().expect("aomenc failed to run");
1936+ assert!(
1937+ out.status.success(),
1938+ "aomenc refused the fixture: {}",
1939+ String::from_utf8_lossy(&out.stderr)
1940+ );
1941+ let stream = out.stdout;
1942+ let smooth_before = decode::smooth_uv_hits();
1943+ let frames = match decode_stream(&stream) {
1944+ Ok(frames) => frames,
1945+ Err(e) => {
1946+ refusals.push(format!("seed {seed}: {e}"));
1947+ continue;
1948+ }
1949+ };
1950+ if decode::smooth_uv_hits() == smooth_before {
1951+ refusals.push(format!(
1952+ "seed {seed}: decoded, but no smooth/paeth uv_mode fired"
1953+ ));
1954+ continue;
1955+ }
1956+ fired_runs += 1;
1957+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
1958+ assert_eq!(
1959+ frames[0].y, ffmpeg_frames[0].y,
1960+ "luma vs ffmpeg (seed {seed})"
1961+ );
1962+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");
1963+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");
1964+ if fired_runs >= 4 {
1965+ return;
1966+ }
1967+ }
1968+ assert!(
1969+ fired_runs > 0,
1970+ "every attempt hit a named refusal or never exercised smooth/paeth chroma:\n{}",
1971+ refusals.join("\n")
1972+ );
1973+ }
1974+
18491975 /// The directional-chroma/angle-delta gate: a real aomenc key frame with
18501976 /// `--enable-directional-intra`/`--enable-angle-delta` left ON (the
18511977 /// opposite of every sibling recipe's `=0`, which existed specifically to