forge
Explore
Log in

Don't you dare go Hollow

Wire read_lr into both SB loops

Browse files at this commit

dc215f73dd0570ea92b2ffa15af5e21cd62c0e72Ahmet Kaan GümüşParent: 4c75e5c
  • feat
    • wire read_lr into both SB loops
    • narrow the whole-frame LR refusal to 'filters not applied'
Show full message
feat(av1): wire read_lr into both SB loops; narrow the whole-frame LR refusal to 'filters not applied'

decode_key_frame_tile_with_cdfs/decode_inter_frame_tile_with_cdfs now take
&LoopRestorationParams and call crate::restoration::read_lr once per
superblock, before decode_partition, storing per-unit Wiener/SGR filters
into a per-plane RestorationGrid (never yet applied to pixels). Public
one-star wrappers pass &LoopRestorationParams::default() unchanged.
stream.rs threads header.loop_restoration through both call sites; the
refusal string is renamed to name the true remaining gap (pixel filters
not applied) now that the partition walk survives a real LR stream.
235 passed / 0 failed (232 baseline + 3 new subexp/recenter tests),
EC_AV1_REQUIRE_AOMENC=1.
crates/ec-av1/src/decode.rsmodified+35 -1
@@ -21,7 +21,7 @@
2121 //! too). Anything outside that refuses with [`Error::unsupported`] rather than
2222 //! silently miscoding.
2323
24-use ec_av1_syntax::{CdefParams, LoopFilterParams};
24+use ec_av1_syntax::{CdefParams, LoopFilterParams, LoopRestorationParams};
2525 use ec_core::{Error, Result};
2626
2727 use crate::cdf;
@@ -4458,6 +4458,7 @@ pub fn decode_key_frame_tile(
44584458 false,
44594459 cdef,
44604460 loop_filter,
4461+ &LoopRestorationParams::default(),
44614462 None,
44624463 tx_select,
44634464 reduced_tx_set,
@@ -4486,6 +4487,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
44864487 enable_edge_filter: bool,
44874488 cdef: &CdefParams,
44884489 loop_filter: &LoopFilterParams,
4490+ lr: &LoopRestorationParams,
44894491 initial_cdfs: Option<Cdfs>,
44904492 tx_select: bool,
44914493 reduced_tx_set: bool,
@@ -4543,10 +4545,25 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
45434545 mi_cols as usize,
45444546 mi_rows as usize,
45454547 );
4548+ let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height);
4549+ let mut lr_reference = [(
4550+ crate::restoration::WienerInfo::default(),
4551+ crate::restoration::SgrprojInfo::default(),
4552+ ); 3];
45464553
45474554 for sb_r in 0..sb_rows {
45484555 neighbours.start_row();
45494556 for sb_c in 0..sb_cols {
4557+ crate::restoration::read_lr(
4558+ &mut dec,
4559+ &mut cdfs,
4560+ lr,
4561+ &mut lr_grid,
4562+ &mut lr_reference,
4563+ sb_r * SB_MI,
4564+ sb_c * SB_MI,
4565+ SB_MI,
4566+ );
45504567 let at = (sb_r as usize * 4, sb_c as usize * 4);
45514568 let ctx = neighbours.partition_ctx(at, SB);
45524569 let (has_cols, has_rows) = (
@@ -9055,6 +9072,7 @@ pub fn decode_inter_frame_tile(
90559072 other_refs,
90569073 cdef,
90579074 loop_filter,
9075+ &LoopRestorationParams::default(),
90589076 None,
90599077 allow_high_precision_mv,
90609078 force_integer_mv,
@@ -9096,6 +9114,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
90969114 other_refs: [Option<&Picture>; 8],
90979115 cdef: &CdefParams,
90989116 loop_filter: &LoopFilterParams,
9117+ lr: &LoopRestorationParams,
90999118 initial_cdfs: Option<Cdfs>,
91009119 allow_high_precision_mv: bool,
91019120 force_integer_mv: bool,
@@ -9271,10 +9290,25 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
92719290 mi_rows as usize,
92729291 );
92739292 let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize);
9293+ let mut lr_grid = crate::restoration::RestorationGrid::new(lr, frame_width, frame_height);
9294+ let mut lr_reference = [(
9295+ crate::restoration::WienerInfo::default(),
9296+ crate::restoration::SgrprojInfo::default(),
9297+ ); 3];
92749298
92759299 for sb_r in 0..sb_rows {
92769300 neighbours.start_row();
92779301 for sb_c in 0..sb_cols {
9302+ crate::restoration::read_lr(
9303+ &mut dec,
9304+ &mut cdfs,
9305+ lr,
9306+ &mut lr_grid,
9307+ &mut lr_reference,
9308+ sb_r * SB_MI,
9309+ sb_c * SB_MI,
9310+ SB_MI,
9311+ );
92789312 let sb_at = (sb_r as usize * 4, sb_c as usize * 4);
92799313 let sb_ctx = neighbours.partition_ctx(sb_at, SB);
92809314 let (has_cols, has_rows) = (
crates/ec-av1/src/stream.rsmodified+8 -1
@@ -191,10 +191,15 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
191191 // silent-desync shape as the refusals above. Traced live 2026-08-27:
192192 // an aomenc inter frame with `Sgrproj` on the V plane desynced the
193193 // partition walk into out-of-alphabet garbage.
194+ // lane-lr r2: the per-superblock `read_lr`/`read_lr_unit` symbols are
195+ // now read (`crate::restoration`) and no longer desync the partition
196+ // walk -- the refusal narrows to its true remaining gap: decoded
197+ // Wiener/SGR filters are stored per unit but never applied to
198+ // pixels.
194199 if header.loop_restoration.uses_lr {
195200 return Err(Error::unsupported(
196201 "AV1 decode_stream",
197- "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)",
202+ "a frame with loop restoration enabled (the per-unit lr symbols are read but the Wiener/self-guided filters are not yet applied to pixels)",
198203 ));
199204 }
200205 // `decode_inter_block`/`decode_inter_block8`'s `GLOBALMV` arm (spec
@@ -370,6 +375,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
370375 enable_edge_filter,
371376 &header.cdef,
372377 &header.loop_filter,
378+ &header.loop_restoration,
373379 initial_cdfs,
374380 header.tx_mode == TxMode::Select,
375381 header.reduced_tx_set,
@@ -437,6 +443,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
437443 other_refs,
438444 &header.cdef,
439445 &header.loop_filter,
446+ &header.loop_restoration,
440447 initial_cdfs,
441448 header.allow_high_precision_mv,
442449 header.force_integer_mv,