forge
Explore
Log in

Don't you dare go Hollow

wip(av1): Neighbours groundwork for TxMode::Select's per-TU luma context

Browse files at this commit

1ee1fd3d08238637564501e545f4f59668f4ee9eAhmet Kaan GümüşParent: ce44f72
record_mi_luma/record_split_luma split the existing whole-block record()/
record_mi() into a per-transform-unit luma coefficient-context write plus
a once-per-block mode/side/chroma write, which a depth-selected luma
transform (smaller than its own coded block) needs and the current
always-full-size path does not yet exercise. Unused for now (dead_code
warnings, same as the pre-existing skip_at) -- the tx_size symbol read,
CDF tables, decode_block/decode_leaf8 wiring, and the stream.rs refusal
narrowing are still open; see HANDOFF in the ledger.
crates/ec-av1/src/decode.rsmodified+63 -0
@@ -658,6 +658,69 @@ impl Neighbours {
658 });658 });
659 }659 }
660 }660 }
661+
662+ /// [`Self::record_mi`]'s plane-0 half only, for one luma transform unit
663+ /// inside a coded block whose luma transform is smaller than its own
664+ /// side (`TxMode::Select`): the real per-transform-unit coefficient
665+ /// context (spec `AboveLevelContext`/`LeftLevelContext`), unlike the
666+ /// coarse per-block `tx_grid`/`fill_lf_grid` state
667+ /// [`Self::record_split_luma`] still writes once for the whole block.
668+ /// Leaves `above_side_mi`/`left_side_mi` and the chroma planes alone --
669+ /// the caller's own [`Self::record_split_luma`] call sets those once,
670+ /// at the block's own true side, not this TU's.
671+ fn record_mi_luma(&mut self, (mi_r, mi_c): (usize, usize), tx_px: usize, grid: &[i32]) {
672+ let state = neighbour_state(grid);
673+ let side_mi = tx_px / MI;
674+ for cell in 0..side_mi {
675+ if mi_r + cell < self.mi_rows {
676+ self.left[mi_r + cell][0] = state;
677+ }
678+ if mi_c + cell < self.mi_cols {
679+ self.above[mi_c + cell][0] = state;
680+ }
681+ }
682+ }
683+
684+ /// [`Self::record`]'s mode/side and chroma-context bookkeeping, for a
685+ /// block whose luma was decoded as several transform units through
686+ /// [`Self::record_mi_luma`] rather than [`Self::record`]'s own single
687+ /// whole-block luma write -- everything [`Self::record`] does except
688+ /// plane 0, which is already correct per-TU by the time this runs.
689+ fn record_split_luma(
690+ &mut self,
691+ at: (usize, usize),
692+ side: usize,
693+ mode: usize,
694+ chroma_grids: [&[i32]; 2],
695+ ) {
696+ let (r, c) = at;
697+ for cell in 0..side / SUB {
698+ self.above_mode[c + cell] = mode;
699+ self.left_mode[r + cell] = mode;
700+ self.above_side[c + cell] = side;
701+ self.left_side[r + cell] = side;
702+ }
703+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
704+ let side_mi = side / MI;
705+ for cell in 0..side_mi {
706+ self.left_side_mi[mi_r + cell] = side;
707+ self.above_side_mi[mi_c + cell] = side;
708+ }
709+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
710+ let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols));
711+ for (plane_idx, grid) in chroma_grids.into_iter().enumerate() {
712+ let plane = plane_idx + 1;
713+ let state = neighbour_state(grid);
714+ for cell in 0..side_mi {
715+ if cell < side_mi.min(bound_h.saturating_sub(mi_r)) {
716+ self.left[mi_r + cell][plane] = state;
717+ }
718+ if cell < side_mi.min(bound_w.saturating_sub(mi_c)) {
719+ self.above[mi_c + cell][plane] = state;
720+ }
721+ }
722+ }
723+ }
661 }724 }
662 725
663 /// Reads one coded block's skip flag, luma mode, angle delta (if the mode726 /// Reads one coded block's skip flag, luma mode, angle delta (if the mode