Wire reduced_tx_set=false inter tx_type gating through decode
Browse files at this commit8cc4428d650eff2a92b749747d49de160d737a80Parent: 8dbd683- feat
- wire reduced_tx_set=false inter tx_type gating through decode
3 changed files +26 -41
- crates/ec-av1/src/decode.rs +25 -29
- crates/ec-av1/src/msac.rs +0 -12
- crates/ec-av1/src/stream.rs +1 -0
crates/ec-av1/src/decode.rsmodified+25 -29
| @@ -2493,30 +2493,6 @@ fn cdef_filter_block( | |||
| 2493 | /// size. `cdef_bits == 0` is this crate's only supported case so far (see the | 2493 | /// size. `cdef_bits == 0` is this crate's only supported case so far (see the |
| 2494 | /// refusal in `stream.rs`), so every 64x64 filter block always uses index 0's | 2494 | /// refusal in `stream.rs`), so every 64x64 filter block always uses index 0's |
| 2495 | /// strengths -- no per-block `cdef_idx` selection is implemented yet. | 2495 | /// strengths -- no per-block `cdef_idx` selection is implemented yet. |
| 2496 | -/// bisect scratch (lane-cdffwd2): dump this frame's Y/U/V exactly the way | ||
| 2497 | -/// the instrumented `aomdec` build's `EC_AV1_PREFILT_DUMP` does (raw | ||
| 2498 | -/// `true_width`x`true_height` bytes per plane, decode order, one file per | ||
| 2499 | -/// frame index), gated on env so it is zero-cost/zero-behavior off. Called | ||
| 2500 | -/// from both the key-frame and inter-frame tile decoders so the frame index | ||
| 2501 | -/// lines up with aomdec's own (which dumps unconditionally every frame). | ||
| 2502 | -fn scratch_dump_prefilt(y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { | ||
| 2503 | - let Some(base) = std::env::var_os("EC_AV1_PREFILT_DUMP_OURS") else { | ||
| 2504 | - return; | ||
| 2505 | - }; | ||
| 2506 | - use std::sync::atomic::{AtomicUsize, Ordering}; | ||
| 2507 | - static IDX: AtomicUsize = AtomicUsize::new(0); | ||
| 2508 | - let idx = IDX.fetch_add(1, Ordering::SeqCst); | ||
| 2509 | - let path = format!("{}.f{}", base.to_string_lossy(), idx); | ||
| 2510 | - let mut out = Vec::new(); | ||
| 2511 | - for plane in [y, u, v] { | ||
| 2512 | - for row in 0..plane.true_height { | ||
| 2513 | - let start = row * plane.width; | ||
| 2514 | - out.extend_from_slice(&plane.data[start..start + plane.true_width]); | ||
| 2515 | - } | ||
| 2516 | - } | ||
| 2517 | - let _ = std::fs::write(path, out); | ||
| 2518 | -} | ||
| 2519 | - | ||
| 2520 | /// Spec 7.14: the in-loop deblocking filter, applied once per frame after | 2496 | /// Spec 7.14: the in-loop deblocking filter, applied once per frame after |
| 2521 | /// tile reconstruction and before [`apply_cdef`]. Uniform-level path only -- | 2497 | /// tile reconstruction and before [`apply_cdef`]. Uniform-level path only -- |
| 2522 | /// `stream.rs` already refuses `delta_lf_present`/segmentation upstream, so | 2498 | /// `stream.rs` already refuses `delta_lf_present`/segmentation upstream, so |
| @@ -3620,7 +3596,6 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 3620 | } | 3596 | } |
| 3621 | } | 3597 | } |
| 3622 | 3598 | ||
| 3623 | - scratch_dump_prefilt(&y, &u, &v); | ||
| 3624 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | 3599 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); |
| 3625 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); | 3600 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 3626 | 3601 | ||
| @@ -5428,6 +5403,9 @@ fn decode_inter_block8( | |||
| 5428 | // just above). | 5403 | // just above). |
| 5429 | skip_mode_present: bool, | 5404 | skip_mode_present: bool, |
| 5430 | skip_mode_frame: [u8; 2], | 5405 | skip_mode_frame: [u8; 2], |
| 5406 | + // lane-cdffwd2: this frame header's own `reduced_tx_set` bit -- see | ||
| 5407 | + // [`decode_inter_frame_tile_with_cdfs`]'s own doc. | ||
| 5408 | + reduced_tx_set: bool, | ||
| 5431 | // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a | 5409 | // lane-av1comp: `Some((ref1, comp_group_idx, compound_idx))` only for a |
| 5432 | // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16 | 5410 | // real `COMPOUND_REFERENCE` leaf, for the caller's own end-of-16x16 |
| 5433 | // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own | 5411 | // `record_compound_ctx` call -- mirrors [`decode_inter_block`]'s own |
| @@ -5751,7 +5729,11 @@ fn decode_inter_block8( | |||
| 5751 | luma_grid = read_inter_plane( | 5729 | luma_grid = read_inter_plane( |
| 5752 | dec, | 5730 | dec, |
| 5753 | cdfs, | 5731 | cdfs, |
| 5754 | - TxbSet::Luma8Inter, | 5732 | + if reduced_tx_set { |
| 5733 | + TxbSet::Luma8Inter | ||
| 5734 | + } else { | ||
| 5735 | + TxbSet::Luma8InterSet1 | ||
| 5736 | + }, | ||
| 5755 | scan8, | 5737 | scan8, |
| 5756 | 0, | 5738 | 0, |
| 5757 | around[0], | 5739 | around[0], |
| @@ -5945,7 +5927,11 @@ fn decode_inter_block8( | |||
| 5945 | luma_grid = read_inter_plane( | 5927 | luma_grid = read_inter_plane( |
| 5946 | dec, | 5928 | dec, |
| 5947 | cdfs, | 5929 | cdfs, |
| 5948 | - TxbSet::Luma8Inter, | 5930 | + if reduced_tx_set { |
| 5931 | + TxbSet::Luma8Inter | ||
| 5932 | + } else { | ||
| 5933 | + TxbSet::Luma8InterSet1 | ||
| 5934 | + }, | ||
| 5949 | scan8, | 5935 | scan8, |
| 5950 | 0, | 5936 | 0, |
| 5951 | around[0], | 5937 | around[0], |
| @@ -6193,6 +6179,7 @@ pub fn decode_inter_frame_tile( | |||
| 6193 | false, | 6179 | false, |
| 6194 | false, | 6180 | false, |
| 6195 | [0; 2], | 6181 | [0; 2], |
| 6182 | + true, | ||
| 6196 | ) | 6183 | ) |
| 6197 | .map(|(picture, _, _)| picture) | 6184 | .map(|(picture, _, _)| picture) |
| 6198 | } | 6185 | } |
| @@ -6238,6 +6225,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 6238 | // `decode_inter_block8` call below. | 6225 | // `decode_inter_block8` call below. |
| 6239 | skip_mode_present: bool, | 6226 | skip_mode_present: bool, |
| 6240 | skip_mode_frame: [u8; 2], | 6227 | skip_mode_frame: [u8; 2], |
| 6228 | + // lane-cdffwd2: this frame header's own `reduced_tx_set` bit, threaded to | ||
| 6229 | + // every inter `tx_type` read below (`false` needs the 12-/16-symbol | ||
| 6230 | + // `Set1` coefficient tables at 16x16/8x8 rather than the reduced | ||
| 6231 | + // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]). | ||
| 6232 | + reduced_tx_set: bool, | ||
| 6241 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { | 6233 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { |
| 6242 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { | 6234 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { |
| 6243 | field, | 6235 | field, |
| @@ -6489,7 +6481,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 6489 | &sign_bias_table, | 6481 | &sign_bias_table, |
| 6490 | base_q_idx, | 6482 | base_q_idx, |
| 6491 | TxbSet::Luma16, | 6483 | TxbSet::Luma16, |
| 6492 | - TxbSet::Luma16Inter, | 6484 | + if reduced_tx_set { |
| 6485 | + TxbSet::Luma16Inter | ||
| 6486 | + } else { | ||
| 6487 | + TxbSet::Luma16InterSet1 | ||
| 6488 | + }, | ||
| 6493 | TxbSet::Chroma8, | 6489 | TxbSet::Chroma8, |
| 6494 | TX16, | 6490 | TX16, |
| 6495 | TX8, | 6491 | TX8, |
| @@ -6569,6 +6565,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 6569 | ref_order_hints, | 6565 | ref_order_hints, |
| 6570 | skip_mode_present, | 6566 | skip_mode_present, |
| 6571 | skip_mode_frame, | 6567 | skip_mode_frame, |
| 6568 | + reduced_tx_set, | ||
| 6572 | )?; | 6569 | )?; |
| 6573 | prev_leaf = Some((leaf_mi, skip, is_inter)); | 6570 | prev_leaf = Some((leaf_mi, skip, is_inter)); |
| 6574 | last_skip_mode = skip_mode_leaf; | 6571 | last_skip_mode = skip_mode_leaf; |
| @@ -6622,7 +6619,6 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 6622 | } | 6619 | } |
| 6623 | } | 6620 | } |
| 6624 | 6621 | ||
| 6625 | - scratch_dump_prefilt(&y, &u, &v); | ||
| 6626 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | 6622 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); |
| 6627 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); | 6623 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 6628 | 6624 | ||
crates/ec-av1/src/msac.rsmodified+0 -12
| @@ -303,9 +303,6 @@ impl<'a> SymbolDecoder<'a> { | |||
| 303 | let mut cur = self.range; | 303 | let mut cur = self.range; |
| 304 | let mut prev; | 304 | let mut prev; |
| 305 | let mut symbol = 0; | 305 | let mut symbol = 0; |
| 306 | - // bisect scratch (lane-cdffwd2): rng_before, matching libaom | ||
| 307 | - // entdec.c's own EC_RNG trace field of the same name. | ||
| 308 | - let rng_before = self.range; | ||
| 309 | loop { | 306 | loop { |
| 310 | prev = cur; | 307 | prev = cur; |
| 311 | let f = u32::from(CDF_TOP - cdf[symbol]); | 308 | let f = u32::from(CDF_TOP - cdf[symbol]); |
| @@ -318,15 +315,6 @@ impl<'a> SymbolDecoder<'a> { | |||
| 318 | } | 315 | } |
| 319 | self.range = prev - cur; | 316 | self.range = prev - cur; |
| 320 | self.value -= cur; | 317 | self.value -= cur; |
| 321 | - if std::env::var_os("EC_RNG").is_some() { | ||
| 322 | - use std::sync::atomic::{AtomicU64, Ordering}; | ||
| 323 | - static N: AtomicU64 = AtomicU64::new(0); | ||
| 324 | - let n = N.fetch_add(1, Ordering::SeqCst); | ||
| 325 | - eprintln!( | ||
| 326 | - "EC_RNG n={n} rng_before={rng_before} rng_after={} nsyms={nsyms} symbol={symbol}", | ||
| 327 | - self.range | ||
| 328 | - ); | ||
| 329 | - } | ||
| 330 | 318 | ||
| 331 | // Renormalise back into `[2^15, 2^16)`, the same shift the encoder | 319 | // Renormalise back into `[2^15, 2^16)`, the same shift the encoder |
| 332 | // applied when it narrowed to this symbol. | 320 | // applied when it narrowed to this symbol. |
crates/ec-av1/src/stream.rsmodified+1 -0
| @@ -378,6 +378,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 378 | enable_jnt_comp, | 378 | enable_jnt_comp, |
| 379 | header.skip_mode_present, | 379 | header.skip_mode_present, |
| 380 | header.skip_mode_frame, | 380 | header.skip_mode_frame, |
| 381 | + header.reduced_tx_set, | ||
| 381 | )? | 382 | )? |
| 382 | }; | 383 | }; |
| 383 | // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's | 384 | // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's |