forge
Explore
Log in

Don't you dare go Hollow

Revert the tx_depth context fix: correct pricing measures worse

Browse files at this commit

1d2760b546ad69d444ac9350612f1c8be4c16744Ahmet Kaan GümüşParent: 9419b29
REFUTED on the 12-frame native gate against a control reproduced in this
worktree at 3c106765. Arm = both halves (key frame off the deblock grid,
inter frame's intra block off the TXFM_CONTEXT bands the encoder now
published per mi cell):

| row    | control      | arm          |
|--------|--------------|--------------|
| film A | +21.0 / -4.8 | +20.9 / -4.8 |
| film B | +24.9 / -1.9 | +25.2 / -1.6 |
| screen | +14.5 / -33.2| +14.5 / -33.2|
| bars 1080p | -2.0 / -17.6 | -2.0 / -17.6 |
| bars 2160p | +8.7 / -13.4 | +8.7 / -13.4 |

Film B moves the wrong way on BOTH columns by 0.3 while film A gains 0.1
on one, so no keep rule is met (not both-improve, not 0.5-down-and-flat,
not flat-within-0.2).

Census of the row the writer really codes each `tx_depth` symbol at, over
the pin encode's key + inter pictures:

  key frames        ctx0 767  ctx1 457  ctx2 156   (ctx2 11.3%)
  inter-frame intra ctx0 227  ctx1 731  ctx2 1902  (ctx2 66.5%)

libaom's default rows 0 and 1 are identical, so only ctx2 moves a price,
and the direction is one-sided: at ctx2 depth 0 costs 0.28 (8x8), 0.61
(16x16), 0.90 (32x32) and 1.54 (64x64) bits LESS than at row 0, while
depth 1 costs 0.56-0.76 bits MORE. Correct pricing therefore discourages
transform splitting, and it does so on two thirds of an inter frame's
intra blocks against one ninth of a key frame's -- which is exactly the
row that loses. The gate says the search's residual/lambda calibration
was leaning on the row-0 handicap; the symbol price itself is not what is
mispriced here.

Nothing else consumed the published bands, so the bands, the shared
tile::tx_size_ctx_txfm_of, the MiGrid cell band and the re-taken pins go
with it (the tree is byte-identical to 3c106765 again). Class
pricer-context-zero has no site left that pays.
crates/ec-av1/src/encode.rsmodified+26 -211
@@ -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
@@ -5226,12 +5222,7 @@ fn code_square(
5226 tx_select: bool,5222 tx_select: bool,
5227 // This tile's intra block-copy state ([`Ibc`]), `None` on a frame whose5223 // This tile's intra block-copy state ([`Ibc`]), `None` on a frame whose
5228 // header did not set `allow_intrabc`.5224 // header did not set `allow_intrabc`.
5229- ibc: Option<&mut Ibc>,5225+ ibc: Option<&mut Ibc>, fctx: &crate::decode::FrameCtx,
5230- // The CDF row this block's `tx_depth` symbol is priced against
5231- // ([`tx_depth_bits`]), read by the caller off its own published transform
5232- // bands -- `0` where the caller keeps none.
5233- tx_ctx: usize,
5234- fctx: &crate::decode::FrameCtx,
5235 ) -> (BlockCoeffs, f64) {5226 ) -> (BlockCoeffs, f64) {
5236 let (luma_set, chroma_set) = if side == SUPERBLOCK {5227 let (luma_set, chroma_set) = if side == SUPERBLOCK {
5237 // A whole superblock coded as ONE intra block (lane-i64): one5228 // A whole superblock coded as ONE intra block (lane-i64): one
@@ -5275,11 +5266,11 @@ fn code_square(
5275 // `tx_depth_bits(32, 0)` -- otherwise the 64-versus-four-32 comparison5266 // `tx_depth_bits(32, 0)` -- otherwise the 64-versus-four-32 comparison
5276 // below hands the root a symbol for free.5267 // below hands the root a symbol for free.
5277 if tx_select && side == SUPERBLOCK {5268 if tx_select && side == SUPERBLOCK {
5278- cost += search.lambda * tx_depth_bits(tx_ctx, side, 0);5269+ cost += search.lambda * tx_depth_bits(side, 0);
5279 }5270 }
5280 if tx_select && max_tx_depth(side) > 0 {5271 if tx_select && max_tx_depth(side) > 0 {
5281 let mut best = (5272 let mut best = (
5282- cost + search.lambda * tx_depth_bits(tx_ctx, side, 0),5273+ cost + search.lambda * tx_depth_bits(side, 0),
5283 0usize,5274 0usize,
5284 luma.snapshot(x, y, side),5275 luma.snapshot(x, y, side),
5285 luma_coeffs,5276 luma_coeffs,
@@ -5290,7 +5281,7 @@ fn code_square(
5290 luma.code_tx_depth(at, mode, angle_delta, depth, None, search, fctx);5281 luma.code_tx_depth(at, mode, angle_delta, depth, None, search, fctx);
5291 let cost_d = sse5282 let cost_d = sse
5292 + search.lambda5283 + search.lambda
5293- * (bits + mode_bits[usize::from(mode)] + tx_depth_bits(tx_ctx, side, depth));5284+ * (bits + mode_bits[usize::from(mode)] + tx_depth_bits(side, depth));
5294 if cost_d < best.0 {5285 if cost_d < best.0 {
5295 best = (cost_d, depth, luma.snapshot(x, y, side), coeffs(&levels, side));5286 best = (cost_d, depth, luma.snapshot(x, y, side), coeffs(&levels, side));
5296 best_types = types;5287 best_types = types;
@@ -5338,7 +5329,7 @@ fn code_square(
5338 * (trial.bits5329 * (trial.bits
5339 + mode_bits[DC_PRED as usize]5330 + mode_bits[DC_PRED as usize]
5340 + crate::tile::palette_bits(&pal, side)5331 + crate::tile::palette_bits(&pal, side)
5341- + if tx_select { tx_depth_bits(tx_ctx, side, 0) } else { 0.0 });5332+ + if tx_select { tx_depth_bits(side, 0) } else { 0.0 });
5342 if cost_p < cost {5333 if cost_p < cost {
5343 cost = cost_p;5334 cost = cost_p;
5344 mode = DC_PRED as u8;5335 mode = DC_PRED as u8;
@@ -5404,7 +5395,7 @@ fn code_square(
5404 + mode_bits[DC_PRED as usize]5395 + mode_bits[DC_PRED as usize]
5405 + one_bits5396 + one_bits
5406 + symbol_bits(&cdf::FILTER_INTRA_MODE, usize::from(fi))5397 + symbol_bits(&cdf::FILTER_INTRA_MODE, usize::from(fi))
5407- + if tx_select { tx_depth_bits(tx_ctx, side, depth) } else { 0.0 });5398+ + if tx_select { tx_depth_bits(side, depth) } else { 0.0 });
5408 if cost_f < cost && best.as_ref().is_none_or(|b| cost_f < b.0) {5399 if cost_f < cost && best.as_ref().is_none_or(|b| cost_f < b.0) {
5409 best = Some((5400 best = Some((
5410 cost_f,5401 cost_f,
@@ -6126,11 +6117,6 @@ fn code_square_inter(
6126 mode_bits,6117 mode_bits,
6127 tx_select() && tx_select_inter(),6118 tx_select() && tx_select_inter(),
6128 None,6119 None,
6129- // lane-txd: an INTER frame's intra block takes its `tx_depth` row
6130- // from the `TXFM_CONTEXT` bands (`tx_size_ctx_txfm`, where an
6131- // inter neighbour votes its own BLOCK size), which `record_mi`
6132- // now publishes per cell.
6133- tx_ctx_txfm(grid, (mi_row, mi_col), side.min(64)),
6134 fctx,6120 fctx,
6135 );6121 );
6136 let luma_set = if side == 8 {6122 let luma_set = if side == 8 {
@@ -6834,31 +6820,6 @@ fn code_square_inter(
6834 /// MV stack reads, over the `size` x `size` 4x4 units it covers. An intra6820 /// MV stack reads, over the `size` x `size` 4x4 units it covers. An intra
6835 /// block casts no vote but is still a coded cell (see `code_square_inter`'s6821 /// block casts no vote but is still a coded cell (see `code_square_inter`'s
6836 /// note on `processed_rows`/`processed_cols`).6822 /// note on `processed_rows`/`processed_cols`).
6837-/// What one coded block publishes into the `TXFM_CONTEXT` bands, in pixels:
6838-/// a SKIPPED inter block records its own BLOCK size (`set_txfm_ctxs`'s
6839-/// `skip_inter` term), every other block its resolved transform
6840-/// (`tile::write_tx_syntax_inter`'s `record_txfm` calls, all of which cover
6841-/// the block's whole span with one value).
6842-fn txfm_px(side: usize, inter: bool, skip: bool, tx_depth: u8) -> u8 {
6843- if inter && skip { side as u8 } else { (side.min(64) >> tx_depth) as u8 }
6844-}
6845-
6846-/// The CDF row an INTER frame's intra block has its `tx_depth` symbol coded
6847-/// against ([`crate::tile::Neighbours::tx_size_ctx_txfm`]), read off the grid
6848-/// the encoder publishes its own blocks into -- the above/left 4x4 cell, each
6849-/// contributing nothing when it falls outside this tile (`MiGrid::get`'s own
6850-/// window, which is the writer's `has_above`/`has_left`).
6851-fn tx_ctx_txfm(grid: &MiGrid, (mi_row, mi_col): (usize, usize), own_side: usize) -> usize {
6852- let cell = |r: usize, c: usize| {
6853- grid.get(r, c).map(|i| (grid.txfm_at(r, c), i.is_inter, usize::from(i.size) * 4))
6854- };
6855- crate::tile::tx_size_ctx_txfm_of(
6856- mi_row.checked_sub(1).and_then(|r| cell(r, mi_col)),
6857- mi_col.checked_sub(1).and_then(|c| cell(mi_row, c)),
6858- own_side,
6859- )
6860-}
6861-
6862 fn record_mi(6823 fn record_mi(
6863 grid: &mut MiGrid,6824 grid: &mut MiGrid,
6864 mi_row: usize,6825 mi_row: usize,
@@ -6868,10 +6829,6 @@ fn record_mi(
6868 // lane-ctx: the block's own `skip`, so the next block's MV stack can hand6829 // lane-ctx: the block's own `skip`, so the next block's MV stack can hand
6869 // the RD pricer the two cells the writer's `skip_ctx` sums.6830 // the RD pricer the two cells the writer's `skip_ctx` sums.
6870 skip: bool,6831 skip: bool,
6871- // lane-txd: the transform side, in pixels, this block leaves in the
6872- // `TXFM_CONTEXT` bands ([`txfm_px`]), which is the state the next intra
6873- // block's `tx_depth` row is read from.
6874- txfm: u8,
6875 ) {6832 ) {
6876 let info = match inter {6833 let info = match inter {
6877 Some(info) => MiInfo {6834 Some(info) => MiInfo {
@@ -6917,7 +6874,6 @@ fn record_mi(
6917 for dc in 0..usize::from(size) {6874 for dc in 0..usize::from(size) {
6918 grid.set(mi_row + dr, mi_col + dc, info);6875 grid.set(mi_row + dr, mi_col + dc, info);
6919 grid.set_skip(mi_row + dr, mi_col + dc, skip);6876 grid.set_skip(mi_row + dr, mi_col + dc, skip);
6920- grid.set_txfm(mi_row + dr, mi_col + dc, txfm);
6921 }6877 }
6922 }6878 }
6923 }6879 }
@@ -7716,38 +7672,6 @@ pub(crate) fn encode_key_frame_inner(
7716 clip_planes_to_tile(&mut luma, &mut chroma, rect);7672 clip_planes_to_tile(&mut luma, &mut chroma, rect);
7717 let mut above_mode = vec![DC_PRED; cols * 2];7673 let mut above_mode = vec![DC_PRED; cols * 2];
7718 let mut left_mode = vec![DC_PRED; rows * 2];7674 let mut left_mode = vec![DC_PRED; rows * 2];
7719- // lane-ctx2: the two bands `Neighbours::tx_size_ctx` reads -- every
7720- // coded block's resolved luma transform side in pixels, over each 4x4
7721- // unit it covers, the way the writer's `record_tx` publishes it. The
7722- // indices are frame-absolute, so a new superblock row needs no reset
7723- // (the writer's `start_row` clears a band indexed within the tile),
7724- // and a block trial that loses is overwritten by the winner's own
7725- // publish, exactly as `above_mode`/`left_mode` are.
7726- let mut above_tx = vec![0u8; cols * 8];
7727- let mut left_tx = vec![0u8; rows * 8];
7728- let tx_ctx = |above_tx: &[u8], left_tx: &[u8], (x, y): (usize, usize), side: usize| {
7729- let (mi_r, mi_c) = (y / 4, x / 4);
7730- crate::tile::tx_size_ctx_of(
7731- (mi_r > rect.mi_row0 as usize, mi_c > rect.mi_col0 as usize),
7732- (above_tx[mi_c], left_tx[mi_r]),
7733- side.min(64),
7734- )
7735- };
7736- let publish_tx = |above_tx: &mut Vec<u8>,
7737- left_tx: &mut Vec<u8>,
7738- (x, y): (usize, usize),
7739- side: usize,
7740- depth: u8| {
7741- let tx = (side.min(64) >> depth) as u8;
7742- for cell in 0..side / 4 {
7743- if let Some(c) = above_tx.get_mut(x / 4 + cell) {
7744- *c = tx;
7745- }
7746- if let Some(c) = left_tx.get_mut(y / 4 + cell) {
7747- *c = tx;
7748- }
7749- }
7750- };
7751 let mut ibc = allow_intrabc.then(|| {7675 let mut ibc = allow_intrabc.then(|| {
7752 Ibc::new(7676 Ibc::new(
7753 (7677 (
@@ -7827,7 +7751,6 @@ pub(crate) fn encode_key_frame_inner(
7827 &mode_bits(above_mode[c64], left_mode[r64]),7751 &mode_bits(above_mode[c64], left_mode[r64]),
7828 tx_select,7752 tx_select,
7829 None,7753 None,
7830- tx_ctx(&above_tx, &left_tx, (x64, y64), SUPERBLOCK),
7831 fctx,7754 fctx,
7832 );7755 );
7833 let cost = cost + search.lambda * crate::tile::partition_bits(SUPERBLOCK, false);7756 let cost = cost + search.lambda * crate::tile::partition_bits(SUPERBLOCK, false);
@@ -7911,9 +7834,7 @@ pub(crate) fn encode_key_frame_inner(
7911 &search,7834 &search,
7912 &mode_bits(above_mode[c0], left_mode[r0]),7835 &mode_bits(above_mode[c0], left_mode[r0]),
7913 tx_select,7836 tx_select,
7914- ibc.as_mut(),7837+ ibc.as_mut(), fctx,
7915- tx_ctx(&above_tx, &left_tx, (x, y), BLOCK),
7916- fctx,
7917 );7838 );
7918 cost_whole += search.lambda * partition_bits(BLOCK, false);7839 cost_whole += search.lambda * partition_bits(BLOCK, false);
7919 let after_whole = snapshot(&luma, &chroma, (x, y), BLOCK);7840 let after_whole = snapshot(&luma, &chroma, (x, y), BLOCK);
@@ -7948,26 +7869,12 @@ pub(crate) fn encode_key_frame_inner(
7948 &search,7869 &search,
7949 &mode_bits(above_mode[sc], left_mode[sr]),7870 &mode_bits(above_mode[sc], left_mode[sr]),
7950 tx_select,7871 tx_select,
7951- ibc.as_mut(),7872+ ibc.as_mut(), fctx,
7952- tx_ctx(
7953- &above_tx,
7954- &left_tx,
7955- (x + (sub % 2) * SUB, y + (sub / 2) * SUB),
7956- SUB,
7957- ),
7958- fctx,
7959 );7873 );
7960 cost_split += cost;7874 cost_split += cost;
7961 split_modes.push(block.mode);7875 split_modes.push(block.mode);
7962 above_mode[sc] = block.mode;7876 above_mode[sc] = block.mode;
7963 left_mode[sr] = block.mode;7877 left_mode[sr] = block.mode;
7964- publish_tx(
7965- &mut above_tx,
7966- &mut left_tx,
7967- (x + (sub % 2) * SUB, y + (sub / 2) * SUB),
7968- SUB,
7969- block.tx_depth,
7970- );
7971 split.push(block);7878 split.push(block);
7972 } else {7879 } else {
7973 // A straddling 16x16: two (or, at a true corner, one)7880 // A straddling 16x16: two (or, at a true corner, one)
@@ -7995,13 +7902,10 @@ pub(crate) fn encode_key_frame_inner(
7995 &search,7902 &search,
7996 &leaf_mode_bits,7903 &leaf_mode_bits,
7997 tx_select,7904 tx_select,
7998- None,7905+ None, fctx,
7999- tx_ctx(&above_tx, &left_tx, (leaf_x, leaf_y), 8),
8000- fctx,
8001 );7906 );
8002 cost_split += cost;7907 cost_split += cost;
8003 split_modes.push(leaf.mode);7908 split_modes.push(leaf.mode);
8004- publish_tx(&mut above_tx, &mut left_tx, (leaf_x, leaf_y), 8, leaf.tx_depth);
8005 leaves.push(leaf);7909 leaves.push(leaf);
8006 }7910 }
8007 split.push(BlockCoeffs {7911 split.push(BlockCoeffs {
@@ -8030,7 +7934,6 @@ pub(crate) fn encode_key_frame_inner(
8030 above_mode[c0 + cell] = whole.mode;7934 above_mode[c0 + cell] = whole.mode;
8031 left_mode[r0 + cell] = whole.mode;7935 left_mode[r0 + cell] = whole.mode;
8032 }7936 }
8033- publish_tx(&mut above_tx, &mut left_tx, (x, y), BLOCK, whole.tx_depth);
8034 modes.push(whole.mode);7937 modes.push(whole.mode);
8035 blocks.push(Quadrant::Whole(whole));7938 blocks.push(Quadrant::Whole(whole));
8036 }7939 }
@@ -8043,7 +7946,6 @@ pub(crate) fn encode_key_frame_inner(
8043 above_mode[sb_col * 4 + cell] = block.mode;7946 above_mode[sb_col * 4 + cell] = block.mode;
8044 left_mode[sb_row * 4 + cell] = block.mode;7947 left_mode[sb_row * 4 + cell] = block.mode;
8045 }7948 }
8046- publish_tx(&mut above_tx, &mut left_tx, (x64, y64), SUPERBLOCK, block.tx_depth);
8047 I64_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);7949 I64_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
8048 if !whole_inside {7950 if !whole_inside {
8049 I64_HITS[2].fetch_add(1, std::sync::atomic::Ordering::Relaxed);7951 I64_HITS[2].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
@@ -11593,8 +11495,7 @@ pub(crate) fn encode_inter_frame(
11593 fctx,11495 fctx,
11594 );11496 );
11595 cost8 += cost;11497 cost8 += cost;
11596- record_mi(&mut grid, mr, mc, 2, leaf8.inter, leaf8.skip,11498+ record_mi(&mut grid, mr, mc, 2, leaf8.inter, leaf8.skip);
11597- txfm_px(8, leaf8.inter.is_some(), leaf8.skip, leaf8.tx_depth));
11598 eight.push(leaf8);11499 eight.push(leaf8);
11599 }11500 }
11600 (eight, cost8)11501 (eight, cost8)
@@ -11616,8 +11517,7 @@ pub(crate) fn encode_inter_frame(
11616 }11517 }
11617 partition_hit(2);11518 partition_hit(2);
11618 cost += leaf_cost;11519 cost += leaf_cost;
11619- record_mi(&mut grid, mi_row, mi_col, 4, leaf.inter, leaf.skip,11520+ record_mi(&mut grid, mi_row, mi_col, 4, leaf.inter, leaf.skip);
11620- txfm_px(SUB, leaf.inter.is_some(), leaf.skip, leaf.tx_depth));
11621 leaves.push(leaf);11521 leaves.push(leaf);
11622 }11522 }
11623 (leaves, cost)11523 (leaves, cost)
@@ -11636,8 +11536,7 @@ pub(crate) fn encode_inter_frame(
11636 }11536 }
11637 partition_hit(0);11537 partition_hit(0);
11638 sb_cost += cost_whole;11538 sb_cost += cost_whole;
11639- record_mi(&mut grid, mi_row, mi_col, 8, block.inter, block.skip,11539+ record_mi(&mut grid, mi_row, mi_col, 8, block.inter, block.skip);
11640- txfm_px(BLOCK, block.inter.is_some(), block.skip, block.tx_depth));
11641 blocks.push((r32 * cols + c32, Quadrant::Whole(block)));11540 blocks.push((r32 * cols + c32, Quadrant::Whole(block)));
11642 } else {11541 } else {
11643 // The sub-positions actually inside the true frame, same11542 // The sub-positions actually inside the true frame, same
@@ -11704,8 +11603,7 @@ pub(crate) fn encode_inter_frame(
11704 // to (0,0), which is the encoder-grid-drift class11603 // to (0,0), which is the encoder-grid-drift class
11705 // -- correct only for as long as a leaf can never11604 // -- correct only for as long as a leaf can never
11706 // be compound.11605 // be compound.
11707- record_mi(&mut grid, mi_row, mi_col, 4, block.inter, block.skip,11606+ record_mi(&mut grid, mi_row, mi_col, 4, block.inter, block.skip);
11708- txfm_px(SUB, block.inter.is_some(), block.skip, block.tx_depth));
11709 leaves.push(block);11607 leaves.push(block);
11710 } else {11608 } else {
11711 let (x_sub, y_sub) = (sc * SUB, sr * SUB);11609 let (x_sub, y_sub) = (sc * SUB, sr * SUB);
@@ -11744,8 +11642,7 @@ pub(crate) fn encode_inter_frame(
11744 );11642 );
11745 // Same publication point as the 16x1611643 // Same publication point as the 16x16
11746 // straddling leaf above (`record_mi`).11644 // straddling leaf above (`record_mi`).
11747- record_mi(&mut grid, mi_row, mi_col, 2, leaf.inter, leaf.skip,11645+ record_mi(&mut grid, mi_row, mi_col, 2, leaf.inter, leaf.skip);
11748- txfm_px(8, leaf.inter.is_some(), leaf.skip, leaf.tx_depth));
11749 eight.push(leaf);11646 eight.push(leaf);
11750 }11647 }
11751 leaves.push(BlockCoeffs {11648 leaves.push(BlockCoeffs {
@@ -11776,8 +11673,7 @@ pub(crate) fn encode_inter_frame(
11776 // Overwrites every 16x16 mi cell the quadrant searches11673 // Overwrites every 16x16 mi cell the quadrant searches
11777 // published under this superblock, so the next block's stack11674 // published under this superblock, so the next block's stack
11778 // is built off the block that was really coded.11675 // is built off the block that was really coded.
11779- record_mi(&mut grid, sb_r * 16, sb_c * 16, 16, block.inter, block.skip,11676+ record_mi(&mut grid, sb_r * 16, sb_c * 16, 16, block.inter, block.skip);
11780- txfm_px(SUPERBLOCK, block.inter.is_some(), block.skip, block.tx_depth));
11781 blocks.push(((sb_r * 2) * cols + sb_c * 2, Quadrant::Whole64(block)));11677 blocks.push(((sb_r * 2) * cols + sb_c * 2, Quadrant::Whole64(block)));
11782 for q in 1..4 {11678 for q in 1..4 {
11783 let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2);11679 let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2);
@@ -12538,81 +12434,6 @@ mod tests {
12538 }12434 }
12539 }12435 }
12540 12436
12541- /// The `tx_depth` symbol is priced off the row the WRITER codes it
12542- /// against, on BOTH frame types (class `pricer-context-zero`; lane-ctx2
12543- /// built only the key-frame half, which lost on its own).
12544- ///
12545- /// Key frames read the deblock grid (`tile::tx_size_ctx_of`, off
12546- /// `Neighbours::record_tx`'s bands); an inter frame's INTRA block reads
12547- /// the `TXFM_CONTEXT` bands instead (`tile::tx_size_ctx_txfm_of`, where an
12548- /// inter neighbour votes its own BLOCK size and a skipped inter block
12549- /// publishes its block size), which the encoder now publishes per mi cell
12550- /// through `record_mi`. Row 0 -- both neighbours narrower, where splitting
12551- /// reads cheapest -- is what both halves used to price at.
12552- #[test]
12553- fn the_tx_depth_pricer_uses_the_writers_own_context_row() {
12554- use crate::cdf::{TX_SIZE_CAT1, TX_SIZE_CAT2};
12555- use crate::encode::symbol_bits as b;
12556- use crate::tile::{tx_size_ctx_of, tx_size_ctx_txfm_of};
12557- // The key-frame rule: (has_above, has_left), the two band cells, this
12558- // block's own largest transform -> the row. A neighbour outside the
12559- // tile contributes nothing however wide its band cell reads.
12560- for (has, bands, max_tx, want) in [
12561- ((false, false), (64u8, 64u8), 32usize, 0usize),
12562- ((true, true), (16, 16), 32, 0),
12563- ((true, true), (32, 16), 32, 1),
12564- ((true, false), (32, 64), 32, 1),
12565- ((true, true), (32, 64), 32, 2),
12566- ((true, true), (8, 8), 8, 2),
12567- ] {
12568- assert_eq!(tx_size_ctx_of(has, bands, max_tx), want, "key {has:?} {bands:?} {max_tx}");
12569- }
12570- // An inter frame's intra block, its above/left neighbours coded INTER
12571- // and published through `record_mi`: a 16x16 intra block at mi (4, 4)
12572- // with 32x32 inter neighbours, which vote their BLOCK size (32 >= 16)
12573- // whatever transform they left in the band.
12574- let mut grid = MiGrid::new(16, 16);
12575- let inter = Some(crate::tile::InterInfo {
12576- ref1: None,
12577- mv1: (0, 0),
12578- ref_frame: crate::mvstack::LAST_FRAME,
12579- mode: crate::tile::InterMode::NearestMv,
12580- mv: (0, 0),
12581- ref_mv_idx: 0,
12582- });
12583- // A SKIPPED 32x32 inter block publishes its block size (32), an
12584- // unskipped one its resolved transform (32 at depth 0).
12585- assert_eq!(txfm_px(BLOCK, true, true, 0), 32);
12586- assert_eq!(txfm_px(BLOCK, true, false, 1), 16);
12587- for (mi_row, mi_col) in [(0usize, 0usize), (0, 4), (4, 0)] {
12588- record_mi(&mut grid, mi_row, mi_col, 8, inter, true, txfm_px(BLOCK, true, true, 0));
12589- }
12590- let ctx = tx_ctx_txfm(&grid, (4, 4), 16);
12591- assert_eq!(
12592- ctx,
12593- tx_size_ctx_txfm_of(Some((32, true, 32)), Some((32, true, 32)), 16),
12594- "the grid's row is not the writer's"
12595- );
12596- assert_eq!(ctx, 2, "two inter neighbours at least as wide vote row 2");
12597- // libaom's default tables give rows 0 and 1 IDENTICAL probabilities in
12598- // every category, so row 2 is the only row that moves a price -- and
12599- // pricing at it is exactly what was red before this lane.
12600- for (side, table) in [(16usize, &TX_SIZE_CAT1), (32, &TX_SIZE_CAT2)] {
12601- for depth in 0..3 {
12602- let got = tx_depth_bits(ctx, side, depth);
12603- assert!(
12604- (got - b(&table[ctx], depth)).abs() < 1e-9,
12605- "side {side} depth {depth} at ctx {ctx}: priced {got}, writer codes {}",
12606- b(&table[ctx], depth)
12607- );
12608- assert!(
12609- (got - b(&table[0], depth)).abs() > 1e-9,
12610- "side {side} depth {depth}: row {ctx} prices the same as row 0"
12611- );
12612- }
12613- }
12614- }
12615-
12616 /// lane-av1tpl2's propagated map, on the two properties every decision12437 /// lane-av1tpl2's propagated map, on the two properties every decision
12617 /// under it rests on: a frame the whole lookahead window repeats exactly12438 /// under it rests on: a frame the whole lookahead window repeats exactly
12618 /// (uniform texture) leans on every cell alike, so every factor is 1 and12439 /// (uniform texture) leans on every cell alike, so every factor is 1 and
@@ -16299,14 +16120,8 @@ mod tests {
16299 // pays the `comp_mode = 0` symbol the writer codes ahead of it, so16120 // pays the `comp_mode = 0` symbol the writer codes ahead of it, so
16300 // single and compound are priced against the same syntax -- 8311 ->16121 // single and compound are priced against the same syntax -- 8311 ->
16301 // 8325 bytes at q=150 and 33087 -> 33014 at q=60.16122 // 8325 bytes at q=150 and 33087 -> 33014 at q=60.
16302- // Re-taken on lane-txd: the `tx_depth` symbol is priced at the
16303- // writer's own row on BOTH frame types (a key frame off the deblock
16304- // grid, an inter frame's intra block off the TXFM_CONTEXT bands the
16305- // encoder now publishes), so every intra block's depth-versus-split
16306- // margin moved -- 8325 -> 8381 bytes at q=150 and 33014 -> 33016 at
16307- // q=60.
16308 let pins: [(u8, usize, u64); 2] =16123 let pins: [(u8, usize, u64); 2] =
16309- [(150, 8381, 0x36ac_5783_4a20_499a), (60, 33016, 0xfcd0_be7a_3600_34ce)];16124+ [(150, 8325, 0xf004_8258_bc60_ff05), (60, 33014, 0x5bc2_5dfd_bd13_18de)];
16310 let coded: Vec<(u8, usize, u64)> = pins16125 let coded: Vec<(u8, usize, u64)> = pins
16311 .iter()16126 .iter()
16312 .map(|&(q, _, _)| {16127 .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