vp9kf: tile-ROW streams decode byte-exact -- MI-aligned extents, frame-scoped contexts
Browse files at this commit332f251105237ec952a381f49128aa843700d539Parent: bd4fadc6 changed files +392 -108
- crates/ec-vp9/src/decode.rs +62 -42
- crates/ec-vp9/src/intra.rs +76 -38
- crates/ec-vp9/src/loopfilter.rs +10 -9
- crates/ec-vp9/src/modes.rs +38 -16
- crates/ec-vp9/tests/scratch_tiledbg.rs +4 -0
- lanes/vp9kf.report.md +202 -3
crates/ec-vp9/src/decode.rsmodified+62 -42
| @@ -244,6 +244,30 @@ impl Decoder { | ||
| 244 | 244 | mi_rows, |
| 245 | 245 | }; |
| 246 | 246 | let mut ti = 0usize; |
| 247 | + // `above_context` / `above_seg_context` and the mi grid are | |
| 248 | + // FRAME-scoped in libvpx: `cm->above_context` is memset once per | |
| 249 | + // frame BEFORE the tile loop (vp9_decodeframe.c:2079-2080 / :2082-2083, | |
| 250 | + // inside the :2077-2083 block), the | |
| 251 | + // shared `cm->mi_grid_visible` accumulates every tile's records, and | |
| 252 | + // the buffers are indexed by ABSOLUTE mi_row/mi_col | |
| 253 | + // (`set_skip_context`, vp9_onyxc_int.h:405-413). A tile row k > 0 | |
| 254 | + // therefore reads above state written by tile row k - 1 — tiles are | |
| 255 | + // disjoint in COLUMN only. Allocating these per tile would discard | |
| 256 | + // that above state and mis-gate `xd->above_mi`, so they live here and | |
| 257 | + // are zeroed exactly once per frame. | |
| 258 | + // libvpx sizes `cm->above_context` by `mi_cols_aligned_to_sb` and the | |
| 259 | + // mi grid stride by `mi_cols`; the above arrays are written/indexed up | |
| 260 | + // to a whole TX_32X32 (8 4x4 units) past the last mi col, so a | |
| 261 | + // non-multiple-of-8 width would otherwise index out of bounds. | |
| 262 | + let aligned_cols = mi_cols.div_ceil(SB_MI) * SB_MI; | |
| 263 | + let mut ectx = [ | |
| 264 | + PlaneContexts::new(aligned_cols * 2), | |
| 265 | + PlaneContexts::new(aligned_cols), | |
| 266 | + PlaneContexts::new(aligned_cols), | |
| 267 | + ]; | |
| 268 | + ectx.iter_mut().for_each(|p| p.above.fill(0)); | |
| 269 | + let mut mi = MiState::new(mi_cols, mi_rows); | |
| 270 | + mi.above_seg.fill(0); | |
| 247 | 271 | for tr in 0..tile_rows { |
| 248 | 272 | let row_lo = ((sb64_rows * tr) >> hdr.tile_info.rows_log2) * SB_MI; |
| 249 | 273 | let row_hi = (((sb64_rows * (tr + 1)) >> hdr.tile_info.rows_log2) * SB_MI).min(mi_rows); |
| @@ -260,35 +284,19 @@ impl Decoder { | ||
| 260 | 284 | } |
| 261 | 285 | let mut r = crate::bool::BoolDecoder::new(tiles[ti])?; |
| 262 | 286 | ti += 1; |
| 263 | - let mut ectx = [ | |
| 264 | - PlaneContexts::new(mi_cols * 2), | |
| 265 | - PlaneContexts::new(mi_cols), | |
| 266 | - PlaneContexts::new(mi_cols), | |
| 267 | - ]; | |
| 268 | - let mut mi = MiState::new(mi_cols, mi_rows); | |
| 269 | - ectx.iter_mut().for_each(|p| p.above.fill(0)); | |
| 270 | - mi.above_seg.fill(0); | |
| 271 | 287 | for sb_row in (row_lo..row_hi).step_by(SB_MI) { |
| 272 | 288 | // libvpx zeroes the left ENTROPY and PARTITION contexts at |
| 273 | 289 | // the start of EVERY superblock row, not just the tile's |
| 274 | - // first one (vp9_decodeframe.c:2256-2258 plain | |
| 275 | - // `decode_tiles`; the row-mt twin is :2114-2115 and the | |
| 276 | - // per-tile-row twins :1825-1826 / :1898-1899): the left | |
| 290 | + // first one (vp9_decodeframe.c:2260-2261 plain | |
| 291 | + // `decode_tiles`; the row-mt twin is :2117-2118 and the | |
| 292 | + // per-tile-row twins :1828-1829 / :1901-1902): the left | |
| 277 | 293 | // edge of an SB row has no pixels to its left. Our luma |
| 278 | 294 | // left index wraps at mi_row 16, so a stale value from two |
| 279 | 295 | // SB rows earlier would otherwise be read here. |
| 280 | - // `above_context`/`above_seg_context` are frame-scoped in | |
| 281 | - // libvpx (`memset` at :2076-2080, before the tile-row | |
| 282 | - // loop) and indexed by ABSOLUTE mi_col (`set_skip_context`, | |
| 283 | - // vp9_onyxc_int.h:409-412), so zeroing them once per tile | |
| 284 | - // is equivalent only for `log2_tile_rows == 0`, where the | |
| 285 | - // disjoint-column argument holds (each tile's xd points | |
| 286 | - // into its own column range: vp9_init_macroblockd, | |
| 287 | - // vp9_onyxc_int.h:381-393). With tile ROWS the first SB row | |
| 288 | - // of tile row k > 0 may legitimately read above state | |
| 289 | - // written by tile row k - 1, which the fills at :269-270 | |
| 290 | - // discard: the tile-row path is NOT equivalent and is not | |
| 291 | - // handled here. | |
| 296 | + // `above_context`/`above_seg_context` are frame-scoped | |
| 297 | + // (memset once per frame at :2079-2083, before the tile | |
| 298 | + // loop) and indexed by ABSOLUTE mi_col, so they persist | |
| 299 | + // across tile rows and are NOT reset here. | |
| 292 | 300 | ectx.iter_mut().for_each(|p| p.left = [0; 32]); |
| 293 | 301 | mi.left_seg = [0; 32]; |
| 294 | 302 | for sb_col in (col_lo..col_hi).step_by(SB_MI) { |
| @@ -302,7 +310,6 @@ impl Decoder { | ||
| 302 | 310 | sb_row, |
| 303 | 311 | sb_col, |
| 304 | 312 | 4, |
| 305 | - row_lo, | |
| 306 | 313 | col_lo, |
| 307 | 314 | tx_mode, |
| 308 | 315 | )?; |
| @@ -326,7 +333,6 @@ impl Decoder { | ||
| 326 | 333 | p.uvs, |
| 327 | 334 | vw, |
| 328 | 335 | vh, |
| 329 | - vw / 2, | |
| 330 | 336 | vh / 2, |
| 331 | 337 | hdr.loop_filter.sharpness, |
| 332 | 338 | ); |
| @@ -366,7 +372,6 @@ impl Decoder { | ||
| 366 | 372 | row: usize, |
| 367 | 373 | col: usize, |
| 368 | 374 | n4: usize, |
| 369 | - tile_row_start: usize, | |
| 370 | 375 | tile_col_start: usize, |
| 371 | 376 | tx_mode: u8, |
| 372 | 377 | ) -> Result<()> { |
| @@ -410,7 +415,6 @@ impl Decoder { | ||
| 410 | 415 | subsize, |
| 411 | 416 | 1, |
| 412 | 417 | 1, |
| 413 | - tile_row_start, | |
| 414 | 418 | tile_col_start, |
| 415 | 419 | tx_mode, |
| 416 | 420 | )?; |
| @@ -428,7 +432,6 @@ impl Decoder { | ||
| 428 | 432 | subsize, |
| 429 | 433 | n4, |
| 430 | 434 | n4, |
| 431 | - tile_row_start, | |
| 432 | 435 | tile_col_start, |
| 433 | 436 | tx_mode, |
| 434 | 437 | )?, |
| @@ -445,7 +448,6 @@ impl Decoder { | ||
| 445 | 448 | subsize, |
| 446 | 449 | n4, |
| 447 | 450 | n8, |
| 448 | - tile_row_start, | |
| 449 | 451 | tile_col_start, |
| 450 | 452 | tx_mode, |
| 451 | 453 | )?; |
| @@ -462,7 +464,6 @@ impl Decoder { | ||
| 462 | 464 | subsize, |
| 463 | 465 | n4, |
| 464 | 466 | n8, |
| 465 | - tile_row_start, | |
| 466 | 467 | tile_col_start, |
| 467 | 468 | tx_mode, |
| 468 | 469 | )?; |
| @@ -481,7 +482,6 @@ impl Decoder { | ||
| 481 | 482 | subsize, |
| 482 | 483 | n8, |
| 483 | 484 | n4, |
| 484 | - tile_row_start, | |
| 485 | 485 | tile_col_start, |
| 486 | 486 | tx_mode, |
| 487 | 487 | )?; |
| @@ -498,7 +498,6 @@ impl Decoder { | ||
| 498 | 498 | subsize, |
| 499 | 499 | n8, |
| 500 | 500 | n4, |
| 501 | - tile_row_start, | |
| 502 | 501 | tile_col_start, |
| 503 | 502 | tx_mode, |
| 504 | 503 | )?; |
| @@ -521,7 +520,6 @@ impl Decoder { | ||
| 521 | 520 | rr, |
| 522 | 521 | cc, |
| 523 | 522 | n8, |
| 524 | - tile_row_start, | |
| 525 | 523 | tile_col_start, |
| 526 | 524 | tx_mode, |
| 527 | 525 | )?; |
| @@ -550,7 +548,6 @@ impl Decoder { | ||
| 550 | 548 | sb_type: usize, |
| 551 | 549 | bwl: usize, |
| 552 | 550 | bhl: usize, |
| 553 | - tile_row_start: usize, | |
| 554 | 551 | tile_col_start: usize, |
| 555 | 552 | tx_mode: u8, |
| 556 | 553 | ) -> Result<()> { |
| @@ -569,10 +566,9 @@ impl Decoder { | ||
| 569 | 566 | sb_type, |
| 570 | 567 | x_mis, |
| 571 | 568 | y_mis, |
| 572 | - tile_row_start, | |
| 573 | 569 | tile_col_start, |
| 574 | 570 | tx_mode, |
| 575 | - &self.ctx.skip, | |
| 571 | + &self.ctx, | |
| 576 | 572 | )?; |
| 577 | 573 | |
| 578 | 574 | // Per-plane 4x4 counts. Sub-8x8 shapes still occupy the WHOLE 8x8 |
| @@ -650,7 +646,6 @@ impl Decoder { | ||
| 650 | 646 | bh, |
| 651 | 647 | mb_to_right, |
| 652 | 648 | mb_to_bottom, |
| 653 | - tile_row_start, | |
| 654 | 649 | tile_col_start, |
| 655 | 650 | )?; |
| 656 | 651 | } |
| @@ -687,7 +682,6 @@ impl Decoder { | ||
| 687 | 682 | bh: usize, |
| 688 | 683 | mb_to_right: i32, |
| 689 | 684 | mb_to_bottom: i32, |
| 690 | - tile_row_start: usize, | |
| 691 | 685 | tile_col_start: usize, |
| 692 | 686 | ) -> Result<()> { |
| 693 | 687 | let s = usize::from(plane != 0); |
| @@ -701,12 +695,16 @@ impl Decoder { | ||
| 701 | 695 | info.uv_mode |
| 702 | 696 | }; |
| 703 | 697 | let planes = self.planes.as_mut().expect("frame scratch"); |
| 704 | - let (pw, ph) = planes.dims(plane); | |
| 705 | - let stride = pw; | |
| 698 | + let stride = planes.dims(plane).0; | |
| 706 | 699 | let bs = 4 << tx_size; |
| 707 | 700 | let x0 = ((mi_col * 8) >> s) + tx_col * 4; |
| 708 | 701 | let y0 = ((mi_row * 8) >> s) + tx_row * 4; |
| 709 | - let up = tx_row != 0 || mi_row > tile_row_start; | |
| 702 | + // vp9_predict_intra_block `have_top = loff || (xd->above_mi != NULL)` | |
| 703 | + // (vp9_reconintra.c:411); `above_mi` is FRAME-gated | |
| 704 | + // (`set_mi_row_col`, vp9_onyxc_int.h:430: `mi_row != 0`), NOT | |
| 705 | + // tile-row-gated. The above row of a tile row k > 0 is decoded by | |
| 706 | + // tile row k - 1 and is available. | |
| 707 | + let up = tx_row != 0 || mi_row > 0; | |
| 710 | 708 | let lft = tx_col != 0 || mi_col > tile_col_start; |
| 711 | 709 | // vp9_predict_intra_block `have_right`: the tx block is not in the |
| 712 | 710 | // last tx column of ITS OWN block (pd->n4_w units) — above-right |
| @@ -714,10 +712,32 @@ impl Decoder { | ||
| 714 | 712 | // neighbour, so it must stage as unavailable. |
| 715 | 713 | let rgt = tx_col + (1usize << tx_size) < bw * 2 >> s; |
| 716 | 714 | |
| 715 | + // `xd->cur_buf->y_width/y_height` (vp9_reconintra.c:288-292) are the | |
| 716 | + // MI-ALIGNED (8-multiple) buffer extent, not the visible coded size: | |
| 717 | + // confirmed by instrumenting the oracle's staging for a 320x242 frame | |
| 718 | + // (`fh=248`, not 242). The extend-vs-direct DECISION is `mb_to_*_edge` | |
| 719 | + // (`:302/326/354`, passed in as `bot_ext`/`right_ext`). | |
| 720 | + let vw = (hdr.mi_cols() as usize * 8) >> s; | |
| 721 | + let vh = (hdr.mi_rows() as usize * 8) >> s; | |
| 722 | + | |
| 717 | 723 | // 1. Intra prediction (reads reconstructed neighbours). |
| 718 | 724 | { |
| 719 | 725 | let (data, _) = planes.plane(plane); |
| 720 | - build_intra_predictors(data, stride, pw, ph, x0, y0, mode, bs, up, lft, rgt); | |
| 726 | + build_intra_predictors( | |
| 727 | + data, | |
| 728 | + stride, | |
| 729 | + vw, | |
| 730 | + vh, | |
| 731 | + x0, | |
| 732 | + y0, | |
| 733 | + mode, | |
| 734 | + bs, | |
| 735 | + up, | |
| 736 | + lft, | |
| 737 | + rgt, | |
| 738 | + mb_to_bottom < 0, | |
| 739 | + mb_to_right < 0, | |
| 740 | + ); | |
| 721 | 741 | } |
| 722 | 742 | |
| 723 | 743 | if info.skip { |
crates/ec-vp9/src/intra.rsmodified+76 -38
| @@ -54,6 +54,13 @@ pub(crate) fn build_intra_predictors( | ||
| 54 | 54 | up_available: bool, |
| 55 | 55 | left_available: bool, |
| 56 | 56 | right_available: bool, |
| 57 | + // `xd->mb_to_bottom_edge < 0` — the MI-ALIGNED block extent overruns the | |
| 58 | + // frame bottom. This is the extend-vs-direct DECISION | |
| 59 | + // (`vp9_reconintra.c:302`); `frame_h` is used only for the extension | |
| 60 | + // LENGTH (`:288-292`). | |
| 61 | + bot_ext: bool, | |
| 62 | + // `xd->mb_to_right_edge < 0` (`vp9_reconintra.c:326/354`). | |
| 63 | + right_ext: bool, | |
| 57 | 64 | ) { |
| 58 | 65 | let (need_left, need_above, need_aboveright) = needs(mode); |
| 59 | 66 | let mut left_col = [0u8; 32]; |
| @@ -62,40 +69,50 @@ pub(crate) fn build_intra_predictors( | ||
| 62 | 69 | data[(((y0 as isize + dy) * stride as isize) + x0 as isize + dx) as usize] |
| 63 | 70 | }; |
| 64 | 71 | |
| 72 | + // NEED_LEFT (vp9_reconintra.c:300-320). `extend_bottom` is `int` in C: | |
| 73 | + // `y0 > frame_height` must not underflow, so it is computed in isize. | |
| 65 | 74 | if need_left { |
| 66 | 75 | if left_available { |
| 67 | - if y0 + bs <= frame_h { | |
| 76 | + let extend_bottom = frame_h as isize - y0 as isize; | |
| 77 | + if !bot_ext || extend_bottom >= bs as isize { | |
| 68 | 78 | for i in 0..bs { |
| 69 | 79 | left_col[i] = at(-1, i as isize); |
| 70 | 80 | } |
| 71 | 81 | } else { |
| 72 | - let extend_bottom = frame_h - y0; | |
| 73 | - for i in 0..extend_bottom { | |
| 82 | + let n = extend_bottom.max(0) as usize; | |
| 83 | + for i in 0..n { | |
| 74 | 84 | left_col[i] = at(-1, i as isize); |
| 75 | 85 | } |
| 76 | - for i in extend_bottom..bs { | |
| 77 | - left_col[i] = at(-1, extend_bottom as isize - 1); | |
| 78 | - } | |
| 86 | + // `ref[(extend_bottom - 1) * ref_stride - 1]` — always the last | |
| 87 | + // VISIBLE row (`y0 + extend_bottom - 1 == frame_h - 1`). | |
| 88 | + let v = at(-1, extend_bottom - 1); | |
| 89 | + left_col[n..bs].fill(v); | |
| 79 | 90 | } |
| 80 | 91 | } else { |
| 81 | 92 | left_col[..bs].fill(129); |
| 82 | 93 | } |
| 83 | 94 | } |
| 84 | 95 | |
| 96 | + // NEED_ABOVE (vp9_reconintra.c:322-348). | |
| 85 | 97 | if need_above { |
| 86 | 98 | if up_available { |
| 87 | - if x0 + bs <= frame_w { | |
| 88 | - for i in 0..bs { | |
| 89 | - above_data[A + i] = at(i as isize, -1); | |
| 99 | + if right_ext { | |
| 100 | + if x0 + bs <= frame_w { | |
| 101 | + for i in 0..bs { | |
| 102 | + above_data[A + i] = at(i as isize, -1); | |
| 103 | + } | |
| 104 | + } else if x0 <= frame_w { | |
| 105 | + let r = frame_w - x0; | |
| 106 | + for i in 0..r { | |
| 107 | + above_data[A + i] = at(i as isize, -1); | |
| 108 | + } | |
| 109 | + let v = above_data[A + r - 1]; | |
| 110 | + above_data[A + r..A + bs].fill(v); | |
| 90 | 111 | } |
| 91 | - } else if x0 <= frame_w { | |
| 92 | - let r = frame_w - x0; | |
| 93 | - for i in 0..r { | |
| 112 | + } else { | |
| 113 | + for i in 0..bs { | |
| 94 | 114 | above_data[A + i] = at(i as isize, -1); |
| 95 | 115 | } |
| 96 | - let v = above_data[A + r - 1]; | |
| 97 | - let n = x0 + bs - frame_w; | |
| 98 | - above_data[A + r..A + r + n].fill(v); | |
| 99 | 116 | } |
| 100 | 117 | above_data[A - 1] = if left_available { at(-1, -1) } else { 129 }; |
| 101 | 118 | } else { |
| @@ -104,37 +121,58 @@ pub(crate) fn build_intra_predictors( | ||
| 104 | 121 | } |
| 105 | 122 | } |
| 106 | 123 | |
| 124 | + // NEED_ABOVERIGHT (vp9_reconintra.c:350-394). | |
| 107 | 125 | if need_aboveright { |
| 108 | 126 | if up_available { |
| 109 | - if x0 + 2 * bs <= frame_w { | |
| 110 | - for i in 0..2 * bs { | |
| 111 | - above_data[A + i] = at(i as isize, -1); | |
| 112 | - } | |
| 113 | - if !(bs == 4 && right_available) { | |
| 114 | - let v = above_data[A + bs - 1]; | |
| 115 | - above_data[A + bs..A + 2 * bs].fill(v); | |
| 127 | + let fill_bs = |d: &mut [u8; 80]| { | |
| 128 | + let v = d[A + bs - 1]; | |
| 129 | + d[A + bs..A + 2 * bs].fill(v); | |
| 130 | + }; | |
| 131 | + if right_ext { | |
| 132 | + if x0 + 2 * bs <= frame_w { | |
| 133 | + if bs == 4 && right_available { | |
| 134 | + for i in 0..2 * bs { | |
| 135 | + above_data[A + i] = at(i as isize, -1); | |
| 136 | + } | |
| 137 | + } else { | |
| 138 | + for i in 0..bs { | |
| 139 | + above_data[A + i] = at(i as isize, -1); | |
| 140 | + } | |
| 141 | + fill_bs(&mut above_data); | |
| 142 | + } | |
| 143 | + } else if x0 + bs <= frame_w { | |
| 144 | + let r = frame_w - x0; | |
| 145 | + if bs == 4 && right_available { | |
| 146 | + for i in 0..r { | |
| 147 | + above_data[A + i] = at(i as isize, -1); | |
| 148 | + } | |
| 149 | + let v = above_data[A + r - 1]; | |
| 150 | + above_data[A + r..A + 2 * bs].fill(v); | |
| 151 | + } else { | |
| 152 | + for i in 0..bs { | |
| 153 | + above_data[A + i] = at(i as isize, -1); | |
| 154 | + } | |
| 155 | + fill_bs(&mut above_data); | |
| 156 | + } | |
| 157 | + } else if x0 <= frame_w { | |
| 158 | + let r = frame_w - x0; | |
| 159 | + for i in 0..r { | |
| 160 | + above_data[A + i] = at(i as isize, -1); | |
| 161 | + } | |
| 162 | + let v = above_data[A + r - 1]; | |
| 163 | + above_data[A + r..A + 2 * bs].fill(v); | |
| 116 | 164 | } |
| 117 | - } else if x0 + bs <= frame_w { | |
| 118 | - let r = frame_w - x0; | |
| 119 | - for i in 0..r { | |
| 165 | + } else { | |
| 166 | + for i in 0..bs { | |
| 120 | 167 | above_data[A + i] = at(i as isize, -1); |
| 121 | 168 | } |
| 122 | 169 | if bs == 4 && right_available { |
| 123 | - let v = above_data[A + r - 1]; | |
| 124 | - let n = x0 + 2 * bs - frame_w; | |
| 125 | - above_data[A + r..A + r + n].fill(v); | |
| 170 | + for i in 0..bs { | |
| 171 | + above_data[A + bs + i] = at((bs + i) as isize, -1); | |
| 172 | + } | |
| 126 | 173 | } else { |
| 127 | - let v = above_data[A + bs - 1]; | |
| 128 | - above_data[A + bs..A + 2 * bs].fill(v); | |
| 129 | - } | |
| 130 | - } else if x0 <= frame_w { | |
| 131 | - let r = frame_w - x0; | |
| 132 | - for i in 0..r { | |
| 133 | - above_data[A + i] = at(i as isize, -1); | |
| 174 | + fill_bs(&mut above_data); | |
| 134 | 175 | } |
| 135 | - let v = above_data[A + r - 1]; | |
| 136 | - let n = x0 + 2 * bs - frame_w; | |
| 137 | - above_data[A + r..A + r + n].fill(v); | |
| 138 | 176 | } |
| 139 | 177 | above_data[A - 1] = if left_available { at(-1, -1) } else { 129 }; |
| 140 | 178 | } else { |
crates/ec-vp9/src/loopfilter.rsmodified+10 -9
| @@ -512,8 +512,11 @@ impl LfGrids { | ||
| 512 | 512 | self.level8[r * self.mi_cols + c] |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - /// Filter the frame's three planes in place. `y_w/h`, `uv_w/h` are | |
| 516 | - /// the coded (aligned) plane sizes. | |
| 515 | + /// Filter the frame's three planes in place. `y_w/h` are the coded | |
| 516 | + /// (aligned) plane sizes; `uv_h` is the chroma height. The chroma | |
| 517 | + /// column pass takes NO width bound (vp9_loopfilter.c:1394 iterates all | |
| 518 | + /// `MI_BLOCK_SIZE >> 1` column groups and `filter_selectively_vert_row2` | |
| 519 | + /// writes whole 8-column groups into the padded plane). | |
| 517 | 520 | pub(crate) fn filter_frame( |
| 518 | 521 | &self, |
| 519 | 522 | y: &mut [u8], |
| @@ -523,7 +526,6 @@ impl LfGrids { | ||
| 523 | 526 | uv_stride: usize, |
| 524 | 527 | y_w: usize, |
| 525 | 528 | y_h: usize, |
| 526 | - uv_w: usize, | |
| 527 | 529 | uv_h: usize, |
| 528 | 530 | sharpness: u8, |
| 529 | 531 | ) { |
| @@ -765,7 +767,7 @@ impl LfGrids { | ||
| 765 | 767 | continue; |
| 766 | 768 | } |
| 767 | 769 | let (bl, li, th) = limits(lvl, sharpness); |
| 768 | - if x8 >= 4 && x8 + 4 <= uv_w { | |
| 770 | + if x8 >= 4 { | |
| 769 | 771 | let taps = if left[TX_16X16] & bit != 0 { |
| 770 | 772 | 16 |
| 771 | 773 | } else if left[TX_8X8] & bit != 0 { |
| @@ -776,7 +778,7 @@ impl LfGrids { | ||
| 776 | 778 | 0 |
| 777 | 779 | }; |
| 778 | 780 | if taps != 0 { |
| 779 | - let t = if taps == 16 && (x8 < 8 || x8 + 8 > uv_w) { | |
| 781 | + let t = if taps == 16 && x8 < 8 { | |
| 780 | 782 | 8 |
| 781 | 783 | } else { |
| 782 | 784 | taps |
| @@ -794,7 +796,7 @@ impl LfGrids { | ||
| 794 | 796 | ); |
| 795 | 797 | } |
| 796 | 798 | } |
| 797 | - if int4 & bit != 0 && x8 + 8 <= uv_w { | |
| 799 | + if int4 & bit != 0 { | |
| 798 | 800 | lpf_edge( |
| 799 | 801 | data, |
| 800 | 802 | y8 * uv_stride + x8 + 4, |
| @@ -826,7 +828,7 @@ impl LfGrids { | ||
| 826 | 828 | continue; |
| 827 | 829 | } |
| 828 | 830 | let (bl, li, th) = limits(lvl, sharpness); |
| 829 | - if y8 >= 4 && y8 + 4 <= uv_h && x8 + 8 <= uv_w { | |
| 831 | + if y8 >= 4 && y8 + 4 <= uv_h { | |
| 830 | 832 | let taps = if above[TX_16X16] & bit != 0 { |
| 831 | 833 | 16 |
| 832 | 834 | } else if above[TX_8X8] & bit != 0 { |
| @@ -858,7 +860,6 @@ impl LfGrids { | ||
| 858 | 860 | if int4 & bit != 0 |
| 859 | 861 | && sbr + 2 * rg != self.mi_rows - 1 |
| 860 | 862 | && y8 + 8 <= uv_h |
| 861 | - && x8 + 8 <= uv_w | |
| 862 | 863 | { |
| 863 | 864 | lpf_edge( |
| 864 | 865 | data, |
| @@ -900,7 +901,7 @@ mod tests { | ||
| 900 | 901 | fn run(g: &LfGrids, y: &mut [u8]) { |
| 901 | 902 | let mut u = vec![128u8; 32 * 32]; |
| 902 | 903 | let mut v = vec![128u8; 32 * 32]; |
| 903 | - g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 32, 0); | |
| 904 | + g.filter_frame(y, 64, &mut u, &mut v, 32, 64, 64, 32, 0); | |
| 904 | 905 | } |
| 905 | 906 | |
| 906 | 907 | /// The luma internal-4x4 horizontal edge fires on the frame's LAST MI row. |
crates/ec-vp9/src/modes.rsmodified+38 -16
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | //! read_intra_frame_mode_info`). |
| 4 | 4 | |
| 5 | 5 | use crate::bool::BoolDecoder; |
| 6 | +use crate::header::FrameContext; | |
| 6 | 7 | use crate::tables::*; |
| 7 | 8 | |
| 8 | 9 | /// One block's parsed prediction record (`MODE_INFO`). |
| @@ -18,14 +19,16 @@ pub(crate) struct MiInfo { | ||
| 18 | 19 | pub bmi: [u8; 4], |
| 19 | 20 | } |
| 20 | 21 | |
| 21 | -/// The mode-info grid and the partition contexts of one tile pass. | |
| 22 | +/// The mode-info grid and the partition contexts of the frame. | |
| 22 | 23 | pub(crate) struct MiState { |
| 23 | 24 | pub mi_cols: usize, |
| 24 | 25 | pub mi_rows: usize, |
| 25 | 26 | /// `mi_row * mi_cols + mi_col`; every cell a block covers holds a |
| 26 | - /// clone of its record (libvpx shares the pointer). | |
| 27 | + /// clone of its record (libvpx shares the pointer). Frame-scoped: a | |
| 28 | + /// tile row k > 0 reads the rows written by tile row k - 1. | |
| 27 | 29 | pub grid: Vec<Option<MiInfo>>, |
| 28 | - /// `above_seg_context`, one byte per 8x8 column (tile-scoped). | |
| 30 | + /// `above_seg_context`, one byte per 8x8 column (frame-scoped, like | |
| 31 | + /// libvpx's `cm->above_seg_context`, memset once per frame). | |
| 29 | 32 | pub above_seg: Vec<u8>, |
| 30 | 33 | /// `left_seg_context`, one byte per 8x8 row (reset per SB row). |
| 31 | 34 | pub left_seg: [u8; 32], |
| @@ -37,13 +40,22 @@ impl MiState { | ||
| 37 | 40 | mi_cols, |
| 38 | 41 | mi_rows, |
| 39 | 42 | grid: vec![None; mi_cols * mi_rows], |
| 40 | - above_seg: vec![0; mi_cols], | |
| 43 | + // `above_seg_context` is `mi_cols_aligned_to_sb` long in libvpx; | |
| 44 | + // `update_partition_ctx` fills `[col .. col + bw)` which can | |
| 45 | + // overrun `mi_cols` by up to a full superblock (a 64x64 block at | |
| 46 | + // the last mi col). | |
| 47 | + above_seg: vec![0; mi_cols.div_ceil(8) * 8], | |
| 41 | 48 | left_seg: [0; 32], |
| 42 | 49 | } |
| 43 | 50 | } |
| 44 | 51 | |
| 45 | - fn above_mi(&self, row: usize, col: usize, tile_row_start: usize) -> Option<&MiInfo> { | |
| 46 | - if row > tile_row_start { | |
| 52 | + /// `xd->above_mi` (`set_mi_row_col`, vp9_onyxc_int.h:430): available iff | |
| 53 | + /// the block is not on the FRAME's first mi row. libvpx gates on | |
| 54 | + /// `mi_row != 0`, not on the tile row start — for a tile-row stream the | |
| 55 | + /// row above tile row k > 0 was decoded by tile row k - 1 into the same | |
| 56 | + /// frame-scoped mi grid. | |
| 57 | + fn above_mi(&self, row: usize, col: usize) -> Option<&MiInfo> { | |
| 58 | + if row > 0 { | |
| 47 | 59 | self.grid[(row - 1) * self.mi_cols + col].as_ref() |
| 48 | 60 | } else { |
| 49 | 61 | None |
| @@ -138,12 +150,11 @@ pub(crate) fn read_intra_frame_mode_info( | ||
| 138 | 150 | sb_type: usize, |
| 139 | 151 | x_mis: usize, |
| 140 | 152 | y_mis: usize, |
| 141 | - tile_row_start: usize, | |
| 142 | 153 | tile_col_start: usize, |
| 143 | 154 | tx_mode: u8, |
| 144 | - skip_probs: &[u8; 3], | |
| 155 | + fc: &FrameContext, | |
| 145 | 156 | ) -> crate::Result<MiInfo> { |
| 146 | - let above_mi = st.above_mi(row, col, tile_row_start).cloned(); | |
| 157 | + let above_mi = st.above_mi(row, col).cloned(); | |
| 147 | 158 | let left_mi = st.left_mi(row, col, tile_col_start).cloned(); |
| 148 | 159 | |
| 149 | 160 | // read_intra_segment_id: keyframes have no temporal prediction; a |
| @@ -167,26 +178,37 @@ pub(crate) fn read_intra_frame_mode_info( | ||
| 167 | 178 | let skip = if seg_skip { |
| 168 | 179 | true |
| 169 | 180 | } else { |
| 170 | - r.read_bool(skip_probs[skip_ctx]) | |
| 181 | + r.read_bool(fc.skip[skip_ctx]) | |
| 171 | 182 | }; |
| 172 | 183 | |
| 173 | 184 | // read_tx_size |
| 174 | 185 | let max_tx = MAX_TXSIZE_LOOKUP[sb_type] as usize; |
| 175 | 186 | let tx_size = if tx_mode == TX_MODE_SELECT && sb_type >= 3 { |
| 176 | - // read_selected_tx_size: ctx from above/left tx sizes. | |
| 187 | + // get_tx_size_context (vp9_pred_common.h:156): default each side to | |
| 188 | + // max_tx, then substitute the other side when one is missing, in | |
| 189 | + // this exact order — the `!has_above` fallback is load-bearing. | |
| 177 | 190 | let ctx = { |
| 178 | 191 | let a = above_mi |
| 179 | 192 | .as_ref() |
| 180 | 193 | .map_or(max_tx, |m| if m.skip { max_tx } else { m.tx_size }); |
| 181 | - let l = left_mi | |
| 194 | + let mut l = left_mi | |
| 182 | 195 | .as_ref() |
| 183 | - .map_or(a, |m| if m.skip { max_tx } else { m.tx_size }); | |
| 196 | + .map_or(max_tx, |m| if m.skip { max_tx } else { m.tx_size }); | |
| 197 | + if left_mi.is_none() { | |
| 198 | + l = a; | |
| 199 | + } | |
| 200 | + let mut a = a; | |
| 201 | + if above_mi.is_none() { | |
| 202 | + a = l; | |
| 203 | + } | |
| 184 | 204 | usize::from(a + l > max_tx) |
| 185 | 205 | }; |
| 206 | + // get_tx_probs (vp9_pred_common.h:173): the FRAME-updated tables | |
| 207 | + // (`cm->fc->tx_probs`), not the const defaults. | |
| 186 | 208 | let probs: &[u8] = match max_tx { |
| 187 | - 1 => &TX_P8X8_PROB[ctx..ctx + 1], | |
| 188 | - 2 => &TX_P16X16_PROB[ctx * 2..ctx * 2 + 2], | |
| 189 | - _ => &TX_P32X32_PROB[ctx * 3..ctx * 3 + 3], | |
| 209 | + 1 => &fc.tx_p8x8[ctx][..], | |
| 210 | + 2 => &fc.tx_p16x16[ctx][..], | |
| 211 | + _ => &fc.tx_p32x32[ctx][..], | |
| 190 | 212 | }; |
| 191 | 213 | let mut tx = r.read_bool(probs[0]) as usize; |
| 192 | 214 | if tx != TX_4X4 && max_tx >= TX_16X16 { |
crates/ec-vp9/tests/scratch_tiledbg.rsmodified+4 -0
| @@ -31,6 +31,10 @@ fn tile_dbg() { | ||
| 31 | 31 | hdr.mi_cols(), |
| 32 | 32 | hdr.mi_rows() |
| 33 | 33 | ); |
| 34 | + println!( | |
| 35 | + " loop_filter level={} sharpness={}", | |
| 36 | + hdr.loop_filter.level, hdr.loop_filter.sharpness | |
| 37 | + ); | |
| 34 | 38 | let tail = &fr.data[off..]; |
| 35 | 39 | println!( |
| 36 | 40 | " tail len {} first16 {:?}", |
lanes/vp9kf.report.mdmodified+202 -3
| @@ -571,9 +571,9 @@ first-divergent-decision evidence lives in the companion lane report | ||
| 571 | 571 | first superblock row (`if sb_row == row_lo { ectx[].left = [0; 32]; mi.left_seg = [0; 32]; }`). |
| 572 | 572 | libvpx zeroes them at the start of EVERY superblock row: |
| 573 | 573 | |
| 574 | -- `vp9/decoder/vp9_decodeframe.c:2256-2258` (plain `decode_tiles`, the path a 1-thread `drv` | |
| 575 | - takes), with the row-mt twin at `:2114-2115` and the per-tile-row twins at `:1825-1826` / | |
| 576 | - `:1898-1899`; | |
| 574 | +- `vp9/decoder/vp9_decodeframe.c:2260-2261` (plain `decode_tiles`, the path a 1-thread `drv` | |
| 575 | + takes), with the row-mt twin at `:2117-2118` and the per-tile-row twins at `:1828-1829` / | |
| 576 | + `:1901-1902`; | |
| 577 | 577 | - `MACROBLOCKD.left_context` is `ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16]` |
| 578 | 578 | (`vp9/common/vp9_blockd.h:192`), so `vp9_zero` clears all 16 slots of all 3 planes; |
| 579 | 579 | `left_seg_context[8]` (`blockd.h:195`) likewise. |
| @@ -653,3 +653,202 @@ fill discards. The comment in `decode.rs` states this explicitly. | ||
| 653 | 653 | **Status: the tile-row class is NOT closed.** No available fixture and no sweep exercises |
| 654 | 654 | `log2_tile_rows > 0`, so none of the three defects is covered by a gate; they were found with |
| 655 | 655 | purpose-built probes, not by the crate's tests. |
| 656 | + | |
| 657 | +## CLOSED (2026-09-17) — the tile-ROW path is byte-exact; fixture recipes recorded | |
| 658 | + | |
| 659 | +All three defects above are fixed, plus a fourth that the same probe isolated. Every fix is | |
| 660 | +ported verbatim from libvpx with the source cited in the code. | |
| 661 | + | |
| 662 | +1. `modes.rs` `read_intra_frame_mode_info` now takes `fc: &FrameContext` and reads | |
| 663 | + `fc.tx_p8x8/tx_p16x16/tx_p32x32[ctx]` (libvpx `get_tx_probs`, `vp9_pred_common.h:173`) — | |
| 664 | + the FRAME-updated tables, not the `TX_*` const defaults. | |
| 665 | +2. The tx-size context now includes libvpx's `if (!has_above) above_ctx = left_ctx;` | |
| 666 | + (`vp9_pred_common.h:156-170`), in the same order as the `!has_left` fallback. | |
| 667 | +3. `MiState::above_mi` (and the pixel gate `let up = ...` in `predict_and_reconstruct`) now | |
| 668 | + gate above availability on the FRAME (`mi_row != 0`; `set_mi_row_col`, | |
| 669 | + `vp9_onyxc_int.h:430`) instead of the tile-row start. `tile_row_start` is gone from the | |
| 670 | + whole decode chain. | |
| 671 | +4. The above ENTROPY/PARTITION contexts and the mi grid are now FRAME-scoped: `ectx` and `mi` | |
| 672 | + are allocated once per frame in `decode_keyframe_inner` (above cleared once, left cleared | |
| 673 | + per SB row), matching libvpx's frame-scoped `cm->above_context` / `above_seg_context` | |
| 674 | + (`vp9_decodeframe.c:2079-2083`). Previously a fresh per-tile `MiState` discarded the above | |
| 675 | + rows a tile row k > 0 legitimately reads. | |
| 676 | +5. (Same availability family, not tile-row-specific — exposed by the tile-row fixture but also | |
| 677 | + reproducible with `-tile-rows 0` on the same clip) `build_intra_predictors` was passed the | |
| 678 | + PADDED plane height (`y` buffer is 64-aligned, so 1080 -> 1088); libvpx passes the VISIBLE | |
| 679 | + coded size (`xd->cur_buf->y_width/y_height`, `vp9_reconintra.c:288-292`). For the last block | |
| 680 | + row the port therefore skipped the bottom border extension and averaged 8 rows of | |
| 681 | + 128-filled padding into DC_PRED instead of replicating the last valid row (found the first | |
| 682 | + divergence at luma (1056, 288), a 32x32 DC_PRED block that a `+8` DC shift then propagated | |
| 683 | + right in halving steps). Now passes `hdr.width/height` (+1>>1 for chroma). | |
| 684 | + | |
| 685 | +### Evidence | |
| 686 | + | |
| 687 | +| # | command | before | after | | |
| 688 | +|---|---|---|---| | |
| 689 | +| 1 | `CARGO_TARGET_DIR=... SWEEP_IVF=/tmp/tr.ivf cargo test -p ec-vp9 --test scratch_realsweep -- --nocapture` (real 1920x1080 clip, `-g 1 -tile-columns 0 -tile-rows 1`, 2 tile rows) | `frame 0: Y 2065984 U 510099 V 510291`; frames 1-2 `DECODE REFUSED/ERR vp9: tile bool decoder desync` -> `RESULT 0 of 3` | `Y 0 U 0 V 0` x3 -> `RESULT 3 of 3 frames byte-exact` | | |
| 690 | +| 2 | `SWEEP_TILE0=1 SWEEP_SRC=/tmp/small320.mp4 ...` (real 320x240 clip) | (previous batch) | `RESULT 3 of 3 frames byte-exact` | | |
| 691 | +| 3 | `SWEEP_IVF=/tmp/t1080.ivf ...` (real 1920x1080 clip, 4 tile columns) | (previous batch) | `RESULT 3 of 3 frames byte-exact` | | |
| 692 | +| 4 | `SWEEP_IVF=/tmp/single1080.ivf` and `/tmp/tr2.ivf` (same 1080p clip, `-tile-rows 0`; and `-tile-rows 2`, 4 tile rows) | (same clip / 2 tile rows) `RESULT 0 of 3` | `RESULT 3 of 3 frames byte-exact` | | |
| 693 | + | |
| 694 | +Intermediate numbers: with fixes 1-4 only, `/tmp/tr.ivf` still showed `Y 6059 U 1658 V 247`, | |
| 695 | +localized to the bottom 24 luma rows — fix 5 removed them. `cargo test -p ec-vp9` -> all | |
| 696 | +binaries green; `cargo check -p ec-vp9` -> the same 5 lib warnings (`TM_PRED`, | |
| 697 | +`read_partition`, `partition_probs`, `x_mis`, `y_mis`), no new ones. | |
| 698 | + | |
| 699 | +### Fixture recipes (both were previously unrecorded — the report named only the source kind) | |
| 700 | + | |
| 701 | +All-intra keyframe sweep (one keyframe per source frame): | |
| 702 | + | |
| 703 | +``` | |
| 704 | +ffmpeg -v error -y -i <a real 1920x1080 clip> -frames:v 3 -c:v libvpx-vp9 -g 1 -crf 32 \ | |
| 705 | + -deadline good -cpu-used 4 -tile-columns 0 -tile-rows 0 -pix_fmt yuv420p -f ivf /tmp/single1080.ivf | |
| 706 | +``` | |
| 707 | + | |
| 708 | +Tile-ROW fixture (2 tile rows, 1 tile column): identical but `-tile-rows 1` -> | |
| 709 | + | |
| 710 | +``` | |
| 711 | +ffmpeg -v error -y -i <a real 1920x1080 clip> -frames:v 3 -c:v libvpx-vp9 -g 1 -crf 32 \ | |
| 712 | + -deadline good -cpu-used 4 -tile-columns 0 -tile-rows 1 -pix_fmt yuv420p -f ivf /tmp/tr.ivf | |
| 713 | +``` | |
| 714 | + | |
| 715 | +Confirm the layout before trusting it: | |
| 716 | +`TILE_SRC=/tmp/tr.ivf cargo test -p ec-vp9 --test scratch_tiledbg -- --nocapture` -> | |
| 717 | +`tile cols 0 rows 1 mi 240x135`, `walk: 2 tiles, prefixes consume 77709 ok=true`. `-tile-rows 2` | |
| 718 | +(4 tile rows) uses `/tmp/tr2.ivf`. The 4-tile-column fixture `/tmp/t1080.ivf` uses | |
| 719 | +`-tile-columns 2 -tile-rows 0`. Odd-shape fixtures (`-deadline good -cpu-used 4` throughout): | |
| 720 | +`/tmp/h242.ivf` = 320x242 (height not a multiple of 8), `/tmp/h1082.ivf` = 1920x1082, | |
| 721 | +`/tmp/w1366.ivf` = `-vf scale=1366:768` of the 320x240 clip (width not a multiple of 8). | |
| 722 | + | |
| 723 | +No commit made by this lane (the orchestrator commits). | |
| 724 | + | |
| 725 | +## PARTIAL / STILL OPEN (2026-09-17b) — edge-shape band; the OC-OOB panic class is closed | |
| 726 | + | |
| 727 | +A second independent verifier confirmed fixes 1-4 above (with citations) and refuted the "use | |
| 728 | +the visible coded size as the edge" model of fix 5 as incomplete. What is now in the tree: | |
| 729 | + | |
| 730 | +- **CLOSED — above-context OOB panic.** `ectx[].above` is now sized `mi_cols_aligned_to_sb` | |
| 731 | + (luma `×2`) and `MiState::above_seg` likewise, matching libvpx's `cm->above_context` / | |
| 732 | + `above_seg_context`. Before: any width not a multiple of 8 (`mi_cols*2` sized array written | |
| 733 | + up to `2*mi_cols + 6` by the last TX_32X32) panicked with an index-out-of-bounds at | |
| 734 | + `decode.rs:767` (the w1366 above-array read; `intra.rs:72` is the other site, the h242 | |
| 735 | + subtraction overflow); 1366-wide input panicked in both the baseline and the patched tree. | |
| 736 | +- **CLOSED — `intra.rs` subtraction overflow.** The NEED_LEFT/NEED_ABOVE/NEED_ABOVERIGHT | |
| 737 | + staging is now ported branch-for-branch from `vp9_reconintra.c:300-394`: the | |
| 738 | + extend-vs-direct DECISION is `xd->mb_to_bottom_edge < 0` / `xd->mb_to_right_edge < 0` | |
| 739 | + (`:302/326/354`, passed in as `bot_ext`/`right_ext`), and `extend_bottom`/`extend_bottom-1` | |
| 740 | + are computed in `isize` so `y0 > frame_h` cannot underflow. `/tmp/h242.ivf` no longer | |
| 741 | + panics (was `attempt to subtract with overflow` at `intra.rs:72`), `/tmp/h1082.ivf` is 3/3. | |
| 742 | +- **CLOSED — the tile-row class (fixes 1-4)**: `/tmp/tr.ivf`, `/tmp/tr2.ivf`, | |
| 743 | + `/tmp/t1080.ivf`, `/tmp/t1080-single.ivf`, `/tmp/single1080.ivf`, and the 320x240 tile0 | |
| 744 | + sweep are all 3/3. | |
| 745 | +- **STILL OPEN — non-multiple-of-8 frame extents**: `/tmp/h242.ivf` -> `RESULT 1 of 3`, | |
| 746 | + `/tmp/w1366.ivf` -> `RESULT 0 of 3`. The divergence is confined to the RECONSTRUCTED | |
| 747 | + OVERHANG (rows >= 242 for h242, columns >= ~1341 for w1366); no visible pixel differs | |
| 748 | + except where a visible block's DC/TM prediction consumes an overhang neighbour. | |
| 749 | + First divergent block, h242 frame 0: luma rows 240-241, x116-143 and x268-271 (+1 each); | |
| 750 | + localized to the left column staged for the 8x8 at `(mi_row 30, mi_col 12)`, whose | |
| 751 | + `x=95` rows 242-247 are written by the `TX_32X32` at the `BLOCK_32X32 (28,8)`. | |
| 752 | + Oracle staged left column over rows 240-255 is `15,25,25,24,25,...,25,26` (a DIRECT read of | |
| 753 | + the buffer's rows, not a clamp at `frame_height=242`); the port with the visible-length model | |
| 754 | + clamps to `extend_bottom = 242-224 = 18` and replicates row 241, giving `15,25,26,26,...`. | |
| 755 | + Using the ALLOCATED extent as the length instead fixes h242 **and** h1082 but regresses | |
| 756 | + tr.ivf / tr2.ivf / single1080.ivf / t1080-single.ivf to 0/3, so neither "visible length" nor | |
| 757 | + "allocated length" is the whole model — the buffer/overhang semantics differ per extent class | |
| 758 | + and are not yet pinned. A dedicated lane should diff the oracle's overhang bytes | |
| 759 | + (`DUMPH` override was added to `/tmp/vp9loss/drv.c`) against the port's padded plane. | |
| 760 | + | |
| 761 | +## RULE NAMED (2026-09-17c) — the staging extent is the MI-ALIGNED buffer size | |
| 762 | + | |
| 763 | +Instrumented `build_intra_predictors` (`STAGEDBG=x0,y0` in `vp9_reconintra.c`) prints the | |
| 764 | +staged `left[]`/`above[]` plus `fw`/`fh`. For the divergent block of `/tmp/h242.ivf` | |
| 765 | +(luma `x0=64 y0=224 bs=32 mode=2 tx=TX_32X32`, block `BLOCK_32X32 (28,8)`): | |
| 766 | + | |
| 767 | +``` | |
| 768 | +STG plane=0 x0=64 y0=224 bs=32 mode=2 mbtb=-64 mbtr=1792 fw=320 fh=248 | |
| 769 | +STG left : 10 16 15 16 16 16 16 16 16 16 16 16 16 16 16 16 16 26 25 24 25 25 25 25 25 25 25 25 25 25 25 25 | |
| 770 | +STG above: ... cor=0 | |
| 771 | +``` | |
| 772 | + | |
| 773 | +`fh=248`, not 242. `vp9_alloc_frame_buffer` sets `y_width/y_height` to the **8-aligned** | |
| 774 | +extent (`aligned_width = (width + 7) & ~7`, `aligned_height = (height + 7) & ~7`; | |
| 775 | +`vpx_scale/generic/yv12config.c:173-174,250-251`) — i.e. exactly `mi_cols*8` / `mi_rows*8`. | |
| 776 | +With `mb_to_bottom_edge = -64` the NEED_LEFT extension path runs with | |
| 777 | +`extend_bottom = 248 - 224 = 24`: `left[0..24]` are direct reads (rows 224..247) and | |
| 778 | +`left[24..32]` replicate row 247 — which reproduces the observed array | |
| 779 | +(`left[18]=25 (row 242), left[19]=24 (row 243), left[20..31]=25`). Neither the visible size | |
| 780 | +(242 -> clamped at row 241) nor the 64-aligned plane size (256 -> `extend_bottom` 32 >= bs, i.e. | |
| 781 | +a full direct read) reproduces it; the 8-aligned extent does. | |
| 782 | + | |
| 783 | +Port: `decode.rs` passes `vw = mi_cols*8 >> s`, `vh = mi_rows*8 >> s` to | |
| 784 | +`build_intra_predictors`, which keeps the MI-aligned extend-vs-direct DECISION | |
| 785 | +(`mb_to_bottom_edge`/`mb_to_right_edge` -> `bot_ext`/`right_ext`) and the signed `isize` | |
| 786 | +extension arithmetic. Both earlier hacks are gone and neither is needed. | |
| 787 | + | |
| 788 | +Result matrix (3-frame scratch_realsweep, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tilerow`): | |
| 789 | + | |
| 790 | +| fixture | shape | result | | |
| 791 | +|---|---|---| | |
| 792 | +| `/tmp/h242.ivf` | 320x242, 1 tile | `RESULT 3 of 3` | | |
| 793 | +| `/tmp/h1082.ivf` | 1920x1082, 1 tile | `RESULT 3 of 3` | | |
| 794 | +| `/tmp/w1366.ivf` | 1366x768, 1 tile | `RESULT 0 of 3` — `Y 0 0 0`, `U 4/5/6 V 37/33/16` | | |
| 795 | +| `/tmp/w1366tc.ivf` | 1366x768, 2 tile columns | `RESULT 0 of 3` (same chroma-only residue) | | |
| 796 | +| `/tmp/h242tr.ivf` | 320x242, `-tile-rows 1` | `RESULT 3 of 3`, but `tile cols 0 rows 0` — the encoder declined tile rows at this height, so the cross-product is still not exercised | | |
| 797 | +| `/tmp/tr.ivf`, `/tmp/tr2.ivf`, `/tmp/t1080.ivf`, `/tmp/t1080-single.ivf`, `/tmp/single1080.ivf` | 1080p, 2/4 tile rows and 4 tile cols | `RESULT 3 of 3` | | |
| 798 | +| `SWEEP_TILE0=1 SWEEP_SRC=/tmp/small320.mp4` | 320x240 | `RESULT 3 of 3` | | |
| 799 | + | |
| 800 | +`cargo test -p ec-vp9` green (lib 9/9, keyframe_exact 4/4); `cargo check -p ec-vp9` = the same | |
| 801 | +5 warnings. No commit (the orchestrator commits). | |
| 802 | + | |
| 803 | +### CLOSED (2026-09-17d) — chroma COLUMN groups are not width-clamped | |
| 804 | + | |
| 805 | +The residue was the COLUMN analogue of the chroma row-group rule already in | |
| 806 | +`skill://vp9-kf-loopfilter-port`. `vp9_filter_block_plane_ss11` iterates ALL | |
| 807 | +`MI_BLOCK_SIZE >> 1` chroma column groups with no plane-width clamp | |
| 808 | +(`vp9_loopfilter.c:1394`) and `filter_selectively_vert_row2` writes whole 8-column groups | |
| 809 | +(`:313-399`); the horizontal pass likewise. The port clamped the groups with `uv_w` | |
| 810 | +(`x8 + 4 <= uv_w` on the vertical edge, `x8 + 8 <= uv_w` on the internal-4x4 vertical edge and | |
| 811 | +on both horizontal edges, plus a V16->V8 downgrade when `x8 + 8 > uv_w`). | |
| 812 | + | |
| 813 | +Effect at 1366 wide (`uv_w = mi_cols*4 = 684` = the ALIGNED chroma width; the visible chroma | |
| 814 | +width is 683): the last column GROUP (chroma columns 680-687) holds visible pixels 680-682 but | |
| 815 | +overhangs the visible plane by 4, so every clamped edge was silently dropped: luma stayed byte-exact while | |
| 816 | +chroma was off by +/-1 at scattered rows (U 4/5/6, V 37/33/16) — the same | |
| 817 | +"Y exact, chroma off by one" signature as the row bug. Because the chroma planes are the padded | |
| 818 | +buffer (mi_cols*8*2/... >= the group write), the writes land in the pad and are harmless. | |
| 819 | + | |
| 820 | +Fix: drop every `uv_w` column clamp from the chroma pass (`x8 >= 4` alone remains, mirroring | |
| 821 | +libvpx's leftmost-column mask clear), drop the `x8 + 8 > uv_w` clause from the V16 downgrade, | |
| 822 | +and remove the now-unused `uv_w` parameter from `filter_frame` (the pass takes no width bound at | |
| 823 | +all — libvpx passes only the stride). `uv_h` clamps are untouched (verified via the 1080p and | |
| 824 | +odd-height sweeps). | |
| 825 | + | |
| 826 | +Rule: **chroma group iteration is MI-row-gated (rows) and MI-col-unbounded (columns) — read | |
| 827 | +libvpx's loop condition and masks, never the plane geometry.** | |
| 828 | + | |
| 829 | +Full matrix after this fix (3-frame scratch_realsweep, | |
| 830 | +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-tilerow`): | |
| 831 | + | |
| 832 | +| fixture | shape | result | | |
| 833 | +|---|---|---| | |
| 834 | +| `/tmp/h242.ivf` | 320x242, 1 tile | 3 of 3 | | |
| 835 | +| `/tmp/h1082.ivf` | 1920x1082, 1 tile | 3 of 3 | | |
| 836 | +| `/tmp/h1082tr.ivf` | 1920x1082, **2 tile rows** | 3 of 3 (`tile cols 0 rows 1`) | | |
| 837 | +| `/tmp/w1366.ivf` | 1366x768, 1 tile | 3 of 3 | | |
| 838 | +| `/tmp/w1366tc.ivf` | 1366x768, **2 tile columns** | 3 of 3 (`tile cols 1 rows 0`) | | |
| 839 | +| `/tmp/h1082trc.ivf` | 1366x1082, tile cols + tile rows requested | 3 of 3, but `tile cols 1 rows 0` (encoder declined tile rows at this height) | | |
| 840 | +| `/tmp/tr.ivf`, `/tmp/tr2.ivf`, `/tmp/t1080.ivf`, `/tmp/t1080-single.ivf`, `/tmp/single1080.ivf` | 1080p, 2/4 tile rows, 4 tile cols | 3 of 3 | | |
| 841 | +| `SWEEP_TILE0=1 SWEEP_SRC=/tmp/small320.mp4` | 320x240 | 3 of 3 | | |
| 842 | + | |
| 843 | +`cargo test -p ec-vp9` green (lib 9/9, keyframe_exact 4/4, the LF witness suite included); | |
| 844 | +`cargo check -p ec-vp9` = the same 5 warnings (`TM_PRED`, `read_partition`, `partition_probs`, | |
| 845 | +`x_mis`, `y_mis`). No commit (the orchestrator commits). | |
| 846 | + | |
| 847 | +Cross-product coverage: odd HEIGHT x tile rows is now exercised (`/tmp/h1082tr.ivf`, | |
| 848 | +`rows_log2=1`). Odd WIDTH x tile columns is exercised (`/tmp/w1366tc.ivf`, `cols_log2=1`). The | |
| 849 | +encoder declines `-tile-rows` at short heights (320x242 gives `rows_log2=0`), so the combination | |
| 850 | +of an odd width AND an odd height AND both tile axes requested is only reachable via | |
| 851 | +`/tmp/h1082trc.ivf`, where the encoder again declined tile rows (columns accepted) — that single | |
| 852 | +cell (odd width × odd height × tile rows) remains unexercised and needs a taller-than-1082, | |
| 853 | +non-multiple-of-8, odd-width source before it can be covered. | |
| 854 | + |