forge
Explore
Log in

Don't you dare go Hollow

Merge 7f2c85c5 (lane-av1-444 10-bit film fix) into main: keep 12-bit compound MC and 4:4:4 chroma port

Browse files at this commit

c5a3cd1b76794a92c4231212709dd377343c6c8cAhmet Kaan GümüşParent: 60c70a0f6ca882
- decode.rs: unify on the lane's ss-aware mv_to_q4(pos, mv, ss) signature;
  main's luma=false call sites become ss_x(fctx)/ss_y(fctx) (identical math
  for 4:2:0), luma=true becomes 0. Intrabc chroma arm keeps main's structure
  with ss-aware MVs. Compound intermediate calls pass fctx and use the lane's
  chroma_side sizing (444-native, degenerates to 420 behavior).
- encode.rs, refusal_inventory.rs, restoration.rs, stream.rs, tile.rs:
  auto-merged clean by git, both sides retained.
- Verified: a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact
  and a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_reach_decode_pixel_exact
  both PASS (not skipped) on this merge.
crates/ec-av1/src/decode.rsmodified+2043 -798

Diff too large; view file

@@ -112,6 +112,9 @@ pub(crate) struct FrameCtx {
112 /// (like [`FrameCtx::bit_depth`]), so a mono frame decoded on a thread112 /// (like [`FrameCtx::bit_depth`]), so a mono frame decoded on a thread
113 /// that last saw a 4:2:0 one never inherits the wrong plane count.113 /// that last saw a 4:2:0 one never inherits the wrong plane count.
114 pub(crate) mono_chrome: std::cell::Cell<bool>,114 pub(crate) mono_chrome: std::cell::Cell<bool>,
115+ /// lane-av1-444: sequence subsampling_x/y. 1,1 is 4:2:0; 0,0 is 4:4:4.
116+ pub(crate) subsampling_x: std::cell::Cell<u8>,
117+ pub(crate) subsampling_y: std::cell::Cell<u8>,
115 pub(crate) superres: std::cell::Cell<(u32, u32)>,118 pub(crate) superres: std::cell::Cell<(u32, u32)>,
116 pub(crate) cdef_transmitted: std::cell::Cell<bool>,119 pub(crate) cdef_transmitted: std::cell::Cell<bool>,
117 pub(crate) cdef_sb_cols: std::cell::Cell<usize>,120 pub(crate) cdef_sb_cols: std::cell::Cell<usize>,
@@ -215,6 +218,8 @@ impl FrameCtx {
215 cdef_bits: std::cell::Cell::new(0),218 cdef_bits: std::cell::Cell::new(0),
216 bit_depth: std::cell::Cell::new(8),219 bit_depth: std::cell::Cell::new(8),
217 mono_chrome: std::cell::Cell::new(false),220 mono_chrome: std::cell::Cell::new(false),
221+ subsampling_x: std::cell::Cell::new(1),
222+ subsampling_y: std::cell::Cell::new(1),
218 superres: std::cell::Cell::new((0, 8)),223 superres: std::cell::Cell::new((0, 8)),
219 cdef_transmitted: std::cell::Cell::new(false),224 cdef_transmitted: std::cell::Cell::new(false),
220 cdef_sb_cols: std::cell::Cell::new(0),225 cdef_sb_cols: std::cell::Cell::new(0),
@@ -312,6 +317,8 @@ pub(crate) fn filter_ctx_copy(fctx: &FrameCtx) -> FrameCtx {
312 let out = FrameCtx::new();317 let out = FrameCtx::new();
313 out.bit_depth.set(fctx.bit_depth.get());318 out.bit_depth.set(fctx.bit_depth.get());
314 out.mono_chrome.set(fctx.mono_chrome.get());319 out.mono_chrome.set(fctx.mono_chrome.get());
320+ out.subsampling_x.set(fctx.subsampling_x.get());
321+ out.subsampling_y.set(fctx.subsampling_y.get());
315 out.interp_filter.set(fctx.interp_filter.get());322 out.interp_filter.set(fctx.interp_filter.get());
316 out.grain_bit_depth.set(fctx.grain_bit_depth.get());323 out.grain_bit_depth.set(fctx.grain_bit_depth.get());
317 out.superres.set(fctx.superres.get());324 out.superres.set(fctx.superres.get());
@@ -634,6 +641,29 @@ pub(crate) fn set_mono(mono_chrome: bool, fctx: &crate::decode::FrameCtx) {
634 fctx.mono_chrome.with(|c| c.set(mono_chrome));641 fctx.mono_chrome.with(|c| c.set(mono_chrome));
635 }642 }
636 643
644+/// Sequence subsampling. Set once per frame from stream.rs, like set_mono.
645+pub(crate) fn set_subsampling(ss_x: u8, ss_y: u8, fctx: &crate::decode::FrameCtx) {
646+ fctx.subsampling_x.set(ss_x);
647+ fctx.subsampling_y.set(ss_y);
648+}
649+
650+#[inline]
651+pub(crate) fn ss_x(fctx: &crate::decode::FrameCtx) -> usize {
652+ fctx.subsampling_x.get() as usize
653+}
654+
655+#[inline]
656+pub(crate) fn ss_y(fctx: &crate::decode::FrameCtx) -> usize {
657+ fctx.subsampling_y.get() as usize
658+}
659+
660+/// libaom ROUND_POWER_OF_TWO. At ss=1 equals div_ceil(dim, 2); at ss=0 is dim.
661+#[inline]
662+pub(crate) fn round_ss(dim: usize, ss: usize) -> usize {
663+ (dim + ((1usize << ss) >> 1)) >> ss
664+}
665+
666+
637 /// This frame's superres state: `(upscaled_width, superres_denom)`, or667 /// This frame's superres state: `(upscaled_width, superres_denom)`, or
638 /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs668 /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs
639 /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid,669 /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid,
@@ -2381,17 +2411,14 @@ pub(crate) struct CflSrc {
2381 py: usize,2411 py: usize,
2382 bw: usize,2412 bw: usize,
2383 bh: usize,2413 bh: usize,
2384- /// Which averager the parse site asked for -- [`cfl_ac_q3_rect`] and
2385- /// [`cfl_ac_q3`] are not the same function at `bw == bh`.
2386- rect: bool,
2387 }2414 }
2388 2415
2389 fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc {2416 fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc {
2390- CflSrc { px, py, bw: side, bh: side, rect: false }2417+ CflSrc { px, py, bw: side, bh: side }
2391 }2418 }
2392 2419
2393 fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc {2420 fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc {
2394- CflSrc { px, py, bw, bh, rect: true }2421+ CflSrc { px, py, bw, bh }
2395 }2422 }
2396 2423
2397 /// lane-wave1 step (i): the pixel-writing half of block decoding, recorded2424 /// lane-wave1 step (i): the pixel-writing half of block decoding, recorded
@@ -3626,11 +3653,7 @@ fn exec_intra(
3626 // written for this block -- at parse time it would have been the previous3653 // written for this block -- at parse time it would have been the previous
3627 // frame's samples.3654 // frame's samples.
3628 let ac = cfl.map(|(alpha, src)| {3655 let ac = cfl.map(|(alpha, src)| {
3629- let sig = if src.rect {3656+ let sig = cfl_ac_ss(&*y, src.px, src.py, src.bw, src.bh, ss_x(fctx), ss_y(fctx));
3630- cfl_ac_q3_rect(&*y, src.px, src.py, src.bw, src.bh)
3631- } else {
3632- cfl_ac_q3(&*y, src.px, src.py, src.bw)
3633- };
3634 (alpha, sig)3657 (alpha, sig)
3635 });3658 });
3636 let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));3659 let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));
@@ -6912,7 +6935,9 @@ fn read_coeffs_rect(
6912 // mask rather than a hardware divide.6935 // mask rather than a hardware divide.
6913 let stride = w + 4;6936 let stride = w + 4;
6914 let n = stride * (h + 4);6937 let n = stride * (h + 4);
6915- debug_assert!(w.is_power_of_two() && n <= 36 * 36);6938+ if !(w.is_power_of_two() && n <= 36 * 36) {
6939+ panic!("rect coeff scratch w={w} h={h} n={n}");
6940+ }
6916 let (mut b96, mut b256, mut b768);6941 let (mut b96, mut b256, mut b768);
6917 // Byte levels, same `0..=15` bound [`read_coeffs`] states.6942 // Byte levels, same `0..=15` bound [`read_coeffs`] states.
6918 let levels: &mut [u8] = if n <= 96 {6943 let levels: &mut [u8] = if n <= 96 {
@@ -7808,8 +7833,8 @@ impl Neighbours {
7808 // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is7833 // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is
7809 // half its luma one (min 4 px, the smallest transform), capped at7834 // half its luma one (min 4 px, the smallest transform), capped at
7810 // TX_32X32 -- independent of this block's luma `tx_depth`.7835 // TX_32X32 -- independent of this block's luma `tx_depth`.
7811- let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;7836+ let uv_tx_w = (((w_mi * MI) >> ss_x(fctx)).max(4).min(32)) as u8;
7812- let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;7837+ let uv_tx_h = (((h_mi * MI) >> ss_y(fctx)).max(4).min(32)) as u8;
7813 if crate::envflags::env_flag!("EC_TXGRID_TRACE") {7838 if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
7814 eprintln!("EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");7839 eprintln!("EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");
7815 }7840 }
@@ -8226,15 +8251,24 @@ impl Neighbours {
8226 // One pass over the cells accumulating all three planes, not one pass8251 // One pass over the cells accumulating all three planes, not one pass
8227 // per plane: the three planes of a cell live in the same8252 // per plane: the three planes of a cell live in the same
8228 // `[Neighbour; 3]` (6 bytes), so the per-plane form loaded the same8253 // `[Neighbour; 3]` (6 bytes), so the per-plane form loaded the same
8229- // cache lines three times (lane-publish).8254+ // cache lines three times (lane-publish). Clamp each edge to the true
8255+ // frame extent: a block at the right/bottom edge may be padded beyond
8256+ // `mi_cols`/`mi_rows`, and libaom's unavailable context is zero there.
8257+ let above_mi = side_mi.min(self.mi_cols.saturating_sub(mi_c));
8258+ let left_mi = side_mi.min(self.mi_rows.saturating_sub(mi_r));
8230 let mut out = [(false, false, 0i32); 3];8259 let mut out = [(false, false, 0i32); 3];
8231- for cell in 0..side_mi {8260+ for cell in 0..above_mi {
8232 let above = &self.above[mi_c + cell];8261 let above = &self.above[mi_c + cell];
8233- let left = &self.left[mi_r + cell];
8234 for (plane, o) in out.iter_mut().enumerate() {8262 for (plane, o) in out.iter_mut().enumerate() {
8235 o.0 |= above[plane].level != 0;8263 o.0 |= above[plane].level != 0;
8264+ o.2 += dc_vote(above[plane].dc);
8265+ }
8266+ }
8267+ for cell in 0..left_mi {
8268+ let left = &self.left[mi_r + cell];
8269+ for (plane, o) in out.iter_mut().enumerate() {
8236 o.1 |= left[plane].level != 0;8270 o.1 |= left[plane].level != 0;
8237- o.2 += dc_vote(above[plane].dc) + dc_vote(left[plane].dc);8271+ o.2 += dc_vote(left[plane].dc);
8238 }8272 }
8239 }8273 }
8240 out8274 out
@@ -8251,16 +8285,18 @@ impl Neighbours {
8251 /// mode-info units, mirroring [`Self::around_mi`].8285 /// mode-info units, mirroring [`Self::around_mi`].
8252 fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {8286 fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {
8253 let (w_mi, h_mi) = (w / MI, h / MI);8287 let (w_mi, h_mi) = (w / MI, h / MI);
8288+ let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c));
8289+ let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r));
8254 // [`Self::around_mi`]'s single pass, with the two extents split.8290 // [`Self::around_mi`]'s single pass, with the two extents split.
8255 let mut out = [(false, false, 0i32); 3];8291 let mut out = [(false, false, 0i32); 3];
8256- for cell in 0..w_mi {8292+ for cell in 0..above_mi {
8257 let above = &self.above[mi_c + cell];8293 let above = &self.above[mi_c + cell];
8258 for (plane, o) in out.iter_mut().enumerate() {8294 for (plane, o) in out.iter_mut().enumerate() {
8259 o.0 |= above[plane].level != 0;8295 o.0 |= above[plane].level != 0;
8260 o.2 += dc_vote(above[plane].dc);8296 o.2 += dc_vote(above[plane].dc);
8261 }8297 }
8262 }8298 }
8263- for cell in 0..h_mi {8299+ for cell in 0..left_mi {
8264 let left = &self.left[mi_r + cell];8300 let left = &self.left[mi_r + cell];
8265 for (plane, o) in out.iter_mut().enumerate() {8301 for (plane, o) in out.iter_mut().enumerate() {
8266 o.1 |= left[plane].level != 0;8302 o.1 |= left[plane].level != 0;
@@ -8270,10 +8306,10 @@ impl Neighbours {
8270 if crate::envflags::env_flag!("EC_DCDUMP") {8306 if crate::envflags::env_flag!("EC_DCDUMP") {
8271 for (plane, o) in out.iter().enumerate() {8307 for (plane, o) in out.iter().enumerate() {
8272 let vote = o.2;8308 let vote = o.2;
8273- let ab: Vec<String> = (0..w_mi)8309+ let ab: Vec<String> = (0..above_mi)
8274 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))8310 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
8275 .collect();8311 .collect();
8276- let lf: Vec<String> = (0..h_mi)8312+ let lf: Vec<String> = (0..left_mi)
8277 .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level))8313 .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level))
8278 .collect();8314 .collect();
8279 eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));8315 eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));
@@ -8303,20 +8339,22 @@ impl Neighbours {
8303 h_mi: usize,8339 h_mi: usize,
8304 ) -> usize {8340 ) -> usize {
8305 let side_mi = w_mi;8341 let side_mi = w_mi;
8342+ let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c));
8343+ let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r));
8306 let mut top = 0u8;8344 let mut top = 0u8;
8307 let mut left = 0u8;8345 let mut left = 0u8;
8308- for cell in 0..w_mi {8346+ for cell in 0..above_mi {
8309 top |= self.above[mi_c + cell][0].level;8347 top |= self.above[mi_c + cell][0].level;
8310 }8348 }
8311- for cell in 0..h_mi {8349+ for cell in 0..left_mi {
8312 left |= self.left[mi_r + cell][0].level;8350 left |= self.left[mi_r + cell][0].level;
8313 }8351 }
8314 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];8352 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];
8315 if crate::envflags::env_flag!("EC_ECDUMP") {8353 if crate::envflags::env_flag!("EC_ECDUMP") {
8316 let ab: Vec<String> =8354 let ab: Vec<String> =
8317- (0..w_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect();8355+ (0..above_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect();
8318 let lf: Vec<String> =8356 let lf: Vec<String> =
8319- (0..h_mi).map(|k| self.left[mi_r + k][0].level.to_string()).collect();8357+ (0..left_mi).map(|k| self.left[mi_r + k][0].level.to_string()).collect();
8320 eprintln!(8358 eprintln!(
8321 "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},]",8359 "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},]",
8322 ab.join(","), lf.join(",")8360 ab.join(","), lf.join(",")
@@ -8428,7 +8466,14 @@ impl Neighbours {
8428 /// coded a smooth `uv_mode` -- libaom's `intra_edge_filter_type` for8466 /// coded a smooth `uv_mode` -- libaom's `intra_edge_filter_type` for
8429 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no8467 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no
8430 /// block has recorded the exact neighbouring mi.8468 /// block has recorded the exact neighbouring mi.
8431- fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {8469+ fn smooth_uv_neighbour(
8470+ &self,
8471+ mi_r: usize,
8472+ mi_c: usize,
8473+ r: usize,
8474+ c: usize,
8475+ fctx: &crate::decode::FrameCtx,
8476+ ) -> bool {
8432 // lane-kf900 r2: libaom reads the chroma neighbours off the CHROMA8477 // lane-kf900 r2: libaom reads the chroma neighbours off the CHROMA
8433 // REFERENCE block, not off the mi that carries the chroma syntax.8478 // REFERENCE block, not off the mi that carries the chroma syntax.
8434 // `set_mi_row_col` (`blockd.h`) takes8479 // `set_mi_row_col` (`blockd.h`) takes
@@ -8445,7 +8490,14 @@ impl Neighbours {
8445 // false for type 1, TRUE for type 0) and upsampled an edge libaom8490 // false for type 1, TRUE for type 0) and upsampled an edge libaom
8446 // leaves alone -- +1 on rows 2/3 of that block and every chroma block8491 // leaves alone -- +1 on rows 2/3 of that block and every chroma block
8447 // predicting from it (class `context-read-from-one-cell`).8492 // predicting from it (class `context-read-from-one-cell`).
8448- self.smooth_uv_neighbour_unsnapped(mi_r & !1, mi_c & !1, r, c)8493+ // lane-av1-444: the snap is the SEQUENCE's subsampling, hardcoded
8494+ // `& !1` before -- at subsampling 0/0 libaom's `mi_row & 0` snaps
8495+ // nothing, and the hardcoded snap read a 4x4 leaf's smooth
8496+ // neighbour two mi away (frame 0 of `av1-profile1-444.ivf`, leaf
8497+ // mi(5,15): left neighbour SMOOTH_V at mi(5,14), read at mi(4,13)).
8498+ let snap_y = (1usize << ss_y(fctx)) - 1;
8499+ let snap_x = (1usize << ss_x(fctx)) - 1;
8500+ self.smooth_uv_neighbour_unsnapped(mi_r & !snap_y, mi_c & !snap_x, r, c)
8449 }8501 }
8450 8502
8451 /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e.8503 /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e.
@@ -9256,17 +9308,21 @@ pub(crate) fn palette_onscreen_dims(
9256 }9308 }
9257 9309
9258 /// [`palette_onscreen`] carried into the chroma plane: `>> subsampling` plus9310 /// [`palette_onscreen`] carried into the chroma plane: `>> subsampling` plus
9259-/// the SAME sub-8 bump the caller's own `(bw / 2).max(4)` applies to the block9311+/// the SAME sub-8 bump the caller's own `(bw >> ss).max(4)` applies to the
9260-/// dimensions (`is_chroma_sub8_x/y`, blockd.h:1533) -- both must move together9312+/// block dimensions (`is_chroma_sub8_x/y`, blockd.h:1533) -- both must move
9261-/// or a cut 8-wide block reads its chroma map at the wrong width.9313+/// together or a cut 8-wide block reads its chroma map at the wrong width.
9314+/// lane-av1-444: the shifts are the sequence's own subsampling (a 4:4:4
9315+/// intra-in-inter palette read its chroma map at the 4:2:0 extent and
9316+/// panicked feeding the 4:2:0-sized prediction to a full-size reconstruct).
9262 pub(crate) fn palette_onscreen_uv(9317 pub(crate) fn palette_onscreen_uv(
9263 luma: (usize, usize),9318 luma: (usize, usize),
9264 on: (usize, usize),9319 on: (usize, usize),
9265 chroma: (usize, usize),9320 chroma: (usize, usize),
9321+ ss: (usize, usize),
9266 ) -> (usize, usize) {9322 ) -> (usize, usize) {
9267 (9323 (
9268- (on.0 >> 1) + (chroma.0 - (luma.0 >> 1)),9324+ (on.0 >> ss.0) + (chroma.0 - (luma.0 >> ss.0)),
9269- (on.1 >> 1) + (chroma.1 - (luma.1 >> 1)),9325+ (on.1 >> ss.1) + (chroma.1 - (luma.1 >> ss.1)),
9270 )9326 )
9271 }9327 }
9272 9328
@@ -9643,8 +9699,8 @@ fn read_intra_mode_rect(
9643 // BLOCK_4X8, both floored at the 4-px transform. Halving the short9699 // BLOCK_4X8, both floored at the 4-px transform. Halving the short
9644 // axis to 2 read HALF the colour-index symbols of a 1:4 strip's9700 // axis to 2 read HALF the colour-index symbols of a 1:4 strip's
9645 // chroma palette and desynced the tile from there.9701 // chroma palette and desynced the tile from there.
9646- let (cw, ch) = ((bw / 2).max(4), (bh / 2).max(4));9702+ let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4));
9647- let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));9703+ let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch), (ss_x(fctx), ss_y(fctx)));
9648 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);9704 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
9649 hit!(PALETTE_UV_HITS);9705 hit!(PALETTE_UV_HITS);
9650 PaletteUv { size: n, u_colors, v_colors, map }9706 PaletteUv { size: n, u_colors, v_colors, map }
@@ -9831,8 +9887,8 @@ fn decode_rect_split(
9831 ) -> Result<()> {9887 ) -> Result<()> {
9832 let (mi_r, mi_c) = at_mi;9888 let (mi_r, mi_c) = at_mi;
9833 let (px, py) = (mi_c * MI, mi_r * MI);9889 let (px, py) = (mi_c * MI, mi_r * MI);
9834- let (cpx, cpy) = (px / 2, py / 2);9890+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
9835- let (chroma_w, chroma_h) = (bw / 2, bh / 2);9891+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
9836 // The chroma transform is picked before any symbol is read, so an9892 // The chroma transform is picked before any symbol is read, so an
9837 // unsupported chroma shape refuses before this strip desyncs the tile.9893 // unsupported chroma shape refuses before this strip desyncs the tile.
9838 let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) {9894 let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) {
@@ -9885,7 +9941,11 @@ fn decode_rect_split(
9885 // caller -- a new strip size would otherwise hit the `expect` below and9941 // caller -- a new strip size would otherwise hit the `expect` below and
9886 // panic instead of refusing by name -- and so stays in9942 // panic instead of refusing by name -- and so stays in
9887 // `refusal_inventory::REFUSALS`.9943 // `refusal_inventory::REFUSALS`.
9888- if !m.skip && chroma.is_none() {9944+ // A 4:4:4 64-axis strip's chroma plane block is larger than one adjusted
9945+ // UV transform (TX_64X32 adjusts to TX_32X32). Those sizes are tiled
9946+ // below; everything else still needs a single-unit table.
9947+ let chroma_tiled = matches!((chroma_w, chroma_h), (64, 32) | (32, 64) | (64, 16) | (16, 64));
9948+ if !m.skip && chroma.is_none() && !chroma_tiled {
9889 return Err(unsupported(9949 return Err(unsupported(
9890 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",9950 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
9891 ));9951 ));
@@ -10162,6 +10222,15 @@ fn decode_rect_split(
10162 // next block then read `dc_sign_ctx` 1 where libaom reads 0). They are10222 // next block then read `dc_sign_ctx` 1 where libaom reads 0). They are
10163 // collected here and replayed after that record.10223 // collected here and replayed after that record.
10164 let mut ll_chroma_units: Vec<((usize, usize), usize, Grid)> = Vec::new();10224 let mut ll_chroma_units: Vec<((usize, usize), usize, Grid)> = Vec::new();
10225+ // The chroma_tiled arm below stamps each unit's coefficient context
10226+ // immediately (so the NEXT unit reads it), then the whole-strip
10227+ // `record_split_luma_rect_mi` rewrites every chroma cell with ONE
10228+ // whole-strip state and the per-unit DC signs and levels are lost
10229+ // (class `override-slot-on-one-arm`). The units are collected here and
10230+ // replayed after that record, the way the lossless arm's
10231+ // `ll_chroma_units` and `decode_inter_block`'s `mu_chroma_units` tail
10232+ // already do.
10233+ let mut tiled_chroma_units: Vec<((usize, usize), usize, Grid, usize, usize)> = Vec::new();
10165 let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh));10234 let ac = m.alpha.map(|_| cfl_src_rect(px, py, bw, bh));
10166 let reach = block_reach;10235 let reach = block_reach;
10167 let (u_grid, v_grid) = if mono(fctx) {10236 let (u_grid, v_grid) = if mono(fctx) {
@@ -10242,6 +10311,86 @@ fn decode_rect_split(
10242 }10311 }
10243 let [ug, vg] = last;10312 let [ug, vg] = last;
10244 (ug, vg)10313 (ug, vg)
10314+ } else if chroma_tiled {
10315+ let (uw, uh, set, scan): (usize, usize, TxbSet, &[u16]) = match (chroma_w, chroma_h) {
10316+ (64, 32) | (32, 64) => (32, 32, TxbSet::Chroma32, default_scan(32)),
10317+ (64, 16) => (32, 16, TxbSet::ChromaRect32x16, &SCAN_32X16),
10318+ (16, 64) => (16, 32, TxbSet::ChromaRect32x16, &SCAN_16X32),
10319+ _ => unreachable!("chroma_tiled"),
10320+ };
10321+ let (nw, nh) = (chroma_w / uw, chroma_h / uh);
10322+ let bigger = chroma_w * chroma_h > uw * uh;
10323+ let default_tx = TxType::DctDct;
10324+ let mut last = [Grid::Zero(uw * uh), Grid::Zero(uw * uh)];
10325+ for plane_idx in 1..=2 {
10326+ for cu_row in 0..nh {
10327+ for cu_col in 0..nw {
10328+ let luma_span_x = uw << ss_x(fctx);
10329+ let luma_span_y = uh << ss_y(fctx);
10330+ let cu_mi = (
10331+ mi_r + cu_row * (luma_span_y / MI),
10332+ mi_c + cu_col * (luma_span_x / MI),
10333+ );
10334+ let cu_around = neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y);
10335+ let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh);
10336+ let cfl = m.alpha.map(|(au, av)| {
10337+ let alpha = if plane_idx == 1 { au } else { av };
10338+ (
10339+ alpha,
10340+ cfl_src_rect(
10341+ px + cu_col * luma_span_x,
10342+ py + cu_row * luma_span_y,
10343+ luma_span_x,
10344+ luma_span_y,
10345+ ),
10346+ )
10347+ });
10348+ // 32x32 does not fit read_coeffs_rect's scratch (768). The
10349+ // square reader is the path every other 32x32 chroma unit uses.
10350+ let levels = if uw == uh {
10351+ let plane = if plane_idx == 1 { &mut *u } else { &mut *v };
10352+ read_plane(
10353+ dec, cdfs, set, scan, plane_idx, cu_around[plane_idx],
10354+ m.mode, m.uv_predict_mode, m.angle_delta_uv, reach,
10355+ plane, cu_x, cu_y, uw, uw, base_q_idx, cfl, None,
10356+ bigger.then_some(3), m.smooth_neighbor_uv, fctx,
10357+ )?
10358+ } else {
10359+ let skip_ctx = usize::from(cu_around[plane_idx].0)
10360+ + usize::from(cu_around[plane_idx].1)
10361+ + usize::from(bigger) * 3;
10362+ let mut coding = cdfs.txb(set, m.uv_predict_mode);
10363+ let (levels, tx_type) = read_coeffs_rect(
10364+ dec, &mut coding, scan, uw, uh, skip_ctx,
10365+ dc_sign_ctx(cu_around[plane_idx].2), default_tx,
10366+ )?;
10367+ let residual = dequant_and_inverse_typed_wh(
10368+ &levels, uw, uh, crate::decode::bit_depth(fctx),
10369+ block_q_idx(fctx),
10370+ plane_q_delta(plane_idx, fctx).0,
10371+ plane_q_delta(plane_idx, fctx).1,
10372+ tx_type,
10373+ );
10374+ push_intra_rect(
10375+ plane_idx, cu_x, cu_y, uw, uh,
10376+ m.uv_predict_mode, m.angle_delta_uv, reach, &residual,
10377+ cfl, None, m.smooth_neighbor_uv, fctx,
10378+ );
10379+ levels
10380+ };
10381+ neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, plane_idx, &levels);
10382+ tiled_chroma_units.push((
10383+ cu_mi,
10384+ plane_idx,
10385+ levels.clone(),
10386+ luma_span_x,
10387+ luma_span_y,
10388+ ));
10389+ last[plane_idx - 1] = levels;
10390+ }
10391+ }
10392+ }
10393+ (last[0].clone(), last[1].clone())
10245 } else {10394 } else {
10246 let (chroma_set, chroma_scan) = chroma.expect("refused above when None");10395 let (chroma_set, chroma_scan) = chroma.expect("refused above when None");
10247 // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size10396 // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size
@@ -10328,6 +10477,9 @@ fn decode_rect_split(
10328 for (cu_mi, plane, unit) in &ll_chroma_units {10477 for (cu_mi, plane, unit) in &ll_chroma_units {
10329 neighbours.record_mi_chroma(*cu_mi, 8, 8, *plane, unit);10478 neighbours.record_mi_chroma(*cu_mi, 8, 8, *plane, unit);
10330 }10479 }
10480+ for (cu_mi, plane, unit, span_w, span_h) in &tiled_chroma_units {
10481+ neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit);
10482+ }
10331 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);10483 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);
10332 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0, fctx);10484 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0, fctx);
10333 if crate::envflags::env_flag!("EC_AV1_TRACE") {10485 if crate::envflags::env_flag!("EC_AV1_TRACE") {
@@ -10932,8 +11084,8 @@ fn decode_intra_rect_in_inter(
10932 PaletteY { size: n, colors, map }11084 PaletteY { size: n, colors, map }
10933 });11085 });
10934 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {11086 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
10935- let (cw, ch) = ((bw / 2).max(4), (bh / 2).max(4));11087+ let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4));
10936- let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));11088+ let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch), (ss_x(fctx), ss_y(fctx)));
10937 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);11089 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
10938 hit!(PALETTE_UV_HITS);11090 hit!(PALETTE_UV_HITS);
10939 hit!(INTRA_IN_INTER_PALETTE_UV_HITS);11091 hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
@@ -10957,7 +11109,7 @@ fn decode_intra_rect_in_inter(
10957 if smooth_neighbor {11109 if smooth_neighbor {
10958 hit!(SMOOTH_LUMA_HITS);11110 hit!(SMOOTH_LUMA_HITS);
10959 }11111 }
10960- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);11112+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
10961 let depth = if fctx.tx_select_inter.with(std::cell::Cell::get) {11113 let depth = if fctx.tx_select_inter.with(std::cell::Cell::get) {
10962 // The frame's own `TXFM_CONTEXT` bands -- [`tx_size_context_txfm_rect`].11114 // The frame's own `TXFM_CONTEXT` bands -- [`tx_size_context_txfm_rect`].
10963 let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx);11115 let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx);
@@ -11179,7 +11331,7 @@ fn decode_intrabc_rect(
11179 let mut pred_y_dense = vec![0u16; bw * bh];11331 let mut pred_y_dense = vec![0u16; bw * bh];
11180 mc::predict_with_filter(11332 mc::predict_with_filter(
11181 &y.data, y.width, y.true_width, y.true_height,11333 &y.data, y.width, y.true_width, y.true_height,
11182- mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),11334+ mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),
11183 bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx,11335 bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx,
11184 );11336 );
11185 let mut pred_y = vec![0u16; side * side];11337 let mut pred_y = vec![0u16; side * side];
@@ -11189,7 +11341,7 @@ fn decode_intrabc_rect(
11189 let mut pred_u_dense = vec![0u16; cw * ch];11341 let mut pred_u_dense = vec![0u16; cw * ch];
11190 mc::predict_with_filter(11342 mc::predict_with_filter(
11191 &u.data, u.width, u.true_width, u.true_height,11343 &u.data, u.width, u.true_width, u.true_height,
11192- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),11344+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)),
11193 cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_u_dense, fctx,11345 cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_u_dense, fctx,
11194 );11346 );
11195 let mut pred_u = vec![0u16; cside * cside];11347 let mut pred_u = vec![0u16; cside * cside];
@@ -11199,7 +11351,7 @@ fn decode_intrabc_rect(
11199 let mut pred_v_dense = vec![0u16; cw * ch];11351 let mut pred_v_dense = vec![0u16; cw * ch];
11200 mc::predict_with_filter(11352 mc::predict_with_filter(
11201 &v.data, v.width, v.true_width, v.true_height,11353 &v.data, v.width, v.true_width, v.true_height,
11202- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),11354+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)),
11203 cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_v_dense, fctx,11355 cw, ch, mc::InterpFilterKind::Bilinear, &mut pred_v_dense, fctx,
11204 );11356 );
11205 let mut pred_v = vec![0u16; cside * cside];11357 let mut pred_v = vec![0u16; cside * cside];
@@ -11524,7 +11676,7 @@ fn decode_block_rect(
11524 // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's11676 // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's
11525 // `uv_mode`, not the luma one.11677 // `uv_mode`, not the luma one.
11526 let smooth_neighbor_uv =11678 let smooth_neighbor_uv =
11527- neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);11679+ neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
11528 // lane-rectsplit r1: `predict_filter_intra` now takes the block's own11680 // lane-rectsplit r1: `predict_filter_intra` now takes the block's own
11529 // `bw`x`bh` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a11681 // `bw`x`bh` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a
11530 // rectangle just as happily), so a `use_filter_intra` strip at this level11682 // rectangle just as happily), so a `use_filter_intra` strip at this level
@@ -11643,8 +11795,8 @@ fn decode_block_rect(
11643 return Ok(());11795 return Ok(());
11644 }11796 }
11645 let (tx_w, tx_h) = (bw, bh);11797 let (tx_w, tx_h) = (bw, bh);
11646- let (cpx, cpy) = (px / 2, py / 2);11798+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
11647- let (chroma_w, chroma_h) = (bw / 2, bh / 2);11799+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
11648 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);11800 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
11649 if crate::envflags::env_flag!("EC_AV1_TRACE") {11801 if crate::envflags::env_flag!("EC_AV1_TRACE") {
11650 let (rng, _) = dec.debug_state();11802 let (rng, _) = dec.debug_state();
@@ -11732,10 +11884,25 @@ fn decode_block_rect(
11732 // (`TxbSet::LumaRect32x16`/`ChromaRect16x8`, see those variants' own11884 // (`TxbSet::LumaRect32x16`/`ChromaRect16x8`, see those variants' own
11733 // doc comments); the scan order and 2D context tables are the real11885 // doc comments); the scan order and 2D context tables are the real
11734 // rect ones (`SCAN_32X16`/etc, `base_ctx_rect`/`br_ctx_rect`).11886 // rect ones (`SCAN_32X16`/etc, `base_ctx_rect`/`br_ctx_rect`).
11735- let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 32 {11887+ let luma_scan: &[u16] = if bw > bh { &SCAN_32X16 } else { &SCAN_16X32 };
11736- (&SCAN_32X16, &SCAN_16X8)11888+ // Chroma tx follows the plane block, not a hardcoded half. At 4:2:0 a
11889+ // 32x16 strip's chroma is 16x8 (ChromaRect16x8); at 4:4:4 it is 32x16
11890+ // (ChromaRect32x16, DCT-only — ADST is undefined on a 32-point axis).
11891+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) {
11892+ (32, 16) => (TxbSet::ChromaRect32x16, &SCAN_32X16),
11893+ (16, 32) => (TxbSet::ChromaRect32x16, &SCAN_16X32),
11894+ (16, 8) => (TxbSet::ChromaRect16x8, &SCAN_16X8),
11895+ (8, 16) => (TxbSet::ChromaRect16x8, &SCAN_8X16),
11896+ _ => {
11897+ return Err(unsupported(
11898+ "a rectangular chroma transform whose size has no coefficient table",
11899+ ))
11900+ }
11901+ };
11902+ let chroma_default_tx = if chroma_w.max(chroma_h) >= 32 {
11903+ TxType::DctDct
11737 } else {11904 } else {
11738- (&SCAN_16X32, &SCAN_8X16)11905+ default_intra_tx_type(uv_predict_mode as u8)
11739 };11906 };
11740 // lane-rectwire r3: real coefficients desync a pixel-exact gate11907 // lane-rectwire r3: real coefficients desync a pixel-exact gate
11741 // (rectwire-flake-1.obu, seed 55) -- both 32x16 strips of frame 0's11908 // (rectwire-flake-1.obu, seed 55) -- both 32x16 strips of frame 0's
@@ -11815,9 +11982,9 @@ fn decode_block_rect(
11815 if let Some((ub, _)) = &palette_uv_bufs {11982 if let Some((ub, _)) = &palette_uv_bufs {
11816 set_palette_pred(ub.clone(), fctx);11983 set_palette_pred(ub.clone(), fctx);
11817 }11984 }
11818- let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);11985+ let u_default_tx = chroma_default_tx;
11819 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);11986 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
11820- let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode);11987+ let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode);
11821 let (u_levels, u_tx_type) = read_chroma_coeffs_rect(11988 let (u_levels, u_tx_type) = read_chroma_coeffs_rect(
11822 dec,11989 dec,
11823 &mut u_coding,11990 &mut u_coding,
@@ -11859,9 +12026,9 @@ fn decode_block_rect(
11859 if let Some((_, vb)) = &palette_uv_bufs {12026 if let Some((_, vb)) = &palette_uv_bufs {
11860 set_palette_pred(vb.clone(), fctx);12027 set_palette_pred(vb.clone(), fctx);
11861 }12028 }
11862- let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);12029+ let v_default_tx = chroma_default_tx;
11863 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);12030 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
11864- let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode);12031+ let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode);
11865 let (v_levels, v_tx_type) = read_chroma_coeffs_rect(12032 let (v_levels, v_tx_type) = read_chroma_coeffs_rect(
11866 dec,12033 dec,
11867 &mut v_coding,12034 &mut v_coding,
@@ -12061,7 +12228,7 @@ fn decode_leaf_rect(
12061 // lane-cfl r1, same defect as [`decode_leaf_8x8`]: chroma's intra-edge12228 // lane-cfl r1, same defect as [`decode_leaf_8x8`]: chroma's intra-edge
12062 // filter type is the NEIGHBOUR's `uv_mode` (libaom `get_filt_type`), not12229 // filter type is the NEIGHBOUR's `uv_mode` (libaom `get_filt_type`), not
12063 // a constant `false`.12230 // a constant `false`.
12064- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);12231+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
12065 let depth = if tx_select {12232 let depth = if tx_select {
12066 // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band read12233 // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band read
12067 // every other rect reader now does -- a no-op on a key frame.12234 // every other rect reader now does -- a no-op on a key frame.
@@ -12147,8 +12314,8 @@ fn decode_leaf_rect(
12147 }12314 }
12148 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);12315 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
12149 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);12316 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
12150- let (cpx, cpy) = (px / 2, py / 2);12317+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
12151- let (chroma_w, chroma_h) = (bw / 2, bh / 2);12318+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
12152 let (luma_levels, u_levels, v_levels);12319 let (luma_levels, u_levels, v_levels);
12153 if skip {12320 if skip {
12154 luma_levels = Grid::Zero(bw * bh);12321 luma_levels = Grid::Zero(bw * bh);
@@ -12183,11 +12350,14 @@ fn decode_leaf_rect(
12183 // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at12350 // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at
12184 // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square12351 // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square
12185 // `tx_size`) and its chroma half (8x4/4x8, `TxbSet::ChromaRect8x4`).12352 // `tx_size`) and its chroma half (8x4/4x8, `TxbSet::ChromaRect8x4`).
12186- let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 16 {12353+ let (luma_scan, chroma_scan): (&[u16], &[u16]) = if ss_x(fctx) == 0 {
12354+ if bw == 16 { (&SCAN_16X8, &SCAN_16X8) } else { (&SCAN_8X16, &SCAN_8X16) }
12355+ } else if bw == 16 {
12187 (&SCAN_16X8, &SCAN_8X4)12356 (&SCAN_16X8, &SCAN_8X4)
12188 } else {12357 } else {
12189 (&SCAN_8X16, &SCAN_4X8)12358 (&SCAN_8X16, &SCAN_4X8)
12190 };12359 };
12360+ let chroma_rect_set = if ss_x(fctx) == 0 { TxbSet::ChromaRect16x8 } else { TxbSet::ChromaRect8x4 };
12191 let around = neighbours.around_mi_rect(leaf_mi, bw, bh);12361 let around = neighbours.around_mi_rect(leaf_mi, bw, bh);
12192 let luma_set = if reduced_tx_set {12362 let luma_set = if reduced_tx_set {
12193 TxbSet::LumaRect16x812363 TxbSet::LumaRect16x8
@@ -12217,7 +12387,7 @@ fn decode_leaf_rect(
12217 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));12387 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
12218 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);12388 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
12219 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);12389 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
12220- let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);12390+ let mut u_coding = cdfs.txb(chroma_rect_set, uv_predict_mode);
12221 let (u_l, u_tx_type) = read_chroma_coeffs_rect(12391 let (u_l, u_tx_type) = read_chroma_coeffs_rect(
12222 dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx,12392 dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx,
12223 dc_sign_ctx(around[1].2), u_default_tx, fctx,12393 dc_sign_ctx(around[1].2), u_default_tx, fctx,
@@ -12236,7 +12406,7 @@ fn decode_leaf_rect(
12236 );12406 );
12237 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);12407 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
12238 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);12408 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
12239- let mut v_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);12409+ let mut v_coding = cdfs.txb(chroma_rect_set, uv_predict_mode);
12240 let (v_l, v_tx_type) = read_chroma_coeffs_rect(12410 let (v_l, v_tx_type) = read_chroma_coeffs_rect(
12241 dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx,12411 dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx,
12242 dc_sign_ctx(around[2].2), v_default_tx, fctx,12412 dc_sign_ctx(around[2].2), v_default_tx, fctx,
@@ -12402,7 +12572,7 @@ fn decode_block_rect4(
12402 // edge-filter strength was read from the wrong neighbour (measured:12572 // edge-filter strength was read from the wrong neighbour (measured:
12403 // seed 43, the last 8x32 strip at luma (152,32), chroma-only mismatch12573 // seed 43, the last 8x32 strip at luma (152,32), chroma-only mismatch
12404 // with luma bit-exact).12574 // with luma bit-exact).
12405- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);12575+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
12406 if filter_intra.is_some() {12576 if filter_intra.is_some() {
12407 hit!(FILTER_INTRA_RECT_HITS);12577 hit!(FILTER_INTRA_RECT_HITS);
12408 if bw > bh {12578 if bw > bh {
@@ -12540,14 +12710,24 @@ fn decode_block_rect4(
12540 neighbours.record_mode_mi(mi_r, mi_c, mi_w, mi_h, mode);12710 neighbours.record_mode_mi(mi_r, mi_c, mi_w, mi_h, mode);
12541 neighbours.record_uv_mode_mi(mi_r, mi_c, mi_w, mi_h, uv_predict_mode);12711 neighbours.record_uv_mode_mi(mi_r, mi_c, mi_w, mi_h, uv_predict_mode);
12542 let (px, py) = (mi_c * MI, mi_r * MI);12712 let (px, py) = (mi_c * MI, mi_r * MI);
12543- let (cpx, cpy) = (px / 2, py / 2);12713+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
12544- let (chroma_w, chroma_h) = (bw / 2, bh / 2);12714+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
12545 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);12715 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
12546- let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh {12716+ // lane-av1-444: the strip's chroma shape follows the subsampling.
12547- (&SCAN_32X8, &SCAN_16X4)12717+ // 4:2:0 codes 16x4/4x16 (`TxbSet::Chroma8`); 4:4:4 codes the strip
12548- } else {12718+ // itself, 32x8/8x32 (`get_txsize_entropy_ctx(TX_32X8)` =
12549- (&SCAN_8X32, &SCAN_4X16)12719+ // `(wide_log2 + high_log2 + 1) >> 1` = the 16x16 set,
12720+ // `TxbSet::Chroma16`). The caller set is closed -- this reader only
12721+ // ever sees 32x8 / 8x32 luma and the sequence header admits ss 0/0
12722+ // and 1/1 only -- so the table is exhaustive.
12723+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) {
12724+ (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),
12725+ (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]),
12726+ (32, 8) => (TxbSet::Chroma16, &SCAN_32X8[..]),
12727+ (8, 32) => (TxbSet::Chroma16, &SCAN_8X32[..]),
12728+ _ => unreachable!("decode_block_rect4 chroma shape set is closed"),
12550 };12729 };
12730+ let luma_scan: &[u16] = if bw > bh { &SCAN_32X8 } else { &SCAN_8X32 };
12551 let (luma_levels, u_levels, v_levels) = if skip {12731 let (luma_levels, u_levels, v_levels) = if skip {
12552 (12732 (
12553 vec![0i32; bw * bh],12733 vec![0i32; bw * bh],
@@ -12569,9 +12749,18 @@ fn decode_block_rect4(
12569 )?;12749 )?;
12570 let mut planes = Vec::with_capacity(2);12750 let mut planes = Vec::with_capacity(2);
12571 for plane in 1..3 {12751 for plane in 1..3 {
12572- let default_tx = default_intra_tx_type(uv_predict_mode as u8);12752+ // `av1_get_tx_type` (`blockd.h:1278`): the mode-indexed type
12753+ // stands only while it is a member of this tx size's set; a
12754+ // 32x8/8x32 chroma transform (4:4:4) squares up to TX_32X32,
12755+ // whose intra set is `EXT_TX_SET_DCTONLY` -- every ADST clamps
12756+ // to DCT_DCT there, and ADST is undefined at widths above 16.
12757+ let default_tx = if chroma_w.max(chroma_h) >= 32 {
12758+ TxType::DctDct
12759+ } else {
12760+ default_intra_tx_type(uv_predict_mode as u8)
12761+ };
12573 let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1);12762 let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1);
12574- let mut coding = cdfs.txb(TxbSet::Chroma8, uv_predict_mode);12763+ let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
12575 let (levels, tx_type) = read_chroma_coeffs_rect(12764 let (levels, tx_type) = read_chroma_coeffs_rect(
12576 dec,12765 dec,
12577 &mut coding,12766 &mut coding,
@@ -12800,7 +12989,10 @@ fn decode_rect4_16(
12800 } else {12989 } else {
12801 (mi_row0, mi_col0 + i)12990 (mi_row0, mi_col0 + i)
12802 };12991 };
12803- let has_chroma = i % 2 == 1;12992+ // lane-av1-444: at 4:4:4 every strip is its own chroma reference
12993+ // (no mi-parity test at ss 0/0, and the strip's own chroma block is
12994+ // already >= 4x4) -- there is no 4:2:0 pair to close.
12995+ let has_chroma = i % 2 == 1 || (ss_x(fctx) == 0 && ss_y(fctx) == 0);
12804 let (mode, uv, _tx) = decode_rect4_16_strip(12996 let (mode, uv, _tx) = decode_rect4_16_strip(
12805 dec,12997 dec,
12806 cdfs,12998 cdfs,
@@ -13017,7 +13209,7 @@ fn predict_intrabc_window(
13017 let mut dense = vec![0u16; w * h];13209 let mut dense = vec![0u16; w * h];
13018 mc::predict_with_filter(13210 mc::predict_with_filter(
13019 &plane.data, plane.width, plane.true_width, plane.true_height,13211 &plane.data, plane.width, plane.true_width, plane.true_height,
13020- mv_to_q4(px, dv_col, luma), mv_to_q4(py, dv_row, luma),13212+ mv_to_q4(px, dv_col, if luma { 0 } else { ss_x(fctx) }), mv_to_q4(py, dv_row, if luma { 0 } else { ss_y(fctx) }),
13021 w, h, mc::InterpFilterKind::Bilinear, &mut dense, fctx,13213 w, h, mc::InterpFilterKind::Bilinear, &mut dense, fctx,
13022 );13214 );
13023 let mut laid = vec![0u16; stride * stride];13215 let mut laid = vec![0u16; stride * stride];
@@ -13090,7 +13282,7 @@ fn decode_rect4_16_intrabc(
13090 let mut pred_y_dense = vec![0u16; bw * bh];13282 let mut pred_y_dense = vec![0u16; bw * bh];
13091 mc::predict_with_filter(13283 mc::predict_with_filter(
13092 &y.data, y.width, y.true_width, y.true_height,13284 &y.data, y.width, y.true_width, y.true_height,
13093- mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),13285+ mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),
13094 bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx,13286 bw, bh, mc::InterpFilterKind::Bilinear, &mut pred_y_dense, fctx,
13095 );13287 );
13096 let mut pred_y = vec![0u16; side * side];13288 let mut pred_y = vec![0u16; side * side];
@@ -13115,7 +13307,7 @@ fn decode_rect4_16_intrabc(
13115 let mut ud = vec![0u16; cw * ch];13307 let mut ud = vec![0u16; cw * ch];
13116 mc::predict_with_filter(13308 mc::predict_with_filter(
13117 &u.data, u.width, u.true_width, u.true_height,13309 &u.data, u.width, u.true_width, u.true_height,
13118- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),13310+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)),
13119 cw, ch, mc::InterpFilterKind::Bilinear, &mut ud, fctx,13311 cw, ch, mc::InterpFilterKind::Bilinear, &mut ud, fctx,
13120 );13312 );
13121 let mut us = vec![0u16; cside * cside];13313 let mut us = vec![0u16; cside * cside];
@@ -13125,7 +13317,7 @@ fn decode_rect4_16_intrabc(
13125 let mut vd = vec![0u16; cw * ch];13317 let mut vd = vec![0u16; cw * ch];
13126 mc::predict_with_filter(13318 mc::predict_with_filter(
13127 &v.data, v.width, v.true_width, v.true_height,13319 &v.data, v.width, v.true_width, v.true_height,
13128- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),13320+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)),
13129 cw, ch, mc::InterpFilterKind::Bilinear, &mut vd, fctx,13321 cw, ch, mc::InterpFilterKind::Bilinear, &mut vd, fctx,
13130 );13322 );
13131 let mut vs = vec![0u16; cside * cside];13323 let mut vs = vec![0u16; cside * cside];
@@ -13403,7 +13595,6 @@ fn decode_rect4_16_strip(
13403 let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };13595 let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };
13404 let (mi_w, mi_h) = (bw / MI, bh / MI);13596 let (mi_w, mi_h) = (bw / MI, bh / MI);
13405 let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 };13597 let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 };
13406- let chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 };
13407 let mut last_uv_mode: Option<usize> = None;13598 let mut last_uv_mode: Option<usize> = None;
13408 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell13599 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell
13409 // aliases all four strips onto one entry, so the mi-exact map wins and13600 // aliases all four strips onto one entry, so the mi-exact map wins and
@@ -13691,15 +13882,20 @@ fn decode_rect4_16_strip(
13691 }13882 }
13692 if has_chroma {13883 if has_chroma {
13693 hit!(RECT4_16_CHROMA_HITS);13884 hit!(RECT4_16_CHROMA_HITS);
13694- let pair_mi = if horz {13885+ // lane-av1-444: at 4:4:4 there is no pair -- every strip is its
13695- (lmi.0 - 1, lmi.1)13886+ // own chroma reference and codes its own 16x4 / 4x16 chroma
13887+ // block. (`set_mi_offsets`'s chroma snap is the zero offset at
13888+ // ss 0/0, so the neighbour reads below anchor at the strip.)
13889+ let (pair_mi, pw, ph) = if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
13890+ (lmi, bw, bh)
13891+ } else if horz {
13892+ ((lmi.0 - 1, lmi.1), 16, 8)
13696 } else {13893 } else {
13697- (lmi.0, lmi.1 - 1)13894+ ((lmi.0, lmi.1 - 1), 8, 16)
13698 };13895 };
13699- let (pw, ph) = if horz { (16, 8) } else { (8, 16) };
13700 let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI);13896 let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI);
13701- let (cpx, cpy) = (ppx / 2, ppy / 2);13897+ let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx));
13702- let (cw, ch) = (pw / 2, ph / 2);13898+ let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx));
13703 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };13899 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
13704 if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {13900 if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {
13705 hit!(RECT4_16_CHROMA_DIR_HITS);13901 hit!(RECT4_16_CHROMA_DIR_HITS);
@@ -13717,7 +13913,7 @@ fn decode_rect4_16_strip(
13717 // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a13913 // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a
13718 // directional chroma strip, moving 4 samples by 1.13914 // directional chroma strip, moving 4 samples by 1.
13719 let smooth_neighbor_uv =13915 let smooth_neighbor_uv =
13720- neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c);13916+ neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx);
13721 if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c)13917 if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c)
13722 {13918 {
13723 hit!(RECT4_16_UV_PAIR_FILT_HITS);13919 hit!(RECT4_16_UV_PAIR_FILT_HITS);
@@ -13841,11 +14037,21 @@ fn decode_rect4_16_strip(
13841 (zeros.clone(), zeros)14037 (zeros.clone(), zeros)
13842 } else {14038 } else {
13843 let around = neighbours.around_mi_rect(pair_mi, pw, ph);14039 let around = neighbours.around_mi_rect(pair_mi, pw, ph);
14040+ // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0
14041+ // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` =
14042+ // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8.
14043+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (cw, ch) {
14044+ (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]),
14045+ (4, 8) => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]),
14046+ (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),
14047+ (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]),
14048+ _ => unreachable!("decode_rect4_16_strip chroma shape set is closed"),
14049+ };
13844 let mut planes = Vec::with_capacity(2);14050 let mut planes = Vec::with_capacity(2);
13845 for plane in 1..3 {14051 for plane in 1..3 {
13846 let default_tx = default_intra_tx_type(uv_predict_mode as u8);14052 let default_tx = default_intra_tx_type(uv_predict_mode as u8);
13847 let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1);14053 let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1);
13848- let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);14054+ let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
13849 let (levels, tx_type) = read_chroma_coeffs_rect(14055 let (levels, tx_type) = read_chroma_coeffs_rect(
13850 dec,14056 dec,
13851 &mut coding,14057 &mut coding,
@@ -14039,7 +14245,7 @@ fn decode_block_rect64(
14039 hit!(SMOOTH_LUMA_HITS);14245 hit!(SMOOTH_LUMA_HITS);
14040 }14246 }
14041 let smooth_neighbor_uv =14247 let smooth_neighbor_uv =
14042- neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);14248+ neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
14043 if filter_intra.is_some() {14249 if filter_intra.is_some() {
14044 // `filter_intra_size_class_rect` already returns `None` for both14250 // `filter_intra_size_class_rect` already returns `None` for both
14045 // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at14251 // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at
@@ -14176,8 +14382,8 @@ fn decode_block_rect64(
14176 return Ok(());14382 return Ok(());
14177 }14383 }
14178 let (tx_w, tx_h) = (bw, bh);14384 let (tx_w, tx_h) = (bw, bh);
14179- let (cpx, cpy) = (px / 2, py / 2);14385+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
14180- let (chroma_w, chroma_h) = (bw / 2, bh / 2);14386+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
14181 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);14387 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
14182 if let Some(ref pyv) = palette_y {14388 if let Some(ref pyv) = palette_y {
14183 let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect();14389 let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect();
@@ -14356,145 +14562,119 @@ fn decode_block_rect64(
14356 leftcol,14562 leftcol,
14357 );14563 );
14358 }14564 }
14359- // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no14565+ // CHROMA. At 4:2:0 the plane block is already one adjusted UV
14360- // corner crop needed (see doc comment).14566+ // transform (<=32 on each axis). At 4:4:4 a 64-axis strip's chroma
14361- let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));14567+ // is larger than that, so it is tiled into 32-capped units.
14362- // The chroma plane is never truncated (both axes <= 32 after14568+ let _ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
14363- // subsampling). Under a 1:4 strip it is a true 32x8/8x32:14569+ let (uw, uh) = (chroma_w.min(32), chroma_h.min(32));
14364- // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 =14570+ let (nw, nh) = (chroma_w / uw, chroma_h / uh);
14365- // TX_16X16 and `txsize_log2_minus4[TX_32X8]` = 4 (256 positions),14571+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (uw, uh) {
14366- // both identical to TX_16X16 -- so [`TxbSet::Chroma16`] is the exact14572+ (32, 32) => (TxbSet::Chroma32, default_scan(32)),
14367- // set, and only the scan is new (lane-tx64x16).14573+ (32, 16) => (TxbSet::ChromaRect32x16, &SCAN_32X16),
14368- let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (bw, bh) {14574+ (16, 32) => (TxbSet::ChromaRect32x16, &SCAN_16X32),
14369- (64, 16) => (TxbSet::Chroma16, &SCAN_32X8),14575+ (32, 8) => (TxbSet::Chroma16, &SCAN_32X8),
14370- (16, 64) => (TxbSet::Chroma16, &SCAN_8X32),14576+ (8, 32) => (TxbSet::Chroma16, &SCAN_8X32),
14371- (64, _) => (TxbSet::ChromaRect32x16, &SCAN_32X16),14577+ _ => {
14372- _ => (TxbSet::ChromaRect32x16, &SCAN_16X32),14578+ return Err(unsupported(
14373- };14579+ "a 64-axis strip whose chroma unit has no coefficient table",
14374- let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);14580+ ))
14375- let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode);
14376- if coeff_trace_on() {
14377- let (rng, _) = dec.debug_state();
14378- eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}");
14379- }
14380- let (u_levels, u_tx_type) = read_chroma_coeffs_rect(
14381- dec,
14382- &mut u_coding,
14383- chroma_scan,
14384- chroma_w,
14385- chroma_h,
14386- u_skip_ctx,
14387- dc_sign_ctx(around[1].2),
14388- TxType::DctDct,
14389- fctx,
14390- )?;
14391- if coeff_trace_on() {
14392- let (rng, _) = dec.debug_state();
14393- eprintln!("EC_COEFF_VAL plane=1 row={mi_r} col={mi_c} rng={rng}");
14394- }
14395- {
14396- let cur = block_q_idx(fctx);
14397- if cur != i32::from(base_q_idx) {
14398- hit!(RECT64_QIDX_DRIFT_HITS);
14399- }
14400- if crate::envflags::env_flag!("EC_AV1_TRACE") {
14401- eprintln!(
14402- "TRACE rect64_dequant plane=1 base_q_idx={base_q_idx} current_q_idx={cur}"
14403- );
14404- }
14405- }
14406- let u_residual = dequant_and_inverse_typed_wh(
14407- &u_levels,
14408- chroma_w,
14409- chroma_h,
14410- crate::decode::bit_depth(fctx),
14411- block_q_idx(fctx),
14412- plane_q_delta(1, fctx).0,
14413- plane_q_delta(1, fctx).1,
14414- u_tx_type,
14415- );
14416- // lane-t900 r34: the UV-palette prediction override, exactly as the
14417- // `skip` arm above installs it. The [`PALETTE_PRED`] slot is a
14418- // set-then-take, so it must be filled again right before each plane's
14419- // own reconstruct; leaving this out of the non-skip arm predicted a
14420- // palette block's chroma off its block edges (measured: testsrc2
14421- // 128x128 10-bit cq55 `--tile-columns=1`, the 32x64 strip at px=96 --
14422- // luma exact, both chroma planes wrong over its whole 16x32).
14423- if let Some((ub, _)) = &palette_uv_bufs {
14424- set_palette_pred(ub.clone(), fctx);
14425- }
14426- push_intra_rect(1,
14427- cpx,
14428- cpy,
14429- chroma_w,
14430- chroma_h,
14431- uv_predict_mode,
14432- angle_delta_uv,
14433- reach,
14434- &u_residual,
14435- alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
14436- None,
14437- smooth_neighbor_uv, fctx,
14438- );
14439- let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
14440- let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode);
14441- if coeff_trace_on() {
14442- let (rng, _) = dec.debug_state();
14443- eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}");
14444- }
14445- let (v_levels, v_tx_type) = read_chroma_coeffs_rect(
14446- dec,
14447- &mut v_coding,
14448- chroma_scan,
14449- chroma_w,
14450- chroma_h,
14451- v_skip_ctx,
14452- dc_sign_ctx(around[2].2),
14453- TxType::DctDct,
14454- fctx,
14455- )?;
14456- if coeff_trace_on() {
14457- let (rng, _) = dec.debug_state();
14458- eprintln!("EC_COEFF_VAL plane=2 row={mi_r} col={mi_c} rng={rng}");
14459- }
14460- {
14461- let cur = block_q_idx(fctx);
14462- if cur != i32::from(base_q_idx) {
14463- hit!(RECT64_QIDX_DRIFT_HITS);
14464 }14581 }
14465- if crate::envflags::env_flag!("EC_AV1_TRACE") {14582+ };
14466- eprintln!(14583+ let bigger = nw * nh > 1;
14467- "TRACE rect64_dequant plane=2 base_q_idx={base_q_idx} current_q_idx={cur}"14584+ let mut u_levels = vec![0i32; chroma_w * chroma_h];
14468- );14585+ let mut v_levels = vec![0i32; chroma_w * chroma_h];
14586+ // The tiled units below stamp their own coefficient context
14587+ // immediately, then the whole-strip `record_rect` rewrite paints
14588+ // every chroma cell with ONE whole-strip state and the per-unit DC
14589+ // signs and levels are lost (class `override-slot-on-one-arm`, same
14590+ // shape as `decode_rect_split`'s chroma_tiled clobber). Collected
14591+ // here and replayed after that record, the c8 `mu_chroma_units` way.
14592+ let mut tiled_chroma_units: Vec<((usize, usize), usize, Grid, usize, usize)> = Vec::new();
14593+ for plane_idx in 1..=2 {
14594+ for cu_row in 0..nh {
14595+ for cu_col in 0..nw {
14596+ let cu_around = if nw == 1 && nh == 1 {
14597+ around
14598+ } else {
14599+ let lsx = uw << ss_x(fctx);
14600+ let lsy = uh << ss_y(fctx);
14601+ let cu_mi = (
14602+ mi_r + cu_row * (lsy / MI),
14603+ mi_c + cu_col * (lsx / MI),
14604+ );
14605+ neighbours.around_mi_rect(cu_mi, lsx, lsy)
14606+ };
14607+ let lsx = uw << ss_x(fctx);
14608+ let lsy = uh << ss_y(fctx);
14609+ let cfl = alpha.map(|(au, av)| {
14610+ let a = if plane_idx == 1 { au } else { av };
14611+ (a, cfl_src_rect(px + cu_col * lsx, py + cu_row * lsy, lsx, lsy))
14612+ });
14613+ let levels = if uw == uh {
14614+ let plane = if plane_idx == 1 { &mut *u } else { &mut *v };
14615+ if let Some((ub, vb)) = &palette_uv_bufs {
14616+ set_palette_pred((if plane_idx == 1 { ub } else { vb }).clone(), fctx);
14617+ }
14618+ read_plane(
14619+ dec, cdfs, chroma_set, chroma_scan, plane_idx, cu_around[plane_idx],
14620+ mode, uv_predict_mode, angle_delta_uv, reach, plane,
14621+ cpx + cu_col * uw, cpy + cu_row * uh, uw, uw, base_q_idx,
14622+ cfl, None, bigger.then_some(3), smooth_neighbor_uv, fctx,
14623+ )?
14624+ } else {
14625+ let skip_ctx = usize::from(cu_around[plane_idx].0)
14626+ + usize::from(cu_around[plane_idx].1)
14627+ + usize::from(bigger) * 3;
14628+ let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
14629+ let (levels, tx_type) = read_chroma_coeffs_rect(
14630+ dec, &mut coding, chroma_scan, uw, uh, skip_ctx,
14631+ dc_sign_ctx(cu_around[plane_idx].2), TxType::DctDct, fctx,
14632+ )?;
14633+ let residual = dequant_and_inverse_typed_wh(
14634+ &levels, uw, uh, crate::decode::bit_depth(fctx),
14635+ block_q_idx(fctx),
14636+ plane_q_delta(plane_idx, fctx).0,
14637+ plane_q_delta(plane_idx, fctx).1,
14638+ tx_type,
14639+ );
14640+ if let Some((ub, vb)) = &palette_uv_bufs {
14641+ set_palette_pred((if plane_idx == 1 { ub } else { vb }).clone(), fctx);
14642+ }
14643+ push_intra_rect(
14644+ plane_idx, cpx + cu_col * uw, cpy + cu_row * uh, uw, uh,
14645+ uv_predict_mode, angle_delta_uv, reach, &residual,
14646+ cfl, None, smooth_neighbor_uv, fctx,
14647+ );
14648+ levels
14649+ };
14650+ let dst = if plane_idx == 1 { &mut u_levels } else { &mut v_levels };
14651+ for row in 0..uh {
14652+ let d = (cu_row * uh + row) * chroma_w + cu_col * uw;
14653+ dst[d..d + uw].copy_from_slice(&levels[row * uw..][..uw]);
14654+ }
14655+ if bigger {
14656+ neighbours.record_mi_chroma(
14657+ (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)),
14658+ lsx, lsy, plane_idx, &levels,
14659+ );
14660+ tiled_chroma_units.push((
14661+ (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)),
14662+ plane_idx,
14663+ levels.clone(),
14664+ lsx,
14665+ lsy,
14666+ ));
14667+ }
14668+ }
14469 }14669 }
14470 }14670 }
14471- let v_residual = dequant_and_inverse_typed_wh(14671+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
14472- &v_levels,14672+ // The per-unit re-stamp: `record_rect` above wrote the whole strip's
14473- chroma_w,14673+ // chroma cells from the assembled grids' one whole-strip state,
14474- chroma_h,14674+ // overwriting exactly the stamps the tiled loop just made.
14475- crate::decode::bit_depth(fctx),14675+ for (cu_mi, plane, unit, span_w, span_h) in &tiled_chroma_units {
14476- block_q_idx(fctx),14676+ neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit);
14477- plane_q_delta(2, fctx).0,
14478- plane_q_delta(2, fctx).1,
14479- v_tx_type,
14480- );
14481- if let Some((_, vb)) = &palette_uv_bufs {
14482- set_palette_pred(vb.clone(), fctx);
14483 }14677 }
14484- push_intra_rect(2,
14485- cpx,
14486- cpy,
14487- chroma_w,
14488- chroma_h,
14489- uv_predict_mode,
14490- angle_delta_uv,
14491- reach,
14492- &v_residual,
14493- alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
14494- None,
14495- smooth_neighbor_uv, fctx,
14496- );
14497- neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
14498 hit!(RECT_COEFF_HITS);14678 hit!(RECT_COEFF_HITS);
14499 }14679 }
14500 let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));14680 let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
@@ -14863,9 +15043,10 @@ fn read_intra_mode(
14863 let on = palette_onscreen_uv(15043 let on = palette_onscreen_uv(
14864 (side, side),15044 (side, side),
14865 palette_onscreen(mi_r, mi_c, side, side, fctx),15045 palette_onscreen(mi_r, mi_c, side, side, fctx),
14866- (side / 2, side / 2),15046+ (side >> ss_x(fctx), side >> ss_y(fctx)),
15047+ (ss_x(fctx), ss_y(fctx)),
14867 );15048 );
14868- let map = decode_color_index_map(dec, cdfs, n, side / 2, on, true);15049+ let map = decode_color_index_map(dec, cdfs, n, side >> ss_x(fctx), on, true);
14869 hit!(PALETTE_UV_HITS);15050 hit!(PALETTE_UV_HITS);
14870 if trace {15051 if trace {
14871 eprintln!(15052 eprintln!(
@@ -14936,6 +15117,38 @@ fn cfl_ac_q3(y: &PlaneBuf<'_>, px: usize, py: usize, side: usize) -> Vec<i32> {
14936 /// (lane-av1cfl) builds a CfL candidate's AC signal from its own `u8`15117 /// (lane-av1cfl) builds a CfL candidate's AC signal from its own `u8`
14937 /// reconstruction through THIS function rather than a second transcription of15118 /// reconstruction through THIS function rather than a second transcription of
14938 /// `cfl_luma_subsampling_420_lbd_c` + `subtract_average_c`.15119 /// `cfl_luma_subsampling_420_lbd_c` + `subtract_average_c`.
15120+/// CfL AC at the frame's subsampling. 4:2:0 keeps the 2x2 average; 4:4:4
15121+/// copies each luma sample shifted to Q3 (`cfl_luma_subsampling_444_lbd`).
15122+fn cfl_ac_ss(
15123+ y: &PlaneBuf<'_>,
15124+ px: usize,
15125+ py: usize,
15126+ bw: usize,
15127+ bh: usize,
15128+ ss_x: usize,
15129+ ss_y: usize,
15130+) -> Vec<i32> {
15131+ if ss_x == 0 && ss_y == 0 {
15132+ let mut ac = vec![0i32; bw * bh];
15133+ let mut sum = 0i32;
15134+ for row in 0..bh {
15135+ for col in 0..bw {
15136+ let q3 = i32::from(y.data[(py + row) * y.width + px + col]) << 3;
15137+ ac[row * bw + col] = q3;
15138+ sum += q3;
15139+ }
15140+ }
15141+ let num_pel = (bw * bh) as i32;
15142+ let avg = (sum + num_pel / 2) >> num_pel.trailing_zeros();
15143+ ac.iter_mut().for_each(|v| *v -= avg);
15144+ ac
15145+ } else if bw == bh {
15146+ cfl_ac_q3(y, px, py, bw)
15147+ } else {
15148+ cfl_ac_q3_rect(y, px, py, bw, bh)
15149+ }
15150+}
15151+
14939 pub(crate) fn cfl_ac_q3_at(15152 pub(crate) fn cfl_ac_q3_at(
14940 px: usize,15153 px: usize,
14941 py: usize,15154 py: usize,
@@ -15282,6 +15495,11 @@ impl PlaneBuf<'_> {
15282 );15495 );
15283 }15496 }
15284 let residual = dense_residual(residual, bw * bh);15497 let residual = dense_residual(residual, bw * bh);
15498+ if crate::envflags::env_flag!("EC_DBG192") && y == 168 && (x == 224 || x == 232) {
15499+ let res0: Vec<i32> = residual[..bw.min(8)].to_vec();
15500+ let pred0: Vec<u16> = prediction[..bw.min(8)].to_vec();
15501+ eprintln!("DBG192 rect x={x} y={y} bw={bw} bh={bh} mode={mode} pred0={pred0:?} res0={res0:?}");
15502+ }
15285 for row in 0..bh {15503 for row in 0..bh {
15286 // Same bottom/right frame-edge clip as [`Self::reconstruct`]'s15504 // Same bottom/right frame-edge clip as [`Self::reconstruct`]'s
15287 // (lane-sb128c r8) -- a 64x128 block at the right edge of a frame15505 // (lane-sb128c r8) -- a 64x128 block at the right edge of a frame
@@ -15354,6 +15572,13 @@ impl PlaneBuf<'_> {
15354 buf15572 buf
15355 } else {15573 } else {
15356 let (above, left, corner) = self.edges(x, y, side, reach);15574 let (above, left, corner) = self.edges(x, y, side, reach);
15575+ if crate::envflags::env_flag!("EC_DEBUG_EDGES") {
15576+ eprintln!(
15577+ "EDGES_SQ x={x} y={y} side={side} mode={mode} above={:?} left={:?} corner={corner:?}",
15578+ above.as_deref(),
15579+ left.as_deref(),
15580+ );
15581+ }
15357 let mut prediction = vec![0u16; side * side];15582 let mut prediction = vec![0u16; side * side];
15358 if let Some(fi_mode) = filter_intra {15583 if let Some(fi_mode) = filter_intra {
15359 crate::intra::predict_filter_intra(15584 crate::intra::predict_filter_intra(
@@ -15400,6 +15625,11 @@ impl PlaneBuf<'_> {
15400 );15625 );
15401 }15626 }
15402 let residual = dense_residual(residual, side * side);15627 let residual = dense_residual(residual, side * side);
15628+ if crate::envflags::env_flag!("EC_DBG192") && y == 168 && (x == 224 || x == 232) {
15629+ let res0: Vec<i32> = residual[..side.min(8)].to_vec();
15630+ let pred0: Vec<u16> = prediction[..side.min(8)].to_vec();
15631+ eprintln!("DBG192 sq x={x} y={y} side={side} mode={mode} cfl={} pred0={pred0:?} res0={res0:?}", cfl.is_some());
15632+ }
15403 for row in 0..side {15633 for row in 0..side {
15404 // lane-sb128c r8: libaom's frame buffer is superblock15634 // lane-sb128c r8: libaom's frame buffer is superblock
15405 // aligned; ours is padded to 32 (`block_grid`), so a 64x6415635 // aligned; ours is padded to 32 (`block_grid`), so a 64x64
@@ -15621,6 +15851,15 @@ fn decode_block(
15621 // multi-transform-unit path below.15851 // multi-transform-unit path below.
15622 let (luma_set, chroma_set, luma_tx, chroma_tx, scans) = if lossless(fctx) {15852 let (luma_set, chroma_set, luma_tx, chroma_tx, scans) = if lossless(fctx) {
15623 (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, (scan4, scan4))15853 (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, (scan4, scan4))
15854+ } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
15855+ let tx = if side >= 64 { 32 } else { side };
15856+ let (set, scan): (TxbSet, &[u16]) = match tx {
15857+ 32 => (TxbSet::Chroma32, scan32),
15858+ 16 => (TxbSet::Chroma16, scan16),
15859+ 8 => (TxbSet::Chroma8, scan8),
15860+ _ => (TxbSet::Chroma4, scan4),
15861+ };
15862+ (luma_set, set, luma_tx, tx, (scans.0, scan))
15624 } else {15863 } else {
15625 (luma_set, chroma_set, luma_tx, chroma_tx, scans)15864 (luma_set, chroma_set, luma_tx, chroma_tx, scans)
15626 };15865 };
@@ -15664,7 +15903,7 @@ fn decode_block(
15664 hit!(SMOOTH_LUMA_HITS);15903 hit!(SMOOTH_LUMA_HITS);
15665 }15904 }
15666 let smooth_neighbor_uv =15905 let smooth_neighbor_uv =
15667- neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);15906+ neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
15668 if crate::envflags::env_flag!("EC_AV1_TRACE") {15907 if crate::envflags::env_flag!("EC_AV1_TRACE") {
15669 eprintln!(15908 eprintln!(
15670 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \15909 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
@@ -15755,8 +15994,8 @@ fn decode_block(
15755 };15994 };
15756 let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8, scan4);15995 let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8, scan4);
15757 let reach = Reach::of(side, px, py, y.width, y.height, fctx);15996 let reach = Reach::of(side, px, py, y.width, y.height, fctx);
15758- let (cpx, cpy) = (px / 2, py / 2);15997+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
15759- let chroma_side = side / 2;15998+ let chroma_side = side >> ss_x(fctx);
15760 // spec 7.11.3.4 with `use_intrabc`: the reference is the *current*15999 // spec 7.11.3.4 with `use_intrabc`: the reference is the *current*
15761 // frame's own pre-loop-filter reconstruction (all loop filters are off16000 // frame's own pre-loop-filter reconstruction (all loop filters are off
15762 // whenever `allow_intrabc`, frame.rs:194/210/252/272) at the full-pel16001 // whenever `allow_intrabc`, frame.rs:194/210/252/272) at the full-pel
@@ -15768,19 +16007,19 @@ fn decode_block(
15768 let mut yb = vec![0u16; side * side];16007 let mut yb = vec![0u16; side * side];
15769 mc::predict_with_filter(16008 mc::predict_with_filter(
15770 &y.data, y.width, y.true_width, y.true_height,16009 &y.data, y.width, y.true_width, y.true_height,
15771- mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),16010+ mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),
15772 side, side, mc::InterpFilterKind::Bilinear, &mut yb, fctx,16011 side, side, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
15773 );16012 );
15774 let mut ub = vec![0u16; chroma_side * chroma_side];16013 let mut ub = vec![0u16; chroma_side * chroma_side];
15775 mc::predict_with_filter(16014 mc::predict_with_filter(
15776 &u.data, u.width, u.true_width, u.true_height,16015 &u.data, u.width, u.true_width, u.true_height,
15777- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),16016+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
15778 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, fctx,16017 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
15779 );16018 );
15780 let mut vb = vec![0u16; chroma_side * chroma_side];16019 let mut vb = vec![0u16; chroma_side * chroma_side];
15781 mc::predict_with_filter(16020 mc::predict_with_filter(
15782 &v.data, v.width, v.true_width, v.true_height,16021 &v.data, v.width, v.true_width, v.true_height,
15783- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),16022+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
15784 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, fctx,16023 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
15785 );16024 );
15786 (yb, ub, vb)16025 (yb, ub, vb)
@@ -15929,7 +16168,7 @@ fn decode_block(
15929 let cn = (chroma_side / chroma_tx).max(1);16168 let cn = (chroma_side / chroma_tx).max(1);
15930 for cu_row in 0..cn {16169 for cu_row in 0..cn {
15931 for cu_col in 0..cn {16170 for cu_col in 0..cn {
15932- let luma_span = chroma_tx * 2;16171+ let luma_span = chroma_tx << ss_x(fctx);
15933 let cu_r = if cn == 1 {16172 let cu_r = if cn == 1 {
15934 reach16173 reach
15935 } else {16174 } else {
@@ -16015,64 +16254,145 @@ fn decode_block(
16015 if intrabc_dv.is_some() {16254 if intrabc_dv.is_some() {
16016 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));16255 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));
16017 }16256 }
16018- if let Some((ub, _)) = &palette_uv_bufs {16257+ // lane-av1-444: this arm is one luma TU (`logical_tx == side`), including
16019- set_palette_pred(ub.clone(), fctx);16258+ // the 64x64 case whose coefficient grid is 32. At 4:4:4 the chroma plane
16020- }16259+ // is the same size as luma and `av1_get_max_uv_txsize` caps it at
16021- let u_grid = read_plane(16260+ // TX_32X32, so a 64x64 block codes four chroma units, plane-major
16022- dec,16261+ // (every U, then every V) — the same loop the multi-TU arm runs.
16023- cdfs,16262+ // At 4:2:0 `chroma_side == chroma_tx`, so it stays one read.
16024- chroma_set,16263+ let cn = (chroma_side / chroma_tx).max(1);
16025- scans.1,16264+ let (u_grid, v_grid, chroma_units) = if cn == 1 {
16026- 1,16265+ if let Some((ub, _)) = &palette_uv_bufs {
16027- around[1],16266+ set_palette_pred(ub.clone(), fctx);
16028- mode,16267+ }
16029- uv_predict_mode,16268+ let u_grid = read_plane(
16030- angle_delta_uv,16269+ dec,
16031- reach,16270+ cdfs,
16032- u,16271+ chroma_set,
16033- cpx,16272+ scans.1,
16034- cpy,16273+ 1,
16035- chroma_side,16274+ around[1],
16036- chroma_tx,16275+ mode,
16037- base_q_idx,16276+ uv_predict_mode,
16038- alpha.zip(ac).map(|((au, _), ac)| (au, ac)),16277+ angle_delta_uv,
16039- None,16278+ reach,
16040- None,16279+ u,
16041- smooth_neighbor_uv, fctx,16280+ cpx,
16042- )?;16281+ cpy,
16043- if crate::envflags::env_flag!("EC_AV1_TRACE") {16282+ chroma_side,
16044- eprintln!(16283+ chroma_tx,
16045- "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",16284+ base_q_idx,
16046- &u.data[cpy * u.width + cpx..][..chroma_side]16285+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
16047- );16286+ None,
16048- }16287+ None,
16049- if let Some((_, vb)) = &palette_uv_bufs {16288+ smooth_neighbor_uv, fctx,
16050- set_palette_pred(vb.clone(), fctx);16289+ )?;
16051- }16290+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
16052- let v_grid = read_plane(16291+ eprintln!(
16053- dec,16292+ "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",
16054- cdfs,16293+ &u.data[cpy * u.width + cpx..][..chroma_side]
16055- chroma_set,16294+ );
16056- scans.1,16295+ }
16057- 2,16296+ if let Some((_, vb)) = &palette_uv_bufs {
16058- around[2],16297+ set_palette_pred(vb.clone(), fctx);
16059- mode,16298+ }
16060- uv_predict_mode,16299+ let v_grid = read_plane(
16061- angle_delta_uv,16300+ dec,
16062- reach,16301+ cdfs,
16063- v,16302+ chroma_set,
16064- cpx,16303+ scans.1,
16065- cpy,16304+ 2,
16066- chroma_side,16305+ around[2],
16067- chroma_tx,16306+ mode,
16068- base_q_idx,16307+ uv_predict_mode,
16069- alpha.zip(ac).map(|((_, av), ac)| (av, ac)),16308+ angle_delta_uv,
16070- None,16309+ reach,
16071- None,16310+ v,
16072- smooth_neighbor_uv, fctx,16311+ cpx,
16073- )?;16312+ cpy,
16313+ chroma_side,
16314+ chroma_tx,
16315+ base_q_idx,
16316+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
16317+ None,
16318+ None,
16319+ smooth_neighbor_uv, fctx,
16320+ )?;
16321+ (u_grid, v_grid, Vec::new())
16322+ } else {
16323+ let chroma_ctx_offset = Some(3);
16324+ let mut u_pass: Vec<Grid> = Vec::new();
16325+ let mut units: Vec<((usize, usize), usize, Grid, Grid)> = Vec::new();
16326+ let mut last_grids = [Grid::Zero(0), Grid::Zero(0)];
16327+ for plane_pass in 1..=2usize {
16328+ let mut pass_idx = 0usize;
16329+ for cu_row in 0..cn {
16330+ for cu_col in 0..cn {
16331+ let luma_span = chroma_tx << ss_x(fctx);
16332+ let cu_mi = (
16333+ mi_r + cu_row * (luma_span / MI),
16334+ mi_c + cu_col * (luma_span / MI),
16335+ );
16336+ let cu_around = neighbours.around_mi(cu_mi, luma_span);
16337+ let cu_reach = tu_reach(
16338+ side,
16339+ side,
16340+ cu_col * luma_span,
16341+ cu_row * luma_span,
16342+ luma_span,
16343+ reach,
16344+ px,
16345+ py,
16346+ y.width,
16347+ y.height, fctx,
16348+ );
16349+ let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx);
16350+ if let Some((ub, vb)) = &palette_uv_bufs {
16351+ let pbuf = if plane_pass == 1 { ub } else { vb };
16352+ set_palette_pred(
16353+ palette_window(
16354+ pbuf, chroma_side, cu_col * chroma_tx, cu_row * chroma_tx,
16355+ chroma_tx, chroma_tx,
16356+ ),
16357+ fctx,
16358+ );
16359+ }
16360+ let buf: &mut PlaneBuf<'static> =
16361+ if plane_pass == 1 { &mut *u } else { &mut *v };
16362+ let cu_grid = read_plane(
16363+ dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode,
16364+ uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y,
16365+ chroma_tx, chroma_tx, base_q_idx,
16366+ alpha.zip(ac).map(|((au, av), ac)| {
16367+ (if plane_pass == 1 { au } else { av }, ac)
16368+ }),
16369+ None, chroma_ctx_offset, smooth_neighbor_uv, fctx,
16370+ )?;
16371+ hit!(CHROMA_SPLIT_TX_HITS);
16372+ // Immediately, so the next unit of this block reads this
16373+ // one's coefficient context. `record` below stamps one
16374+ // chroma state across the whole block; the replay after
16375+ // it puts the per-unit state back.
16376+ neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_pass, &cu_grid);
16377+ if plane_pass == 1 {
16378+ u_pass.push(cu_grid);
16379+ } else {
16380+ let u_grid = std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0));
16381+ units.push((cu_mi, luma_span, u_grid.clone(), cu_grid.clone()));
16382+ last_grids = [u_grid, cu_grid];
16383+ }
16384+ pass_idx += 1;
16385+ }
16386+ }
16387+ }
16388+ (last_grids[0].clone(), last_grids[1].clone(), units)
16389+ };
16074 fctx.intrabc_chroma_tx.with(|c| c.set(None));16390 fctx.intrabc_chroma_tx.with(|c| c.set(None));
16075 neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);16391 neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]);
16392+ for (cu_mi, luma_span, u_unit, v_unit) in &chroma_units {
16393+ neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 1, u_unit);
16394+ neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 2, v_unit);
16395+ }
16076 } else {16396 } else {
16077 // Several luma transform units, raster order (spec16397 // Several luma transform units, raster order (spec
16078 // `transform_block`'s loop): the block's resolved transform is16398 // `transform_block`'s loop): the block's resolved transform is
@@ -16237,7 +16557,7 @@ fn decode_block(
16237 // The chroma context arrays are indexed in LUMA mi, so this16557 // The chroma context arrays are indexed in LUMA mi, so this
16238 // unit's anchor is its own luma quadrant: `chroma_tx` chroma16558 // unit's anchor is its own luma quadrant: `chroma_tx` chroma
16239 // pixels span `2 * chroma_tx` luma ones.16559 // pixels span `2 * chroma_tx` luma ones.
16240- let luma_span = chroma_tx * 2;16560+ let luma_span = chroma_tx << ss_x(fctx);
16241 let cu_mi = (16561 let cu_mi = (
16242 mi_r + cu_row * (luma_span / MI),16562 mi_r + cu_row * (luma_span / MI),
16243 mi_c + cu_col * (luma_span / MI),16563 mi_c + cu_col * (luma_span / MI),
@@ -16494,7 +16814,7 @@ fn decode_block_128rect(
16494 if smooth_neighbor {16814 if smooth_neighbor {
16495 hit!(SMOOTH_LUMA_HITS);16815 hit!(SMOOTH_LUMA_HITS);
16496 }16816 }
16497- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);16817+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
16498 // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or16818 // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or
16499 // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc).16819 // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc).
16500 // lane-lossless128: a LOSSLESS frame codes no tx-size symbol at all --16820 // lane-lossless128: a LOSSLESS frame codes no tx-size symbol at all --
@@ -16545,8 +16865,8 @@ fn decode_block_128rect(
16545 TxbSet::Chroma3216865 TxbSet::Chroma32
16546 };16866 };
16547 let chroma_scan = default_scan(chroma_tx);16867 let chroma_scan = default_scan(chroma_tx);
16548- let (cpx, cpy) = (px / 2, py / 2);16868+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
16549- let (chroma_w, chroma_h) = (bw / 2, bh / 2);16869+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
16550 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);16870 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
16551 let (nch_x, nch_y) = (bw / 64, bh / 64);16871 let (nch_x, nch_y) = (bw / 64, bh / 64);
16552 // The frame's own mi grid (`av1_calc_mi_size`, 8-px aligned): libaom's16872 // The frame's own mi grid (`av1_calc_mi_size`, 8-px aligned): libaom's
@@ -16566,7 +16886,7 @@ fn decode_block_128rect(
16566 let mut units: Vec<(usize, (usize, usize), Grid)> = Vec::new();16886 let mut units: Vec<(usize, (usize, usize), Grid)> = Vec::new();
16567 // The chroma context arrays are indexed in LUMA mi; every chroma unit of16887 // The chroma context arrays are indexed in LUMA mi; every chroma unit of
16568 // every chunk shares this luma span (2 chroma pixels per luma unit).16888 // every chunk shares this luma span (2 chroma pixels per luma unit).
16569- let luma_span = chroma_tx * 2;16889+ let luma_span = chroma_tx << ss_x(fctx);
16570 for ch_row in 0..nch_y {16890 for ch_row in 0..nch_y {
16571 for ch_col in 0..nch_x {16891 for ch_col in 0..nch_x {
16572 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {16892 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {
@@ -16641,8 +16961,8 @@ fn decode_block_128rect(
16641 let cn = (32 / chroma_tx).max(1);16961 let cn = (32 / chroma_tx).max(1);
16642 // libaom's per-chunk `unit_width/height` (plane-mi units of the16962 // libaom's per-chunk `unit_width/height` (plane-mi units of the
16643 // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`.16963 // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`.
16644- let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> 1;16964+ let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> ss_x(fctx);
16645- let unit_h = ((ch_row + 1) * 16).min(max_h_mi) >> 1;16965+ let unit_h = ((ch_row + 1) * 16).min(max_h_mi) >> ss_y(fctx);
16646 let stepc = (chroma_tx / 4).max(1);16966 let stepc = (chroma_tx / 4).max(1);
16647 // `decode_token_recon_block` codes a mu chunk PLANE-MAJOR: every U16967 // `decode_token_recon_block` codes a mu chunk PLANE-MAJOR: every U
16648 // unit of the chunk, then every V unit. At one unit per plane per16968 // unit of the chunk, then every V unit. At one unit per plane per
@@ -16660,8 +16980,8 @@ fn decode_block_128rect(
16660 let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx;16980 let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx;
16661 let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx;16981 let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx;
16662 let cu_mi = (16982 let cu_mi = (
16663- mi_r + ch_row * 16 + ci_row * (chroma_tx / 2),16983+ mi_r + ch_row * 16 + ci_row * ((chroma_tx << ss_y(fctx)) / 4),
16664- mi_c + ch_col * 16 + ci_col * (chroma_tx / 2),16984+ mi_c + ch_col * 16 + ci_col * ((chroma_tx << ss_x(fctx)) / 4),
16665 );16985 );
16666 let cu_r = tu_reach(16986 let cu_r = tu_reach(
16667 bw,16987 bw,
@@ -16861,7 +17181,7 @@ fn decode_leaf8(
16861 // The `uv_mode` neighbours are mi-exact (`uv_mode_col`/`uv_mode_row`),17181 // The `uv_mode` neighbours are mi-exact (`uv_mode_col`/`uv_mode_row`),
16862 // with the coarse [`SUB`] slot as the fallback when no block recorded17182 // with the coarse [`SUB`] slot as the fallback when no block recorded
16863 // that exact mi cell.17183 // that exact mi cell.
16864- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);17184+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
16865 if smooth_neighbor {17185 if smooth_neighbor {
16866 hit!(SMOOTH_LUMA_HITS);17186 hit!(SMOOTH_LUMA_HITS);
16867 }17187 }
@@ -16976,7 +17296,15 @@ fn decode_leaf8(
16976 };17296 };
16977 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);17297 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
16978 let reach = Reach::of(8, px, py, y.width, y.height, fctx);17298 let reach = Reach::of(8, px, py, y.width, y.height, fctx);
16979- let (cpx, cpy) = (px / 2, py / 2);17299+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
17300+ // 4:4:4: this 8x8 block's chroma plane block is 8x8 (same scan as luma,
17301+ // `scans.0`). 4:2:0 stays the 4x4 unit this leaf was written for.
17302+ let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
17303+ let (csz, cset, cscan) = if chroma_444 {
17304+ (8usize, TxbSet::Chroma8, scans.0)
17305+ } else {
17306+ (4usize, TxbSet::Chroma4, scans.1)
17307+ };
16980 // spec 7.11.3.4 with `use_intrabc`, same as `decode_block`: predict from17308 // spec 7.11.3.4 with `use_intrabc`, same as `decode_block`: predict from
16981 // the CURRENT frame's own pre-loop-filter reconstruction (every loop17309 // the CURRENT frame's own pre-loop-filter reconstruction (every loop
16982 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at17310 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at
@@ -16986,19 +17314,19 @@ fn decode_leaf8(
16986 let mut yb = vec![0u16; 8 * 8];17314 let mut yb = vec![0u16; 8 * 8];
16987 mc::predict_with_filter(17315 mc::predict_with_filter(
16988 &y.data, y.width, y.true_width, y.true_height,17316 &y.data, y.width, y.true_width, y.true_height,
16989- mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),17317+ mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),
16990 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx,17318 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
16991 );17319 );
16992 let mut ub = vec![0u16; 4 * 4];17320 let mut ub = vec![0u16; 4 * 4];
16993 mc::predict_with_filter(17321 mc::predict_with_filter(
16994 &u.data, u.width, u.true_width, u.true_height,17322 &u.data, u.width, u.true_width, u.true_height,
16995- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),17323+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
16996 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,17324 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
16997 );17325 );
16998 let mut vb = vec![0u16; 4 * 4];17326 let mut vb = vec![0u16; 4 * 4];
16999 mc::predict_with_filter(17327 mc::predict_with_filter(
17000 &v.data, v.width, v.true_width, v.true_height,17328 &v.data, v.width, v.true_width, v.true_height,
17001- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),17329+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
17002 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,17330 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
17003 );17331 );
17004 (yb, ub, vb)17332 (yb, ub, vb)
@@ -17084,11 +17412,11 @@ fn decode_leaf8(
17084 push_intra(1, 17412 push_intra(1,
17085 cpx,17413 cpx,
17086 cpy,17414 cpy,
17087- 4,17415+ csz,
17088 uv_predict_mode,17416 uv_predict_mode,
17089 angle_delta_uv,17417 angle_delta_uv,
17090 reach,17418 reach,
17091- &ZERO_RESIDUAL[..16],17419+ &ZERO_RESIDUAL[..csz * csz],
17092 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),17420 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
17093 None,17421 None,
17094 smooth_neighbor_uv, fctx,17422 smooth_neighbor_uv, fctx,
@@ -17101,18 +17429,18 @@ fn decode_leaf8(
17101 push_intra(2, 17429 push_intra(2,
17102 cpx,17430 cpx,
17103 cpy,17431 cpy,
17104- 4,17432+ csz,
17105 uv_predict_mode,17433 uv_predict_mode,
17106 angle_delta_uv,17434 angle_delta_uv,
17107 reach,17435 reach,
17108- &ZERO_RESIDUAL[..16],17436+ &ZERO_RESIDUAL[..csz * csz],
17109 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),17437 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
17110 None,17438 None,
17111 smooth_neighbor_uv, fctx,17439 smooth_neighbor_uv, fctx,
17112 );17440 );
17113 luma_grid = Grid::Zero(64);17441 luma_grid = Grid::Zero(64);
17114- u_grid = Grid::Zero(16);17442+ u_grid = Grid::Zero(csz * csz);
17115- v_grid = Grid::Zero(16);17443+ v_grid = Grid::Zero(csz * csz);
17116 } else if resolved != 4 {17444 } else if resolved != 4 {
17117 let around = neighbours.around_mi(leaf_mi, 8);17445 let around = neighbours.around_mi(leaf_mi, 8);
17118 if let Some(buf) = &palette_y_buf {17446 if let Some(buf) = &palette_y_buf {
@@ -17161,8 +17489,8 @@ fn decode_leaf8(
17161 u_grid = read_plane(17489 u_grid = read_plane(
17162 dec,17490 dec,
17163 cdfs,17491 cdfs,
17164- TxbSet::Chroma4,17492+ cset,
17165- scans.1,17493+ cscan,
17166 1,17494 1,
17167 around[1],17495 around[1],
17168 mode,17496 mode,
@@ -17172,8 +17500,8 @@ fn decode_leaf8(
17172 u,17500 u,
17173 cpx,17501 cpx,
17174 cpy,17502 cpy,
17175- 4,17503+ csz,
17176- TX4,17504+ csz,
17177 base_q_idx,17505 base_q_idx,
17178 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),17506 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
17179 None,17507 None,
@@ -17188,8 +17516,8 @@ fn decode_leaf8(
17188 v_grid = read_plane(17516 v_grid = read_plane(
17189 dec,17517 dec,
17190 cdfs,17518 cdfs,
17191- TxbSet::Chroma4,17519+ cset,
17192- scans.1,17520+ cscan,
17193 2,17521 2,
17194 around[2],17522 around[2],
17195 mode,17523 mode,
@@ -17199,8 +17527,8 @@ fn decode_leaf8(
17199 v,17527 v,
17200 cpx,17528 cpx,
17201 cpy,17529 cpy,
17202- 4,17530+ csz,
17203- TX4,17531+ csz,
17204 base_q_idx,17532 base_q_idx,
17205 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),17533 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
17206 None,17534 None,
@@ -17300,8 +17628,8 @@ fn decode_leaf8(
17300 u_grid = read_plane(17628 u_grid = read_plane(
17301 dec,17629 dec,
17302 cdfs,17630 cdfs,
17303- TxbSet::Chroma4,17631+ cset,
17304- scans.1,17632+ cscan,
17305 1,17633 1,
17306 chroma_around[1],17634 chroma_around[1],
17307 mode,17635 mode,
@@ -17311,8 +17639,8 @@ fn decode_leaf8(
17311 u,17639 u,
17312 cpx,17640 cpx,
17313 cpy,17641 cpy,
17314- 4,17642+ csz,
17315- TX4,17643+ csz,
17316 base_q_idx,17644 base_q_idx,
17317 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),17645 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
17318 None,17646 None,
@@ -17325,8 +17653,8 @@ fn decode_leaf8(
17325 v_grid = read_plane(17653 v_grid = read_plane(
17326 dec,17654 dec,
17327 cdfs,17655 cdfs,
17328- TxbSet::Chroma4,17656+ cset,
17329- scans.1,17657+ cscan,
17330 2,17658 2,
17331 chroma_around[2],17659 chroma_around[2],
17332 mode,17660 mode,
@@ -17336,8 +17664,8 @@ fn decode_leaf8(
17336 v,17664 v,
17337 cpx,17665 cpx,
17338 cpy,17666 cpy,
17339- 4,17667+ csz,
17340- TX4,17668+ csz,
17341 base_q_idx,17669 base_q_idx,
17342 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),17670 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
17343 None,17671 None,
@@ -17572,6 +17900,194 @@ fn read_intra_mode_sub8(
17572 }17900 }
17573 Ok((skip, mode, angle_delta_y, chroma, filter_intra, None))17901 Ok((skip, mode, angle_delta_y, chroma, filter_intra, None))
17574 }17902 }
17903+/// 4:4:4 sub-8x8 key-frame leaf chroma (lane-av1-444). At subsampling 0/0
17904+/// `is_chroma_reference` (av1_common_int.h:1459) is unconditional, so EVERY
17905+/// 4x4 / 4x8 / 8x4 leaf codes its own full-resolution chroma unit right
17906+/// after its own luma (`read_intra_mode_sub8` already read this leaf's own
17907+/// `uv_mode`), not the one shared 4x4 unit [`decode_leaf_split4`] /
17908+/// [`decode_leaf_rect8`]'s group tails decode at 4:2:0. Mirrors those tails
17909+/// arm for arm at leaf scale: a skipped leaf keeps its CfL contribution, an
17910+/// intrabc leaf predicts a frame copy at its DV with the luma `tx_type`
17911+/// inherited through [`INTRABC_CHROMA_TX`] (the caller arms it right after
17912+/// the luma read). The chroma position, reach and entropy-context span are
17913+/// the leaf's own (ss 0/0); the 4x8/8x4 unit reads the same
17914+/// `ChromaRect8x4` tables [`decode_rect_split`] proves for that shape.
17915+/// Records the leaf's own `uv_mode` map entry and chroma above/left state,
17916+/// and returns the (u, v) grids for the caller's coarse slots.
17917+#[allow(clippy::too_many_arguments)]
17918+fn sub8_leaf_chroma444(
17919+ dec: &mut SymbolDecoder,
17920+ cdfs: &mut Cdfs,
17921+ neighbours: &mut Neighbours,
17922+ lmi: (usize, usize),
17923+ bw: usize,
17924+ bh: usize,
17925+ uv_mode: usize,
17926+ alpha: Option<(i32, i32)>,
17927+ skip: bool,
17928+ intrabc_dv: Option<(i32, i32)>,
17929+ y: &PlaneBuf<'static>,
17930+ u: &mut PlaneBuf<'static>,
17931+ v: &mut PlaneBuf<'static>,
17932+ scan4: &[u16],
17933+ base_q_idx: u8,
17934+ smooth_neighbor_uv: bool,
17935+ fctx: &crate::decode::FrameCtx,
17936+) -> Result<(Grid, Grid)> {
17937+ let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
17938+ let (w_mi, h_mi) = (bw / MI, bh / MI);
17939+ neighbours.record_uv_mode_mi(lmi.0, lmi.1, w_mi, h_mi, uv_predict_mode);
17940+ let (px, py) = (lmi.1 * MI, lmi.0 * MI);
17941+ let square = (bw, bh) == (4, 4);
17942+ // `Reach::of_rect` has no 4x4 table (`rect_reach_tables` starts at 4x8);
17943+ // the square unit takes the leaf's own `Reach::of`, as its luma does.
17944+ let reach = if square {
17945+ Reach::of(4, px, py, y.width, y.height, fctx)
17946+ } else {
17947+ Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx)
17948+ };
17949+ let grids = if skip {
17950+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
17951+ if square {
17952+ push_intra(1, px, py, 4, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
17953+ push_intra(2, px, py, 4, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
17954+ } else {
17955+ push_intra_rect(1, px, py, bw, bh, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..bw * bh], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
17956+ push_intra_rect(2, px, py, bw, bh, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..bw * bh], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
17957+ }
17958+ // The same arm-without-clear route the 4:2:0 tails count: a skipped
17959+ // leaf reads no coefficient, so an armed intrabc slot is dropped.
17960+ if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
17961+ hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
17962+ fctx.intrabc_chroma_tx.with(|c| c.set(None));
17963+ }
17964+ (Grid::Zero(bw * bh), Grid::Zero(bw * bh))
17965+ } else if let Some(dv) = intrabc_dv {
17966+ // Frame copy at the DV; the residual still reads the ordinary chroma
17967+ // tables with the inherited luma `tx_type` (see the 4:2:0 tails).
17968+ let mut ub = vec![0u16; bw * bh];
17969+ mc::predict_with_filter(
17970+ &u.data, u.width, u.true_width, u.true_height,
17971+ mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0),
17972+ bw, bh, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
17973+ );
17974+ let mut vb = vec![0u16; bw * bh];
17975+ mc::predict_with_filter(
17976+ &v.data, v.width, v.true_width, v.true_height,
17977+ mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0),
17978+ bw, bh, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
17979+ );
17980+ let around = neighbours.around_mi_rect(lmi, bw, bh);
17981+ let pair = if square {
17982+ set_palette_pred(ub, fctx);
17983+ let ug = read_plane(
17984+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], DC_PRED, DC_PRED,
17985+ 0, reach, u, px, py, 4, TX4, base_q_idx,
17986+ None, None, None, smooth_neighbor_uv, fctx,
17987+ )?;
17988+ set_palette_pred(vb, fctx);
17989+ let vg = read_plane(
17990+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], DC_PRED, DC_PRED,
17991+ 0, reach, v, px, py, 4, TX4, base_q_idx,
17992+ None, None, None, smooth_neighbor_uv, fctx,
17993+ )?;
17994+ (ug, vg)
17995+ } else {
17996+ let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };
17997+ let default_tx =
17998+ fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct);
17999+ let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh));
18000+ for (plane_idx, buf) in [(1usize, ub), (2usize, vb)] {
18001+ let skip_ctx =
18002+ usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
18003+ let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, DC_PRED);
18004+ let (levels, tx_type) = read_coeffs_rect(
18005+ dec, &mut coding, scan, bw, bh, skip_ctx,
18006+ dc_sign_ctx(around[plane_idx].2), default_tx,
18007+ )?;
18008+ let residual = dequant_and_inverse_typed_wh(
18009+ &levels, bw, bh, crate::decode::bit_depth(fctx), block_q_idx(fctx),
18010+ plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1,
18011+ tx_type,
18012+ );
18013+ set_palette_pred(buf, fctx);
18014+ push_intra_rect(
18015+ plane_idx, px, py, bw, bh, DC_PRED, 0, reach, &residual,
18016+ None, None, smooth_neighbor_uv, fctx,
18017+ );
18018+ if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; }
18019+ }
18020+ out
18021+ };
18022+ fctx.intrabc_chroma_tx.with(|c| c.set(None));
18023+ pair
18024+ } else {
18025+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
18026+ let around = neighbours.around_mi_rect(lmi, bw, bh);
18027+ if square {
18028+ let ug = read_plane(
18029+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], uv_mode, uv_predict_mode,
18030+ 0, reach, u, px, py, 4, TX4, base_q_idx,
18031+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
18032+ )?;
18033+ let vg = read_plane(
18034+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], uv_mode, uv_predict_mode,
18035+ 0, reach, v, px, py, 4, TX4, base_q_idx,
18036+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
18037+ )?;
18038+ (ug, vg)
18039+ } else {
18040+ // `av1_get_max_uv_txsize(BLOCK_4X8/8X4)` at ss 0/0 is the rect
18041+ // transform itself; its `tx_type` is mode-derived with the
18042+ // <32 set (`decode_rect_split`'s own rule for this shape).
18043+ let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };
18044+ let default_tx = default_intra_tx_type(uv_predict_mode as u8);
18045+ let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh));
18046+ for plane_idx in 1..=2usize {
18047+ let skip_ctx =
18048+ usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
18049+ let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
18050+ let (levels, tx_type) = read_coeffs_rect(
18051+ dec, &mut coding, scan, bw, bh, skip_ctx,
18052+ dc_sign_ctx(around[plane_idx].2), default_tx,
18053+ )?;
18054+ let residual = dequant_and_inverse_typed_wh(
18055+ &levels, bw, bh, crate::decode::bit_depth(fctx), block_q_idx(fctx),
18056+ plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1,
18057+ tx_type,
18058+ );
18059+ let cfl = alpha
18060+ .zip(ac)
18061+ .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac));
18062+ push_intra_rect(
18063+ plane_idx, px, py, bw, bh, uv_predict_mode, 0, reach, &residual,
18064+ cfl, None, smooth_neighbor_uv, fctx,
18065+ );
18066+ if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; }
18067+ }
18068+ out
18069+ }
18070+ };
18071+ // libaom `av1_set_entropy_contexts` stamps above/left PER TRANSFORM UNIT:
18072+ // the leaf's own chroma span, not the 8x8 group's.
18073+ let (u_grid, v_grid) = grids;
18074+ let u_state = neighbour_state(&u_grid);
18075+ let v_state = neighbour_state(&v_grid);
18076+ for cell in 0..h_mi {
18077+ if lmi.0 + cell < neighbours.mi_rows {
18078+ neighbours.left[lmi.0 + cell][1] = u_state;
18079+ neighbours.left[lmi.0 + cell][2] = v_state;
18080+ }
18081+ }
18082+ for cell in 0..w_mi {
18083+ if lmi.1 + cell < neighbours.mi_cols {
18084+ neighbours.above[lmi.1 + cell][1] = u_state;
18085+ neighbours.above[lmi.1 + cell][2] = v_state;
18086+ }
18087+ }
18088+ Ok((u_grid, v_grid))
18089+}
18090+
17575 18091
17576 /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves18092 /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves
17577 /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s18093 /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s
@@ -17617,7 +18133,7 @@ fn decode_leaf_split4(
17617 }18133 }
17618 // See `decode_leaf8`'s own `smooth_neighbor_uv`: the chroma edge-filter18134 // See `decode_leaf8`'s own `smooth_neighbor_uv`: the chroma edge-filter
17619 // type is the chroma neighbours' `uv_mode`, mi-exact where recorded.18135 // type is the chroma neighbours' `uv_mode`, mi-exact where recorded.
17620- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);18136+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
17621 let mut leaf_modes = [0usize; 4];18137 let mut leaf_modes = [0usize; 4];
17622 let mut leaf_skips = [false; 4];18138 let mut leaf_skips = [false; 4];
17623 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;18139 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;
@@ -17625,6 +18141,14 @@ fn decode_leaf_split4(
17625 // leaf is an intrabc block -- its prediction/reconstruction below is a18141 // leaf is an intrabc block -- its prediction/reconstruction below is a
17626 // frame copy at this DV, not an intra one.18142 // frame copy at this DV, not an intra one.
17627 let mut last_intrabc: Option<(i32, i32)> = None;18143 let mut last_intrabc: Option<(i32, i32)> = None;
18144+ // 4:4:4 (lane-av1-444): `is_chroma_reference` (av1_common_int.h:1459) is
18145+ // unconditional at subsampling 0/0, so EVERY 4x4 leaf reads its own
18146+ // `uv_mode` and codes its own full-resolution 4x4 chroma unit right
18147+ // after its luma -- there is no shared group unit at all.
18148+ let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
18149+ // The last leaf's own `uv_predict_mode`, for the coarse above/left slots
18150+ // the 4:2:0 tail fills from the group's single unit.
18151+ let mut last_uv444 = DC_PRED;
17628 for i in 0..4usize {18152 for i in 0..4usize {
17629 let (dr, dc) = (i / 2, i % 2);18153 let (dr, dc) = (i / 2, i % 2);
17630 let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc);18154 let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc);
@@ -17642,7 +18166,7 @@ fn decode_leaf_split4(
17642 } else {18166 } else {
17643 leaf_modes[i - 1]18167 leaf_modes[i - 1]
17644 };18168 };
17645- let has_chroma = i == 3;18169+ let has_chroma = chroma_444 || i == 3;
17646 let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1);18170 let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1);
17647 let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8(18171 let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8(
17648 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,18172 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,
@@ -17679,7 +18203,7 @@ fn decode_leaf_split4(
17679 let mut yb = vec![0u16; 16];18203 let mut yb = vec![0u16; 16];
17680 mc::predict_with_filter(18204 mc::predict_with_filter(
17681 &y.data, y.width, y.true_width, y.true_height,18205 &y.data, y.width, y.true_width, y.true_height,
17682- mv_to_q4(px, dv.1, true), mv_to_q4(py, dv.0, true),18206+ mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0),
17683 4, 4, mc::InterpFilterKind::Bilinear, &mut yb, fctx,18207 4, 4, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
17684 );18208 );
17685 set_palette_pred(yb.clone(), fctx);18209 set_palette_pred(yb.clone(), fctx);
@@ -17716,24 +18240,35 @@ fn decode_leaf_split4(
17716 neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx);18240 neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx);
17717 record_intrabc_mi(lmi.0, lmi.1, 1, Some(dv), neighbours, fctx);18241 record_intrabc_mi(lmi.0, lmi.1, 1, Some(dv), neighbours, fctx);
17718 if has_chroma {18242 if has_chroma {
17719- last_uv = Some((DC_PRED, 0, None));
17720 // An intrabc block is an INTER block for `av1_get_tx_type`, so18243 // An intrabc block is an INTER block for `av1_get_tx_type`, so
17721- // the group's chroma inherits the LUMA's coded transform type18244+ // the chroma inherits the LUMA's coded transform type
17722 // (`xd->tx_type_map` at the co-located luma position) -- the18245 // (`xd->tx_type_map` at the co-located luma position) -- the
17723 // luma `read_plane` above just set [`LUMA_TX_TYPE`]. Armed for18246 // luma `read_plane` above just set [`LUMA_TX_TYPE`]. Armed for
17724- // exactly this group's two chroma reads.18247+ // exactly this leaf's two chroma reads.
17725 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));18248 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));
17726- // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE18249+ if chroma_444 {
17727- // leaf's own block -- libaom codes one chroma unit under the18250+ // lane-av1-444: this leaf codes its OWN 4x4 chroma unit
17728- // last sub-block only (`is_chroma_reference`), so its prediction18251+ // right here (frame copy at the DV); no group tail.
17729- // is that leaf's `uv_mode` (CfL alpha and all) unless THAT leaf18252+ sub8_leaf_chroma444(
17730- // is the intrabc one. Arming this from a non-chroma-reference18253+ dec, cdfs, neighbours, lmi, 4, 4, DC_PRED, None, skip,
17731- // leaf's DV made `warped.obu`'s 8x8 group at mi(40,62) copy18254+ Some(dv), y, u, v, scan4, base_q_idx,
17732- // frame bytes at mi(41,62)'s vector where aomdec predicts18255+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
17733- // `uv_mode=UV_CFL_PRED`: luma stayed byte-exact and only chroma18256+ )?;
17734- // moved (class chroma-keyed-at-a-non-chroma-leaf). Mirrors18257+ last_uv444 = DC_PRED;
17735- // [`decode_leaf_rect8`]'s own placement.18258+ } else {
17736- last_intrabc = Some(dv);18259+ last_uv = Some((DC_PRED, 0, None));
18260+ // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE
18261+ // leaf's own block -- libaom codes one chroma unit under the
18262+ // last sub-block only (`is_chroma_reference`), so its prediction
18263+ // is that leaf's `uv_mode` (CfL alpha and all) unless THAT leaf
18264+ // is the intrabc one. Arming this from a non-chroma-reference
18265+ // leaf's DV made `warped.obu`'s 8x8 group at mi(40,62) copy
18266+ // frame bytes at mi(41,62)'s vector where aomdec predicts
18267+ // `uv_mode=UV_CFL_PRED`: luma stayed byte-exact and only chroma
18268+ // moved (class chroma-keyed-at-a-non-chroma-leaf). Mirrors
18269+ // [`decode_leaf_rect8`]'s own placement.
18270+ last_intrabc = Some(dv);
18271+ }
17737 }18272 }
17738 continue;18273 continue;
17739 }18274 }
@@ -17774,16 +18309,37 @@ fn decode_leaf_split4(
17774 neighbours.fill_skip_grid(lmi, 1, skip);18309 neighbours.fill_skip_grid(lmi, 1, skip);
17775 neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx);18310 neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx);
17776 if has_chroma {18311 if has_chroma {
17777- last_uv = chroma;18312+ if chroma_444 {
18313+ // lane-av1-444: the leaf's own 4x4 chroma unit, coded right
18314+ // after its luma (no shared group unit at ss 0/0).
18315+ let (uv_mode, _, alpha) =
18316+ chroma.expect("4:4:4 reads uv_mode on every leaf");
18317+ sub8_leaf_chroma444(
18318+ dec, cdfs, neighbours, lmi, 4, 4, uv_mode, alpha, skip,
18319+ None, y, u, v, scan4, base_q_idx,
18320+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
18321+ )?;
18322+ last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
18323+ } else {
18324+ last_uv = chroma;
18325+ }
17778 }18326 }
17779 }18327 }
17780 // lane-av1mono: as [`decode_leaf_rect8`] -- a monochrome frame has no18328 // lane-av1mono: as [`decode_leaf_rect8`] -- a monochrome frame has no
17781 // chroma to reconstruct and no uv_mode was read.18329 // chroma to reconstruct and no uv_mode was read.
17782 let (u_grid, v_grid): (Grid, Grid) = if mono(fctx) {18330 let (u_grid, v_grid): (Grid, Grid) = if mono(fctx) {
17783 (Grid::Zero(16), Grid::Zero(16))18331 (Grid::Zero(16), Grid::Zero(16))
18332+ } else if chroma_444 {
18333+ // lane-av1-444: every leaf coded and reconstructed its own chroma in
18334+ // the loop above ([`sub8_leaf_chroma444`] stamped the mi-exact maps
18335+ // and per-leaf entropy state); only the coarse slots remain, filled
18336+ // from the bottom-right leaf like the 4:2:0 tail's single unit.
18337+ neighbours.above_uv_mode[c] = last_uv444;
18338+ neighbours.left_uv_mode[r] = last_uv444;
18339+ (Grid::Zero(16), Grid::Zero(16))
17784 } else {18340 } else {
17785 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);18341 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
17786- let (cpx, cpy) = (gpx / 2, gpy / 2);18342+ let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
17787 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);18343 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
17788 let (uv_mode, angle_delta_uv, alpha) =18344 let (uv_mode, angle_delta_uv, alpha) =
17789 last_uv.expect("i==3 always sets has_chroma, so chroma is always Some");18345 last_uv.expect("i==3 always sets has_chroma, so chroma is always Some");
@@ -17828,13 +18384,13 @@ fn decode_leaf_split4(
17828 let mut ub = vec![0u16; 16];18384 let mut ub = vec![0u16; 16];
17829 mc::predict_with_filter(18385 mc::predict_with_filter(
17830 &u.data, u.width, u.true_width, u.true_height,18386 &u.data, u.width, u.true_width, u.true_height,
17831- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),18387+ mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)),
17832 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,18388 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
17833 );18389 );
17834 let mut vb = vec![0u16; 16];18390 let mut vb = vec![0u16; 16];
17835 mc::predict_with_filter(18391 mc::predict_with_filter(
17836 &v.data, v.width, v.true_width, v.true_height,18392 &v.data, v.width, v.true_width, v.true_height,
17837- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),18393+ mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)),
17838 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,18394 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
17839 );18395 );
17840 let chroma_around = neighbours.around_mi(leaf_mi, 8);18396 let chroma_around = neighbours.around_mi(leaf_mi, 8);
@@ -17890,19 +18446,23 @@ fn decode_leaf_split4(
17890 neighbours.left_side_mi[leaf_mi.0 + cell] = 4;18446 neighbours.left_side_mi[leaf_mi.0 + cell] = 4;
17891 neighbours.above_side_mi[leaf_mi.1 + cell] = 4;18447 neighbours.above_side_mi[leaf_mi.1 + cell] = 4;
17892 }18448 }
17893- let round_up_even = |n: usize| n.div_ceil(2) * 2;18449+ // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each
17894- let bound_h = round_up_even(neighbours.mi_rows);18450+ // leaf's own span as it decoded; these placeholder grids carry no state.
17895- let bound_w = round_up_even(neighbours.mi_cols);18451+ if !chroma_444 {
17896- let u_state = neighbour_state(&u_grid);18452+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
17897- let v_state = neighbour_state(&v_grid);18453+ let bound_h = round_up_even(neighbours.mi_rows);
17898- for cell in 0..side_mi {18454+ let bound_w = round_up_even(neighbours.mi_cols);
17899- if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) {18455+ let u_state = neighbour_state(&u_grid);
17900- neighbours.left[leaf_mi.0 + cell][1] = u_state;18456+ let v_state = neighbour_state(&v_grid);
17901- neighbours.left[leaf_mi.0 + cell][2] = v_state;18457+ for cell in 0..side_mi {
17902- }18458+ if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) {
17903- if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) {18459+ neighbours.left[leaf_mi.0 + cell][1] = u_state;
17904- neighbours.above[leaf_mi.1 + cell][1] = u_state;18460+ neighbours.left[leaf_mi.0 + cell][2] = v_state;
17905- neighbours.above[leaf_mi.1 + cell][2] = v_state;18461+ }
18462+ if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) {
18463+ neighbours.above[leaf_mi.1 + cell][1] = u_state;
18464+ neighbours.above[leaf_mi.1 + cell][2] = v_state;
18465+ }
17906 }18466 }
17907 }18467 }
17908 // lane-dkey: a sub-8x8 leaf can never use palette (`av1_allow_palette`18468 // lane-dkey: a sub-8x8 leaf can never use palette (`av1_allow_palette`
@@ -17972,7 +18532,7 @@ fn decode_leaf_rect8(
17972 // lane-modectx r1: availability-correct fallback pair (see18532 // lane-modectx r1: availability-correct fallback pair (see
17973 // `modes_above_left`), not the raw coarse bands.18533 // `modes_above_left`), not the raw coarse bands.
17974 let (above_mode, left_mode) = neighbours.modes_above_left(r, c);18534 let (above_mode, left_mode) = neighbours.modes_above_left(r, c);
17975- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);18535+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
17976 let (bw, bh) = if vert { (4, 8) } else { (8, 4) };18536 let (bw, bh) = if vert { (4, 8) } else { (8, 4) };
17977 let (w_mi, h_mi) = (bw / MI, bh / MI);18537 let (w_mi, h_mi) = (bw / MI, bh / MI);
17978 let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 };18538 let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 };
@@ -17981,6 +18541,11 @@ fn decode_leaf_rect8(
17981 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;18541 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;
17982 // lane-av1txr: as [`decode_leaf_split4`]'s own `last_intrabc`.18542 // lane-av1txr: as [`decode_leaf_split4`]'s own `last_intrabc`.
17983 let mut last_intrabc: Option<(i32, i32)> = None;18543 let mut last_intrabc: Option<(i32, i32)> = None;
18544+ // 4:4:4 (lane-av1-444): as [`decode_leaf_split4`] -- at subsampling 0/0
18545+ // EVERY 4x8/8x4 leaf reads its own `uv_mode` and codes its own
18546+ // full-resolution rect chroma unit right after its luma.
18547+ let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
18548+ let mut last_uv444 = DC_PRED;
17984 for i in 0..2usize {18549 for i in 0..2usize {
17985 let lmi = if vert {18550 let lmi = if vert {
17986 (leaf_mi.0, leaf_mi.1 + i)18551 (leaf_mi.0, leaf_mi.1 + i)
@@ -17999,7 +18564,7 @@ fn decode_leaf_rect8(
17999 } else {18564 } else {
18000 neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode)18565 neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode)
18001 };18566 };
18002- let has_chroma = i == 1;18567+ let has_chroma = chroma_444 || i == 1;
18003 let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1);18568 let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1);
18004 let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8(18569 let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8(
18005 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,18570 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,
@@ -18080,7 +18645,7 @@ fn decode_leaf_rect8(
18080 let mut yb = vec![0u16; tw * th];18645 let mut yb = vec![0u16; tw * th];
18081 mc::predict_with_filter(18646 mc::predict_with_filter(
18082 &y.data, y.width, y.true_width, y.true_height,18647 &y.data, y.width, y.true_width, y.true_height,
18083- mv_to_q4(tu_px, dv.1, true), mv_to_q4(tu_py, dv.0, true),18648+ mv_to_q4(tu_px, dv.1, 0), mv_to_q4(tu_py, dv.0, 0),
18084 tw, th, mc::InterpFilterKind::Bilinear, &mut yb, fctx,18649 tw, th, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
18085 );18650 );
18086 set_palette_pred(yb, fctx);18651 set_palette_pred(yb, fctx);
@@ -18173,11 +18738,22 @@ fn decode_leaf_rect8(
18173 // 4x8/8x4 leaf needs its true `w_mi`x`h_mi` (lane-av1txr).18738 // 4x8/8x4 leaf needs its true `w_mi`x`h_mi` (lane-av1txr).
18174 record_intrabc_mi_rect(lmi.0, lmi.1, w_mi, h_mi, Some(dv), neighbours, fctx);18739 record_intrabc_mi_rect(lmi.0, lmi.1, w_mi, h_mi, Some(dv), neighbours, fctx);
18175 if has_chroma {18740 if has_chroma {
18176- last_uv = Some((DC_PRED, 0, None));
18177- last_intrabc = Some(dv);
18178 // See [`decode_leaf_split4`]: an intrabc block's chroma18741 // See [`decode_leaf_split4`]: an intrabc block's chroma
18179 // inherits the luma transform type.18742 // inherits the luma transform type.
18180 fctx.intrabc_chroma_tx.with(|c| c.set(Some(chroma_tx)));18743 fctx.intrabc_chroma_tx.with(|c| c.set(Some(chroma_tx)));
18744+ if chroma_444 {
18745+ // lane-av1-444: this leaf codes its OWN rect chroma unit
18746+ // right here (frame copy at the DV); no group tail.
18747+ sub8_leaf_chroma444(
18748+ dec, cdfs, neighbours, lmi, bw, bh, DC_PRED, None, skip,
18749+ Some(dv), y, u, v, scan4, base_q_idx,
18750+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
18751+ )?;
18752+ last_uv444 = DC_PRED;
18753+ } else {
18754+ last_uv = Some((DC_PRED, 0, None));
18755+ last_intrabc = Some(dv);
18756+ }
18181 }18757 }
18182 continue;18758 continue;
18183 }18759 }
@@ -18314,7 +18890,20 @@ fn decode_leaf_rect8(
18314 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);18890 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
18315 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, 4, 4, 0, fctx);18891 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, 4, 4, 0, fctx);
18316 if has_chroma {18892 if has_chroma {
18317- last_uv = chroma;18893+ if chroma_444 {
18894+ // lane-av1-444: the leaf's own rect chroma unit after its
18895+ // split luma (no shared group unit at ss 0/0).
18896+ let (uv_mode, _, alpha) =
18897+ chroma.expect("4:4:4 reads uv_mode on every leaf");
18898+ sub8_leaf_chroma444(
18899+ dec, cdfs, neighbours, lmi, bw, bh, uv_mode, alpha, skip,
18900+ None, y, u, v, scan4, base_q_idx,
18901+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
18902+ )?;
18903+ last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
18904+ } else {
18905+ last_uv = chroma;
18906+ }
18318 }18907 }
18319 continue;18908 continue;
18320 }18909 }
@@ -18389,7 +18978,20 @@ fn decode_leaf_rect8(
18389 let (tx_w, tx_h) = if split { (4, 4) } else { (bw as u8, bh as u8) };18978 let (tx_w, tx_h) = if split { (4, 4) } else { (bw as u8, bh as u8) };
crates/ec-av1/src/encode.rsmodified+2 -0
@@ -6500,6 +6500,8 @@ fn search_chroma(
6500 side.min(luma.true_height.saturating_sub(y)),6500 side.min(luma.true_height.saturating_sub(y)),
6501 ),6501 ),
6502 (at.side, at.side),6502 (at.side, at.side),
6503+ // The encoder writes 4:2:0 only (`palette_uv_side` above).
6504+ (1, 1),
6503 );6505 );
6504 for mut pal in palette_candidates(&u_source) {6506 for mut pal in palette_candidates(&u_source) {
6505 let n = usize::from(pal.size);6507 let n = usize::from(pal.size);
crates/ec-av1/src/refusal_inventory.rsmodified+8 -2
@@ -38,6 +38,12 @@ const CAPABILITY_CLAIMS: &[&str] = &[
38 38
39 #[cfg(test)]39 #[cfg(test)]
40 const REFUSALS: &[&str] = &[40 const REFUSALS: &[&str] = &[
41+ // lane-av1-444 c4's rect/1:4 chroma port added two shape guards whose
42+ // strings never landed here (continuation 8's suite run caught the
43+ // drift); both are decoder-side "no table for that shape yet" guards on
44+ // 4:4:4 rect strips, same family as the rect luma/chroma entries below.
45+ "a 64-axis strip whose chroma unit has no coefficient table",
46+ "a rectangular chroma transform whose size has no coefficient table",
41 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",47 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
42 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",48 "a split intra strip whose transform unit is {tx_w}x{tx_h} (no luma coefficient tables for that shape here)",
43 "an OBMC neighbour whose switchable interp filter was never recorded",49 "an OBMC neighbour whose switchable interp filter was never recorded",
@@ -88,7 +94,7 @@ const REFUSALS: &[&str] = &[
88 // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused94 // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused
89 // at the sequence header. Gate:95 // at the sequence header. Gate:
90 // `a_non_420_subsampled_sequence_header_is_refused_by_name`.96 // `a_non_420_subsampled_sequence_header_is_refused_by_name`.
91- "a chroma format other than 4:2:0 (subsampling_x/y != 1/1): every chroma extent in this decoder is hardcoded to 4:2:0 and the probe emits 4:2:0 planes only, so a 4:4:4/4:2:2 stream would decode silently wrong pixels",97+ "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported",
92 // lane-av1txr-r2: the third member of the same silent-garbage family.98 // lane-av1txr-r2: the third member of the same silent-garbage family.
93 // `using_qmatrix`/`qm_y`/`qm_u`/`qm_v` are parsed by `ec-av1-syntax` but99 // `using_qmatrix`/`qm_y`/`qm_u`/`qm_v` are parsed by `ec-av1-syntax` but
94 // read by NOTHING on the decode path -- dequantisation is `base_q_idx` +100 // read by NOTHING on the decode path -- dequantisation is `base_q_idx` +
@@ -380,7 +386,7 @@ const PROVEN: &[(&str, &str)] = &[
380 // profile-0 CONTROL still decodes -- the refusal is exercised, not merely386 // profile-0 CONTROL still decodes -- the refusal is exercised, not merely
381 // present.387 // present.
382 (388 (
383- "a chroma format other than 4:2:0 (subsampling_x/y != 1/1): every chroma extent in this decoder is hardcoded to 4:2:0 and the probe emits 4:2:0 planes only, so a 4:4:4/4:2:2 stream would decode silently wrong pixels",389+ "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported",
384 "a_non_420_subsampled_sequence_header_is_refused_by_name",390 "a_non_420_subsampled_sequence_header_is_refused_by_name",
385 ),391 ),
386 // lane-av1txr-r2: the gate encodes the same source twice with real aomenc392 // lane-av1txr-r2: the gate encodes the same source twice with real aomenc
crates/ec-av1/src/restoration.rsmodified+19 -2
@@ -415,6 +415,16 @@ pub(crate) struct RestorationGrid {
415 415
416 impl RestorationGrid {416 impl RestorationGrid {
417 pub(crate) fn new(lr: &LoopRestorationParams, frame_width: u32, frame_height: u32) -> Self {417 pub(crate) fn new(lr: &LoopRestorationParams, frame_width: u32, frame_height: u32) -> Self {
418+ Self::with_ss(lr, frame_width, frame_height, 1, 1)
419+ }
420+
421+ pub(crate) fn with_ss(
422+ lr: &LoopRestorationParams,
423+ frame_width: u32,
424+ frame_height: u32,
425+ ss_x: u8,
426+ ss_y: u8,
427+ ) -> Self {
418 let mut horz_units = [1usize; 3];428 let mut horz_units = [1usize; 3];
419 let mut vert_units = [1usize; 3];429 let mut vert_units = [1usize; 3];
420 let mut units: [Vec<UnitFilter>; 3] = [Vec::new(), Vec::new(), Vec::new()];430 let mut units: [Vec<UnitFilter>; 3] = [Vec::new(), Vec::new(), Vec::new()];
@@ -425,7 +435,10 @@ impl RestorationGrid {
425 let (pw, ph) = if plane == 0 {435 let (pw, ph) = if plane == 0 {
426 (frame_width, frame_height)436 (frame_width, frame_height)
427 } else {437 } else {
428- ((frame_width + 1) / 2, (frame_height + 1) / 2)438+ (
439+ (frame_width + u32::from(ss_x)) >> ss_x,
440+ (frame_height + u32::from(ss_y)) >> ss_y,
441+ )
429 };442 };
430 let unit_size = lr.loop_restoration_size[plane];443 let unit_size = lr.loop_restoration_size[plane];
431 horz_units[plane] = count_units(pw, unit_size);444 horz_units[plane] = count_units(pw, unit_size);
@@ -488,7 +501,11 @@ pub(crate) fn read_lr(
488 if ftype == RestorationType::None {501 if ftype == RestorationType::None {
489 continue;502 continue;
490 }503 }
491- let mi_size = if plane == 0 { 4u32 } else { 2u32 };504+ let mi_size = if plane == 0 {
505+ 4u32
506+ } else {
507+ 4u32 >> (crate::decode::ss_x(fctx) as u32)
508+ };
492 let unit_size = lr.loop_restoration_size[plane];509 let unit_size = lr.loop_restoration_size[plane];
493 let horz_units = grid.horz_units[plane] as u32;510 let horz_units = grid.horz_units[plane] as u32;
494 let vert_units = grid.vert_units[plane] as u32;511 let vert_units = grid.vert_units[plane] as u32;
crates/ec-av1/src/stream.rsmodified+6 -4
@@ -1708,10 +1708,11 @@ fn decode_frame(
1708 // unaffected. Gates: `a_non_420_subsampled_sequence_header_is_refused_by_1708 // unaffected. Gates: `a_non_420_subsampled_sequence_header_is_refused_by_
1709 // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:41709 // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:4
1710 // stream).1710 // stream).
1711- if seq.subsampling_x != 1 || seq.subsampling_y != 1 {1711+ // lane-av1-444: 4:4:4 (ss 0,0) is decoded. 4:2:2 (ss_x != ss_y) is not.
1712+ if seq.subsampling_x != seq.subsampling_y {
1712 return Err(Error::unsupported(1713 return Err(Error::unsupported(
1713 "AV1 decode_stream",1714 "AV1 decode_stream",
1714- "a chroma format other than 4:2:0 (subsampling_x/y != 1/1): every chroma extent in this decoder is hardcoded to 4:2:0 and the probe emits 4:2:0 planes only, so a 4:4:4/4:2:2 stream would decode silently wrong pixels",1715+ "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported",
1715 ));1716 ));
1716 }1717 }
1717 // lane-av1txr-r2: `quantization_params.using_qmatrix` (spec 5.9.12) is1718 // lane-av1txr-r2: `quantization_params.using_qmatrix` (spec 5.9.12) is
@@ -1799,6 +1800,7 @@ fn decode_frame(
1799 // the bit depth so a mono frame decoded on a thread that last saw a1800 // the bit depth so a mono frame decoded on a thread that last saw a
1800 // 4:2:0 one never inherits the wrong plane count.1801 // 4:2:0 one never inherits the wrong plane count.
1801 crate::decode::set_mono(seq.mono_chrome, fctx);1802 crate::decode::set_mono(seq.mono_chrome, fctx);
1803+ crate::decode::set_subsampling(seq.subsampling_x, seq.subsampling_y, fctx);
1802 // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it1804 // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it
1803 // codes every tile symbol against the CDFs it started with, so the tile1805 // codes every tile symbol against the CDFs it started with, so the tile
1804 // readers must not adapt (libaom `decodeframe.c:2909`:1806 // readers must not adapt (libaom `decodeframe.c:2909`:
@@ -2180,11 +2182,11 @@ pub(crate) mod tests {
2180 #[test]2182 #[test]
2181 fn a_non_420_subsampled_sequence_header_is_refused_by_name() {2183 fn a_non_420_subsampled_sequence_header_is_refused_by_name() {
2182 const NAME: &str = "a_non_420_subsampled_sequence_header_is_refused_by_name";2184 const NAME: &str = "a_non_420_subsampled_sequence_header_is_refused_by_name";
2183- const REFUSAL: &str = "a chroma format other than 4:2:0";2185+ const REFUSAL: &str = "a chroma format of 4:2:2";
2184 let fctx = &crate::decode::FrameCtx::new();2186 let fctx = &crate::decode::FrameCtx::new();
2185 let picture = test_card(64, 64);2187 let picture = test_card(64, 64);
2186 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();2188 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
2187- for (profile, label, sx, sy) in [(1u8, "4:4:4", 0u8, 0u8), (2, "4:2:2", 1, 0)] {2189+ for (profile, label, sx, sy) in [(2u8, "4:2:2", 1u8, 0u8)] {
2188 let color = ec_av1_syntax::ColorConfig {2190 let color = ec_av1_syntax::ColorConfig {
2189 num_planes: 3,2191 num_planes: 3,
2190 subsampling_x: sx,2192 subsampling_x: sx,
crates/ec-av1/src/tile.rsmodified+2 -1
@@ -4972,7 +4972,8 @@ fn write_palette_syntax(
4972 &pal.map,4972 &pal.map,
4973 uv_side,4973 uv_side,
4974 n,4974 n,
4975- crate::decode::palette_onscreen_uv((side, side), on, (uv_side, uv_side)),4975+ // The encoder writes 4:2:0 only (`palette_uv_side` above).
4976+ crate::decode::palette_onscreen_uv((side, side), on, (uv_side, uv_side), (1, 1)),
4976 );4977 );
4977 note_palette_uv(n);4978 note_palette_uv(n);
4978 }4979 }
lanes/av1444.report.mdadded+460 -0
@@ -0,0 +1,460 @@
1+# Lane av1444: AV1 4:4:4 (WIP)
2+
3+Branch `lane-av1-444`, base `7f8d6cf6`. Worktree
4+`/home/user/Documents/Code/Rust/edith_codecs-av1444`. Private
5+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1444`,
6+`TMPDIR=$HOME/.cache/av1444-tmp`. Not pushed.
7+
8+Status: **fixture byte-exact end-to-end** (continuation 8). 4:4:4 is
9+byte-exact on every SQUARE witness: 8-bit profile 1 filters off AND on
10+(loop filter + CDEF + restoration), forced-64x64-block arms (exercises the
11+four-TX_32X32 chroma loop), 10-bit profile 2 filters off AND on, plus the
12+FULL `av1-profile1-444.ivf` fixture: all 60 shown frames identical to
13+ffmpeg AND aomdec (three-way sha256 `c3f95bca…`). The entropy ladder is in
14+sync end-to-end; the inter sub8/64x64 chroma paths at 4:4:4 are ported and
15+witnessed by the fixture itself. 420 square arms stay IDENTICAL
16+(regression). 4:2:2 stays a named refusal. Open: two PRE-EXISTING 10-bit
17+film (1920x792, warp/globalmv) suite failures inherited from continuations
18+5-7 — see continuation 8's attribution; outside this lane's 444 arms.
19+
20+## What changed (this continuation, on top of the staged WIP commit)
21+
22+1. `decode_block` single-TU arm (was the prior agent's unstaged edit,
23+ debug prints removed): at 4:4:4 a 64x64 block's chroma is coded as
24+ four TX_32X32 units plane-major — confirmed bug-for-bug against
25+ libaom `av1_get_max_uv_txsize` (`av1_get_adjusted_tx_size`,
26+ blockd.h:1361) and the plane-major unit loop in
27+ `decode_token_recon_block` (decodeframe.c:970-1010).
28+2. **Root cause of the 36k chroma diffs** (the prior agent chased a
29+ phantom 64x64 block — the stream has none): `u`/`v`
30+ `set_tile_origin` hardcoded the 4:2:0 halving (`mi * 2`). At 4:4:4
31+ the halved `tile_x1` clamped `PlaneBuf::edges`' `across` below the
32+ block's own x for every chroma block in the right half of the tile
33+ (and `tile_y1` the left edge in the bottom half), so those blocks
34+ predicted with edges missing (left-only/above-only DC). Localized by
35+ proving the entropy ladder identical (1596/1596 rng rungs vs the
36+ instrumented aomdec), then diffing `OUR_PRED`/`EC_PREDOUT8` for the
37+ first divergent CFL block: aom DC 129, ours 145, traced to
38+ `above=None` in `edges()`. Tile bounds now `mi * 4 >> ss`; identical
39+ at 4:2:0.
40+3. Loop filter: `deblock_plane_span` clipped chroma to
41+ `frame_width/2 × frame_height/2` (another hardcoded halving) — at
42+ 4:4:4 the filter never touched three quarters of each chroma plane.
43+ Crop now follows `ss`. (CDEF and restoration were already exact:
44+ isolating arms `--loopfilter-control=0` vs `--enable-cdef=0` /
45+ `--enable-restoration=0`.)
46+4. Rect/1:4 4:4:4 port (in progress):
47+ - `decode_block_rect4` (32x8/8x32 strips): chroma table was
48+ hardcoded 4:2:0 (`Chroma8`, SCAN_16X4/4X16, mode-derived tx_type
49+ with no size clamp → ADST-at-32 panic). Now shape-keyed
50+ (4:4:4: `Chroma16`, SCAN_32X8/8X32) with the
51+ `av1_get_ext_tx_set_type` DCT_ONLY clamp at square-up ≥ 32
52+ (blockd.h:1278).
53+ - Inter rect chroma: a 64-axis strip at 4:4:4 keeps its 64-px chroma
54+ axis, capped to 32-wide units (`av1_get_max_uv_txsize`), so it
55+ codes TWO units plane-major. New `read_inter_rect_chroma` helper
56+ (both `decode_inter_block` rect readers call it);
57+ `read_inter_plane_rect`'s chroma skip_ctx takes the +3 (libaom
58+ +10) offset for multi-unit blocks; `rect_inter_chroma_set` gained
59+ the (32,32) → `Chroma32` entry.
60+ - `decode_rect4_16_strip` (16x4/4x16 strips): at 4:4:4 there is no
61+ 4:2:0 chroma pair — every strip is its own chroma reference
62+ (`is_chroma_reference`: no mi-parity test at ss 0/0, strip's own
63+ chroma ≥ 4x4). `has_chroma` is now true for every strip at ss 0/0
64+ (key-frame caller `decode_rect4_16` AND the inter
65+ `inter_strip_chroma` construction), the pair origin/tables/CfL
66+ window anchor at the strip itself, and the inter `prev`
67+ (both-strips MC) is disabled at 4:4:4.
68+ - Leftover instrumentation from the staged WIP removed (EC_64*,
69+ EC_TILE); `EC_RECTCHROMA_GAP` stays (deliberate diagnostic per its
70+ comment).
71+
72+## Byte-exactness (all vs aomdec, ffmpeg cross-checked; recipes in
73+`$HOME/.cache/av1444/witness_*.sh`)
74+
75+| stream | result |
76+| --- | --- |
77+| profile 1, filters off, square 128x128 2f | IDENTICAL (98304 B) |
78+| profile 1, filters ON (LF+CDEF+LR), square | IDENTICAL |
79+| profile 1, filters off, forced 64x64 blocks (`gradients --min-partition-size=64`, 8 64x64 leaves) | IDENTICAL |
80+| profile 1, filters on, forced 64x64 blocks | IDENTICAL |
81+| profile 2 10-bit, filters off, square | IDENTICAL (196608 B yuv444p10le) |
82+| profile 2 10-bit, filters on, square | IDENTICAL |
83+| profile 0 420, filters off, square | IDENTICAL (regression) |
84+| profile 0 420, filters on, square | IDENTICAL (regression) |
85+| `av1-profile1-444.ivf` (320x240, rect/1:4 shapes) | decodes 24+ frames, then **panics** `reconstruct_rect len 64 index 64` (decode.rs:3619, `exec_intra` track-caller) after `EC_RECTCHROMA_GAP luma=64x16 tx=16x16` — the 64-axis intra strip's split-transform chroma path is the next defect |
86+
87+## Still refused or unproven
88+
89+| shape | disposition |
90+| --- | --- |
91+| 4:2:2 (`ss_x != ss_y`) | refused by name. Gate re-scoped, not re-run |
92+| inter rect2 sub8 (8x4/4x8 pieces) at 4:4:4 per-piece chroma | unported — `decode_inter_sub8_rect2` still codes the 4:2:0 group unit |
93+| `decode_inter_sub8_split4` per-piece chroma eob CDF adaptation | wall (below), first mismatch deep in frame 1 |
94+| full `cargo test -p ec-av1` | NOT run this round. Do not claim green |
95+| 0-warning parity | build is warning-clean (`cargo build --release -p ec-av1 --example decode_probe`); full-suite parity not measured |
96+
97+## Continuation 4 (2026-09-23, Av1X444Cont4)
98+
99+1. **Edge panic fixed (Rauf's clamp, verified bug-for-bug, committed)**:
100+ `around_mi`/`around_mi_rect`/`luma_skip_ctx_rect` clamp each walk to
101+ `mi_cols`/`mi_rows`. libaom facts checked: the above/left entropy+coeff
102+ arrays are `aom_calloc(aligned_mi_cols, ..)` per tile row
103+ (alloccommon.c:437-448, `ALIGN_POWER_OF_TWO(mi_cols, MAX_MIB_SIZE_LOG2)` =
104+ exactly 80 for the 320 px fixture) — zero-initialized and never written
105+ beyond the frame extent, and `get_txb_ctx_general` (txb_common.h:281)
106+ walks only the TXB's own span, so beyond-frame cells contribute ZERO to
107+ every context on libaom's side too. The clamp reproduces exactly that;
108+ there is no edge sample extension for these entropy-context arrays. The
109+ fixture's `reconstruct_rect len 64 index 64` panic is gone: the probe
110+ decodes all 60 frames, exit 0.
111+2. **Fixture frame 0 (first shown frame) still byte-exact** vs ffmpeg
112+ yuv444p after the above (re-verified every round).
113+3. **decode_idx 1 (hidden inter, base_q 57, show_frame=0) root-caused and
114+ partially fixed**: the frame's first partition reads
115+ (`w64/w32/w16` all SPLIT at mi (0,0)) were in sync, but aom reads an
116+ **8x8-level `partition_w8` symbol** before each 8x8 leaf of the inter
117+ walker too (the keyframe walker already read it; the inter walker reads
118+ it silently — the missing *per-piece chroma* was the real gap):
119+ at ss 0/0 `is_chroma_reference` is unconditional
120+ (av1_common_int.h:1459 — `!subsampling_x/y` force both disjuncts true),
121+ so every 4x4 piece of a `partition_w8 == SPLIT` group codes its OWN 4x4
122+ U and V unit right after its luma, plane order 0,1,2 per leaf.
123+ `decode_inter_sub8_split4` coded the 4:2:0 group unit instead. Fixed:
124+ per-piece chroma MC (piece's own mv/filters, ss 0) + per-piece
125+ `read_inter_plane` + `record_mi_chroma`; the group unit is now gated
126+ `!chroma_444`, with `record_uv_mode_mi`/`record_strip_palette` hoisted so
127+ they run at both subsamplings. Result: the coefficient-step ladder
128+ against instrumented aomdec moved from first mismatch at step 387 to
129+ step 925 (15 chroma TUs + the whole (0,2) group and (2,0)/(2,2) 8x8
130+ blocks now bit-identical; all `partition_w8` values match through
131+ mi (2,6)).
132+4. **Current wall (precisely localized)**: decode_idx 1, the (2,6) split4
133+ group's piece-0 U TU (4x4, ss 0/0). Both sides read the identical
134+ `all_zero` symbol (rng 34242, value 0), then the `eob_pt` read diverges:
135+ aom eob=4, ours eob=2, from identical pre-state. Instrumented oracle
136+ (`EC_EOBPT_CDF` print added to decodetxb.c, `ninja aomdec` rebuild) shows
137+ aom's `eob_flag_cdf16[PLANE_UV][0]` contents at that read =
138+ `[30271, 28672, 23902, 15775]` — heavily adapted — while ours
139+ (`eob_pt_16_chroma`, bound `cdf_state.rs:1841`) is still near its default
140+ `[6764, 8165, 12733, 17250]`. So aom's chroma-4x4-2D eob CDF instance
141+ receives adaptation from reads our model routes elsewhere (or misses):
142+ the next suspects are (a) `decode_inter_sub8_rect2`'s per-piece chroma
143+ (still the 4:2:0 group unit — aom codes per-piece 8x4/4x8 chroma units,
144+ same 16-coeff eob class), and (b) the intra 16x4/4x16 strips' chroma
145+ units in inter frames (`intra16x4_in_inter` 16x4=68 4x16=24), whose
146+ 4x4-class eob reads must land on the same `eob_flag_cdf16[UV][2D]`
147+ instance. Tooling left in place: `EC_DBG_SUB8=1` (per-b8 partition
148+ value/pre/post rng, per-piece skip/is_inter), `EC_TRACE_PART=1`
149+ (EC_PART-style partition walk), oracle-side `EC_EOBPT_CDF=1`
150+ (per-4x4-eob CDF contents + mi). Comparison harness:
151+ `EC_TRACE_COEFF=1 aomdec` vs `EC_TRACE_COEFF=1 decode_probe` on
152+ `$HOME/.cache/av1444/f2.obu` (2-frame cut), diff with the 15
153+ instrument-only chroma `tx_type` lines dropped.
154+5. Regression arms after the change: 420 square IDENTICAL, 444 square
155+ filters off IDENTICAL, 444 square filters on IDENTICAL, forced-64x64
156+ 444 IDENTICAL (witness scripts, rerun this round).
157+6. **Frame-output policy note**: `decode_probe` writes only SHOWN frames
158+ (`is_shown` gate); aomdec/ffmpeg likewise. The first shown frame is
159+ decode_idx 0; decode_idx 1..5 are hidden alt-ref/LF-update frames — they
160+ still must decode bit-exactly because every later shown frame references
161+ them.
162+
163+## Next
164+
165+1. Frame 18's 2-pixel U diff (see continuation 5's wall): confirm
166+ whether the covering block is a UV-PALETTE block (`intra_in_inter_palette:
167+ uv=76` counter fires) — compare `read_palette_colors_uv`
168+ (decode.rs:8979, libaom decodemv.c:509) delta decoding vs libaom, or
169+ if not palette, dump the residual/inverse of the covering 4x4.
170+2. Then frames 18..59: iterate the same way (ladder is already
171+ end-to-end clean on the 24-frame cut, so expect reconstruction-only
172+ walls; re-diff per frame group).
173+3. Flip the refusal gate (`a_non_420_subsampled_sequence_header_is_
174+ refused_by_name` re-scope) to a fixture witness gate; witness or
175+ refuse inter square 64x64 444 (the forced-64x64 witness already
176+ passes — that arm is intra-only, the inter 64x64 path is new).
177+4. Full suite `--test-threads=1` (NOT run this round), 0-warning
178+ parity (build IS warning-clean), update this report.
179+
180+## Continuation 8 (2026-09-23, Av1X444Cont8 — lane closed: fixture byte-exact end-to-end)
181+
182+Round-7's ONE-symbol wall is RESOLVED; `av1-profile1-444.ivf` decodes ALL 60
183+shown frames byte-exact vs ffmpeg AND aomdec (three-way sha256
184+`c3f95bca00f0ba5ea9f7071f5645edd910b590efebea2d73398017d10dc272d7`).
185+
186+1. **Root cause (class `override-slot-on-one-arm` via a zero grid):** the
187+ 64x64-inter four-TX_32X32 chroma arm read each unit correctly and stamped
188+ each unit's context IMMEDIATELY (`record_mi_chroma(cu_mi, 32, 32, ..)`),
189+ then set `mu_chroma = true` and handed `Grid::Zero` to `u_grid`/`v_grid`.
190+ The block tail then painted 0 over those correct stamps TWICE:
191+ `record_rect_mi`'s whole-block chroma write (state of the zero grid) and
192+ the `mu_chroma_units` re-stamp, which sliced its "units" out of the SAME
193+ zero grids. Every block after a 64x64 inter block thus read chroma
194+ coefficient contexts 0 across the block's whole span. Oracle trace at the
195+ wall (`EC_DBGCTX`, rebuilt `build-c/aomdec`): `mi=52,16 plane=1 tx=2
196+ above0=0 left0=21 base=1 off=7 ctx=8 cellsA=0,0,0,0 cellsL=21,21,21,21`
197+ — aom's left cells for the mi(52,16) U TX_16X16 hold the mi(48,0) block's
198+ U TX_32X32 (48,8) unit's running cul (raw cell 21; only zero-vs-nonzero
199+ matters for `get_entropy_context`), ours held 0 → ctx 0 vs 8.
200+2. **Fix (both copies of the arm — single-ref and compound):**
201+ - The arm now assembles the four per-unit coefficient grids per plane
202+ into `u_grid`/`v_grid` (`mu_units` + `Grid::Own`, same pattern as the
203+ 128-root path), so the block-tail re-stamp slices REAL states.
204+ - `mu_chroma_units` collection enumerates FOUR TX_32X32 units per 64x64
205+ mu chunk at ss 0/0 (one at 4:2:0 — byte-identical to the old loop),
206+ each at its own mi origin, own `(32 << ss)`-px entropy-cell span, own
207+ 32x32 quadrant of the assembled grid; the stamp loop uses each unit's
208+ own span (was a blanket 64 px). Lossless branch unchanged.
209+3. **Witness gate (all fresh runs, ffmpeg `-y` added to the scripts — the
210+ old scripts could silently compare a STALE ffmpeg reference when the
211+ output file existed):**
212+
213+ | stream | result |
214+ | --- | --- |
215+ | `av1-profile1-444.ivf`, all 60 shown frames | IDENTICAL (ffmpeg == aomdec == ours, sha256 above) |
216+ | 444 square 8-bit, filters off | IDENTICAL |
217+ | 444 square 8-bit, filters ON (LF+CDEF+LR) | IDENTICAL |
218+ | 444 square 10-bit, filters off | IDENTICAL (new `witness_444_10b.sh`) |
219+ | 444 square 10-bit, filters on | IDENTICAL |
220+ | 444 forced-64x64 blocks (`gradients --min-partition-size=64`) | IDENTICAL |
221+ | 420 square, filters off (regression) | IDENTICAL |
222+ | 420 square, filters ON (regression) | IDENTICAL |
223+ | 4:2:2 | refused by name (suite gate, unchanged) |
224+
225+ **Inter square 64x64 at 4:4:4 is witnessed by the fixture itself**: the
226+ 64x64 PARTITION_NONE inter block at mi(48,0) of decode idx 52 codes the
227+ four-unit U/V TX_32X32 loop, and every later block in rows 48..59
228+ (including f52's own mi(52,16) read) consumes its per-unit contexts —
229+ byte-exactness of frames 52..59 is that consumption proof. The
230+ forced-64x64 generated arm stays intra-only and passes.
231+4. Regression arms quoted above; `reelb_*` 10-bit, mono 60f, qmatrix-refused
232+ and cdf-exact gates ride the full suite (final line appended below).
233+5. Named gap, unchanged: an inter 128x128 block at 4:4:4 still codes ONE
234+ chroma unit per mu chunk where libaom codes four (`side > 64` arm) —
235+ unported symbol stream, same disposition class as the rect2 sub8 row.
236+ The collection fix makes the CONTEXT machinery unit-complete for it, but
237+ the stream port is not attempted.
238+6. **Full suite** (`cargo test -p ec-av1 -- --test-threads=1`, hub-supervised,
239+ commit f9d5d393, 661 tests, 3h29m):
240+ `test result: FAILED. 656 passed; 5 failed; 0 ignored; 0 measured; ...`
241+ with every failure attributed:
242+ - `refusal_inventory::tests::the_decode_path_refuses_exactly_the_listed_
243+ cases` — continuation 4's rect chroma guards never landed in
244+ `REFUSALS`; FIXED this round (both strings added, module 14/14 green
245+ in isolation, committed).
246+ - `a_real_affine_global_motion_stream_...` and
247+ `a_real_aomenc_10bit_inter_sequence_with_a_split_transform_intra_
248+ strip_...` — the KNOWN live-aomenc infra race: both GREEN in isolated
249+ re-runs on the same tree (affine `ok ... 18.34s`; the flakes follow
250+ the documented kill-child/drain/isolated-rerun protocol).
251+ - `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` and
252+ `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_reach_...`
253+ — ATTRIBUTION CORRECTED (2026-09-24, lane-av1-444-film): the earlier
254+ "pre-existing at b9530604" line above was WRONG — the reviewer reran
255+ all three trees and these two gates FAIL at 1ad7e0fc and b9530604 but
256+ PASS on main 73f3ac64 and fork 7f8d6cf6. They are THIS LANE's
257+ regression, and continuation 7 had already diagnosed the mechanism:
258+ the 444 delta moved the sub8 group tails'
259+ `record_uv_mode_mi(gr, gc, 2, 2, DC_PRED)` to a bare `!chroma_444`
260+ gate, which at 4:2:0 stamps DC over an INTRA chroma-reference piece's
261+ real `uv_predict_mode` (continuation 7's trace: pieces 12/11/9/12 at
262+ (42,54..55) wiped to 0) and drops the next block's chroma intra-edge
263+ filter (class `override-slot-on-one-arm`). 1920x792 10-bit films,
264+ scattered +-1..7 reconstruction diffs. FIXED on lane-av1-444-film:
265+ both stamps gated `!chroma_444 && !intra_chroma` (port of
266+ lane-av1-cfl's 7c6dad53), plus three same-class per-unit chroma
267+ re-stamps (decode_rect_split chroma_tiled, decode_block_rect64
268+ bigger arm, read_inter_rect_chroma multi arm) matching the in-tree c8
269+ `mu_chroma_units` pattern.
270+ All named regression gates green in this run and the witness table:
271+ 4:2:2 refused (`a_non_420_subsampled_sequence_header_is_refused_by_name
272+ ok`), qmatrix refused, cdf gates, mono 60f, reelb_* 10-bit — all `ok`.
273+
274+## Continuation 7 (2026-09-23, Vefa — budget-wall WIP)
275+
276+Round-6's wall is RESOLVED; the fixture moved from "shown 18 seed" to a new,
277+exactly-localized wall at decode idx 52 (shown 49).
278+
279+1. **Root cause (leaf B was a victim, class stale-neighbour-mode):** leaf
280+ (42,58)'s chroma DC base 145-vs-146 traced to its LEFT edge, not to the DC
281+ gather. Our `dc()` already carries libaom's `(sum + count/2) / count` bias;
282+ the sums differed because leaf A (42,56) output was wrong: its left
283+ neighbour (42,55) coded `uv=SMOOTH_H` (11) on a 4x4 intra-in-inter piece,
284+ but the inter sub8 group tails (`decode_inter_sub8_split4` /
285+ `decode_inter_sub8_rect2`) stamped `DC_PRED` over the whole 2x2-mi group's
286+ uv-mode neighbour cells AFTER the pieces had recorded their own modes
287+ (trace: pieces 12/11/9/12 at (42,54..55) wiped to 0). libaom keeps every
288+ sub-block's own `mbmi->uv_mode`. Consequence chain: aom
289+ `get_intra_edge_filter_type`=1 for leaf A vs our 0 → libaom's type-1
290+ upsample cap (`blk_wh <= 8`) leaves the edge alone while our type-0 cap
291+ (`blk_wh <= 16`) UPSAMPLES it for V_PRED p_angle=87 (dx=3): base row0
292+ [174,172,**179**,189,185,**183**,195,**182**] vs aom
293+ [174,172,**178**,189,185,**182**,195,**183**] — every later sample
294+ reproduced numerically. Leaf B's left column then differed at rows
295+ 168/170, and the (correct) biased DC rounded 145 vs 146.
296+2. **Fix:** gate both group-tail uv stamps on `!chroma_444`. At ss 0/0 every
297+ piece already writes its own state (inter pieces through
298+ `record_inter_rect_mi`'s is_inter DC stamp, intra pieces through
299+ `decode_intra_sub8_leaf`'s chroma_444 arm); the group stamp is 4:2:0-only.
300+3. **Verified:** w24 cut — ALL 26 decode-order frames prefilt byte-exact
301+ (was f19=122 U/V diffs, f20, f22). Full fixture — decode 0..51 (shown
302+ 0..48) byte-exact vs ffmpeg yuv444p; round-6's f1 single V sample is gone.
303+4. **New wall (localized, next round):** decode idx 52 first diverges at
304+ Y(128,192) (ours 210, aom 209); prefilt 21735 diffs; the symbol ladder
305+ desyncs INSIDE frame 52. Facts: aom f52 walk at mi(52,16) is
306+ BLOCK_16X16 PARTITION_NONE (`EC_PART bsize=6 value=0`); luma ONE
307+ TX_16X16 (matches ours); then chroma U TX_16X16 reads all_zero with
308+ `txb_skip_ctx=8` = base 1 + offset 7 (`get_txb_ctx_general`: chroma
309+ offset 10 iff plane_bsize bigger than the transform, else 7;
310+ plane_bsize==BLOCK_16X16==tx → 7). OUR same-position read: all_zero
311+ **ctx=0** — `decode_block`'s cn==1 chroma arm passes offset `None`
312+ (only cn>1 passes `Some(3)`), and our above/left entropy flags read
313+ 0 where aom's combine gives 1. Pinned with the rebuilt oracle's new
314+ `EC_DBGCTX` print (cellsA/cellsL per unit): aom's U TX_16X16 cellsA
315+ = 0,0,0,0 but cellsL = **21,21,21,21** — the left cells at mi rows
316+ 52..55 were written by the 64x64 mi(48,0) block's U TX_32X32 (48,8)
317+ unit with cul 21, while OUR left cells for the same rows/plane read 0.
318+ So the desync is ONE symbol (the U all_zero) and the suspect is our
319+ per-unit chroma context WRITE for the 64x64 inter path
320+ (`record_mi_chroma` span/cul derivation) or its cell mapping — our
321+ (48,8) U grid has its coefficients in the unit's TOP half (grid rows
322+ 8..15), so a correct bottom-cell write would be 0 and the 21 must
323+ come from aom's cul derivation over the whole 32x32 unit (cul is a
324+ running count, not per-cell) — verify `read_coeffs`' cul accounting
325+ against libaom's `read_coeffs_txb` loop.
326+5. **Infra note:** the oracle's `EC_AV1_POSTCDEF_DUMP` index is off by one
327+ (aom pc.fK = decode K+1); under that alignment CDEF is byte-exact frames
328+ 44..51, and post-deblock is byte-exact through idx 51 — the wall is NOT
329+ loop-filter related.
330+6. NOT done this round (budget): regression arms (420/444 square, forced-64,
331+ mono, 10-bit, qmatrix, cdf) and the full suite. Committed at the wall;
332+ tree clean; no push.
333+
334+
335+
336+Round-5's frame-18 target was mis-aimed: the visible 2-pixel U diff is
337+INHERITED. Per-frame prefilt diff (EC_AV1_PREFILT_DUMP, crop-aware):
338+f0..f18 byte-exact (f1: one V sample (224,272) ours +1, non-propagating),
339+**f19 (hidden) = 122 U/V diffs** around rows 168..179 / cols 225..247,
340+f20 = exactly the known 2 U samples, f22 = 50 U diffs. The root lives in
341+hidden frame idx 19; f20/f22 inherit it through MC.
342+
343+Enum correction (class stale-assumption): libaom's UV_PREDICTION_MODE has
344+UV_CFL_PRED **at index 13** (after PAETH/SMOOTH_H), not 1; uv=1 is
345+UV_V_PRED. So f19's leaf (42,56) is V_PRED (not CFL) and leaf (42,58) is
346+**CFL** (not smooth/palette). Round-5's read_palette_colors_uv suspicion
347+was a dead end — the (42,56) block reads no palette and (42,58) reads no
348+palette; both sides' PALSYN rows agree rng-for-rng (47240 anchor).
349+
350+Verified bit-exact this round (instrumented C-only oracle build at
351+~/.cache/aom-oracle/build-c plus new EC_DQCOEFF / EC_PREDB8 / EC_TXIN8 /
352+EC_TXOUT8 / EC_FINAL8 dumps): coefficient levels+signs, dqcoeff grids
353+(OUR_DQ == aom EC_DQCOEFF after reading aom's buffer column-major),
354+qindex 123 (delta-q applied correctly on both sides), quant tables, the
355+dequant formula, the 1D idct8 + row/col shift composition (python replica
356+matches oracle TXIN/TXOUT exactly), CFL weights/scaling, and the leaf's
357+residual: OUR res0 == aom TXOUT row0 exactly
358+([14,-31,-67,-63,-17,5,-17,-23]).
359+
360+**Localized defect:** f19 leaf (42,58) V (UV_CFL_PRED, alpha=-1): aom
361+composes base 146 + CFL + residual; ours composes base **145** + identical
362+CFL + identical residual → every sample exactly -1. The -1 is in the
363+chroma DC_PRED base: aom 146 = round((Σabove 960 + Σleft 1369)/16) with
364+Σleft including (175,231)=166; our 145 is one rounding/edge-sample step
365+off (candidates: missing rounding bias (2329>>4), or the left edge sample
366+set). Our (168,231)=180 vs aom 181 is leaf A's own diff, not leaf B's
367+edge (smooth_v not in play; leaf B's below-left (175,231)=166 identical).
368+
369+Still open (next steps): 1) pin the DC_PRED edge/rounding divergence in
370+our intra DC path for this leaf (DBG192 build committed: EC_DBG192=1
371+dumps pred0/res0 at x=224/232 y=168); 2) leaf (42,56) V_PRED's scattered
372+±1 U/V diffs (base = clean above-row copy, residual identical ⇒ its own
373+edge/availability wrinkle — needs the same treatment); 3) f1's single V
374+sample; 4) re-run the fixture end-to-end + witness gate + regression
375+arms + full suite after the fix.
376+
377+Oracle/oracle-build notes: EC_AV1_PREFILT_DUMP crops at true dims on the
378+aom side; ours writes padded planes (Y 240x320, U/V stride 320 with a
379+16-row top border, offsets 81920 / 163840 in the fN file). aomdec's
380+EC_COEFF `pos` is a zigzag raster pos; EC_COEFF_VAL is per-unit, not
381+per-coefficient. The f9 unit at the same mi/rng anchor was a red herring
382+— always pair units by EC_FINAL8 pixel values, not by rng.
383+
384+## Continuation 5 (2026-09-23, Semiha)
385+
386+Round-4's wall was misdiagnosed: aom's divergent eob read was
387+`eob_flag_cdf16[PLANE_UV][ctx=1]` (the trace prints `ctx=1`; the
388+"[UV][2D]" reading was wrong), adapted in frame 1, while ours bound the
389+ctx-0 row. Chasing it surfaced four real defects, all entropy-side; the
390+whole-stream ladder then went clean and the wall moved to a
391+reconstruction rounding.
392+
393+1. **`decode_inter_sub8_split4` per-piece chroma now inherits the
394+ piece's own luma `tx_type`** (was hardcoded `Some(DctDct)`): an inter
395+ block's chroma never codes its own symbol but inherits the colocated
396+ luma transform's coded type (`av1_get_tx_type`, blockd.h:1291), which
397+ decides `eob_multi_ctx` (decodetxb.c:214: `(tx_class == TX_CLASS_2D)
398+ ? 0 : 1`). A piece whose luma picked V_DCT/H_DCT desynced the chroma
399+ eob read one row. This was the round-4 wall.
400+2. **`decode_inter_sub8_rect2` per-piece 8x4/4x8 chroma ported** (round
401+ 4's suspect (a), confirmed by trace: aom codes a chroma TX_8X4 at
402+ mi (3,8) that ours skipped): at ss 0/0 every piece codes its own U/V
403+ units right after its luma, predicted from the piece's own mv/filters
404+ at the piece's own pixel position, inheriting the piece's first
405+ luma TU's tx_type (`TxbSet::ChromaRect8x4`). The 4:2:0 group unit is
406+ gated `!chroma_444`; `record_uv_mode_mi`/`record_strip_palette` are
407+ hoisted to run at both subsamplings (same pattern as split4's r4
408+ port). Skip pieces push zero-residual MC and zero chroma context.
409+3. **`decode_intra_sub8_leaf` chroma is per-piece at ss 0/0** (round 4
410+ had `chroma_444 || i == 3` on the split caller only, and the leaf
411+ still anchored "the group's one 4x4 unit" at the group origin): the
412+ leaf now anchors at the piece's own position with the piece's own
413+ shape — a 4x4 unit under SPLIT (`Chroma4`, `read_plane`), the leaf's
414+ own TX_8X4/4X8 unit under HORZ/VERT (`ChromaRect8x4` via
415+ `read_coeffs_rect`, tx_type from the uv mode via
416+ `Intra_Mode_To_Tx_Type`, CFL alpha window over the piece's own
417+ footprint). The rect2 caller passes `chroma_444 || i == 1`. uv_mode
418+ neighbour publishing is per-piece at ss 0/0
419+ (`record_uv_mode_mi(lmi, w_mi, h_mi, ..)`).
420+4. **A 64x64 INTER block codes FOUR TX_32X32 chroma units, plane-major,
421+ at ss 0/0** (was one 64x64 read through 32-class tables): each unit
422+ carries the +10 `get_txb_ctx_general` offset (chroma plane block
423+ larger than the transform; our `txb_skip_chroma_32` holds those rows
424+ at +3, so `luma_skip_ctx: Some(3)`, the lane-sb128b r3 convention as
425+ the 128 mu path), predicts from its own 32x32 window of the block's
426+ MC buffer, and records chroma context per unit immediately
427+ (`record_mi_chroma`), with `mu_chroma = true` so the block-level
428+ record does not overwrite the per-unit states.
429+
430+Ladder evidence (`ladder.py` left in `$HOME/.cache/av1444/`; two-pointer
431+walk on `(tag, rng)` tolerating the known instrument asymmetries — aom's
432+chroma `tag=tx_type` prints, `post_golomb` echo rows, ours' `sign_rect`
433+batching and golomb-tail br rows): on the 24-frame cut
434+(`w24.obu`), ours 358473/358473 steps, aom 355132/355132, zero
435+unexplained mismatch — the ENTROPY stream is end-to-end in sync.
436+Round-4's named suspects (b) — intra 16x4/4x16 strips feeding
437+`eob_flag_cdf16[UV][2D]` — did NOT materialize: TX_16X4 chroma is
438+64-coeff (cdf64 class); the cdf16 UV instance is fed only by split4
439+piece chroma, all of which now bind correctly.
440+
441+Pixel state (`w24.our.yuv` vs `w24.ref.yuv`, 24-frame cut): shown
442+frames 0..17 byte-exact; frame 18 differs in exactly TWO U samples,
443+(168,230)=218 vs 217 and (168,231)=204 vs 203 (+1 both), confirmed
444+PRE-loop-filter via `EC_AV1_PREFILT_DUMP` (decode idx 20 == shown 18) —
445+a reconstruction defect, not entropy. Full 60-frame run: frames
446+0..17 exact, first diffs frame 18 (U,2 px), then sparse U diffs frames
447+19..37, Y diffs from frame 49 (drift accumulating behind the frame-18
448+seed). Prediction of the covering block is IDENTICAL to the oracle
449+(aom `EC_PREDOUT8 mi_row=42 mi_col=57 plane=1 sum=3280 row0=205,206,209,200`
450+== ours), so the residual/dequant/inverse or a UV-palette colour write
451+is the remaining suspect: the block is adjacent to `intra_in_inter_
452+palette uv=76` territory and the (224,168) 8x8 leaves no `OUR_TXTYPE`
453+trace, so it is likely a UV-PALETTE block — compare `read_palette_
454+colors_uv` (decode.rs:8979, libaom decodemv.c:509) delta/rounding.
455+
456+Regression arms this round: 444 square filters off IDENTICAL, 444
457+filters on IDENTICAL (aomdec==ffmpeg cross-check), 420+forced-64x64
458+IDENTICAL. 10-bit arms and mono NOT rerun this round. Full suite NOT
459+run (budget wall). Build is 0-warning
460+(`cargo build --release -p ec-av1 --example decode_probe`).