forge
Explore
Log in

Don't you dare go Hollow

Revert the tx_depth context pricing: no split-lambda calibration recovers it

Browse files at this commit

9c0f6290873d02aba36396b6b2af49a486cf151dAhmet Kaan GümüşParent: 651e207
lane-split's charter. With the correct pricing on, EC_AV1_SPLIT_LAMBDA sweeps
0.6/0.8/1.0/1.25/1.5/2.0 on the film B gate row to +28.4/+0.5, +26.1/-0.9,
+25.2/-1.6, +25.9/-1.1, +26.2/-0.9, +26.3/-0.8: a single-peaked curve whose
optimum IS the control weight, and every point is worse than the row-0-priced
control (+24.9/-1.9). So the split trial's rate weight was not the
mis-calibrated term either, and the pricing fix goes back out; the census and
the swept knob (SPLIT_LAMBDA = 1.0) stay. Encoder output is byte-identical to
2caf213b (both stream pins green, unmoved).
crates/ec-av1/src/encode.rsmodified+27 -208
@@ -4227,21 +4227,17 @@ fn max_tx_depth(side: usize) -> usize {
4227 }4227 }
4228 }4228 }
4229 4229
4230-/// What the `tx_depth` symbol itself costs, off the size category's own CDF4230+/// What the `tx_depth` symbol itself costs, off the size category's own CDF.
4231-/// at `ctx` -- the row [`crate::tile::tx_size_ctx_of`] picks from the4231+/// Priced at context row 0 -- the writer picks the real row from its
4232-/// transform sides the blocks above and to the left published, which is what4232+/// neighbours' transform sizes, which the search has no view of; the term is
4233-/// the writer's `write_luma_select` codes the symbol against.4233+/// the same for every depth of one block either way, so it only shifts the
4234-///4234+/// depth-0-versus-split margin, never the ordering between two splits.
4235-/// Before lane-ctx2 this was row 0 for every block (class4235+fn tx_depth_bits(side: usize, depth: usize) -> f64 {
4236-/// `pricer-context-zero`): the term shifts the depth-0-versus-split margin,
4237-/// and row 0 is the row where BOTH neighbours are narrower than this block's
4238-/// transform -- the case in which splitting reads cheapest.
4239-fn tx_depth_bits(ctx: usize, side: usize, depth: usize) -> f64 {
4240 match side {4236 match side {
4241- 8 => symbol_bits(&cdf::TX_SIZE_CAT0[ctx], depth),4237+ 8 => symbol_bits(&cdf::TX_SIZE_CAT0[0], depth),
4242- 16 => symbol_bits(&cdf::TX_SIZE_CAT1[ctx], depth),4238+ 16 => symbol_bits(&cdf::TX_SIZE_CAT1[0], depth),
4243- 32 => symbol_bits(&cdf::TX_SIZE_CAT2[ctx], depth),4239+ 32 => symbol_bits(&cdf::TX_SIZE_CAT2[0], depth),
4244- _ => symbol_bits(&cdf::TX_SIZE_CAT3[ctx], depth),4240+ _ => symbol_bits(&cdf::TX_SIZE_CAT3[0], depth),
4245 }4241 }
4246 }4242 }
4247 4243
@@ -5345,13 +5341,9 @@ fn code_square(
5345 // This tile's intra block-copy state ([`Ibc`]), `None` on a frame whose5341 // This tile's intra block-copy state ([`Ibc`]), `None` on a frame whose
5346 // header did not set `allow_intrabc`.5342 // header did not set `allow_intrabc`.
5347 ibc: Option<&mut Ibc>,5343 ibc: Option<&mut Ibc>,
5348- // The CDF row this block's `tx_depth` symbol is priced against
5349- // ([`tx_depth_bits`]), read by the caller off its own published transform
5350- // bands -- `0` where the caller keeps none.
5351- tx_ctx: usize,
5352 // Whether this is a KEY frame's block, read only by the split census5344 // Whether this is a KEY frame's block, read only by the split census
5353- // ([`SPLIT_CENSUS`]): the two frame types price `tx_depth` off different5345+ // ([`SPLIT_CENSUS`]): the two frame types split at very different rates,
5354- // band sets and split at different rates, which is the whole finding.5346+ // which is this lane's whole finding.
5355 census_key: bool,5347 census_key: bool,
5356 fctx: &crate::decode::FrameCtx,5348 fctx: &crate::decode::FrameCtx,
5357 ) -> (BlockCoeffs, f64) {5349 ) -> (BlockCoeffs, f64) {
@@ -5397,11 +5389,11 @@ fn code_square(
5397 // `tx_depth_bits(32, 0)` -- otherwise the 64-versus-four-32 comparison5389 // `tx_depth_bits(32, 0)` -- otherwise the 64-versus-four-32 comparison
5398 // below hands the root a symbol for free.5390 // below hands the root a symbol for free.
5399 if tx_select && side == SUPERBLOCK {5391 if tx_select && side == SUPERBLOCK {
5400- cost += search.lambda * tx_depth_bits(tx_ctx, side, 0);5392+ cost += search.lambda * tx_depth_bits(side, 0);
5401 }5393 }
5402 if tx_select && max_tx_depth(side) > 0 {5394 if tx_select && max_tx_depth(side) > 0 {
5403 let mut best = (5395 let mut best = (
5404- cost + search.lambda * tx_depth_bits(tx_ctx, side, 0),5396+ cost + search.lambda * tx_depth_bits(side, 0),
5405 0usize,5397 0usize,
5406 luma.snapshot(x, y, side),5398 luma.snapshot(x, y, side),
5407 luma_coeffs,5399 luma_coeffs,
@@ -5415,16 +5407,16 @@ fn code_square(
5415 let (_, sse, bits, _) =5407 let (_, sse, bits, _) =
5416 luma.code_tx_depth(at, mode, angle_delta, 0, None, search, fctx);5408 luma.code_tx_depth(at, mode, angle_delta, 0, None, search, fctx);
5417 luma.restore(x, y, side, &kept);5409 luma.restore(x, y, side, &kept);
5418- (bits + tx_depth_bits(tx_ctx, side, 0), sse)5410+ (bits + tx_depth_bits(side, 0), sse)
5419 });5411 });
5420 let mut census_split: Option<(f64, f64)> = None;5412 let mut census_split: Option<(f64, f64)> = None;
5421 for depth in 1..=max_tx_depth(side) {5413 for depth in 1..=max_tx_depth(side) {
5422 let (levels, sse, bits, types) =5414 let (levels, sse, bits, types) =
5423 luma.code_tx_depth(at, mode, angle_delta, depth, None, search, fctx);5415 luma.code_tx_depth(at, mode, angle_delta, depth, None, search, fctx);
5424- let rate = bits + mode_bits[usize::from(mode)] + tx_depth_bits(tx_ctx, side, depth);5416+ let rate = bits + mode_bits[usize::from(mode)] + tx_depth_bits(side, depth);
5425 let cost_d = sse + search.lambda * split_lambda_mult() * rate;5417 let cost_d = sse + search.lambda * split_lambda_mult() * rate;
5426 if census_flat.is_some() {5418 if census_flat.is_some() {
5427- let c = (bits + tx_depth_bits(tx_ctx, side, depth), sse);5419+ let c = (bits + tx_depth_bits(side, depth), sse);
5428 if census_split.is_none_or(|b| sse + search.lambda * rate < b.1 + search.lambda * b.0)5420 if census_split.is_none_or(|b| sse + search.lambda * rate < b.1 + search.lambda * b.0)
5429 {5421 {
5430 census_split = Some(c);5422 census_split = Some(c);
@@ -5480,7 +5472,7 @@ fn code_square(
5480 * (trial.bits5472 * (trial.bits
5481 + mode_bits[DC_PRED as usize]5473 + mode_bits[DC_PRED as usize]
5482 + crate::tile::palette_bits(&pal, side)5474 + crate::tile::palette_bits(&pal, side)
5483- + if tx_select { tx_depth_bits(tx_ctx, side, 0) } else { 0.0 });5475+ + if tx_select { tx_depth_bits(side, 0) } else { 0.0 });
5484 if cost_p < cost {5476 if cost_p < cost {
5485 cost = cost_p;5477 cost = cost_p;
5486 mode = DC_PRED as u8;5478 mode = DC_PRED as u8;
@@ -5546,7 +5538,7 @@ fn code_square(
5546 + mode_bits[DC_PRED as usize]5538 + mode_bits[DC_PRED as usize]
5547 + one_bits5539 + one_bits
5548 + symbol_bits(&cdf::FILTER_INTRA_MODE, usize::from(fi))5540 + symbol_bits(&cdf::FILTER_INTRA_MODE, usize::from(fi))
5549- + if tx_select { tx_depth_bits(tx_ctx, side, depth) } else { 0.0 });5541+ + if tx_select { tx_depth_bits(side, depth) } else { 0.0 });
5550 if cost_f < cost && best.as_ref().is_none_or(|b| cost_f < b.0) {5542 if cost_f < cost && best.as_ref().is_none_or(|b| cost_f < b.0) {
5551 best = Some((5543 best = Some((
5552 cost_f,5544 cost_f,
@@ -6268,11 +6260,6 @@ fn code_square_inter(
6268 mode_bits,6260 mode_bits,
6269 tx_select() && tx_select_inter(),6261 tx_select() && tx_select_inter(),
6270 None,6262 None,
6271- // lane-txd: an INTER frame's intra block takes its `tx_depth` row
6272- // from the `TXFM_CONTEXT` bands (`tx_size_ctx_txfm`, where an
6273- // inter neighbour votes its own BLOCK size), which `record_mi`
6274- // now publishes per cell.
6275- tx_ctx_txfm(grid, (mi_row, mi_col), side.min(64)),
6276 false,6263 false,
6277 fctx,6264 fctx,
6278 );6265 );
@@ -6977,31 +6964,6 @@ fn code_square_inter(
6977 /// MV stack reads, over the `size` x `size` 4x4 units it covers. An intra6964 /// MV stack reads, over the `size` x `size` 4x4 units it covers. An intra
6978 /// block casts no vote but is still a coded cell (see `code_square_inter`'s6965 /// block casts no vote but is still a coded cell (see `code_square_inter`'s
6979 /// note on `processed_rows`/`processed_cols`).6966 /// note on `processed_rows`/`processed_cols`).
6980-/// What one coded block publishes into the `TXFM_CONTEXT` bands, in pixels:
6981-/// a SKIPPED inter block records its own BLOCK size (`set_txfm_ctxs`'s
6982-/// `skip_inter` term), every other block its resolved transform
6983-/// (`tile::write_tx_syntax_inter`'s `record_txfm` calls, all of which cover
6984-/// the block's whole span with one value).
6985-fn txfm_px(side: usize, inter: bool, skip: bool, tx_depth: u8) -> u8 {
6986- if inter && skip { side as u8 } else { (side.min(64) >> tx_depth) as u8 }
6987-}
6988-
6989-/// The CDF row an INTER frame's intra block has its `tx_depth` symbol coded
6990-/// against ([`crate::tile::Neighbours::tx_size_ctx_txfm`]), read off the grid
6991-/// the encoder publishes its own blocks into -- the above/left 4x4 cell, each
6992-/// contributing nothing when it falls outside this tile (`MiGrid::get`'s own
6993-/// window, which is the writer's `has_above`/`has_left`).
6994-fn tx_ctx_txfm(grid: &MiGrid, (mi_row, mi_col): (usize, usize), own_side: usize) -> usize {
6995- let cell = |r: usize, c: usize| {
6996- grid.get(r, c).map(|i| (grid.txfm_at(r, c), i.is_inter, usize::from(i.size) * 4))
6997- };
6998- crate::tile::tx_size_ctx_txfm_of(
6999- mi_row.checked_sub(1).and_then(|r| cell(r, mi_col)),
7000- mi_col.checked_sub(1).and_then(|c| cell(mi_row, c)),
7001- own_side,
7002- )
7003-}
7004-
7005 fn record_mi(6967 fn record_mi(
7006 grid: &mut MiGrid,6968 grid: &mut MiGrid,
7007 mi_row: usize,6969 mi_row: usize,
@@ -7011,10 +6973,6 @@ fn record_mi(
7011 // lane-ctx: the block's own `skip`, so the next block's MV stack can hand6973 // lane-ctx: the block's own `skip`, so the next block's MV stack can hand
7012 // the RD pricer the two cells the writer's `skip_ctx` sums.6974 // the RD pricer the two cells the writer's `skip_ctx` sums.
7013 skip: bool,6975 skip: bool,
7014- // lane-txd: the transform side, in pixels, this block leaves in the
7015- // `TXFM_CONTEXT` bands ([`txfm_px`]), which is the state the next intra
7016- // block's `tx_depth` row is read from.
7017- txfm: u8,
7018 ) {6976 ) {
7019 let info = match inter {6977 let info = match inter {
7020 Some(info) => MiInfo {6978 Some(info) => MiInfo {
@@ -7060,7 +7018,6 @@ fn record_mi(
7060 for dc in 0..usize::from(size) {7018 for dc in 0..usize::from(size) {
7061 grid.set(mi_row + dr, mi_col + dc, info);7019 grid.set(mi_row + dr, mi_col + dc, info);
7062 grid.set_skip(mi_row + dr, mi_col + dc, skip);7020 grid.set_skip(mi_row + dr, mi_col + dc, skip);
7063- grid.set_txfm(mi_row + dr, mi_col + dc, txfm);
7064 }7021 }
7065 }7022 }
7066 }7023 }
@@ -7859,38 +7816,6 @@ pub(crate) fn encode_key_frame_inner(
7859 clip_planes_to_tile(&mut luma, &mut chroma, rect);7816 clip_planes_to_tile(&mut luma, &mut chroma, rect);
7860 let mut above_mode = vec![DC_PRED; cols * 2];7817 let mut above_mode = vec![DC_PRED; cols * 2];
7861 let mut left_mode = vec![DC_PRED; rows * 2];7818 let mut left_mode = vec![DC_PRED; rows * 2];
7862- // lane-ctx2: the two bands `Neighbours::tx_size_ctx` reads -- every
7863- // coded block's resolved luma transform side in pixels, over each 4x4
7864- // unit it covers, the way the writer's `record_tx` publishes it. The
7865- // indices are frame-absolute, so a new superblock row needs no reset
7866- // (the writer's `start_row` clears a band indexed within the tile),
7867- // and a block trial that loses is overwritten by the winner's own
7868- // publish, exactly as `above_mode`/`left_mode` are.
7869- let mut above_tx = vec![0u8; cols * 8];
7870- let mut left_tx = vec![0u8; rows * 8];
7871- let tx_ctx = |above_tx: &[u8], left_tx: &[u8], (x, y): (usize, usize), side: usize| {
7872- let (mi_r, mi_c) = (y / 4, x / 4);
7873- crate::tile::tx_size_ctx_of(
7874- (mi_r > rect.mi_row0 as usize, mi_c > rect.mi_col0 as usize),
7875- (above_tx[mi_c], left_tx[mi_r]),
7876- side.min(64),
7877- )
7878- };
7879- let publish_tx = |above_tx: &mut Vec<u8>,
7880- left_tx: &mut Vec<u8>,
7881- (x, y): (usize, usize),
7882- side: usize,
7883- depth: u8| {
7884- let tx = (side.min(64) >> depth) as u8;
7885- for cell in 0..side / 4 {
7886- if let Some(c) = above_tx.get_mut(x / 4 + cell) {
7887- *c = tx;
7888- }
7889- if let Some(c) = left_tx.get_mut(y / 4 + cell) {
7890- *c = tx;
7891- }
7892- }
7893- };
7894 let mut ibc = allow_intrabc.then(|| {7819 let mut ibc = allow_intrabc.then(|| {
7895 Ibc::new(7820 Ibc::new(
7896 (7821 (
@@ -7970,7 +7895,6 @@ pub(crate) fn encode_key_frame_inner(
7970 &mode_bits(above_mode[c64], left_mode[r64]),7895 &mode_bits(above_mode[c64], left_mode[r64]),
7971 tx_select,7896 tx_select,
7972 None,7897 None,
7973- tx_ctx(&above_tx, &left_tx, (x64, y64), SUPERBLOCK),
7974 true,7898 true,
7975 fctx,7899 fctx,
7976 );7900 );
@@ -8056,7 +7980,6 @@ pub(crate) fn encode_key_frame_inner(
8056 &mode_bits(above_mode[c0], left_mode[r0]),7980 &mode_bits(above_mode[c0], left_mode[r0]),
8057 tx_select,7981 tx_select,
8058 ibc.as_mut(),7982 ibc.as_mut(),
8059- tx_ctx(&above_tx, &left_tx, (x, y), BLOCK),
8060 true,7983 true,
8061 fctx,7984 fctx,
8062 );7985 );
@@ -8094,12 +8017,6 @@ pub(crate) fn encode_key_frame_inner(
8094 &mode_bits(above_mode[sc], left_mode[sr]),8017 &mode_bits(above_mode[sc], left_mode[sr]),
8095 tx_select,8018 tx_select,
8096 ibc.as_mut(),8019 ibc.as_mut(),
8097- tx_ctx(
8098- &above_tx,
8099- &left_tx,
8100- (x + (sub % 2) * SUB, y + (sub / 2) * SUB),
8101- SUB,
8102- ),
8103 true,8020 true,
8104 fctx,8021 fctx,
8105 );8022 );
@@ -8107,13 +8024,6 @@ pub(crate) fn encode_key_frame_inner(
8107 split_modes.push(block.mode);8024 split_modes.push(block.mode);
8108 above_mode[sc] = block.mode;8025 above_mode[sc] = block.mode;
8109 left_mode[sr] = block.mode;8026 left_mode[sr] = block.mode;
8110- publish_tx(
8111- &mut above_tx,
8112- &mut left_tx,
8113- (x + (sub % 2) * SUB, y + (sub / 2) * SUB),
8114- SUB,
8115- block.tx_depth,
8116- );
8117 split.push(block);8027 split.push(block);
8118 } else {8028 } else {
8119 // A straddling 16x16: two (or, at a true corner, one)8029 // A straddling 16x16: two (or, at a true corner, one)
@@ -8142,13 +8052,11 @@ pub(crate) fn encode_key_frame_inner(
8142 &leaf_mode_bits,8052 &leaf_mode_bits,
8143 tx_select,8053 tx_select,
8144 None,8054 None,
8145- tx_ctx(&above_tx, &left_tx, (leaf_x, leaf_y), 8),
8146 true,8055 true,
8147 fctx,8056 fctx,
8148 );8057 );
8149 cost_split += cost;8058 cost_split += cost;
8150 split_modes.push(leaf.mode);8059 split_modes.push(leaf.mode);
8151- publish_tx(&mut above_tx, &mut left_tx, (leaf_x, leaf_y), 8, leaf.tx_depth);
8152 leaves.push(leaf);8060 leaves.push(leaf);
8153 }8061 }
8154 split.push(BlockCoeffs {8062 split.push(BlockCoeffs {
@@ -8177,7 +8085,6 @@ pub(crate) fn encode_key_frame_inner(
8177 above_mode[c0 + cell] = whole.mode;8085 above_mode[c0 + cell] = whole.mode;
8178 left_mode[r0 + cell] = whole.mode;8086 left_mode[r0 + cell] = whole.mode;
8179 }8087 }
8180- publish_tx(&mut above_tx, &mut left_tx, (x, y), BLOCK, whole.tx_depth);
8181 modes.push(whole.mode);8088 modes.push(whole.mode);
8182 blocks.push(Quadrant::Whole(whole));8089 blocks.push(Quadrant::Whole(whole));
8183 }8090 }
@@ -8190,7 +8097,6 @@ pub(crate) fn encode_key_frame_inner(
8190 above_mode[sb_col * 4 + cell] = block.mode;8097 above_mode[sb_col * 4 + cell] = block.mode;
8191 left_mode[sb_row * 4 + cell] = block.mode;8098 left_mode[sb_row * 4 + cell] = block.mode;
8192 }8099 }
8193- publish_tx(&mut above_tx, &mut left_tx, (x64, y64), SUPERBLOCK, block.tx_depth);
8194 I64_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);8100 I64_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
8195 if !whole_inside {8101 if !whole_inside {
8196 I64_HITS[2].fetch_add(1, std::sync::atomic::Ordering::Relaxed);8102 I64_HITS[2].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
@@ -11740,8 +11646,7 @@ pub(crate) fn encode_inter_frame(
11740 fctx,11646 fctx,
11741 );11647 );
11742 cost8 += cost;11648 cost8 += cost;
11743- record_mi(&mut grid, mr, mc, 2, leaf8.inter, leaf8.skip,11649+ record_mi(&mut grid, mr, mc, 2, leaf8.inter, leaf8.skip);
11744- txfm_px(8, leaf8.inter.is_some(), leaf8.skip, leaf8.tx_depth));
11745 eight.push(leaf8);11650 eight.push(leaf8);
11746 }11651 }
11747 (eight, cost8)11652 (eight, cost8)
@@ -11763,8 +11668,7 @@ pub(crate) fn encode_inter_frame(
11763 }11668 }
11764 partition_hit(2);11669 partition_hit(2);
11765 cost += leaf_cost;11670 cost += leaf_cost;
11766- record_mi(&mut grid, mi_row, mi_col, 4, leaf.inter, leaf.skip,11671+ record_mi(&mut grid, mi_row, mi_col, 4, leaf.inter, leaf.skip);
11767- txfm_px(SUB, leaf.inter.is_some(), leaf.skip, leaf.tx_depth));
11768 leaves.push(leaf);11672 leaves.push(leaf);
11769 }11673 }
11770 (leaves, cost)11674 (leaves, cost)
@@ -11783,8 +11687,7 @@ pub(crate) fn encode_inter_frame(
11783 }11687 }
11784 partition_hit(0);11688 partition_hit(0);
11785 sb_cost += cost_whole;11689 sb_cost += cost_whole;
11786- record_mi(&mut grid, mi_row, mi_col, 8, block.inter, block.skip,11690+ record_mi(&mut grid, mi_row, mi_col, 8, block.inter, block.skip);
11787- txfm_px(BLOCK, block.inter.is_some(), block.skip, block.tx_depth));
11788 blocks.push((r32 * cols + c32, Quadrant::Whole(block)));11691 blocks.push((r32 * cols + c32, Quadrant::Whole(block)));
11789 } else {11692 } else {
11790 // The sub-positions actually inside the true frame, same11693 // The sub-positions actually inside the true frame, same
@@ -11851,8 +11754,7 @@ pub(crate) fn encode_inter_frame(
11851 // to (0,0), which is the encoder-grid-drift class11754 // to (0,0), which is the encoder-grid-drift class
11852 // -- correct only for as long as a leaf can never11755 // -- correct only for as long as a leaf can never
11853 // be compound.11756 // be compound.
11854- record_mi(&mut grid, mi_row, mi_col, 4, block.inter, block.skip,11757+ record_mi(&mut grid, mi_row, mi_col, 4, block.inter, block.skip);
11855- txfm_px(SUB, block.inter.is_some(), block.skip, block.tx_depth));
11856 leaves.push(block);11758 leaves.push(block);
11857 } else {11759 } else {
11858 let (x_sub, y_sub) = (sc * SUB, sr * SUB);11760 let (x_sub, y_sub) = (sc * SUB, sr * SUB);
@@ -11891,8 +11793,7 @@ pub(crate) fn encode_inter_frame(
11891 );11793 );
11892 // Same publication point as the 16x1611794 // Same publication point as the 16x16
11893 // straddling leaf above (`record_mi`).11795 // straddling leaf above (`record_mi`).
11894- record_mi(&mut grid, mi_row, mi_col, 2, leaf.inter, leaf.skip,11796+ record_mi(&mut grid, mi_row, mi_col, 2, leaf.inter, leaf.skip);
11895- txfm_px(8, leaf.inter.is_some(), leaf.skip, leaf.tx_depth));
11896 eight.push(leaf);11797 eight.push(leaf);
11897 }11798 }
11898 leaves.push(BlockCoeffs {11799 leaves.push(BlockCoeffs {
@@ -11923,8 +11824,7 @@ pub(crate) fn encode_inter_frame(
11923 // Overwrites every 16x16 mi cell the quadrant searches11824 // Overwrites every 16x16 mi cell the quadrant searches
11924 // published under this superblock, so the next block's stack11825 // published under this superblock, so the next block's stack
11925 // is built off the block that was really coded.11826 // is built off the block that was really coded.
11926- record_mi(&mut grid, sb_r * 16, sb_c * 16, 16, block.inter, block.skip,11827+ record_mi(&mut grid, sb_r * 16, sb_c * 16, 16, block.inter, block.skip);
11927- txfm_px(SUPERBLOCK, block.inter.is_some(), block.skip, block.tx_depth));
11928 blocks.push(((sb_r * 2) * cols + sb_c * 2, Quadrant::Whole64(block)));11828 blocks.push(((sb_r * 2) * cols + sb_c * 2, Quadrant::Whole64(block)));
11929 for q in 1..4 {11829 for q in 1..4 {
11930 let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2);11830 let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2);
@@ -12685,81 +12585,6 @@ mod tests {
12685 }12585 }
12686 }12586 }
12687 12587
12688- /// The `tx_depth` symbol is priced off the row the WRITER codes it
12689- /// against, on BOTH frame types (class `pricer-context-zero`; lane-ctx2
12690- /// built only the key-frame half, which lost on its own).
12691- ///
12692- /// Key frames read the deblock grid (`tile::tx_size_ctx_of`, off
12693- /// `Neighbours::record_tx`'s bands); an inter frame's INTRA block reads
12694- /// the `TXFM_CONTEXT` bands instead (`tile::tx_size_ctx_txfm_of`, where an
12695- /// inter neighbour votes its own BLOCK size and a skipped inter block
12696- /// publishes its block size), which the encoder now publishes per mi cell
12697- /// through `record_mi`. Row 0 -- both neighbours narrower, where splitting
12698- /// reads cheapest -- is what both halves used to price at.
12699- #[test]
12700- fn the_tx_depth_pricer_uses_the_writers_own_context_row() {
12701- use crate::cdf::{TX_SIZE_CAT1, TX_SIZE_CAT2};
12702- use crate::encode::symbol_bits as b;
12703- use crate::tile::{tx_size_ctx_of, tx_size_ctx_txfm_of};
12704- // The key-frame rule: (has_above, has_left), the two band cells, this
12705- // block's own largest transform -> the row. A neighbour outside the
12706- // tile contributes nothing however wide its band cell reads.
12707- for (has, bands, max_tx, want) in [
12708- ((false, false), (64u8, 64u8), 32usize, 0usize),
12709- ((true, true), (16, 16), 32, 0),
12710- ((true, true), (32, 16), 32, 1),
12711- ((true, false), (32, 64), 32, 1),
12712- ((true, true), (32, 64), 32, 2),
12713- ((true, true), (8, 8), 8, 2),
12714- ] {
12715- assert_eq!(tx_size_ctx_of(has, bands, max_tx), want, "key {has:?} {bands:?} {max_tx}");
12716- }
12717- // An inter frame's intra block, its above/left neighbours coded INTER
12718- // and published through `record_mi`: a 16x16 intra block at mi (4, 4)
12719- // with 32x32 inter neighbours, which vote their BLOCK size (32 >= 16)
12720- // whatever transform they left in the band.
12721- let mut grid = MiGrid::new(16, 16);
12722- let inter = Some(crate::tile::InterInfo {
12723- ref1: None,
12724- mv1: (0, 0),
12725- ref_frame: crate::mvstack::LAST_FRAME,
12726- mode: crate::tile::InterMode::NearestMv,
12727- mv: (0, 0),
12728- ref_mv_idx: 0,
12729- });
12730- // A SKIPPED 32x32 inter block publishes its block size (32), an
12731- // unskipped one its resolved transform (32 at depth 0).
12732- assert_eq!(txfm_px(BLOCK, true, true, 0), 32);
12733- assert_eq!(txfm_px(BLOCK, true, false, 1), 16);
12734- for (mi_row, mi_col) in [(0usize, 0usize), (0, 4), (4, 0)] {
12735- record_mi(&mut grid, mi_row, mi_col, 8, inter, true, txfm_px(BLOCK, true, true, 0));
12736- }
12737- let ctx = tx_ctx_txfm(&grid, (4, 4), 16);
12738- assert_eq!(
12739- ctx,
12740- tx_size_ctx_txfm_of(Some((32, true, 32)), Some((32, true, 32)), 16),
12741- "the grid's row is not the writer's"
12742- );
12743- assert_eq!(ctx, 2, "two inter neighbours at least as wide vote row 2");
12744- // libaom's default tables give rows 0 and 1 IDENTICAL probabilities in
12745- // every category, so row 2 is the only row that moves a price -- and
12746- // pricing at it is exactly what was red before this lane.
12747- for (side, table) in [(16usize, &TX_SIZE_CAT1), (32, &TX_SIZE_CAT2)] {
12748- for depth in 0..3 {
12749- let got = tx_depth_bits(ctx, side, depth);
12750- assert!(
12751- (got - b(&table[ctx], depth)).abs() < 1e-9,
12752- "side {side} depth {depth} at ctx {ctx}: priced {got}, writer codes {}",
12753- b(&table[ctx], depth)
12754- );
12755- assert!(
12756- (got - b(&table[0], depth)).abs() > 1e-9,
12757- "side {side} depth {depth}: row {ctx} prices the same as row 0"
12758- );
12759- }
12760- }
12761- }
12762-
12763 /// lane-av1tpl2's propagated map, on the two properties every decision12588 /// lane-av1tpl2's propagated map, on the two properties every decision
12764 /// under it rests on: a frame the whole lookahead window repeats exactly12589 /// under it rests on: a frame the whole lookahead window repeats exactly
12765 /// (uniform texture) leans on every cell alike, so every factor is 1 and12590 /// (uniform texture) leans on every cell alike, so every factor is 1 and
@@ -16445,15 +16270,9 @@ mod tests {
16445 // at q=60. Re-taken on lane-ctx2: a single-reference candidate now16270 // at q=60. Re-taken on lane-ctx2: a single-reference candidate now
16446 // pays the `comp_mode = 0` symbol the writer codes ahead of it, so16271 // pays the `comp_mode = 0` symbol the writer codes ahead of it, so
16447 // single and compound are priced against the same syntax -- 8311 ->16272 // single and compound are priced against the same syntax -- 8311 ->
16448- // 8325 bytes at q=150 and 33087 -> 33014 at q=60. Re-taken again in16273+ // 8325 bytes at q=150 and 33087 -> 33014 at q=60.
16449- // Re-taken on lane-txd: the `tx_depth` symbol is priced at the
16450- // writer's own row on BOTH frame types (a key frame off the deblock
16451- // grid, an inter frame's intra block off the TXFM_CONTEXT bands the
16452- // encoder now publishes), so every intra block's depth-versus-split
16453- // margin moved -- 8325 -> 8381 bytes at q=150 and 33014 -> 33016 at
16454- // q=60.
16455 let pins: [(u8, usize, u64); 2] =16274 let pins: [(u8, usize, u64); 2] =
16456- [(150, 8381, 0x36ac_5783_4a20_499a), (60, 33016, 0xfcd0_be7a_3600_34ce)];16275+ [(150, 8325, 0xf004_8258_bc60_ff05), (60, 33014, 0x5bc2_5dfd_bd13_18de)];
16457 let coded: Vec<(u8, usize, u64)> = pins16276 let coded: Vec<(u8, usize, u64)> = pins
16458 .iter()16277 .iter()
16459 .map(|&(q, _, _)| {16278 .map(|&(q, _, _)| {
crates/ec-av1/src/mvstack.rsmodified+0 -26
@@ -259,14 +259,6 @@ pub struct MiGrid {
259 /// writer and the decoder read their `skip` neighbours from their own259 /// writer and the decoder read their `skip` neighbours from their own
260 /// bands and leave this `false` (lane-ctx).260 /// bands and leave this `false` (lane-ctx).
261 skips: Vec<bool>,261 skips: Vec<bool>,
262- /// The transform side, in pixels, each cell's block published into libaom's
263- /// `TXFM_CONTEXT` bands (`tile::write_tx_syntax_inter`'s `record_txfm`) --
264- /// a skipped inter block's own BLOCK size, everything else's resolved
265- /// transform. Beside `cells` for the same reason `skips` is: the cell must
266- /// stay 16 bytes, and the mv scan never reads this. Only the ENCODER fills
267- /// it (`encode::record_mi`), so the RD pricer can read an inter frame's
268- /// intra block `tx_depth` row off the writer's own bands (lane-txd).
269- txfm: Vec<u8>,
270 /// lane-tiles r6: the current tile's own mi-unit bounds (spec: an MV262 /// lane-tiles r6: the current tile's own mi-unit bounds (spec: an MV
271 /// candidate scan never reaches across a tile boundary, mirroring263 /// candidate scan never reaches across a tile boundary, mirroring
272 /// `PlaneBuf`'s `tile_x0`/`tile_x1` reach clamp for intra prediction).264 /// `PlaneBuf`'s `tile_x0`/`tile_x1` reach clamp for intra prediction).
@@ -296,7 +288,6 @@ impl MiGrid {
296 rows,288 rows,
297 cells: vec![None; cols * rows],289 cells: vec![None; cols * rows],
298 skips: vec![false; cols * rows],290 skips: vec![false; cols * rows],
299- txfm: vec![0; cols * rows],
300 tile_row0: 0,291 tile_row0: 0,
301 tile_col0: 0,292 tile_col0: 0,
302 tile_row1: rows,293 tile_row1: rows,
@@ -352,23 +343,6 @@ impl MiGrid {
352 }343 }
353 }344 }
354 345
355- /// Records the transform side one block published at `(row, col)` -- see
356- /// `txfm`.
357- pub fn set_txfm(&mut self, row: usize, col: usize, tx_px: u8) {
358- if row < self.rows && col < self.cols {
359- self.txfm[row * self.cols + col] = tx_px;
360- }
361- }
362-
363- /// The transform side published at `(row, col)`, `0` outside the grid.
364- pub fn txfm_at(&self, row: usize, col: usize) -> u8 {
365- if row < self.rows && col < self.cols {
366- self.txfm[row * self.cols + col]
367- } else {
368- 0
369- }
370- }
371-
372 /// The `skip` flag of the unit at `(row, col)`, `false` outside this346 /// The `skip` flag of the unit at `(row, col)`, `false` outside this
373 /// tile's own window (the same clamp [`Self::get`] applies).347 /// tile's own window (the same clamp [`Self::get`] applies).
374 pub fn skip_at(&self, row: usize, col: usize) -> bool {348 pub fn skip_at(&self, row: usize, col: usize) -> bool {
crates/ec-av1/src/tile.rsmodified+12 -52
@@ -2410,13 +2410,16 @@ impl Neighbours {
2410 /// off a CDF row one higher than the decoder's, which is the first2410 /// off a CDF row one higher than the decoder's, which is the first
2411 /// divergence of the inter `TxMode::Select` stream.2411 /// divergence of the inter `TxMode::Select` stream.
2412 fn tx_size_ctx_txfm(&self, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize {2412 fn tx_size_ctx_txfm(&self, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize {
2413- tx_size_ctx_txfm_of(2413+ let (has_above, has_left) = (self.has_above(mi_r), self.has_left(mi_c));
2414- self.has_above(mi_r)2414+ let mut above = usize::from(self.above_txfm[mi_c]) >= own_side;
2415- .then(|| (self.above_txfm[mi_c], self.above_inter[mi_c], self.above_side_mi[mi_c])),2415+ let mut left = usize::from(self.left_txfm[mi_r]) >= own_side;
2416- self.has_left(mi_c)2416+ if has_above && self.above_inter[mi_c] {
2417- .then(|| (self.left_txfm[mi_r], self.left_inter[mi_r], self.left_side_mi[mi_r])),2417+ above = self.above_side_mi[mi_c] >= own_side;
2418- own_side,2418+ }
2419- )2419+ if has_left && self.left_inter[mi_r] {
2420+ left = self.left_side_mi[mi_r] >= own_side;
2421+ }
2422+ usize::from(has_above && above) + usize::from(has_left && left)
2420 }2423 }
2421 2424
2422 /// `get_tx_size_context` (decode.rs [`crate::decode::tx_size_context`]):2425 /// `get_tx_size_context` (decode.rs [`crate::decode::tx_size_context`]):
@@ -2424,11 +2427,8 @@ impl Neighbours {
2424 /// largest transform, plus whether the one to the left is at least as2427 /// largest transform, plus whether the one to the left is at least as
2425 /// tall. A neighbour outside the tile contributes nothing.2428 /// tall. A neighbour outside the tile contributes nothing.
2426 fn tx_size_ctx(&self, (mi_r, mi_c): (usize, usize), max_tx: usize) -> usize {2429 fn tx_size_ctx(&self, (mi_r, mi_c): (usize, usize), max_tx: usize) -> usize {
2427- tx_size_ctx_of(2430+ usize::from(self.has_above(mi_r) && usize::from(self.above_tx[mi_c]) >= max_tx)
2428- (self.has_above(mi_r), self.has_left(mi_c)),2431+ + usize::from(self.has_left(mi_c) && usize::from(self.left_tx[mi_r]) >= max_tx)
2429- (self.above_tx[mi_c], self.left_tx[mi_r]),
2430- max_tx,
2431- )
2432 }2432 }
2433 2433
2434 /// Publishes one block's resolved transform side over every 4x4 unit it2434 /// Publishes one block's resolved transform side over every 4x4 unit it
@@ -4309,46 +4309,6 @@ fn write_luma_tus(
4309 Ok(())4309 Ok(())
4310 }4310 }
4311 4311
4312-/// `get_tx_size_context` (decode.rs [`crate::decode::tx_size_context`]) over
4313-/// the two band cells themselves: whether the transform above is at least as
4314-/// wide as this block's own largest transform, plus whether the one to the
4315-/// left is at least as tall; a neighbour outside the tile contributes nothing.
4316-///
4317-/// Free-standing so the RD pricer can read the row the writer really codes a
4318-/// `tx_depth` symbol against off its own published band, without two
4319-/// transcriptions of the same rule (lane-ctx2).
4320-pub(crate) fn tx_size_ctx_of(
4321- (has_above, has_left): (bool, bool),
4322- (above_tx, left_tx): (u8, u8),
4323- max_tx: usize,
4324-) -> usize {
4325- usize::from(has_above && usize::from(above_tx) >= max_tx)
4326- + usize::from(has_left && usize::from(left_tx) >= max_tx)
4327-}
4328-
4329-/// [`Neighbours::tx_size_ctx_txfm`] over the neighbours' own published state:
4330-/// each of `above`/`left` is `None` outside the tile (which contributes
4331-/// nothing), else its `TXFM_CONTEXT` band cell, whether it was coded inter,
4332-/// and its BLOCK side in pixels -- an INTER neighbour votes that block side
4333-/// rather than its transform.
4334-///
4335-/// Free-standing so the RD pricer reads the row an inter frame's intra block
4336-/// is really coded against off its own published bands, with no second
4337-/// transcription of the rule (lane-txd).
4338-pub(crate) fn tx_size_ctx_txfm_of(
4339- above: Option<(u8, bool, usize)>,
4340- left: Option<(u8, bool, usize)>,
4341- own_side: usize,
4342-) -> usize {
4343- let vote = |n: Option<(u8, bool, usize)>| match n {
4344- Some((txfm, is_inter, block_side)) => {
4345- if is_inter { block_side >= own_side } else { usize::from(txfm) >= own_side }
4346- }
4347- None => false,
4348- };
4349- usize::from(vote(above)) + usize::from(vote(left))
4350-}
4351-
4352 /// Writes one intra block's luma residual under `TxMode::Select`: the4312 /// Writes one intra block's luma residual under `TxMode::Select`: the
4353 /// `tx_depth` symbol (spec 5.11.16 `read_selected_tx_size`, off the size4313 /// `tx_depth` symbol (spec 5.11.16 `read_selected_tx_size`, off the size
4354 /// category's own CDF at [`Neighbours::tx_size_ctx`]'s row), then the4314 /// category's own CDF at [`Neighbours::tx_size_ctx`]'s row), then the