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(
4039 }4039 }
4040 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;4040 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
4041 if trace {4041 if trace {
4042- eprintln!("TRACE skip value={}", skip as i32);4042+ eprintln!("TRACE skip value={} rng={}", skip as i32, dec.debug_state().0);
4043 }4043 }
4044 istep!("skip", skip as i32);4044 istep!("skip", skip as i32);
4045 // spec order (see the comment below on `read_intrabc_info`): `skip`,4045 // spec order (see the comment below on `read_intrabc_info`): `skip`,
@@ -4073,7 +4073,7 @@ fn read_intra_mode(
4073 let left_ctx = INTRA_MODE_CTX[left_mode];4073 let left_ctx = INTRA_MODE_CTX[left_mode];
4074 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);4074 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
4075 if trace {4075 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);
4077 }4077 }
4078 istep!("mode", mode as i32);4078 istep!("mode", mode as i32);
4079 let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {4079 let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {
@@ -4095,7 +4095,7 @@ fn read_intra_mode(
4095 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])4095 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
4096 };4096 };
4097 if trace {4097 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);
4099 }4099 }
4100 istep!("uv_mode", uv_mode as i32);4100 istep!("uv_mode", uv_mode as i32);
4101 let alpha = if cfl && uv_mode == UV_CFL_PRED {4101 let alpha = if cfl && uv_mode == UV_CFL_PRED {
@@ -4214,7 +4214,7 @@ fn read_intra_mode(
4214 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;4214 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
4215 if trace {4215 if trace {
4216 eprintln!(4216 eprintln!(
4217- "TRACE use_filter_intra side={side} value={}",4217+ "TRACE use_filter_intra side={side} rng={} value={}", dec.debug_state().0,
4218 use_filter_intra as i324218 use_filter_intra as i32
4219 );4219 );
4220 }4220 }
@@ -5483,7 +5483,7 @@ fn read_intra_mode_sub8(
5483 let trace = std::env::var_os("EC_AV1_TRACE").is_some();5483 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
5484 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;5484 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
5485 if trace {5485 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);
5487 }5487 }
5488 maybe_read_cdef_idx(dec, mi_r, mi_c, skip);5488 maybe_read_cdef_idx(dec, mi_r, mi_c, skip);
5489 maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip);5489 maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip);
@@ -5500,17 +5500,18 @@ fn read_intra_mode_sub8(
5500 let left_ctx = INTRA_MODE_CTX[left_mode];5500 let left_ctx = INTRA_MODE_CTX[left_mode];
5501 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);5501 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
5502 if trace {5502 if trace {
5503- eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode}");5503+ eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0);
5504- }5504+ }
5505- let angle_delta_y = if (V_PRED..=D67_PRED).contains(&mode) {5505+ // No `angle_delta` at all below 8x8: spec 5.11.6's `intra_angle_info_y`/
5506- read_angle_delta(dec, &mut cdfs.angle_delta[mode - V_PRED])5506+ // `_uv` are gated on `MiSize >= BLOCK_8X8` (libaom `av1_use_angle_delta`,
5507- } else {5507+ // blockd.h), so a directional mode on a `BLOCK_4X4` leaf carries no delta
5508- 05508+ // symbol. Reading one consumed a symbol the encoder never wrote and
5509- };5509+ // desynced the tile at the very next element.
5510+ let angle_delta_y = 0;
5510 let chroma = if has_chroma {5511 let chroma = if has_chroma {
5511 let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);5512 let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);
5512 if trace {5513 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);
5514 }5515 }
5515 if (9..=12).contains(&uv_mode) {5516 if (9..=12).contains(&uv_mode) {
5516 SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));5517 SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
@@ -5520,12 +5521,11 @@ fn read_intra_mode_sub8(
5520 } else {5521 } else {
5521 None5522 None
5522 };5523 };
5523- let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {5524+ if (V_PRED..=D67_PRED).contains(&uv_mode) {
5524 DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));5525 DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
5525- read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])5526+ }
5526- } else {5527+ // See the luma comment above: no angle delta below 8x8.
5527- 05528+ let angle_delta_uv = 0;
5528- };
5529 Some((uv_mode, angle_delta_uv, alpha))5529 Some((uv_mode, angle_delta_uv, alpha))
5530 } else {5530 } else {
5531 None5531 None
@@ -5573,7 +5573,10 @@ fn decode_leaf_split4(
5573 enable_filter_intra: bool,5573 enable_filter_intra: bool,
5574 allow_intrabc: bool,5574 allow_intrabc: bool,
5575 reduced_tx_set: bool,5575 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)> {
5577 SUB8_SPLIT_HITS.with(|c| c.set(c.get() + 1));5580 SUB8_SPLIT_HITS.with(|c| c.set(c.get() + 1));
5578 let (r, c) = outer_at;5581 let (r, c) = outer_at;
5579 let mut above_mode = neighbours.above_mode[c];5582 let mut above_mode = neighbours.above_mode[c];
@@ -5612,7 +5615,11 @@ fn decode_leaf_split4(
5612 neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);5615 neighbours.record_mi_luma(lmi, 4, &vec![0i32; 16]);
5613 } else {5616 } else {
5614 let tu_around = neighbours.around_mi(lmi, 4)[0];5617 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.
5616 let tu_grid = read_plane(5623 let tu_grid = read_plane(
5617 dec,5624 dec,
5618 cdfs,5625 cdfs,
@@ -5632,7 +5639,7 @@ fn decode_leaf_split4(
5632 base_q_idx,5639 base_q_idx,
5633 None,5640 None,
5634 filter_intra,5641 filter_intra,
5635- Some(tu_skip_ctx),5642+ None,
5636 smooth_neighbor,5643 smooth_neighbor,
5637 )?;5644 )?;
5638 neighbours.record_mi_luma(lmi, 4, &tu_grid);5645 neighbours.record_mi_luma(lmi, 4, &tu_grid);
@@ -5704,7 +5711,7 @@ fn decode_leaf_split4(
5704 neighbours.above[leaf_mi.1 + cell][2] = v_state;5711 neighbours.above[leaf_mi.1 + cell][2] = v_state;
5705 }5712 }
5706 }5713 }
5707- Ok(leaf_modes[3])5714+ Ok((leaf_modes[2], leaf_modes[1]))
5708 }5715 }
5709 5716
5710 /// Spec 7.15.3's `Cdef_Directions`: `(row, col)` offsets for the two primary5717 /// 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(
7352 // the one or two the edge leaves.7359 // the one or two the edge leaves.
7353 let (mi_row0, mi_col0) =7360 let (mi_row0, mi_col0) =
7354 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);7361 (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];
7356 for i in 0..4 {7377 for i in 0..4 {
7357 let (mr, mc) =7378 let (mr, mc) =
7358 (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);7379 (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);
7359 let leaf_mi = (mr as usize, mc as usize);7380 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+ }
7360 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);7394 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
7361 let part8 =7395 let part8 =
7362 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);7396 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
@@ -7373,7 +7407,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7373 at16,7407 at16,
7374 leaf_mi,7408 leaf_mi,
7375 (&scan8, &scan4),7409 (&scan8, &scan4),
7376- prev_leaf,7410+ None,
7377 &mut y,7411 &mut y,
7378 &mut u,7412 &mut u,
7379 &mut v,7413 &mut v,
@@ -7383,7 +7417,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7383 allow_intrabc,7417 allow_intrabc,
7384 tx_select,7418 tx_select,
7385 reduced_tx_set,7419 reduced_tx_set,
7386- )?7420+ ).map(|m| (m, m))?
7387 } else if part8 == PARTITION_SPLIT {7421 } else if part8 == PARTITION_SPLIT {
7388 decode_leaf_split4(7422 decode_leaf_split4(
7389 &mut dec,7423 &mut dec,
@@ -7392,7 +7426,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7392 at16,7426 at16,
7393 leaf_mi,7427 leaf_mi,
7394 &scan4,7428 &scan4,
7395- prev_leaf,7429+ None,
7396 &mut y,7430 &mut y,
7397 &mut u,7431 &mut u,
7398 &mut v,7432 &mut v,
@@ -7406,11 +7440,15 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7406 "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)",7440 "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)",
7407 ));7441 ));
7408 };7442 };
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);
7410 }7446 }
7411- if let Some((_, mode)) = prev_leaf {7447+ if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) {
7412- neighbours.above_mode[sc] = mode;7448+ neighbours.above_mode[sc] = below;
7413- neighbours.left_mode[sr] = mode;7449+ }
7450+ if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) {
7451+ neighbours.left_mode[sr] = right;
7414 }7452 }
7415 continue;7453 continue;
7416 }7454 }
@@ -7444,9 +7482,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7444 .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2))7482 .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2))
7445 .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols)7483 .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols)
7446 .collect();7484 .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];
7448 for (mr, mc) in leaf_positions {7488 for (mr, mc) in leaf_positions {
7449 let leaf_mi = (mr as usize, mc as usize);7489 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+ }
7450 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);7504 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
7451 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);7505 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
7452 if std::env::var_os("EC_AV1_TRACE").is_some() {7506 if std::env::var_os("EC_AV1_TRACE").is_some() {
@@ -7462,7 +7516,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7462 at16,7516 at16,
7463 leaf_mi,7517 leaf_mi,
7464 (&scan8, &scan4),7518 (&scan8, &scan4),
7465- prev_leaf,7519+ None,
7466 &mut y,7520 &mut y,
7467 &mut u,7521 &mut u,
7468 &mut v,7522 &mut v,
@@ -7472,7 +7526,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7472 allow_intrabc,7526 allow_intrabc,
7473 tx_select,7527 tx_select,
7474 reduced_tx_set,7528 reduced_tx_set,
7475- )?7529+ ).map(|m| (m, m))?
7476 } else if part8 == PARTITION_SPLIT {7530 } else if part8 == PARTITION_SPLIT {
7477 decode_leaf_split4(7531 decode_leaf_split4(
7478 &mut dec,7532 &mut dec,
@@ -7481,7 +7535,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7481 at16,7535 at16,
7482 leaf_mi,7536 leaf_mi,
7483 &scan4,7537 &scan4,
7484- prev_leaf,7538+ None,
7485 &mut y,7539 &mut y,
7486 &mut u,7540 &mut u,
7487 &mut v,7541 &mut v,
@@ -7495,7 +7549,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7495 "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)",7549 "a HORZ/VERT partition below 8x8 (this decoder's transform primitive is square-only; 4x8/8x4 need a real rectangular transform)",
7496 ));7550 ));
7497 };7551 };
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);
7499 }7555 }
7500 // `record()`'s `above_mode`/`left_mode`7556 // `record()`'s `above_mode`/`left_mode`
7501 // write is a no-op at an 8x8 leaf's own7557 // write is a no-op at an 8x8 leaf's own
@@ -7503,9 +7559,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7503 // 16x16 slot's leaves are done, from the7559 // 16x16 slot's leaves are done, from the
7504 // last leaf (mirrors the writer's r157560 // last leaf (mirrors the writer's r15
7505 // fix).7561 // fix).
7506- if let Some((_, mode)) = prev_leaf {7562+ if let Some((below, _)) = sib_modes[2].or(sib_modes[3]).or(sib_modes[0]) {
7507- neighbours.above_mode[sc] = mode;7563+ neighbours.above_mode[sc] = below;
7508- neighbours.left_mode[sr] = mode;7564+ }
7565+ if let Some((_, right)) = sib_modes[1].or(sib_modes[3]).or(sib_modes[0]) {
7566+ neighbours.left_mode[sr] = right;
7509 }7567 }
7510 }7568 }
7511 }7569 }