forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

rect4.rs3994 lines, 157.9 KiBHistoryRawDownload
1//! Rect4 and 16-wide block decoders, including the intrabc and strip paths. //! av1split: moved out of `decode/mod.rs`; the items are unchanged apart from visibility. (D18)
2
3use super::*;
4
5/// Decodes one 32x8 / 8x32 strip of a 32x32-level `PARTITION_HORZ_4` /
6/// `PARTITION_VERT_4` (lane-tx64x16 r3): [`decode_block_rect`]'s 4:1 sibling,
7/// addressed by REAL mi coordinates for the same reason [`decode_leaf_rect`]
8/// is -- strips 1 and 3 start 8 px into a 16-px [`SUB`] cell, which an
9/// `at`-derived `px = c * SUB` cannot name. `prev_strip` carries the previous
10/// strip's mode so this one's mode context sees its true above/left
11/// neighbour inside the same 32x32 (`decode_leaf_rect`'s convention).
12///
13/// Tables: LUMA `TX_32X8`/`TX_8X32` averages to the 16x16 entropy context
14/// ([`TxbSet::LumaRect32x8`], 256 positions) and scans with
15/// [`SCAN_32X8`]/[`SCAN_8X32`]; CHROMA `TX_16X4`/`TX_4X16` averages to the
16/// 8x8 one ([`TxbSet::Chroma8`], 64 positions) and scans with
17/// [`SCAN_16X4`]/[`SCAN_4X16`]. Neither shape takes the rect sqrt2 scale --
18/// `get_rect_tx_log_ratio` fires at ratio 1 only, and this is ratio 2
19/// (`inverse_transform_2d_typed_wh`'s own `rect_scale`).
20///
21/// A split transform (`tx_depth != 0`) refuses by name: `depth_to_tx_size` of
22/// a 4:1 strip is not simply `bw.min(bh) >> (depth - 1)` the way a 2:1
23/// strip's is, so [`decode_rect_split`]'s per-unit walk cannot be reused
24/// unexamined.
25#[allow(clippy::too_many_arguments)]
26pub(super) fn decode_block_rect4(
27 dec: &mut SymbolDecoder,
28 cdfs: &mut Cdfs,
29 neighbours: &mut Neighbours,
30 strip_mi: (usize, usize),
31 bw: usize,
32 bh: usize,
33 prev_strip: Option<((usize, usize), usize)>,
34 y: &mut PlaneBuf<'static>,
35 u: &mut PlaneBuf<'static>,
36 v: &mut PlaneBuf<'static>,
37 enable_filter_intra: bool,
38 allow_screen_content_tools: bool,
39 base_q_idx: u8,
40 tx_select: bool,
41 fctx: &crate::decode::FrameCtx,
42) -> Result<(usize, usize)> {
43 let _ = base_q_idx;
44 let (mi_r, mi_c) = strip_mi;
45 let (r, c) = (mi_r / (SUB / MI), mi_c / (SUB / MI));
46 let (mi_w, mi_h) = (bw / MI, bh / MI);
47 let mut above_mode = neighbours.above_mode[c];
48 let mut left_mode = neighbours.left_mode[r];
49 if let Some(((pr, pc), pmode)) = prev_strip {
50 if pc == mi_c && mi_r == pr + mi_h {
51 above_mode = pmode;
52 } else if pr == mi_r && mi_c == pc + mi_w {
53 left_mode = pmode;
54 }
55 }
56 // lane-rectsplitx r2, ROOT CAUSE of the 1:4 mismatch: mi-exact +
57 // availability-correct neighbour modes (see
58 // [`Neighbours::modes_above_left_mi`]). The coarse 16x16 bands alias every
59 // 8-px strip of a `HORZ_4`/`VERT_4` onto one cell.
60 let (above_mode, left_mode) =
61 neighbours.modes_above_left_mi(mi_r, mi_c, (above_mode, left_mode));
62 // lane-kf900 r4: this strip's own palette-Y mode ctx and colour cache.
63 // Passing `None`/`&[]` read `palette_y_mode` off CDF row 0 and every
64 // `palette_colors_y` cache hit off an EMPTY cache -- right symbol count,
65 // wrong interval, so a screen-content tile desynced at the first strip
66 // whose neighbour used a palette (class [[cdf-row-held-constant]]).
67 let pal_at = (mi_r, mi_c);
68 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(pal_at);
69 let palette_uv_cache = neighbours.palette_uv_cache_mi(pal_at);
70 let (
71 skip,
72 mode,
73 angle_delta_y,
74 uv_mode,
75 angle_delta_uv,
76 alpha,
77 filter_intra,
78 palette_y,
79 palette_uv,
80 intrabc,
81 ) = read_intra_mode_rect(
82 dec,
83 cdfs,
84 above_mode,
85 left_mode,
86 true,
87 true,
88 bw,
89 bh,
90 enable_filter_intra,
91 neighbours.skip_txfm_ctx(mi_r, mi_c),
92 allow_screen_content_tools,
93 Some((palette_ctx, &palette_cache)),
94 &palette_uv_cache,
95 mi_r,
96 mi_c,
97 fctx,
98 )?;
99 if let Some((dv_row, dv_col)) = intrabc {
100 decode_intrabc_rect(
101 dec,
102 cdfs,
103 neighbours,
104 strip_mi,
105 (bw, bh),
106 skip,
107 (dv_row, dv_col),
108 y,
109 u,
110 v,
111 base_q_idx,
112 fctx,
113 )?;
114 return Ok((DC_PRED, DC_PRED));
115 }
116 // lane-kf900 r4: palette prediction on this shape, exactly as
117 // [`decode_block_rect`] does one aspect ratio up -- the colour-index map
118 // mapped through the base colours IS the prediction (it reads no edge
119 // pixels), handed to each `reconstruct_rect` through [`set_palette_pred`].
120 if palette_y.is_some() || palette_uv.is_some() {
121 hit!(RECT4_PALETTE_HITS);
122 }
123 let palette_y_buf: Option<Vec<u16>> = palette_y
124 .as_ref()
125 .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
126 let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
127 (
128 p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
129 p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
130 )
131 });
132 let (pal_y_size, pal_y_colors) = palette_y
133 .as_ref()
134 .map_or((0, [0u16; 8]), |p| (p.size, p.colors));
135 let (pal_uv_size, pal_uv_colors) = palette_uv
136 .as_ref()
137 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
138 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
139 if smooth_neighbor {
140 hit!(SMOOTH_LUMA_HITS);
141 }
142 // lane-rectsplitx r2: this strip's REAL mi, not the [`SUB`] cell's
143 // top-left -- a 1:4 strip starts 8 px into a 16-px cell, so
144 // `r * (SUB / MI)` names a different mi column and the chroma
145 // edge-filter strength was read from the wrong neighbour (measured:
146 // seed 43, the last 8x32 strip at luma (152,32), chroma-only mismatch
147 // with luma bit-exact).
148 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
149 if filter_intra.is_some() {
150 hit!(FILTER_INTRA_RECT_HITS);
151 if bw > bh {
152 hit!(FILTER_INTRA_RECT4_HORZ_HITS);
153 } else {
154 hit!(FILTER_INTRA_RECT4_VERT_HITS);
155 }
156 }
157 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
158 DC_PRED
159 } else {
160 uv_mode
161 };
162 // lane-av1mixloss: the lossless-segment early return (`decodeframe.c:1203`)
163 // precedes `TX_MODE_SELECT`, so a lossless-segment rect4 block codes no
164 // depth symbol here either (class sweep of the sub8 leaf's fix).
165 let depth = if tx_select && !lossless(fctx) {
166 // lane-av1txbands: EVERY frame now reads the real `TXFM_CONTEXT`
167 // bands (`get_tx_size_context`, libaom `pred_common.h:342`) -- an
168 // intra-only frame publishes them from every block too
169 // ([`Neighbours::fill_lf_grid_rect`]). Measured on the 10-bit
170 // 1920x792 128-superblock stream,
171 // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read
172 // `tx_size_cat2` row 1 where libaom reads row 2.
173 let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx);
174 let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
175 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
176 eprintln!(
177 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",
178 dec.debug_state().0
179 );
180 }
181 d
182 } else {
183 0
184 };
185 // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra
186 // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`].
187 publish_txfm_bands_if_in_inter(
188 neighbours,
189 (mi_r, mi_c),
190 depth_to_tx_wh(bw, bh, depth, fctx),
191 (bw, bh),
192 fctx,
193 );
194 if depth != 0 || lossless(fctx) {
195 // lane-rectsplitx r1: the per-transform-unit walk, at this strip's
196 // real mi position (strips 1 and 3 of a HORZ_4 start 8 px into a
197 // 16-px [`SUB`] cell). depth 1 is the RECT unit TX_16X8/TX_8X16
198 // (`sub_tx_size_map[TX_32X8] == TX_16X8`), depth 2 the square TX_8X8;
199 // both interleave in every real stream.
200 hit!(TX_DEPTH_HITS);
201 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
202 // lane-rectsplitx r2: both depths ship together, as the r1 handoff
203 // predicted -- depth 1 fires FIRST in every attempt that splits at
204 // all, so a depth-2-only lift could never be gated. The r1 mismatch
205 // was never the rect unit: it was the neighbour MODE the strip reads
206 // (see `modes_above_left_mi`).
207 let which = if depth == 1 {
208 &RECT4_SPLIT_DEPTH1_HITS
209 } else {
210 &RECT4_SPLIT_DEPTH2_HITS
211 };
212 hit_do! { which.with(|c| c.set(c.get() + 1)); }
213 let modes = RectStripModes {
214 skip,
215 mode,
216 angle_delta_y,
217 uv_predict_mode,
218 angle_delta_uv,
219 alpha,
220 filter_intra,
221 smooth_neighbor,
222 smooth_neighbor_uv,
223 palette_y: palette_y_buf.clone(),
224 palette_uv: palette_uv_bufs.clone(),
225 };
226 if palette_y.is_some() || palette_uv.is_some() {
227 hit!(PALETTE_SPLIT_TX_HITS);
228 }
229 decode_rect_split(
230 dec,
231 cdfs,
232 neighbours,
233 (mi_r, mi_c),
234 bw,
235 bh,
236 tx_w,
237 tx_h,
238 &modes,
239 y,
240 u,
241 v,
242 base_q_idx,
243 false,
244 fctx,
245 )?;
246 record_strip_palette(
247 neighbours,
248 pal_at,
249 bw,
250 bh,
251 pal_y_size,
252 pal_y_colors,
253 pal_uv_size,
254 pal_uv_colors,
255 );
256 if bw > bh {
257 hit!(RECT4_32_HORZ_HITS);
258 } else {
259 hit!(RECT4_32_VERT_HITS);
260 }
261 if !skip {
262 hit!(RECT4_COEFF_HITS);
263 }
264 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
265 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
266 // frame, so this 1:4 strip -- which is also the INTER frame's reader
267 // for 32x8/8x32 ([`decode_intra_rect4_in_inter`]) -- publishes its
268 // transform size in both TXFM_CONTEXT bands. Without it the next block
269 // reads the row's stale value.
270 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
271 return Ok((mode, uv_predict_mode));
272 }
273 // The coarse (16-px [`SUB`] cell) mode/side arrays cannot name a strip
274 // that is 8 px tall, so each strip stamps every cell it touches and the
275 // LAST strip wins -- which is the right answer for the block below/right
276 // of the 32x32, the only reader outside it. Written after this strip's
277 // own context read above, never before.
278 for cell in 0..bw.div_ceil(SUB) {
279 neighbours.above_mode[c + cell] = mode;
280 neighbours.above_uv_mode[c + cell] = uv_predict_mode;
281 neighbours.above_side[c + cell] = bw;
282 }
283 for cell in 0..bh.div_ceil(SUB) {
284 neighbours.left_mode[r + cell] = mode;
285 neighbours.left_uv_mode[r + cell] = uv_predict_mode;
286 neighbours.left_side[r + cell] = bh;
287 }
288 // ...and the mi-EXACT maps the coarse cells alias away, exactly as
289 // [`decode_leaf_rect`] does (the split arm above records these through
290 // `record_mi_luma_rect`). Without this an unsplit 32x8 strip left
291 // `sub8_mode_row` holding the previous block, and the next 32x32's
292 // strips read a stale `kf_y_mode` row (measured: mi(4,8) on the band
293 // fixture).
294 neighbours.record_mode_mi(mi_r, mi_c, mi_w, mi_h, mode);
295 neighbours.record_uv_mode_mi(mi_r, mi_c, mi_w, mi_h, uv_predict_mode);
296 let (px, py) = (mi_c * MI, mi_r * MI);
297 let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
298 let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
299 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
300 // lane-av1-444: the strip's chroma shape follows the subsampling.
301 // 4:2:0 codes 16x4/4x16 (`TxbSet::Chroma8`); 4:4:4 codes the strip
302 // itself, 32x8/8x32 (`get_txsize_entropy_ctx(TX_32X8)` =
303 // `(wide_log2 + high_log2 + 1) >> 1` = the 16x16 set,
304 // `TxbSet::Chroma16`). The caller set is closed -- this reader only ever
305 // sees 32x8 / 8x32 luma. lane-av1422lift: this sentence used to end "and
306 // the sequence header admits ss 0/0 and 1/1 only -- so the table is
307 // exhaustive", which was a claim about a guard rather than about this
308 // reader. The header admits ss (1,1), (1,0) and (0,0), and the (1,0)
309 // 4:2:2 arm is dispatched a few lines below (`chroma422_rect32`), so the
310 // table's exhaustiveness comes from the reader's own luma shape -- which
311 // is what the sentence now claims.
312 let chroma422_rect32 = (chroma_w, chroma_h) == (4, 32) && ss_x(fctx) == 1 && ss_y(fctx) == 0;
313 let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) {
314 (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),
315 (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]),
316 (32, 8) => (TxbSet::Chroma16, &SCAN_32X8[..]),
317 (8, 32) => (TxbSet::Chroma16, &SCAN_8X32[..]),
318 // lane-av1-422: a 4:2:2 1:4 strip halves only the width, so the
319 // landscape leaves (32x8, 16x4 luma) code their chroma as the RECT
320 // (16,8)/(8,4) -- the same TxbSet/scan pair the (16,8)/(8,4) rows of
321 // [`decode_rect_split`]'s chroma table use.
322 // lane-av1-422p: the PORTRAIT leaf occurs too -- the pinned
323 // fixture's frame 2 carries an 8x32 strip at ss(1,0), whose (4, 32)
324 // chroma block `ss_size_lookup[BLOCK_8X32][1][0]` marks
325 // BLOCK_INVALID (255, enums.h). BLOCK_INVALID does not mean
326 // "uncodable": `av1_get_tx_size` reads `max_txsize_rect_lookup[255]`
327 // OUT OF BOUNDS there, the byte at +255 in the pinned Release oracle
328 // is 0x05 = TX_4X8 (the `decode_token_recon_block` copy at
329 // 0xc0d030, objdump-measured), and `av1_get_adjusted_tx_size` has no
330 // TX_4X8 case. libaom HAS the transform, so the shape CHUNKS (the
331 // `chroma422_rect32` arm below) into FOUR stacked TX_4X8 units per
332 // plane (`tx_size_high_unit[TX_4X8] = 2`: blk_row 0, 2, 4, 6)
333 // instead of refusing; no coefficient-table row is added, because
334 // BLOCK_4X32 is not a table libaom has. 4:2:0 and 4:4:4 never land
335 // here (their 8x32 strips read (4, 16) and (8, 32)), so the row is
336 // 4:2:2-only.
337 (16, 8) => (TxbSet::ChromaRect16x8, &SCAN_16X8[..]),
338 (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]),
339 // lane-av1-422p: the units' own set/scan -- the whole-rect read
340 // below never sees this row, the `chroma422_rect32` arm chunks
341 // first. Anything else is still a named-lane gap.
342 (4, 32) if ss_x(fctx) == 1 && ss_y(fctx) == 0 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]),
343 _ => unreachable!("decode_block_rect4 chroma shape set is closed: {chroma_w}x{chroma_h}"),
344 };
345 let luma_scan: &[u16] = if bw > bh { &SCAN_32X8 } else { &SCAN_8X32 };
346 let (luma_levels, u_levels, v_levels) = if skip {
347 (
348 vec![0i32; bw * bh],
349 vec![0i32; chroma_w * chroma_h],
350 vec![0i32; chroma_w * chroma_h],
351 )
352 } else if chroma422_rect32 {
353 // lane-av1-422p: the (4, 32) plane as FOUR TX_4X8 units per plane,
354 // plane-major (every U unit, then every V) -- the walk the pinned
355 // oracle's `decode_token_recon_block` makes for the BLOCK_INVALID
356 // plane block: TX_4X8, so stepr = `tx_size_high_unit[TX_4X8]` = 2
357 // 4-px rows and stepc = 1, unit rows at chroma y 0, 8, 16, 24.
358 // Luma is the same single TX_8X32 rect the general arm reads.
359 let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh);
360 let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x8, mode);
361 let (luma_levels, luma_tx_type) = read_coeffs_rect(
362 dec,
363 &mut luma_coding,
364 luma_scan,
365 bw,
366 bh,
367 0,
368 dc_sign_ctx(around[0].2),
369 TxType::DctDct,
370 0,
371 )?;
372 hit!(RECT4_COEFF_HITS);
373 let luma_residual = dequant_and_inverse_typed_wh(
374 &luma_levels,
375 bw,
376 bh,
377 crate::decode::bit_depth(fctx),
378 block_q_idx(fctx),
379 plane_q_delta(0, fctx).0,
380 plane_q_delta(0, fctx).1,
381 luma_tx_type,
382 block_iqmatrix(fctx, 0, bw, bh, luma_tx_type),
383 );
384 if let Some(b) = &palette_y_buf {
385 set_palette_pred(b.clone(), fctx);
386 }
387 push_intra_rect(
388 y,
389 u,
390 v,
391 0,
392 px,
393 py,
394 bw,
395 bh,
396 mode,
397 angle_delta_y,
398 reach,
399 &luma_residual,
400 None,
401 filter_intra,
402 smooth_neighbor,
403 fctx,
404 );
405 // CfL parameters are computed ONCE per block over the strip's luma
406 // (`are_parameters_computed`) and shared by all four units, as in
407 // every other chunk arm.
408 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
409 let mut unit_grids: Vec<((usize, usize), usize, Grid)> = Vec::new();
410 for plane in [1usize, 2] {
411 for unit_row in 0..4usize {
412 let unit_mi = (mi_r + unit_row * 2, mi_c);
413 let unit_reach = tu_reach_rect(
414 bw,
415 bh,
416 0,
417 unit_row * 8,
418 8,
419 8,
420 reach,
421 px,
422 py,
423 y.width,
424 y.height,
425 fctx,
426 );
427 if let Some((ub, vb)) = &palette_uv_bufs {
428 let pbuf = if plane == 1 { ub } else { vb };
429 set_palette_pred(palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), fctx);
430 }
431 // Each unit is read and recorded IMMEDIATELY: unit row 0's
432 // `txb_skip_ctx` still sees the real above/left neighbour
433 // states, a lower unit sees this block's own upper unit's
434 // (libaom's per-unit `set_entropy_context`), and the lower
435 // unit predicts off the upper one's reconstructed samples.
436 let chroma_around = neighbours.around_mi_422_chroma(unit_mi, 8, 8);
437 let unit_grid = read_rect_chroma_unit(
438 dec,
439 cdfs,
440 TxbSet::ChromaRect8x4,
441 &SCAN_4X8,
442 4,
443 8,
444 plane,
445 chroma_around[plane],
446 uv_predict_mode,
447 angle_delta_uv,
448 unit_reach,
449 y,
450 u,
451 v,
452 cpx,
453 cpy + unit_row * 8,
454 base_q_idx,
455 // `get_txb_ctx_general`'s chroma branch
456 // (txb_common.h): plane_bsize is BLOCK_INVALID (255)
457 // here, `num_pels_log2_lookup[255]` = 255 (the +255
458 // byte of the decodetxb copy at 0xc0de70,
459 // objdump-measured) exceeds `BLOCK_4X8`'s 5, so the
460 // ctx_offset is 10 -- the port's offset-7-first
461 // `txb_skip_chroma_8` stores the offset-10 rows at
462 // rows 3..6, hence +3.
463 Some(3),
464 alpha
465 .zip(ac)
466 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
467 smooth_neighbor_uv,
468 fctx,
469 )?;
470 neighbours.record_mi_chroma(unit_mi, 8, 8, plane, &unit_grid);
471 unit_grids.push((unit_mi, plane, unit_grid));
472 }
473 }
474 // The whole-block stamp rewrites the chroma cells ONE state wide,
475 // which would erase the unit boundary the next block reads (class
476 // `override-slot-on-one-arm`), so it carries zero chroma grids and
477 // the per-unit writes replay after it. Its luma cells and side
478 // spans are this arm's own bookkeeping.
479 let zero_chroma = vec![0i32; chroma_w * chroma_h];
480 neighbours.record_mi_rect(
481 (mi_r, mi_c),
482 bw,
483 bh,
484 &[&luma_levels[..], &zero_chroma[..], &zero_chroma[..]],
485 );
486 for (unit_mi, plane, grid) in &unit_grids {
487 neighbours.record_mi_chroma(*unit_mi, 8, 8, *plane, grid);
488 }
489 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);
490 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx);
491 record_strip_palette(
492 neighbours,
493 pal_at,
494 bw,
495 bh,
496 pal_y_size,
497 pal_y_colors,
498 pal_uv_size,
499 pal_uv_colors,
500 );
501 if bw > bh {
502 hit!(RECT4_32_HORZ_HITS);
503 } else {
504 hit!(RECT4_32_VERT_HITS);
505 }
506 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
507 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
508 // frame, so this 1:4 strip -- which is also the INTER frame's reader
509 // for 32x8/8x32 ([`decode_intra_rect4_in_inter`]) -- publishes its
510 // transform size in both TXFM_CONTEXT bands. Without it the next block
511 // reads the row's stale value.
512 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (bw, bh), (bw, bh));
513 return Ok((mode, uv_predict_mode));
514 } else {
515 let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh);
516 // lane-av1lr422: the chroma planes of a 4:2:2 strip take their
517 // above votes per chroma column (see `around_mi_422_chroma`), not
518 // per luma mi. The full-rect gather counts each chroma column twice,
519 // which flips `dc_sign_ctx` and desyncs the tile (libaom reads
520 // dc_sign_ctx 0 where this read 2, at 10-bit 4:2:2 200x120).
521 let chroma_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
522 neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh)
523 } else {
524 around
525 };
526 let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x8, mode);
527 let (luma_levels, luma_tx_type) = read_coeffs_rect(
528 dec,
529 &mut luma_coding,
530 luma_scan,
531 bw,
532 bh,
533 0,
534 dc_sign_ctx(around[0].2),
535 TxType::DctDct,
536 0,
537 )?;
538 let mut planes = Vec::with_capacity(2);
539 // Index loop mirrors the spec's per-position form over several offsets; an iterator would obscure it.
540 #[allow(clippy::needless_range_loop)]
541 for plane in 1..3 {
542 // `av1_get_tx_type` (`blockd.h:1278`): the mode-indexed type
543 // stands only while it is a member of this tx size's set; a
544 // 32x8/8x32 chroma transform (4:4:4) squares up to TX_32X32,
545 // whose intra set is `EXT_TX_SET_DCTONLY` -- every ADST clamps
546 // to DCT_DCT there, and ADST is undefined at widths above 16.
547 let default_tx = if chroma_w.max(chroma_h) >= 32 {
548 TxType::DctDct
549 } else {
550 default_intra_tx_type(uv_predict_mode as u8)
551 };
552 let skip_ctx =
553 usize::from(chroma_around[plane].0) + usize::from(chroma_around[plane].1);
554 let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
555 let (levels, tx_type) = read_chroma_coeffs_rect(
556 dec,
557 &mut coding,
558 chroma_scan,
559 chroma_w,
560 chroma_h,
561 skip_ctx,
562 dc_sign_ctx(chroma_around[plane].2),
563 default_tx,
564 fctx,
565 plane,
566 )?;
567 planes.push((levels, tx_type));
568 }
569 let (v_levels, v_tx_type) = planes.pop().expect("plane 2");
570 let (u_levels, u_tx_type) = planes.pop().expect("plane 1");
571 hit!(RECT4_COEFF_HITS);
572 let luma_residual = dequant_and_inverse_typed_wh(
573 &luma_levels,
574 bw,
575 bh,
576 crate::decode::bit_depth(fctx),
577 block_q_idx(fctx),
578 plane_q_delta(0, fctx).0,
579 plane_q_delta(0, fctx).1,
580 luma_tx_type,
581 block_iqmatrix(fctx, 0, bw, bh, luma_tx_type),
582 );
583 if let Some(b) = &palette_y_buf {
584 set_palette_pred(b.clone(), fctx);
585 }
586 push_intra_rect(
587 y,
588 u,
589 v,
590 0,
591 px,
592 py,
593 bw,
594 bh,
595 mode,
596 angle_delta_y,
597 reach,
598 &luma_residual,
599 None,
600 filter_intra,
601 smooth_neighbor,
602 fctx,
603 );
604 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
605 for (plane, levels, tx_type) in [(1usize, &u_levels, u_tx_type), (2, &v_levels, v_tx_type)]
606 {
607 let residual = dequant_and_inverse_typed_wh(
608 levels,
609 chroma_w,
610 chroma_h,
611 crate::decode::bit_depth(fctx),
612 block_q_idx(fctx),
613 plane_q_delta(plane, fctx).0,
614 plane_q_delta(plane, fctx).1,
615 tx_type,
616 block_iqmatrix(fctx, plane, chroma_w, chroma_h, tx_type),
617 );
618 if let Some((ub, vb)) = &palette_uv_bufs {
619 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
620 }
621 push_intra_rect(
622 y,
623 u,
624 v,
625 plane,
626 cpx,
627 cpy,
628 chroma_w,
629 chroma_h,
630 uv_predict_mode,
631 angle_delta_uv,
632 reach,
633 &residual,
634 alpha
635 .zip(ac)
636 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
637 None,
638 smooth_neighbor_uv,
639 fctx,
640 );
641 }
642 neighbours.record_mi_rect(
643 (mi_r, mi_c),
644 bw,
645 bh,
646 &[&luma_levels[..], &u_levels[..], &v_levels[..]],
647 );
648 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);
649 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx);
650 record_strip_palette(
651 neighbours,
652 pal_at,
653 bw,
654 bh,
655 pal_y_size,
656 pal_y_colors,
657 pal_uv_size,
658 pal_uv_colors,
659 );
660 if bw > bh {
661 hit!(RECT4_32_HORZ_HITS);
662 } else {
663 hit!(RECT4_32_VERT_HITS);
664 }
665 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
666 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
667 // frame, so this 1:4 strip -- which is also the INTER frame's reader
668 // for 32x8/8x32 ([`decode_intra_rect4_in_inter`]) -- publishes its
669 // transform size in both TXFM_CONTEXT bands. Without it the next block
670 // reads the row's stale value.
671 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (bw, bh), (bw, bh));
672 return Ok((mode, uv_predict_mode));
673 };
674 if let Some(b) = &palette_y_buf {
675 set_palette_pred(b.clone(), fctx);
676 }
677 push_intra_rect(
678 y,
679 u,
680 v,
681 0,
682 px,
683 py,
684 bw,
685 bh,
686 mode,
687 angle_delta_y,
688 reach,
689 &luma_levels,
690 None,
691 filter_intra,
692 smooth_neighbor,
693 fctx,
694 );
695 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
696 if chroma422_rect32 {
697 // lane-av1-422p: `predict_and_reconstruct_intra_block` (decodeframe.c
698 // ~1000) predicts EVERY unit regardless of `skip_txfm`, so the skip
699 // arm walks the same four TX_4X8 units per plane -- the lower unit
700 // predicts off the upper one's predicted samples. No coefficients
701 // are coded; the tail's whole-block zero stamp below is the state
702 // libaom's `set_entropy_context` leaves.
703 for plane in [1usize, 2] {
704 for unit_row in 0..4usize {
705 let unit_reach = tu_reach_rect(
706 bw,
707 bh,
708 0,
709 unit_row * 8,
710 8,
711 8,
712 reach,
713 px,
714 py,
715 y.width,
716 y.height,
717 fctx,
718 );
719 if let Some((ub, vb)) = &palette_uv_bufs {
720 let pbuf = if plane == 1 { ub } else { vb };
721 set_palette_pred(palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), fctx);
722 }
723 push_intra_rect(
724 y,
725 u,
726 v,
727 plane,
728 cpx,
729 cpy + unit_row * 8,
730 4,
731 8,
732 uv_predict_mode,
733 angle_delta_uv,
734 unit_reach,
735 &ZERO_RESIDUAL[..4 * 8],
736 alpha
737 .zip(ac)
738 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
739 None,
740 smooth_neighbor_uv,
741 fctx,
742 );
743 }
744 }
745 } else {
746 if let Some((ub, _)) = &palette_uv_bufs {
747 set_palette_pred(ub.clone(), fctx);
748 }
749 push_intra_rect(
750 y,
751 u,
752 v,
753 1,
754 cpx,
755 cpy,
756 chroma_w,
757 chroma_h,
758 uv_predict_mode,
759 angle_delta_uv,
760 reach,
761 &u_levels,
762 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
763 None,
764 smooth_neighbor_uv,
765 fctx,
766 );
767 if let Some((_, vb)) = &palette_uv_bufs {
768 set_palette_pred(vb.clone(), fctx);
769 }
770 push_intra_rect(
771 y,
772 u,
773 v,
774 2,
775 cpx,
776 cpy,
777 chroma_w,
778 chroma_h,
779 uv_predict_mode,
780 angle_delta_uv,
781 reach,
782 &v_levels,
783 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
784 None,
785 smooth_neighbor_uv,
786 fctx,
787 );
788 }
789 neighbours.record_mi_rect(
790 (mi_r, mi_c),
791 bw,
792 bh,
793 &[&luma_levels[..], &u_levels[..], &v_levels[..]],
794 );
795 neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip);
796 neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx);
797 record_strip_palette(
798 neighbours,
799 pal_at,
800 bw,
801 bh,
802 pal_y_size,
803 pal_y_colors,
804 pal_uv_size,
805 pal_uv_colors,
806 );
807 if bw > bh {
808 hit!(RECT4_32_HORZ_HITS);
809 } else {
810 hit!(RECT4_32_VERT_HITS);
811 }
812 // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm,
813 // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter
814 // frame, so this 1:4 strip -- which is also the INTER frame's reader
815 // for 32x8/8x32 ([`decode_intra_rect4_in_inter`]) -- publishes its
816 // transform size in both TXFM_CONTEXT bands. Without it the next block
817 // reads the row's stale value.
818 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (bw, bh), (bw, bh));
819 Ok((mode, uv_predict_mode))
820}
821
822/// Decodes the four 16x4 / 4x16 strips of a 16x16-level `PARTITION_HORZ_4` /
823/// `PARTITION_VERT_4` (lane-r14) -- [`decode_block_rect4`]'s pair one level
824/// down, and the first shape here whose luma block is a single mi row (or
825/// column).
826///
827/// What is new at this size is CHROMA. `is_chroma_reference`
828/// (`av1_common_int.h`) is false for a 4:2:0 block one mi tall (wide) on an
829/// EVEN mi row (column), so strips 0 and 2 read no `uv_mode`/`cfl_alpha`/
830/// `angle_delta_uv` at all and code no chroma residual; strips 1 and 3 close
831/// the pair and carry the chroma of the whole 16x8 (8x16) luma pair --
832/// `setup_pred_plane`'s own `if (subsampling_y && (mi_row & 1) &&
833/// mi_size_high[bsize] == 1) mi_row -= 1` offset, i.e. an 8x4 (4x8) chroma
834/// transform at the PAIR's origin, with CfL averaging over the pair's luma.
835///
836/// Tables: LUMA `TX_16X4`/`TX_4X16` averages to the 8x8 entropy context
837/// ((0 + 2 + 1) >> 1 = 1) with 64 coded positions, so its CDF set is
838/// [`TxbSet::LumaRect16x4`] (`Luma8`'s tables, the `TX_4X4` `tx_type` row);
839/// scans are [`SCAN_16X4`]/[`SCAN_4X16`]. CHROMA `TX_8X4`/`TX_4X8` is
840/// [`TxbSet::ChromaRect8x4`] with [`SCAN_8X4`]/[`SCAN_4X8`]. Angle deltas ARE
841/// coded (`av1_use_angle_delta` compares the BLOCK_SIZES_ALL enum index, and
842/// BLOCK_16X4 is 17), and so is `use_filter_intra` (both sides <= 32) off this
843/// shape's own CDF row.
844///
845/// A split transform (`tx_depth != 0`, `sub_tx_size_map[TX_16X4] == TX_8X4`)
846/// refuses by name rather than guess-decode.
847#[allow(clippy::too_many_arguments)]
848pub(super) fn decode_rect4_16(
849 dec: &mut SymbolDecoder,
850 cdfs: &mut Cdfs,
851 neighbours: &mut Neighbours,
852 at16: (usize, usize),
853 horz: bool,
854 y: &mut PlaneBuf<'static>,
855 u: &mut PlaneBuf<'static>,
856 v: &mut PlaneBuf<'static>,
857 enable_filter_intra: bool,
858 allow_screen_content_tools: bool,
859 base_q_idx: u8,
860 tx_select: bool,
861 reduced_tx_set: bool,
862 fctx: &crate::decode::FrameCtx,
863) -> Result<()> {
864 let (r, c) = at16;
865 let (mi_row0, mi_col0) = (r * (SUB / MI), c * (SUB / MI));
866 let (bw, bh) = if horz { (16, 4) } else { (4, 16) };
867 let (_mi_w, _mi_h) = (bw / MI, bh / MI);
868 let _scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 };
869 let _chroma_scan: &[u16] = if horz { &SCAN_8X4 } else { &SCAN_4X8 };
870 let mut prev: Option<((usize, usize), usize)> = None;
871 let mut last_mode = DC_PRED;
872 let mut last_uv_mode = DC_PRED;
873 for i in 0..4usize {
874 let lmi = if horz {
875 (mi_row0 + i, mi_col0)
876 } else {
877 (mi_row0, mi_col0 + i)
878 };
879 // lane-av1-444: at 4:4:4 every strip is its own chroma reference
880 // (no mi-parity test at ss 0/0, and the strip's own chroma block is
881 // already >= 4x4) -- there is no 4:2:0 pair to close.
882 // lane-av1-422o: the parity rule is per axis, straight out of
883 // `is_chroma_reference`: a HORZ 16x4 strip (1 mi tall) keeps the
884 // `ss_y == 0 -> every strip a reference` row rule, but a VERT 4x16
885 // strip (1 mi wide) keeps the COLUMN clause `(mi_col & 1) || !(bw &
886 // 1) || !ss_x`, which with bw == 1 mi reduces to `mi_col odd` for
887 // every ss_x == 1 format -- the ODD strip closes the pair and reads
888 // the chroma, exactly like 4:2:0. (VERT_4 partitions start on an
889 // even mi_col, so `i % 2 == 1` is that clause.)
890 let has_chroma = i % 2 == 1 || (horz && ss_y(fctx) == 0) || (!horz && ss_x(fctx) == 0);
891 let (mode, uv, _tx) = decode_rect4_16_strip(
892 dec,
893 cdfs,
894 neighbours,
895 lmi,
896 horz,
897 has_chroma,
898 prev,
899 y,
900 u,
901 v,
902 enable_filter_intra,
903 allow_screen_content_tools,
904 base_q_idx,
905 tx_select,
906 reduced_tx_set,
907 fctx,
908 )?;
909 if let Some(m) = uv {
910 last_uv_mode = m;
911 }
912 last_mode = mode;
913 prev = Some((lmi, mode));
914 }
915 // The coarse 16-px cell holds one entry for the whole 16x16: the last
916 // strip is what a block below (right) sees through it, the mi-exact maps
917 // above answering everything finer.
918 neighbours.above_mode[c] = last_mode;
919 neighbours.left_mode[r] = last_mode;
920 neighbours.above_uv_mode[c] = last_uv_mode;
921 neighbours.left_uv_mode[r] = last_uv_mode;
922 neighbours.above_side[c] = bw;
923 neighbours.left_side[r] = bh;
924 Ok(())
925}
926
927/// One 16x4 / 4x16 strip of a 16x16-level 1:4 partition, intra-coded --
928/// [`decode_rect4_16`]'s per-strip body, lifted (lane-intra16x4) so the INTER
929/// block path can decode a SINGLE intra strip of a partition whose other
930/// strips are inter. `prev` is the previous strip's `(mi, mode)` (the
931/// key-frame caller's coarse-cell stand-in; `None` on the inter path, where
932/// every strip publishes its own mi-exact mode). Returns
933/// `(y_mode, uv_predict_mode when this strip closes the 4:2:0 chroma pair)`.
934/// Intrabc reconstruction for a rect strip that OWNS its chroma
935/// (`bw/2 x bh/2` at the strip origin). 16x4/4x16 is not this shape -- that
936/// pair goes through [`decode_rect4_16_intrabc`].
937///
938/// This is the same control flow as the unmerged lane's `decode_intrabc_rect`
939/// (predict once, then one residual per transform unit on the INTER sets,
940/// chroma inherits luma's `tx_type`), written against the helpers that exist
941/// on this tree so a 2:1 strip no longer hides the 16x4 pair witness. The
942/// merge with lane-av1-intrabc should keep one of the two bodies; the call
943/// shape is the same.
944#[allow(clippy::too_many_arguments)]
945pub(super) fn decode_intrabc_owned_rect(
946 dec: &mut SymbolDecoder,
947 cdfs: &mut Cdfs,
948 neighbours: &mut Neighbours,
949 (mi_r, mi_c): (usize, usize),
950 (bw, bh): (usize, usize),
951 skip: bool,
952 (dv_row, dv_col): (i32, i32),
953 y: &mut PlaneBuf<'static>,
954 u: &mut PlaneBuf<'static>,
955 v: &mut PlaneBuf<'static>,
956 base_q_idx: u8,
957 tx_select: bool,
958 reduced_tx_set: bool,
959 fctx: &crate::decode::FrameCtx,
960) -> Result<()> {
961 let _ = base_q_idx;
962 let (px, py) = (mi_c * MI, mi_r * MI);
963 // lane-av1chromarect: libaom does NOT halve a 128-root intra-BC strip's
964 // chroma plane block. `av1_get_max_uv_txsize` (blockd.h:1372) is
965 // `max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, ss_y)]` run
966 // through `av1_get_adjusted_tx_size`, and `get_plane_block_size` is
967 // `ss_size_lookup[bsize]` -- at 4:4:4 the chroma plane block is the block's
968 // OWN footprint, so the extent below and the eight chroma MV origin pairs
969 // that follow must be `>> ss_x` / `>> ss_y`, not `/ 2`. At 4:2:0
970 // (`ss_x == ss_y == 1`) the two forms are the same arithmetic.
971 // MEASURED on the 4:4:4 LOSSY witness `fixtures/r512.obu` (6948 B, 3
972 // frames, 5 strips through this function): with the halving, frame 0
973 // diverges from the aomdec oracle in 166229 Y / 155383 U / 153498 V
974 // samples and both later frames keep luma byte-exact while 74708 U +
975 // 73501 V (f1) and 9216 U + 8192 V (f2) are wrong -- chroma-only, which is
976 // what makes this a chroma-sizing defect and not a block-geometry one.
977 // Re-measured by this lane; see lanes/av1chromarect.report.md.
978 if crate::envflags::env_flag!("EC_HALVSWEEP") {
979 eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}");
980 }
981 let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
982 let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
983 let side = bw.max(bh);
984 let cside = cw.max(ch);
985 if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
986 hit!(IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS);
987 }
988 let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
989 let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get);
990 fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set));
991 // `read_block_tx_size_rect` keys on this cell. A key frame forces it
992 // false; the real bit is the caller's `tx_select`. Restored before return.
993 fctx.tx_select_inter.with(|c| c.set(tx_select));
994 let restore = ReducedTxRestore {
995 fctx,
996 saved_reduced,
997 saved_tx,
998 };
999
1000 let pred_y = predict_intrabc_window(y, px, py, bw, bh, dv_col, dv_row, true, side, fctx);
1001 let pred_u = predict_intrabc_window(u, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx);
1002 let pred_v = predict_intrabc_window(v, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx);
1003
1004 let mi_cols = 2 * y.true_width.div_ceil(8);
1005 let mi_rows = 2 * y.true_height.div_ceil(8);
1006 let leaves = read_block_tx_size_rect(
1007 dec,
1008 cdfs,
1009 neighbours,
1010 (mi_r, mi_c),
1011 (bw, bh),
1012 (mi_cols, mi_rows),
1013 skip,
1014 fctx,
1015 )?;
1016 let mut luma_tx_type = TxType::DctDct;
1017 let luma_grid;
1018 let u_grid;
1019 let v_grid;
1020 if skip {
1021 // `reconstruct_mc_rect` indexes the residual at the square stride.
1022 // `bw * bh` underruns on a VERT strip (8x16: stride 16, 16 rows, index 136).
1023 push_mc_rect(
1024 y,
1025 u,
1026 v,
1027 0,
1028 px,
1029 py,
1030 side,
1031 bw,
1032 bh,
1033 Pred::Inline(&pred_y, side),
1034 &ZERO_RESIDUAL[..side * bh],
1035 fctx,
1036 );
1037 push_mc_rect(
1038 y,
1039 u,
1040 v,
1041 1,
1042 cpx,
1043 cpy,
1044 cside,
1045 cw,
1046 ch,
1047 Pred::Inline(&pred_u, cside),
1048 &ZERO_RESIDUAL[..cside * ch],
1049 fctx,
1050 );
1051 push_mc_rect(
1052 y,
1053 u,
1054 v,
1055 2,
1056 cpx,
1057 cpy,
1058 cside,
1059 cw,
1060 ch,
1061 Pred::Inline(&pred_v, cside),
1062 &ZERO_RESIDUAL[..cside * ch],
1063 fctx,
1064 );
1065 if let Some(ls) = leaves.as_ref() {
1066 // libaom `av1_reset_entropy_context` (`if (mbmi->skip_txfm)`,
1067 // decodeframe.c:1262 -> blockd.c:58): a SKIPPED block zeroes its
1068 // whole entropy-band footprint. The non-skip arm below writes
1069 // those bands per transform unit and the tail's
1070 // `record_split_luma_rect_mi` writes chroma only, so without
1071 // this walk a skipped strip whose `leaves` resolved (every
1072 // lossless frame -- `read_block_tx_size_rect`'s lossless arm
1073 // returns the 4x4 grid before it looks at `skip`) leaked the
1074 // PREVIOUS occupant's luma bands into the next block's
1075 // `txb_skip`/coefficient contexts (lane-av1-loss64: the skipped
1076 // 8x16 intrabc strip at mi(48,66) of the 320x242 lossless sb128
1077 // stream left a stale 7 in left[48] and mi(48,68)'s first
1078 // transform unit read `txb_skip_ctx` 3 where aomdec reads 1).
1079 hit!(SKIP_LOSSLESS_BAND_RESET_HITS);
1080 for &(row, col, tw, th) in ls {
1081 neighbours.record_mi_luma_rect(
1082 (mi_r + row, mi_c + col),
1083 tw,
1084 th,
1085 &ZERO_RESIDUAL[..tw * th],
1086 );
1087 }
1088 }
1089 luma_grid = Grid::Zero(side * side);
1090 u_grid = Grid::Zero(cside * cside);
1091 v_grid = Grid::Zero(cside * cside);
1092 } else if let Some(ls) = leaves.as_ref() {
1093 let mut leaf_types: Vec<(usize, usize, usize, usize, TxType)> =
1094 Vec::with_capacity(ls.len());
1095 for (idx, &(row, col, tw, th)) in ls.iter().enumerate() {
1096 let tu_mi = (mi_r + row, mi_c + col);
1097 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
1098 let tu_pred = Pred::Inline(&pred_y, side).offset(row * MI * side + col * MI);
1099 let (g, tt) = if tw == th {
1100 read_inter_plane(
1101 dec,
1102 cdfs,
1103 inter_txbset_for(tw, reduced_tx_set),
1104 default_scan(tw.min(32)),
1105 0,
1106 neighbours.around_mi(tu_mi, tw)[0],
1107 0,
1108 y,
1109 u,
1110 v,
1111 tu_px,
1112 tu_py,
1113 tw,
1114 base_q_idx,
1115 tu_pred,
1116 None,
1117 Some(neighbours.luma_skip_ctx(tu_mi, tw / MI)),
1118 fctx,
1119 )?
1120 } else {
1121 read_inter_plane_rect(
1122 dec,
1123 cdfs,
1124 rect_inter_luma_set(tw, th, fctx)?,
1125 (tw, th),
1126 side,
1127 0,
1128 neighbours.around_mi_rect(tu_mi, tw, th)[0],
1129 0,
1130 y,
1131 u,
1132 v,
1133 tu_px,
1134 tu_py,
1135 tu_pred,
1136 None,
1137 Some(neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI)),
1138 fctx,
1139 )?
1140 };
1141 leaf_types.push((row, col, tw, th, tt));
1142 if idx == 0 {
1143 luma_tx_type = tt;
1144 }
1145 neighbours.record_mi_luma_rect(tu_mi, tw, th, &g);
1146 if tw != th {
1147 neighbours.fill_lf_grid_leaf_luma(
1148 (tu_mi.0, tu_mi.1),
1149 tw / MI,
1150 th / MI,
1151 tw as u8,
1152 th as u8,
1153 );
1154 }
1155 }
1156 luma_grid = Grid::Zero(side * side);
1157 if cw.min(32) != cw || ch.min(32) != ch {
1158 // lane-av1chromarect: more than one chroma transform unit (the
1159 // 4:4:4 32x64/64x32 plane block). See the helper.
1160 let (ug, vg) = read_intrabc_rect_chroma_split(
1161 y,
1162 u,
1163 v,
1164 dec,
1165 cdfs,
1166 neighbours,
1167 (mi_r, mi_c),
1168 (cpx, cpy),
1169 (cw, ch),
1170 cside,
1171 &pred_u,
1172 &pred_v,
1173 &leaf_types,
1174 luma_tx_type,
1175 fctx,
1176 )?;
1177 u_grid = ug;
1178 v_grid = vg;
1179 } else {
1180 // lane-av1422ibctxsel: at ss (1, 0) a chroma 4-px cell spans TWO
1181 // luma mi columns, so a luma-span gather counts each chroma
1182 // column twice; libaom's `get_txb_ctx_general` reads one vote per
1183 // CHROMA cell, which is what `around_mi_422_chroma`'s
1184 // every-second sampling produces. Both non-split chroma arms of
1185 // this function route through it under the ss (1, 0) guard; every
1186 // other subsampling keeps the plain gather verbatim. WITNESS: the
1187 // no-leaves twin below (24 entries on
1188 // `fixtures/ibc422_nonsplit_ctx.obu`, five of them V-plane reads
1189 // whose two gathers disagree -- `dc_sign_ctx` 1 vs 0; gate
1190 // `a_422_intrabc_owned_rect_nonsplit_chroma_context_uses_the_pair_rule`).
1191 // THIS branch has no stream that splits a transform on the strip:
1192 // it needs `TX_MODE_SELECT` plus a `txfm_partition` split of the
1193 // 64x32 strip, a conjunction no measured stream has produced
1194 // (`lane-av1422ibcrect` measured 0 entries under
1195 // `TX_MODE_LARGEST`); the routing here is identical, so a future
1196 // witness takes the same code.
1197 let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
1198 hit!(IBC_OWNED_RECT_422_PAIR_HITS);
1199 neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh)
1200 } else {
1201 neighbours.around_mi_rect((mi_r, mi_c), bw, bh)
1202 };
1203 let (ug, _) = read_inter_plane_rect(
1204 dec,
1205 cdfs,
1206 rect_inter_chroma_set(cw, ch)?,
1207 (cw, ch),
1208 cside,
1209 1,
1210 around[1],
1211 0,
1212 y,
1213 u,
1214 v,
1215 cpx,
1216 cpy,
1217 Pred::Inline(&pred_u, cside),
1218 Some(luma_tx_type),
1219 None,
1220 fctx,
1221 )?;
1222 let (vg, _) = read_inter_plane_rect(
1223 dec,
1224 cdfs,
1225 rect_inter_chroma_set(cw, ch)?,
1226 (cw, ch),
1227 cside,
1228 2,
1229 around[2],
1230 0,
1231 y,
1232 u,
1233 v,
1234 cpx,
1235 cpy,
1236 Pred::Inline(&pred_v, cside),
1237 Some(luma_tx_type),
1238 None,
1239 fctx,
1240 )?;
1241 u_grid = ug;
1242 v_grid = vg;
1243 }
1244 } else {
1245 let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh);
1246 let (g, tt) = read_inter_plane_rect(
1247 dec,
1248 cdfs,
1249 rect_inter_luma_set(bw, bh, fctx)?,
1250 (bw, bh),
1251 side,
1252 0,
1253 around[0],
1254 0,
1255 y,
1256 u,
1257 v,
1258 px,
1259 py,
1260 Pred::Inline(&pred_y, side),
1261 None,
1262 None,
1263 fctx,
1264 )?;
1265 luma_tx_type = tt;
1266 luma_grid = g;
1267 if cw.min(32) != cw || ch.min(32) != ch {
1268 // lane-av1chromarect: more than one chroma transform unit (the
1269 // 4:4:4 32x64/64x32 plane block). See the helper.
1270 let (ug, vg) = read_intrabc_rect_chroma_split(
1271 y,
1272 u,
1273 v,
1274 dec,
1275 cdfs,
1276 neighbours,
1277 (mi_r, mi_c),
1278 (cpx, cpy),
1279 (cw, ch),
1280 cside,
1281 &pred_u,
1282 &pred_v,
1283 &[],
1284 luma_tx_type,
1285 fctx,
1286 )?;
1287 u_grid = ug;
1288 v_grid = vg;
1289 } else {
1290 // lane-av1422ibctxsel: the twin of the tree branch above -- the
1291 // CHROMA context at ss (1, 0) is the pair rule (one vote per
1292 // chroma 4-px cell); `around` stays the plain luma-span gather
1293 // for plane 0 (lane-av1422ibcrect measured this arm entered 24
1294 // times by a 4:2:2 64x32 strip whose two gathers happened to
1295 // agree -- `fixtures/ibc422_nonsplit_ctx.obu` is the stream where
1296 // they do not).
1297 let around_chroma = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
1298 hit!(IBC_OWNED_RECT_422_PAIR_HITS);
1299 neighbours.around_mi_422_chroma((mi_r, mi_c), bw, bh)
1300 } else {
1301 around
1302 };
1303 let (ug, _) = read_inter_plane_rect(
1304 dec,
1305 cdfs,
1306 rect_inter_chroma_set(cw, ch)?,
1307 (cw, ch),
1308 cside,
1309 1,
1310 around_chroma[1],
1311 0,
1312 y,
1313 u,
1314 v,
1315 cpx,
1316 cpy,
1317 Pred::Inline(&pred_u, cside),
1318 Some(luma_tx_type),
1319 None,
1320 fctx,
1321 )?;
1322 let (vg, _) = read_inter_plane_rect(
1323 dec,
1324 cdfs,
1325 rect_inter_chroma_set(cw, ch)?,
1326 (cw, ch),
1327 cside,
1328 2,
1329 around_chroma[2],
1330 0,
1331 y,
1332 u,
1333 v,
1334 cpx,
1335 cpy,
1336 Pred::Inline(&pred_v, cside),
1337 Some(luma_tx_type),
1338 None,
1339 fctx,
1340 )?;
1341 u_grid = ug;
1342 v_grid = vg;
1343 }
1344 }
1345 drop(restore);
1346 // lane-av1chromarect: when the chroma plane block was walked as SEVERAL
1347 // transform units, each unit stamped its own span through
1348 // `record_mi_chroma` and the whole-block stamp below would overwrite them
1349 // with one state (class `override-slot-on-one-arm`). libaom keeps the
1350 // per-unit above/left contexts distinct; the next block's first unit
1351 // reads them.
1352 // `!skip` matters: a SKIPPED strip reads no chroma unit at all (its whole
1353 // chroma plane block is one `push_mc_rect` of `ZERO_RESIDUAL`), so no
1354 // per-unit `record_mi_chroma` ran and the whole-block chroma stamp below
1355 // is still the only one that happens.
1356 let chroma_split_units = !skip && (cw.min(32) != cw || ch.min(32) != ch);
1357 if leaves.is_some() {
1358 if chroma_split_units {
1359 neighbours.record_split_luma_rect_mi_modes((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED);
1360 } else {
1361 neighbours.record_split_luma_rect_mi(
1362 (mi_r, mi_c),
1363 bw,
1364 bh,
1365 DC_PRED,
1366 DC_PRED,
1367 [&u_grid, &v_grid],
1368 );
1369 }
1370 } else if chroma_split_units {
1371 neighbours.record_rect_mi_luma_only((mi_r, mi_c), bw, bh, DC_PRED, DC_PRED, &luma_grid);
1372 } else {
1373 neighbours.record_rect_mi(
1374 (mi_r, mi_c),
1375 bw,
1376 bh,
1377 DC_PRED,
1378 DC_PRED,
1379 &[&luma_grid, &u_grid, &v_grid],
1380 );
1381 }
1382 neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]);
1383 neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]);
1384 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
1385 // lane-av1oddheightfork3: see `decode_intrabc_rect`'s call -- the tree
1386 // published the bands, so no whole-footprint publish here.
1387 neighbours.fill_lf_grid_rect_after_vartx(
1388 (mi_r, mi_c),
1389 bw / MI,
1390 bh / MI,
1391 bw.min(64) as u8,
1392 bh.min(64) as u8,
1393 0,
1394 fctx,
1395 );
1396 record_intrabc_mi_rect(
1397 mi_r,
1398 mi_c,
1399 bw / MI,
1400 bh / MI,
1401 Some((dv_row, dv_col)),
1402 neighbours,
1403 fctx,
1404 );
1405 let _ = luma_tx_type;
1406 Ok(())
1407}
1408
1409/// The chroma plane block of a 128-root intra-BC HORZ/VERT strip when that
1410/// plane block needs MORE THAN ONE transform unit -- the 4:4:4 cell, and the
1411/// 4:2:0 cell of a strip with a 128-px axis.
1412///
1413/// libaom never forms a 64-point CHROMA transform. `get_vartx_max_txsize`
1414/// (blockd.h:1447) returns `av1_get_adjusted_tx_size(max_txsize_rect_lookup
1415/// [plane_bsize])` and `av1_get_adjusted_tx_size` maps `TX_32X64`/`TX_64X32`
1416/// to `TX_32X32`; `decode_token_recon_block` (decodeframe.c:994-1004) then
1417/// steps the plane block by that size's mi units, and
1418/// `decode_reconstruct_tx`'s `tx_size == plane_tx_size || plane` arm never
1419/// recurses for chroma -- the same statement from the other side. So a 4:4:4
1420/// 32x64 chroma plane block is TWO stacked `TX_32X32` units, each with its
1421/// own eob, its own scan and its own coefficient context, NOT one 32x64 unit
1422/// whose coded corner happens to be 32x32: `av1_get_max_eob`'s 64-axis
1423/// truncation is a LUMA rule, and a chroma plane block is never 64 points
1424/// long to begin with.
1425///
1426/// That is exactly the tiling [`read_inter_rect_chroma`] implements
1427/// (`(write_chroma_w.min(32), write_chroma_h.min(32))` and the `nx * ny`
1428/// walk); this is the same walk for a caller that keeps its own grid
1429/// assembly and neighbour recording. The single-unit case is deliberately
1430/// NOT routed through here, so at 4:2:0 and at every 4:4:4 shape below 64
1431/// the caller keeps its own one-unit read verbatim.
1432#[allow(clippy::too_many_arguments)]
1433fn read_intrabc_rect_chroma_split(
1434 y: &mut PlaneBuf<'static>,
1435 u: &mut PlaneBuf<'static>,
1436 v: &mut PlaneBuf<'static>,
1437 dec: &mut SymbolDecoder,
1438 cdfs: &mut Cdfs,
1439 neighbours: &mut Neighbours,
1440 (mi_r, mi_c): (usize, usize),
1441 (cpx, cpy): (usize, usize),
1442 (cw, ch): (usize, usize),
1443 cside: usize,
1444 pred_u: &[u16],
1445 pred_v: &[u16],
1446 leaf_tx_types: &[(usize, usize, usize, usize, TxType)],
1447 luma_tx_type: TxType,
1448 fctx: &crate::decode::FrameCtx,
1449) -> Result<(Grid, Grid)> {
1450 let (uw, uh) = (cw.min(32), ch.min(32));
1451 let (nx, ny) = (cw / uw, ch / uh);
1452 let set = rect_inter_chroma_set(uw, uh)?;
1453 let assembled_h = ch.max(cside);
1454 let mut assembled: [Vec<i32>; 2] = [
1455 vec![0i32; cside * assembled_h],
1456 vec![0i32; cside * assembled_h],
1457 ];
1458 for plane_idx in 1..=2 {
1459 let src = if plane_idx == 1 { pred_u } else { pred_v };
1460 for cu_row in 0..ny {
1461 for cu_col in 0..nx {
1462 let (span_x, span_y) = (uw << ss_x(fctx), uh << ss_y(fctx));
1463 let cu_mi = (mi_r + cu_row * (span_y / MI), mi_c + cu_col * (span_x / MI));
1464 // lane-av1422llintra: the same ss (1, 0) above-column
1465 // double-count as the lossless walk at 12735 -- one chroma
1466 // column spans two luma mi columns and libaom reads one.
1467 // Identical at 4:2:0 and 4:4:4, where the plane block is
1468 // square.
1469 let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
1470 neighbours.around_mi_422_chroma(cu_mi, span_x, span_y)
1471 } else {
1472 neighbours.around_mi_rect(cu_mi, span_x, span_y)
1473 };
1474 let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh);
1475 let cu_pred = Pred::Inline(src, cside).offset(cu_row * uh * cside + cu_col * uw);
1476 // libaom's `av1_get_tx_type` (blockd.h:1287) reads
1477 // `xd->tx_type_map` at the chroma unit's OWN position scaled
1478 // back to luma, so a unit sitting over a luma leaf that coded
1479 // nothing takes that leaf's stamp, not the block-level one.
1480 let rel_mi = (cu_mi.0 - mi_r, cu_mi.1 - mi_c);
1481 let inherit_tx_type =
1482 covering_leaf_tx_type(leaf_tx_types, rel_mi).or(Some(luma_tx_type));
1483 let cu_grid = read_inter_plane_rect(
1484 dec,
1485 cdfs,
1486 set,
1487 (uw, uh),
1488 cside,
1489 plane_idx,
1490 cu_around[plane_idx],
1491 0,
1492 y,
1493 u,
1494 v,
1495 cu_x,
1496 cu_y,
1497 cu_pred,
1498 inherit_tx_type,
1499 // `get_txb_ctx`: plus 10 when the plane block is bigger
1500 // than the transform -- the same offset-3 convention
1501 // `read_inter_rect_chroma` passes on this arm.
1502 Some(3),
1503 fctx,
1504 )?
1505 .0;
1506 // Immediately, so the next unit of this block reads this one's
1507 // coefficient context (libaom updates the chroma above/left
1508 // contexts per unit).
1509 neighbours.record_mi_chroma(cu_mi, span_x, span_y, plane_idx, &cu_grid);
1510 let dst = &mut assembled[plane_idx - 1];
1511 for rr in 0..uh {
1512 let start = (cu_row * uh + rr) * cside + cu_col * uw;
1513 dst[start..start + uw].copy_from_slice(&cu_grid[rr * uw..][..uw]);
1514 }
1515 }
1516 }
1517 }
1518 let [ug, vg] = assembled;
1519 Ok((Grid::Own(ug), Grid::Own(vg)))
1520}
1521
1522// Signature mirrors the spec's per-call inputs; a parameter struct would only move them.
1523#[allow(clippy::too_many_arguments)]
1524fn predict_intrabc_window(
1525 plane: &PlaneBuf<'_>,
1526 px: usize,
1527 py: usize,
1528 w: usize,
1529 h: usize,
1530 dv_col: i32,
1531 dv_row: i32,
1532 luma: bool,
1533 stride: usize,
1534 fctx: &crate::decode::FrameCtx,
1535) -> Vec<u16> {
1536 let mut dense = vec![0u16; w * h];
1537 mc::predict_with_filter(
1538 &plane.data,
1539 plane.width,
1540 plane.true_width,
1541 plane.true_height,
1542 mv_to_q4(px, dv_col, if luma { 0 } else { ss_x(fctx) }),
1543 mv_to_q4(py, dv_row, if luma { 0 } else { ss_y(fctx) }),
1544 w,
1545 h,
1546 mc::InterpFilterKind::Bilinear,
1547 &mut dense,
1548 fctx,
1549 );
1550 let mut laid = vec![0u16; stride * stride];
1551 for row in 0..h {
1552 laid[row * stride..][..w].copy_from_slice(&dense[row * w..][..w]);
1553 }
1554 laid
1555}
1556
1557pub(super) struct ReducedTxRestore<'a> {
1558 pub(super) fctx: &'a crate::decode::FrameCtx,
1559 pub(super) saved_reduced: bool,
1560 pub(super) saved_tx: bool,
1561}
1562impl Drop for ReducedTxRestore<'_> {
1563 fn drop(&mut self) {
1564 self.fctx
1565 .reduced_tx_set_inter
1566 .with(|c| c.set(self.saved_reduced));
1567 self.fctx.tx_select_inter.with(|c| c.set(self.saved_tx));
1568 }
1569}
1570
1571/// Reconstruction of one intrabc 16x4 / 4x16 strip (lane-av1-rect14).
1572///
1573/// A 1:4 strip is a PAIR. Both children share one chroma block, and only the
1574/// odd-mi member codes it (`is_chroma_reference`, `av1_common_int.h:1454`:
1575/// the bottom strip of a `HORZ_4`, the right strip of a `VERT_4`). The chroma
1576/// plane block is `ss_size_lookup[BLOCK_16X4][1][1] == BLOCK_8X4` (and
1577/// `BLOCK_4X8` for `VERT_4`) at the PAIR origin -- `setup_pred_plane`'s
1578/// `mi_row -= 1` when the block is one mi tall on an odd row. Luma is this
1579/// strip's own footprint, copied from this strip's DV. The block is
1580/// `is_inter_block`, so the residual uses the INTER sets and chroma inherits
1581/// the luma unit's coded `tx_type`.
1582///
1583/// Not [`decode_intrabc_rect`]: that helper (lane-av1-intrabc, not on this
1584/// tree) predicts chroma at `bw/2 x bh/2` of the strip itself. At 16x4 that
1585/// is an 8x2 half-pair at the odd strip -- wrong size, wrong origin, and it
1586/// would code chroma on every strip.
1587#[allow(clippy::too_many_arguments)]
1588pub(super) fn decode_rect4_16_intrabc(
1589 dec: &mut SymbolDecoder,
1590 cdfs: &mut Cdfs,
1591 neighbours: &mut Neighbours,
1592 lmi: (usize, usize),
1593 horz: bool,
1594 has_chroma: bool,
1595 skip: bool,
1596 (dv_row, dv_col): (i32, i32),
1597 y: &mut PlaneBuf<'static>,
1598 u: &mut PlaneBuf<'static>,
1599 v: &mut PlaneBuf<'static>,
1600 base_q_idx: u8,
1601 tx_select: bool,
1602 reduced_tx_set: bool,
1603 fctx: &crate::decode::FrameCtx,
1604) -> Result<(usize, Option<usize>, (usize, usize))> {
1605 let _ = base_q_idx;
1606 hit!(RECT4_16_INTRABC_HITS);
1607 let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };
1608 let (mi_w, mi_h) = (bw / MI, bh / MI);
1609 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
1610 let side = bw.max(bh);
1611 // `rect_inter_luma_set` reads the frame cell. A key frame's tile decoder
1612 // publishes `reduced_tx_set` into it; set it here too so a caller that
1613 // passed the bit explicitly cannot disagree with the set we read.
1614 let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
1615 fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set));
1616 let restored = scopeguard_reduced(fctx, saved_reduced);
1617
1618 let mut pred_y_dense = vec![0u16; bw * bh];
1619 mc::predict_with_filter(
1620 &y.data,
1621 y.width,
1622 y.true_width,
1623 y.true_height,
1624 mv_to_q4(px, dv_col, 0),
1625 mv_to_q4(py, dv_row, 0),
1626 bw,
1627 bh,
1628 mc::InterpFilterKind::Bilinear,
1629 &mut pred_y_dense,
1630 fctx,
1631 );
1632 let mut pred_y = vec![0u16; side * side];
1633 for row in 0..bh {
1634 pred_y[row * side..][..bw].copy_from_slice(&pred_y_dense[row * bw..][..bw]);
1635 }
1636
1637 // lane-av1444rect r2 (the class this lane named, second instance): the
1638 // pair geometry below is the 4:2:0 one and was applied at every `ss`. At
1639 // ss (0,0) `is_chroma_reference` (av1_common_int.h:1454) is
1640 // unconditionally true -- the strip is its own chroma reference, there is
1641 // no pair, and its chroma plane block IS the strip: 16x4 (HORZ_4) / 4x16
1642 // (VERT_4) at the strip's own origin, with its coefficient context read
1643 // over that same extent. The old constants instead predicted and coded an
1644 // 8x4 block at `(lmi - 1) * MI / 2`, a quarter of the position.
1645 //
1646 // MEASURED on a `testsrc2` 640x480 `--tune-content=screen --enable-intrabc=1
1647 // --enable-palette=1 --cq-level=60 --min-partition-size=4
1648 // --max-partition-size=64 --sb-size=64 --profile=1` stream (1016 B, 17
1649 // intrabc 16x4 strips at ss (0,0)): 455240 of 921600 samples wrong, the
1650 // entropy fork at read 11750 (`decodetxb.c:158`, the chroma `txb_skip`).
1651 // `--enable-intrabc=0` at the same settings is byte-exact, and the 4:2:0
1652 // twin of the same recipe is byte-exact.
1653 //
1654 // 4:2:0 alone keeps every constant below verbatim: a 1:4 strip's chroma
1655 // plane block is 4:2:0's PAIR (the block above / beside it), because at
1656 // ss (1,1) the strip's 8x2 chroma lies INSIDE that neighbour's chroma.
1657 //
1658 // lane-av1422luma: at ss (1,0) that containment is gone -- 4:2:2 subsamples
1659 // x only, so the strip's chroma is 8x4 (full height) at the STRIP'S OWN
1660 // origin, and libaom's own clause agrees: `is_chroma_reference`
1661 // (av1_common_int.h:1454) ends in `|| !subsampling_y`, which answers TRUE
1662 // for every block at ss_y 0. Reading the strip's chroma at the 4:2:0 pair
1663 // origin instead puts the unit one mi row high: on `s422_416x250_10b`
1664 // (416x250 10-bit, sha256 d6aa7f45...) that is the V/U pair's `txb_skip`
1665 // read at mi (51,84) -- ctx 2 where the oracle reads 8, `all_zero` decoded
1666 // as 1 instead of 0, and the frame desyncs from there (luma included).
1667 // The origin half is `lane/av1422seed`'s unlanded hunk, reproduced here so
1668 // the arm is measurable whole; the gather and the publication extents
1669 // below are this lane's. VERT_4 stays on the pair: `ss_size_lookup
1670 // [BLOCK_4X16][1][0]` is BLOCK_INVALID at 4:2:2, so only HORZ reaches it.
1671 let own444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
1672 let own422 = ss_x(fctx) == 1 && ss_y(fctx) == 0 && horz;
1673 if own422 && has_chroma {
1674 hit!(INTRABC_RECT4_OWN_CHROMA422_HITS);
1675 }
1676 // One predicate for "this strip IS its own chroma reference": the strip's
1677 // own mi position, its own luma extent, and per-axis subsampled sizes.
1678 let own_chroma = own444 || own422;
1679 if ss_x(fctx) == 0 && ss_y(fctx) == 0 && has_chroma {
1680 hit!(INTRABC_RECT4_OWN_CHROMA444_HITS);
1681 }
1682 let (pw, ph) = if own444 {
1683 (bw, bh)
1684 } else if horz {
1685 (16usize, 8usize)
1686 } else {
1687 (8, 16)
1688 };
1689 let (cw, ch) = if own_chroma {
1690 (bw >> ss_x(fctx), bh >> ss_y(fctx))
1691 } else {
1692 // lane/av1422rect4dead: this arm is the 4:2:0 PAIR geometry, and at ss
1693 // (1, 0) it cannot run. The sole caller is `decode_rect4_16_strip`,
1694 // reached only through the two 16x16-level 1:4 arms; both sit under
1695 // `refuse_invalid_subsize((16, 16), part16)`, and at ss (1, 0) that
1696 // guard refuses exactly the shape that would land here:
1697 // `partition_subsize_dims((16, 16), PARTITION_VERT_4) == (4, 16)`,
1698 // which is in `PLANE_BLOCK_INVALID_422`. The surviving 16x4 HORZ_4
1699 // strip takes `own422` above, not this arm. At ss (1, 1) the arm is
1700 // live and correct (the pair IS the geometry), and at ss (0, 0)
1701 // `own444` already won, so this assert never fires there. The
1702 // assertion is the closure the repo rule asks for; the census test
1703 // `decode_rect4_16_intrabc_else_arm_stays_closed_at_422` below reds if
1704 // either this assert or its guard chain is removed.
1705 assert!(
1706 !(ss_x(fctx) == 1 && ss_y(fctx) == 0),
1707 "decode_rect4_16_intrabc else arm entered at ss (1, 0) with a 4x16 \
1708 VERT_4 strip: (4, 16) is BLOCK_INVALID at 4:2:2 and the 16x16-level \
1709 refuse_invalid_subsize above both callers must have refused this \
1710 before the dispatch -- the closure is gone"
1711 );
1712 (pw / 2, ph / 2)
1713 };
1714 let pair_mi = if has_chroma {
1715 if own_chroma {
1716 lmi
1717 } else if horz {
1718 (lmi.0 - 1, lmi.1)
1719 } else {
1720 (lmi.0, lmi.1 - 1)
1721 }
1722 } else {
1723 lmi
1724 };
1725 let (cpx, cpy) = if has_chroma {
1726 if own_chroma {
1727 (px >> ss_x(fctx), py >> ss_y(fctx))
1728 } else {
1729 (pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)
1730 }
1731 } else {
1732 (0, 0)
1733 };
1734 let cside = cw.max(ch);
1735 let (pred_u, pred_v) = if has_chroma {
1736 let mut ud = vec![0u16; cw * ch];
1737 mc::predict_with_filter(
1738 &u.data,
1739 u.width,
1740 u.true_width,
1741 u.true_height,
1742 mv_to_q4(cpx, dv_col, ss_x(fctx)),
1743 mv_to_q4(cpy, dv_row, ss_y(fctx)),
1744 cw,
1745 ch,
1746 mc::InterpFilterKind::Bilinear,
1747 &mut ud,
1748 fctx,
1749 );
1750 let mut us = vec![0u16; cside * cside];
1751 for row in 0..ch {
1752 us[row * cside..][..cw].copy_from_slice(&ud[row * cw..][..cw]);
1753 }
1754 let mut vd = vec![0u16; cw * ch];
1755 mc::predict_with_filter(
1756 &v.data,
1757 v.width,
1758 v.true_width,
1759 v.true_height,
1760 mv_to_q4(cpx, dv_col, ss_x(fctx)),
1761 mv_to_q4(cpy, dv_row, ss_y(fctx)),
1762 cw,
1763 ch,
1764 mc::InterpFilterKind::Bilinear,
1765 &mut vd,
1766 fctx,
1767 );
1768 let mut vs = vec![0u16; cside * cside];
1769 for row in 0..ch {
1770 vs[row * cside..][..cw].copy_from_slice(&vd[row * cw..][..cw]);
1771 }
1772 (us, vs)
1773 } else {
1774 (Vec::new(), Vec::new())
1775 };
1776
1777 // Key-frame `tx_select` is the parameter. `tx_select_inter` is forced
1778 // false for a key frame, so `read_block_tx_size_rect` would skip the
1779 // symbol; read it here against the parameter the intra path already uses.
1780 // A skipped intrabc block predicts the whole footprint once and codes
1781 // no residual (`decode_token_recon_block`'s inter branch). Lossless
1782 // still forces TX_4X4 when the block is coded.
1783 let leaves = if skip || (!lossless(fctx) && !tx_select) {
1784 None
1785 } else if lossless(fctx) {
1786 let mut leaves = Vec::new();
1787 for row in 0..bh / MI {
1788 for col in 0..bw / MI {
1789 leaves.push((row, col, 4usize, 4usize));
1790 }
1791 }
1792 // libaom's `else` branch (`!xd->lossless` fails the var-tx
1793 // condition): `set_txfm_ctxs(TX_4X4, ..)` over the block's own
1794 // width/height. Same reason as `read_block_tx_size_rect`'s arm --
1795 // it is what makes this body's `fill_lf_grid_rect_after_vartx`
1796 // suppression sound.
1797 txfm_partition_update_rect(neighbours, lmi, (4, 4), (bw, bh));
1798 Some(leaves)
1799 } else {
1800 let ctx = txfm_partition_ctx_rect(
1801 neighbours.above_txfm[lmi.1],
1802 neighbours.left_txfm[lmi.0],
1803 side,
1804 bw,
1805 bh,
1806 );
1807 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
1808 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
1809 let (rng, _) = dec.debug_state();
1810 eprintln!(
1811 "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} rng={rng}",
1812 lmi.0,
1813 lmi.1,
1814 u8::from(split)
1815 );
1816 }
1817 if !split {
1818 None
1819 } else {
1820 let (sub_w, sub_h) = sub_tx_size_map(bw, bh);
1821 let mi_cols = 2 * y.true_width.div_ceil(8);
1822 let mi_rows = 2 * y.true_height.div_ceil(8);
1823 let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(lmi.1));
1824 let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(lmi.0));
1825 let mut out = Vec::new();
1826 for row in (0..bh / MI).step_by(sub_h / MI) {
1827 for col in (0..bw / MI).step_by(sub_w / MI) {
1828 read_var_tx_size(
1829 dec,
1830 cdfs,
1831 neighbours,
1832 lmi,
1833 side,
1834 (max_w_mi, max_h_mi),
1835 (sub_w, sub_h),
1836 1,
1837 row,
1838 col,
1839 &mut out,
1840 );
1841 }
1842 }
1843 Some(out)
1844 }
1845 };
1846 let (tx_w, tx_h) = leaves
1847 .as_ref()
1848 .and_then(|ls| ls.first())
1849 .map_or((bw, bh), |l| (l.2, l.3));
1850
1851 let mut luma_tx_type = TxType::DctDct;
1852 let luma_grid;
1853 let mut u_grid = Grid::Zero(cw * ch);
1854 let mut v_grid = Grid::Zero(cw * ch);
1855 let chroma_stamped_per_unit;
1856
1857 if skip {
1858 push_mc_rect(
1859 y,
1860 u,
1861 v,
1862 0,
1863 px,
1864 py,
1865 side,
1866 bw,
1867 bh,
1868 Pred::Inline(&pred_y, side),
1869 &ZERO_RESIDUAL[..side * bh],
1870 fctx,
1871 );
1872 luma_grid = Grid::Zero(bw * bh);
1873 if has_chroma {
1874 push_mc_rect(
1875 y,
1876 u,
1877 v,
1878 1,
1879 cpx,
1880 cpy,
1881 cside,
1882 cw,
1883 ch,
1884 Pred::Inline(&pred_u, cside),
1885 &ZERO_RESIDUAL[..cside * ch],
1886 fctx,
1887 );
1888 push_mc_rect(
1889 y,
1890 u,
1891 v,
1892 2,
1893 cpx,
1894 cpy,
1895 cside,
1896 cw,
1897 ch,
1898 Pred::Inline(&pred_v, cside),
1899 &ZERO_RESIDUAL[..cside * ch],
1900 fctx,
1901 );
1902 }
1903 chroma_stamped_per_unit = false;
1904 } else if let Some(ls) = leaves.as_ref() {
1905 if lossless(fctx) {
1906 for &(row, col, _tw, _th) in ls {
1907 let tu_mi = (lmi.0 + row, lmi.1 + col);
1908 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
1909 let tu_pred = Pred::Inline(&pred_y, side).offset(row * MI * side + col * MI);
1910 let (g, _) = read_inter_plane(
1911 dec,
1912 cdfs,
1913 if reduced_tx_set {
1914 TxbSet::Luma4Inter
1915 } else {
1916 TxbSet::Luma4InterSet1
1917 },
1918 default_scan(4),
1919 0,
1920 neighbours.around_mi(tu_mi, 4)[0],
1921 0,
1922 y,
1923 u,
1924 v,
1925 tu_px,
1926 tu_py,
1927 4,
1928 base_q_idx,
1929 tu_pred,
1930 None,
1931 Some(neighbours.luma_skip_ctx(tu_mi, 1)),
1932 fctx,
1933 )?;
1934 neighbours.record_mi_luma_rect(tu_mi, 4, 4, &g);
1935 }
1936 } else {
1937 for (idx, &(row, col, tw, th)) in ls.iter().enumerate() {
1938 let tu_mi = (lmi.0 + row, lmi.1 + col);
1939 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
1940 let tu_pred = Pred::Inline(&pred_y, side).offset(row * MI * side + col * MI);
1941 let (g, tt) = if tw == th {
1942 read_inter_plane(
1943 dec,
1944 cdfs,
1945 inter_txbset_for(tw, reduced_tx_set),
1946 default_scan(tw.min(32)),
1947 0,
1948 neighbours.around_mi(tu_mi, tw)[0],
1949 0,
1950 y,
1951 u,
1952 v,
1953 tu_px,
1954 tu_py,
1955 tw,
1956 base_q_idx,
1957 tu_pred,
1958 None,
1959 Some(neighbours.luma_skip_ctx(tu_mi, tw / MI)),
1960 fctx,
1961 )?
1962 } else {
1963 read_inter_plane_rect(
1964 dec,
1965 cdfs,
1966 rect_inter_luma_set(tw, th, fctx)?,
1967 (tw, th),
1968 side,
1969 0,
1970 neighbours.around_mi_rect(tu_mi, tw, th)[0],
1971 0,
1972 y,
1973 u,
1974 v,
1975 tu_px,
1976 tu_py,
1977 tu_pred,
1978 None,
1979 Some(neighbours.luma_skip_ctx_rect(tu_mi, tw / MI, th / MI)),
1980 fctx,
1981 )?
1982 };
1983 if idx == 0 {
1984 luma_tx_type = tt;
1985 }
1986 neighbours.record_mi_luma_rect(tu_mi, tw, th, &g);
1987 }
1988 }
1989 luma_grid = Grid::Zero(bw * bh);
1990 chroma_stamped_per_unit = has_chroma && lossless(fctx);
1991 if has_chroma && lossless(fctx) {
1992 let (mut uo, mut vo) = (Vec::new(), Vec::new());
1993 read_inter_chroma_lossless(
1994 y,
1995 u,
1996 v,
1997 dec,
1998 cdfs,
1999 neighbours,
2000 Pred::Inline(&pred_u, cside),
2001 Pred::Inline(&pred_v, cside),
2002 pair_mi,
2003 (cpx, cpy),
2004 (0, 0),
2005 (cw, ch),
2006 (cw, ch),
2007 cside,
2008 0,
2009 base_q_idx,
2010 &mut uo,
2011 &mut vo,
2012 fctx,
2013 )?;
2014 u_grid = if uo.is_empty() {
2015 Grid::Zero(cw * ch)
2016 } else {
2017 Grid::Own(uo)
2018 };
2019 v_grid = if vo.is_empty() {
2020 Grid::Zero(cw * ch)
2021 } else {
2022 Grid::Own(vo)
2023 };
2024 } else if has_chroma {
2025 // lane-av1422luma: the own-chroma route reads its context over its
2026 // OWN extent; at ss (1,0) it additionally goes through the
2027 // every-second-column gather (one chroma 4-px column spans two
2028 // luma mi columns, so the per-mi gather would count each column's
2029 // whole-unit dc sign twice and OR in cells the unit does not
2030 // cover) -- the same choice the `decode_rect4_16` chroma arm
2031 // makes at `decode.rs:19577`. 4:4:4 keeps the per-mi gather: at
2032 // ss_x 0 a chroma column IS a luma mi column, so sampling would
2033 // halve its own above span.
2034 let (gmi, gw, gh) = if own_chroma {
2035 (lmi, bw, bh)
2036 } else {
2037 (pair_mi, pw, ph)
2038 };
2039 let around = if own422 {
2040 neighbours.around_mi_422_chroma(gmi, gw, gh)
2041 } else {
2042 neighbours.around_mi_rect(gmi, gw, gh)
2043 };
2044 let (ug, _) = read_inter_plane_rect(
2045 dec,
2046 cdfs,
2047 rect_inter_chroma_set(cw, ch)?,
2048 (cw, ch),
2049 cside,
2050 1,
2051 around[1],
2052 0,
2053 y,
2054 u,
2055 v,
2056 cpx,
2057 cpy,
2058 Pred::Inline(&pred_u, cside),
2059 Some(luma_tx_type),
2060 None,
2061 fctx,
2062 )?;
2063 u_grid = ug;
2064 let (vg, _) = read_inter_plane_rect(
2065 dec,
2066 cdfs,
2067 rect_inter_chroma_set(cw, ch)?,
2068 (cw, ch),
2069 cside,
2070 2,
2071 around[2],
2072 0,
2073 y,
2074 u,
2075 v,
2076 cpx,
2077 cpy,
2078 Pred::Inline(&pred_v, cside),
2079 Some(luma_tx_type),
2080 None,
2081 fctx,
2082 )?;
2083 v_grid = vg;
2084 }
2085 } else {
2086 let around = neighbours.around_mi_rect(lmi, bw, bh);
2087 let (g, tt) = read_inter_plane_rect(
2088 dec,
2089 cdfs,
2090 rect_inter_luma_set(bw, bh, fctx)?,
2091 (bw, bh),
2092 side,
2093 0,
2094 around[0],
2095 0,
2096 y,
2097 u,
2098 v,
2099 px,
2100 py,
2101 Pred::Inline(&pred_y, side),
2102 None,
2103 None,
2104 fctx,
2105 )?;
2106 luma_tx_type = tt;
2107 luma_grid = g;
2108 chroma_stamped_per_unit = false;
2109 if has_chroma {
2110 // lane-av1422luma: as the lossless twin above -- own extent, and
2111 // the sampled gather at 4:2:2 only.
2112 let (gmi, gw, gh) = if own_chroma {
2113 (lmi, bw, bh)
2114 } else {
2115 (pair_mi, pw, ph)
2116 };
2117 let around = if own422 {
2118 neighbours.around_mi_422_chroma(gmi, gw, gh)
2119 } else {
2120 neighbours.around_mi_rect(gmi, gw, gh)
2121 };
2122 let (ug, _) = read_inter_plane_rect(
2123 dec,
2124 cdfs,
2125 rect_inter_chroma_set(cw, ch)?,
2126 (cw, ch),
2127 cside,
2128 1,
2129 around[1],
2130 0,
2131 y,
2132 u,
2133 v,
2134 cpx,
2135 cpy,
2136 Pred::Inline(&pred_u, cside),
2137 Some(luma_tx_type),
2138 None,
2139 fctx,
2140 )?;
2141 u_grid = ug;
2142 let (vg, _) = read_inter_plane_rect(
2143 dec,
2144 cdfs,
2145 rect_inter_chroma_set(cw, ch)?,
2146 (cw, ch),
2147 cside,
2148 2,
2149 around[2],
2150 0,
2151 y,
2152 u,
2153 v,
2154 cpx,
2155 cpy,
2156 Pred::Inline(&pred_v, cside),
2157 Some(luma_tx_type),
2158 None,
2159 fctx,
2160 )?;
2161 v_grid = vg;
2162 }
2163 }
2164 drop(restored);
2165
2166 if leaves.is_none() {
2167 neighbours.record_mi_luma_rect(lmi, bw, bh, &luma_grid);
2168 }
2169 neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, DC_PRED);
2170 neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip);
2171 // lane-av1oddheightfork3: this body reads its own var-tx tree inline
2172 // (`read_var_tx_size` per child), so the bands are per-leaf already; the
2173 // whole-footprint publish overwrote them with the block's own size.
2174 neighbours.fill_lf_grid_rect_after_vartx(lmi, mi_w, mi_h, tx_w as u8, tx_h as u8, 0, fctx);
2175 for cell in 0..mi_w {
2176 if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) {
2177 *slot = bw as u8;
2178 }
2179 }
2180 for cell in 0..mi_h {
2181 if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) {
2182 *slot = bh as u8;
2183 }
2184 }
2185 let mut last_uv = None;
2186 if has_chroma {
2187 hit!(RECT4_16_CHROMA_HITS);
2188 // lane-av1422luma: the uv-mode publication and the left/above skip
2189 // state below are the STRIP's own at 4:2:2 / 4:4:4 -- publishing the
2190 // pair extent (one mi row off, `ph`/`pw`) is what the NEXT block's
2191 // chroma skip context then reads.
2192 let (rmi, rw, rh) = if own_chroma {
2193 (lmi, bw, bh)
2194 } else {
2195 (pair_mi, pw, ph)
2196 };
2197 neighbours.record_uv_mode_mi(rmi.0, rmi.1, rw / MI, rh / MI, DC_PRED);
2198 if !chroma_stamped_per_unit {
2199 let u_state = neighbour_state(&u_grid);
2200 let v_state = neighbour_state(&v_grid);
2201 let round_up_even = |n: usize| n.div_ceil(2) * 2;
2202 let bound_h = round_up_even(neighbours.mi_rows);
2203 let bound_w = round_up_even(neighbours.mi_cols);
2204 for cell in 0..(rh / MI) {
2205 if rmi.0 + cell < bound_h
2206 && let Some(slot) = neighbours.left.get_mut(rmi.0 + cell)
2207 {
2208 slot[1] = u_state;
2209 slot[2] = v_state;
2210 }
2211 }
2212 for cell in 0..(rw / MI) {
2213 if rmi.1 + cell < bound_w
2214 && let Some(slot) = neighbours.above.get_mut(rmi.1 + cell)
2215 {
2216 slot[1] = u_state;
2217 slot[2] = v_state;
2218 }
2219 }
2220 }
2221 last_uv = Some(DC_PRED);
2222 }
2223 if horz {
2224 hit!(RECT4_16_HORZ_HITS);
2225 } else {
2226 hit!(RECT4_16_VERT_HITS);
2227 }
2228 record_strip_palette(neighbours, lmi, bw, bh, 0, [0u16; 8], 0, [0u16; 8]);
2229 if leaves.is_none() {
2230 // Skip and TX_MODE_LARGEST publish the block size (`set_txfm_ctxs`
2231 // with `skip && is_inter`, or the unsplit unit). A split tree already
2232 // published per leaf inside `read_var_tx_size`.
2233 txfm_partition_update_rect(neighbours, lmi, (tx_w, tx_h), (bw, bh));
2234 }
2235 record_intrabc_mi_rect(
2236 lmi.0,
2237 lmi.1,
2238 mi_w,
2239 mi_h,
2240 Some((dv_row, dv_col)),
2241 neighbours,
2242 fctx,
2243 );
2244 Ok((DC_PRED, last_uv, (tx_w, tx_h)))
2245}
2246
2247/// Restores `reduced_tx_set_inter` when the intrabc pair reader returns,
2248/// including through `?`.
2249pub(super) struct ReducedRestore<'a> {
2250 pub(super) fctx: &'a crate::decode::FrameCtx,
2251 pub(super) saved: bool,
2252}
2253impl Drop for ReducedRestore<'_> {
2254 fn drop(&mut self) {
2255 self.fctx.reduced_tx_set_inter.with(|c| c.set(self.saved));
2256 }
2257}
2258fn scopeguard_reduced(fctx: &crate::decode::FrameCtx, saved: bool) -> ReducedRestore<'_> {
2259 ReducedRestore { fctx, saved }
2260}
2261
2262#[allow(clippy::too_many_arguments)]
2263pub(super) fn decode_rect4_16_strip(
2264 dec: &mut SymbolDecoder,
2265 cdfs: &mut Cdfs,
2266 neighbours: &mut Neighbours,
2267 lmi: (usize, usize),
2268 horz: bool,
2269 has_chroma: bool,
2270 prev: Option<((usize, usize), usize)>,
2271 y: &mut PlaneBuf<'static>,
2272 u: &mut PlaneBuf<'static>,
2273 v: &mut PlaneBuf<'static>,
2274 enable_filter_intra: bool,
2275 allow_screen_content_tools: bool,
2276 base_q_idx: u8,
2277 tx_select: bool,
2278 reduced_tx_set: bool,
2279 fctx: &crate::decode::FrameCtx,
2280) -> Result<(usize, Option<usize>, (usize, usize))> {
2281 let (r, c) = (lmi.0 / (SUB / MI), lmi.1 / (SUB / MI));
2282 let (bw, bh) = if horz { (16usize, 4usize) } else { (4, 16) };
2283 let (mi_w, mi_h) = (bw / MI, bh / MI);
2284 let scan: &[u16] = if horz { &SCAN_16X4 } else { &SCAN_4X16 };
2285 let mut last_uv_mode: Option<usize> = None;
2286 // `decode_block_rect4`'s own neighbour rule: the coarse 16-px cell
2287 // aliases all four strips onto one entry, so the mi-exact map wins and
2288 // the previous strip stands in on the split axis.
2289 let mut above_mode = neighbours.above_mode[c];
2290 let mut left_mode = neighbours.left_mode[r];
2291 if let Some(((pr, pc), pmode)) = prev {
2292 if pc == lmi.1 && lmi.0 == pr + mi_h {
2293 above_mode = pmode;
2294 } else if pr == lmi.0 && lmi.1 == pc + mi_w {
2295 left_mode = pmode;
2296 }
2297 }
2298 let (above_mode, left_mode) =
2299 neighbours.modes_above_left_mi(lmi.0, lmi.1, (above_mode, left_mode));
2300 // lane-kf900 r4: the strip's real palette ctx + colour cache (see
2301 // [`decode_block_rect4`]); `None`/`&[]` here read `palette_y_mode`
2302 // off CDF row 0 and every cache hit off an empty cache.
2303 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(lmi);
2304 let palette_uv_cache = neighbours.palette_uv_cache_mi(lmi);
2305 let (
2306 skip,
2307 mode,
2308 angle_delta_y,
2309 uv_mode,
2310 angle_delta_uv,
2311 alpha,
2312 filter_intra,
2313 palette_y,
2314 palette_uv,
2315 intrabc,
2316 ) = read_intra_mode_rect(
2317 dec,
2318 cdfs,
2319 above_mode,
2320 left_mode,
2321 true,
2322 has_chroma,
2323 bw,
2324 bh,
2325 enable_filter_intra,
2326 neighbours.skip_txfm_ctx(lmi.0, lmi.1),
2327 allow_screen_content_tools,
2328 Some((palette_ctx, &palette_cache)),
2329 &palette_uv_cache,
2330 lmi.0,
2331 lmi.1,
2332 fctx,
2333 )?;
2334 if let Some(dv) = intrabc {
2335 return decode_rect4_16_intrabc(
2336 dec,
2337 cdfs,
2338 neighbours,
2339 lmi,
2340 horz,
2341 has_chroma,
2342 skip,
2343 dv,
2344 y,
2345 u,
2346 v,
2347 base_q_idx,
2348 tx_select,
2349 reduced_tx_set,
2350 fctx,
2351 );
2352 }
2353 if palette_y.is_some() || palette_uv.is_some() {
2354 hit!(RECT4_PALETTE_HITS);
2355 }
2356 // The colour-index map through the base colours IS the prediction.
2357 // Chroma's map is the PAIR's 8x4 (4x8) block, matching the one
2358 // chroma transform this closing strip codes.
2359 let palette_y_buf: Option<Vec<u16>> = palette_y
2360 .as_ref()
2361 .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect());
2362 let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| {
2363 (
2364 p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
2365 p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
2366 )
2367 });
2368 let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode);
2369 if smooth_neighbor {
2370 hit!(SMOOTH_LUMA_HITS);
2371 }
2372 if filter_intra.is_some() {
2373 hit!(FILTER_INTRA_RECT_HITS);
2374 }
2375 // `bsize_to_tx_size_cat(BLOCK_16X4)`: `max_txsize_rect_lookup` is
2376 // TX_16X4 and `sub_tx_size_map` reaches TX_4X4 in two steps, so the
2377 // depth symbol is the 3-symbol `tx_size_cat1` -- not the 2-symbol
2378 // `cat0` a 4x8 leaf reads nor the `cat2` a 32x8 strip does.
2379 // lane-av1mixloss: the lossless-segment early return
2380 // (`decodeframe.c:1203`) precedes `TX_MODE_SELECT`, so a
2381 // lossless-segment strip codes no depth symbol here either (class
2382 // sweep of the sub8 leaf's fix).
2383 let depth = if tx_select && !lossless(fctx) {
2384 // lane-av1txbands: every frame reads the real `TXFM_CONTEXT` bands
2385 // (`get_tx_size_context`, libaom `pred_common.h:342`).
2386 let ctx = tx_size_context_txfm_rect(neighbours, lmi, bw, bh, fctx);
2387 let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]);
2388 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
2389 eprintln!(
2390 "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}",
2391 lmi.0,
2392 lmi.1,
2393 dec.debug_state().0
2394 );
2395 }
2396 d
2397 } else {
2398 0
2399 };
2400 if depth != 0 {
2401 hit!(TX_DEPTH_HITS);
2402 hit!(RECT4_16_SPLIT_HITS);
2403 }
2404 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
2405 let (px, py) = (lmi.1 * MI, lmi.0 * MI);
2406 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
2407 neighbours.record_mode_mi(lmi.0, lmi.1, mi_w, mi_h, mode);
2408 if depth != 0 || lossless(fctx) {
2409 // [`decode_rect_split`]'s per-unit walk, inlined because the
2410 // CHROMA of this shape belongs to the strip's 4:2:0 pair, not to
2411 // the strip (that function codes one chroma transform per block).
2412 // depth 1 is the 2:1 rect unit TX_8X4/TX_4X8
2413 // (`sub_tx_size_map[TX_16X4]`), depth 2 the square TX_4X4; each
2414 // unit predicts off the units before it in raster order.
2415 let rect_unit = tx_w != tx_h;
2416 let zero_tu = vec![0i32; tx_w * tx_h];
2417 for tu_row in 0..bh / tx_h {
2418 for tu_col in 0..bw / tx_w {
2419 let tu_mi = (lmi.0 + tu_row * (tx_h / MI), lmi.1 + tu_col * (tx_w / MI));
2420 let (tu_px, tu_py) = (px + tu_col * tx_w, py + tu_row * tx_h);
2421 let tu_reach =
2422 Reach::of_tu(bw, bh, tu_col * tx_w, tu_row * tx_h, tx_w, tx_h, reach);
2423 if let Some(b) = &palette_y_buf {
2424 let tu_buf: Vec<u16> = (0..tx_h)
2425 .flat_map(|i| {
2426 let base = (tu_row * tx_h + i) * bw + tu_col * tx_w;
2427 b[base..base + tx_w].iter().copied()
2428 })
2429 .collect();
2430 set_palette_pred(tu_buf, fctx);
2431 }
2432 if skip {
2433 push_intra_rect(
2434 y,
2435 u,
2436 v,
2437 0,
2438 tu_px,
2439 tu_py,
2440 tx_w,
2441 tx_h,
2442 mode,
2443 angle_delta_y,
2444 tu_reach,
2445 &zero_tu,
2446 None,
2447 filter_intra,
2448 smooth_neighbor,
2449 fctx,
2450 );
2451 neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &zero_tu);
2452 } else if rect_unit {
2453 // `get_txsize_entropy_ctx(TX_8X4)` is the 8x8 class with
2454 // 32 coded positions and the `TX_4X4` `tx_type` row:
2455 // exactly [`TxbSet::LumaRect4x8`].
2456 let tu_around = neighbours.around_mi_rect(tu_mi, tx_w, tx_h)[0];
2457 let tu_skip_ctx = neighbours.luma_skip_ctx_rect(tu_mi, tx_w / MI, tx_h / MI);
2458 let set = if reduced_tx_set {
2459 TxbSet::LumaRect4x8
2460 } else {
2461 TxbSet::LumaRect4x8Set1
2462 };
2463 let tu_scan: &[u16] = if tx_w > tx_h { &SCAN_8X4 } else { &SCAN_4X8 };
2464 let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra));
2465 let (tu_grid, tu_tx_type) = read_coeffs_rect(
2466 dec,
2467 &mut coding,
2468 tu_scan,
2469 tx_w,
2470 tx_h,
2471 tu_skip_ctx,
2472 dc_sign_ctx(tu_around.2),
2473 TxType::DctDct,
2474 0,
2475 )?;
2476 let residual = dequant_and_inverse_typed_wh(
2477 &tu_grid,
2478 tx_w,
2479 tx_h,
2480 crate::decode::bit_depth(fctx),
2481 block_q_idx(fctx),
2482 plane_q_delta(0, fctx).0,
2483 plane_q_delta(0, fctx).1,
2484 tu_tx_type,
2485 block_iqmatrix(fctx, 0, tx_w, tx_h, tu_tx_type),
2486 );
2487 push_intra_rect(
2488 y,
2489 u,
2490 v,
2491 0,
2492 tu_px,
2493 tu_py,
2494 tx_w,
2495 tx_h,
2496 mode,
2497 angle_delta_y,
2498 tu_reach,
2499 &residual,
2500 None,
2501 filter_intra,
2502 smooth_neighbor,
2503 fctx,
2504 );
2505 if tu_grid.iter().any(|&l| l != 0) {
2506 hit!(RECT4_16_COEFF_HITS);
2507 }
2508 neighbours.record_mi_luma_rect(tu_mi, tx_w, tx_h, &tu_grid);
2509 } else {
2510 let tu_around = neighbours.around_mi(tu_mi, tx_w)[0];
2511 let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_w / MI);
2512 let tu_grid = read_plane(
2513 dec,
2514 cdfs,
2515 txbset_for(tx_w, reduced_tx_set),
2516 default_scan(tx_w),
2517 0,
2518 tu_around,
2519 mode,
2520 mode,
2521 angle_delta_y,
2522 tu_reach,
2523 y,
2524 u,
2525 v,
2526 tu_px,
2527 tu_py,
2528 tx_w,
2529 tx_w,
2530 base_q_idx,
2531 None,
2532 filter_intra,
2533 Some(tu_skip_ctx),
2534 smooth_neighbor,
2535 fctx,
2536 )?;
2537 if tu_grid.iter().any(|&l| l != 0) {
2538 hit!(RECT4_16_COEFF_HITS);
2539 }
2540 neighbours.record_mi_luma(tu_mi, tx_w, &tu_grid);
2541 }
2542 }
2543 }
2544 } else {
2545 let levels = if skip {
2546 let zeros = Grid::Zero(bw * bh);
2547 if let Some(b) = &palette_y_buf {
2548 set_palette_pred(b.clone(), fctx);
2549 }
2550 push_intra_rect(
2551 y,
2552 u,
2553 v,
2554 0,
2555 px,
2556 py,
2557 bw,
2558 bh,
2559 mode,
2560 angle_delta_y,
2561 reach,
2562 &zeros,
2563 None,
2564 filter_intra,
2565 smooth_neighbor,
2566 fctx,
2567 );
2568 zeros
2569 } else {
2570 // The strip's luma TU *is* the strip (`plane_bsize ==
2571 // txsize_to_bsize[tx_size]`), so `get_txb_ctx` fixes
2572 // `txb_skip_ctx` at 0.
2573 let around = neighbours.around_mi_rect(lmi, bw, bh)[0];
2574 let set = if reduced_tx_set {
2575 TxbSet::LumaRect16x4
2576 } else {
2577 TxbSet::LumaRect16x4Set1
2578 };
2579 let mut coding = cdfs.txb(set, fi_tx_row(mode, filter_intra));
2580 let (levels, tx_type) = read_coeffs_rect(
2581 dec,
2582 &mut coding,
2583 scan,
2584 bw,
2585 bh,
2586 0,
2587 dc_sign_ctx(around.2),
2588 TxType::DctDct,
2589 0,
2590 )?;
2591 let residual = dequant_and_inverse_typed_wh(
2592 &levels,
2593 bw,
2594 bh,
2595 crate::decode::bit_depth(fctx),
2596 block_q_idx(fctx),
2597 plane_q_delta(0, fctx).0,
2598 plane_q_delta(0, fctx).1,
2599 tx_type,
2600 block_iqmatrix(fctx, 0, bw, bh, tx_type),
2601 );
2602 if let Some(b) = &palette_y_buf {
2603 set_palette_pred(b.clone(), fctx);
2604 }
2605 push_intra_rect(
2606 y,
2607 u,
2608 v,
2609 0,
2610 px,
2611 py,
2612 bw,
2613 bh,
2614 mode,
2615 angle_delta_y,
2616 reach,
2617 &residual,
2618 None,
2619 filter_intra,
2620 smooth_neighbor,
2621 fctx,
2622 );
2623 hit!(RECT4_16_COEFF_HITS);
2624 levels
2625 };
2626 neighbours.record_mi_luma_rect(lmi, bw, bh, &levels);
2627 }
2628 neighbours.fill_skip_grid_rect(lmi, mi_w, mi_h, skip);
2629 neighbours.fill_lf_grid_rect(lmi, mi_w, mi_h, tx_w as u8, tx_h as u8, 0, fctx);
2630 // `update_partition_context` writes `partition_context_lookup[
2631 // BLOCK_16X4]` over the whole 16x16: full width above, a 4-px side on
2632 // the left (mirrored under VERT_4).
2633 for cell in 0..mi_w {
2634 if let Some(slot) = neighbours.above_side_mi.get_mut(lmi.1 + cell) {
2635 *slot = bw as u8;
2636 }
2637 }
2638 for cell in 0..mi_h {
2639 if let Some(slot) = neighbours.left_side_mi.get_mut(lmi.0 + cell) {
2640 *slot = bh as u8;
2641 }
2642 }
2643 if has_chroma {
2644 hit!(RECT4_16_CHROMA_HITS);
2645 // lane-av1-444: at 4:4:4 there is no pair -- every strip is its
2646 // own chroma reference and codes its own 16x4 / 4x16 chroma
2647 // block. (`set_mi_offsets`'s chroma snap is the zero offset at
2648 // ss 0/0, so the neighbour reads below anchor at the strip.)
2649 let (pair_mi, pw, ph) = if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
2650 (lmi, bw, bh)
2651 } else if ss_y(fctx) == 0 && horz {
2652 // lane-av1-422: chroma height is NOT subsampled, so a HORZ
2653 // 16x4 strip is its own chroma reference (`is_chroma_reference`
2654 // at ss(1,0): bh == 1 mi, so the row clause reduces to
2655 // `!ss_y`) and codes its own `ss_size_lookup[BLOCK_16X4][1][0]`
2656 // = BLOCK_8X4 chroma block -- a valid transform, no pair.
2657 // (lane-av1-422o: a VERTICAL 4x16 strip now falls through to
2658 // the pair merge below -- its own chroma block
2659 // `ss_size_lookup[BLOCK_4X16][1][0]` is BLOCK_INVALID, the
2660 // walk proved such leaves exist, and libaom codes the pair's
2661 // chroma from the closing strip; the chunk lives in the
2662 // `chroma422_pair16` arm below.)
2663 (lmi, bw, bh)
2664 } else if horz {
2665 ((lmi.0 - 1, lmi.1), 16, 8)
2666 } else {
2667 ((lmi.0, lmi.1 - 1), 8, 16)
2668 };
2669 let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI);
2670 let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx));
2671 let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx));
2672 // lane-av1-422o: the 4:2:2 pair's chroma of a VERT 4x16 strip
2673 // pair: (4, 16) at ss(1,0). The bsize is still BLOCK_4X16, whose
2674 // `ss_size_lookup[..][1][0]` is BLOCK_INVALID, so libaom's
2675 // `av1_get_tx_size` reads `max_txsize_rect_lookup[255]` -- the
2676 // out-of-bounds byte is TX_4X8 in the pinned Release oracle, and
2677 // `av1_get_adjusted_tx_size` has no TX_4X8 case to adjust it.
2678 // `decode_token_recon_block` walks unit_width =
2679 // ROUND_POWER_OF_TWO(1, 1) = 1, unit_height = 4, with stepr =
2680 // tx_size_high_unit[TX_4X8] = 2: TWO TX_4X8 units per plane
2681 // (chroma rows 0..8 and 8..16), plane-major. Even the skip arm
2682 // walks per unit: `predict_and_reconstruct_intra_block` predicts
2683 // every unit regardless of `skip_txfm`.
2684 let chroma422_pair16 = (cw, ch) == (4, 16) && ss_x(fctx) == 1;
2685 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
2686 DC_PRED
2687 } else {
2688 uv_mode
2689 };
2690 if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {
2691 hit!(RECT4_16_CHROMA_DIR_HITS);
2692 }
2693 let pair_reach = Reach::of_rect(pw, ph, ppx, ppy, y.width, y.height, fctx);
2694 // lane-kf1200 r1: the chroma edge-filter type reads the neighbours
2695 // of the CHROMA block, which for a 16x4/4x16 pair is `pair_mi`'s
2696 // 16x8/8x16 region -- libaom builds `chroma_above_mbmi`/
2697 // `chroma_left_mbmi` from `mi[-((mi_row & ss_y) * stride + (mi_col
2698 // & ss_x))]` (`set_mi_offsets`, av1/common/blockd.h ~1050), i.e.
2699 // the pair's top-left luma mi, never this leaf's odd row/column.
2700 // Reading `lmi` here named the leaf directly above (a non-chroma
2701 // -reference 4-row block, `uv_mode == UV_DC_PRED`) and so lost a
2702 // SMOOTH neighbour: filt_type 0 instead of 1 turned
2703 // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a
2704 // directional chroma strip, moving 4 samples by 1.
2705 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx);
2706 // lane-av1422warp: `smooth_uv_neighbour_unsnapped` now takes the
2707 // frame's own `ss_x` -- the unsnapped read is the pair-merge witness
2708 // counter's mirror of the snapping form, and the shipped read offsets
2709 // the above COLUMN by `+ss_x` (libaom's `chroma_above_mi`).
2710 //
2711 // lane-av1leftwit: this mirror is NOT evidence about the left read's
2712 // `+ss_y` term, whatever a report once said. It reads the leaf's own
2713 // (odd) mi row, which no decode call site does -- every one of them
2714 // uses the snapping form, whose base row is even -- and its result
2715 // feeds `RECT4_16_UV_PAIR_FILT_HITS` only. What it measures is real
2716 // and worth keeping (the pair's chroma-reference read against the
2717 // leaf's own row: 51/24/121/0/1 hits on the five fixtures censused),
2718 // so it stays; the decode path's own reach for the `+ss_y` term is
2719 // `uv_left_1mi_split_hits()`.
2720 if smooth_neighbor_uv
2721 != neighbours.smooth_uv_neighbour_unsnapped(
2722 lmi.0,
2723 lmi.1,
2724 r,
2725 c,
2726 ss_x(fctx),
2727 ss_y(fctx),
2728 false,
2729 )
2730 {
2731 hit!(RECT4_16_UV_PAIR_FILT_HITS);
2732 }
2733 // lane-av1-rect14: a lossless frame forces TX_4X4 on every plane
2734 // (`av1_get_tx_size`, blockd.h:1381). The pair's chroma block is
2735 // 8x4 (HORZ_4) or 4x8 (VERT_4) -- two TX_4X4s, plane-major
2736 // (`decode_token_recon_block`), not one `ChromaRect8x4`. Reading
2737 // the rect here consumed one symbol block too few and desynced
2738 // the next strip's `skip` (measured: lossless sb128 320x240,
2739 // mi(1,20) uv_mode matched, the following skip did not).
2740 let lossless_pair = lossless(fctx);
2741 let (u_levels, v_levels) = if lossless_pair {
2742 hit!(RECT4_16_LOSSLESS_CHROMA_HITS);
2743 if skip {
2744 for plane in 1..3usize {
2745 for rr in 0..ch / 4 {
2746 for cc in 0..cw / 4 {
2747 let (ox, oy) = (cc * 4, rr * 4);
2748 // The unit's origin and extent in LUMA pixels: `<< ss`
2749 // at 4:2:0 (8x8 luma for a 4x4 chroma unit), identity
2750 // at 4:4:4 -- the same form as the block-walk sibling
2751 // at decode.rs:35342. The hardcoded `ox * 2 / 8` is
2752 // only right at ss (1,1): at 4:4:4 it claims a 4x4
2753 // chroma unit is 8x8 luma, so `of_tu`'s
2754 // `col_off + tx_w < bw` test answers against a
2755 // footprint twice the real one and every unit past
2756 // the block's midpoint wrongly reports
2757 // `above_right = false` -- a directional chroma
2758 // strip then predicts from a neighbour libaom
2759 // never reads (measured: key frame 0, 4:4:4 lossless
2760 // 16x4 strip at (104,26), U 29 + V 34 samples wrong,
2761 // entropy bit-identical over 351109 EC_SYMR reads).
2762 // lane-av1422llpred r2: this site had the OTHER half
2763 // of the same shape -- `tu_reach` takes ONE size for
2764 // both axes, so a subsampled chroma unit's height
2765 // came from `<< ss_x` instead of `<< ss_y` (a TX_4x4
2766 // chroma unit is `4 << ss_x` luma px wide but
2767 // `4 << ss_y` tall). Identical at 4:2:0/4:4:4.
2768 let cu_reach = tu_reach_rect(
2769 pw,
2770 ph,
2771 ox << ss_x(fctx),
2772 oy << ss_y(fctx),
2773 4 << ss_x(fctx),
2774 4 << ss_y(fctx),
2775 pair_reach,
2776 ppx,
2777 ppy,
2778 y.width,
2779 y.height,
2780 fctx,
2781 );
2782 if let Some((ub, vb)) = &palette_uv_bufs {
2783 let buf = if plane == 1 { ub } else { vb };
2784 set_palette_pred(palette_window(buf, cw, ox, oy, 4, 4), fctx);
2785 }
2786 push_intra(
2787 y,
2788 u,
2789 v,
2790 plane,
2791 cpx + ox,
2792 cpy + oy,
2793 4,
2794 uv_predict_mode,
2795 angle_delta_uv,
2796 cu_reach,
2797 &ZERO_RESIDUAL[..16],
2798 None,
2799 None,
2800 smooth_neighbor_uv,
2801 fctx,
2802 );
2803 let cu_mi = (
2804 pair_mi.0 + (oy << ss_y(fctx)) / MI,
2805 pair_mi.1 + (ox << ss_x(fctx)) / MI,
2806 );
2807 neighbours.record_mi_chroma(
2808 cu_mi,
2809 4 << ss_x(fctx),
2810 4 << ss_y(fctx),
2811 plane,
2812 &ZERO_RESIDUAL[..16],
2813 );
2814 }
2815 }
2816 }
2817 (Grid::Zero(cw * ch), Grid::Zero(cw * ch))
2818 } else {
2819 let scan4 = default_scan(4);
2820 // `get_txb_ctx`: offset 10 (our tables store it at +3)
2821 // when the plane block is larger than the transform.
2822 let offset = Some(3usize);
2823 let mut uo = vec![0i32; cw * ch];
2824 let mut vo = vec![0i32; cw * ch];
2825 for plane in 1..3usize {
2826 for rr in 0..ch / 4 {
2827 for cc in 0..cw / 4 {
2828 let (ox, oy) = (cc * 4, rr * 4);
2829 if cpx + ox >= u.true_width || cpy + oy >= u.true_height {
2830 continue;
2831 }
2832 // The unit's stamp is its own span: aom
2833 // `av1_set_entropy_contexts` (blockd.c:29)
2834 // memsets exactly `tx_size_wide_unit` x
2835 // `tx_size_high_unit` cells at the unit's own
2836 // `(aoff, loff)` -- for TX_4X4 ONE above cell
2837 // and ONE left cell. `(oy / 2, ox / 2)` +
2838 // `(8, 8)` is the 4:2:0 subsampled form (one
2839 // chroma cell = 8 luma px = 2 mi cells); at
2840 // 4:4:4 a unit is ONE mi cell, and the 2x2
2841 // smear let a 4-wide strip's later units
2842 // overwrite the NEXT COLUMN's above cell with
2843 // their own state -- a column aom never sees
2844 // this block write -- so the following block's
2845 // `all_zero` read the wrong `txb_skip` row
2846 // (frame-0 read #452, the llkf named gap).
2847 let cu_mi = (
2848 pair_mi.0 + (oy << ss_y(fctx)) / MI,
2849 pair_mi.1 + (ox << ss_x(fctx)) / MI,
2850 );
2851 // One luma-mi cell: the chroma entropy arrays
2852 // are subsampled, and our bands replicate that
2853 // one entry over the unit's two cells
2854 // (`read_intra_chroma_lossless`).
2855 let cu_around = neighbours.around_mi(cu_mi, MI);
2856 // Same ss-aware luma footprint as the skip arm
2857 // above -- `ox * 2 / 8` is the 4:2:0-only form and
2858 // mis-answers `of_tu` at 4:4:4 (see there).
2859 // lane-av1422llpred r2: and the SKIP arm's fix
2860 // missed the other half of the same shape -- one
2861 // size for both axes makes the height come from
2862 // `<< ss_x`, so only 4:2:2 can reach it.
2863 let cu_reach = tu_reach_rect(
2864 pw,
2865 ph,
2866 ox << ss_x(fctx),
2867 oy << ss_y(fctx),
2868 4 << ss_x(fctx),
2869 4 << ss_y(fctx),
2870 pair_reach,
2871 ppx,
2872 ppy,
2873 y.width,
2874 y.height,
2875 fctx,
2876 );
2877 if let Some((ub, vb)) = &palette_uv_bufs {
2878 let buf = if plane == 1 { ub } else { vb };
2879 set_palette_pred(palette_window(buf, cw, ox, oy, 4, 4), fctx);
2880 }
2881 let cu_grid = read_plane(
2882 dec,
2883 cdfs,
2884 TxbSet::Chroma4,
2885 scan4,
2886 plane,
2887 cu_around[plane],
2888 mode,
2889 uv_predict_mode,
2890 angle_delta_uv,
2891 cu_reach,
2892 y,
2893 u,
2894 v,
2895 cpx + ox,
2896 cpy + oy,
2897 4,
2898 4,
2899 base_q_idx,
2900 None,
2901 None,
2902 offset,
2903 smooth_neighbor_uv,
2904 fctx,
2905 )?;
2906 neighbours.record_mi_chroma(
2907 cu_mi,
2908 4 << ss_x(fctx),
2909 4 << ss_y(fctx),
2910 plane,
2911 &cu_grid,
2912 );
2913 hit!(CHROMA_SPLIT_TX_HITS);
2914 let dst = if plane == 1 { &mut uo } else { &mut vo };
2915 for row in 0..4 {
2916 let start = (oy + row) * cw + ox;
2917 dst[start..start + 4].copy_from_slice(&cu_grid[row * 4..][..4]);
2918 }
2919 }
2920 }
2921 }
2922 (Grid::Own(uo), Grid::Own(vo))
2923 }
2924 } else if skip {
2925 let zeros = Grid::Zero(cw * ch);
2926 // libaom `predict_and_reconstruct_intra_block` (decodeframe.c
2927 // ~1000) predicts EVERY plane and only guards the residual on
2928 // `mbmi->skip_txfm`, so a skipped `UV_CFL_PRED` block is still
2929 // DC + alpha * luma-AC. Dropping the CfL term here left a
2930 // chroma-only bounded box on ReelC's key frames.
2931 let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph));
2932 if alpha.is_some() {
2933 hit!(CHROMA_SKIP_CFL_HITS);
2934 }
2935 for plane in [1usize, 2] {
2936 if chroma422_pair16 {
2937 // lane-av1-422o: two TX_4X8 units, each predicted on
2938 // its own edges (the lower one off the upper one's
2939 // samples); no coefficients are coded, and libaom's
2940 // `set_entropy_context` zeroed the block's own cells,
2941 // so the pair-wide zero stamp below stays correct.
2942 for unit_row in 0..2usize {
2943 let unit_reach = tu_reach_rect(
2944 pw,
2945 ph,
2946 0,
2947 unit_row * 8,
2948 8,
2949 8,
2950 pair_reach,
2951 ppx,
2952 ppy,
2953 y.width,
2954 y.height,
2955 fctx,
2956 );
2957 if let Some((ub, vb)) = &palette_uv_bufs {
2958 let pbuf = if plane == 1 { ub } else { vb };
2959 set_palette_pred(palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), fctx);
2960 }
2961 push_intra_rect(
2962 y,
2963 u,
2964 v,
2965 plane,
2966 cpx,
2967 cpy + unit_row * 8,
2968 4,
2969 8,
2970 uv_predict_mode,
2971 angle_delta_uv,
2972 unit_reach,
2973 &ZERO_RESIDUAL[..4 * 8],
2974 alpha
2975 .zip(ac)
2976 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
2977 None,
2978 smooth_neighbor_uv,
2979 fctx,
2980 );
2981 }
2982 } else {
2983 if let Some((ub, vb)) = &palette_uv_bufs {
2984 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
2985 }
2986 push_intra_rect(
2987 y,
2988 u,
2989 v,
2990 plane,
2991 cpx,
2992 cpy,
2993 cw,
2994 ch,
2995 uv_predict_mode,
2996 angle_delta_uv,
2997 pair_reach,
2998 &zeros,
2999 alpha
3000 .zip(ac)
3001 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
3002 None,
3003 smooth_neighbor_uv,
3004 fctx,
3005 );
3006 }
3007 }
3008 (zeros.clone(), zeros)
3009 } else if chroma422_pair16 {
3010 // lane-av1-422o: the pair's 4x16 chroma as TWO TX_4X8 units
3011 // per plane, plane-major (every U unit, then every V). Each
3012 // unit: the `ChromaRect8x4` tables (`get_txsize_entropy_ctx`
3013 // squares TX_4X8 up to the 8x8 class), `SCAN_4X8`, and a
3014 // `txb_skip_ctx` of above+left in the OFFSET-10 rows -- the
3015 // offset comes from `num_pels_log2_lookup[plane_bsize] >
3016 // num_pels_log2_lookup[BLOCK_4X8]` with plane_bsize =
3017 // BLOCK_INVALID (255), and the byte at that table's +255 in
3018 // the pinned Release oracle is 255 (`cmpb` against the
3019 // `0xc0db70` copy decodetxb.c links), i.e. the bigger-plane
3020 // arm: +3 on the offset-7-first chroma tables. No tx_type
3021 // symbol (only y plane's is transmitted); the unit's type is
3022 // `intra_mode_to_tx_type(UV mode)` kept by the all-16 ext-tx
3023 // set -- [`read_rect_chroma_unit`]'s own default. CfL params
3024 // are computed ONCE per block (`are_parameters_computed`)
3025 // over the pair's luma, shared by both units. Each unit is
3026 // predicted and recorded immediately, so the lower unit
3027 // reads the upper one's coefficient context.
3028 let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph));
3029 for plane in [1usize, 2] {
3030 for unit_row in 0..2usize {
3031 let unit_mi = (pair_mi.0 + unit_row * 2, pair_mi.1);
3032 let unit_reach = tu_reach_rect(
3033 pw,
3034 ph,
3035 0,
3036 unit_row * 8,
3037 8,
3038 8,
3039 pair_reach,
3040 ppx,
3041 ppy,
3042 y.width,
3043 y.height,
3044 fctx,
3045 );
3046 if let Some((ub, vb)) = &palette_uv_bufs {
3047 let pbuf = if plane == 1 { ub } else { vb };
3048 set_palette_pred(palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), fctx);
3049 }
3050 let chroma_around = neighbours.around_mi_422_chroma(unit_mi, 8, 8);
3051 let unit_grid = read_rect_chroma_unit(
3052 dec,
3053 cdfs,
3054 TxbSet::ChromaRect8x4,
3055 &SCAN_4X8,
3056 4,
3057 8,
3058 plane,
3059 chroma_around[plane],
3060 uv_predict_mode,
3061 angle_delta_uv,
3062 unit_reach,
3063 y,
3064 u,
3065 v,
3066 cpx,
3067 cpy + unit_row * 8,
3068 base_q_idx,
3069 // lane-av1-422q: the offset-10 rows -- the same
3070 // measured rule as the 4x32 arm (plane_bsize
3071 // BLOCK_INVALID for the pair's BLOCK_4X16 too;
3072 // num_pels_log2_lookup[255] = 0xff at the
3073 // 0xc0de70 copy -> +3 on the offset-7-first
3074 // chroma tables; see lanes/av1422q.report.md).
3075 Some(3),
3076 alpha
3077 .zip(ac)
3078 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
3079 smooth_neighbor_uv,
3080 fctx,
3081 )?;
3082 neighbours.record_mi_chroma(unit_mi, 8, 8, plane, &unit_grid);
3083 }
3084 }
3085 (Grid::Zero(cw * ch), Grid::Zero(cw * ch))
3086 } else {
3087 // lane-av1422ctxgather: 4:2:2's chroma above votes sample
3088 // every second luma-mi cell
3089 // ([`Neighbours::around_mi_422_chroma`]: at ss_x 1 one
3090 // chroma 4-px column spans two luma mi columns, and the
3091 // plain per-mi gather counts each column's whole-unit dc
3092 // sign twice). The left extent is unsubsampled at ss_y 0,
3093 // so its per-mi cells already line up one-to-one.
3094 let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
3095 neighbours.around_mi_422_chroma(pair_mi, pw, ph)
3096 } else {
3097 neighbours.around_mi_rect(pair_mi, pw, ph)
3098 };
3099 // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0
3100 // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` =
3101 // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8.
3102 let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (cw, ch) {
3103 (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]),
3104 (4, 8) => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]),
3105 (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),
3106 // lane-av1-444: 4:4:4's own-strip vert chroma is (4,16)
3107 // -- one TX_4X16. (lane-av1-422o: the 4:2:2 pair's
3108 // (4,16) never reaches this row; `chroma422_pair16`
3109 // intercepts it above and chunks it into TX_4X8 units.)
3110 (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]),
3111 // lane-av1-422: a 4:2:2 HORZ pair (16x8 luma) keeps the
3112 // pair's height: an 8x8 SQUARE chroma block, the same
3113 // `TxbSet::Chroma8` set any 8x8 chroma plane reads. The
3114 // 4:2:0 pair's chroma is 8x4 and 4:4:4's is 16x4, so this
3115 // row is unreachable there. It is also the witness arm:
3116 // a restored `/2 chroma height` lands on (8,4) and the
3117 // counter reads 0.
3118 (8, 8) => {
3119 hit!(CHROMA422_SQUARE_HITS);
3120 (TxbSet::Chroma8, default_scan(8))
3121 }
3122 // lane-av1-422o: with the `chroma422_pair16` arm above,
3123 // the (2,16) own-strip shape and the 4:4:4 shapes are the
3124 // only residents; anything else is a named-lane gap.
3125 _ => unreachable!("decode_rect4_16_strip chroma shape set is closed"),
3126 };
3127 let mut planes = Vec::with_capacity(2);
3128 // Index loop mirrors the spec's per-position form over several offsets; an iterator would obscure it.
3129 #[allow(clippy::needless_range_loop)]
3130 for plane in 1..3 {
3131 let default_tx = default_intra_tx_type(uv_predict_mode as u8);
3132 let skip_ctx = usize::from(around[plane].0) + usize::from(around[plane].1);
3133 let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
3134 let (levels, tx_type) = read_chroma_coeffs_rect(
3135 dec,
3136 &mut coding,
3137 chroma_scan,
3138 cw,
3139 ch,
3140 skip_ctx,
3141 dc_sign_ctx(around[plane].2),
3142 default_tx,
3143 fctx,
3144 plane,
3145 )?;
3146 planes.push((levels, tx_type));
3147 }
3148 let (v_levels, v_tx_type) = planes.pop().expect("plane 2");
3149 let (u_levels, u_tx_type) = planes.pop().expect("plane 1");
3150 // CfL averages the luma of the WHOLE pair, the region this one
3151 // chroma transform covers.
3152 let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph));
3153 for (plane, levels, tx_type) in
3154 [(1usize, &u_levels, u_tx_type), (2, &v_levels, v_tx_type)]
3155 {
3156 let residual = dequant_and_inverse_typed_wh(
3157 levels,
3158 cw,
3159 ch,
3160 crate::decode::bit_depth(fctx),
3161 block_q_idx(fctx),
3162 plane_q_delta(plane, fctx).0,
3163 plane_q_delta(plane, fctx).1,
3164 tx_type,
3165 block_iqmatrix(fctx, plane, cw, ch, tx_type),
3166 );
3167 if let Some((ub, vb)) = &palette_uv_bufs {
3168 set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx);
3169 }
3170 push_intra_rect(
3171 y,
3172 u,
3173 v,
3174 plane,
3175 cpx,
3176 cpy,
3177 cw,
3178 ch,
3179 uv_predict_mode,
3180 angle_delta_uv,
3181 pair_reach,
3182 &residual,
3183 alpha
3184 .zip(ac)
3185 .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)),
3186 None,
3187 smooth_neighbor_uv,
3188 fctx,
3189 );
3190 }
3191 (u_levels, v_levels)
3192 };
3193 neighbours.record_uv_mode_mi(pair_mi.0, pair_mi.1, pw / MI, ph / MI, uv_predict_mode);
3194 // A lossless pair already stamped each TX_4X4 (`record_mi_chroma`).
3195 // The single-state rewrite below is the non-lossless TX_8X4/TX_4X8.
3196 // lane-av1-422o: the chunked pair's cells are stamped PER UNIT in
3197 // the arm above (libaom's coefficient contexts are per
3198 // 4x4-cell); a pair-wide state would erase the unit boundary the
3199 // next block reads.
3200 if !lossless_pair && !chroma422_pair16 {
3201 // The chroma planes' coefficient context, over the PAIR's mi span
3202 // (`decode_leaf_rect8`'s own rule: a subsampled plane's bound is
3203 // the luma one rounded up to its 4x4 unit).
3204 let u_state = neighbour_state(&u_levels);
3205 let v_state = neighbour_state(&v_levels);
3206 let round_up_even = |n: usize| n.div_ceil(2) * 2;
3207 let bound_h = round_up_even(neighbours.mi_rows);
3208 let bound_w = round_up_even(neighbours.mi_cols);
3209 for cell in 0..(ph / MI) {
3210 if pair_mi.0 + cell < bound_h
3211 && let Some(slot) = neighbours.left.get_mut(pair_mi.0 + cell)
3212 {
3213 slot[1] = u_state;
3214 slot[2] = v_state;
3215 }
3216 }
3217 for cell in 0..(pw / MI) {
3218 if pair_mi.1 + cell < bound_w
3219 && let Some(slot) = neighbours.above.get_mut(pair_mi.1 + cell)
3220 {
3221 slot[1] = u_state;
3222 slot[2] = v_state;
3223 }
3224 }
3225 }
3226 last_uv_mode = Some(uv_predict_mode);
3227 }
3228 if horz {
3229 hit!(RECT4_16_HORZ_HITS);
3230 } else {
3231 hit!(RECT4_16_VERT_HITS);
3232 }
3233 let (pal_y_size, pal_y_colors) = palette_y
3234 .as_ref()
3235 .map_or((0, [0u16; 8]), |p| (p.size, p.colors));
3236 let (pal_uv_size, pal_uv_colors) = palette_uv
3237 .as_ref()
3238 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
3239 record_strip_palette(
3240 neighbours,
3241 lmi,
3242 bw,
3243 bh,
3244 pal_y_size,
3245 pal_y_colors,
3246 pal_uv_size,
3247 pal_uv_colors,
3248 );
3249 // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)`
3250 // (libaom `decode_token_recon_block`, run for EVERY block of an inter
3251 // frame): the above row records `tx_size_wide` over the block's width and
3252 // the left column `tx_size_high` over its height. This 1:4 strip reader is
3253 // also the INTER frame's reader for the shape ([`decode_intra_rect4_in_inter`]),
3254 // and it published neither band -- so the block after a 64x16 strip read
3255 // the row's init value 64 as its left transform height and took
3256 // `tx_size_cat3` row 1 where libaom takes row 0 (lane-frame36 r1: the
3257 // 3840x1608 10-bit stream's first silent wall, decode-order frame 33 at
3258 // mi(16,480)). Same write as [`set_txfm_ctxs`], rect-aware.
3259 txfm_partition_update_rect(neighbours, lmi, (tx_w, tx_h), (bw, bh));
3260 Ok((mode, last_uv_mode, (tx_w, tx_h)))
3261}
3262
3263/// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/
3264/// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /
3265/// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike
3266/// that 32x16/16x32 strip, both dimensions here exceed the 32-coefficient
3267/// cap, so LUMA needs the same corner truncation [`decode_block`] already
3268/// does for a plain 64x64 square (spec 5.11.40): `get_txsize_entropy_ctx`
3269/// resolves TX_64X32/TX_32X64 to TX_64X64 regardless of orientation (see
3270/// this function's own charter/report), so both strips read a real 32x32
3271/// corner through [`read_coeffs`] with [`TxbSet::Luma64`]/[`SCAN_32`] and
3272/// embed it top-left of a zeroed `bw`x`bh` grid, mirroring
3273/// [`read_plane`]'s `tx_side != side` branch generalized to non-square.
3274/// CHROMA (TX_32X16/TX_16X32) resolves to TX_32X32 -- a real, *untruncated*
3275/// `bw/2`x`bh/2` transform via [`read_coeffs_rect`] with
3276/// [`TxbSet::ChromaRect32x16`] and the matching [`SCAN_32X16`]/
3277/// [`SCAN_16X32`], same as [`decode_block_rect`]'s own chroma path. Like
3278/// that function, only the single-transform-unit (`tx_depth == 0`) case is
3279/// supported: a split transform refuses by name rather than guess-decode.
3280#[allow(clippy::too_many_arguments)]
3281pub(super) fn decode_block_rect64(
3282 dec: &mut SymbolDecoder,
3283 cdfs: &mut Cdfs,
3284 neighbours: &mut Neighbours,
3285 at: (usize, usize),
3286 bw: usize,
3287 bh: usize,
3288 y: &mut PlaneBuf<'static>,
3289 u: &mut PlaneBuf<'static>,
3290 v: &mut PlaneBuf<'static>,
3291 enable_filter_intra: bool,
3292 allow_screen_content_tools: bool,
3293 base_q_idx: u8,
3294 tx_select: bool,
3295 reduced_tx_set: bool,
3296 fctx: &crate::decode::FrameCtx,
3297) -> Result<()> {
3298 let (r, c) = at;
3299 let (px, py) = (c * SUB, r * SUB);
3300 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
3301 let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
3302 let palette_uv_cache = neighbours.palette_uv_cache(at);
3303 let (
3304 skip,
3305 mode,
3306 angle_delta_y,
3307 uv_mode,
3308 angle_delta_uv,
3309 alpha,
3310 filter_intra,
3311 palette_y,
3312 palette_uv,
3313 intrabc,
3314 ) = read_intra_mode_rect(
3315 dec,
3316 cdfs,
3317 nb_above_mode,
3318 nb_left_mode,
3319 // `is_cfl_allowed` (spec 5.11.5) caps CFL at <=32x32; these
3320 // superblock-level HORZ/VERT strips are 64x32/32x64, so unlike
3321 // `decode_block_rect`'s own 32x16/16x32 strips (where `true` is
3322 // correct), CFL must never be offered here -- passing `true`
3323 // read `uv_mode` off the 14-symbol `uv_mode_cfl` CDF instead of
3324 // the real 13-symbol `uv_mode_no_cfl` one and desynced the tile
3325 // from this block's very first symbol (lane-sbpart r3 bisect).
3326 false,
3327 true,
3328 bw,
3329 bh,
3330 enable_filter_intra,
3331 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
3332 allow_screen_content_tools,
3333 Some((palette_ctx, &palette_cache)),
3334 &palette_uv_cache,
3335 r * (SUB / MI),
3336 c * (SUB / MI),
3337 fctx,
3338 )?;
3339 if let Some((dv_row, dv_col)) = intrabc {
3340 return decode_intrabc_owned_rect(
3341 dec,
3342 cdfs,
3343 neighbours,
3344 (r * (SUB / MI), c * (SUB / MI)),
3345 (bw, bh),
3346 skip,
3347 (dv_row, dv_col),
3348 y,
3349 u,
3350 v,
3351 base_q_idx,
3352 tx_select,
3353 reduced_tx_set,
3354 fctx,
3355 );
3356 }
3357 if (palette_y.is_some() || palette_uv.is_some()) && !skip {
3358 // lane-t900 r34: a non-skip palette block on a superblock-level strip
3359 // -- counted so its gate cannot go vacuous (this was a refusal until
3360 // r34; see the gate `a_real_aomenc_palette_stream_with_8x8_leaves_
3361 // decodes_pixel_exact`).
3362 hit!(PALETTE_SB_STRIP_HITS);
3363 }
3364 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
3365 if smooth_neighbor {
3366 hit!(SMOOTH_LUMA_HITS);
3367 }
3368 let smooth_neighbor_uv =
3369 neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
3370 if filter_intra.is_some() {
3371 // `filter_intra_size_class_rect` already returns `None` for both
3372 // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at
3373 // 32 on both axes), so this symbol is never read at this level --
3374 // kept only as the same defensive refusal [`decode_block_rect`] has.
3375 return Err(unsupported(
3376 "filter intra on a superblock-level HORZ/VERT strip (never expected -- \
3377 av1_filter_intra_allowed_bsize caps at 32x32)",
3378 ));
3379 }
3380 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
3381 DC_PRED
3382 } else {
3383 uv_mode
3384 };
3385 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
3386 // lane-av1mixloss: the lossless-segment early return (`decodeframe.c:1203`)
3387 // precedes `TX_MODE_SELECT`, so a lossless-segment 64-axis rect block codes
3388 // no depth symbol here either (class sweep of the sub8 leaf's fix).
3389 let depth = if tx_select && !lossless(fctx) {
3390 // lane-av1txbands: EVERY frame now reads the real `TXFM_CONTEXT`
3391 // bands (`get_tx_size_context`, libaom `pred_common.h:342`) -- an
3392 // intra-only frame publishes them from every block too
3393 // ([`Neighbours::fill_lf_grid_rect`]). Measured on the 10-bit
3394 // 1920x792 128-superblock stream,
3395 // decode-order frame 1: the 32x8 HORZ_4 strip at mi(48,176) read
3396 // `tx_size_cat2` row 1 where libaom reads row 2.
3397 let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw, bh, fctx);
3398 // lane-rectsplit r1: `bsize_to_tx_size_cat` (libaom `decodemv.c`)
3399 // counts `sub_tx_size_map` steps from the block's own max rect
3400 // transform down to TX_4X4, minus one -- BLOCK_64X32's chain
3401 // (TX_64X32 -> TX_32X32 -> TX_16X16 -> TX_8X8 -> TX_4X4) is four
3402 // steps, so this level's category is 3 (the same one a 64x64 square
3403 // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF
3404 // here was a wrong-table read of a real symbol.
3405 let d = dec.symbol(&mut cdfs.tx_size_cat3[ctx]);
3406 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
3407 eprintln!(
3408 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=3 rng={}",
3409 dec.debug_state().0
3410 );
3411 }
3412 d
3413 } else {
3414 0
3415 };
3416 // lane-t900 r1: this strip's own `set_txfm_ctxs` when it is an intra
3417 // block of an INTER frame -- see [`publish_txfm_bands_if_in_inter`].
3418 publish_txfm_bands_if_in_inter(
3419 neighbours,
3420 (mi_r, mi_c),
3421 depth_to_tx_wh(bw, bh, depth, fctx),
3422 (bw, bh),
3423 fctx,
3424 );
3425 if depth != 0 || lossless(fctx) {
3426 hit!(TX_DEPTH_HITS);
3427 // lane-rectsplit r1/r4: the superblock-level strip splits its
3428 // transform through the very same per-unit path as its 32x32-level
3429 // sibling; [`depth_to_tx_wh`] names the unit, which for a 64x16/16x64
3430 // 1:4 strip is the 2:1 rect TX_32X16 at depth 1 (lane-rectchroma r1
3431 // measured the old square formula mis-tiling exactly that strip).
3432 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth, fctx);
3433 if bw.max(bh) / bw.min(bh) == 4 {
3434 let which = if depth == 1 {
3435 &RECT4_SPLIT_DEPTH1_HITS
3436 } else {
3437 &RECT4_SPLIT_DEPTH2_HITS
3438 };
3439 hit_do! { which.with(|c| c.set(c.get() + 1)); }
3440 }
3441 if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
3442 eprintln!(
3443 "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
3444 depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \
3445 angle_y={angle_delta_y}"
3446 );
3447 }
3448 let modes = RectStripModes {
3449 skip,
3450 mode,
3451 angle_delta_y,
3452 uv_predict_mode,
3453 angle_delta_uv,
3454 alpha,
3455 filter_intra,
3456 smooth_neighbor,
3457 smooth_neighbor_uv,
3458 palette_y: palette_y
3459 .as_ref()
3460 .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()),
3461 palette_uv: palette_uv.as_ref().map(|p| {
3462 (
3463 p.map.iter().map(|&i| p.u_colors[i as usize]).collect(),
3464 p.map.iter().map(|&i| p.v_colors[i as usize]).collect(),
3465 )
3466 }),
3467 };
3468 if palette_y.is_some() || palette_uv.is_some() {
3469 hit!(PALETTE_SPLIT_TX_HITS);
3470 }
3471 decode_rect_split(
3472 dec,
3473 cdfs,
3474 neighbours,
3475 (mi_r, mi_c),
3476 bw,
3477 bh,
3478 tx_w,
3479 tx_h,
3480 &modes,
3481 y,
3482 u,
3483 v,
3484 base_q_idx,
3485 reduced_tx_set,
3486 fctx,
3487 )?;
3488 // Same early-return palette stamp as [`decode_block_rect`]'s split arm
3489 // (lane-palette2 r10): this return skips the fn's own tail, so a
3490 // split-tx superblock strip would otherwise leave the above/left
3491 // palette arrays holding a dead block's colours.
3492 let (py_size, py_colors) = palette_y
3493 .as_ref()
3494 .map_or((0, [0u16; 8]), |p| (p.size, p.colors));
3495 neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors);
3496 let (puv_size, puv_colors) = palette_uv
3497 .as_ref()
3498 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
3499 neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors);
3500 // lane-frame36 r2: `set_txfm_ctxs` runs for EVERY block and this early
3501 // return skips the fn's own tail, so a SPLIT superblock-level strip
3502 // published no TXFM_CONTEXT band and the next block read the row's init
3503 // value 64 as its left transform height. Measured on the 10-bit
3504 // 3840x1608 stream, decode-order frame 33: after the split 16x64 strip
3505 // at mi(192,140) (`tx_depth=1` -> TX_16X32) the 32x64 block at
3506 // mi(192,144) took `tx_size_cat3` row 2 where libaom takes row 1. The
3507 // bands carry the SPLIT unit's size, not the block's.
3508 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
3509 hit!(RECT64_SPLIT_TXFM_PUBLISH_HITS);
3510 hit!(RECT_PARTITION_HITS);
3511 return Ok(());
3512 }
3513 let (tx_w, tx_h) = (bw, bh);
3514 let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
3515 let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
3516 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
3517 if let Some(ref pyv) = palette_y {
3518 let buf: Vec<u16> = pyv
3519 .map
3520 .iter()
3521 .map(|&idx| pyv.colors[idx as usize])
3522 .collect();
3523 set_palette_pred(buf, fctx);
3524 }
3525 let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|puv| {
3526 (
3527 puv.map
3528 .iter()
3529 .map(|&idx| puv.u_colors[idx as usize])
3530 .collect(),
3531 puv.map
3532 .iter()
3533 .map(|&idx| puv.v_colors[idx as usize])
3534 .collect(),
3535 )
3536 });
3537 if skip {
3538 push_intra_rect(
3539 y,
3540 u,
3541 v,
3542 0,
3543 px,
3544 py,
3545 bw,
3546 bh,
3547 mode,
3548 angle_delta_y,
3549 reach,
3550 &ZERO_RESIDUAL[..bw * bh],
3551 None,
3552 filter_intra,
3553 smooth_neighbor,
3554 fctx,
3555 );
3556 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
3557 if let Some((ub, _)) = &palette_uv_bufs {
3558 set_palette_pred(ub.clone(), fctx);
3559 }
3560 push_intra_rect(
3561 y,
3562 u,
3563 v,
3564 1,
3565 cpx,
3566 cpy,
3567 chroma_w,
3568 chroma_h,
3569 uv_predict_mode,
3570 angle_delta_uv,
3571 reach,
3572 &ZERO_RESIDUAL[..chroma_w * chroma_h],
3573 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
3574 None,
3575 smooth_neighbor_uv,
3576 fctx,
3577 );
3578 if let Some((_, vb)) = &palette_uv_bufs {
3579 set_palette_pred(vb.clone(), fctx);
3580 }
3581 push_intra_rect(
3582 y,
3583 u,
3584 v,
3585 2,
3586 cpx,
3587 cpy,
3588 chroma_w,
3589 chroma_h,
3590 uv_predict_mode,
3591 angle_delta_uv,
3592 reach,
3593 &ZERO_RESIDUAL[..chroma_w * chroma_h],
3594 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
3595 None,
3596 smooth_neighbor_uv,
3597 fctx,
3598 );
3599 neighbours.record_rect(
3600 at,
3601 bw,
3602 bh,
3603 mode,
3604 uv_predict_mode,
3605 &[
3606 &ZERO_RESIDUAL[..bw * bh],
3607 &ZERO_RESIDUAL[..chroma_w * chroma_h],
3608 &ZERO_RESIDUAL[..chroma_w * chroma_h],
3609 ],
3610 );
3611 } else {
3612 let around = neighbours.around_rect(at, bw, bh);
3613 // LUMA: the coded corner, embedded top-left of the true bw x bh grid
3614 // (see this function's own doc comment). A 64-length axis codes only
3615 // its low 32 coefficients, so the corner is `min(bw, 32)` x
3616 // `min(bh, 32)`: 32x32 under a 64x32/32x64 HORZ/VERT strip, and
3617 // 32x16/16x32 under a 64x16/16x64 1:4 strip (lane-tx64x16).
3618 let (luma_cw, luma_ch) = (bw.min(32), bh.min(32));
3619 let scan32 = default_scan(TX32);
3620 if coeff_trace_on() {
3621 let (rng, _) = dec.debug_state();
3622 eprintln!(
3623 "EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size={luma_cw}x{luma_ch} rng={rng}"
3624 );
3625 }
3626 let (luma_corner, luma_tx_type) = if (luma_cw, luma_ch) == (32, 32) {
3627 let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode);
3628 read_coeffs(
3629 dec,
3630 &mut luma_coding,
3631 scan32,
3632 0,
3633 dc_sign_ctx(around[0].2),
3634 TxType::DctDct,
3635 Some((bw, bh)),
3636 )?
3637 } else {
3638 // `av1_get_adjusted_tx_size` (`blockd.h:1361`) maps TX_64X16 ->
3639 // TX_32X16 and TX_16X64 -> TX_16X32, and `av1_scan_orders`
3640 // (`scan.c`) gives both the very same `default_scan_32x16` /
3641 // `default_scan_16x32` the 2:1 sizes use ("Half of the
3642 // coefficients of tx64 at higher frequencies are set to zeros. So
3643 // tx32's scan order is used"). `get_txsize_entropy_ctx` is
3644 // (txsize_sqr + txsize_sqr_up + 1) >> 1 = (TX_16X16 + TX_64X64 +
3645 // 1) >> 1 = TX_32X32 and `txsize_log2_minus4[TX_64X16]` is 5 (a
3646 // 512-position eob group) -- BOTH identical to TX_32X16, so the
3647 // 2:1 CDF set `LumaRect32x16` is bit-exact here and no new table
3648 // is owed. `av1_nz_map_ctx_offset[TX_64X16]` is literally
3649 // `av1_nz_map_ctx_offset_32x16` (`txb_common.c:340`), which is
3650 // what `base_ctx_rect` computes at (32, 16).
3651 let luma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 };
3652 let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode);
3653 read_coeffs_rect(
3654 dec,
3655 &mut luma_coding,
3656 luma_scan,
3657 luma_cw,
3658 luma_ch,
3659 0,
3660 dc_sign_ctx(around[0].2),
3661 TxType::DctDct,
3662 0,
3663 )?
3664 };
3665 if coeff_trace_on() {
3666 let (rng, _) = dec.debug_state();
3667 eprintln!("EC_COEFF_VAL plane=0 row={mi_r} col={mi_c} rng={rng}");
3668 }
3669 let mut luma_levels = vec![0i32; bw * bh];
3670 for row in 0..luma_ch {
3671 luma_levels[row * bw..][..luma_cw]
3672 .copy_from_slice(&luma_corner[row * luma_cw..][..luma_cw]);
3673 }
3674 {
3675 let cur = block_q_idx(fctx);
3676 if cur != i32::from(base_q_idx) {
3677 hit!(RECT64_QIDX_DRIFT_HITS);
3678 }
3679 if crate::envflags::env_flag!("EC_AV1_TRACE") {
3680 eprintln!(
3681 "TRACE rect64_dequant plane=0 base_q_idx={base_q_idx} current_q_idx={cur}"
3682 );
3683 }
3684 }
3685 let luma_residual = dequant_and_inverse_typed_wh(
3686 &luma_levels,
3687 bw,
3688 bh,
3689 crate::decode::bit_depth(fctx),
3690 block_q_idx(fctx),
3691 plane_q_delta(0, fctx).0,
3692 plane_q_delta(0, fctx).1,
3693 luma_tx_type,
3694 block_iqmatrix(fctx, 0, bw, bh, luma_tx_type),
3695 );
3696 push_intra_rect(
3697 y,
3698 u,
3699 v,
3700 0,
3701 px,
3702 py,
3703 bw,
3704 bh,
3705 mode,
3706 angle_delta_y,
3707 reach,
3708 &luma_residual,
3709 None,
3710 filter_intra,
3711 smooth_neighbor,
3712 fctx,
3713 );
3714 if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
3715 let leftcol: Vec<u16> = if px > 0 {
3716 (py..py + bh)
3717 .map(|row| y.data[row * y.width + px - 1])
3718 .collect()
3719 } else {
3720 vec![]
3721 };
3722 eprintln!(
3723 "DUMP64 mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} mode={mode} \
3724 skip={skip} eob_nonzero={} row0={:?} leftcol={:?}",
3725 luma_corner.iter().any(|&v| v != 0),
3726 &y.data[py * y.width + px..][..bw],
3727 leftcol,
3728 );
3729 }
3730 // CHROMA. At 4:2:0 the plane block is already one adjusted UV
3731 // transform (<=32 on each axis). At 4:4:4 a 64-axis strip's chroma
3732 // is larger than that, so it is tiled into 32-capped units.
3733 let _ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
3734 let (uw, uh) = (chroma_w.min(32), chroma_h.min(32));
3735 let (nw, nh) = (chroma_w / uw, chroma_h / uh);
3736 let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (uw, uh) {
3737 (32, 32) => (TxbSet::Chroma32, default_scan(32)),
3738 (32, 16) => (TxbSet::ChromaRect32x16, &SCAN_32X16),
3739 (16, 32) => (TxbSet::ChromaRect32x16, &SCAN_16X32),
3740 (32, 8) => (TxbSet::Chroma16, &SCAN_32X8),
3741 (8, 32) => (TxbSet::Chroma16, &SCAN_8X32),
3742 _ => {
3743 return Err(unsupported(
3744 "a 64-axis strip whose chroma unit has no coefficient table",
3745 ));
3746 }
3747 };
3748 let bigger = nw * nh > 1;
3749 // lane-av1444palw: the reach census for the horizontal arm of this
3750 // walk. `EC_PALWALK=1` prints, per rect64 block, the plane-block
3751 // geometry, the unit grid it was tiled into, and whether a chroma
3752 // palette was present -- so a fixture search can tell `nw >= 2` (the
3753 // arm nothing had reached) from `nh >= 2` (the arm the corpus census
3754 // already covered), and can see WHY a candidate block did not fire.
3755 // Diagnostic only; no decode behaviour depends on it.
3756 if crate::envflags::env_flag!("EC_PALWALK") {
3757 eprintln!(
3758 "EC_PALWALK mi={r},{c} px={px} py={py} bw={bw} bh={bh} cw={chroma_w} \
3759 ch={chroma_h} uw={uw} uh={uh} nw={nw} nh={nh} ast={allow_screen_content_tools} \
3760 puv={} py_pal={}",
3761 palette_uv.is_some() as i32,
3762 palette_y.is_some() as i32
3763 );
3764 }
3765 let mut u_levels = vec![0i32; chroma_w * chroma_h];
3766 let mut v_levels = vec![0i32; chroma_w * chroma_h];
3767 // The tiled units below stamp their own coefficient context
3768 // immediately, then the whole-strip `record_rect` rewrite paints
3769 // every chroma cell with ONE whole-strip state and the per-unit DC
3770 // signs and levels are lost (class `override-slot-on-one-arm`, same
3771 // shape as `decode_rect_split`'s chroma_tiled clobber). Collected
3772 // here and replayed after that record, the c8 `mu_chroma_units` way.
3773 let mut tiled_chroma_units: Vec<((usize, usize), usize, Grid, usize, usize)> = Vec::new();
3774 for plane_idx in 1..=2 {
3775 for cu_row in 0..nh {
3776 for cu_col in 0..nw {
3777 let cu_around = if nw == 1 && nh == 1 {
3778 around
3779 } else {
3780 let lsx = uw << ss_x(fctx);
3781 let lsy = uh << ss_y(fctx);
3782 let cu_mi = (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI));
3783 // lane-av1422llintra: same ss (1, 0) above-column
3784 // double-count as 12735 -- one chroma column spans two
3785 // luma mi columns, libaom reads one. Identical number
3786 // at 4:2:0 and 4:4:4.
3787 if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
3788 neighbours.around_mi_422_chroma(cu_mi, lsx, lsy)
3789 } else {
3790 neighbours.around_mi_rect(cu_mi, lsx, lsy)
3791 }
3792 };
3793 let lsx = uw << ss_x(fctx);
3794 let lsy = uh << ss_y(fctx);
3795 let cfl = alpha.map(|(au, av)| {
3796 let a = if plane_idx == 1 { au } else { av };
3797 (
3798 a,
3799 cfl_src_rect(px + cu_col * lsx, py + cu_row * lsy, lsx, lsy),
3800 )
3801 });
3802 let levels = if uw == uh {
3803 if let Some((ub, vb)) = &palette_uv_bufs {
3804 let pbuf = if plane_idx == 1 { ub } else { vb };
3805 set_palette_pred(
3806 palette_window(pbuf, chroma_w, cu_col * uw, cu_row * uh, uw, uh),
3807 fctx,
3808 );
3809 // Counted only when the window is a STRICT sub-slice of the
3810 // block's buffer, i.e. when the 32-cap actually tiled the
3811 // block: at nw * nh == 1 the window is a re-stride copy of
3812 // the whole buffer and windowing is load-bearing for
3813 // nothing. The `bigger` guard is what makes a hit PROOF
3814 // that the tiled arm ran, rather than proof that some
3815 // palette chroma block existed.
3816 if bigger {
3817 hit!(CHROMA_PALETTE_WINDOW_HITS);
3818 }
3819 }
3820 read_plane(
3821 dec,
3822 cdfs,
3823 chroma_set,
3824 chroma_scan,
3825 plane_idx,
3826 cu_around[plane_idx],
3827 mode,
3828 uv_predict_mode,
3829 angle_delta_uv,
3830 reach,
3831 y,
3832 u,
3833 v,
3834 cpx + cu_col * uw,
3835 cpy + cu_row * uh,
3836 uw,
3837 uw,
3838 base_q_idx,
3839 cfl,
3840 None,
3841 bigger.then_some(3),
3842 smooth_neighbor_uv,
3843 fctx,
3844 )?
3845 } else {
3846 let skip_ctx = usize::from(cu_around[plane_idx].0)
3847 + usize::from(cu_around[plane_idx].1)
3848 + usize::from(bigger) * 3;
3849 let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
3850 let (levels, tx_type) = read_chroma_coeffs_rect(
3851 dec,
3852 &mut coding,
3853 chroma_scan,
3854 uw,
3855 uh,
3856 skip_ctx,
3857 dc_sign_ctx(cu_around[plane_idx].2),
3858 TxType::DctDct,
3859 fctx,
3860 plane_idx,
3861 )?;
3862 let residual = dequant_and_inverse_typed_wh(
3863 &levels,
3864 uw,
3865 uh,
3866 crate::decode::bit_depth(fctx),
3867 block_q_idx(fctx),
3868 plane_q_delta(plane_idx, fctx).0,
3869 plane_q_delta(plane_idx, fctx).1,
3870 tx_type,
3871 block_iqmatrix(fctx, plane_idx, uw, uh, tx_type),
3872 );
3873 if let Some((ub, vb)) = &palette_uv_bufs {
3874 let pbuf = if plane_idx == 1 { ub } else { vb };
3875 set_palette_pred(
3876 palette_window(pbuf, chroma_w, cu_col * uw, cu_row * uh, uw, uh),
3877 fctx,
3878 );
3879 // Counted only when the window is a STRICT sub-slice of the
3880 // block's buffer, i.e. when the 32-cap actually tiled the
3881 // block: at nw * nh == 1 the window is a re-stride copy of
3882 // the whole buffer and windowing is load-bearing for
3883 // nothing. The `bigger` guard is what makes a hit PROOF
3884 // that the tiled arm ran, rather than proof that some
3885 // palette chroma block existed.
3886 if bigger {
3887 hit!(CHROMA_PALETTE_WINDOW_HITS);
3888 }
3889 }
3890 push_intra_rect(
3891 y,
3892 u,
3893 v,
3894 plane_idx,
3895 cpx + cu_col * uw,
3896 cpy + cu_row * uh,
3897 uw,
3898 uh,
3899 uv_predict_mode,
3900 angle_delta_uv,
3901 reach,
3902 &residual,
3903 cfl,
3904 None,
3905 smooth_neighbor_uv,
3906 fctx,
3907 );
3908 levels
3909 };
3910 let dst = if plane_idx == 1 {
3911 &mut u_levels
3912 } else {
3913 &mut v_levels
3914 };
3915 for row in 0..uh {
3916 let d = (cu_row * uh + row) * chroma_w + cu_col * uw;
3917 dst[d..d + uw].copy_from_slice(&levels[row * uw..][..uw]);
3918 }
3919 if bigger {
3920 neighbours.record_mi_chroma(
3921 (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)),
3922 lsx,
3923 lsy,
3924 plane_idx,
3925 &levels,
3926 );
3927 tiled_chroma_units.push((
3928 (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)),
3929 plane_idx,
3930 levels.clone(),
3931 lsx,
3932 lsy,
3933 ));
3934 }
3935 }
3936 }
3937 }
3938 neighbours.record_rect(
3939 at,
3940 bw,
3941 bh,
3942 mode,
3943 uv_predict_mode,
3944 &[&luma_levels[..], &u_levels[..], &v_levels[..]],
3945 );
3946 // The per-unit re-stamp: `record_rect` above wrote the whole strip's
3947 // chroma cells from the assembled grids' one whole-strip state,
3948 // overwriting exactly the stamps the tiled loop just made.
3949 for (cu_mi, plane, unit, span_w, span_h) in &tiled_chroma_units {
3950 neighbours.record_mi_chroma(*cu_mi, *span_w, *span_h, *plane, unit);
3951 }
3952 hit!(RECT_COEFF_HITS);
3953 }
3954 let (py_size, py_colors) = palette_y
3955 .as_ref()
3956 .map_or((0, [0u16; 8]), |p| (p.size, p.colors));
3957 neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, py_size, py_colors);
3958 let (puv_size, puv_colors) = palette_uv
3959 .as_ref()
3960 .map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
3961 neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, puv_size, puv_colors);
3962 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
3963 neighbours.fill_lf_grid_rect(
3964 (mi_r, mi_c),
3965 bw / MI,
3966 bh / MI,
3967 tx_w as u8,
3968 tx_h as u8,
3969 0,
3970 fctx,
3971 );
3972 // `set_txfm_ctxs(mbmi->tx_size, n4_w, n4_h, skip && is_inter, xd)`
3973 // (libaom `decode_token_recon_block`, run for EVERY block of an inter
3974 // frame): the above row records `tx_size_wide` over the block's width and
3975 // the left column `tx_size_high` over its height. This 1:4 strip reader is
3976 // also the INTER frame's reader for the shape ([`decode_intra_rect4_in_inter`]),
3977 // and it published neither band -- so the block after a 64x16 strip read
3978 // the row's init value 64 as its left transform height and took
3979 // `tx_size_cat3` row 1 where libaom takes row 0 (lane-frame36 r1: the
3980 // 3840x1608 10-bit stream's first silent wall, decode-order frame 33 at
3981 // mi(16,480)). Same write as [`set_txfm_ctxs`], rect-aware.
3982 txfm_partition_update_rect(neighbours, (mi_r, mi_c), (tx_w, tx_h), (bw, bh));
3983 hit!(SB_RECT_HITS);
3984 match (bw, bh) {
3985 (64, 16) => hit!(SB_RECT4_HORZ_HITS),
3986 (16, 64) => hit!(SB_RECT4_VERT_HITS),
3987 _ => {}
3988 }
3989 if crate::envflags::env_flag!("EC_AV1_TRACE") {
3990 let (rng, _) = dec.debug_state();
3991 eprintln!("TRACE_RECT64_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} rng={rng}");
3992 }
3993 Ok(())
3994}