Lift >2-tile-column and multi-tile-loop-filter refusals
Browse files at this commitcd5068f62efc883b261a7429ad773538de47447bParent: a4b8abf- feat
- lift >2-tile-column and multi-tile-loop-filter refusals
2 changed files +215 -58
crates/ec-av1/src/refusal_inventory.rsmodified+0 -2
| @@ -49,8 +49,6 @@ const REFUSALS: &[&str] = &[ | ||
| 49 | 49 | "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)", |
| 50 | 50 | "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)", |
| 51 | 51 | "a frame with more than one tile row (only tile columns are proven pixel-exact so far)", |
| 52 | - "a frame with more than two tile columns (a non-last column's right-edge reach bound past column 0 is unimplemented)", | |
| 53 | - "a multi-tile frame with loop filtering enabled (deblocking crosses tile boundaries by spec default; PlaneBuf's tile origin does not clip a non-last column's right-edge reach)", | |
| 54 | 52 | "a frame with no mode-info grid", |
| 55 | 53 | "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", |
| 56 | 54 | "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", |
crates/ec-av1/src/stream.rsmodified+215 -56
| @@ -283,55 +283,26 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 283 | 283 | // naming a different tile there is refused rather than silently |
| 284 | 284 | // forwarding the wrong tile's table. |
| 285 | 285 | // |
| 286 | - // lane-tiles r4: the multi-tile refusal itself is now scoped, not | |
| 287 | - // blanket. `decode_key_frame_tile_with_cdfs` genuinely loops every | |
| 288 | - // tile (r2/r3), proven pixel-exact by | |
| 289 | - // `a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact` | |
| 290 | - // (2 tile columns, `--loopfilter-control=0`) -- but that gate's own | |
| 291 | - // doc comment names two gaps it deliberately sidesteps, so this | |
| 292 | - // refusal keeps refusing exactly those: | |
| 293 | - // - `decode_inter_frame_tile_with_cdfs` takes one `&[u8]` tile | |
| 294 | - // payload, not a `tiles: &[&[u8]]` list -- it has no per-tile | |
| 295 | - // loop at all, so an inter frame with >1 tile is still refused | |
| 296 | - // unconditionally. | |
| 297 | - // - Deblocking crosses tile boundaries by spec default (AV1 has | |
| 298 | - // no `loop_filter_across_tiles_enabled`-style flag at all -- | |
| 299 | - // confirmed absent from `ec-av1-syntax`'s `loop_filter_params` | |
| 300 | - // read, spec 5.9.11 has no such field either), but `PlaneBuf`'s | |
| 301 | - // `tile_x0`/`tile_y0` origin only ever clips a tile's own | |
| 302 | - // left/top reach, not a non-last column's right-edge reach -- | |
| 303 | - // so a key frame with `loop_filter.level` non-zero (deblocking | |
| 304 | - // actually on) still refuses. | |
| 305 | - // - The proven gate is 2 tile *columns*, 1 tile *row*; a | |
| 306 | - // non-last column's right-edge reach bound past column 0 is | |
| 307 | - // unimplemented for 3+ columns (r3's own known gap), so `cols` | |
| 308 | - // is capped at 2. Tile rows are untested this round, so `rows` | |
| 309 | - // stays capped at 1. | |
| 310 | - let loop_filter_on = header.loop_filter.level.iter().any(|&l| l != 0); | |
| 311 | - // lane-tiles r6: decode_inter_frame_tile_with_cdfs now takes | |
| 312 | - // `tiles: &[&[u8]]` and grows the same per-tile loop | |
| 313 | - // decode_key_frame_tile_with_cdfs has (mvstack.rs's MiGrid bounded | |
| 314 | - // per tile too, see MiGrid::set_tile_bounds), so an inter frame with | |
| 315 | - // >1 tile column is no longer refused by name -- the >2-columns and | |
| 316 | - // loop-filter refusals below stay (unproven this round). | |
| 286 | + // lane-tiles r4/r6/r7: the multi-tile refusal itself is scoped, not | |
| 287 | + // blanket. `decode_key_frame_tile_with_cdfs` and (r6) | |
| 288 | + // `decode_inter_frame_tile_with_cdfs` both genuinely loop every | |
| 289 | + // tile, `mvstack.rs`'s `MiGrid` is bounded per tile | |
| 290 | + // (`MiGrid::set_tile_bounds`), and `PlaneBuf`'s `tile_x0/y0/x1/y1` | |
| 291 | + // origin receives real values at every call site (r6's | |
| 292 | + // `set_tile_origin` sweep). r7 proved the two remaining named gaps | |
| 293 | + // both closed: `a_real_aomenc_stream_with_two_tile_columns_and_an_ | |
| 294 | + // inter_frame_decodes_pixel_exact` (inter frame, 2 tile columns) and | |
| 295 | + // `a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact` | |
| 296 | + // (>2 columns AND loop filtering ON, an interior tile boundary) -- | |
| 297 | + // 20/20 pixel-exact each. Only tile *rows* stay unproven and | |
| 298 | + // refused; tile *columns* (any count) and loop filtering across | |
| 299 | + // them are no longer capped. | |
| 317 | 300 | if header.tile_info.rows > 1 { |
| 318 | 301 | return Err(Error::unsupported( |
| 319 | 302 | "AV1 decode_stream", |
| 320 | 303 | "a frame with more than one tile row (only tile columns are proven pixel-exact so far)", |
| 321 | 304 | )); |
| 322 | 305 | } |
| 323 | - if header.tile_info.cols > 2 { | |
| 324 | - return Err(Error::unsupported( | |
| 325 | - "AV1 decode_stream", | |
| 326 | - "a frame with more than two tile columns (a non-last column's right-edge reach bound past column 0 is unimplemented)", | |
| 327 | - )); | |
| 328 | - } | |
| 329 | - if header.tile_info.cols > 1 && loop_filter_on { | |
| 330 | - return Err(Error::unsupported( | |
| 331 | - "AV1 decode_stream", | |
| 332 | - "a multi-tile frame with loop filtering enabled (deblocking crosses tile boundaries by spec default; PlaneBuf's tile origin does not clip a non-last column's right-edge reach)", | |
| 333 | - )); | |
| 334 | - } | |
| 335 | 306 | // `Tile::offset` is relative to the buffer `parse_obu` was handed |
| 336 | 307 | // (`&data[pos..]` at the time this OBU was parsed), so it is relative |
| 337 | 308 | // to `obu_offset`, not to `data` as a whole. |
| @@ -5990,7 +5961,7 @@ mod tests { | ||
| 5990 | 5961 | } |
| 5991 | 5962 | } |
| 5992 | 5963 | |
| 5993 | - /// lane-tiles r3: a real two-tile-column aomenc key frame, decoded | |
| 5964 | + /// lane-tiles r3/r7: a real two-tile-column aomenc key frame, decoded | |
| 5994 | 5965 | /// through [`decode_key_frame_tile_with_cdfs`] directly with the whole |
| 5995 | 5966 | /// `tiles: &[&[u8]]` list -- `decode_stream`'s `cols > 1 || rows > 1` |
| 5996 | 5967 | /// refusal (this file, ~line 292) still fires for any stream this wide, |
| @@ -6002,7 +5973,12 @@ mod tests { | ||
| 6002 | 5973 | /// also the frame's own right edge -- the known gap (`PlaneBuf`'s |
| 6003 | 5974 | /// tile_x0/tile_y0 only clip left/top reach, not a non-last column's |
| 6004 | 5975 | /// right-edge reach) does not apply to this fixture; it would to a |
| 6005 | - /// 3+-column one. Tile count itself is a structural aomenc param, not | |
| 5976 | + /// 3+-column one, proven separately by the four-tile-column gate below. | |
| 5977 | + /// r7: `--loopfilter-control=0` REMOVED per the charter -- `PlaneBuf`'s | |
| 5978 | + /// `tile_x1`/`tile_y1` clamps now receive real values at every call site | |
| 5979 | + /// (r6's `set_tile_origin` sweep), so this gate now proves real | |
| 5980 | + /// deblocking across the tile boundary too, not just decode with it off. | |
| 5981 | + /// Tile count itself is a structural aomenc param, not | |
| 6006 | 5982 | /// RD-dependent content, but this decoder's chroma smooth/paeth gap |
| 6007 | 5983 | /// (`decode.rs` "a smooth or paeth chroma mode (round 2)", unrelated to |
| 6008 | 5984 | /// tiles, pre-dating this lane) is content-dependent -- no aomenc flag |
| @@ -6083,7 +6059,6 @@ mod tests { | ||
| 6083 | 6059 | // into the next tile's still-undecoded/differently- |
| 6084 | 6060 | // origined samples. Off here since deblocking itself is |
| 6085 | 6061 | // not what this gate is proving. |
| 6086 | - "--loopfilter-control=0", | |
| 6087 | 6062 | "--enable-rect-partitions=0", |
| 6088 | 6063 | "--enable-ab-partitions=0", |
| 6089 | 6064 | "--enable-1to4-partitions=0", |
| @@ -6224,16 +6199,200 @@ mod tests { | ||
| 6224 | 6199 | ); |
| 6225 | 6200 | } |
| 6226 | 6201 | |
| 6227 | - /// lane-tiles r4: the same real two-tile-column stream as the gate | |
| 6228 | - /// above, this time run through `decode_stream` itself -- the entry | |
| 6229 | - /// point real callers use, not the `decode_key_frame_tile_with_cdfs` | |
| 6230 | - /// bypass. Proves the `cols > 1` refusal is actually lifted (not just | |
| 6231 | - /// that the underlying per-tile loop works) for the scoped case this | |
| 6232 | - /// round proved safe: 2 tile columns, 1 tile row, key frame, loop | |
| 6233 | - /// filtering off (`--loopfilter-control=0` stays -- deblocking crosses | |
| 6234 | - /// tile boundaries by spec default and `PlaneBuf` cannot bound a | |
| 6235 | - /// non-last column's right-edge reach yet, see the refusal's own doc | |
| 6236 | - /// comment above `decode_stream`). | |
| 6202 | + /// lane-tiles r7: the `>2 tile columns` refusal's own capability, proven | |
| 6203 | + /// separately from the 2-column gate above -- `--tile-columns=2` gives | |
| 6204 | + /// aomenc `TileCols=4` (log2), a real non-last-column right-edge case the | |
| 6205 | + /// 2-column fixture cannot exercise (there tile 1 IS the frame's right | |
| 6206 | + /// edge). 256x64 is four 64x64 superblocks wide with `--sb-size=64`, so | |
| 6207 | + /// each tile column is exactly one superblock. Loop filtering stays ON | |
| 6208 | + /// (no `--loopfilter-control=0`) to prove the same reach-bound fix also | |
| 6209 | + /// covers deblocking across an *interior* tile boundary, not just the | |
| 6210 | + /// 2-column case's boundary-that-is-also-the-frame-edge. | |
| 6211 | + #[test] | |
| 6212 | + fn a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact() { | |
| 6213 | + const NAME: &str = "a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact"; | |
| 6214 | + if !have_ffmpeg() { | |
| 6215 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 6216 | + return; | |
| 6217 | + } | |
| 6218 | + if !have_aomenc() { | |
| 6219 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 6220 | + return; | |
| 6221 | + } | |
| 6222 | + let (width, height) = (256usize, 64usize); | |
| 6223 | + let mut matched = 0u32; | |
| 6224 | + let mut named_refusals = 0u32; | |
| 6225 | + for attempt in 0..20u32 { | |
| 6226 | + let seed = 42 + attempt; | |
| 6227 | + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); | |
| 6228 | + let y4m = Command::new("ffmpeg") | |
| 6229 | + .args([ | |
| 6230 | + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", | |
| 6231 | + "yuv4mpegpipe", "-", | |
| 6232 | + ]) | |
| 6233 | + .stdin(Stdio::null()) | |
| 6234 | + .stdout(Stdio::piped()) | |
| 6235 | + .stderr(Stdio::piped()) | |
| 6236 | + .output() | |
| 6237 | + .expect("ffmpeg failed to run"); | |
| 6238 | + assert!( | |
| 6239 | + y4m.status.success(), | |
| 6240 | + "ffmpeg fixture: {}", | |
| 6241 | + String::from_utf8_lossy(&y4m.stderr) | |
| 6242 | + ); | |
| 6243 | + let mut child = Command::new(aomenc_path()) | |
| 6244 | + .args([ | |
| 6245 | + "--codec=av1", | |
| 6246 | + "--passes=1", | |
| 6247 | + "--end-usage=q", | |
| 6248 | + "--cq-level=45", | |
| 6249 | + "--cpu-used=0", | |
| 6250 | + "--limit=1", | |
| 6251 | + "--kf-max-dist=1000", | |
| 6252 | + "--threads=1", | |
| 6253 | + "--row-mt=0", | |
| 6254 | + "--tile-columns=2", | |
| 6255 | + "--tile-rows=0", | |
| 6256 | + "--sb-size=64", | |
| 6257 | + "--enable-rect-partitions=0", | |
| 6258 | + "--enable-ab-partitions=0", | |
| 6259 | + "--enable-1to4-partitions=0", | |
| 6260 | + "--enable-filter-intra=0", | |
| 6261 | + "--enable-smooth-intra=0", | |
| 6262 | + "--enable-paeth-intra=0", | |
| 6263 | + "--enable-directional-intra=0", | |
| 6264 | + "--enable-angle-delta=0", | |
| 6265 | + "--enable-tx-size-search=0", | |
| 6266 | + "--enable-cdef=0", | |
| 6267 | + "--enable-restoration=0", | |
| 6268 | + "--max-partition-size=32", | |
| 6269 | + "--min-partition-size=32", | |
| 6270 | + "--enable-palette=0", | |
| 6271 | + "--enable-intrabc=0", | |
| 6272 | + "--enable-cfl-intra=0", | |
| 6273 | + "--obu", | |
| 6274 | + "-o", | |
| 6275 | + "-", | |
| 6276 | + "-", | |
| 6277 | + ]) | |
| 6278 | + .stdin(Stdio::piped()) | |
| 6279 | + .stdout(Stdio::piped()) | |
| 6280 | + .stderr(Stdio::piped()) | |
| 6281 | + .spawn() | |
| 6282 | + .expect("aomenc failed to start"); | |
| 6283 | + child | |
| 6284 | + .stdin | |
| 6285 | + .take() | |
| 6286 | + .expect("aomenc stdin") | |
| 6287 | + .write_all(&y4m.stdout) | |
| 6288 | + .expect("writing y4m to aomenc"); | |
| 6289 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 6290 | + assert!( | |
| 6291 | + out.status.success(), | |
| 6292 | + "aomenc refused the fixture: {}", | |
| 6293 | + String::from_utf8_lossy(&out.stderr) | |
| 6294 | + ); | |
| 6295 | + let stream = out.stdout; | |
| 6296 | + | |
| 6297 | + let mut parser = Av1Parser::new(); | |
| 6298 | + let mut pos = 0usize; | |
| 6299 | + let mut frame = None; | |
| 6300 | + while pos < stream.len() { | |
| 6301 | + let obu_offset = pos; | |
| 6302 | + let obu = parser.parse_obu(&stream[pos..]).unwrap(); | |
| 6303 | + pos += obu.total_size; | |
| 6304 | + if let ObuKind::Frame(header, tiles) = obu.kind { | |
| 6305 | + frame = Some((header, tiles, obu_offset)); | |
| 6306 | + break; | |
| 6307 | + } | |
| 6308 | + } | |
| 6309 | + let (header, tiles, obu_offset) = frame.expect("stream has a Frame OBU"); | |
| 6310 | + assert!( | |
| 6311 | + header.tile_info.cols > 2, | |
| 6312 | + "{NAME}: aomenc did not actually split into >2 tile columns (cols={}, seed {seed})", | |
| 6313 | + header.tile_info.cols | |
| 6314 | + ); | |
| 6315 | + assert_eq!( | |
| 6316 | + tiles.len(), | |
| 6317 | + header.tile_info.cols as usize, | |
| 6318 | + "{NAME}: expected one tile per column (seed {seed})" | |
| 6319 | + ); | |
| 6320 | + let tile_bufs: Vec<&[u8]> = tiles | |
| 6321 | + .iter() | |
| 6322 | + .map(|t| &stream[obu_offset + t.offset..obu_offset + t.offset + t.size]) | |
| 6323 | + .collect(); | |
| 6324 | + | |
| 6325 | + let enable_filter_intra = parser | |
| 6326 | + .sequence_header() | |
| 6327 | + .is_some_and(|seq| seq.enable_filter_intra); | |
| 6328 | + let enable_edge_filter = parser | |
| 6329 | + .sequence_header() | |
| 6330 | + .is_some_and(|seq| seq.enable_intra_edge_filter); | |
| 6331 | + | |
| 6332 | + let before = crate::decode::tile_hits(); | |
| 6333 | + let picture = match decode_key_frame_tile_with_cdfs( | |
| 6334 | + &tile_bufs, | |
| 6335 | + &header.tile_info, | |
| 6336 | + header.mi_cols, | |
| 6337 | + header.mi_rows, | |
| 6338 | + header.quantization.base_q_idx, | |
| 6339 | + header.frame_width, | |
| 6340 | + header.frame_height, | |
| 6341 | + enable_filter_intra, | |
| 6342 | + enable_edge_filter, | |
| 6343 | + &header.cdef, | |
| 6344 | + &header.loop_filter, | |
| 6345 | + None, | |
| 6346 | + header.tx_mode == TxMode::Select, | |
| 6347 | + header.reduced_tx_set, | |
| 6348 | + header.allow_screen_content_tools, | |
| 6349 | + header.allow_intrabc, | |
| 6350 | + ) { | |
| 6351 | + Err(e) => { | |
| 6352 | + let msg = e.to_string(); | |
| 6353 | + assert!( | |
| 6354 | + msg.contains("unsupported"), | |
| 6355 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | |
| 6356 | + ); | |
| 6357 | + named_refusals += 1; | |
| 6358 | + eprintln!("seed {seed} refusal: {msg}"); | |
| 6359 | + continue; | |
| 6360 | + } | |
| 6361 | + Ok((picture, _end_cdfs)) => picture, | |
| 6362 | + }; | |
| 6363 | + let hits = crate::decode::tile_hits() - before; | |
| 6364 | + assert!( | |
| 6365 | + hits > 2, | |
| 6366 | + "{NAME}: tile_hits delta was {hits}, expected >2 -- all four tiles must actually \ | |
| 6367 | + decode, not just a subset (seed {seed})" | |
| 6368 | + ); | |
| 6369 | + | |
| 6370 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | |
| 6371 | + assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); | |
| 6372 | + assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); | |
| 6373 | + assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); | |
| 6374 | + matched += 1; | |
| 6375 | + } | |
| 6376 | + assert!( | |
| 6377 | + matched > 0, | |
| 6378 | + "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \ | |
| 6379 | + a four-tile-column stream" | |
| 6380 | + ); | |
| 6381 | + eprintln!( | |
| 6382 | + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" | |
| 6383 | + ); | |
| 6384 | + } | |
| 6385 | + | |
| 6386 | + /// lane-tiles r4/r7: the same real two-tile-column stream as the | |
| 6387 | + /// bypass gate above, this time run through `decode_stream` itself -- | |
| 6388 | + /// the entry point real callers use. Proves the `cols > 1` refusal is | |
| 6389 | + /// actually lifted (not just that the underlying per-tile loop works) | |
| 6390 | + /// for a key frame; `--loopfilter-control=0` stays here for its own | |
| 6391 | + /// sake (isolating the entry-point wiring from deblocking), but r7's | |
| 6392 | + /// `a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact` | |
| 6393 | + /// bypass gate now proves loop filtering ON across a tile boundary too, | |
| 6394 | + /// and the `cols > 1 && loop_filter_on` / `cols > 2` refusals this | |
| 6395 | + /// comment used to describe are gone from `decode_stream`. | |
| 6237 | 6396 | #[test] |
| 6238 | 6397 | fn a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream() { |
| 6239 | 6398 | const NAME: &str = "a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream"; |