forge
Explore
Log in

Don't you dare go Hollow

wip(sub8): session restart -- uncommitted builder state preserved by orchestrator

Browse files at this commit

00f1f0d7461a60932065c722e86a478b74ac5942Ahmet Kaan GümüşParent: 915be45
crates/ec-av1/src/decode.rsmodified+96 -38
@@ -4039,7 +4039,7 @@ fn read_intra_mode(
40394039 }
40404040 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
40414041 if trace {
4042- eprintln!("TRACE skip value={}", skip as i32);
4042+ eprintln!("TRACE skip value={} rng={}", skip as i32, dec.debug_state().0);
40434043 }
40444044 istep!("skip", skip as i32);
40454045 // spec order (see the comment below on `read_intrabc_info`): `skip`,
@@ -4073,7 +4073,7 @@ fn read_intra_mode(
40734073 let left_ctx = INTRA_MODE_CTX[left_mode];
40744074 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
40754075 if trace {
4076- eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode}");
4076+ eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0);
40774077 }
40784078 istep!("mode", mode as i32);
40794079 let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {
@@ -4095,7 +4095,7 @@ fn read_intra_mode(
40954095 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
40964096 };
40974097 if trace {
4098- eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode}");
4098+ eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode} rng={}", dec.debug_state().0);
40994099 }
41004100 istep!("uv_mode", uv_mode as i32);
41014101 let alpha = if cfl && uv_mode == UV_CFL_PRED {
@@ -4214,7 +4214,7 @@ fn read_intra_mode(
42144214 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
42154215 if trace {
42164216 eprintln!(
4217- "TRACE use_filter_intra side={side} value={}",
4217+ "TRACE use_filter_intra side={side} rng={} value={}", dec.debug_state().0,
42184218 use_filter_intra as i32
42194219 );
42204220 }
@@ -5483,7 +5483,7 @@ fn read_intra_mode_sub8(
54835483 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
54845484 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
54855485 if trace {
5486- eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) value={}", skip as i32);
5486+ eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0);
54875487 }
54885488 maybe_read_cdef_idx(dec, mi_r, mi_c, skip);
54895489 maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip);
@@ -5500,17 +5500,18 @@ fn read_intra_mode_sub8(
55005500 let left_ctx = INTRA_MODE_CTX[left_mode];
55015501 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
55025502 if trace {
5503- eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode}");
5504- }
5505- let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {
5506- read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED])
5507- } else {
5508- 0
5509- };
5503+ eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0);
5504+ }
5505+ // No `angle_delta` at all below 8x8: spec 5.11.6's `intra_angle_info_y`/
5506+ // `_uv` are gated on `MiSize >= BLOCK_8X8` (libaom `av1_use_angle_delta`,
5507+ // blockd.h), so a directional mode on a `BLOCK_4X4` leaf carries no delta
5508+ // symbol. Reading one consumed a symbol the encoder never wrote and
5509+ // desynced the tile at the very next element.
5510+ let angle_delta_y = 0;
55105511 let chroma = if has_chroma {
55115512 let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);
55125513 if trace {
5513- eprintln!("TRACE sub8 uv_mode value={uv_mode}");
5514+ eprintln!("TRACE sub8 uv_mode value={uv_mode} rng={}", dec.debug_state().0);
55145515 }
55155516 if (9..=12).contains(&uv_mode) {
55165517 SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
@@ -5520,12 +5521,11 @@ fn read_intra_mode_sub8(
55205521 } else {
55215522 None
55225523 };
5523- let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
5524+ if (V_PRED..=D67_PRED).contains(&uv_mode) {
55245525 DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
5525- read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
5526- } else {
5527- 0
5528- };
5526+ }
5527+ // See the luma comment above: no angle delta below 8x8.
5528+ let angle_delta_uv = 0;
55295529 Some((uv_mode, angle_delta_uv, alpha))
55305530 } else {
55315531 None
@@ -5573,7 +5573,10 @@ fn decode_leaf_split4(
55735573 enable_filter_intra: bool,
55745574 allow_intrabc: bool,
55755575 reduced_tx_set: bool,
5576-) -> Result<usize> {
5576+ // Returns `(below_mode, right_mode)`: the mode a neighbour BELOW this 8x8
5577+ // group sees (its bottom-left 4x4, libaom reads mi(row-1, col)) and the
5578+ // one a neighbour to its RIGHT sees (its top-right 4x4, mi(row, col-1)).
5579+) -> Result<(usize, usize)> {
55775580 SUB8_SPLIT_HITS.with(|c| c.set(c.get() + 1));
55785581 let (r, c) = outer_at;
55795582 let mut above_mode = neighbours.above_mode[c];
@@ -5612,7 +5615,11 @@ fn decode_leaf_split4(
56125615 neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
56135616 } else {
56145617 let tu_around = neighbours.around_mi(lmi, 4)[0];
5615- let tu_skip_ctx = neighbours.luma_skip_ctx(lmi, 1);
5618+ // A `BLOCK_4X4` leaf's luma TU *is* the whole block, so libaom's
5619+ // `get_txb_ctx` takes its `plane_bsize == txsize_to_bsize[tx_size]`
5620+ // branch: `txb_skip_ctx = 0`, never the neighbour-magnitude table
5621+ // (`txb_common.h:400`). Reading the table here decoded `all_zero`
5622+ // off the wrong CDF on the very first leaf and desynced the tile.
56165623 let tu_grid = read_plane(
56175624 dec,
56185625 cdfs,
@@ -5632,7 +5639,7 @@ fn decode_leaf_split4(
56325639 base_q_idx,
56335640 None,
56345641 filter_intra,
5635- Some(tu_skip_ctx),
5642+ None,
56365643 smooth_neighbor,
56375644 )?;
56385645 neighbours.record_mi_luma(lmi, 4, &tu_grid);
@@ -5704,7 +5711,7 @@ fn decode_leaf_split4(
57045711 neighbours.above[leaf_mi.1 + cell][2] = v_state;
57055712 }
57065713 }
5707- Ok(leaf_modes[3])
5714+ Ok((leaf_modes[2], leaf_modes[1]))
57085715 }
57095716
57105717 /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary
@@ -7352,11 +7359,38 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
73527359 // the one or two the edge leaves.
73537360 let (mi_row0, mi_col0) =
73547361 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
7355- let mut prev_leaf: Option<((usize, usize), usize)> = None;
7362+ // Each 8x8 leaf's intra-mode context
7363+ // must see its own siblings: the
7364+ // bottom-left leaf's ABOVE neighbour
7365+ // is leaf 0, not the previously
7366+ // decoded leaf 1 (and the bottom-right
7367+ // leaf's above is leaf 1, while
7368+ // `prev_leaf` only ever carried the
7369+ // immediately preceding one). The
7370+ // coarse `above_mode`/`left_mode`
7371+ // arrays hold one slot per 16x16, so
7372+ // the sibling modes are swapped in
7373+ // around each leaf call and restored
7374+ // after; the loop tail writes the last
7375+ // leaf's mode as before.
7376+ let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4];
73567377 for i in 0..4 {
73577378 let (mr, mc) =
73587379 (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);
73597380 let leaf_mi = (mr as usize, mc as usize);
7381+ let li = i as usize;
7382+ let saved_modes =
7383+ (neighbours.above_mode[sc], neighbours.left_mode[sr]);
7384+ if li >= 2 {
7385+ if let Some((below, _)) = sib_modes[li - 2] {
7386+ neighbours.above_mode[sc] = below;
7387+ }
7388+ }
7389+ if li % 2 == 1 {
7390+ if let Some((_, right)) = sib_modes[li - 1] {
7391+ neighbours.left_mode[sr] = right;
7392+ }
7393+ }
73607394 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
73617395 let part8 =
73627396 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
@@ -7373,7 +7407,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
73737407 at16,
73747408 leaf_mi,
73757409 (&scan8, &scan4),
7376- prev_leaf,
7410+ None,
73777411 &mut y,
73787412 &mut u,
73797413 &mut v,
@@ -7383,7 +7417,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
73837417 allow_intrabc,
73847418 tx_select,
73857419 reduced_tx_set,
7386- )?
7420+ ).map(|m| (m, m))?
73877421 } else if part8 == PARTITION_SPLIT {
73887422 decode_leaf_split4(
73897423 &mut dec,
@@ -7392,7 +7426,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
73927426 at16,
73937427 leaf_mi,
73947428 &scan4,
7395- prev_leaf,
7429+ None,
73967430 &mut y,
73977431 &mut u,
73987432 &mut v,
@@ -7406,11 +7440,15 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
74067440 "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)",
74077441 ));
74087442 };
7409- prev_leaf = Some((leaf_mi, leaf_mode));
7443+ neighbours.above_mode[sc] = saved_modes.0;
7444+ neighbours.left_mode[sr] = saved_modes.1;
7445+ sib_modes[li] = Some(leaf_mode);
74107446 }
7411- if let Some((_, mode)) = prev_leaf {
7412- neighbours.above_mode[sc] = mode;
7413- neighbours.left_mode[sr] = mode;
7447+ if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) {
7448+ neighbours.above_mode[sc] = below;
7449+ }
7450+ if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) {
7451+ neighbours.left_mode[sr] = right;
74147452 }
74157453 continue;
74167454 }
@@ -7444,9 +7482,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
74447482 .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2))
74457483 .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols)
74467484 .collect();
7447- let mut prev_leaf: Option<((usize, usize), usize)> = None;
7485+ // See the sibling-mode note in the clean
7486+ // SPLIT path above.
7487+ let mut sib_modes: [Option<(usize, usize)>; 4] = [None; 4];
74487488 for (mr, mc) in leaf_positions {
74497489 let leaf_mi = (mr as usize, mc as usize);
7490+ let li = (((mr - mi_row0) / 2) * 2 + (mc - mi_col0) / 2)
7491+ as usize;
7492+ let saved_modes =
7493+ (neighbours.above_mode[sc], neighbours.left_mode[sr]);
7494+ if li >= 2 {
7495+ if let Some((below, _)) = sib_modes[li - 2] {
7496+ neighbours.above_mode[sc] = below;
7497+ }
7498+ }
7499+ if li % 2 == 1 {
7500+ if let Some((_, right)) = sib_modes[li - 1] {
7501+ neighbours.left_mode[sr] = right;
7502+ }
7503+ }
74507504 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
74517505 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
74527506 if std::env::var_os("EC_AV1_TRACE").is_some() {
@@ -7462,7 +7516,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
74627516 at16,
74637517 leaf_mi,
74647518 (&scan8, &scan4),
7465- prev_leaf,
7519+ None,
74667520 &mut y,
74677521 &mut u,
74687522 &mut v,
@@ -7472,7 +7526,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
74727526 allow_intrabc,
74737527 tx_select,
74747528 reduced_tx_set,
7475- )?
7529+ ).map(|m| (m, m))?
74767530 } else if part8 == PARTITION_SPLIT {
74777531 decode_leaf_split4(
74787532 &mut dec,
@@ -7481,7 +7535,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
74817535 at16,
74827536 leaf_mi,
74837537 &scan4,
7484- prev_leaf,
7538+ None,
74857539 &mut y,
74867540 &mut u,
74877541 &mut v,
@@ -7495,7 +7549,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
74957549 "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)",
74967550 ));
74977551 };
7498- prev_leaf = Some((leaf_mi, leaf_mode));
7552+ neighbours.above_mode[sc] = saved_modes.0;
7553+ neighbours.left_mode[sr] = saved_modes.1;
7554+ sib_modes[li] = Some(leaf_mode);
74997555 }
75007556 // `record()`'s `above_mode`/`left_mode`
75017557 // write is a no-op at an 8x8 leaf's own
@@ -7503,9 +7559,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
75037559 // 16x16 slot's leaves are done, from the
75047560 // last leaf (mirrors the writer's r15
75057561 // fix).
7506- if let Some((_, mode)) = prev_leaf {
7507- neighbours.above_mode[sc] = mode;
7508- neighbours.left_mode[sr] = mode;
7562+ if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) {
7563+ neighbours.above_mode[sc] = below;
7564+ }
7565+ if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) {
7566+ neighbours.left_mode[sr] = right;
75097567 }
75107568 }
75117569 }