forge
Explore
Log in

Don't you dare go Hollow

ec-av1: 4:4:4 chroma byte-exact (square profile-1, filters off)

Browse files at this commit

a44ac26bb333e0113f7d4d6e35eda498facde121Ahmet Kaan GümüşParent: d6b7cc7
Two fixes on top of the staged WIP:

1. decode_block's single-TU arm: at 4:4:4 a 64x64 block's chroma plane
   block is 64x64 but av1_get_max_uv_txsize caps the uv transform at
   TX_32X32 (av1_get_adjusted_tx_size, blockd.h:1361), so the block
   codes four chroma units plane-major (decodeframe.c
   decode_token_recon_block: for(plane) for(blk_row) for(blk_col)).
   The arm now runs the multi-TU arm's cn x cn chroma loop when
   chroma_side > chroma_tx; at 4:2:0 chroma_side == chroma_tx and the
   old single-read path is kept.

2. Root cause of the remaining 36k chroma diffs: u/v set_tile_origin
   hardcoded the 4:2:0 halving (mi * 2). At 4:4:4 the halved tile_x1
   clamped PlaneBuf::edges' across below the block's own x for every
   chroma block in the right half of the tile (and tile_y1 the left
   edge in the bottom half), so those blocks predicted with edges
   missing (left-only/above-only/no DC). Tile bounds now follow the
   sequence subsampling (mi * 4 >> ss); identical at 4:2:0.

Witnesses (aomenc oracle, aomdec+ffmpeg cross-checked):
- square profile-1 444 filters off: IDENTICAL (98304 B, 2 frames)
- 420 square profile-0 filters off: IDENTICAL (regression arm)
- 444 forced 64x64 blocks (gradients --min-partition-size=64):
  IDENTICAL, exercises the cn=2 chroma loop (8 64x64 leaves)
- full entropy ladder vs instrumented aomdec: 1596/1596 rng rungs
crates/ec-av1/src/decode.rsmodified+153 -76
@@ -14887,68 +14887,145 @@ fn decode_block(
14887 if intrabc_dv.is_some() {14887 if intrabc_dv.is_some() {
14888 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));14888 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));
14889 }14889 }
14890- if let Some((ub, _)) = &palette_uv_bufs {14890+ // lane-av1-444: this arm is one luma TU (`logical_tx == side`), including
14891- set_palette_pred(ub.clone(), fctx);14891+ // the 64x64 case whose coefficient grid is 32. At 4:4:4 the chroma plane
14892- }14892+ // is the same size as luma and `av1_get_max_uv_txsize` caps it at
14893- // lane-av1-444: a 64x64 block takes this arm (`logical_tx == side`).14893+ // TX_32X32, so a 64x64 block codes four chroma units, plane-major
14894- // At 4:4:4 its chroma plane is 64x64 and libaom codes four TX_32X3214894+ // (every U, then every V) — the same loop the multi-TU arm runs.
14895- // units. This read is still one unit (`chroma_side` x `chroma_tx`).14895+ // At 4:2:0 `chroma_side == chroma_tx`, so it stays one read.
14896- // Luma of that block matches; chroma does not. See lanes/av1444.report.md.14896+ let cn = (chroma_side / chroma_tx).max(1);
14897- let u_grid = read_plane(14897+ let (u_grid, v_grid, chroma_units) = if cn == 1 {
14898- dec,14898+ if let Some((ub, _)) = &palette_uv_bufs {
14899- cdfs,14899+ set_palette_pred(ub.clone(), fctx);
14900- chroma_set,14900+ }
14901- scans.1,14901+ let u_grid = read_plane(
14902- 1,14902+ dec,
14903- around[1],14903+ cdfs,
14904- mode,14904+ chroma_set,
14905- uv_predict_mode,14905+ scans.1,
14906- angle_delta_uv,14906+ 1,
14907- reach,14907+ around[1],
14908- u,14908+ mode,
14909- cpx,14909+ uv_predict_mode,
14910- cpy,14910+ angle_delta_uv,
14911- chroma_side,14911+ reach,
14912- chroma_tx,14912+ u,
14913- base_q_idx,14913+ cpx,
14914- alpha.zip(ac).map(|((au, _), ac)| (au, ac)),14914+ cpy,
14915- None,14915+ chroma_side,
14916- None,14916+ chroma_tx,
14917- smooth_neighbor_uv, fctx,14917+ base_q_idx,
14918- )?;14918+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
14919- if crate::envflags::env_flag!("EC_AV1_TRACE") {14919+ None,
14920- eprintln!(14920+ None,
14921- "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",14921+ smooth_neighbor_uv, fctx,
14922- &u.data[cpy * u.width + cpx..][..chroma_side]14922+ )?;
14923- );14923+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
14924- }14924+ eprintln!(
14925- if let Some((_, vb)) = &palette_uv_bufs {14925+ "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",
14926- set_palette_pred(vb.clone(), fctx);14926+ &u.data[cpy * u.width + cpx..][..chroma_side]
14927- }14927+ );
14928- let v_grid = read_plane(14928+ }
14929- dec,14929+ if let Some((_, vb)) = &palette_uv_bufs {
14930- cdfs,14930+ set_palette_pred(vb.clone(), fctx);
14931- chroma_set,14931+ }
14932- scans.1,14932+ let v_grid = read_plane(
14933- 2,14933+ dec,
14934- around[2],14934+ cdfs,
14935- mode,14935+ chroma_set,
14936- uv_predict_mode,14936+ scans.1,
14937- angle_delta_uv,14937+ 2,
14938- reach,14938+ around[2],
14939- v,14939+ mode,
14940- cpx,14940+ uv_predict_mode,
14941- cpy,14941+ angle_delta_uv,
14942- chroma_side,14942+ reach,
14943- chroma_tx,14943+ v,
14944- base_q_idx,14944+ cpx,
14945- alpha.zip(ac).map(|((_, av), ac)| (av, ac)),14945+ cpy,
14946- None,14946+ chroma_side,
14947- None,14947+ chroma_tx,
14948- smooth_neighbor_uv, fctx,14948+ base_q_idx,
14949- )?;14949+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
14950+ None,
14951+ None,
14952+ smooth_neighbor_uv, fctx,
14953+ )?;
14954+ (u_grid, v_grid, Vec::new())
14955+ } else {
14956+ let chroma_ctx_offset = Some(3);
14957+ let mut u_pass: Vec<Grid> = Vec::new();
14958+ let mut units: Vec<((usize, usize), usize, Grid, Grid)> = Vec::new();
14959+ let mut last_grids = [Grid::Zero(0), Grid::Zero(0)];
14960+ for plane_pass in 1..=2usize {
14961+ let mut pass_idx = 0usize;
14962+ for cu_row in 0..cn {
14963+ for cu_col in 0..cn {
14964+ let luma_span = chroma_tx << ss_x(fctx);
14965+ let cu_mi = (
14966+ mi_r + cu_row * (luma_span / MI),
14967+ mi_c + cu_col * (luma_span / MI),
14968+ );
14969+ let cu_around = neighbours.around_mi(cu_mi, luma_span);
14970+ let cu_reach = tu_reach(
14971+ side,
14972+ side,
14973+ cu_col * luma_span,
14974+ cu_row * luma_span,
14975+ luma_span,
14976+ reach,
14977+ px,
14978+ py,
14979+ y.width,
14980+ y.height, fctx,
14981+ );
14982+ let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx);
14983+ if let Some((ub, vb)) = &palette_uv_bufs {
14984+ let pbuf = if plane_pass == 1 { ub } else { vb };
14985+ set_palette_pred(
14986+ palette_window(
14987+ pbuf, chroma_side, cu_col * chroma_tx, cu_row * chroma_tx,
14988+ chroma_tx, chroma_tx,
14989+ ),
14990+ fctx,
14991+ );
14992+ }
14993+ let buf: &mut PlaneBuf<'static> =
14994+ if plane_pass == 1 { &mut *u } else { &mut *v };
14995+ let cu_grid = read_plane(
14996+ dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode,
14997+ uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y,
14998+ chroma_tx, chroma_tx, base_q_idx,
14999+ alpha.zip(ac).map(|((au, av), ac)| {
15000+ (if plane_pass == 1 { au } else { av }, ac)
15001+ }),
15002+ None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
15003+ )?;
15004+ hit!(CHROMA_SPLIT_TX_HITS);
15005+ // Immediately, so the next unit of this block reads this
15006+ // one's coefficient context. `record` below stamps one
15007+ // chroma state across the whole block; the replay after
15008+ // it puts the per-unit state back.
15009+ neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_pass, &cu_grid);
15010+ if plane_pass == 1 {
15011+ u_pass.push(cu_grid);
15012+ } else {
15013+ let u_grid = std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0));
15014+ units.push((cu_mi, luma_span, u_grid.clone(), cu_grid.clone()));
15015+ last_grids = [u_grid, cu_grid];
15016+ }
15017+ pass_idx += 1;
15018+ }
15019+ }
15020+ }
15021+ (last_grids[0].clone(), last_grids[1].clone(), units)
15022+ };
14950 fctx.intrabc_chroma_tx.with(|c| c.set(None));15023 fctx.intrabc_chroma_tx.with(|c| c.set(None));
14951 neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);15024 neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
15025+ for (cu_mi, luma_span, u_unit, v_unit) in &chroma_units {
15026+ neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 1, u_unit);
15027+ neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 2, v_unit);
15028+ }
14952 } else {15029 } else {
14953 // Several luma transform units, raster order (spec15030 // Several luma transform units, raster order (spec
14954 // `transform_block`'s loop): the block's resolved transform is15031 // `transform_block`'s loop): the block's resolved transform is
@@ -23103,16 +23180,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
23103 (mi_row1 as usize * 4).min(y.height),23180 (mi_row1 as usize * 4).min(y.height),
23104 );23181 );
23105 u.set_tile_origin(23182 u.set_tile_origin(
23106- mi_col0 as usize * 2,23183+ (mi_col0 as usize * 4) >> ss_x(fctx),
23107- mi_row0 as usize * 2,23184+ (mi_row0 as usize * 4) >> ss_y(fctx),
23108- (mi_col1 as usize * 2).min(u.width),23185+ ((mi_col1 as usize * 4) >> ss_x(fctx)).min(u.width),
23109- (mi_row1 as usize * 2).min(u.height),23186+ ((mi_row1 as usize * 4) >> ss_y(fctx)).min(u.height),
23110 );23187 );
23111 v.set_tile_origin(23188 v.set_tile_origin(
23112- mi_col0 as usize * 2,23189+ (mi_col0 as usize * 4) >> ss_x(fctx),
23113- mi_row0 as usize * 2,23190+ (mi_row0 as usize * 4) >> ss_y(fctx),
23114- (mi_col1 as usize * 2).min(v.width),23191+ ((mi_col1 as usize * 4) >> ss_x(fctx)).min(v.width),
23115- (mi_row1 as usize * 2).min(v.height),23192+ ((mi_row1 as usize * 4) >> ss_y(fctx)).min(v.height),
23116 );23193 );
23117 hit!(TILE_HITS);23194 hit!(TILE_HITS);
23118 23195
@@ -35870,16 +35947,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
35870 (mi_row1 as usize * 4).min(y.height),35947 (mi_row1 as usize * 4).min(y.height),
35871 );35948 );
35872 u.set_tile_origin(35949 u.set_tile_origin(
35873- mi_col0 as usize * 2,35950+ (mi_col0 as usize * 4) >> ss_x(fctx),
35874- mi_row0 as usize * 2,35951+ (mi_row0 as usize * 4) >> ss_y(fctx),
35875- (mi_col1 as usize * 2).min(u.width),35952+ ((mi_col1 as usize * 4) >> ss_x(fctx)).min(u.width),
35876- (mi_row1 as usize * 2).min(u.height),35953+ ((mi_row1 as usize * 4) >> ss_y(fctx)).min(u.height),
35877 );35954 );
35878 v.set_tile_origin(35955 v.set_tile_origin(
35879- mi_col0 as usize * 2,35956+ (mi_col0 as usize * 4) >> ss_x(fctx),
35880- mi_row0 as usize * 2,35957+ (mi_row0 as usize * 4) >> ss_y(fctx),
35881- (mi_col1 as usize * 2).min(v.width),35958+ ((mi_col1 as usize * 4) >> ss_x(fctx)).min(v.width),
35882- (mi_row1 as usize * 2).min(v.height),35959+ ((mi_row1 as usize * 4) >> ss_y(fctx)).min(v.height),
35883 );35960 );
35884 // lane-tiles r6: an MV candidate scan (mvstack.rs's grid.get) must35961 // lane-tiles r6: an MV candidate scan (mvstack.rs's grid.get) must
35885 // not reach across a tile boundary any more than intra prediction's35962 // not reach across a tile boundary any more than intra prediction's