forge
Explore
Log in

Don't you dare go Hollow

wip(av1): palette/intrabc syntax consumption (in progress, threading not finished)

Browse files at this commit

b46f7d8b74b41b581e84f5192fb6797b36efe9a1Ahmet Kaan GümüşParent: d393fb5
Committed by the orchestrator: the builder hit its turn cap mid-threading.
crates/ec-av1/src/cdf.rsmodified+46 -0
@@ -326,6 +326,52 @@ pub const FILTER_INTRA: [[u16; 3]; 4] = [
326 /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks.326 /// `FILTER_INTRA_MODES` a `use_filter_intra` block picks.
327 pub const FILTER_INTRA_MODE: [u16; 6] = [8949, 12776, 17211, 29558, 32768, 0];327 pub const FILTER_INTRA_MODE: [u16; 6] = [8949, 12776, 17211, 29558, 32768, 0];
328 328
329+/// `default_palette_y_size_cdf` (entropymode.c): `PALETTE_SIZES` (2..=8),
330+/// indexed by `av1_get_palette_bsize_ctx` (0..=6, `PALATTE_BSIZE_CTXS`).
331+pub const PALETTE_Y_SIZE: [[u16; 8]; 7] = [
332+ [7952, 13000, 18149, 21478, 25527, 29241, 32768, 0],
333+ [7139, 11421, 16195, 19544, 23666, 28073, 32768, 0],
334+ [7788, 12741, 17325, 20500, 24315, 28530, 32768, 0],
335+ [8271, 14064, 18246, 21564, 25071, 28533, 32768, 0],
336+ [12725, 19180, 21863, 24839, 27535, 30120, 32768, 0],
337+ [9711, 14888, 16923, 21052, 25661, 27875, 32768, 0],
338+ [14940, 20797, 21678, 24186, 27033, 28999, 32768, 0],
339+];
340+/// `default_palette_uv_size_cdf` (entropymode.c): as [`PALETTE_Y_SIZE`], for
341+/// the chroma plane's own palette size.
342+pub const PALETTE_UV_SIZE: [[u16; 8]; 7] = [
343+ [8713, 19979, 27128, 29609, 31331, 32272, 32768, 0],
344+ [5839, 15573, 23581, 26947, 29848, 31700, 32768, 0],
345+ [4426, 11260, 17999, 21483, 25863, 29430, 32768, 0],
346+ [3228, 9464, 14993, 18089, 22523, 27420, 32768, 0],
347+ [3768, 8886, 13091, 17852, 22495, 27207, 32768, 0],
348+ [2464, 8451, 12861, 21632, 25525, 28555, 32768, 0],
349+ [1269, 5435, 10433, 18963, 21700, 25865, 32768, 0],
350+];
351+/// `default_palette_y_mode_cdf` (entropymode.c): whether a `DC_PRED` block
352+/// uses a palette, indexed `[bsize_ctx][palette_mode_ctx]`
353+/// (`palette_mode_ctx` from `av1_get_palette_mode_ctx` -- this decoder never
354+/// completes a decode with a nonzero neighbour `palette_size`, so only row
355+/// `[.][0]` is ever read, but the whole table is here to match libaom's
356+/// adaptation shape exactly).
357+pub const PALETTE_Y_MODE: [[[u16; 3]; 3]; 7] = [
358+ [[31676, 32768, 0], [3419, 32768, 0], [1261, 32768, 0]],
359+ [[31912, 32768, 0], [2859, 32768, 0], [980, 32768, 0]],
360+ [[31823, 32768, 0], [3400, 32768, 0], [781, 32768, 0]],
361+ [[32030, 32768, 0], [3561, 32768, 0], [904, 32768, 0]],
362+ [[32309, 32768, 0], [7337, 32768, 0], [1462, 32768, 0]],
363+ [[32265, 32768, 0], [4015, 32768, 0], [1521, 32768, 0]],
364+ [[32450, 32768, 0], [7946, 32768, 0], [129, 32768, 0]],
365+];
366+/// `default_palette_uv_mode_cdf` (entropymode.c): whether a `UV_DC_PRED`
367+/// block uses a chroma palette, indexed by `palette_uv_mode_ctx` (whether
368+/// this block's own luma palette was used -- always 0 here, see
369+/// [`PALETTE_Y_MODE`]'s doc).
370+pub const PALETTE_UV_MODE: [[u16; 3]; 2] = [[32461, 32768, 0], [21488, 32768, 0]];
371+/// `default_intrabc_cdf` (entropymode.c): the `use_intrabc` flag on an
372+/// intra frame with `allow_intrabc` set.
373+pub const INTRABC: [u16; 3] = [30531, 32768, 0];
374+
329 /// `default_tx_size_cdf[0]` (entropymode.c): an 8x8 block's `tx_depth` flag375 /// `default_tx_size_cdf[0]` (entropymode.c): an 8x8 block's `tx_depth` flag
330 /// (`TX8` vs `TX4`), indexed by `tx_size_context` (0..=2).376 /// (`TX8` vs `TX4`), indexed by `tx_size_context` (0..=2).
331 pub const TX_SIZE_CAT0: [[u16; 3]; 3] = [[19968, 32768, 0], [19968, 32768, 0], [24320, 32768, 0]];377 pub const TX_SIZE_CAT0: [[u16; 3]; 3] = [[19968, 32768, 0], [19968, 32768, 0], [24320, 32768, 0]];
crates/ec-av1/src/cdf_state.rsmodified+21 -0
@@ -401,6 +401,17 @@ pub(crate) struct Cdfs {
401 /// A `SWITCHABLE`-filter inter block's own `interp_filter[dir]` -- see401 /// A `SWITCHABLE`-filter inter block's own `interp_filter[dir]` -- see
402 /// [`cdf::SWITCHABLE_INTERP`].402 /// [`cdf::SWITCHABLE_INTERP`].
403 pub switchable_interp: [[u16; 4]; 16],403 pub switchable_interp: [[u16; 4]; 16],
404+ /// A `DC_PRED` block's own palette-use flag -- see [`cdf::PALETTE_Y_MODE`].
405+ pub palette_y_mode: [[[u16; 3]; 3]; 7],
406+ /// A palette block's own size (2..=8) -- see [`cdf::PALETTE_Y_SIZE`].
407+ pub palette_y_size: [[u16; 8]; 7],
408+ /// A `UV_DC_PRED` block's own chroma palette-use flag -- see
409+ /// [`cdf::PALETTE_UV_MODE`].
410+ pub palette_uv_mode: [[u16; 3]; 2],
411+ /// A chroma palette block's own size -- see [`cdf::PALETTE_UV_SIZE`].
412+ pub palette_uv_size: [[u16; 8]; 7],
413+ /// The `use_intrabc` flag -- see [`cdf::INTRABC`].
414+ pub intrabc: [u16; 3],
404 }415 }
405 416
406 /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`,417 /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`,
@@ -615,6 +626,11 @@ impl Cdfs {
615 reset2(&mut self.tx_size_cat1);626 reset2(&mut self.tx_size_cat1);
616 reset2(&mut self.tx_size_cat2);627 reset2(&mut self.tx_size_cat2);
617 reset2(&mut self.tx_size_cat3);628 reset2(&mut self.tx_size_cat3);
629+ reset3(&mut self.palette_y_mode);
630+ reset2(&mut self.palette_y_size);
631+ reset2(&mut self.palette_uv_mode);
632+ reset2(&mut self.palette_uv_size);
633+ reset1(&mut self.intrabc);
618 }634 }
619 635
620 /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and636 /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and
@@ -1056,6 +1072,11 @@ impl Cdfs {
1056 tx_size_cat2: cdf::TX_SIZE_CAT2,1072 tx_size_cat2: cdf::TX_SIZE_CAT2,
1057 tx_size_cat3: cdf::TX_SIZE_CAT3,1073 tx_size_cat3: cdf::TX_SIZE_CAT3,
1058 switchable_interp: cdf::SWITCHABLE_INTERP,1074 switchable_interp: cdf::SWITCHABLE_INTERP,
1075+ palette_y_mode: cdf::PALETTE_Y_MODE,
1076+ palette_y_size: cdf::PALETTE_Y_SIZE,
1077+ palette_uv_mode: cdf::PALETTE_UV_MODE,
1078+ palette_uv_size: cdf::PALETTE_UV_SIZE,
1079+ intrabc: cdf::INTRABC,
1059 }1080 }
1060 }1081 }
1061 1082
crates/ec-av1/src/decode.rsmodified+82 -0
@@ -1533,6 +1533,22 @@ fn filter_intra_size_class(side: usize) -> Option<usize> {
1533 }1533 }
1534 }1534 }
1535 1535
1536+/// `av1_allow_palette`'s size bound (blockd.h: `block_size_wide/high <=
1537+/// MAX_PALETTE_BLOCK_WIDTH/HEIGHT` (64) and `sb_type >= BLOCK_8X8`) plus
1538+/// `av1_get_palette_bsize_ctx` (pred_common.h: `num_pels_log2_lookup[bsize]
1539+/// - num_pels_log2_lookup[BLOCK_8X8]`, i.e. `2*log2(side) - 6` for this
1540+/// decoder's square-only blocks) -- `None` past the bound (never gates a
1541+/// palette read), `Some(bsize_ctx)` otherwise.
1542+fn palette_bsize_ctx(side: usize) -> Option<usize> {
1543+ match side {
1544+ 8 => Some(0),
1545+ 16 => Some(2),
1546+ 32 => Some(4),
1547+ 64 => Some(6),
1548+ _ => None,
1549+ }
1550+}
1551+
1536 /// `read_angle_delta`/`Angle_Delta` (spec 5.11.42 + 9.3): the symbol minus1552 /// `read_angle_delta`/`Angle_Delta` (spec 5.11.42 + 9.3): the symbol minus
1537 /// [`ANGLE_DELTA_ZERO`] gives the signed `-MAX_ANGLE_DELTA..=MAX_ANGLE_DELTA`1553 /// [`ANGLE_DELTA_ZERO`] gives the signed `-MAX_ANGLE_DELTA..=MAX_ANGLE_DELTA`
1538 /// delta [`crate::intra::predict`] wants; bumps [`ANGLE_DELTA_HITS`] whenever1554 /// delta [`crate::intra::predict`] wants; bumps [`ANGLE_DELTA_HITS`] whenever
@@ -1553,6 +1569,8 @@ fn read_intra_mode(
1553 cfl: bool,1569 cfl: bool,
1554 side: usize,1570 side: usize,
1555 enable_filter_intra: bool,1571 enable_filter_intra: bool,
1572+ allow_screen_content_tools: bool,
1573+ allow_intrabc: bool,
1556 ) -> Result<(1574 ) -> Result<(
1557 bool,1575 bool,
1558 usize,1576 usize,
@@ -1567,6 +1585,26 @@ fn read_intra_mode(
1567 if trace {1585 if trace {
1568 eprintln!("TRACE skip value={}", skip as i32);1586 eprintln!("TRACE skip value={}", skip as i32);
1569 }1587 }
1588+ // `read_intrabc_info` (spec 5.11.13, libaom decodemv.c:693, called at
1589+ // :811 right after `skip_txfm`/`segment_id`/`cdef`/`delta_q` and before
1590+ // `mbmi->mode` is ever read): a `use_intrabc` symbol only present on an
1591+ // intra frame whose header set `allow_intrabc`. Actual intra block copy
1592+ // needs `assign_dv`'s own motion-vector-prediction machinery (`av1_find_mv_refs`,
1593+ // `av1_find_ref_dv`) this decoder does not carry -- lane-screen scope
1594+ // draws the line at consuming this one flag symbol and refusing by name
1595+ // when it fires, so the arithmetic decoder still resyncs for a stream
1596+ // that merely allows (but never uses) intrabc.
1597+ if allow_intrabc {
1598+ let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0;
1599+ if trace {
1600+ eprintln!("TRACE use_intrabc value={}", use_intrabc as i32);
1601+ }
1602+ if use_intrabc {
1603+ return Err(unsupported(
1604+ "a block that actually uses intrabc (this decoder never reconstructs one)",
1605+ ));
1606+ }
1607+ }
1570 let above_ctx = INTRA_MODE_CTX[above_mode];1608 let above_ctx = INTRA_MODE_CTX[above_mode];
1571 let left_ctx = INTRA_MODE_CTX[left_mode];1609 let left_ctx = INTRA_MODE_CTX[left_mode];
1572 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);1610 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
@@ -1619,6 +1657,32 @@ fn read_intra_mode(
1619 } else {1657 } else {
1620 01658 0
1621 };1659 };
1660+ // `read_palette_mode_info` (spec 5.11.13, libaom decodemv.c:567, called
1661+ // at :840 right after `xd->cfl.store_y` and before `read_filter_intra_mode_info`):
1662+ // gated by `av1_allow_palette` (blockd.h -- size bound only,
1663+ // [`palette_bsize_ctx`]). `palette_mode_ctx`/`palette_uv_mode_ctx`
1664+ // (`av1_get_palette_mode_ctx`, pred_common.h) read the neighbours' own
1665+ // `palette_size[0] > 0` -- always 0 here since a nonzero size refuses
1666+ // the whole decode below, so no successfully-completed decode ever has
1667+ // such a neighbour (corner-cut: hardcoded ctx 0 instead of tracking it,
1668+ // ceiling = real palette reconstruction, out of this lane's scope).
1669+ // A nonzero `palette_size` needs the color-cache/delta-coded-colors
1670+ // syntax this decoder does not reconstruct -- refuse by name rather
1671+ // than silently drop pixels.
1672+ if allow_screen_content_tools
1673+ && let Some(bsize_ctx) = palette_bsize_ctx(side)
1674+ {
1675+ if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 {
1676+ return Err(unsupported(
1677+ "a block that actually uses a palette (Y) -- reconstruction is out of scope",
1678+ ));
1679+ }
1680+ if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 {
1681+ return Err(unsupported(
1682+ "a block that actually uses a palette (UV) -- reconstruction is out of scope",
1683+ ));
1684+ }
1685+ }
1622 // `read_filter_intra_mode_info` (spec 5.11.14, libaom decodemv.c): a1686 // `read_filter_intra_mode_info` (spec 5.11.14, libaom decodemv.c): a
1623 // `use_filter_intra` symbol this decoder never read at all until1687 // `use_filter_intra` symbol this decoder never read at all until
1624 // lane-av1real r10 -- silently skipping it left every bit past a1688 // lane-av1real r10 -- silently skipping it left every bit past a
@@ -1991,6 +2055,8 @@ fn decode_block(
1991 v: &mut PlaneBuf,2055 v: &mut PlaneBuf,
1992 base_q_idx: u8,2056 base_q_idx: u8,
1993 enable_filter_intra: bool,2057 enable_filter_intra: bool,
2058+ allow_screen_content_tools: bool,
2059+ allow_intrabc: bool,
1994 scan32: &[u16],2060 scan32: &[u16],
1995 scan16: &[u16],2061 scan16: &[u16],
1996 scan8: &[u16],2062 scan8: &[u16],
@@ -2009,6 +2075,8 @@ fn decode_block(
2009 cfl,2075 cfl,
2010 side,2076 side,
2011 enable_filter_intra,2077 enable_filter_intra,
2078+ allow_screen_content_tools,
2079+ allow_intrabc,
2012 )?;2080 )?;
2013 // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED`2081 // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED`
2014 // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the2082 // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the
@@ -2297,6 +2365,8 @@ fn decode_leaf8(
2297 v: &mut PlaneBuf,2365 v: &mut PlaneBuf,
2298 base_q_idx: u8,2366 base_q_idx: u8,
2299 enable_filter_intra: bool,2367 enable_filter_intra: bool,
2368+ allow_screen_content_tools: bool,
2369+ allow_intrabc: bool,
2300 tx_select: bool,2370 tx_select: bool,
2301 reduced_tx_set: bool,2371 reduced_tx_set: bool,
2302 ) -> Result<usize> {2372 ) -> Result<usize> {
@@ -2322,6 +2392,8 @@ fn decode_leaf8(
2322 true,2392 true,
2323 8,2393 8,
2324 enable_filter_intra,2394 enable_filter_intra,
2395+ allow_screen_content_tools,
2396+ allow_intrabc,
2325 )?;2397 )?;
2326 let uv_predict_mode = if uv_mode == UV_CFL_PRED {2398 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
2327 DC_PRED2399 DC_PRED
@@ -3614,6 +3686,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
3614 &mut v,3686 &mut v,
3615 base_q_idx,3687 base_q_idx,
3616 enable_filter_intra,3688 enable_filter_intra,
3689+ allow_screen_content_tools,
3690+ allow_intrabc,
3617 &scan32,3691 &scan32,
3618 &scan16,3692 &scan16,
3619 &scan8,3693 &scan8,
@@ -3681,6 +3755,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
3681 &mut v,3755 &mut v,
3682 base_q_idx,3756 base_q_idx,
3683 enable_filter_intra,3757 enable_filter_intra,
3758+ allow_screen_content_tools,
3759+ allow_intrabc,
3684 &scan32,3760 &scan32,
3685 &scan16,3761 &scan16,
3686 &scan8,3762 &scan8,
@@ -3730,6 +3806,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
3730 &mut v,3806 &mut v,
3731 base_q_idx,3807 base_q_idx,
3732 enable_filter_intra,3808 enable_filter_intra,
3809+ allow_screen_content_tools,
3810+ allow_intrabc,
3733 &scan32,3811 &scan32,
3734 &scan16,3812 &scan16,
3735 &scan8,3813 &scan8,
@@ -3784,6 +3862,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
3784 &mut v,3862 &mut v,
3785 base_q_idx,3863 base_q_idx,
3786 enable_filter_intra,3864 enable_filter_intra,
3865+ allow_screen_content_tools,
3866+ allow_intrabc,
3787 tx_select,3867 tx_select,
3788 reduced_tx_set,3868 reduced_tx_set,
3789 )?;3869 )?;
@@ -3853,6 +3933,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
3853 &mut v,3933 &mut v,
3854 base_q_idx,3934 base_q_idx,
3855 enable_filter_intra,3935 enable_filter_intra,
3936+ allow_screen_content_tools,
3937+ allow_intrabc,
3856 tx_select,3938 tx_select,
3857 reduced_tx_set,3939 reduced_tx_set,
3858 )?;3940 )?;