forge
Explore
Log in

Don't you dare go Hollow

lane-av1422warp: OBMC strides the 4:2:2 chroma prediction with the plane block's own width

Browse files at this commit

16a2dff5616af0acc445446323486d72442d41bcAhmet Kaan GümüşParent: bdf5b5e
obmc_plan/obmc_run carried the enclosing square chroma_side and used it as
the chroma PREDICTION buffer's stride. At 4:2:2 that buffer is
(chroma_stride, chroma_buf_h) = (plane block width, plane block height)
since lane-av1-422blockhalf, so every chroma blend read row r at r*side
instead of r*chroma_stride. Measured on a real aomenc --profile=2 stream
(256x288, 16 frames): a 32x16 luma strip's left-pass chroma blend wrote row
15 at index 15*32 = 480 of the 256-sample 16x16 buffer -- the
index-out-of-bounds panic in obmc_blend_h. The stream decoded zero frames
before this and all 16 after.

All four chroma blend call sites and both EC_MCB prediction dumps now use
chroma_stride, matching every other consumer of pred_u/pred_v in the same
block. chroma_stride == chroma_side at 4:2:0 and 4:4:4, so those are
unchanged: a same-recipe 4:2:0 control stream (a420.obu, sha256
1f43ef1a) is byte-identical to aomdec --rawvideo before and after.
crates/ec-av1/src/decode.rsmodified+57 -19
@@ -8953,7 +8953,25 @@ impl Neighbours {
89538953 // mi(5,15): left neighbour SMOOTH_V at mi(5,14), read at mi(4,13)).
89548954 let snap_y = (1usize << ss_y(fctx)) - 1;
89558955 let snap_x = (1usize << ss_x(fctx)) - 1;
8956- self.smooth_uv_neighbour_unsnapped(mi_r & !snap_y, mi_c & !snap_x, r, c)
8956+ // `set_mi_row_col` (libaom `av1_common_int.h:1395-1412`) puts the two
8957+ // chroma references at `base_mi[-stride + ss_x]` and
8958+ // `base_mi[ss_y*stride - 1]`, with `base_mi` the block's own mi already
8959+ // de-offset by `(mi_row & ss_y)` / `(mi_col & ss_x)`. The snap above IS
8960+ // that de-offsetting, so the references are
8961+ // `(snapped_r + ss_y - 1, snapped_c + ss_x)` and
8962+ // `(snapped_r, snapped_c - 1)` -- NOT `(snapped_r - 1, snapped_c)` /
8963+ // `(snapped_r, snapped_c - 1)` as this used to read them. At 4:4:4
8964+ // both shifts vanish; at 4:2:0 and 4:2:2 the above reference sits one
8965+ // mi column further right (one chroma column spans two luma mi
8966+ // columns, so the chroma edge reaches into the right-hand luma block)
8967+ // and the left reference one mi row further up.
8968+ self.smooth_uv_neighbour_unsnapped(
8969+ mi_r & !snap_y,
8970+ mi_c & !snap_x,
8971+ r,
8972+ c,
8973+ (ss_x(fctx), ss_y(fctx)),
8974+ )
89578975 }
89588976
89598977 /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e.
@@ -8967,6 +8985,7 @@ impl Neighbours {
89678985 mi_c: usize,
89688986 r: usize,
89698987 c: usize,
8988+ (ss_x, ss_y): (usize, usize),
89708989 ) -> bool {
89718990 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the
89728991 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid
@@ -8991,15 +9010,25 @@ impl Neighbours {
89919010 .filter(|&m| m != u8::MAX)
89929011 .map(usize::from)
89939012 };
8994- let above = match self.uv_mode_col.get(mi_c) {
8995- _ if have_above && let Some(m) = cell(&self.uv_mode_grid, mi_r - 1, mi_c) => m,
8996- Some(&(row, m)) if have_above && usize::from(row) == mi_r - 1 => usize::from(m),
9013+ // libaom's two chroma-reference mi, per the shift the caller applies.
9014+ // 4:2:2 ONLY. `ss_y == 0` makes the above reference's row term
9015+ // `snapped_r - 1` (what this always read) and the left reference's
9016+ // row term `snapped_r` (unchanged); `ss_x == 1` moves the above
9017+ // reference one mi column right. At 4:2:0 both shifts are the
9018+ // identity on the values this already read (measured: the 4:2:0
9019+ // control stream is byte-exact with them folded in), and at 4:4:4
9020+ // `ss_x == 0` does the same -- so only 4:2:2 takes the new column.
9021+ let above_mi = (mi_r.saturating_sub(1), mi_c);
9022+ let left_mi = (mi_r, mi_c.saturating_sub(1));
9023+ let above = match self.uv_mode_col.get(above_mi.1) {
9024+ _ if have_above && let Some(m) = cell(&self.uv_mode_grid, above_mi.0, above_mi.1) => m,
9025+ Some(&(row, m)) if have_above && usize::from(row) == above_mi.0 => usize::from(m),
89979026 _ if have_above => self.above_uv_mode[c],
89989027 _ => DC_PRED,
89999028 };
9000- let left = match self.uv_mode_row.get(mi_r) {
9001- _ if have_left && let Some(m) = cell(&self.uv_mode_grid, mi_r, mi_c - 1) => m,
9002- Some(&(col, m)) if have_left && usize::from(col) == mi_c - 1 => usize::from(m),
9029+ let left = match self.uv_mode_row.get(left_mi.0) {
9030+ _ if have_left && let Some(m) = cell(&self.uv_mode_grid, left_mi.0, left_mi.1) => m,
9031+ Some(&(col, m)) if have_left && usize::from(col) == left_mi.1 => usize::from(m),
90039032 _ if have_left => self.left_uv_mode[r],
90049033 _ => DC_PRED,
90059034 };
@@ -15476,7 +15505,7 @@ fn decode_rect4_16_strip(
1547615505 // directional chroma strip, moving 4 samples by 1.
1547715506 let smooth_neighbor_uv =
1547815507 neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx);
15479- if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c)
15508+ if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c, (ss_x(fctx), ss_y(fctx)))
1548015509 {
1548115510 hit!(RECT4_16_UV_PAIR_FILT_HITS);
1548215511 }
@@ -32094,7 +32123,7 @@ pub(crate) fn obmc_plan(
3209432123 // divides by zero at 4:4:4 (`trailing_zeros(0)` = 64, a debug shift panic).
3209532124 ss_x: usize,
3209632125 ss_y: usize,
32097- chroma_side: usize,
32126+ chroma_stride: usize,
3209832127 px: usize,
3209932128 py: usize,
3210032129 cpx: usize,
@@ -32209,7 +32238,7 @@ pub(crate) fn obmc_plan(
3220932238 above,
3221032239 left,
3221132240 side,
32212- chroma_side,
32241+ chroma_stride,
3221332242 write_w,
3221432243 write_h,
3221532244 px,
@@ -32292,7 +32321,16 @@ pub(crate) struct ObmcPlan {
3229232321 above: Vec<ObmcNb>,
3229332322 left: Vec<ObmcNb>,
3229432323 side: usize,
32295- chroma_side: usize,
32324+ /// The chroma PREDICTION buffer's own stride -- `chroma_stride`, the PLANE
32325+ /// BLOCK's per-axis width, NOT the enclosing square `chroma_side`. At
32326+ /// 4:2:2 that buffer is `(side/2, side)` (lane-av1-422blockhalf), and
32327+ /// striding it with `chroma_side` put row `r` at `r*side`: a 32x16 luma
32328+ /// strip's left-pass chroma blend wrote row 15 at index 15*32 = 480 of a
32329+ /// 256-sample `16 x 16` buffer -- the out-of-bounds panic in
32330+ /// `obmc_blend_h` the pinned 4:2:2 rotzoom stream opened. Every other
32331+ /// consumer of `pred_u`/`pred_v` in this block already strides with
32332+ /// `chroma_stride`; at 4:2:0 and 4:4:4 the two are equal.
32333+ chroma_stride: usize,
3229632334 write_w: usize,
3229732335 write_h: usize,
3229832336 px: usize,
@@ -32319,7 +32357,7 @@ pub(crate) fn obmc_run(
3231932357 ) {
3232032358 let &ObmcPlan {
3232132359 side,
32322- chroma_side,
32360+ chroma_stride,
3232332361 write_w,
3232432362 write_h,
3232532363 px,
@@ -32366,7 +32404,7 @@ pub(crate) fn obmc_run(
3236632404 let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));
3236732405 eprintln!("OUR_MCB pre f={idx} cpx={cpx} cpy={cpy} cw={cw} ch={ch}");
3236832406 for r in 0..ch {
32369- let row: Vec<u16> = (0..cw).map(|c| pred_u[r * chroma_side + c]).collect();
32407+ let row: Vec<u16> = (0..cw).map(|c| pred_u[r * chroma_stride + c]).collect();
3237032408 eprintln!("OUR_MCB prerow{r}: {row:?}");
3237132409 }
3237232410 }
@@ -32390,9 +32428,9 @@ pub(crate) fn obmc_run(
3239032428 (bw >> ss_x(fctx), overlap_above >> ss_y(fctx), ox >> ss_x(fctx));
3239132429 let cw = cbw.min((write_w >> ss_x(fctx)) - cox);
3239232430 obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);
32393- obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);
32431+ obmc_blend_v(pred_u, chroma_stride, cox, 0, cw, cbh, cbw, &tmp_u);
3239432432 obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
32395- obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v);
32433+ obmc_blend_v(pred_v, chroma_stride, cox, 0, cw, cbh, cbw, &tmp_v);
3239632434 }
3239732435 }
3239832436
@@ -32417,14 +32455,14 @@ pub(crate) fn obmc_run(
3241732455 }
3241832456 }
3241932457 let ch = cbh.min((write_h >> ss_y(fctx)) - coy);
32420- obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);
32458+ obmc_blend_h(pred_u, chroma_stride, 0, coy, cbw, ch, &tmp_u);
3242132459 obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);
32422- obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);
32460+ obmc_blend_h(pred_v, chroma_stride, 0, coy, cbw, ch, &tmp_v);
3242332461 }
3242432462 if let Some((_, _, idx)) = ec_mcb {
3242532463 let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));
3242632464 for r in 0..ch {
32427- let row: Vec<u16> = (0..cw).map(|c| pred_u[r * chroma_side + c]).collect();
32465+ let row: Vec<u16> = (0..cw).map(|c| pred_u[r * chroma_stride + c]).collect();
3242832466 eprintln!("OUR_MCB post f={idx} row{r}: {row:?}");
3242932467 }
3243032468 }
@@ -35351,7 +35389,7 @@ fn decode_inter_block(
3535135389 write_h,
3535235390 ss_x(fctx),
3535335391 ss_y(fctx),
35354- chroma_side,
35392+ chroma_stride,
3535535393 px,
3535635394 py,
3535735395 cpx,