The writer's intrabc DV predictor and wavefront follow the superblock size
Browse files at this commit44a12afb848d9227a5d0c78b8c2566748e59271aParent: ab4ff0c- fix
- the writer's intrabc DV predictor and wavefront follow the superblock size
2 changed files +25 -16
- crates/ec-av1/src/encode.rs +18 -10
- crates/ec-av1/src/tile.rs +7 -6
crates/ec-av1/src/encode.rsmodified+18 -10
| @@ -5161,7 +5161,9 @@ fn intrabc_step() -> usize { | |||
| 5161 | const IBC_HASH: usize = 16; | 5161 | const IBC_HASH: usize = 16; |
| 5162 | 5162 | ||
| 5163 | /// libaom `INTRABC_DELAY_PIXELS / 64` -- how many 64x64 superblocks behind | 5163 | /// libaom `INTRABC_DELAY_PIXELS / 64` -- how many 64x64 superblocks behind |
| 5164 | -/// the current one the source's bottom-right corner must already be. | 5164 | +/// the current one the source's bottom-right corner must already be. Under |
| 5165 | +/// 128 superblocks the same 256 pixels are two superblocks, which | ||
| 5166 | +/// [`Ibc::dv_valid`] derives from the size itself. | ||
| 5165 | const INTRABC_DELAY_SB64: i32 = 4; | 5167 | const INTRABC_DELAY_SB64: i32 = 4; |
| 5166 | 5168 | ||
| 5167 | /// FNV-1a over one `IBC_HASH`-square of `plane` at `(x, y)`. | 5169 | /// FNV-1a over one `IBC_HASH`-square of `plane` at `(x, y)`. |
| @@ -5297,22 +5299,28 @@ impl Ibc { | |||
| 5297 | if sx < tx0 || sy < ty0 || sx + w > tx1 || sy + h > ty1 { | 5299 | if sx < tx0 || sy < ty0 || sx + w > tx1 || sy + h > ty1 { |
| 5298 | return false; | 5300 | return false; |
| 5299 | } | 5301 | } |
| 5300 | - let active_sb_row = (y as i32 - ty0) >> 6; | 5302 | + // lane-b128m: libaom counts this wavefront in SUPERBLOCKS, and the |
| 5301 | - let active_sb_col = (x as i32 - tx0) >> 6; | 5303 | + // superblock is 128 wide under `EC_AV1_SB128` (`INTRABC_DELAY_SB = |
| 5302 | - let src_sb_row = (sy + h - 1 - ty0) >> 6; | 5304 | + // INTRABC_DELAY_PIXELS >> sb_size_log2`, i.e. 2 there and 4 here). |
| 5303 | - let src_sb_col = (sx + w - 1 - tx0) >> 6; | 5305 | + // Counting 64s under a 128 superblock let the search take a source |
| 5306 | + // from a 64 row the 128 visit order had not reconstructed yet. | ||
| 5307 | + let sb_log2 = if crate::encode::sb128_on() { 7 } else { 6 }; | ||
| 5308 | + let delay: i32 = if sb_log2 == 7 { INTRABC_DELAY_SB64 / 2 } else { INTRABC_DELAY_SB64 }; | ||
| 5309 | + let active_sb_row = (y as i32 - ty0) >> sb_log2; | ||
| 5310 | + let active_sb_col = (x as i32 - tx0) >> sb_log2; | ||
| 5311 | + let src_sb_row = (sy + h - 1 - ty0) >> sb_log2; | ||
| 5312 | + let src_sb_col = (sx + w - 1 - tx0) >> sb_log2; | ||
| 5304 | // This lane's own restriction (see the doc comment). | 5313 | // This lane's own restriction (see the doc comment). |
| 5305 | if src_sb_row >= active_sb_row { | 5314 | if src_sb_row >= active_sb_row { |
| 5306 | return false; | 5315 | return false; |
| 5307 | } | 5316 | } |
| 5308 | - let total = ((tx1 - tx0 - 1) >> 6) + 1; | 5317 | + let total = ((tx1 - tx0 - 1) >> sb_log2) + 1; |
| 5309 | - if src_sb_row * total + src_sb_col >= active_sb_row * total + active_sb_col - INTRABC_DELAY_SB64 | 5318 | + if src_sb_row * total + src_sb_col >= active_sb_row * total + active_sb_col - delay { |
| 5310 | - { | ||
| 5311 | return false; | 5319 | return false; |
| 5312 | } | 5320 | } |
| 5313 | // libaom's wavefront: only the top-left cone of the frame is legal. | 5321 | // libaom's wavefront: only the top-left cone of the frame is legal. |
| 5314 | - let wf = (1 + INTRABC_DELAY_SB64) * (active_sb_row - src_sb_row); | 5322 | + let wf = (1 + delay) * (active_sb_row - src_sb_row); |
| 5315 | - src_sb_col < active_sb_col - INTRABC_DELAY_SB64 + wf | 5323 | + src_sb_col < active_sb_col - delay + wf |
| 5316 | } | 5324 | } |
| 5317 | } | 5325 | } |
| 5318 | 5326 | ||
crates/ec-av1/src/tile.rsmodified+7 -6
| @@ -3724,12 +3724,13 @@ fn intrabc_dv_pred(mi_r: usize, mi_c: usize, side: usize) -> (i32, i32) { | |||
| 3724 | }); | 3724 | }); |
| 3725 | let mut pred = stack_pred.unwrap_or((0, 0)); | 3725 | let mut pred = stack_pred.unwrap_or((0, 0)); |
| 3726 | if pred == (0, 0) { | 3726 | if pred == (0, 0) { |
| 3727 | - // 64x64 superblocks: the only size this encoder's sequence header | 3727 | + // `av1_find_ref_dv` takes `mib_size`, the SEQUENCE's superblock size |
| 3728 | - // signals (`use_128x128_superblock: false`), so `mib_size` is 16 mi. | 3728 | + // in mi units (lane-b128m: hardcoding 16 here made the writer's DV |
| 3729 | - // The tile row start is 0, exactly as decode.rs `read_intrabc_dv` | 3729 | + // predictor one 64 superblock up while decode.rs `read_intrabc_dv` |
| 3730 | - // takes it -- both are written for the single-tile-row streams this | 3730 | + // took 128 -- identical symbols, different reconstructed DV). The |
| 3731 | - // encoder produces. | 3731 | + // tile row start is 0, exactly as the reader takes it -- both are |
| 3732 | - let sb_mi = 16i32; | 3732 | + // written for the single-tile-row streams this encoder produces. |
| 3733 | + let sb_mi = if sb128_armed() { 32i32 } else { 16i32 }; | ||
| 3733 | let sb_px = sb_mi * MI as i32; | 3734 | let sb_px = sb_mi * MI as i32; |
| 3734 | pred = if (mi_r as i32) < sb_mi { | 3735 | pred = if (mi_r as i32) < sb_mi { |
| 3735 | (0, -(sb_px + INTRABC_DELAY_PIXELS) * 8) | 3736 | (0, -(sb_px + INTRABC_DELAY_PIXELS) * 8) |