lane-av1422llinter2: a lossless chroma plane block is per-axis, so the 8x8 leaf's TX_4X4 walk is gated on its SHAPE, not on 4:4:4
Browse files at this commit3685753175c8b284a9874f086fe2ab5b77ce2c2aParent: b5109421 changed file +66 -36
- crates/ec-av1/src/decode.rs +66 -36
crates/ec-av1/src/decode.rsmodified+66 -36
| @@ -38053,14 +38053,30 @@ fn read_inter_chroma_lossless( | |||
| 38053 | Ok(()) | 38053 | Ok(()) |
| 38054 | } | 38054 | } |
| 38055 | 38055 | ||
| 38056 | -/// The 8x8 inter leaf's lossless 4:4:4 chroma arm (lane-av1-llinter), shared | 38056 | +/// The 8x8 inter leaf's lossless chroma arm (lane-av1-llinter), shared by the |
| 38057 | -/// by the single-ref and compound paths: the plane block is a 2x2 raster of | 38057 | +/// single-ref and compound paths, for every plane block BIGGER than 4x4: |
| 38058 | -/// TX_4X4 units (`av1_get_tx_size`: lossless returns TX_4X4 for EVERY plane, | 38058 | +/// libaom's `read_tx_size` (`av1/decoder/decodeframe.c:1197`, |
| 38059 | -/// not just luma), read by the same per-unit walk the bigger inter blocks | 38059 | +/// `if (xd->lossless[xd->mi[0]->segment_id]) return TX_4X4;`) returns TX_4X4 |
| 38060 | -/// run. Returns the two block grids composed at stride 8 (`Grid::Zero` when | 38060 | +/// for EVERY plane of a lossless block, not just luma, so the plane block is |
| 38061 | -/// every unit hung off the frame edge) and leaves each unit's own coefficient | 38061 | +/// a raster of TX_4X4 units read by the same per-unit walk the bigger inter |
| 38062 | -/// context stamped in the neighbour bands -- the caller's tail must not let | 38062 | +/// blocks run. |
| 38063 | -/// its whole-block `record_mi` overwrite them. | 38063 | +/// |
| 38064 | +/// **The plane block is PER-AXIS**, `av1_ss_size_lookup[BLOCK_8X8][ss_x][ss_y]` | ||
| 38065 | +/// (`av1/common/blockd.h:1186`): BLOCK_8X8 at 4:4:4 (2x2 units), BLOCK_4X8 at | ||
| 38066 | +/// 4:2:2 (1x2 units), BLOCK_4X4 at 4:2:0 (one unit, `get_txb_ctx`'s | ||
| 38067 | +/// `plane_bsize == txsize_to_bsize[tx_size]` branch, ctx_offset 7 -- the one | ||
| 38068 | +/// shape that keeps the single-unit read and is NOT routed here). Gating this | ||
| 38069 | +/// arm on the 4:4:4 shape instead left 4:2:2 coding its 4x8 plane block as ONE | ||
| 38070 | +/// TX_4X8 unit at ctx_offset 7, where libaom reads TWO TX_4X4 units at | ||
| 38071 | +/// ctx_offset 10 (`av1/common/txb_common.h:430-433`): the first unit's | ||
| 38072 | +/// `txb_skip` symbol then came out of the wrong CDF row, which desynchronised | ||
| 38073 | +/// the coder for the rest of the frame. | ||
| 38074 | +/// | ||
| 38075 | +/// `(blk_w, blk_h)` is that per-axis plane block and `stride` the composed | ||
| 38076 | +/// grid's row pitch (the leaf's `chroma_w`); the grids are `stride * blk_h` | ||
| 38077 | +/// (`Grid::Zero` when every unit hung off the frame edge) and each unit's own | ||
| 38078 | +/// coefficient context is left stamped in the neighbour bands -- the caller's | ||
| 38079 | +/// tail must not let its whole-block `record_mi` overwrite them. | ||
| 38064 | #[allow(clippy::too_many_arguments)] | 38080 | #[allow(clippy::too_many_arguments)] |
| 38065 | fn leaf8_inter_chroma_lossless( | 38081 | fn leaf8_inter_chroma_lossless( |
| 38066 | dec: &mut SymbolDecoder, | 38082 | dec: &mut SymbolDecoder, |
| @@ -38072,6 +38088,10 @@ fn leaf8_inter_chroma_lossless( | |||
| 38072 | sv: Pred<'_>, | 38088 | sv: Pred<'_>, |
| 38073 | at_mi: (usize, usize), | 38089 | at_mi: (usize, usize), |
| 38074 | (cpx, cpy): (usize, usize), | 38090 | (cpx, cpy): (usize, usize), |
| 38091 | + // The leaf's CHROMA PLANE BLOCK, per axis, and the composed grid's row | ||
| 38092 | + // pitch -- `(8, 8)`/`8` at 4:4:4, `(4, 8)`/`4` at 4:2:2. | ||
| 38093 | + (blk_w, blk_h): (usize, usize), | ||
| 38094 | + stride: usize, | ||
| 38075 | base_q_idx: u8, | 38095 | base_q_idx: u8, |
| 38076 | fctx: &crate::decode::FrameCtx, | 38096 | fctx: &crate::decode::FrameCtx, |
| 38077 | ) -> Result<(Grid, Grid)> { | 38097 | ) -> Result<(Grid, Grid)> { |
| @@ -38087,23 +38107,24 @@ fn leaf8_inter_chroma_lossless( | |||
| 38087 | at_mi, | 38107 | at_mi, |
| 38088 | (cpx, cpy), | 38108 | (cpx, cpy), |
| 38089 | (0, 0), | 38109 | (0, 0), |
| 38090 | - (8, 8), | 38110 | + (blk_w, blk_h), |
| 38091 | - (8, 8), | 38111 | + (blk_w, blk_h), |
| 38092 | - 8, | 38112 | + stride, |
| 38093 | 0, | 38113 | 0, |
| 38094 | base_q_idx, | 38114 | base_q_idx, |
| 38095 | &mut uo, | 38115 | &mut uo, |
| 38096 | &mut vo, | 38116 | &mut vo, |
| 38097 | fctx, | 38117 | fctx, |
| 38098 | )?; | 38118 | )?; |
| 38119 | + let n = stride * blk_h; | ||
| 38099 | Ok(( | 38120 | Ok(( |
| 38100 | if uo.is_empty() { | 38121 | if uo.is_empty() { |
| 38101 | - Grid::Zero(64) | 38122 | + Grid::Zero(n) |
| 38102 | } else { | 38123 | } else { |
| 38103 | Grid::Own(uo) | 38124 | Grid::Own(uo) |
| 38104 | }, | 38125 | }, |
| 38105 | if vo.is_empty() { | 38126 | if vo.is_empty() { |
| 38106 | - Grid::Zero(64) | 38127 | + Grid::Zero(n) |
| 38107 | } else { | 38128 | } else { |
| 38108 | Grid::Own(vo) | 38129 | Grid::Own(vo) |
| 38109 | }, | 38130 | }, |
| @@ -49982,12 +50003,15 @@ fn decode_inter_block8( | |||
| 49982 | fctx, | 50003 | fctx, |
| 49983 | )?; | 50004 | )?; |
| 49984 | luma_grid = grid8; | 50005 | luma_grid = grid8; |
| 49985 | - // 4:4:4 lossless 8x8 inter leaf: the chroma plane block is | 50006 | + // Lossless 8x8 inter leaf: `av1_get_tx_size` returns |
| 49986 | - // the 8x8 leaf itself, read as one unit by the 444 walk | 50007 | + // TX_4X4 for EVERY plane of a lossless block |
| 49987 | - // (`chroma_w == 8` is `SIDE >> ss_x == 8`, i.e. ss_x 0). | 50008 | + // (`decodeframe.c:1197`), so the chroma plane block is a |
| 49988 | - // The 4:2:2 rect unit and the 4:2:0/4:4:4 square read are | 50009 | + // raster of TX_4X4 units whenever it is BIGGER than one -- |
| 49989 | - // the `else` below, dispatched on `chroma_422`. | 50010 | + // 4:4:4's 8x8 (2x2) and 4:2:2's 4x8 (1x2). Only 4:2:0's |
| 49990 | - if chroma_w == 8 && lossless(fctx) && !mono(fctx) { | 50011 | + // 4x4 keeps the single-unit read, where |
| 50012 | + // `plane_bsize == txsize_to_bsize[tx_size]` puts | ||
| 50013 | + // `get_txb_ctx`'s ctx_offset at 7. | ||
| 50014 | + if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) { | ||
| 49991 | let (ug, vg) = leaf8_inter_chroma_lossless( | 50015 | let (ug, vg) = leaf8_inter_chroma_lossless( |
| 49992 | dec, | 50016 | dec, |
| 49993 | cdfs, | 50017 | cdfs, |
| @@ -49998,6 +50022,8 @@ fn decode_inter_block8( | |||
| 49998 | sv, | 50022 | sv, |
| 49999 | leaf_mi, | 50023 | leaf_mi, |
| 50000 | (cpx, cpy), | 50024 | (cpx, cpy), |
| 50025 | + (chroma_w, chroma_h), | ||
| 50026 | + chroma_w, | ||
| 50001 | base_q_idx, | 50027 | base_q_idx, |
| 50002 | fctx, | 50028 | fctx, |
| 50003 | )?; | 50029 | )?; |
| @@ -50941,11 +50967,10 @@ fn decode_inter_block8( | |||
| 50941 | fctx, | 50967 | fctx, |
| 50942 | )?; | 50968 | )?; |
| 50943 | luma_grid = grid8; | 50969 | luma_grid = grid8; |
| 50944 | - // 4:4:4 lossless 8x8 inter leaf (compound twin of the single-ref | 50970 | + // Lossless 8x8 inter leaf, compound twin of the single-ref arm |
| 50945 | - // arm above): the chroma plane block is the 8x8 leaf itself, read | 50971 | + // above -- same per-axis plane block (4:4:4 8x8, 4:2:2 4x8) and |
| 50946 | - // as one unit by the 444 walk. The 4:2:2 rect unit and the | 50972 | + // the same "bigger than one TX_4X4" gate. |
| 50947 | - // 4:2:0/4:4:4 square read are the `else` below. | 50973 | + if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) { |
| 50948 | - if chroma_w == 8 && lossless(fctx) && !mono(fctx) { | ||
| 50949 | let (ug, vg) = leaf8_inter_chroma_lossless( | 50974 | let (ug, vg) = leaf8_inter_chroma_lossless( |
| 50950 | dec, | 50975 | dec, |
| 50951 | cdfs, | 50976 | cdfs, |
| @@ -50956,6 +50981,8 @@ fn decode_inter_block8( | |||
| 50956 | sv, | 50981 | sv, |
| 50957 | leaf_mi, | 50982 | leaf_mi, |
| 50958 | (cpx, cpy), | 50983 | (cpx, cpy), |
| 50984 | + (chroma_w, chroma_h), | ||
| 50985 | + chroma_w, | ||
| 50959 | base_q_idx, | 50986 | base_q_idx, |
| 50960 | fctx, | 50987 | fctx, |
| 50961 | )?; | 50988 | )?; |
| @@ -51563,19 +51590,22 @@ fn decode_inter_block8( | |||
| 51563 | } else { | 51590 | } else { |
| 51564 | (around[1], around[2]) | 51591 | (around[1], around[2]) |
| 51565 | }; | 51592 | }; |
| 51566 | - if chroma_w == 8 && lossless(fctx) && !mono(fctx) { | ||
| 51567 | // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane | 51593 | // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane |
| 51568 | - // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's 8x8 | 51594 | + // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's chroma |
| 51569 | - // chroma plane block is a 2x2 raster of TX_4X4 units per | 51595 | + // plane block is a raster of TX_4X4 units per plane, plane-major |
| 51570 | - // plane, plane-major -- the same per-unit walk the >=16x16 | 51596 | + // -- the same per-unit walk the >=16x16 intra-in-inter block |
| 51571 | - // intra-in-inter block runs, not one TX_8X8 unit (whose WHT | 51597 | + // runs, not one TX_8X8 unit (whose WHT hits `TxParams::run`'s |
| 51572 | - // hits `TxParams::run`'s `(8, 8) != (4, 4)` lossless assert). | 51598 | + // `(8, 8) != (4, 4)` lossless assert). The plane block is |
| 51599 | + // PER-AXIS, `av1_ss_size_lookup[BLOCK_8X8][ss_x][ss_y]`: 8x8 at | ||
| 51600 | + // 4:4:4 (2x2 units) and 4x8 at 4:2:2 (1x2), so both walk here and | ||
| 51601 | + // only 4:2:0's 4x4 keeps the single-unit read in the `else` | ||
| 51602 | + // below (`plane_bsize == txsize_to_bsize[tx_size]`, ctx_offset 7). | ||
| 51573 | // The walk stamps each unit's own coefficient context | 51603 | // The walk stamps each unit's own coefficient context |
| 51574 | // (`record_mi_chroma` inside it), so the tail's whole-block | 51604 | // (`record_mi_chroma` inside it), so the tail's whole-block |
| 51575 | // `record_mi` gets its chroma half saved/restored around -- | 51605 | // `record_mi` gets its chroma half saved/restored around -- |
| 51576 | // the same rule the INTER arms' | 51606 | // the same rule the INTER arms' |
| 51577 | - // `leaf8_inter_chroma_lossless` obeys. 4:2:0 keeps its single | 51607 | + // `leaf8_inter_chroma_lossless` obeys. |
| 51578 | - // TX_4X4 unit in the `else` below. | 51608 | + if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) { |
| 51579 | let (mut uo, mut vo) = (Vec::new(), Vec::new()); | 51609 | let (mut uo, mut vo) = (Vec::new(), Vec::new()); |
| 51580 | read_intra_chroma_lossless( | 51610 | read_intra_chroma_lossless( |
| 51581 | dec, | 51611 | dec, |
| @@ -51587,9 +51617,9 @@ fn decode_inter_block8( | |||
| 51587 | (px, py), | 51617 | (px, py), |
| 51588 | (cpx, cpy), | 51618 | (cpx, cpy), |
| 51589 | SIDE, | 51619 | SIDE, |
| 51590 | - (chroma_w, chroma_w), | 51620 | + (chroma_w, chroma_h), |
| 51591 | (0, 0), | 51621 | (0, 0), |
| 51592 | - (chroma_w, chroma_w), | 51622 | + (chroma_w, chroma_h), |
| 51593 | chroma_w, | 51623 | chroma_w, |
| 51594 | reach, | 51624 | reach, |
| 51595 | (y.width, y.height), | 51625 | (y.width, y.height), |
| @@ -51604,12 +51634,12 @@ fn decode_inter_block8( | |||
| 51604 | fctx, | 51634 | fctx, |
| 51605 | )?; | 51635 | )?; |
| 51606 | u_grid = if uo.is_empty() { | 51636 | u_grid = if uo.is_empty() { |
| 51607 | - Grid::Zero(64) | 51637 | + Grid::Zero(chroma_w * chroma_h) |
| 51608 | } else { | 51638 | } else { |
| 51609 | Grid::Own(uo) | 51639 | Grid::Own(uo) |
| 51610 | }; | 51640 | }; |
| 51611 | v_grid = if vo.is_empty() { | 51641 | v_grid = if vo.is_empty() { |
| 51612 | - Grid::Zero(64) | 51642 | + Grid::Zero(chroma_w * chroma_h) |
| 51613 | } else { | 51643 | } else { |
| 51614 | Grid::Own(vo) | 51644 | Grid::Own(vo) |
| 51615 | }; | 51645 | }; |