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 {
8953 // mi(5,15): left neighbour SMOOTH_V at mi(5,14), read at mi(4,13)).8953 // mi(5,15): left neighbour SMOOTH_V at mi(5,14), read at mi(4,13)).
8954 let snap_y = (1usize << ss_y(fctx)) - 1;8954 let snap_y = (1usize << ss_y(fctx)) - 1;
8955 let snap_x = (1usize << ss_x(fctx)) - 1;8955 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+ )
8957 }8975 }
8958 8976
8959 /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e.8977 /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e.
@@ -8967,6 +8985,7 @@ impl Neighbours {
8967 mi_c: usize,8985 mi_c: usize,
8968 r: usize,8986 r: usize,
8969 c: usize,8987 c: usize,
8988+ (ss_x, ss_y): (usize, usize),
8970 ) -> bool {8989 ) -> bool {
8971 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the8990 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the
8972 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid8991 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid
@@ -8991,15 +9010,25 @@ impl Neighbours {
8991 .filter(|&m| m != u8::MAX)9010 .filter(|&m| m != u8::MAX)
8992 .map(usize::from)9011 .map(usize::from)
8993 };9012 };
8994- let above = match self.uv_mode_col.get(mi_c) {9013+ // libaom's two chroma-reference mi, per the shift the caller applies.
8995- _ if have_above && let Some(m) = cell(&self.uv_mode_grid, mi_r - 1, mi_c) => m,9014+ // 4:2:2 ONLY. `ss_y == 0` makes the above reference's row term
8996- Some(&(row, m)) if have_above && usize::from(row) == mi_r - 1 => usize::from(m),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),
8997 _ if have_above => self.above_uv_mode[c],9026 _ if have_above => self.above_uv_mode[c],
8998 _ => DC_PRED,9027 _ => DC_PRED,
8999 };9028 };
9000- let left = match self.uv_mode_row.get(mi_r) {9029+ let left = match self.uv_mode_row.get(left_mi.0) {
9001- _ if have_left && let Some(m) = cell(&self.uv_mode_grid, mi_r, mi_c - 1) => m,9030+ _ if have_left && let Some(m) = cell(&self.uv_mode_grid, left_mi.0, left_mi.1) => m,
9002- Some(&(col, m)) if have_left && usize::from(col) == mi_c - 1 => usize::from(m),9031+ Some(&(col, m)) if have_left && usize::from(col) == left_mi.1 => usize::from(m),
9003 _ if have_left => self.left_uv_mode[r],9032 _ if have_left => self.left_uv_mode[r],
9004 _ => DC_PRED,9033 _ => DC_PRED,
9005 };9034 };
@@ -15476,7 +15505,7 @@ fn decode_rect4_16_strip(
15476 // directional chroma strip, moving 4 samples by 1.15505 // directional chroma strip, moving 4 samples by 1.
15477 let smooth_neighbor_uv =15506 let smooth_neighbor_uv =
15478 neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx);15507 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)))
15480 {15509 {
15481 hit!(RECT4_16_UV_PAIR_FILT_HITS);15510 hit!(RECT4_16_UV_PAIR_FILT_HITS);
15482 }15511 }
@@ -32094,7 +32123,7 @@ pub(crate) fn obmc_plan(
32094 // divides by zero at 4:4:4 (`trailing_zeros(0)` = 64, a debug shift panic).32123 // divides by zero at 4:4:4 (`trailing_zeros(0)` = 64, a debug shift panic).
32095 ss_x: usize,32124 ss_x: usize,
32096 ss_y: usize,32125 ss_y: usize,
32097- chroma_side: usize,32126+ chroma_stride: usize,
32098 px: usize,32127 px: usize,
32099 py: usize,32128 py: usize,
32100 cpx: usize,32129 cpx: usize,
@@ -32209,7 +32238,7 @@ pub(crate) fn obmc_plan(
32209 above,32238 above,
32210 left,32239 left,
32211 side,32240 side,
32212- chroma_side,32241+ chroma_stride,
32213 write_w,32242 write_w,
32214 write_h,32243 write_h,
32215 px,32244 px,
@@ -32292,7 +32321,16 @@ pub(crate) struct ObmcPlan {
32292 above: Vec<ObmcNb>,32321 above: Vec<ObmcNb>,
32293 left: Vec<ObmcNb>,32322 left: Vec<ObmcNb>,
32294 side: usize,32323 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,
32296 write_w: usize,32334 write_w: usize,
32297 write_h: usize,32335 write_h: usize,
32298 px: usize,32336 px: usize,
@@ -32319,7 +32357,7 @@ pub(crate) fn obmc_run(
32319 ) {32357 ) {
32320 let &ObmcPlan {32358 let &ObmcPlan {
32321 side,32359 side,
32322- chroma_side,32360+ chroma_stride,
32323 write_w,32361 write_w,
32324 write_h,32362 write_h,
32325 px,32363 px,
@@ -32366,7 +32404,7 @@ pub(crate) fn obmc_run(
32366 let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));32404 let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));
32367 eprintln!("OUR_MCB pre f={idx} cpx={cpx} cpy={cpy} cw={cw} ch={ch}");32405 eprintln!("OUR_MCB pre f={idx} cpx={cpx} cpy={cpy} cw={cw} ch={ch}");
32368 for r in 0..ch {32406 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();
32370 eprintln!("OUR_MCB prerow{r}: {row:?}");32408 eprintln!("OUR_MCB prerow{r}: {row:?}");
32371 }32409 }
32372 }32410 }
@@ -32390,9 +32428,9 @@ pub(crate) fn obmc_run(
32390 (bw >> ss_x(fctx), overlap_above >> ss_y(fctx), ox >> ss_x(fctx));32428 (bw >> ss_x(fctx), overlap_above >> ss_y(fctx), ox >> ss_x(fctx));
32391 let cw = cbw.min((write_w >> ss_x(fctx)) - cox);32429 let cw = cbw.min((write_w >> ss_x(fctx)) - cox);
32392 obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_u, fctx);32430 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);
32394 obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);32432 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);
32396 }32434 }
32397 }32435 }
32398 32436
@@ -32417,14 +32455,14 @@ pub(crate) fn obmc_run(
32417 }32455 }
32418 }32456 }
32419 let ch = cbh.min((write_h >> ss_y(fctx)) - coy);32457 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);
32421 obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, nb.h_kind, nb.v_kind, nb.scale, &mut tmp_v, fctx);32459 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);
32423 }32461 }
32424 if let Some((_, _, idx)) = ec_mcb {32462 if let Some((_, _, idx)) = ec_mcb {
32425 let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));32463 let (cw, ch) = (write_w >> ss_x(fctx), write_h >> ss_y(fctx));
32426 for r in 0..ch {32464 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();
32428 eprintln!("OUR_MCB post f={idx} row{r}: {row:?}");32466 eprintln!("OUR_MCB post f={idx} row{r}: {row:?}");
32429 }32467 }
32430 }32468 }
@@ -35351,7 +35389,7 @@ fn decode_inter_block(
35351 write_h,35389 write_h,
35352 ss_x(fctx),35390 ss_x(fctx),
35353 ss_y(fctx),35391 ss_y(fctx),
35354- chroma_side,35392+ chroma_stride,
35355 px,35393 px,
35356 py,35394 py,
35357 cpx,35395 cpx,