A non-chroma-reference inter block wiped its neighbours' chroma coefficient contexts
Browse files at this commit8b5425d6ae2e67b1bbc61f6756549d35c9ea20b9Parent: e049d65- fix
- a non-chroma-reference inter block wiped its neighbours' chroma coefficient contexts
1 changed file +40 -4
- crates/ec-av1/src/decode.rs +40 -4
crates/ec-av1/src/decode.rsmodified+40 -4
| @@ -5401,14 +5401,14 @@ impl Neighbours { | ||
| 5401 | 5401 | left_coded |= left.level != 0; |
| 5402 | 5402 | vote += dc_vote(left.dc); |
| 5403 | 5403 | } |
| 5404 | - if plane == 0 && std::env::var_os("EC_DCDUMP").is_some() { | |
| 5404 | + if std::env::var_os("EC_DCDUMP").is_some() { | |
| 5405 | 5405 | let ab: Vec<String> = (0..w_mi) |
| 5406 | - .map(|k| format!("{:?}/{}", self.above[mi_c + k][0].dc, self.above[mi_c + k][0].level)) | |
| 5406 | + .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level)) | |
| 5407 | 5407 | .collect(); |
| 5408 | 5408 | let lf: Vec<String> = (0..h_mi) |
| 5409 | - .map(|k| format!("{:?}/{}", self.left[mi_r + k][0].dc, self.left[mi_r + k][0].level)) | |
| 5409 | + .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level)) | |
| 5410 | 5410 | .collect(); |
| 5411 | - eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); | |
| 5411 | + eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(",")); | |
| 5412 | 5412 | } |
| 5413 | 5413 | (above_coded, left_coded, vote) |
| 5414 | 5414 | }) |
| @@ -22927,6 +22927,28 @@ fn decode_inter_block( | ||
| 22927 | 22927 | } else { |
| 22928 | 22928 | Vec::new() |
| 22929 | 22929 | }; |
| 22930 | + // libaom `av1_reset_entropy_context` / `av1_set_entropy_contexts`: | |
| 22931 | + // `nplanes = 1 + (num_planes - 1) * xd->is_chroma_ref` -- a block that is | |
| 22932 | + // NOT the chroma reference of its 4:2:0 pair codes no chroma transform at | |
| 22933 | + // all, so it leaves its neighbours' CHROMA coefficient contexts exactly as | |
| 22934 | + // it found them. `record_rect_mi`/`record_split_luma_rect_mi` below write | |
| 22935 | + // all three planes unconditionally, and for such a strip the chroma grids | |
| 22936 | + // are all-zero (see the `!has_chroma` arm above) -- that wiped the real | |
| 22937 | + // left-neighbour chroma state, so the PAIR's own `all_zero` then read | |
| 22938 | + // `txb_skip_ctx` one row low (lane-t900 r3, 10-bit 1920x792 stream, | |
| 22939 | + // mi(40,220): base 1 where libaom gathers 2). Snapshot and restore is | |
| 22940 | + // equivalent to not writing them, without threading a flag through both | |
| 22941 | + // recorders. | |
| 22942 | + let saved_chroma_ctx = (!has_chroma).then(|| { | |
| 22943 | + let (w_mi, h_mi) = (write_w / MI, write_h / MI); | |
| 22944 | + let left: Vec<[Neighbour; 2]> = (0..h_mi) | |
| 22945 | + .filter_map(|k| neighbours.left.get(at.0 + k).map(|s| [s[1], s[2]])) | |
| 22946 | + .collect(); | |
| 22947 | + let above: Vec<[Neighbour; 2]> = (0..w_mi) | |
| 22948 | + .filter_map(|k| neighbours.above.get(at.1 + k).map(|s| [s[1], s[2]])) | |
| 22949 | + .collect(); | |
| 22950 | + (left, above) | |
| 22951 | + }); | |
| 22930 | 22952 | if vartx_leaves.is_some() { |
| 22931 | 22953 | // Plane 0 is already correct per transform unit |
| 22932 | 22954 | // ([`Neighbours::record_mi_luma`] above); this writes everything else |
| @@ -22960,6 +22982,20 @@ fn decode_inter_block( | ||
| 22960 | 22982 | &[luma_grid, u_grid, v_grid], |
| 22961 | 22983 | ); |
| 22962 | 22984 | } |
| 22985 | + if let Some((left, above)) = saved_chroma_ctx { | |
| 22986 | + for (k, v) in left.into_iter().enumerate() { | |
| 22987 | + if let Some(slot) = neighbours.left.get_mut(at.0 + k) { | |
| 22988 | + slot[1] = v[0]; | |
| 22989 | + slot[2] = v[1]; | |
| 22990 | + } | |
| 22991 | + } | |
| 22992 | + for (k, v) in above.into_iter().enumerate() { | |
| 22993 | + if let Some(slot) = neighbours.above.get_mut(at.1 + k) { | |
| 22994 | + slot[1] = v[0]; | |
| 22995 | + slot[2] = v[1]; | |
| 22996 | + } | |
| 22997 | + } | |
| 22998 | + } | |
| 22963 | 22999 | if let Some((s, u_state, v_state)) = pair_chroma { |
| 22964 | 23000 | let (pw, ph) = if s.horz { (16usize, 8usize) } else { (8, 16) }; |
| 22965 | 23001 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |