forge
Explore
Log in

Don't you dare go Hollow

Decode_block_rect64 + wire PARTITION_HORZ/VERT at the 64x64 (SB) level

Browse files at this commit

cd6e1761d03d5e7588cdb0a89cce599a2375e07eAhmet Kaan GümüşParent: 61401f0
  • feat
    • decode_block_rect64 + wire PARTITION_HORZ/VERT at the 64x64 (SB) level
Show full message
feat(av1): decode_block_rect64 + wire PARTITION_HORZ/VERT at the 64x64 (SB) level
crates/ec-av1/src/decode.rsmodified+342 -0
@@ -465,6 +465,20 @@ pub(crate) fn rect_coeff_hits() -> usize {
465465 RECT_COEFF_HITS.with(|c| c.get())
466466 }
467467
468+// lane-sbpart r2: how many superblock-level `PARTITION_HORZ`/`PARTITION_VERT`
469+// blocks (two true 64x32/32x64 strips, [`decode_block_rect64`]) fired -- the
470+// gate's proof this round's arms actually reached a real block, not just
471+// that `partition_w64` read one of those two symbol values.
472+thread_local! {
473+ static SB_RECT_HITS: std::cell::Cell<usize> =
474+ const { std::cell::Cell::new(0) };
475+}
476+
477+/// Current value of [`SB_RECT_HITS`].
478+pub(crate) fn sb_rect_hits() -> usize {
479+ SB_RECT_HITS.with(|c| c.get())
480+}
481+
468482 // lane-partab r1: how many 32x32 quadrants decoded an AB partition
469483 // (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one
470484 // 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the
@@ -2569,6 +2583,267 @@ fn decode_block_rect(
25692583 Ok(())
25702584 }
25712585
2586+/// Decodes one true `bw`x`bh` superblock-level `PARTITION_HORZ`/
2587+/// `PARTITION_VERT` strip (lane-sbpart r2, `bw, bh` one of `(64, 32)` /
2588+/// `(32, 64)` -- [`decode_block_rect`]'s own sibling one level up). Unlike
2589+/// that 32x16/16x32 strip, both dimensions here exceed the 32-coefficient
2590+/// cap, so LUMA needs the same corner truncation [`decode_block`] already
2591+/// does for a plain 64x64 square (spec 5.11.40): `get_txsize_entropy_ctx`
2592+/// resolves TX_64X32/TX_32X64 to TX_64X64 regardless of orientation (see
2593+/// this function's own charter/report), so both strips read a real 32x32
2594+/// corner through [`read_coeffs`] with [`TxbSet::Luma64`]/[`SCAN_32`] and
2595+/// embed it top-left of a zeroed `bw`x`bh` grid, mirroring
2596+/// [`read_plane`]'s `tx_side != side` branch generalized to non-square.
2597+/// CHROMA (TX_32X16/TX_16X32) resolves to TX_32X32 -- a real, *untruncated*
2598+/// `bw/2`x`bh/2` transform via [`read_coeffs_rect`] with
2599+/// [`TxbSet::ChromaRect32x16`] and the matching [`SCAN_32X16`]/
2600+/// [`SCAN_16X32`], same as [`decode_block_rect`]'s own chroma path. Like
2601+/// that function, only the single-transform-unit (`tx_depth == 0`) case is
2602+/// supported: a split transform refuses by name rather than guess-decode.
2603+#[allow(clippy::too_many_arguments)]
2604+fn decode_block_rect64(
2605+ dec: &mut SymbolDecoder,
2606+ cdfs: &mut Cdfs,
2607+ neighbours: &mut Neighbours,
2608+ at: (usize, usize),
2609+ bw: usize,
2610+ bh: usize,
2611+ y: &mut PlaneBuf,
2612+ u: &mut PlaneBuf,
2613+ v: &mut PlaneBuf,
2614+ enable_filter_intra: bool,
2615+ allow_screen_content_tools: bool,
2616+ base_q_idx: u8,
2617+ tx_select: bool,
2618+) -> Result<()> {
2619+ let (r, c) = at;
2620+ let (px, py) = (c * SUB, r * SUB);
2621+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
2622+ read_intra_mode_rect(
2623+ dec,
2624+ cdfs,
2625+ neighbours.above_mode[c],
2626+ neighbours.left_mode[r],
2627+ true,
2628+ bw,
2629+ bh,
2630+ enable_filter_intra,
2631+ neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
2632+ allow_screen_content_tools,
2633+ r * (SUB / MI),
2634+ c * (SUB / MI),
2635+ )?;
2636+ let smooth_neighbor =
2637+ is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
2638+ if smooth_neighbor {
2639+ SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1));
2640+ }
2641+ let smooth_neighbor_uv =
2642+ is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]);
2643+ if filter_intra.is_some() {
2644+ // `filter_intra_size_class_rect` already returns `None` for both
2645+ // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at
2646+ // 32 on both axes), so this symbol is never read at this level --
2647+ // kept only as the same defensive refusal [`decode_block_rect`] has.
2648+ return Err(unsupported(
2649+ "filter intra on a superblock-level HORZ/VERT strip (never expected -- \
2650+ av1_filter_intra_allowed_bsize caps at 32x32)",
2651+ ));
2652+ }
2653+ let uv_predict_mode = if uv_mode == UV_CFL_PRED {
2654+ DC_PRED
2655+ } else {
2656+ uv_mode
2657+ };
2658+ let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2659+ let depth = if tx_select {
2660+ let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
2661+ dec.symbol(&mut cdfs.tx_size_cat2[ctx])
2662+ } else {
2663+ 0
2664+ };
2665+ if depth != 0 {
2666+ TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
2667+ return Err(unsupported(
2668+ "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \
2669+ prediction is not ported)",
2670+ ));
2671+ }
2672+ let (tx_w, tx_h) = (bw, bh);
2673+ let (cpx, cpy) = (px / 2, py / 2);
2674+ let (chroma_w, chroma_h) = (bw / 2, bh / 2);
2675+ let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
2676+ if skip {
2677+ y.reconstruct_rect(
2678+ px,
2679+ py,
2680+ bw,
2681+ bh,
2682+ mode,
2683+ angle_delta_y,
2684+ reach,
2685+ &vec![0i32; bw * bh],
2686+ None,
2687+ filter_intra,
2688+ smooth_neighbor,
2689+ );
2690+ let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
2691+ u.reconstruct_rect(
2692+ cpx,
2693+ cpy,
2694+ chroma_w,
2695+ chroma_h,
2696+ uv_predict_mode,
2697+ angle_delta_uv,
2698+ reach,
2699+ &vec![0i32; chroma_w * chroma_h],
2700+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
2701+ None,
2702+ smooth_neighbor_uv,
2703+ );
2704+ v.reconstruct_rect(
2705+ cpx,
2706+ cpy,
2707+ chroma_w,
2708+ chroma_h,
2709+ uv_predict_mode,
2710+ angle_delta_uv,
2711+ reach,
2712+ &vec![0i32; chroma_w * chroma_h],
2713+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
2714+ None,
2715+ smooth_neighbor_uv,
2716+ );
2717+ neighbours.record_rect(
2718+ at,
2719+ bw,
2720+ bh,
2721+ mode,
2722+ uv_predict_mode,
2723+ &[
2724+ vec![0i32; bw * bh],
2725+ vec![0i32; chroma_w * chroma_h],
2726+ vec![0i32; chroma_w * chroma_h],
2727+ ],
2728+ );
2729+ } else {
2730+ let around = neighbours.around_rect(at, bw, bh);
2731+ // LUMA: a real 32x32 corner, embedded top-left of the true bw x bh
2732+ // grid (see this function's own doc comment).
2733+ let scan32 = default_scan(TX32);
2734+ let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode);
2735+ let (luma_corner, luma_tx_type) = read_coeffs(
2736+ dec,
2737+ &mut luma_coding,
2738+ &scan32,
2739+ 0,
2740+ dc_sign_ctx(around[0].2),
2741+ TxType::DctDct,
2742+ )?;
2743+ let mut luma_levels = vec![0i32; bw * bh];
2744+ for row in 0..32 {
2745+ luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]);
2746+ }
2747+ let luma_residual = dequant_and_inverse_typed_wh(
2748+ &luma_levels,
2749+ bw,
2750+ bh,
2751+ 8,
2752+ i32::from(base_q_idx),
2753+ luma_tx_type,
2754+ );
2755+ y.reconstruct_rect(
2756+ px,
2757+ py,
2758+ bw,
2759+ bh,
2760+ mode,
2761+ angle_delta_y,
2762+ reach,
2763+ &luma_residual,
2764+ None,
2765+ filter_intra,
2766+ smooth_neighbor,
2767+ );
2768+ // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no
2769+ // corner crop needed (see doc comment).
2770+ let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
2771+ let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 };
2772+ let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
2773+ let mut u_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode);
2774+ let (u_levels, u_tx_type) = read_coeffs_rect(
2775+ dec,
2776+ &mut u_coding,
2777+ chroma_scan,
2778+ chroma_w,
2779+ chroma_h,
2780+ u_skip_ctx,
2781+ dc_sign_ctx(around[1].2),
2782+ TxType::DctDct,
2783+ )?;
2784+ let u_residual = dequant_and_inverse_typed_wh(
2785+ &u_levels,
2786+ chroma_w,
2787+ chroma_h,
2788+ 8,
2789+ i32::from(base_q_idx),
2790+ u_tx_type,
2791+ );
2792+ u.reconstruct_rect(
2793+ cpx,
2794+ cpy,
2795+ chroma_w,
2796+ chroma_h,
2797+ uv_predict_mode,
2798+ angle_delta_uv,
2799+ reach,
2800+ &u_residual,
2801+ alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
2802+ None,
2803+ smooth_neighbor_uv,
2804+ );
2805+ let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
2806+ let mut v_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode);
2807+ let (v_levels, v_tx_type) = read_coeffs_rect(
2808+ dec,
2809+ &mut v_coding,
2810+ chroma_scan,
2811+ chroma_w,
2812+ chroma_h,
2813+ v_skip_ctx,
2814+ dc_sign_ctx(around[2].2),
2815+ TxType::DctDct,
2816+ )?;
2817+ let v_residual = dequant_and_inverse_typed_wh(
2818+ &v_levels,
2819+ chroma_w,
2820+ chroma_h,
2821+ 8,
2822+ i32::from(base_q_idx),
2823+ v_tx_type,
2824+ );
2825+ v.reconstruct_rect(
2826+ cpx,
2827+ cpy,
2828+ chroma_w,
2829+ chroma_h,
2830+ uv_predict_mode,
2831+ angle_delta_uv,
2832+ reach,
2833+ &v_residual,
2834+ alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
2835+ None,
2836+ smooth_neighbor_uv,
2837+ );
2838+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]);
2839+ RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
2840+ }
2841+ neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
2842+ neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
2843+ SB_RECT_HITS.with(|c| c.set(c.get() + 1));
2844+ Ok(())
2845+}
2846+
25722847 /// `read_angle_delta`/`Angle_Delta` (spec 5.11.42 + 9.3): the symbol minus
25732848 /// [`ANGLE_DELTA_ZERO`] gives the signed `-MAX_ANGLE_DELTA..=MAX_ANGLE_DELTA`
25742849 /// delta [`crate::intra::predict`] wants; bumps [`ANGLE_DELTA_HITS`] whenever
@@ -5289,6 +5564,73 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
52895564 }
52905565 }
52915566 }
5567+ PARTITION_HORZ => {
5568+ // lane-sbpart r2: two true 64x32 strips.
5569+ decode_block_rect64(
5570+ &mut dec,
5571+ &mut cdfs,
5572+ &mut neighbours,
5573+ at,
5574+ 64,
5575+ 32,
5576+ &mut y,
5577+ &mut u,
5578+ &mut v,
5579+ enable_filter_intra,
5580+ allow_screen_content_tools,
5581+ base_q_idx,
5582+ tx_select,
5583+ )?;
5584+ decode_block_rect64(
5585+ &mut dec,
5586+ &mut cdfs,
5587+ &mut neighbours,
5588+ (at.0 + 2, at.1),
5589+ 64,
5590+ 32,
5591+ &mut y,
5592+ &mut u,
5593+ &mut v,
5594+ enable_filter_intra,
5595+ allow_screen_content_tools,
5596+ base_q_idx,
5597+ tx_select,
5598+ )?;
5599+ }
5600+ PARTITION_VERT => {
5601+ // lane-sbpart r2: mirror of PARTITION_HORZ above with
5602+ // width/height swapped.
5603+ decode_block_rect64(
5604+ &mut dec,
5605+ &mut cdfs,
5606+ &mut neighbours,
5607+ at,
5608+ 32,
5609+ 64,
5610+ &mut y,
5611+ &mut u,
5612+ &mut v,
5613+ enable_filter_intra,
5614+ allow_screen_content_tools,
5615+ base_q_idx,
5616+ tx_select,
5617+ )?;
5618+ decode_block_rect64(
5619+ &mut dec,
5620+ &mut cdfs,
5621+ &mut neighbours,
5622+ (at.0, at.1 + 2),
5623+ 32,
5624+ 64,
5625+ &mut y,
5626+ &mut u,
5627+ &mut v,
5628+ enable_filter_intra,
5629+ allow_screen_content_tools,
5630+ base_q_idx,
5631+ tx_select,
5632+ )?;
5633+ }
52925634 _ => {
52935635 return Err(unsupported(
52945636 "a superblock-level partition type other than NONE or SPLIT (this \