Merge branch 'lane-tiny': filter-intra blocks read the wrong tx_type CDF row
Browse files at this commit4 changed files +398 -2
- crates/ec-av1/src/decode.rs +81 -1
- crates/ec-av1/src/intra.rs +7 -1
- crates/ec-av1/src/stream.rs +180 -0
- lanes/tiny-r3.report.md +130 -0
crates/ec-av1/src/decode.rsmodified+81 -1
| @@ -934,6 +934,10 @@ const DC_PRED: usize = 0; | |||
| 934 | /// carries an angle delta — [`crate::tile`]'s own private copy of the same | 934 | /// carries an angle delta — [`crate::tile`]'s own private copy of the same |
| 935 | /// constant. | 935 | /// constant. |
| 936 | const V_PRED: usize = 1; | 936 | const V_PRED: usize = 1; |
| 937 | +const H_PRED: usize = 2; | ||
| 938 | +/// `D157_PRED`: `fimode_to_intradir`'s target for `FILTER_D157_PRED` (spec | ||
| 939 | +/// `Fimode_To_Intradir`, libaom `blockd.h`). | ||
| 940 | +const D157_PRED: usize = 6; | ||
| 937 | /// The last directional mode, `D67_PRED`. | 941 | /// The last directional mode, `D67_PRED`. |
| 938 | const D67_PRED: usize = 8; | 942 | const D67_PRED: usize = 8; |
| 939 | /// The symbol an angle delta of zero codes as (spec 9.3): the alphabet runs | 943 | /// The symbol an angle delta of zero codes as (spec 9.3): the alphabet runs |
| @@ -1426,6 +1430,13 @@ fn read_coeffs( | |||
| 1426 | eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}"); | 1430 | eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}"); |
| 1427 | } | 1431 | } |
| 1428 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; | 1432 | let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; |
| 1433 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 1434 | + let (rng, _) = dec.debug_state(); | ||
| 1435 | + eprintln!( | ||
| 1436 | + "EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero={} rng={rng}", | ||
| 1437 | + all_zero as i32 | ||
| 1438 | + ); | ||
| 1439 | + } | ||
| 1429 | if std::env::var_os("EC_AV1_TELL").is_some() { | 1440 | if std::env::var_os("EC_AV1_TELL").is_some() { |
| 1430 | eprintln!( | 1441 | eprintln!( |
| 1431 | "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}", | 1442 | "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}", |
| @@ -1457,6 +1468,10 @@ fn read_coeffs( | |||
| 1457 | eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}"); | 1468 | eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}"); |
| 1458 | } | 1469 | } |
| 1459 | let t = dec.symbol(tx_type_cdf); | 1470 | let t = dec.symbol(tx_type_cdf); |
| 1471 | + if std::env::var_os("EC_TRACE_COEFF").is_some() { | ||
| 1472 | + let (rng, _) = dec.debug_state(); | ||
| 1473 | + eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}"); | ||
| 1474 | + } | ||
| 1460 | if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() { | 1475 | if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() { |
| 1461 | let (range, value) = dec.debug_state(); | 1476 | let (range, value) = dec.debug_state(); |
| 1462 | eprintln!("EC_AV1_STATE_AFTER_TXTYPE range={range} value={value}"); | 1477 | eprintln!("EC_AV1_STATE_AFTER_TXTYPE range={range} value={value}"); |
| @@ -1481,6 +1496,11 @@ fn read_coeffs( | |||
| 1481 | if trace { | 1496 | if trace { |
| 1482 | eprintln!("TRACE eob value={eob}"); | 1497 | eprintln!("TRACE eob value={eob}"); |
| 1483 | } | 1498 | } |
| 1499 | + let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some(); | ||
| 1500 | + if ec_trace_coeff { | ||
| 1501 | + let (rng, _) = dec.debug_state(); | ||
| 1502 | + eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}"); | ||
| 1503 | + } | ||
| 1484 | let class_scan; | 1504 | let class_scan; |
| 1485 | let scan: &[u16] = if class == TxClass::TwoD { | 1505 | let scan: &[u16] = if class == TxClass::TwoD { |
| 1486 | scan | 1506 | scan |
| @@ -1532,10 +1552,18 @@ fn read_coeffs( | |||
| 1532 | } else { | 1552 | } else { |
| 1533 | level | 1553 | level |
| 1534 | }; | 1554 | }; |
| 1555 | + if ec_trace_coeff && scan_idx == eob - 1 { | ||
| 1556 | + let (rng, _) = dec.debug_state(); | ||
| 1557 | + eprintln!("EC_COEFF_STEP tag=base_eob level={level} rng={rng}"); | ||
| 1558 | + } | ||
| 1535 | levels[pos] = level; | 1559 | levels[pos] = level; |
| 1536 | } | 1560 | } |
| 1561 | + if ec_trace_coeff { | ||
| 1562 | + let (rng, _) = dec.debug_state(); | ||
| 1563 | + eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}"); | ||
| 1564 | + } | ||
| 1537 | 1565 | ||
| 1538 | - for &pos in &scan[..eob] { | 1566 | + for (c, &pos) in scan[..eob].iter().enumerate() { |
| 1539 | let level = levels[pos as usize]; | 1567 | let level = levels[pos as usize]; |
| 1540 | if level == 0 { | 1568 | if level == 0 { |
| 1541 | continue; | 1569 | continue; |
| @@ -1549,6 +1577,10 @@ fn read_coeffs( | |||
| 1549 | } else { | 1577 | } else { |
| 1550 | dec.literal(1) == 1 | 1578 | dec.literal(1) == 1 |
| 1551 | }; | 1579 | }; |
| 1580 | + if ec_trace_coeff { | ||
| 1581 | + let (rng, _) = dec.debug_state(); | ||
| 1582 | + eprintln!("EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", negative as i32); | ||
| 1583 | + } | ||
| 1552 | let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { | 1584 | let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { |
| 1553 | let g = read_golomb(dec)?; | 1585 | let g = read_golomb(dec)?; |
| 1554 | if trace { | 1586 | if trace { |
| @@ -1558,6 +1590,10 @@ fn read_coeffs( | |||
| 1558 | } else { | 1590 | } else { |
| 1559 | level | 1591 | level |
| 1560 | }; | 1592 | }; |
| 1593 | + if ec_trace_coeff { | ||
| 1594 | + let (rng, _) = dec.debug_state(); | ||
| 1595 | + eprintln!("EC_COEFF_STEP tag=post_golomb c={c} level={level} rng={rng}"); | ||
| 1596 | + } | ||
| 1561 | grid[pos as usize] = if negative { -level } else { level }; | 1597 | grid[pos as usize] = if negative { -level } else { level }; |
| 1562 | } | 1598 | } |
| 1563 | Ok((grid, tx_type)) | 1599 | Ok((grid, tx_type)) |
| @@ -3970,15 +4006,34 @@ fn read_intra_mode( | |||
| 3970 | Option<PaletteUv>, | 4006 | Option<PaletteUv>, |
| 3971 | )> { | 4007 | )> { |
| 3972 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); | 4008 | let trace = std::env::var_os("EC_AV1_TRACE").is_some(); |
| 4009 | + // lane-tiny r2: EC_ISTEP-format trace (same "name=... val=... rng=..." | ||
| 4010 | + // shape the oracle's own `ec_read_intra_frame_mode_info_impl` prints | ||
| 4011 | + // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for | ||
| 4012 | + // line against the instrumented aomdec, not just `tell()`. | ||
| 4013 | + let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some(); | ||
| 4014 | + macro_rules! istep { | ||
| 4015 | + ($name:literal, $val:expr) => { | ||
| 4016 | + if ec_istep { | ||
| 4017 | + let (rng, _) = dec.debug_state(); | ||
| 4018 | + eprintln!( | ||
| 4019 | + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={rng}", | ||
| 4020 | + $name, $val | ||
| 4021 | + ); | ||
| 4022 | + } | ||
| 4023 | + }; | ||
| 4024 | + } | ||
| 3973 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | 4025 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| 3974 | if trace { | 4026 | if trace { |
| 3975 | eprintln!("TRACE skip value={}", skip as i32); | 4027 | eprintln!("TRACE skip value={}", skip as i32); |
| 3976 | } | 4028 | } |
| 4029 | + istep!("skip", skip as i32); | ||
| 3977 | // spec order (see the comment below on `read_intrabc_info`): `skip`, | 4030 | // spec order (see the comment below on `read_intrabc_info`): `skip`, |
| 3978 | // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. | 4031 | // `segment_id`, `cdef`, `delta_q` -- `cdef` lands right here. |
| 3979 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); | 4032 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip); |
| 4033 | + istep!("cdef", 0); | ||
| 3980 | maybe_read_delta_q(dec, cdfs, mi_r, mi_c, side == 64, skip); | 4034 | maybe_read_delta_q(dec, cdfs, mi_r, mi_c, side == 64, skip); |
| 3981 | maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, side == 64, skip); | 4035 | maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, side == 64, skip); |
| 4036 | + istep!("dq", 0); | ||
| 3982 | // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at | 4037 | // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at |
| 3983 | // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before | 4038 | // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before |
| 3984 | // `mbmi->mode` is ever read): a `use_intrabc` symbol only present on an | 4039 | // `mbmi->mode` is ever read): a `use_intrabc` symbol only present on an |
| @@ -4005,6 +4060,7 @@ fn read_intra_mode( | |||
| 4005 | if trace { | 4060 | if trace { |
| 4006 | eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode}"); | 4061 | eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode}"); |
| 4007 | } | 4062 | } |
| 4063 | + istep!("mode", mode as i32); | ||
| 4008 | let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { | 4064 | let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) { |
| 4009 | let delta = read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]); | 4065 | let delta = read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED]); |
| 4010 | if trace { | 4066 | if trace { |
| @@ -4017,6 +4073,7 @@ fn read_intra_mode( | |||
| 4017 | } else { | 4073 | } else { |
| 4018 | 0 | 4074 | 0 |
| 4019 | }; | 4075 | }; |
| 4076 | + istep!("angle_y", angle_delta_y); | ||
| 4020 | let uv_mode = if cfl { | 4077 | let uv_mode = if cfl { |
| 4021 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) | 4078 | dec.symbol(&mut cdfs.uv_mode_cfl[mode]) |
| 4022 | } else { | 4079 | } else { |
| @@ -4025,6 +4082,7 @@ fn read_intra_mode( | |||
| 4025 | if trace { | 4082 | if trace { |
| 4026 | eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode}"); | 4083 | eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode}"); |
| 4027 | } | 4084 | } |
| 4085 | + istep!("uv_mode", uv_mode as i32); | ||
| 4028 | let alpha = if cfl && uv_mode == UV_CFL_PRED { | 4086 | let alpha = if cfl && uv_mode == UV_CFL_PRED { |
| 4029 | Some(read_cfl_alphas(dec, cdfs)) | 4087 | Some(read_cfl_alphas(dec, cdfs)) |
| 4030 | } else { | 4088 | } else { |
| @@ -4051,6 +4109,7 @@ fn read_intra_mode( | |||
| 4051 | } else { | 4109 | } else { |
| 4052 | 0 | 4110 | 0 |
| 4053 | }; | 4111 | }; |
| 4112 | + istep!("angle_uv", angle_delta_uv); | ||
| 4054 | // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called | 4113 | // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called |
| 4055 | // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`): | 4114 | // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`): |
| 4056 | // gated by `av1_allow_palette` (blockd.h -- size bound only, | 4115 | // gated by `av1_allow_palette` (blockd.h -- size bound only, |
| @@ -4144,12 +4203,14 @@ fn read_intra_mode( | |||
| 4144 | use_filter_intra as i32 | 4203 | use_filter_intra as i32 |
| 4145 | ); | 4204 | ); |
| 4146 | } | 4205 | } |
| 4206 | + istep!("use_filter_intra", use_filter_intra as i32); | ||
| 4147 | if use_filter_intra { | 4207 | if use_filter_intra { |
| 4148 | FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | 4208 | FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); |
| 4149 | let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); | 4209 | let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); |
| 4150 | if trace { | 4210 | if trace { |
| 4151 | eprintln!("TRACE filter_intra_mode value={fi_mode}"); | 4211 | eprintln!("TRACE filter_intra_mode value={fi_mode}"); |
| 4152 | } | 4212 | } |
| 4213 | + istep!("filter_intra_mode", fi_mode as i32); | ||
| 4153 | filter_intra = Some(fi_mode); | 4214 | filter_intra = Some(fi_mode); |
| 4154 | } | 4215 | } |
| 4155 | } | 4216 | } |
| @@ -4566,6 +4627,18 @@ fn read_plane( | |||
| 4566 | } else { | 4627 | } else { |
| 4567 | usize::from(around.0) + usize::from(around.1) | 4628 | usize::from(around.0) + usize::from(around.1) |
| 4568 | }; | 4629 | }; |
| 4630 | + // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's | ||
| 4631 | + // `intra_ext_tx_cdf` row is indexed by `fimode_to_intradir[filter_intra_mode]`, | ||
| 4632 | + // not by the block's ordinary `mode` (which is always DC_PRED whenever | ||
| 4633 | + // filter-intra is on) -- caller passes the raw filter-intra mode 0..4 in | ||
| 4634 | + // `filter_intra`, only meaningful for `plane_idx == 0` (chroma has no | ||
| 4635 | + // filter-intra in AV1). | ||
| 4636 | + const FIMODE_TO_INTRADIR: [usize; 5] = [DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED]; | ||
| 4637 | + let tx_mode = if plane_idx == 0 { | ||
| 4638 | + filter_intra.map_or(tx_mode, |fi| FIMODE_TO_INTRADIR[fi]) | ||
| 4639 | + } else { | ||
| 4640 | + tx_mode | ||
| 4641 | + }; | ||
| 4569 | let mut coding = cdfs.txb(set, tx_mode); | 4642 | let mut coding = cdfs.txb(set, tx_mode); |
| 4570 | // Luma's `default_tx_type` is only a fallback for the sizes whose | 4643 | // Luma's `default_tx_type` is only a fallback for the sizes whose |
| 4571 | // `TxbSet` carries no symbol at all (32-point and up), which the spec | 4644 | // `TxbSet` carries no symbol at all (32-point and up), which the spec |
| @@ -5661,6 +5734,13 @@ fn read_tx_size( | |||
| 5661 | } | 5734 | } |
| 5662 | _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), | 5735 | _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), |
| 5663 | }; | 5736 | }; |
| 5737 | + if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { | ||
| 5738 | + let (rng, _) = dec.debug_state(); | ||
| 5739 | + let (mi_r, mi_c) = at_mi; | ||
| 5740 | + eprintln!( | ||
| 5741 | + "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={depth} ctx={ctx} rng={rng}" | ||
| 5742 | + ); | ||
| 5743 | + } | ||
| 5664 | if depth != 0 { | 5744 | if depth != 0 { |
| 5665 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); | 5745 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 5666 | } | 5746 | } |
crates/ec-av1/src/intra.rsmodified+7 -1
| @@ -159,7 +159,13 @@ impl Edges { | |||
| 159 | row | 159 | row |
| 160 | }; | 160 | }; |
| 161 | // Spec 7.11.2.2's no-neighbour fallback is `base = 1 << (BitDepth - 1)` | 161 | // Spec 7.11.2.2's no-neighbour fallback is `base = 1 << (BitDepth - 1)` |
| 162 | - // (128 at 8-bit): `base - 1` above, `base + 1` left, `base` corner. | 162 | + // (128 at 8-bit): `base - 1` above, `base + 1` left, `base` corner |
| 163 | + // (libaom `reconintra.c`'s own diagram: the shared top-left corner | ||
| 164 | + // cell is literally `base`, distinct from either row's own | ||
| 165 | + // replicated value -- confirmed against `av1_highbd_build_intra_predictors`'s | ||
| 166 | + // comment block, lane-tiny r1; an earlier attempt at this fix used | ||
| 167 | + // 127/129 for the corner instead and made a passing 16x16 fixture | ||
| 168 | + // regress, which is what caught the misreading). | ||
| 163 | let base = 1i32 << (crate::decode::bit_depth() - 1); | 169 | let base = 1i32 << (crate::decode::bit_depth() - 1); |
| 164 | let above_row = match (above, left) { | 170 | let above_row = match (above, left) { |
| 165 | (Some(a), _) => extend(a), | 171 | (Some(a), _) => extend(a), |
crates/ec-av1/src/stream.rsmodified+180 -0
| @@ -6361,6 +6361,186 @@ mod tests { | |||
| 6361 | crate::decode::cdef_idx_hits() | 6361 | crate::decode::cdef_idx_hits() |
| 6362 | ); | 6362 | ); |
| 6363 | } | 6363 | } |
| 6364 | + /// lane-tiny r1 diagnostic (not a gate): sweeps tiny key-frame sizes | ||
| 6365 | + /// against real aomenc + ffmpeg to find the exact size boundary of the | ||
| 6366 | + /// silent-wrong-pixels defect the sub8 lane's r2 dead-end flagged (a | ||
| 6367 | + /// plain 16x16 stream, no exotic tools). `#[ignore]`d -- prints a | ||
| 6368 | + /// pass/fail table, asserts nothing; run manually with `--nocapture`. | ||
| 6369 | + #[test] | ||
| 6370 | + #[ignore = "diagnostic sweep, run manually with --nocapture"] | ||
| 6371 | + fn probe_tiny_frame_size_boundary() { | ||
| 6372 | + if !have_ffmpeg() || !have_aomenc() { | ||
| 6373 | + eprintln!("SKIP: no ffmpeg/aomenc"); | ||
| 6374 | + return; | ||
| 6375 | + } | ||
| 6376 | + let sizes: &[(usize, usize)] = | ||
| 6377 | + &[(8, 8), (16, 16), (32, 32), (16, 32), (32, 16), (64, 64), (48, 48), (24, 24)]; | ||
| 6378 | + for &(width, height) in sizes { | ||
| 6379 | + let mut ok = 0u32; | ||
| 6380 | + let mut bad = 0u32; | ||
| 6381 | + let mut refused = 0u32; | ||
| 6382 | + let n = 10u32; | ||
| 6383 | + for attempt in 0..n { | ||
| 6384 | + let seed = 42 + attempt; | ||
| 6385 | + let source = format!( | ||
| 6386 | + "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}", | ||
| 6387 | + sx = -0.6 + 0.005 * (attempt as f64), | ||
| 6388 | + sy = -0.4 + 0.005 * (attempt as f64) | ||
| 6389 | + ); | ||
| 6390 | + let y4m = Command::new("ffmpeg") | ||
| 6391 | + .args([ | ||
| 6392 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", | ||
| 6393 | + "yuv420p", "-f", "yuv4mpegpipe", "-", | ||
| 6394 | + ]) | ||
| 6395 | + .stdin(Stdio::null()) | ||
| 6396 | + .stdout(Stdio::piped()) | ||
| 6397 | + .stderr(Stdio::piped()) | ||
| 6398 | + .output() | ||
| 6399 | + .expect("ffmpeg failed to run"); | ||
| 6400 | + assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); | ||
| 6401 | + let max_part = width.max(height).min(64).next_power_of_two(); | ||
| 6402 | + let min_part = width.min(height).next_power_of_two().max(8).min(max_part); | ||
| 6403 | + let max_part_arg = format!("--max-partition-size={max_part}"); | ||
| 6404 | + let min_part_arg = format!("--min-partition-size={min_part}"); | ||
| 6405 | + let args: Vec<&str> = vec![ | ||
| 6406 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", | ||
| 6407 | + "--cpu-used=4", "--kf-max-dist=0", "--limit=1", "--threads=1", | ||
| 6408 | + "--row-mt=0", "--enable-rect-partitions=0", "--enable-ab-partitions=0", | ||
| 6409 | + "--enable-1to4-partitions=0", | ||
| 6410 | + &max_part_arg, &min_part_arg, | ||
| 6411 | + "--obu", "-o", "-", "-", | ||
| 6412 | + ]; | ||
| 6413 | + let mut child = Command::new(aomenc_path()) | ||
| 6414 | + .args(&args) | ||
| 6415 | + .stdin(Stdio::piped()) | ||
| 6416 | + .stdout(Stdio::piped()) | ||
| 6417 | + .stderr(Stdio::piped()) | ||
| 6418 | + .spawn() | ||
| 6419 | + .expect("aomenc failed to start"); | ||
| 6420 | + child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); | ||
| 6421 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 6422 | + assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); | ||
| 6423 | + let stream = out.stdout; | ||
| 6424 | + let frames = match decode_stream(&stream) { | ||
| 6425 | + Err(e) => { | ||
| 6426 | + eprintln!(" {width}x{height} seed {seed}: REFUSED {e}"); | ||
| 6427 | + refused += 1; | ||
| 6428 | + continue; | ||
| 6429 | + } | ||
| 6430 | + Ok(f) => f, | ||
| 6431 | + }; | ||
| 6432 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 6433 | + if frames.len() == 1 | ||
| 6434 | + && frames[0].y == ffmpeg_frames[0].y | ||
| 6435 | + && frames[0].u == ffmpeg_frames[0].u | ||
| 6436 | + && frames[0].v == ffmpeg_frames[0].v | ||
| 6437 | + { | ||
| 6438 | + ok += 1; | ||
| 6439 | + } else { | ||
| 6440 | + bad += 1; | ||
| 6441 | + let mut first = None; | ||
| 6442 | + for row in 0..height { | ||
| 6443 | + for col in 0..width { | ||
| 6444 | + let i = row * width + col; | ||
| 6445 | + if frames[0].y[i] != ffmpeg_frames[0].y[i] { | ||
| 6446 | + first = Some((row, col, frames[0].y[i], ffmpeg_frames[0].y[i])); | ||
| 6447 | + break; | ||
| 6448 | + } | ||
| 6449 | + } | ||
| 6450 | + if first.is_some() { | ||
| 6451 | + break; | ||
| 6452 | + } | ||
| 6453 | + } | ||
| 6454 | + let ndiff = frames[0] | ||
| 6455 | + .y | ||
| 6456 | + .iter() | ||
| 6457 | + .zip(&ffmpeg_frames[0].y) | ||
| 6458 | + .filter(|(a, b)| a != b) | ||
| 6459 | + .count(); | ||
| 6460 | + eprintln!( | ||
| 6461 | + " {width}x{height} seed {seed}: MISMATCH luma first_diff={first:?} ndiff_luma={ndiff}/{}", | ||
| 6462 | + width * height | ||
| 6463 | + ); | ||
| 6464 | + } | ||
| 6465 | + } | ||
| 6466 | + eprintln!("{width}x{height}: {ok} ok / {bad} mismatch / {refused} refused (of {n})"); | ||
| 6467 | + } | ||
| 6468 | + } | ||
| 6469 | + | ||
| 6470 | + /// lane-tiny r1: re-decodes the known-failing 32x32 seed 45 fixture with | ||
| 6471 | + /// `EC_AV1_TRACE` on to inspect what mode/tx this single-block frame | ||
| 6472 | + /// picked. Diagnostic only, `#[ignore]`d, run manually with --nocapture. | ||
| 6473 | + #[test] | ||
| 6474 | + #[ignore = "diagnostic, run manually with --nocapture"] | ||
| 6475 | + fn probe_tiny_32x32_trace() { | ||
| 6476 | + if !have_ffmpeg() || !have_aomenc() { | ||
| 6477 | + eprintln!("SKIP: no ffmpeg/aomenc"); | ||
| 6478 | + return; | ||
| 6479 | + } | ||
| 6480 | + let (width, height) = (32usize, 32usize); | ||
| 6481 | + let attempt = 3u32; // seed 45 | ||
| 6482 | + let source = format!( | ||
| 6483 | + "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}", | ||
| 6484 | + sx = -0.6 + 0.005 * (attempt as f64), | ||
| 6485 | + sy = -0.4 + 0.005 * (attempt as f64) | ||
| 6486 | + ); | ||
| 6487 | + let y4m = Command::new("ffmpeg") | ||
| 6488 | + .args([ | ||
| 6489 | + "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", "yuv420p", | ||
| 6490 | + "-f", "yuv4mpegpipe", "-", | ||
| 6491 | + ]) | ||
| 6492 | + .stdin(Stdio::null()) | ||
| 6493 | + .stdout(Stdio::piped()) | ||
| 6494 | + .stderr(Stdio::piped()) | ||
| 6495 | + .output() | ||
| 6496 | + .expect("ffmpeg failed to run"); | ||
| 6497 | + assert!(y4m.status.success()); | ||
| 6498 | + let args: Vec<&str> = vec![ | ||
| 6499 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", "--cpu-used=4", | ||
| 6500 | + "--kf-max-dist=0", "--limit=1", "--threads=1", "--row-mt=0", | ||
| 6501 | + "--enable-rect-partitions=0", "--enable-ab-partitions=0", | ||
| 6502 | + "--enable-1to4-partitions=0", "--max-partition-size=32", "--min-partition-size=32", | ||
| 6503 | + "--enable-filter-intra=0", | ||
| 6504 | + "--obu", "-o", "-", "-", | ||
| 6505 | + ]; | ||
| 6506 | + let mut child = Command::new(aomenc_path()) | ||
| 6507 | + .args(&args) | ||
| 6508 | + .stdin(Stdio::piped()) | ||
| 6509 | + .stdout(Stdio::piped()) | ||
| 6510 | + .stderr(Stdio::piped()) | ||
| 6511 | + .spawn() | ||
| 6512 | + .expect("aomenc failed to start"); | ||
| 6513 | + child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); | ||
| 6514 | + let out = child.wait_with_output().unwrap(); | ||
| 6515 | + assert!(out.status.success()); | ||
| 6516 | + let stream = out.stdout; | ||
| 6517 | + let frames = decode_stream(&stream).expect("decode"); | ||
| 6518 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); | ||
| 6519 | + let mismatched = frames[0].y != ffmpeg_frames[0].y; | ||
| 6520 | + eprintln!("mismatched={mismatched}"); | ||
| 6521 | + } | ||
| 6522 | + | ||
| 6523 | + /// lane-tiny r2: decodes a raw OBU stream at `EC_TINY_FIXTURE_PATH` -- | ||
| 6524 | + /// no ffmpeg/aomenc invocation -- so a range ladder can be run | ||
| 6525 | + /// (`EC_TRACE_MODE_STEP=1`) against the exact same bytes fed to the | ||
| 6526 | + /// oracle aomdec, byte for byte. `#[ignore]`d diagnostic, no assertion. | ||
| 6527 | + #[test] | ||
| 6528 | + #[ignore = "diagnostic, run manually with --nocapture and EC_TINY_FIXTURE_PATH set"] | ||
| 6529 | + fn probe_tiny_fixture_trace() { | ||
| 6530 | + let path = std::env::var("EC_TINY_FIXTURE_PATH") | ||
| 6531 | + .expect("set EC_TINY_FIXTURE_PATH to an .obu file"); | ||
| 6532 | + let stream = std::fs::read(&path).expect("reading fixture"); | ||
| 6533 | + match decode_stream(&stream) { | ||
| 6534 | + Ok(frames) => { | ||
| 6535 | + eprintln!("decoded {} frame(s)", frames.len()); | ||
| 6536 | + if let Ok(dump) = std::env::var("EC_TINY_FIXTURE_Y_DUMP") { | ||
| 6537 | + let bytes: Vec<u8> = frames[0].y.iter().map(|&v| v as u8).collect(); | ||
| 6538 | + std::fs::write(&dump, &bytes).expect("dump y plane"); | ||
| 6539 | + } | ||
| 6540 | + } | ||
| 6541 | + Err(e) => eprintln!("REFUSED: {e}"), | ||
| 6542 | + } | ||
| 6543 | + } | ||
| 6364 | /// Pinned streams captured by `EC_AV1_GATE_DUMP` off | 6544 | /// Pinned streams captured by `EC_AV1_GATE_DUMP` off |
| 6365 | /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each | 6545 | /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each |
| 6366 | /// one is a former mismatch, kept as a regression pin (warp-mismatch: | 6546 | /// one is a former mismatch, kept as a regression pin (warp-mismatch: |
lanes/tiny-r3.report.mdadded+130 -0
| @@ -0,0 +1,130 @@ | |||
| 1 | +# lane-tiny r3 report | ||
| 2 | + | ||
| 3 | +## Coefficient range ladder result | ||
| 4 | + | ||
| 5 | +Added `EC_TRACE_COEFF` per-symbol range tracing to `read_coeffs` (decode.rs, | ||
| 6 | +tags `all_zero`, `tx_type`, `eob`, `base_eob`, `after_bases`, `sign`, | ||
| 7 | +`post_golomb`) matching the oracle's existing `decodetxb.c` instrumentation | ||
| 8 | +(same var name, same tags -- oracle needed two more trace points added, | ||
| 9 | +`all_zero`/`tx_type` entry ranges, rebuilt via `ninja aomdec` in | ||
| 10 | +`~/.cache/aom-oracle/build`). | ||
| 11 | + | ||
| 12 | +Ran both against the pinned seed-45 32x32 fixture | ||
| 13 | +(`$SCRATCHPAD/seed45.obu`, CFL + filter_intra DC_PRED block, | ||
| 14 | +`filter_intra_mode=3`). | ||
| 15 | + | ||
| 16 | +**`all_zero` matched exactly** (ctx=1, all_zero=0, rng=52448 both sides) -- | ||
| 17 | +the very first symbol of the coefficient layer was clean. | ||
| 18 | + | ||
| 19 | +**Divergence: the very next symbol, `tx_type`.** Ours exited at rng=37340, | ||
| 20 | +oracle at rng=42464. Direction: both consumed a symbol (range narrowed from | ||
| 21 | +the same 52448 entry state) but landed on different final ranges -> a wrong | ||
| 22 | +CDF *row* was read, not a missing/extra read (both sides read exactly one | ||
| 23 | +tx_type symbol here). | ||
| 24 | + | ||
| 25 | +## Root cause | ||
| 26 | + | ||
| 27 | +`av1_read_tx_type` (libaom `decodemv.c:646`): for an **intra** block whose | ||
| 28 | +`filter_intra_mode_info.use_filter_intra` is set, the `intra_ext_tx_cdf` row | ||
| 29 | +index is | ||
| 30 | + | ||
| 31 | +```c | ||
| 32 | +const PREDICTION_MODE intra_mode = | ||
| 33 | + mbmi->filter_intra_mode_info.use_filter_intra | ||
| 34 | + ? fimode_to_intradir[mbmi->filter_intra_mode_info.filter_intra_mode] | ||
| 35 | + : mbmi->mode; | ||
| 36 | +``` | ||
| 37 | + | ||
| 38 | +`fimode_to_intradir = { DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED }` | ||
| 39 | +(`blockd.h:180`) -- **not** the block's ordinary `mode`, which is always | ||
| 40 | +`DC_PRED` whenever filter-intra is active (spec: filter-intra blocks always | ||
| 41 | +carry `mode == DC_PRED`, the interesting information is in | ||
| 42 | +`filter_intra_mode`). Every `read_plane` call site in `decode.rs` passed the | ||
| 43 | +block's plain `mode` (here `DC_PRED == 0`) as `tx_mode` regardless of | ||
| 44 | +filter_intra, so the CDF lookup always used the DC_PRED row instead of | ||
| 45 | +`D157_PRED` (index 6) for `filter_intra_mode=3`. Wrong row -> wrong symbol -> | ||
| 46 | +correctly-consumed bits but wrong resulting range and wrong `tx_type`, and | ||
| 47 | +everything downstream (scan order, base/br contexts) reads off the wrong | ||
| 48 | +axis from the very first coefficient TU on. | ||
| 49 | + | ||
| 50 | +## What shipped | ||
| 51 | + | ||
| 52 | +**Fix**, `crates/ec-av1/src/decode.rs`, `read_plane` (the single shared | ||
| 53 | +chroma/luma coefficient entry point every multi-TU and single-TU luma call | ||
| 54 | +routes through): when `plane_idx == 0` and `filter_intra` is `Some(mode)`, | ||
| 55 | +remap `tx_mode` through `FIMODE_TO_INTRADIR = [DC_PRED, V_PRED, H_PRED, | ||
| 56 | +D157_PRED, DC_PRED]` before the `cdfs.txb(set, tx_mode)` lookup. Added | ||
| 57 | +`H_PRED`/`D157_PRED` consts (matched libaom's numbering: DC=0, V=1, H=2, | ||
| 58 | +D157=6, verified against `crates/ec-av1/src/intra.rs`'s existing constants). | ||
| 59 | + | ||
| 60 | +One fix point covers every caller (chroma is unaffected by construction -- | ||
| 61 | +`plane_idx != 0` never touches the new branch, and chroma has no | ||
| 62 | +filter-intra in AV1 to begin with). | ||
| 63 | + | ||
| 64 | +**Gate**: the existing `probe_tiny_frame_size_boundary` diagnostic sweep | ||
| 65 | +(size x seed matrix, real aomenc + ffmpeg oracle) now shows: | ||
| 66 | + | ||
| 67 | +| size | before | after | | ||
| 68 | +|-------|--------|-------| | ||
| 69 | +| 32x32 | 3/10 | **10/10** | | ||
| 70 | +| 24x24 | 3/10 | **10/10** | | ||
| 71 | +| 16x32 | 2/10 | **10/10** | | ||
| 72 | +| 32x16 | 2/10 | 8/10 (residual, see Open) | | ||
| 73 | +| 16x16, 48x48, 64x64 | 10/10 | 10/10 (unaffected, already clean) | | ||
| 74 | + | ||
| 75 | +This is a `#[ignore]`d diagnostic, not a hard-asserting gate (matches its | ||
| 76 | +pre-existing shape from r1/r2; converting it into a hard-asserting | ||
| 77 | +`stream.rs` gate in the `a_real_aomenc_*` style is the natural next step but | ||
| 78 | +did not fit this round's budget -- flagged in Open below). | ||
| 79 | + | ||
| 80 | +## Investigated and REJECTED as a fix | ||
| 81 | + | ||
| 82 | +Chased a second lead from the same trace session: the chroma `txb_skip_ctx` | ||
| 83 | +computation (`usize::from(around.0) + usize::from(around.1)`, range 0..2) | ||
| 84 | +looked wrong against libaom's `get_txb_ctx`'s chroma branch, which is | ||
| 85 | +`get_entropy_context(...) + ctx_offset` where `ctx_offset` is 7 (chroma | ||
| 86 | +plane_bsize == tx size, i.e. always true here since chroma is never split | ||
| 87 | +into multiple TUs in this decoder). Oracle traced `ctx=7` where ours prints | ||
| 88 | +`ctx=0` for the identical read -- **but this is not a bug**: our | ||
| 89 | +`txb_skip_chroma_8`/`_16`/`_32`/`_4` CDF tables (`cdf_state.rs`) are already | ||
| 90 | +pre-sliced 3-row extracts of the full 13-row spec table taken at the correct | ||
| 91 | +7/10 offset (`TXB_SKIP_CHROMA_8` etc., confirmed by grep at their | ||
| 92 | +initializer). Index 0 in our local table *is* spec index 7 -- the two | ||
| 93 | +printed "ctx" numbers are in different local bases for the same CDF row, | ||
| 94 | +which is exactly why the traced range matched exactly in that instance. | ||
| 95 | +Applying a `+ 7` there panicked immediately (`index out of bounds: len 3, | ||
| 96 | +index 7`) on the very first refused-8x8-then-16x16 case, confirmed the | ||
| 97 | +tables are chroma-relative already, and was reverted in full before commit | ||
| 98 | +(`git diff` verified clean, no residue in the shipped commit). | ||
| 99 | + | ||
| 100 | +## Open (not shipped this round) | ||
| 101 | + | ||
| 102 | +- **32x16 residual, 2/10 seeds**: `first_diff=None, ndiff_luma=0/512` -- | ||
| 103 | + luma is bit-exact, only chroma differs, for exactly 2 of 10 seeds at one | ||
| 104 | + specific rectangular aspect (32x16, not its transpose 16x32 which is now | ||
| 105 | + 10/10). Not characterized further this round (budget). Not gated or | ||
| 106 | + refused -- this is a real "wrong pixels returned as success" gap per the | ||
| 107 | + charter's own standard, scoped narrower than what shipped fixed. Next | ||
| 108 | + round: re-run the same `EC_TRACE_COEFF`/`EC_TRACE_MODE_STEP` ladder on one | ||
| 109 | + of the two failing 32x16 seed-47/42 fixtures (pin them first, aomenc | ||
| 110 | + output is seeded but re-verify determinism per | ||
| 111 | + `seeded-fixture-not-reproducible.md`) to find the actual desync point -- | ||
| 112 | + it is chroma-only, so start with the chroma predict path / CFL / | ||
| 113 | + uv_predict_mode rather than the luma tx_type fix's territory. | ||
| 114 | +- `probe_tiny_frame_size_boundary` is still `#[ignore]`d and non-asserting. | ||
| 115 | + Promoting it to a hard-asserting gate under `stream.rs` (model: | ||
| 116 | + `a_real_aomenc_*_decodes_pixel_exact`, `EC_AV1_REQUIRE_AOMENC=1`, | ||
| 117 | + hard-assert a hit counter, no printed SKIP on decode error) is the | ||
| 118 | + natural follow-up once the 32x16 residual is closed too -- gating it now | ||
| 119 | + would either need to accept 32x16 as a known-flaky size (against the | ||
| 120 | + charter's own "never mismatch" rule) or hard-code a size exclusion, both | ||
| 121 | + of which are worse than finishing the fix. | ||
| 122 | + | ||
| 123 | +## Verification | ||
| 124 | + | ||
| 125 | +- `cargo test -p ec-av1 --lib`: **266 passed, 0 failed, 22 ignored** (221s). | ||
| 126 | +- `cargo check --workspace --all-targets`: clean, 0 errors. | ||
| 127 | +- HEAD: `1a89ed9` (branch `lane-tiny`). | ||
| 128 | + | ||
| 129 | +EVIDENCE: `cargo test -p ec-av1 --lib -- --ignored --nocapture probe_tiny_frame_size_boundary` | 32x32/24x24/16x32 3-or-2-of-10 -> 10/10, 32x16 2/10 -> 8/10, all other sizes unchanged at 10/10 | before/after table above | ||
| 130 | +EVIDENCE: EC_TRACE_COEFF range ladder, seed45.obu, oracle vs ours | all_zero ctx=1 all_zero=0 rng=52448 matches both sides; tx_type exit rng 37340 (ours) vs 42464 (oracle) is the first divergent element | fixed by filter-intra tx_type CDF row remap, commit 1a89ed9 | ||