Merge branch 'lane-blockscratch' (f579f8e1): inter-block level grids as a Grid enum pointing at the static zero residual when nothing was coded, chroma unit collectors filled lazily, var-tx leaf list borrowed instead of cloned; byte-exact, -0.6% instructions
Browse files at this commit1 changed file +139 -75
- crates/ec-av1/src/decode.rs +139 -75
crates/ec-av1/src/decode.rsmodified+139 -75
| @@ -2199,6 +2199,37 @@ fn push_pred_samples(v: &[u16], fctx: &crate::decode::FrameCtx) -> u32 { | |||
| 2199 | /// (a 128-wide inter block's prediction stride). | 2199 | /// (a 128-wide inter block's prediction stride). |
| 2200 | static ZERO_RESIDUAL: [i32; 128 * 128] = [0; 128 * 128]; | 2200 | static ZERO_RESIDUAL: [i32; 128 * 128] = [0; 128 * 128]; |
| 2201 | 2201 | ||
| 2202 | +/// lane-blockscratch: one plane's coefficient levels as the block-tail | ||
| 2203 | +/// neighbour writes want them. A plane that coded nothing (a skipped block, a | ||
| 2204 | +/// strip with no chroma, luma under a var-tx split whose units already wrote | ||
| 2205 | +/// themselves) names the shared [`ZERO_RESIDUAL`] instead of allocating and | ||
| 2206 | +/// zeroing up to 64 KB of its own per block. | ||
| 2207 | +enum Grid { | ||
| 2208 | + Zero(usize), | ||
| 2209 | + Own(Vec<i32>), | ||
| 2210 | +} | ||
| 2211 | + | ||
| 2212 | +/// lane-blockscratch: the mu-chunk chroma collector, allocated by the first | ||
| 2213 | +/// unit that writes into it. Only a block wider or taller than 64 px codes its | ||
| 2214 | +/// chroma per 64x64 chunk; every smaller block used to allocate and zero both | ||
| 2215 | +/// collectors per block and then drop them untouched. | ||
| 2216 | +fn mu_units(v: &mut Vec<i32>, n: usize) -> &mut Vec<i32> { | ||
| 2217 | + if v.is_empty() { | ||
| 2218 | + *v = vec![0i32; n]; | ||
| 2219 | + } | ||
| 2220 | + v | ||
| 2221 | +} | ||
| 2222 | + | ||
| 2223 | +impl std::ops::Deref for Grid { | ||
| 2224 | + type Target = [i32]; | ||
| 2225 | + fn deref(&self) -> &[i32] { | ||
| 2226 | + match self { | ||
| 2227 | + Grid::Zero(n) => &ZERO_RESIDUAL[..*n], | ||
| 2228 | + Grid::Own(v) => v, | ||
| 2229 | + } | ||
| 2230 | + } | ||
| 2231 | +} | ||
| 2232 | + | ||
| 2202 | /// `residual`, or `n` zeros when it is the empty all-zero marker. | 2233 | /// `residual`, or `n` zeros when it is the empty all-zero marker. |
| 2203 | fn dense_residual(residual: &[i32], n: usize) -> &[i32] { | 2234 | fn dense_residual(residual: &[i32], n: usize) -> &[i32] { |
| 2204 | if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual } | 2235 | if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual } |
| @@ -25028,9 +25059,9 @@ fn decode_inter_block( | |||
| 25028 | sv, | 25059 | sv, |
| 25029 | &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, | 25060 | &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, |
| 25030 | ); | 25061 | ); |
| 25031 | - luma_grid = vec![0i32; side * side]; | 25062 | + luma_grid = Grid::Zero(side * side); |
| 25032 | - u_grid = vec![0i32; chroma_side * chroma_side]; | 25063 | + u_grid = Grid::Zero(chroma_side * chroma_side); |
| 25033 | - v_grid = vec![0i32; chroma_side * chroma_side]; | 25064 | + v_grid = Grid::Zero(chroma_side * chroma_side); |
| 25034 | } else { | 25065 | } else { |
| 25035 | // lane-inter4 r2: a rect strip's coefficient context spans its | 25066 | // lane-inter4 r2: a rect strip's coefficient context spans its |
| 25036 | // OWN width above and height left -- reading `side` cells both | 25067 | // OWN width above and height left -- reading `side` cells both |
| @@ -25044,9 +25075,9 @@ fn decode_inter_block( | |||
| 25044 | // lane-sb128c r1: a 128x128 inter block's four chroma units | 25075 | // lane-sb128c r1: a 128x128 inter block's four chroma units |
| 25045 | // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); | 25076 | // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); |
| 25046 | // these collect them for the block-level neighbour write-back. | 25077 | // these collect them for the block-level neighbour write-back. |
| 25047 | - let mut u_units = vec![0i32; chroma_side * chroma_side]; | 25078 | + let mut u_units: Vec<i32> = Vec::new(); |
| 25048 | - let mut v_units = vec![0i32; chroma_side * chroma_side]; | 25079 | + let mut v_units: Vec<i32> = Vec::new(); |
| 25049 | - if let Some(leaves) = vartx_leaves.clone() { | 25080 | + if let Some(leaves) = vartx_leaves.as_ref() { |
| 25050 | // spec 5.11.17's transform tree, leaf by leaf in the order | 25081 | // spec 5.11.17's transform tree, leaf by leaf in the order |
| 25051 | // `read_var_tx_size` coded it: each unit reads its own | 25082 | // `read_var_tx_size` coded it: each unit reads its own |
| 25052 | // coefficients against the neighbour magnitudes the | 25083 | // coefficients against the neighbour magnitudes the |
| @@ -25168,11 +25199,10 @@ fn decode_inter_block( | |||
| 25168 | ); | 25199 | ); |
| 25169 | CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | 25200 | CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); |
| 25170 | mu_chroma = true; | 25201 | mu_chroma = true; |
| 25171 | - let dst = if plane_idx == 1 { | 25202 | + let dst = mu_units( |
| 25172 | - &mut u_units | 25203 | + if plane_idx == 1 { &mut u_units } else { &mut v_units }, |
| 25173 | - } else { | 25204 | + chroma_side * chroma_side, |
| 25174 | - &mut v_units | 25205 | + ); |
| 25175 | - }; | ||
| 25176 | for rr in 0..cu_tx { | 25206 | for rr in 0..cu_tx { |
| 25177 | let start = | 25207 | let start = |
| 25178 | (cr * cu_tx + rr) * chroma_side + cc * cu_tx; | 25208 | (cr * cu_tx + rr) * chroma_side + cc * cu_tx; |
| @@ -25187,7 +25217,7 @@ fn decode_inter_block( | |||
| 25187 | // position back to luma, so an inter block's chroma | 25217 | // position back to luma, so an inter block's chroma |
| 25188 | // inherits the *first* (top-left) luma unit's coded type. | 25218 | // inherits the *first* (top-left) luma unit's coded type. |
| 25189 | luma_tx_type = first_tx_type; | 25219 | luma_tx_type = first_tx_type; |
| 25190 | - luma_grid = vec![0i32; side * side]; | 25220 | + luma_grid = Grid::Zero(side * side); |
| 25191 | } else if rect_tu { | 25221 | } else if rect_tu { |
| 25192 | // The whole-block rectangular transform unit | 25222 | // The whole-block rectangular transform unit |
| 25193 | // (`txfm_partition` said 0 at depth 0). | 25223 | // (`txfm_partition` said 0 at depth 0). |
| @@ -25208,9 +25238,10 @@ fn decode_inter_block( | |||
| 25208 | None, fctx, | 25238 | None, fctx, |
| 25209 | )?; | 25239 | )?; |
| 25210 | luma_tx_type = tx_type; | 25240 | luma_tx_type = tx_type; |
| 25211 | - luma_grid = embed_rect_grid(&grid, write_w, write_h, side); | 25241 | + luma_grid = Grid::Own(embed_rect_grid(&grid, write_w, write_h, side)); |
| 25212 | } else { | 25242 | } else { |
| 25213 | - (luma_grid, luma_tx_type) = read_inter_plane( | 25243 | + { |
| 25244 | + let coded = read_inter_plane( | ||
| 25214 | dec, | 25245 | dec, |
| 25215 | cdfs, | 25246 | cdfs, |
| 25216 | luma_set_inter, | 25247 | luma_set_inter, |
| @@ -25227,20 +25258,31 @@ fn decode_inter_block( | |||
| 25227 | None, | 25258 | None, |
| 25228 | None, fctx, | 25259 | None, fctx, |
| 25229 | )?; | 25260 | )?; |
| 25261 | + luma_grid = Grid::Own(coded.0); | ||
| 25262 | + luma_tx_type = coded.1; | ||
| 25263 | + } | ||
| 25230 | } | 25264 | } |
| 25231 | if side > 64 { | 25265 | if side > 64 { |
| 25232 | // Already read inside the mu-chunk loop above -- at the 128 | 25266 | // Already read inside the mu-chunk loop above -- at the 128 |
| 25233 | // root a rect (128x64/64x128) block's chroma is per mu | 25267 | // root a rect (128x64/64x128) block's chroma is per mu |
| 25234 | // chunk too, so this test comes BEFORE the `rect_tu` one. | 25268 | // chunk too, so this test comes BEFORE the `rect_tu` one. |
| 25235 | - u_grid = std::mem::take(&mut u_units); | 25269 | + u_grid = if u_units.is_empty() { |
| 25236 | - v_grid = std::mem::take(&mut v_units); | 25270 | + Grid::Zero(chroma_side * chroma_side) |
| 25271 | + } else { | ||
| 25272 | + Grid::Own(std::mem::take(&mut u_units)) | ||
| 25273 | + }; | ||
| 25274 | + v_grid = if v_units.is_empty() { | ||
| 25275 | + Grid::Zero(chroma_side * chroma_side) | ||
| 25276 | + } else { | ||
| 25277 | + Grid::Own(std::mem::take(&mut v_units)) | ||
| 25278 | + }; | ||
| 25237 | } else if rect_tu { | 25279 | } else if rect_tu { |
| 25238 | // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a | 25280 | // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a |
| 25239 | // 2:1 strip is the strip's own rect chroma size (16x8 / | 25281 | // 2:1 strip is the strip's own rect chroma size (16x8 / |
| 25240 | // 8x16), one unit for the whole block, and it codes no | 25282 | // 8x16), one unit for the whole block, and it codes no |
| 25241 | // `tx_type` symbol -- it inherits the luma unit's. | 25283 | // `tx_type` symbol -- it inherits the luma unit's. |
| 25242 | let (uw, uh) = (write_chroma_w, write_chroma_h); | 25284 | let (uw, uh) = (write_chroma_w, write_chroma_h); |
| 25243 | - u_grid = embed_rect_grid( | 25285 | + u_grid = Grid::Own(embed_rect_grid( |
| 25244 | &read_inter_plane_rect( | 25286 | &read_inter_plane_rect( |
| 25245 | dec, | 25287 | dec, |
| 25246 | cdfs, | 25288 | cdfs, |
| @@ -25261,8 +25303,8 @@ fn decode_inter_block( | |||
| 25261 | uw, | 25303 | uw, |
| 25262 | uh, | 25304 | uh, |
| 25263 | chroma_side, | 25305 | chroma_side, |
| 25264 | - ); | 25306 | + )); |
| 25265 | - v_grid = embed_rect_grid( | 25307 | + v_grid = Grid::Own(embed_rect_grid( |
| 25266 | &read_inter_plane_rect( | 25308 | &read_inter_plane_rect( |
| 25267 | dec, | 25309 | dec, |
| 25268 | cdfs, | 25310 | cdfs, |
| @@ -25283,9 +25325,9 @@ fn decode_inter_block( | |||
| 25283 | uw, | 25325 | uw, |
| 25284 | uh, | 25326 | uh, |
| 25285 | chroma_side, | 25327 | chroma_side, |
| 25286 | - ); | 25328 | + )); |
| 25287 | } else { | 25329 | } else { |
| 25288 | - u_grid = read_inter_plane( | 25330 | + u_grid = Grid::Own(read_inter_plane( |
| 25289 | dec, | 25331 | dec, |
| 25290 | cdfs, | 25332 | cdfs, |
| 25291 | chroma_set, | 25333 | chroma_set, |
| @@ -25302,8 +25344,8 @@ fn decode_inter_block( | |||
| 25302 | Some(luma_tx_type), | 25344 | Some(luma_tx_type), |
| 25303 | None, fctx, | 25345 | None, fctx, |
| 25304 | )? | 25346 | )? |
| 25305 | - .0; | 25347 | + .0); |
| 25306 | - v_grid = read_inter_plane( | 25348 | + v_grid = Grid::Own(read_inter_plane( |
| 25307 | dec, | 25349 | dec, |
| 25308 | cdfs, | 25350 | cdfs, |
| 25309 | chroma_set, | 25351 | chroma_set, |
| @@ -25320,7 +25362,7 @@ fn decode_inter_block( | |||
| 25320 | Some(luma_tx_type), | 25362 | Some(luma_tx_type), |
| 25321 | None, fctx, | 25363 | None, fctx, |
| 25322 | )? | 25364 | )? |
| 25323 | - .0; | 25365 | + .0); |
| 25324 | } | 25366 | } |
| 25325 | } | 25367 | } |
| 25326 | } else { | 25368 | } else { |
| @@ -26279,9 +26321,9 @@ fn decode_inter_block( | |||
| 26279 | &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, | 26321 | &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, |
| 26280 | ); | 26322 | ); |
| 26281 | } | 26323 | } |
| 26282 | - luma_grid = vec![0i32; side * side]; | 26324 | + luma_grid = Grid::Zero(side * side); |
| 26283 | - u_grid = vec![0i32; chroma_side * chroma_side]; | 26325 | + u_grid = Grid::Zero(chroma_side * chroma_side); |
| 26284 | - v_grid = vec![0i32; chroma_side * chroma_side]; | 26326 | + v_grid = Grid::Zero(chroma_side * chroma_side); |
| 26285 | } else { | 26327 | } else { |
| 26286 | // lane-inter4 r2: a rect strip's coefficient context spans its | 26328 | // lane-inter4 r2: a rect strip's coefficient context spans its |
| 26287 | // OWN width above and height left -- reading `side` cells both | 26329 | // OWN width above and height left -- reading `side` cells both |
| @@ -26307,9 +26349,9 @@ fn decode_inter_block( | |||
| 26307 | // lane-sb128c r1: a 128x128 inter block's four chroma units | 26349 | // lane-sb128c r1: a 128x128 inter block's four chroma units |
| 26308 | // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); | 26350 | // are read INSIDE the luma leaf loop (one per 64x64 mu chunk); |
| 26309 | // these collect them for the block-level neighbour write-back. | 26351 | // these collect them for the block-level neighbour write-back. |
| 26310 | - let mut u_units = vec![0i32; chroma_side * chroma_side]; | 26352 | + let mut u_units: Vec<i32> = Vec::new(); |
| 26311 | - let mut v_units = vec![0i32; chroma_side * chroma_side]; | 26353 | + let mut v_units: Vec<i32> = Vec::new(); |
| 26312 | - if let Some(leaves) = vartx_leaves.clone() { | 26354 | + if let Some(leaves) = vartx_leaves.as_ref() { |
| 26313 | // spec 5.11.17's transform tree, leaf by leaf in the order | 26355 | // spec 5.11.17's transform tree, leaf by leaf in the order |
| 26314 | // `read_var_tx_size` coded it: each unit reads its own | 26356 | // `read_var_tx_size` coded it: each unit reads its own |
| 26315 | // coefficients against the neighbour magnitudes the | 26357 | // coefficients against the neighbour magnitudes the |
| @@ -26431,11 +26473,10 @@ fn decode_inter_block( | |||
| 26431 | ); | 26473 | ); |
| 26432 | CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | 26474 | CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); |
| 26433 | mu_chroma = true; | 26475 | mu_chroma = true; |
| 26434 | - let dst = if plane_idx == 1 { | 26476 | + let dst = mu_units( |
| 26435 | - &mut u_units | 26477 | + if plane_idx == 1 { &mut u_units } else { &mut v_units }, |
| 26436 | - } else { | 26478 | + chroma_side * chroma_side, |
| 26437 | - &mut v_units | 26479 | + ); |
| 26438 | - }; | ||
| 26439 | for rr in 0..cu_tx { | 26480 | for rr in 0..cu_tx { |
| 26440 | let start = | 26481 | let start = |
| 26441 | (cr * cu_tx + rr) * chroma_side + cc * cu_tx; | 26482 | (cr * cu_tx + rr) * chroma_side + cc * cu_tx; |
| @@ -26450,7 +26491,7 @@ fn decode_inter_block( | |||
| 26450 | // position back to luma, so an inter block's chroma | 26491 | // position back to luma, so an inter block's chroma |
| 26451 | // inherits the *first* (top-left) luma unit's coded type. | 26492 | // inherits the *first* (top-left) luma unit's coded type. |
| 26452 | luma_tx_type = first_tx_type; | 26493 | luma_tx_type = first_tx_type; |
| 26453 | - luma_grid = vec![0i32; side * side]; | 26494 | + luma_grid = Grid::Zero(side * side); |
| 26454 | } else if rect_tu { | 26495 | } else if rect_tu { |
| 26455 | // The whole-block rectangular transform unit | 26496 | // The whole-block rectangular transform unit |
| 26456 | // (`txfm_partition` said 0 at depth 0). | 26497 | // (`txfm_partition` said 0 at depth 0). |
| @@ -26471,9 +26512,10 @@ fn decode_inter_block( | |||
| 26471 | None, fctx, | 26512 | None, fctx, |
| 26472 | )?; | 26513 | )?; |
| 26473 | luma_tx_type = tx_type; | 26514 | luma_tx_type = tx_type; |
| 26474 | - luma_grid = embed_rect_grid(&grid, write_w, write_h, side); | 26515 | + luma_grid = Grid::Own(embed_rect_grid(&grid, write_w, write_h, side)); |
| 26475 | } else { | 26516 | } else { |
| 26476 | - (luma_grid, luma_tx_type) = read_inter_plane( | 26517 | + { |
| 26518 | + let coded = read_inter_plane( | ||
| 26477 | dec, | 26519 | dec, |
| 26478 | cdfs, | 26520 | cdfs, |
| 26479 | luma_set_inter, | 26521 | luma_set_inter, |
| @@ -26490,6 +26532,9 @@ fn decode_inter_block( | |||
| 26490 | None, | 26532 | None, |
| 26491 | None, fctx, | 26533 | None, fctx, |
| 26492 | )?; | 26534 | )?; |
| 26535 | + luma_grid = Grid::Own(coded.0); | ||
| 26536 | + luma_tx_type = coded.1; | ||
| 26537 | + } | ||
| 26493 | } | 26538 | } |
| 26494 | if !has_chroma { | 26539 | if !has_chroma { |
| 26495 | // `is_chroma_reference` is false for this strip: libaom's | 26540 | // `is_chroma_reference` is false for this strip: libaom's |
| @@ -26498,21 +26543,29 @@ fn decode_inter_block( | |||
| 26498 | // `reconstruct_inter_block`'s `for (plane...)` guarded by | 26543 | // `reconstruct_inter_block`'s `for (plane...)` guarded by |
| 26499 | // `xd->is_chroma_ref`) codes NO chroma transform here, so | 26544 | // `xd->is_chroma_ref`) codes NO chroma transform here, so |
| 26500 | // neither symbol nor context exists. | 26545 | // neither symbol nor context exists. |
| 26501 | - u_grid = vec![0i32; chroma_side * chroma_side]; | 26546 | + u_grid = Grid::Zero(chroma_side * chroma_side); |
| 26502 | - v_grid = vec![0i32; chroma_side * chroma_side]; | 26547 | + v_grid = Grid::Zero(chroma_side * chroma_side); |
| 26503 | } else if side > 64 { | 26548 | } else if side > 64 { |
| 26504 | // Already read inside the mu-chunk loop above -- at the 128 | 26549 | // Already read inside the mu-chunk loop above -- at the 128 |
| 26505 | // root a rect (128x64/64x128) block's chroma is per mu | 26550 | // root a rect (128x64/64x128) block's chroma is per mu |
| 26506 | // chunk too, so this test comes BEFORE the `rect_tu` one. | 26551 | // chunk too, so this test comes BEFORE the `rect_tu` one. |
| 26507 | - u_grid = std::mem::take(&mut u_units); | 26552 | + u_grid = if u_units.is_empty() { |
| 26508 | - v_grid = std::mem::take(&mut v_units); | 26553 | + Grid::Zero(chroma_side * chroma_side) |
| 26554 | + } else { | ||
| 26555 | + Grid::Own(std::mem::take(&mut u_units)) | ||
| 26556 | + }; | ||
| 26557 | + v_grid = if v_units.is_empty() { | ||
| 26558 | + Grid::Zero(chroma_side * chroma_side) | ||
| 26559 | + } else { | ||
| 26560 | + Grid::Own(std::mem::take(&mut v_units)) | ||
| 26561 | + }; | ||
| 26509 | } else if rect_tu { | 26562 | } else if rect_tu { |
| 26510 | // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a | 26563 | // `av1_get_max_uv_txsize(bsize)`: the chroma transform of a |
| 26511 | // 2:1 strip is the strip's own rect chroma size (16x8 / | 26564 | // 2:1 strip is the strip's own rect chroma size (16x8 / |
| 26512 | // 8x16), one unit for the whole block, and it codes no | 26565 | // 8x16), one unit for the whole block, and it codes no |
| 26513 | // `tx_type` symbol -- it inherits the luma unit's. | 26566 | // `tx_type` symbol -- it inherits the luma unit's. |
| 26514 | let (uw, uh) = (write_chroma_w, write_chroma_h); | 26567 | let (uw, uh) = (write_chroma_w, write_chroma_h); |
| 26515 | - u_grid = embed_rect_grid( | 26568 | + u_grid = Grid::Own(embed_rect_grid( |
| 26516 | &read_inter_plane_rect( | 26569 | &read_inter_plane_rect( |
| 26517 | dec, | 26570 | dec, |
| 26518 | cdfs, | 26571 | cdfs, |
| @@ -26533,8 +26586,8 @@ fn decode_inter_block( | |||
| 26533 | uw, | 26586 | uw, |
| 26534 | uh, | 26587 | uh, |
| 26535 | chroma_side, | 26588 | chroma_side, |
| 26536 | - ); | 26589 | + )); |
| 26537 | - v_grid = embed_rect_grid( | 26590 | + v_grid = Grid::Own(embed_rect_grid( |
| 26538 | &read_inter_plane_rect( | 26591 | &read_inter_plane_rect( |
| 26539 | dec, | 26592 | dec, |
| 26540 | cdfs, | 26593 | cdfs, |
| @@ -26555,9 +26608,9 @@ fn decode_inter_block( | |||
| 26555 | uw, | 26608 | uw, |
| 26556 | uh, | 26609 | uh, |
| 26557 | chroma_side, | 26610 | chroma_side, |
| 26558 | - ); | 26611 | + )); |
| 26559 | } else { | 26612 | } else { |
| 26560 | - u_grid = read_inter_plane( | 26613 | + u_grid = Grid::Own(read_inter_plane( |
| 26561 | dec, | 26614 | dec, |
| 26562 | cdfs, | 26615 | cdfs, |
| 26563 | chroma_set, | 26616 | chroma_set, |
| @@ -26574,8 +26627,8 @@ fn decode_inter_block( | |||
| 26574 | Some(luma_tx_type), | 26627 | Some(luma_tx_type), |
| 26575 | None, fctx, | 26628 | None, fctx, |
| 26576 | )? | 26629 | )? |
| 26577 | - .0; | 26630 | + .0); |
| 26578 | - v_grid = read_inter_plane( | 26631 | + v_grid = Grid::Own(read_inter_plane( |
| 26579 | dec, | 26632 | dec, |
| 26580 | cdfs, | 26633 | cdfs, |
| 26581 | chroma_set, | 26634 | chroma_set, |
| @@ -26592,7 +26645,7 @@ fn decode_inter_block( | |||
| 26592 | Some(luma_tx_type), | 26645 | Some(luma_tx_type), |
| 26593 | None, fctx, | 26646 | None, fctx, |
| 26594 | )? | 26647 | )? |
| 26595 | - .0; | 26648 | + .0); |
| 26596 | } | 26649 | } |
| 26597 | } | 26650 | } |
| 26598 | } | 26651 | } |
| @@ -26974,9 +27027,9 @@ fn decode_inter_block( | |||
| 26974 | // `decode_token_recon_block` walks `mu_blocks_wide/high` and codes | 27027 | // `decode_token_recon_block` walks `mu_blocks_wide/high` and codes |
| 26975 | // every plane of a chunk before the next chunk's luma. These collect | 27028 | // every plane of a chunk before the next chunk's luma. These collect |
| 26976 | // the four TX_32X32 units per plane for the block-level write-back. | 27029 | // the four TX_32X32 units per plane for the block-level write-back. |
| 26977 | - let mut u_units = vec![0i32; chroma_side * chroma_side]; | 27030 | + let mut u_units: Vec<i32> = Vec::new(); |
| 26978 | - let mut v_units = vec![0i32; chroma_side * chroma_side]; | 27031 | + let mut v_units: Vec<i32> = Vec::new(); |
| 26979 | - if let Some(leaves) = vartx_leaves.clone() { | 27032 | + if let Some(leaves) = vartx_leaves.as_ref() { |
| 26980 | let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); | 27033 | let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); |
| 26981 | for (idx, &(row, col, tx_px, _)) in leaves.iter().enumerate() { | 27034 | for (idx, &(row, col, tx_px, _)) in leaves.iter().enumerate() { |
| 26982 | let tu_mi = (at_mi.0 + row, at_mi.1 + col); | 27035 | let tu_mi = (at_mi.0 + row, at_mi.1 + col); |
| @@ -27012,13 +27065,13 @@ fn decode_inter_block( | |||
| 27012 | filter_intra, | 27065 | filter_intra, |
| 27013 | smooth_neighbor, fctx, | 27066 | smooth_neighbor, fctx, |
| 27014 | ); | 27067 | ); |
| 27015 | - vec![0i32; tx_px * tx_px] | 27068 | + Grid::Zero(tx_px * tx_px) |
| 27016 | } else { | 27069 | } else { |
| 27017 | // The unit's bsize is smaller than the block it sits in, | 27070 | // The unit's bsize is smaller than the block it sits in, |
| 27018 | // so `txb_skip_ctx` is the neighbour-magnitude table, not | 27071 | // so `txb_skip_ctx` is the neighbour-magnitude table, not |
| 27019 | // the lone-TU 0 (`get_txb_ctx_general`). | 27072 | // the lone-TU 0 (`get_txb_ctx_general`). |
| 27020 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); | 27073 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI); |
| 27021 | - read_plane( | 27074 | + Grid::Own(read_plane( |
| 27022 | dec, | 27075 | dec, |
| 27023 | cdfs, | 27076 | cdfs, |
| 27024 | txbset_for(tx_px, reduced), | 27077 | txbset_for(tx_px, reduced), |
| @@ -27043,7 +27096,7 @@ fn decode_inter_block( | |||
| 27043 | filter_intra, | 27096 | filter_intra, |
| 27044 | Some(tu_skip_ctx), | 27097 | Some(tu_skip_ctx), |
| 27045 | smooth_neighbor, fctx, | 27098 | smooth_neighbor, fctx, |
| 27046 | - )? | 27099 | + )?) |
| 27047 | }; | 27100 | }; |
| 27048 | neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); | 27101 | neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid); |
| 27049 | if side > 64 { | 27102 | if side > 64 { |
| @@ -27082,9 +27135,9 @@ fn decode_inter_block( | |||
| 27082 | None, | 27135 | None, |
| 27083 | smooth_neighbor_uv, fctx, | 27136 | smooth_neighbor_uv, fctx, |
| 27084 | ); | 27137 | ); |
| 27085 | - vec![0i32; cu_tx * cu_tx] | 27138 | + Grid::Zero(cu_tx * cu_tx) |
| 27086 | } else { | 27139 | } else { |
| 27087 | - read_plane( | 27140 | + Grid::Own(read_plane( |
| 27088 | dec, | 27141 | dec, |
| 27089 | cdfs, | 27142 | cdfs, |
| 27090 | chroma_set, | 27143 | chroma_set, |
| @@ -27111,7 +27164,7 @@ fn decode_inter_block( | |||
| 27111 | // (lane-sb128b r3). | 27164 | // (lane-sb128b r3). |
| 27112 | Some(3), | 27165 | Some(3), |
| 27113 | smooth_neighbor_uv, fctx, | 27166 | smooth_neighbor_uv, fctx, |
| 27114 | - )? | 27167 | + )?) |
| 27115 | }; | 27168 | }; |
| 27116 | // Immediately, so the NEXT chunk's unit reads this | 27169 | // Immediately, so the NEXT chunk's unit reads this |
| 27117 | // one's coefficient context. | 27170 | // one's coefficient context. |
| @@ -27119,7 +27172,10 @@ fn decode_inter_block( | |||
| 27119 | cu_mi, luma_span, luma_span, plane_idx, &cu_grid, | 27172 | cu_mi, luma_span, luma_span, plane_idx, &cu_grid, |
| 27120 | ); | 27173 | ); |
| 27121 | CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | 27174 | CHROMA_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); |
| 27122 | - let dst = if plane_idx == 1 { &mut u_units } else { &mut v_units }; | 27175 | + let dst = mu_units( |
| 27176 | + if plane_idx == 1 { &mut u_units } else { &mut v_units }, | ||
| 27177 | + chroma_side * chroma_side, | ||
| 27178 | + ); | ||
| 27123 | for rr in 0..cu_tx { | 27179 | for rr in 0..cu_tx { |
| 27124 | let start = (cr * cu_tx + rr) * chroma_side + cc * cu_tx; | 27180 | let start = (cr * cu_tx + rr) * chroma_side + cc * cu_tx; |
| 27125 | dst[start..start + cu_tx] | 27181 | dst[start..start + cu_tx] |
| @@ -27131,9 +27187,17 @@ fn decode_inter_block( | |||
| 27131 | } | 27187 | } |
| 27132 | if side > 64 { | 27188 | if side > 64 { |
| 27133 | // Chroma is already coded and reconstructed per mu chunk above. | 27189 | // Chroma is already coded and reconstructed per mu chunk above. |
| 27134 | - luma_grid = vec![0i32; side * side]; | 27190 | + luma_grid = Grid::Zero(side * side); |
| 27135 | - u_grid = std::mem::take(&mut u_units); | 27191 | + u_grid = if u_units.is_empty() { |
| 27136 | - v_grid = std::mem::take(&mut v_units); | 27192 | + Grid::Zero(chroma_side * chroma_side) |
| 27193 | + } else { | ||
| 27194 | + Grid::Own(std::mem::take(&mut u_units)) | ||
| 27195 | + }; | ||
| 27196 | + v_grid = if v_units.is_empty() { | ||
| 27197 | + Grid::Zero(chroma_side * chroma_side) | ||
| 27198 | + } else { | ||
| 27199 | + Grid::Own(std::mem::take(&mut v_units)) | ||
| 27200 | + }; | ||
| 27137 | INTRA_128_IN_INTER_HITS.with(|c| c.set(c.get() + 1)); | 27201 | INTRA_128_IN_INTER_HITS.with(|c| c.set(c.get() + 1)); |
| 27138 | } else if skip { | 27202 | } else if skip { |
| 27139 | if !split_luma { | 27203 | if !split_luma { |
| @@ -27184,21 +27248,21 @@ fn decode_inter_block( | |||
| 27184 | None, | 27248 | None, |
| 27185 | smooth_neighbor_uv, fctx, | 27249 | smooth_neighbor_uv, fctx, |
| 27186 | ); | 27250 | ); |
| 27187 | - luma_grid = vec![0i32; side * side]; | 27251 | + luma_grid = Grid::Zero(side * side); |
| 27188 | - u_grid = vec![0i32; chroma_side * chroma_side]; | 27252 | + u_grid = Grid::Zero(chroma_side * chroma_side); |
| 27189 | - v_grid = vec![0i32; chroma_side * chroma_side]; | 27253 | + v_grid = Grid::Zero(chroma_side * chroma_side); |
| 27190 | } else { | 27254 | } else { |
| 27191 | let around = neighbours.around_mi(at, side); | 27255 | let around = neighbours.around_mi(at, side); |
| 27192 | - luma_grid = if split_luma { | 27256 | + if split_luma { |
| 27193 | // Already coded and reconstructed unit by unit above; the | 27257 | // Already coded and reconstructed unit by unit above; the |
| 27194 | // block-level grid is only the neighbour write-back's input, | 27258 | // block-level grid is only the neighbour write-back's input, |
| 27195 | // which `record_split_luma` ignores for plane 0. | 27259 | // which `record_split_luma` ignores for plane 0. |
| 27196 | - vec![0i32; side * side] | 27260 | + luma_grid = Grid::Zero(side * side); |
| 27197 | } else { | 27261 | } else { |
| 27198 | if let Some(buf) = &palette_y_buf { | 27262 | if let Some(buf) = &palette_y_buf { |
| 27199 | set_palette_pred(buf.clone(), fctx); | 27263 | set_palette_pred(buf.clone(), fctx); |
| 27200 | } | 27264 | } |
| 27201 | - read_plane( | 27265 | + luma_grid = Grid::Own(read_plane( |
| 27202 | dec, | 27266 | dec, |
| 27203 | cdfs, | 27267 | cdfs, |
| 27204 | luma_set_intra, | 27268 | luma_set_intra, |
| @@ -27219,13 +27283,13 @@ fn decode_inter_block( | |||
| 27219 | filter_intra, | 27283 | filter_intra, |
| 27220 | None, | 27284 | None, |
| 27221 | smooth_neighbor, fctx, | 27285 | smooth_neighbor, fctx, |
| 27222 | - )? | 27286 | + )?); |
| 27223 | - }; | 27287 | + } |
| 27224 | let ac = alpha.map(|_| cfl_src(px, py, side)); | 27288 | let ac = alpha.map(|_| cfl_src(px, py, side)); |
| 27225 | if let Some((ub, _)) = &palette_uv_bufs { | 27289 | if let Some((ub, _)) = &palette_uv_bufs { |
| 27226 | set_palette_pred(ub.clone(), fctx); | 27290 | set_palette_pred(ub.clone(), fctx); |
| 27227 | } | 27291 | } |
| 27228 | - u_grid = read_plane( | 27292 | + u_grid = Grid::Own(read_plane( |
| 27229 | dec, | 27293 | dec, |
| 27230 | cdfs, | 27294 | cdfs, |
| 27231 | chroma_set, | 27295 | chroma_set, |
| @@ -27246,11 +27310,11 @@ fn decode_inter_block( | |||
| 27246 | None, | 27310 | None, |
| 27247 | None, | 27311 | None, |
| 27248 | smooth_neighbor_uv, fctx, | 27312 | smooth_neighbor_uv, fctx, |
| 27249 | - )?; | 27313 | + )?); |
| 27250 | if let Some((_, vb)) = &palette_uv_bufs { | 27314 | if let Some((_, vb)) = &palette_uv_bufs { |
| 27251 | set_palette_pred(vb.clone(), fctx); | 27315 | set_palette_pred(vb.clone(), fctx); |
| 27252 | } | 27316 | } |
| 27253 | - v_grid = read_plane( | 27317 | + v_grid = Grid::Own(read_plane( |
| 27254 | dec, | 27318 | dec, |
| 27255 | cdfs, | 27319 | cdfs, |
| 27256 | chroma_set, | 27320 | chroma_set, |
| @@ -27271,7 +27335,7 @@ fn decode_inter_block( | |||
| 27271 | None, | 27335 | None, |
| 27272 | None, | 27336 | None, |
| 27273 | smooth_neighbor_uv, fctx, | 27337 | smooth_neighbor_uv, fctx, |
| 27274 | - )?; | 27338 | + )?); |
| 27275 | } | 27339 | } |
| 27276 | } | 27340 | } |
| 27277 | // lane-comppin r9: end-of-block checkpoint -- everything between | 27341 | // lane-comppin r9: end-of-block checkpoint -- everything between |