forge
Explore
Log in

Don't you dare go Hollow

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 commit

3685753175c8b284a9874f086fe2ab5b77ce2c2aAhmet Kaan GümüşParent: b510942
libaom's read_tx_size (av1/decoder/decodeframe.c:1197) returns TX_4X4 for
EVERY plane of a lossless block, and get_txb_ctx (av1/common/txb_common.h,
the chroma branch) reads txb_skip_ctx = combine_entropy_contexts(a,l) +
ctx_offset with ctx_offset 10 whenever the plane block is bigger than the
transform. The plane block is per-axis --
av1_ss_size_lookup[BLOCK_8X8][ss_x][ss_y] is 8x8 at 4:4:4, 4x8 at 4:2:2,
4x4 at 4:2:0 -- so a lossless 8x8 inter leaf codes a 2x2 raster of TX_4X4
units at 4:4:4, a 1x2 raster at offset 10 at 4:2:2, and a SINGLE unit at
offset 7 only at 4:2:0.

All three 8x8-leaf lossless arms (single-ref inter, compound inter,
intra-in-inter) gated that walk on `chroma_w == 8`, i.e. on ss_x == 0, so
4:2:2 fell through to the one-unit TX_4X8 read at offset 7. The first
4:2:2 chroma unit's txb_skip symbol then came out of the wrong CDF row
against an identical coder state, which desynchronises the rest of the
frame. The intra-in-inter arm additionally passed (chroma_w, chroma_w)
where the plane block is (chroma_w, chroma_h).

Gated on `chroma_w > 4 || chroma_h > 4` -- the same predicate
read_inter_chroma_lossless already uses to pick the offset-10 rows -- and
threaded the per-axis plane block and the composed grid's row pitch
through leaf8_inter_chroma_lossless and the intra call.
crates/ec-av1/src/decode.rsmodified+71 -41
@@ -38053,14 +38053,30 @@ fn read_inter_chroma_lossless(
3805338053 Ok(())
3805438054 }
3805538055
38056-/// The 8x8 inter leaf's lossless 4:4:4 chroma arm (lane-av1-llinter), shared
38057-/// by the single-ref and compound paths: the plane block is a 2x2 raster of
38058-/// TX_4X4 units (`av1_get_tx_size`: lossless returns TX_4X4 for EVERY plane,
38059-/// not just luma), read by the same per-unit walk the bigger inter blocks
38060-/// run. Returns the two block grids composed at stride 8 (`Grid::Zero` when
38061-/// every unit hung off the frame edge) and leaves each unit's own coefficient
38062-/// context stamped in the neighbour bands -- the caller's tail must not let
38063-/// its whole-block `record_mi` overwrite them.
38056+/// The 8x8 inter leaf's lossless chroma arm (lane-av1-llinter), shared by the
38057+/// single-ref and compound paths, for every plane block BIGGER than 4x4:
38058+/// libaom's `read_tx_size` (`av1/decoder/decodeframe.c:1197`,
38059+/// `if (xd->lossless[xd->mi[0]->segment_id]) return TX_4X4;`) returns TX_4X4
38060+/// for EVERY plane of a lossless block, not just luma, so the plane block is
38061+/// a raster of TX_4X4 units read by the same per-unit walk the bigger inter
38062+/// blocks run.
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.
3806438080 #[allow(clippy::too_many_arguments)]
3806538081 fn leaf8_inter_chroma_lossless(
3806638082 dec: &mut SymbolDecoder,
@@ -38072,6 +38088,10 @@ fn leaf8_inter_chroma_lossless(
3807238088 sv: Pred<'_>,
3807338089 at_mi: (usize, usize),
3807438090 (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,
3807538095 base_q_idx: u8,
3807638096 fctx: &crate::decode::FrameCtx,
3807738097 ) -> Result<(Grid, Grid)> {
@@ -38087,23 +38107,24 @@ fn leaf8_inter_chroma_lossless(
3808738107 at_mi,
3808838108 (cpx, cpy),
3808938109 (0, 0),
38090- (8, 8),
38091- (8, 8),
38092- 8,
38110+ (blk_w, blk_h),
38111+ (blk_w, blk_h),
38112+ stride,
3809338113 0,
3809438114 base_q_idx,
3809538115 &mut uo,
3809638116 &mut vo,
3809738117 fctx,
3809838118 )?;
38119+ let n = stride * blk_h;
3809938120 Ok((
3810038121 if uo.is_empty() {
38101- Grid::Zero(64)
38122+ Grid::Zero(n)
3810238123 } else {
3810338124 Grid::Own(uo)
3810438125 },
3810538126 if vo.is_empty() {
38106- Grid::Zero(64)
38127+ Grid::Zero(n)
3810738128 } else {
3810838129 Grid::Own(vo)
3810938130 },
@@ -49982,12 +50003,15 @@ fn decode_inter_block8(
4998250003 fctx,
4998350004 )?;
4998450005 luma_grid = grid8;
49985- // 4:4:4 lossless 8x8 inter leaf: the chroma plane block is
49986- // the 8x8 leaf itself, read as one unit by the 444 walk
49987- // (`chroma_w == 8` is `SIDE >> ss_x == 8`, i.e. ss_x 0).
49988- // The 4:2:2 rect unit and the 4:2:0/4:4:4 square read are
49989- // the `else` below, dispatched on `chroma_422`.
49990- if chroma_w == 8 && lossless(fctx) && !mono(fctx) {
50006+ // Lossless 8x8 inter leaf: `av1_get_tx_size` returns
50007+ // TX_4X4 for EVERY plane of a lossless block
50008+ // (`decodeframe.c:1197`), so the chroma plane block is a
50009+ // raster of TX_4X4 units whenever it is BIGGER than one --
50010+ // 4:4:4's 8x8 (2x2) and 4:2:2's 4x8 (1x2). Only 4:2:0's
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) {
4999150015 let (ug, vg) = leaf8_inter_chroma_lossless(
4999250016 dec,
4999350017 cdfs,
@@ -49998,6 +50022,8 @@ fn decode_inter_block8(
4999850022 sv,
4999950023 leaf_mi,
5000050024 (cpx, cpy),
50025+ (chroma_w, chroma_h),
50026+ chroma_w,
5000150027 base_q_idx,
5000250028 fctx,
5000350029 )?;
@@ -50941,11 +50967,10 @@ fn decode_inter_block8(
5094150967 fctx,
5094250968 )?;
5094350969 luma_grid = grid8;
50944- // 4:4:4 lossless 8x8 inter leaf (compound twin of the single-ref
50945- // arm above): the chroma plane block is the 8x8 leaf itself, read
50946- // as one unit by the 444 walk. The 4:2:2 rect unit and the
50947- // 4:2:0/4:4:4 square read are the `else` below.
50948- if chroma_w == 8 && lossless(fctx) && !mono(fctx) {
50970+ // Lossless 8x8 inter leaf, compound twin of the single-ref arm
50971+ // above -- same per-axis plane block (4:4:4 8x8, 4:2:2 4x8) and
50972+ // the same "bigger than one TX_4X4" gate.
50973+ if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) {
5094950974 let (ug, vg) = leaf8_inter_chroma_lossless(
5095050975 dec,
5095150976 cdfs,
@@ -50956,6 +50981,8 @@ fn decode_inter_block8(
5095650981 sv,
5095750982 leaf_mi,
5095850983 (cpx, cpy),
50984+ (chroma_w, chroma_h),
50985+ chroma_w,
5095950986 base_q_idx,
5096050987 fctx,
5096150988 )?;
@@ -51563,19 +51590,22 @@ fn decode_inter_block8(
5156351590 } else {
5156451591 (around[1], around[2])
5156551592 };
51566- if chroma_w == 8 && lossless(fctx) && !mono(fctx) {
51567- // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane
51568- // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's 8x8
51569- // chroma plane block is a 2x2 raster of TX_4X4 units per
51570- // plane, plane-major -- the same per-unit walk the >=16x16
51571- // intra-in-inter block runs, not one TX_8X8 unit (whose WHT
51572- // hits `TxParams::run`'s `(8, 8) != (4, 4)` lossless assert).
51573- // The walk stamps each unit's own coefficient context
51574- // (`record_mi_chroma` inside it), so the tail's whole-block
51575- // `record_mi` gets its chroma half saved/restored around --
51576- // the same rule the INTER arms'
51577- // `leaf8_inter_chroma_lossless` obeys. 4:2:0 keeps its single
51578- // TX_4X4 unit in the `else` below.
51593+ // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane
51594+ // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's chroma
51595+ // plane block is a raster of TX_4X4 units per plane, plane-major
51596+ // -- the same per-unit walk the >=16x16 intra-in-inter block
51597+ // runs, not one TX_8X8 unit (whose WHT hits `TxParams::run`'s
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).
51603+ // The walk stamps each unit's own coefficient context
51604+ // (`record_mi_chroma` inside it), so the tail's whole-block
51605+ // `record_mi` gets its chroma half saved/restored around --
51606+ // the same rule the INTER arms'
51607+ // `leaf8_inter_chroma_lossless` obeys.
51608+ if lossless(fctx) && (chroma_w > 4 || chroma_h > 4) && !mono(fctx) {
5157951609 let (mut uo, mut vo) = (Vec::new(), Vec::new());
5158051610 read_intra_chroma_lossless(
5158151611 dec,
@@ -51587,9 +51617,9 @@ fn decode_inter_block8(
5158751617 (px, py),
5158851618 (cpx, cpy),
5158951619 SIDE,
51590- (chroma_w, chroma_w),
51620+ (chroma_w, chroma_h),
5159151621 (0, 0),
51592- (chroma_w, chroma_w),
51622+ (chroma_w, chroma_h),
5159351623 chroma_w,
5159451624 reach,
5159551625 (y.width, y.height),
@@ -51604,12 +51634,12 @@ fn decode_inter_block8(
5160451634 fctx,
5160551635 )?;
5160651636 u_grid = if uo.is_empty() {
51607- Grid::Zero(64)
51637+ Grid::Zero(chroma_w * chroma_h)
5160851638 } else {
5160951639 Grid::Own(uo)
5161051640 };
5161151641 v_grid = if vo.is_empty() {
51612- Grid::Zero(64)
51642+ Grid::Zero(chroma_w * chroma_h)
5161351643 } else {
5161451644 Grid::Own(vo)
5161551645 };