forge
Explore
Log in

Don't you dare go Hollow

wip(av1): dkey lane snapshot at the turn cap (orchestrator)

Browse files at this commit

8c864700ca1cb797bbef6732245ccedb331a06c7Ahmet Kaan GümüşParent: edaf368
crates/ec-av1/src/decode.rsmodified+80 -0
@@ -15718,6 +15718,19 @@ fn decode_leaf_split4(
15718 neighbours.above[leaf_mi.1 + cell][2] = v_state;15718 neighbours.above[leaf_mi.1 + cell][2] = v_state;
15719 }15719 }
15720 }15720 }
15721+ // lane-dkey: a sub-8x8 leaf can never use palette (`av1_allow_palette`
15722+ // needs BLOCK_8X8 and up), and libaom's mi grid says so -- its
15723+ // `palette_size` is 0 in every one of these mi cells, so the NEXT block's
15724+ // `av1_get_palette_mode_ctx` and colour cache read 0 here. This decoder
15725+ // only ever WROTE palette state from the >=8x8 readers, so an 8x8 palette
15726+ // block above a 4x4 group left its size/colours standing in the mi-granular
15727+ // bands: the block below the group read `palette_y_mode` off CDF row 1
15728+ // where libaom reads row 0 (class [[cdf-row-held-constant]]), decoded a
15729+ // palette libaom never coded, and then skipped the `use_filter_intra`
15730+ // symbol that a palette block has none of -- one symbol short, tile
15731+ // desynced. Publishing the group's own zeros is the clear.
15732+ neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
15733+ neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
15721 Ok((leaf_modes[2], leaf_modes[1]))15734 Ok((leaf_modes[2], leaf_modes[1]))
15722 }15735 }
15723 15736
@@ -16078,6 +16091,19 @@ fn decode_leaf_rect8(
16078 neighbours.above[leaf_mi.1 + cell][2] = v_state;16091 neighbours.above[leaf_mi.1 + cell][2] = v_state;
16079 }16092 }
16080 }16093 }
16094+ // lane-dkey (same clear as `decode_leaf_split4`): a sub-8x8 leaf can never use palette (`av1_allow_palette`
16095+ // needs BLOCK_8X8 and up), and libaom's mi grid says so -- its
16096+ // `palette_size` is 0 in every one of these mi cells, so the NEXT block's
16097+ // `av1_get_palette_mode_ctx` and colour cache read 0 here. This decoder
16098+ // only ever WROTE palette state from the >=8x8 readers, so an 8x8 palette
16099+ // block above a 4x4 group left its size/colours standing in the mi-granular
16100+ // bands: the block below the group read `palette_y_mode` off CDF row 1
16101+ // where libaom reads row 0 (class [[cdf-row-held-constant]]), decoded a
16102+ // palette libaom never coded, and then skipped the `use_filter_intra`
16103+ // symbol that a palette block has none of -- one symbol short, tile
16104+ // desynced. Publishing the group's own zeros is the clear.
16105+ neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
16106+ neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
16081 // `(below_mode, right_mode)`: the sub-block a neighbour below sees is the16107 // `(below_mode, right_mode)`: the sub-block a neighbour below sees is the
16082 // bottom one (the second under HORZ, the left one under VERT), the one a16108 // bottom one (the second under HORZ, the left one under VERT), the one a
16083 // neighbour to the right sees is the top-right (the second under VERT).16109 // neighbour to the right sees is the top-right (the second under VERT).
@@ -29588,6 +29614,15 @@ fn decode_inter_block(
29588 write_h / MI,29614 write_h / MI,
29589 skip,29615 skip,
29590 );29616 );
29617+ // lane-dkey sweep: an INTER block (and every sub-8x8 leaf) has
29618+ // `palette_size == 0` in libaom's mi grid, so the next block's
29619+ // `av1_get_palette_mode_ctx`/colour cache must read 0 across this
29620+ // footprint. Only the >=8x8 intra readers published palette state, so a
29621+ // palette block's size/colours stayed standing in the mi-granular bands
29622+ // and a later intra block read `palette_y_mode` off the wrong CDF row
29623+ // (class [[cdf-row-held-constant]]).
29624+ neighbours.record_palette_y_rect((rmi, cmi), write_w, write_h, 0, [0u16; 8]);
29625+ neighbours.record_palette_uv_rect((rmi, cmi), write_w, write_h, 0, [0u16; 8]);
29591 neighbours.fill_lf_grid_rect(29626 neighbours.fill_lf_grid_rect(
29592 (rmi, cmi),29627 (rmi, cmi),
29593 write_w / MI,29628 write_w / MI,
@@ -30072,6 +30107,15 @@ fn decode_inter_sub8_split4(
30072 // var-tx context instead of leaving whatever the previous block left.30107 // var-tx context instead of leaving whatever the previous block left.
30073 set_txfm_ctxs(neighbours, lmi, B4, 1, 1, false);30108 set_txfm_ctxs(neighbours, lmi, B4, 1, 1, false);
30074 neighbours.fill_skip_grid_rect(lmi, 1, 1, skip);30109 neighbours.fill_skip_grid_rect(lmi, 1, 1, skip);
30110+ // lane-dkey sweep: an INTER block (and every sub-8x8 leaf) has
30111+ // `palette_size == 0` in libaom's mi grid, so the next block's
30112+ // `av1_get_palette_mode_ctx`/colour cache must read 0 across this
30113+ // footprint. Only the >=8x8 intra readers published palette state, so a
30114+ // palette block's size/colours stayed standing in the mi-granular bands
30115+ // and a later intra block read `palette_y_mode` off the wrong CDF row
30116+ // (class [[cdf-row-held-constant]]).
30117+ neighbours.record_palette_y_rect(lmi, MI, MI, 0, [0u16; 8]);
30118+ neighbours.record_palette_uv_rect(lmi, MI, MI, 0, [0u16; 8]);
30075 neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME), fctx);30119 neighbours.fill_lf_grid_rect(lmi, 1, 1, B4 as u8, B4 as u8, ref_frame.max(LAST_FRAME), fctx);
30076 last_skip = skip;30120 last_skip = skip;
30077 }30121 }
@@ -30529,6 +30573,15 @@ fn decode_intra_sub8_leaf(
30529 }30573 }
30530 let (tx_w, tx_h) = if split { (4, 4) } else { (bw, bh) };30574 let (tx_w, tx_h) = if split { (4, 4) } else { (bw, bh) };
30531 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);30575 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
30576+ // lane-dkey sweep: an INTER block (and every sub-8x8 leaf) has
30577+ // `palette_size == 0` in libaom's mi grid, so the next block's
30578+ // `av1_get_palette_mode_ctx`/colour cache must read 0 across this
30579+ // footprint. Only the >=8x8 intra readers published palette state, so a
30580+ // palette block's size/colours stayed standing in the mi-granular bands
30581+ // and a later intra block read `palette_y_mode` off the wrong CDF row
30582+ // (class [[cdf-row-held-constant]]).
30583+ neighbours.record_palette_y_rect(lmi, w_mi * MI, h_mi * MI, 0, [0u16; 8]);
30584+ neighbours.record_palette_uv_rect(lmi, w_mi * MI, h_mi * MI, 0, [0u16; 8]);
30532 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w as u8, tx_h as u8, 0, fctx);30585 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w as u8, tx_h as u8, 0, fctx);
30533 // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter == 0, xd)`: an30586 // `set_txfm_ctxs(tx_size, n4_w, n4_h, skip && is_inter == 0, xd)`: an
30534 // intra block of an inter frame publishes its TRANSFORM dims, never its30587 // intra block of an inter frame publishes its TRANSFORM dims, never its
@@ -31142,6 +31195,15 @@ fn decode_inter_sub8_rect2(
31142 neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED);31195 neighbours.record_mode_mi(rmi, cmi, w_mi, h_mi, DC_PRED);
31143 neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false);31196 neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, true, ref_frame, resolved_filter, false);
31144 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);31197 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
31198+ // lane-dkey sweep: an INTER block (and every sub-8x8 leaf) has
31199+ // `palette_size == 0` in libaom's mi grid, so the next block's
31200+ // `av1_get_palette_mode_ctx`/colour cache must read 0 across this
31201+ // footprint. Only the >=8x8 intra readers published palette state, so a
31202+ // palette block's size/colours stayed standing in the mi-granular bands
31203+ // and a later intra block read `palette_y_mode` off the wrong CDF row
31204+ // (class [[cdf-row-held-constant]]).
31205+ neighbours.record_palette_y_rect(lmi, w_mi * MI, h_mi * MI, 0, [0u16; 8]);
31206+ neighbours.record_palette_uv_rect(lmi, w_mi * MI, h_mi * MI, 0, [0u16; 8]);
31145 last_skip = skip;31207 last_skip = skip;
31146 }31208 }
31147 // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded31209 // lane-sub8intra: when the chroma-reference sub-block was INTRA it coded
@@ -32244,6 +32306,15 @@ fn decode_inter_block8(
32244 // dlist excludes it (3 luma samples on a 192x128 inter frame).32306 // dlist excludes it (3 luma samples on a 192x128 inter frame).
32245 hit!(INTER8_SKIP_BAND_HITS);32307 hit!(INTER8_SKIP_BAND_HITS);
32246 neighbours.fill_skip_grid(leaf_mi, 2, skip);32308 neighbours.fill_skip_grid(leaf_mi, 2, skip);
32309+ // lane-dkey sweep: an INTER block (and every sub-8x8 leaf) has
32310+ // `palette_size == 0` in libaom's mi grid, so the next block's
32311+ // `av1_get_palette_mode_ctx`/colour cache must read 0 across this
32312+ // footprint. Only the >=8x8 intra readers published palette state, so a
32313+ // palette block's size/colours stayed standing in the mi-granular bands
32314+ // and a later intra block read `palette_y_mode` off the wrong CDF row
32315+ // (class [[cdf-row-held-constant]]).
32316+ neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
32317+ neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
32247 // lane-sub8x4 r2: `split8` is this leaf's OWN var-tx split, so32318 // lane-sub8x4 r2: `split8` is this leaf's OWN var-tx split, so
32248 // the deblock grid must publish the TX_4X4 leaves' width the32319 // the deblock grid must publish the TX_4X4 leaves' width the
32249 // same way the fall-through arm below does (libaom32320 // same way the fall-through arm below does (libaom
@@ -33441,6 +33512,15 @@ fn decode_inter_block8(
33441 // gate failed on an instrumentation gap, with the band written either way.33512 // gate failed on an instrumentation gap, with the band written either way.
33442 hit!(INTER8_SKIP_BAND_HITS);33513 hit!(INTER8_SKIP_BAND_HITS);
33443 neighbours.fill_skip_grid(leaf_mi, 2, skip);33514 neighbours.fill_skip_grid(leaf_mi, 2, skip);
33515+ // lane-dkey sweep: an INTER block (and every sub-8x8 leaf) has
33516+ // `palette_size == 0` in libaom's mi grid, so the next block's
33517+ // `av1_get_palette_mode_ctx`/colour cache must read 0 across this
33518+ // footprint. Only the >=8x8 intra readers published palette state, so a
33519+ // palette block's size/colours stayed standing in the mi-granular bands
33520+ // and a later intra block read `palette_y_mode` off the wrong CDF row
33521+ // (class [[cdf-row-held-constant]]).
33522+ neighbours.record_palette_y_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
33523+ neighbours.record_palette_uv_rect(leaf_mi, 8, 8, 0, [0u16; 8]);
33444 neighbours.fill_lf_grid(33524 neighbours.fill_lf_grid(
33445 leaf_mi,33525 leaf_mi,
33446 2,33526 2,
crates/ec-av1/src/encode.rsmodified+28 -0
@@ -13302,6 +13302,34 @@ mod tests {
13302 );13302 );
13303 let stream = std::fs::read(&obu).expect("reference stream");13303 let stream = std::fs::read(&obu).expect("reference stream");
13304 let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());13304 let decoded = ffmpeg_decode_sequence(&stream, width, height, source.len());
13305+ // lane-dkey: every reference point must also decode through OUR
13306+ // decoder, sample-exact against ffmpeg's decode of the same bytes.
13307+ // A BD table computed off streams we cannot read is a table about
13308+ // an encoder we cannot check; this is the assertion that would
13309+ // have caught the `force_integer_mv` defect (its stream decoded to
13310+ // 25 dB garbage while this gate stayed green) and the crf-5 key
13311+ // frame desync. A failure names the encoder, the point's flags and
13312+ // the first differing frame/plane/sample.
13313+ match crate::stream::decode_stream(&stream) {
13314+ Ok(ours) => {
13315+ assert_eq!(
13316+ ours.len(),
13317+ decoded.len(),
13318+ "{encoder} {params:?}: our decoder returned {} shown frames, ffmpeg {}",
13319+ ours.len(),
13320+ decoded.len(),
13321+ );
13322+ for (f, (o, d)) in ours.iter().zip(&decoded).enumerate() {
13323+ if let Some((plane, s, got, want)) = first_plane_mismatch(o, d) {
13324+ panic!(
13325+ "{encoder} {params:?} frame {f} plane {plane} sample {s}: our \
13326+ decoder decoded {got}, ffmpeg {want}"
13327+ );
13328+ }
13329+ }
13330+ }
13331+ Err(e) => panic!("{encoder} {params:?}: our decoder refused the stream ({e})"),
13332+ }
13305 let mean: f64 = decoded13333 let mean: f64 = decoded
13306 .iter()13334 .iter()
13307 .zip(source)13335 .zip(source)
crates/ec-av1/src/motion_field.rsmodified+5 -1
@@ -201,7 +201,11 @@ pub fn lower_mv_precision(
201 _ => v - m,201 _ => v - m,
202 }202 }
203 };203 };
204- return (round(mv.0), round(mv.1));204+ let out = (round(mv.0), round(mv.1));
205+ if out != mv && crate::envflags::env_flag!("EC_TRACE_TPL") {
206+ eprintln!("EC_INTMV rounded {mv:?} -> {out:?}");
207+ }
208+ return out;
205 }209 }
206 if allow_high_precision_mv {210 if allow_high_precision_mv {
207 return mv;211 return mv;