Full-plane gate for rect inter chroma narrow-kernel prediction
Browse files at this commitcd6e06e6b4df368a42d44e546f1388039103a714Parent: 795aad1- test
- full-plane gate for rect inter chroma narrow-kernel prediction
1 changed file +198 -0
- crates/ec-av1/src/stream.rs +198 -0
crates/ec-av1/src/stream.rsmodified+198 -0
| @@ -24227,4 +24227,202 @@ mod tests { | ||
| 24227 | 24227 | "{NAME}: no 32/16-level frame-edge bit was ever answered HORZ/VERT" |
| 24228 | 24228 | ); |
| 24229 | 24229 | } |
| 24230 | + | |
| 24231 | + /// lane-rectchroma2 r1, the defect this gate exists for: our inter path | |
| 24232 | + /// predicts a RECTANGULAR block over its enclosing SQUARE buffer | |
| 24233 | + /// (`side`x`side`, `chroma_side`x`chroma_side` -- see | |
| 24234 | + /// [`crate::decode`]'s `write_w`/`write_h` corner-cut), and | |
| 24235 | + /// [`crate::mc::predict_with_filters`] took libaom's narrow-block 4-tap | |
| 24236 | + /// decision from that buffer's dimensions. libaom | |
| 24237 | + /// (`av1_get_interp_filter_params_with_block_size`, called per axis from | |
| 24238 | + /// `inter_predictor` with `w` then `h`) takes it from the PREDICTION | |
| 24239 | + /// block's own dimensions, so an 8x16 / 16x8 inter block -- whose chroma | |
| 24240 | + /// is 4x8 / 8x4 -- must use the 4-tap kernel on the short axis. Luma is | |
| 24241 | + /// never <= 4 wide here, which is exactly why every such stream decoded | |
| 24242 | + /// LUMA EXACT and differed by +-1 on scattered chroma samples of those | |
| 24243 | + /// blocks (lane-interedge r1's 192x128 control, a size with no frame-edge | |
| 24244 | + /// node at all). | |
| 24245 | + /// | |
| 24246 | + /// Full-plane (Y+U+V) compare of EVERY decode-order frame | |
| 24247 | + /// (`--lag-in-frames=0`), both orientations (192x128 and its transposed | |
| 24248 | + /// twin, so the 4x8 and 8x4 chroma shapes both fire -- class | |
| 24249 | + /// `scan-weights-cross-axis`), 8 AND 10 bit (his films are yuv420p10le), | |
| 24250 | + /// cq 20/32/45, CDEF and loop restoration left ON. The counter is reset | |
| 24251 | + /// per attempt and read only on an attempt that decoded and compared | |
| 24252 | + /// (class `counter-from-refused-stream`); it counts predictions whose | |
| 24253 | + /// kernel choice DIFFERS from what the square buffer would have given, so | |
| 24254 | + /// a zero means the recipe lost the shape this gate pins. | |
| 24255 | + #[test] | |
| 24256 | + fn a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact() { | |
| 24257 | + const NAME: &str = | |
| 24258 | + "a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact"; | |
| 24259 | + let _gate_lock = lock_gate_counters(); | |
| 24260 | + if !have_ffmpeg() { | |
| 24261 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 24262 | + return; | |
| 24263 | + } | |
| 24264 | + if !have_aomenc() { | |
| 24265 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 24266 | + return; | |
| 24267 | + } | |
| 24268 | + const FRAMES: usize = 6; | |
| 24269 | + let mut compared = 0usize; | |
| 24270 | + let mut narrow_by_depth = [0usize; 2]; | |
| 24271 | + let mut narrow_by_shape = [0usize; 2]; | |
| 24272 | + for (si, (width, height)) in [(192usize, 128usize), (128usize, 192usize)] | |
| 24273 | + .into_iter() | |
| 24274 | + .enumerate() | |
| 24275 | + { | |
| 24276 | + for (di, depth) in [8usize, 10].into_iter().enumerate() { | |
| 24277 | + let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" }; | |
| 24278 | + let y4m = Command::new("ffmpeg") | |
| 24279 | + .args([ | |
| 24280 | + "-v", "error", "-f", "lavfi", "-i", | |
| 24281 | + &format!("mandelbrot=size={width}x{height}:rate=25"), | |
| 24282 | + "-pix_fmt", pix, "-strict", "-1", "-vframes", &FRAMES.to_string(), | |
| 24283 | + "-f", "yuv4mpegpipe", "-", | |
| 24284 | + ]) | |
| 24285 | + .stdin(Stdio::null()) | |
| 24286 | + .stdout(Stdio::piped()) | |
| 24287 | + .stderr(Stdio::piped()) | |
| 24288 | + .output() | |
| 24289 | + .expect("ffmpeg failed to run"); | |
| 24290 | + assert!( | |
| 24291 | + y4m.status.success(), | |
| 24292 | + "{NAME}: ffmpeg fixture ({width}x{height}, depth={depth}): {}", | |
| 24293 | + String::from_utf8_lossy(&y4m.stderr) | |
| 24294 | + ); | |
| 24295 | + for cq in [20usize, 32, 45] { | |
| 24296 | + let encode = || { | |
| 24297 | + let mut child = Command::new(aomenc_path()) | |
| 24298 | + .args([ | |
| 24299 | + "--codec=av1", "--passes=1", "--end-usage=q", | |
| 24300 | + &format!("--cq-level={cq}"), | |
| 24301 | + "--cpu-used=4", "--threads=1", "--row-mt=0", | |
| 24302 | + "--kf-max-dist=9999", &format!("--limit={FRAMES}"), | |
| 24303 | + "--lag-in-frames=0", | |
| 24304 | + &format!("--bit-depth={depth}"), | |
| 24305 | + &format!("--input-bit-depth={depth}"), | |
| 24306 | + // Rect partitions ON is the whole point; every | |
| 24307 | + // other tool below is another lane's open gap | |
| 24308 | + // that would refuse before a pixel compare. | |
| 24309 | + "--enable-rect-partitions=1", "--enable-ab-partitions=0", | |
| 24310 | + "--enable-1to4-partitions=0", "--min-partition-size=8", | |
| 24311 | + "--max-partition-size=64", "--enable-palette=0", | |
| 24312 | + "--enable-intrabc=0", "--enable-warped-motion=0", | |
| 24313 | + "--enable-obmc=0", "--enable-masked-comp=0", | |
| 24314 | + "--enable-interintra-comp=0", "--enable-onesided-comp=0", | |
| 24315 | + "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", | |
| 24316 | + "--enable-ref-frame-mvs=0", "--enable-angle-delta=0", | |
| 24317 | + "--enable-cfl-intra=0", "--enable-directional-intra=0", | |
| 24318 | + "--enable-smooth-intra=0", "--enable-paeth-intra=0", | |
| 24319 | + "--enable-filter-intra=0", "--enable-tx-size-search=0", | |
| 24320 | + "--obu", "-o", "-", "-", | |
| 24321 | + ]) | |
| 24322 | + .stdin(Stdio::piped()) | |
| 24323 | + .stdout(Stdio::piped()) | |
| 24324 | + .stderr(Stdio::piped()) | |
| 24325 | + .spawn() | |
| 24326 | + .expect("aomenc failed to start"); | |
| 24327 | + child | |
| 24328 | + .stdin | |
| 24329 | + .take() | |
| 24330 | + .expect("aomenc stdin") | |
| 24331 | + .write_all(&y4m.stdout) | |
| 24332 | + .expect("writing y4m to aomenc"); | |
| 24333 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 24334 | + assert!( | |
| 24335 | + out.status.success(), | |
| 24336 | + "aomenc refused the fixture ({width}x{height}, depth={depth}, \ | |
| 24337 | + cq={cq}): {}", | |
| 24338 | + String::from_utf8_lossy(&out.stderr) | |
| 24339 | + ); | |
| 24340 | + out.stdout | |
| 24341 | + }; | |
| 24342 | + let stream = encode(); | |
| 24343 | + assert_eq!( | |
| 24344 | + stream, | |
| 24345 | + encode(), | |
| 24346 | + "{NAME}: aomenc output is not reproducible ({width}x{height}, \ | |
| 24347 | + depth={depth}, cq={cq})" | |
| 24348 | + ); | |
| 24349 | + crate::mc::reset_rect_narrow_kern_hits(); | |
| 24350 | + let frames = match decode_stream(&stream) { | |
| 24351 | + Ok(frames) => frames, | |
| 24352 | + Err(e) => { | |
| 24353 | + let msg = e.to_string(); | |
| 24354 | + assert!( | |
| 24355 | + msg.contains("unsupported"), | |
| 24356 | + "{NAME}: decode failed ({width}x{height}, depth={depth}, \ | |
| 24357 | + cq={cq}): {msg}" | |
| 24358 | + ); | |
| 24359 | + eprintln!( | |
| 24360 | + "{NAME}: {width}x{height} depth={depth} cq={cq} arm refused \ | |
| 24361 | + (not compared): {msg}" | |
| 24362 | + ); | |
| 24363 | + continue; | |
| 24364 | + } | |
| 24365 | + }; | |
| 24366 | + let narrow = crate::mc::rect_narrow_kern_hits(); | |
| 24367 | + let ffmpeg_frames = if depth == 10 { | |
| 24368 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | |
| 24369 | + } else { | |
| 24370 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | |
| 24371 | + }; | |
| 24372 | + assert_eq!( | |
| 24373 | + ffmpeg_frames.len(), | |
| 24374 | + frames.len(), | |
| 24375 | + "{NAME}: ffmpeg frame count ({width}x{height}, depth={depth}, cq={cq})" | |
| 24376 | + ); | |
| 24377 | + assert_eq!( | |
| 24378 | + frames.len(), | |
| 24379 | + FRAMES, | |
| 24380 | + "{NAME}: not every coded frame was decoded ({width}x{height}, \ | |
| 24381 | + depth={depth}, cq={cq})" | |
| 24382 | + ); | |
| 24383 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 24384 | + assert_eq!( | |
| 24385 | + got.y, want.y, | |
| 24386 | + "{NAME} frame {i} luma vs ffmpeg ({width}x{height}, depth={depth}, \ | |
| 24387 | + cq={cq}, narrow-kernel hits {narrow})" | |
| 24388 | + ); | |
| 24389 | + assert_eq!( | |
| 24390 | + got.u, want.u, | |
| 24391 | + "{NAME} frame {i} U vs ffmpeg ({width}x{height}, depth={depth}, \ | |
| 24392 | + cq={cq}, narrow-kernel hits {narrow})" | |
| 24393 | + ); | |
| 24394 | + assert_eq!( | |
| 24395 | + got.v, want.v, | |
| 24396 | + "{NAME} frame {i} V vs ffmpeg ({width}x{height}, depth={depth}, \ | |
| 24397 | + cq={cq}, narrow-kernel hits {narrow})" | |
| 24398 | + ); | |
| 24399 | + } | |
| 24400 | + compared += 1; | |
| 24401 | + narrow_by_depth[di] += narrow; | |
| 24402 | + narrow_by_shape[si] += narrow; | |
| 24403 | + eprintln!( | |
| 24404 | + "{NAME}: {width}x{height} depth={depth} cq={cq} {} frames full-plane \ | |
| 24405 | + exact, narrow-kernel hits {narrow}", | |
| 24406 | + frames.len() | |
| 24407 | + ); | |
| 24408 | + } | |
| 24409 | + } | |
| 24410 | + } | |
| 24411 | + assert_eq!( | |
| 24412 | + compared, 12, | |
| 24413 | + "{NAME}: only {compared} of 12 arms were pixel-compared -- a refusal makes this \ | |
| 24414 | + gate vacuous" | |
| 24415 | + ); | |
| 24416 | + assert!( | |
| 24417 | + narrow_by_depth[0] > 0 && narrow_by_depth[1] > 0, | |
| 24418 | + "{NAME}: no rect-chroma narrow kernel fired at 8-bit ({}) or 10-bit ({}) -- the \ | |
| 24419 | + recipe lost the shape this gate pins", | |
| 24420 | + narrow_by_depth[0], narrow_by_depth[1] | |
| 24421 | + ); | |
| 24422 | + assert!( | |
| 24423 | + narrow_by_shape[0] > 0 && narrow_by_shape[1] > 0, | |
| 24424 | + "{NAME}: the shape fired in only one orientation (192x128 {}, 128x192 {})", | |
| 24425 | + narrow_by_shape[0], narrow_by_shape[1] | |
| 24426 | + ); | |
| 24427 | + } | |
| 24230 | 24428 | } |