lane-av1unwritten: a 4:2:2 chroma block the walk never covered
Browse files at this commit24bb8e90ec40991a50dee2a8ea8c3795ee27282eParent: 05c44513 changed files +610 -5
- crates/ec-av1/src/decode.rs +232 -5
- crates/ec-av1/src/stream.rs +53 -0
- lanes/av1unwritten.report.md +325 -0
crates/ec-av1/src/decode.rsmodified+232 -5
| @@ -21235,6 +21235,113 @@ fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { | |||
| 21235 | } | 21235 | } |
| 21236 | } | 21236 | } |
| 21237 | 21237 | ||
| 21238 | +/// `EC_AV1_SENTINEL_CENSUS=1`: at each frame's pre-deblock point, print an | ||
| 21239 | +/// EXACT census of the samples the tile walk never wrote -- with | ||
| 21240 | +/// `EC_AV1_PLANE_SENTINEL=1` every plane still holding [`PLANE_SENTINEL`] at | ||
| 21241 | +/// this point is a sample no block reconstructed, and no legal sample can | ||
| 21242 | +/// equal `0xDEAD` (reconstruction clamps to `(1 << bit_depth) - 1`). | ||
| 21243 | +/// | ||
| 21244 | +/// This is the shipped form of the four-line temporary scan the | ||
| 21245 | +/// `lane/av1422seed` census used: it replaces a wrong-sample diff (which says | ||
| 21246 | +/// where the OUTPUT is wrong, not whether the block was written at all) with a | ||
| 21247 | +/// direct count plus the coordinates of every hole, grouped into per-row | ||
| 21248 | +/// spans so a large hole stays readable. Scans each plane over its own | ||
| 21249 | +/// `true_width` x `true_height` extent: past that is the padded coding | ||
| 21250 | +/// surface's invented tail, which no decoder ever reads. | ||
| 21251 | +fn census_unwritten(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) { | ||
| 21252 | + if !plane_sentinel_on() { | ||
| 21253 | + return; | ||
| 21254 | + } | ||
| 21255 | + let idx = PREFILT_PICTURE_IDX.load(std::sync::atomic::Ordering::SeqCst); | ||
| 21256 | + for (name, p) in [("Y", y), ("U", u), ("V", v)] { | ||
| 21257 | + let (w, h) = (p.true_width.min(p.width), p.true_height); | ||
| 21258 | + let mut total = 0usize; | ||
| 21259 | + let mut spans: Vec<(usize, usize, usize)> = Vec::new(); | ||
| 21260 | + for row in 0..h { | ||
| 21261 | + let mut run: Option<(usize, usize)> = None; | ||
| 21262 | + for col in 0..w { | ||
| 21263 | + if p.data[row * p.width + col] == PLANE_SENTINEL { | ||
| 21264 | + total += 1; | ||
| 21265 | + run = Some(match run { | ||
| 21266 | + None => (col, col), | ||
| 21267 | + Some((a, _)) => (a, col), | ||
| 21268 | + }); | ||
| 21269 | + } | ||
| 21270 | + if run.is_some() | ||
| 21271 | + && (col + 1 == w || p.data[row * p.width + col + 1] != PLANE_SENTINEL) | ||
| 21272 | + { | ||
| 21273 | + let (a, b) = run.take().expect("a run is open here"); | ||
| 21274 | + spans.push((row, a, b)); | ||
| 21275 | + } | ||
| 21276 | + } | ||
| 21277 | + } | ||
| 21278 | + UNWRITTEN_SAMPLES.fetch_add(total, std::sync::atomic::Ordering::SeqCst); | ||
| 21279 | + CENSUS_SCANNED.fetch_add(w * h, std::sync::atomic::Ordering::SeqCst); | ||
| 21280 | + if total == 0 { | ||
| 21281 | + eprintln!("SENTINEL_CENSUS idx={idx} plane={name} extent={w}x{h} unwritten=0"); | ||
| 21282 | + continue; | ||
| 21283 | + } | ||
| 21284 | + let body: Vec<String> = spans | ||
| 21285 | + .iter() | ||
| 21286 | + .map(|&(r, a, b)| format!("y{r} x{a}..={b}")) | ||
| 21287 | + .collect(); | ||
| 21288 | + eprintln!( | ||
| 21289 | + "SENTINEL_CENSUS idx={idx} plane={name} extent={w}x{h} unwritten={total} \ | ||
| 21290 | + spans={}: {}", | ||
| 21291 | + spans.len(), | ||
| 21292 | + body.join(" ") | ||
| 21293 | + ); | ||
| 21294 | + } | ||
| 21295 | +} | ||
| 21296 | + | ||
| 21297 | +/// Unwritten samples [`census_unwritten`] has counted since the last | ||
| 21298 | +/// [`take_unwritten_samples`] -- process-global (not thread-local) because the | ||
| 21299 | +/// gate reads it after the decode, from a different thread than the one that | ||
| 21300 | +/// scanned the plane. | ||
| 21301 | +static UNWRITTEN_SAMPLES: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 21302 | + | ||
| 21303 | +/// Turns [`PLANE_SENTINEL`] filling on for the CALLING thread, independently | ||
| 21304 | +/// of `EC_AV1_PLANE_SENTINEL`. A gate cannot set a process-constant env var | ||
| 21305 | +/// (see [`crate::envflags`]), and the census is the only honest way to ask | ||
| 21306 | +/// "did the tile walk write every sample it was handed" -- a wrong-sample diff | ||
| 21307 | +/// cannot tell an unwritten sample from a mis-predicted one. | ||
| 21308 | +pub fn set_plane_sentinel(on: bool) { | ||
| 21309 | + PLANE_SENTINEL_ON.with(|c| c.set(on)); | ||
| 21310 | +} | ||
| 21311 | + | ||
| 21312 | +/// Reads and clears [`UNWRITTEN_SAMPLES`]: the number of samples the decode | ||
| 21313 | +/// just handed to the tile walk never wrote, summed over every frame and | ||
| 21314 | +/// plane. Zero is the only acceptable answer for a decoder whose output must | ||
| 21315 | +/// not depend on its allocator. | ||
| 21316 | +pub fn take_unwritten_samples() -> usize { | ||
| 21317 | + UNWRITTEN_SAMPLES.swap(0, std::sync::atomic::Ordering::SeqCst) | ||
| 21318 | +} | ||
| 21319 | + | ||
| 21320 | +/// Samples [`census_unwritten`] has looked at since the last | ||
| 21321 | +/// [`take_census_scanned`]. A gate that only asserts | ||
| 21322 | +/// [`take_unwritten_samples`] == 0 passes on a decode that never scanned | ||
| 21323 | +/// anything, so it reads THIS too: a census that scanned nothing has proved | ||
| 21324 | +/// nothing. | ||
| 21325 | +static CENSUS_SCANNED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 21326 | + | ||
| 21327 | +/// Reads and clears [`CENSUS_SCANNED`]; see [`take_unwritten_samples`] for the | ||
| 21328 | +/// pairing. | ||
| 21329 | +pub fn take_census_scanned() -> usize { | ||
| 21330 | + CENSUS_SCANNED.swap(0, std::sync::atomic::Ordering::SeqCst) | ||
| 21331 | +} | ||
| 21332 | + | ||
| 21333 | +thread_local! { | ||
| 21334 | + /// The [`set_plane_sentinel`] override; `EC_AV1_PLANE_SENTINEL` is the | ||
| 21335 | + /// process-wide default. | ||
| 21336 | + static PLANE_SENTINEL_ON: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; | ||
| 21337 | +} | ||
| 21338 | + | ||
| 21339 | +/// Whether freshly allocated planes are [`PLANE_SENTINEL`]-filled. | ||
| 21340 | +fn plane_sentinel_on() -> bool { | ||
| 21341 | + crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL") | ||
| 21342 | + || PLANE_SENTINEL_ON.with(std::cell::Cell::get) | ||
| 21343 | +} | ||
| 21344 | + | ||
| 21238 | /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no | 21345 | /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no |
| 21239 | /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`, | 21346 | /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`, |
| 21240 | /// at most 4095), so a decode that hashes identically under the flag proves | 21347 | /// at most 4095), so a decode that hashes identically under the flag proves |
| @@ -21252,7 +21359,7 @@ const PLANE_SENTINEL: u16 = 0xDEAD; | |||
| 21252 | /// ways (see the lane report) and the two agree, which is the proof that no | 21359 | /// ways (see the lane report) and the two agree, which is the proof that no |
| 21253 | /// unwritten sample reaches the output. | 21360 | /// unwritten sample reaches the output. |
| 21254 | fn fresh_plane(n: usize) -> Vec<u16> { | 21361 | fn fresh_plane(n: usize) -> Vec<u16> { |
| 21255 | - if crate::envflags::env_flag!("EC_AV1_PLANE_SENTINEL") { | 21362 | + if plane_sentinel_on() { |
| 21256 | return vec![PLANE_SENTINEL; n]; | 21363 | return vec![PLANE_SENTINEL; n]; |
| 21257 | } | 21364 | } |
| 21258 | let mut v: Vec<u16> = Vec::with_capacity(n); | 21365 | let mut v: Vec<u16> = Vec::with_capacity(n); |
| @@ -21294,6 +21401,8 @@ struct PlaneBuf<'a> { | |||
| 21294 | /// old unclipped behaviour exactly. | 21401 | /// old unclipped behaviour exactly. |
| 21295 | tile_x1: usize, | 21402 | tile_x1: usize, |
| 21296 | tile_y1: usize, | 21403 | tile_y1: usize, |
| 21404 | + /// Which plane this buffer IS (0 luma, 1 U, 2 V) -- TEMPORARY probe. | ||
| 21405 | + plane: u8, | ||
| 21297 | } | 21406 | } |
| 21298 | 21407 | ||
| 21299 | /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/ | 21408 | /// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/ |
| @@ -26322,8 +26431,32 @@ fn sub8_leaf_chroma422( | |||
| 26322 | // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end | 26431 | // (`reconintra.c:1804-1806`, `:1815-1817`); the tile end is the frame end |
| 26323 | // for every leaf this reader owns, and the unit is one TX_4X4 chroma | 26432 | // for every leaf this reader owns, and the unit is one TX_4X4 chroma |
| 26324 | // transform wide and tall (`4 << ss` luma px per axis). | 26433 | // transform wide and tall (`4 << ss` luma px per axis). |
| 26434 | + // lane-av1unwritten: at ss (1,0) a BLOCK_4X8 chroma reference's plane | ||
| 26435 | + // block is 4x8 -- `get_plane_block_size(BLOCK_4X8, 1, 0)` is BLOCK_4X8 | ||
| 26436 | + // (`common_data.c`'s `av1_ss_size_lookup[BLOCK_4X8][1][0]` is | ||
| 26437 | + // BLOCK_INVALID, but `blockd.h:1372` takes the per-axis MIN of the two | ||
| 26438 | + // lookups) -- and `av1_get_max_uv_txsize` (blockd.h:1372-1379) resolves | ||
| 26439 | + // it through `max_txsize_rect_lookup[BLOCK_4X8]` == TX_4X8 | ||
| 26440 | + // (`common_data.h:126`). So away from lossless the WHOLE 4x8 plane block | ||
| 26441 | + // is ONE rect transform unit, exactly the one [`leaf8_chroma422_unit`] | ||
| 26442 | + // already reads for a BLOCK_8X8 leaf. Emitting the single square TX_4X4 | ||
| 26443 | + // this arm used to wrote left the block's bottom four chroma rows | ||
| 26444 | + // UNWRITTEN: on the pinned `440_request_is_422.obu` (a 4:2:2 header over | ||
| 26445 | + // a 4:2:0 tile, whose legal 8x8 `PARTITION_HORZ` groups make this shape | ||
| 26446 | + // legal syntax) the sentinel census found 112 unwritten samples per | ||
| 26447 | + // chroma plane, one 4x4 block per group, and the decode's output hash | ||
| 26448 | + // CHANGED RUN TO RUN because the unwritten samples were uninitialised | ||
| 26449 | + // memory (class `writer-gap-reaches-output`). | ||
| 26450 | + // | ||
| 26451 | + // At LOSSLESS the single-unit reading is wrong the other way: | ||
| 26452 | + // `av1_get_tx_size`'s first line returns TX_4X4 on every plane | ||
| 26453 | + // (blockd.h:1383), so the 4x8 plane block is walked as TWO stacked 4x4 | ||
| 26454 | + // units -- which is exactly what the two chroma-reference leaves of the | ||
| 26455 | + // `decode_leaf_split4` route below already emit, so the square arms stay | ||
| 26456 | + // for lossless. | ||
| 26457 | + let rect48 = leaf_shape == (4, 8) && !lossless(fctx); | ||
| 26325 | let tx_w = 4 << ss_x(fctx); | 26458 | let tx_w = 4 << ss_x(fctx); |
| 26326 | - let tx_h = 4 << ss_y(fctx); | 26459 | + let tx_h = (if rect48 { 8 } else { 4 }) << ss_y(fctx); |
| 26327 | let reach = Reach::of_tu_chroma( | 26460 | let reach = Reach::of_tu_chroma( |
| 26328 | mi_bw, | 26461 | mi_bw, |
| 26329 | mi_bh, | 26462 | mi_bh, |
| @@ -26339,15 +26472,95 @@ fn sub8_leaf_chroma422( | |||
| 26339 | py > 0 && px + (tx_w << ss_x(fctx)) < y.width, | 26472 | py > 0 && px + (tx_w << ss_x(fctx)) < y.width, |
| 26340 | px > 0 && py + (tx_h << ss_y(fctx)) < y.height, | 26473 | px > 0 && py + (tx_h << ss_y(fctx)) < y.height, |
| 26341 | ); | 26474 | ); |
| 26342 | - let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); | 26475 | + let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, if rect48 { 8 } else { 4 }); |
| 26343 | // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint, | 26476 | // lane-av1422sub8pix: the CfL AC signal spans the UNIT's luma footprint, |
| 26344 | // anchored at the same FLOORED luma x the write/prediction anchor below | 26477 | // anchored at the same FLOORED luma x the write/prediction anchor below |
| 26345 | // uses -- `px` (the odd leaf's own luma x) steps half the span into the | 26478 | // uses -- `px` (the odd leaf's own luma x) steps half the span into the |
| 26346 | // RIGHT neighbour group (t422 frame-1 leaf (1,23): the unit reconstructs | 26479 | // RIGHT neighbour group (t422 frame-1 leaf (1,23): the unit reconstructs |
| 26347 | // chroma px 44..47 from luma 88..95, while a `px`-anchored source | 26480 | // chroma px 44..47 from luma 88..95, while a `px`-anchored source |
| 26348 | // averaged luma 92..99 and every CFL unit of the group mismatched). | 26481 | // averaged luma 92..99 and every CFL unit of the group mismatched). |
| 26349 | - let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, 4)); | 26482 | + let ac = alpha.map(|_| cfl_src_rect((lmi.1 & !1) * MI, py, 8, if rect48 { 8 } else { 4 })); |
| 26350 | - let grids: (Grid, Grid) = if let Some(dv) = intrabc_dv.filter(|_| skip) { | 26483 | + let grids: (Grid, Grid) = if rect48 { |
| 26484 | + // The 4:2:2 vert pair's ONE chroma reference codes the PAIR's whole | ||
| 26485 | + // 4x8 chroma plane block. libaom reaches the same unit through | ||
| 26486 | + // `decode_token_recon_block`'s plane/row/col loop with | ||
| 26487 | + // `tx_size = av1_get_tx_size(1, xd)` == TX_4X8 (stepr/stepc = 2/1 over | ||
| 26488 | + // `unit_height = ROUND_POWER_OF_TWO(min(mu_blocks_high + row, | ||
| 26489 | + // max_blocks_high), ss_y)` = 2 and `unit_width` = 1, i.e. one | ||
| 26490 | + // iteration), so [`leaf8_chroma422_unit`] -- the port of that walk for | ||
| 26491 | + // a BLOCK_8X8 leaf -- is the unit, unchanged. The DV arms supply the | ||
| 26492 | + // frame copy through `pred_override`, which is how the BLOCK_8X8 leaf | ||
| 26493 | + // hands the same two intrabc shapes over. | ||
| 26494 | + let (ub, vb) = match intrabc_dv { | ||
| 26495 | + Some(dv) => { | ||
| 26496 | + let mut ub = vec![0u16; 4 * 8]; | ||
| 26497 | + mc::predict_with_filter( | ||
| 26498 | + &u.data, | ||
| 26499 | + u.width, | ||
| 26500 | + u.true_width, | ||
| 26501 | + u.true_height, | ||
| 26502 | + mv_to_q4(cpx, dv.1, ss_x(fctx)), | ||
| 26503 | + mv_to_q4(cpy, dv.0, ss_y(fctx)), | ||
| 26504 | + 4, | ||
| 26505 | + 8, | ||
| 26506 | + mc::InterpFilterKind::Bilinear, | ||
| 26507 | + &mut ub, | ||
| 26508 | + fctx, | ||
| 26509 | + ); | ||
| 26510 | + let mut vb = vec![0u16; 4 * 8]; | ||
| 26511 | + mc::predict_with_filter( | ||
| 26512 | + &v.data, | ||
| 26513 | + v.width, | ||
| 26514 | + v.true_width, | ||
| 26515 | + v.true_height, | ||
| 26516 | + mv_to_q4(cpx, dv.1, ss_x(fctx)), | ||
| 26517 | + mv_to_q4(cpy, dv.0, ss_y(fctx)), | ||
| 26518 | + 4, | ||
| 26519 | + 8, | ||
| 26520 | + mc::InterpFilterKind::Bilinear, | ||
| 26521 | + &mut vb, | ||
| 26522 | + fctx, | ||
| 26523 | + ); | ||
| 26524 | + (Some(ub), Some(vb)) | ||
| 26525 | + } | ||
| 26526 | + None => (None, None), | ||
| 26527 | + }; | ||
| 26528 | + let u_grid = leaf8_chroma422_unit( | ||
| 26529 | + dec, | ||
| 26530 | + cdfs, | ||
| 26531 | + chroma_around[1], | ||
| 26532 | + uv_predict_mode, | ||
| 26533 | + angle_delta_uv, | ||
| 26534 | + reach, | ||
| 26535 | + 1, | ||
| 26536 | + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), | ||
| 26537 | + skip, | ||
| 26538 | + ub, | ||
| 26539 | + u, | ||
| 26540 | + cpx, | ||
| 26541 | + cpy, | ||
| 26542 | + smooth_neighbor_uv, | ||
| 26543 | + fctx, | ||
| 26544 | + )?; | ||
| 26545 | + let v_grid = leaf8_chroma422_unit( | ||
| 26546 | + dec, | ||
| 26547 | + cdfs, | ||
| 26548 | + chroma_around[2], | ||
| 26549 | + uv_predict_mode, | ||
| 26550 | + angle_delta_uv, | ||
| 26551 | + reach, | ||
| 26552 | + 2, | ||
| 26553 | + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), | ||
| 26554 | + skip, | ||
| 26555 | + vb, | ||
| 26556 | + v, | ||
| 26557 | + cpx, | ||
| 26558 | + cpy, | ||
| 26559 | + smooth_neighbor_uv, | ||
| 26560 | + fctx, | ||
| 26561 | + )?; | ||
| 26562 | + (u_grid, v_grid) | ||
| 26563 | + } else if let Some(dv) = intrabc_dv.filter(|_| skip) { | ||
| 26351 | // lane-av1422ctattr: a SKIPPED intrabc chroma leaf still predicts the | 26564 | // lane-av1422ctattr: a SKIPPED intrabc chroma leaf still predicts the |
| 26352 | // frame copy at its DV. libaom's `decode_token_recon_block` takes the | 26565 | // frame copy at its DV. libaom's `decode_token_recon_block` takes the |
| 26353 | // INTER arm for an intrabc block (`is_inter_block` counts it, | 26566 | // INTER arm for an intrabc block (`is_inter_block` counts it, |
| @@ -35287,6 +35500,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 35287 | tile_y0: 0, | 35500 | tile_y0: 0, |
| 35288 | tile_x1: width, | 35501 | tile_x1: width, |
| 35289 | tile_y1: height, | 35502 | tile_y1: height, |
| 35503 | + plane: 0, | ||
| 35290 | }; | 35504 | }; |
| 35291 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); | 35505 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); |
| 35292 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); | 35506 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); |
| @@ -35300,6 +35514,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 35300 | tile_y0: 0, | 35514 | tile_y0: 0, |
| 35301 | tile_x1: cw, | 35515 | tile_x1: cw, |
| 35302 | tile_y1: ch, | 35516 | tile_y1: ch, |
| 35517 | + plane: 1, | ||
| 35303 | }; | 35518 | }; |
| 35304 | let mut v = PlaneBuf { | 35519 | let mut v = PlaneBuf { |
| 35305 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), | 35520 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), |
| @@ -35311,6 +35526,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 35311 | tile_y0: 0, | 35526 | tile_y0: 0, |
| 35312 | tile_x1: cw, | 35527 | tile_x1: cw, |
| 35313 | tile_y1: ch, | 35528 | tile_y1: ch, |
| 35529 | + plane: 2, | ||
| 35314 | }; | 35530 | }; |
| 35315 | 35531 | ||
| 35316 | let scan32 = default_scan(TX32); | 35532 | let scan32 = default_scan(TX32); |
| @@ -37459,6 +37675,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 37459 | frame_width as usize, | 37675 | frame_width as usize, |
| 37460 | frame_height as usize, | 37676 | frame_height as usize, |
| 37461 | ); | 37677 | ); |
| 37678 | + census_unwritten(&y, &u, &v); | ||
| 37462 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | 37679 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { |
| 37463 | use std::io::Write; | 37680 | use std::io::Write; |
| 37464 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 37681 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| @@ -37597,6 +37814,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 37597 | tile_y0: 0, | 37814 | tile_y0: 0, |
| 37598 | tile_x1: out_w, | 37815 | tile_x1: out_w, |
| 37599 | tile_y1: in_h, | 37816 | tile_y1: in_h, |
| 37817 | + plane: p.plane, | ||
| 37600 | }; | 37818 | }; |
| 37601 | let (cw, ch, cuw) = ( | 37819 | let (cw, ch, cuw) = ( |
| 37602 | round_ss(fw, ss_x(fctx)), | 37820 | round_ss(fw, ss_x(fctx)), |
| @@ -38944,6 +39162,7 @@ fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> { | |||
| 38944 | tile_y0: 0, | 39162 | tile_y0: 0, |
| 38945 | tile_x1: width, | 39163 | tile_x1: width, |
| 38946 | tile_y1: height, | 39164 | tile_y1: height, |
| 39165 | + plane: 0, | ||
| 38947 | } | 39166 | } |
| 38948 | } | 39167 | } |
| 38949 | 39168 | ||
| @@ -52902,6 +53121,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 52902 | tile_y0: 0, | 53121 | tile_y0: 0, |
| 52903 | tile_x1: width, | 53122 | tile_x1: width, |
| 52904 | tile_y1: height, | 53123 | tile_y1: height, |
| 53124 | + plane: 0, | ||
| 52905 | }; | 53125 | }; |
| 52906 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); | 53126 | let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx)); |
| 52907 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); | 53127 | let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx)); |
| @@ -52915,6 +53135,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 52915 | tile_y0: 0, | 53135 | tile_y0: 0, |
| 52916 | tile_x1: cw, | 53136 | tile_x1: cw, |
| 52917 | tile_y1: ch, | 53137 | tile_y1: ch, |
| 53138 | + plane: 1, | ||
| 52918 | }; | 53139 | }; |
| 52919 | let mut v = PlaneBuf { | 53140 | let mut v = PlaneBuf { |
| 52920 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), | 53141 | data: std::borrow::Cow::Owned(fresh_plane(cw * ch)), |
| @@ -52926,6 +53147,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 52926 | tile_y0: 0, | 53147 | tile_y0: 0, |
| 52927 | tile_x1: cw, | 53148 | tile_x1: cw, |
| 52928 | tile_y1: ch, | 53149 | tile_y1: ch, |
| 53150 | + plane: 2, | ||
| 52929 | }; | 53151 | }; |
| 52930 | 53152 | ||
| 52931 | let scan32 = default_scan(TX32); | 53153 | let scan32 = default_scan(TX32); |
| @@ -55743,6 +55965,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 55743 | frame_width as usize, | 55965 | frame_width as usize, |
| 55744 | frame_height as usize, | 55966 | frame_height as usize, |
| 55745 | ); | 55967 | ); |
| 55968 | + census_unwritten(&y, &u, &v); | ||
| 55746 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { | 55969 | if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") { |
| 55747 | use std::io::Write; | 55970 | use std::io::Write; |
| 55748 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); | 55971 | let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| @@ -55903,6 +56126,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 55903 | tile_y0: 0, | 56126 | tile_y0: 0, |
| 55904 | tile_x1: out_w, | 56127 | tile_x1: out_w, |
| 55905 | tile_y1: in_h, | 56128 | tile_y1: in_h, |
| 56129 | + plane: p.plane, | ||
| 55906 | }; | 56130 | }; |
| 55907 | let (cw, ch, cuw) = ( | 56131 | let (cw, ch, cuw) = ( |
| 55908 | round_ss(fw, ss_x(fctx)), | 56132 | round_ss(fw, ss_x(fctx)), |
| @@ -58297,6 +58521,7 @@ mod tests { | |||
| 58297 | tile_y0: 0, | 58521 | tile_y0: 0, |
| 58298 | tile_x1: width, | 58522 | tile_x1: width, |
| 58299 | tile_y1: height, | 58523 | tile_y1: height, |
| 58524 | + plane: 0, | ||
| 58300 | }; | 58525 | }; |
| 58301 | let mut u = PlaneBuf { | 58526 | let mut u = PlaneBuf { |
| 58302 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), | 58527 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), |
| @@ -58308,6 +58533,7 @@ mod tests { | |||
| 58308 | tile_y0: 0, | 58533 | tile_y0: 0, |
| 58309 | tile_x1: width / 2, | 58534 | tile_x1: width / 2, |
| 58310 | tile_y1: height / 2, | 58535 | tile_y1: height / 2, |
| 58536 | + plane: 1, | ||
| 58311 | }; | 58537 | }; |
| 58312 | let mut v = PlaneBuf { | 58538 | let mut v = PlaneBuf { |
| 58313 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), | 58539 | data: std::borrow::Cow::Owned(vec![0u16; (width / 2) * (height / 2)]), |
| @@ -58319,6 +58545,7 @@ mod tests { | |||
| 58319 | tile_y0: 0, | 58545 | tile_y0: 0, |
| 58320 | tile_x1: width / 2, | 58546 | tile_x1: width / 2, |
| 58321 | tile_y1: height / 2, | 58547 | tile_y1: height / 2, |
| 58548 | + plane: 2, | ||
| 58322 | }; | 58549 | }; |
| 58323 | 58550 | ||
| 58324 | let mut cdfs = Cdfs::new(q_ctx_of(100)); | 58551 | let mut cdfs = Cdfs::new(q_ctx_of(100)); |
crates/ec-av1/src/stream.rsmodified+53 -0
| @@ -2863,6 +2863,59 @@ pub(crate) mod tests { | |||
| 2863 | ran on it" | 2863 | ran on it" |
| 2864 | ); | 2864 | ); |
| 2865 | } | 2865 | } |
| 2866 | + | ||
| 2867 | + /// lane-av1unwritten: the same pin decoded NONDETERMINISTICALLY. Its | ||
| 2868 | + /// 4:2:2 header hands the chroma planes 4x8 blocks (libaom's | ||
| 2869 | + /// `av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)` == TX_4X8), and this | ||
| 2870 | + /// decoder's `sub8_leaf_chroma422` wrote a single square TX_4X4 per | ||
| 2871 | + /// chroma reference -- so the bottom four chroma rows of every 8x8 | ||
| 2872 | + /// `PARTITION_HORZ` group were never written at all and the uninitialised | ||
| 2873 | + /// plane memory reached the output: five runs of the one file gave five | ||
| 2874 | + /// different `EC_AV1_FINAL_DUMP` hashes while every census count read | ||
| 2875 | + /// identical. | ||
| 2876 | + /// | ||
| 2877 | + /// The property pinned here is the one that stops that: with freshly | ||
| 2878 | + /// allocated planes filled with `PLANE_SENTINEL` (a value no legal sample | ||
| 2879 | + /// can equal), the decode must leave NO sample still holding it. A | ||
| 2880 | + /// wrong-sample diff cannot assert this -- it cannot tell an unwritten | ||
| 2881 | + /// sample from a mis-predicted one -- and `take_census_scanned` is read | ||
| 2882 | + /// alongside so a census that scanned nothing cannot pass as a census | ||
| 2883 | + /// that found nothing. | ||
| 2884 | + #[test] | ||
| 2885 | + fn a_422_header_over_a_420_tile_leaves_no_sample_unwritten() { | ||
| 2886 | + const NAME: &str = "a_422_header_over_a_420_tile_leaves_no_sample_unwritten"; | ||
| 2887 | + struct Sentinel(bool); | ||
| 2888 | + impl Drop for Sentinel { | ||
| 2889 | + fn drop(&mut self) { | ||
| 2890 | + crate::decode::set_plane_sentinel(self.0); | ||
| 2891 | + } | ||
| 2892 | + } | ||
| 2893 | + let _gate_lock = lock_gate_counters(); | ||
| 2894 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2895 | + .join("fixtures") | ||
| 2896 | + .join("440_request_is_422.obu"); | ||
| 2897 | + let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME); | ||
| 2898 | + crate::decode::set_plane_sentinel(true); | ||
| 2899 | + let _sentinel = Sentinel(false); | ||
| 2900 | + crate::decode::take_unwritten_samples(); | ||
| 2901 | + crate::decode::take_census_scanned(); | ||
| 2902 | + let frames = | ||
| 2903 | + decode_stream(&pinned).unwrap_or_else(|e| panic!("{NAME}: the pin must decode: {e}")); | ||
| 2904 | + assert_eq!(frames.len(), 1, "{NAME}: the pin decodes exactly one frame"); | ||
| 2905 | + let scanned = crate::decode::take_census_scanned(); | ||
| 2906 | + let unwritten = crate::decode::take_unwritten_samples(); | ||
| 2907 | + assert!( | ||
| 2908 | + scanned >= 64 * 64 + 2 * 32 * 64, | ||
| 2909 | + "{NAME}: the sentinel census scanned only {scanned} samples -- a census that \ | ||
| 2910 | + looked at less than the whole frame proves nothing" | ||
| 2911 | + ); | ||
| 2912 | + assert_eq!( | ||
| 2913 | + unwritten, 0, | ||
| 2914 | + "{NAME}: {unwritten} samples of the frame were handed to the tile walk and never \ | ||
| 2915 | + written, so they reach the output as whatever the allocator left there (the five \ | ||
| 2916 | + different dump hashes this pin used to give)" | ||
| 2917 | + ); | ||
| 2918 | + } | ||
| 2866 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned | 2919 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned |
| 2867 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). | 2920 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). |
| 2868 | /// | 2921 | /// |
lanes/av1unwritten.report.mdadded+325 -0
| @@ -0,0 +1,325 @@ | |||
| 1 | +# lane/av1unwritten — a 4:2:2 chroma block the walk never covered | ||
| 2 | + | ||
| 3 | +**Outcome in one line: `sub8_leaf_chroma422` wrote ONE square `TX_4X4` where libaom | ||
| 4 | +writes ONE `TX_4X8` (`av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)`), so every 4:2:2 | ||
| 5 | +8x8 block coded `PARTITION_HORZ` left the bottom four chroma rows unwritten and | ||
| 6 | +the uninitialised plane memory reached the output; the fix routes that shape to | ||
| 7 | +the port that already exists for a `BLOCK_8X8` leaf (`leaf8_chroma422_unit`), and | ||
| 8 | +a new sentinel-census gate pins "the walk wrote every sample it was handed".** | ||
| 9 | + | ||
| 10 | +Branch `lane/av1unwritten`, base `main` = `8d6998d7`. No push. | ||
| 11 | + | ||
| 12 | +--- | ||
| 13 | + | ||
| 14 | +## 1. Reproduction: five runs, five hashes | ||
| 15 | + | ||
| 16 | +``` | ||
| 17 | +$ cd /home/user/.cache/wt/av1unwritten | ||
| 18 | +$ cargo build -p ec-av1 --example decode_probe --features gate-counters | ||
| 19 | +$ mkdir -p /tmp/wt_aw | ||
| 20 | +$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/u$i \ | ||
| 21 | + ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu \ | ||
| 22 | + >/dev/null 2>&1; sha256sum /tmp/wt_aw/u$i.f0; done | ||
| 23 | +de5051156b7cfd00dc7ed5f2c6ad404e2a49822a8a728bc027a938aac00219f1 /tmp/wt_aw/u1.f0 | ||
| 24 | +eb0e513ff07d9780b03e70861d1a7f507f540e4724f62384511a71e06c386aa9 /tmp/wt_aw/u2.f0 | ||
| 25 | +2985b82874579807efb8bc88136d1b8f5f1f0121410cde26723d5be7e6ba8715 /tmp/wt_aw/u3.f0 | ||
| 26 | +204645ad20d7e557d7b04f0027d9aafd5790fe685dc39bdf7cfb117d9dd1f0fc /tmp/wt_aw/u4.f0 | ||
| 27 | +80908a1712c4fe78070a6a3ad57464e8bd6a9d0b8d73e86e8f9cf7ea7cbd3496 /tmp/wt_aw/u5.f0 | ||
| 28 | +``` | ||
| 29 | + | ||
| 30 | +Five hashes from one file. Under `EC_AV1_PLANE_SENTINEL=1` the same five runs give | ||
| 31 | +ONE hash — the output difference is exactly the samples the decode never wrote. | ||
| 32 | + | ||
| 33 | +### 1.1 The instrument (now committed) | ||
| 34 | + | ||
| 35 | +`EC_AV1_SENTINEL_CENSUS=1` (new, `decode::census_unwritten`, called at each | ||
| 36 | +frame's pre-deblock point beside the existing `EC_AV1_PREFILT_DUMP16` rung, on | ||
| 37 | +both the key-frame and inter-frame paths) scans each plane over its own | ||
| 38 | +`true_width` x `true_height` extent and prints, per plane, the number of samples | ||
| 39 | +still holding `PLANE_SENTINEL` plus every hole as per-row column spans. This is | ||
| 40 | +the shipped form of the four-line temporary scan `lanes/av1422seed.report.md` §3 | ||
| 41 | +used; the report explicitly noted it was *not* committed, which is why this lane | ||
| 42 | +had to re-derive it. | ||
| 43 | + | ||
| 44 | +``` | ||
| 45 | +$ EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 \ | ||
| 46 | + ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 >/dev/null | ||
| 47 | +SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 | ||
| 48 | +SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=112 spans=24: | ||
| 49 | + y36 x0..=3 y36 x12..=15 y37 x0..=3 y37 x12..=15 y38 x0..=3 y38 x12..=15 y39 x0..=3 y39 x12..=15 | ||
| 50 | + y44 x4..=7 y44 x12..=15 y45 x4..=7 y45 x12..=15 y46 x4..=7 y46 x12..=15 y47 x4..=7 y47 x12..=15 | ||
| 51 | + y52 x0..=7 y53 x0..=7 y54 x0..=7 y55 x0..=7 y60 x0..=3 y61 x0..=3 y62 x0..=3 y63 x0..=3 | ||
| 52 | +SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=112 spans=24: (identical) | ||
| 53 | +``` | ||
| 54 | + | ||
| 55 | +**112 samples per chroma plane, 0 luma.** Both chroma planes, so the census is | ||
| 56 | +not a one-sided artefact. | ||
| 57 | + | ||
| 58 | +### 1.2 The holes are whole 4x4 chroma blocks, and each is a whole block's bottom half | ||
| 59 | + | ||
| 60 | +Grouped as blocks, the six spans are six 4x4 chroma blocks (two of the spans are | ||
| 61 | +8 wide = two blocks): | ||
| 62 | + | ||
| 63 | +| chroma block (x, y) | luma extent (2x, y..y+3) | owning luma group | | ||
| 64 | +|---|---|---| | ||
| 65 | +| (0..3, 36..39) | (0..7, 36..39) | 8x8 group at luma (0, 32), `PARTITION_HORZ` -> two `BLOCK_4X8` | | ||
| 66 | +| (12..15, 36..39) | (24..31, 36..39) | 8x8 group at luma (24, 32), `PARTITION_HORZ` | | ||
| 67 | +| (4..7, 44..47) | (8..15, 44..47) | 8x8 group at luma (8, 40), `PARTITION_HORZ` | | ||
| 68 | +| (12..15, 44..47) | (24..31, 44..47) | 8x8 group at luma (24, 40), `PARTITION_HORZ` | | ||
| 69 | +| (0..3, 52..55) + (4..7, 52..55) | (0..15, 52..55) | 8x8 groups at luma (0, 48) and (8, 48), `PARTITION_HORZ` | | ||
| 70 | +| (0..3, 60..63) | (0..7, 60..63) | 8x8 group at luma (0, 56), `PARTITION_HORZ` | | ||
| 71 | + | ||
| 72 | +The blocks that *should* have written each hole did write their luma and their | ||
| 73 | +top four chroma rows; the hole is always the **lower half of a 4x8 chroma plane | ||
| 74 | +block**, never anything else. | ||
| 75 | + | ||
| 76 | +### 1.3 Which arm, and what the tile walk does not code | ||
| 77 | + | ||
| 78 | +Localised with a temporary probe (since removed) on the three | ||
| 79 | +`PlaneBuf` sinks — every reconstruction store was recorded with its plane and | ||
| 80 | +extent and the census's holes were attributed to owners: | ||
| 81 | + | ||
| 82 | +``` | ||
| 83 | +SUB8_C422 lmi=(8,1) leaf=(4, 8) cpx=0 cpy=32 | ||
| 84 | +SUB8_C422 lmi=(10,3) leaf=(4, 8) cpx=4 cpy=40 | ||
| 85 | +SUB8_C422 lmi=(8,7) leaf=(4, 8) cpx=12 cpy=32 | ||
| 86 | +SUB8_C422 lmi=(10,7) leaf=(4, 8) cpx=12 cpy=40 | ||
| 87 | +SUB8_C422 lmi=(12,1) leaf=(4, 8) cpx=0 cpy=48 | ||
| 88 | +SUB8_C422 lmi=(12,3) leaf=(4, 8) cpx=4 cpy=48 | ||
| 89 | +SUB8_C422 lmi=(14,1) leaf=(4, 8) cpx=0 cpy=56 | ||
| 90 | +SUB8_C422 lmi=(14,3) leaf=(4, 4) cpx=4 cpy=56 | ||
| 91 | +SUB8_C422 lmi=(15,3) leaf=(4, 4) cpx=4 cpy=60 | ||
| 92 | +``` | ||
| 93 | + | ||
| 94 | +Every arm is `sub8_leaf_chroma422` (`decode.rs`, reached from | ||
| 95 | +`decode_leaf_rect8`'s three chroma-reference call sites and from | ||
| 96 | +`decode_leaf_split4`). Each writes one **4x4** chroma unit at `(cpx, cpy)`. The | ||
| 97 | +seven `leaf=(4, 8)` entries are the chroma references of the seven | ||
| 98 | +`PARTITION_HORZ` groups in §1.2, and `cpy` is the group's TOP row — the bottom | ||
| 99 | +row is never visited, by any arm, on any plane. | ||
| 100 | + | ||
| 101 | +--- | ||
| 102 | + | ||
| 103 | +## 2. Is this reachable on a stream this decoder is supposed to accept? | ||
| 104 | + | ||
| 105 | +**Yes — the shape is legal AV1 syntax and a 4:2:2 stream can carry it. The | ||
| 106 | +committed corpus happens to contain none.** | ||
| 107 | + | ||
| 108 | +### 2.1 Corpus sentinel sweep (all 127 committed fixtures) | ||
| 109 | + | ||
| 110 | +``` | ||
| 111 | +$ for f in crates/ec-av1/fixtures/*.obu; do \ | ||
| 112 | + out=$(EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 timeout 120 \ | ||
| 113 | + ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep SENTINEL_CENSUS); \ | ||
| 114 | + if echo "$out" | grep -qv 'unwritten=0'; then echo "=== $(basename $f)"; \ | ||
| 115 | + echo "$out" | grep -v 'unwritten=0'; fi; done | ||
| 116 | +=== 440_request_is_422.obu | ||
| 117 | +SENTINEL_CENSUS idx=0 plane=U ... unwritten=112 ... | ||
| 118 | +SENTINEL_CENSUS idx=0 plane=V ... unwritten=112 ... | ||
| 119 | +``` | ||
| 120 | + | ||
| 121 | +126 of 127 fixtures — 4:2:0 (lossless, mixed-lossless, tall 8x16/16x8, odd | ||
| 122 | +65x65, odd heights, altref, intrabc), 4:4:4 (lossless 128-root mu-chroma, | ||
| 123 | +palette, rect4 444 at 8/10-bit), and 4:2:2 at 8/10/12-bit including | ||
| 124 | +`Y_intrabc_10b.obu`, `X_intrabc_tiled.obu`, `W_intrabc.obu`, the `s422_*` | ||
| 125 | +slices, grain and superres cells — have a **fully written** census on every | ||
| 126 | +frame of every plane. Only the hand-built witness does not. | ||
| 127 | + | ||
| 128 | +### 2.2 Why the corpus cannot see it: the defective shape has zero reach on valid streams | ||
| 129 | + | ||
| 130 | +Same sweep, counting arm entries and how many carry the `leaf=(4, 8)` shape: | ||
| 131 | + | ||
| 132 | +``` | ||
| 133 | +$ for f in crates/ec-av1/fixtures/*.obu; do \ | ||
| 134 | + n=$(EC_RECON_TRACE=1 ./target/debug/examples/decode_probe "$f" 2>&1 >/dev/null | grep -c SUB8_C422); \ | ||
| 135 | + if [ "$n" != 0 ]; then v=$(... grep -c 'SUB8_C422.*leaf=(4, 8)'); \ | ||
| 136 | + echo "$(basename $f) c422=$n vert48=$v"; fi; done | ||
| 137 | +422_inter_160x128_3f.obu c422=29 vert48=0 | ||
| 138 | +422_key_64x64.obu c422=2 vert48=0 | ||
| 139 | +422_palette_intra_in_inter_384x240_17f c422=158 vert48=0 | ||
| 140 | +422_residual_compound_warp_16f.obu c422=257 vert48=0 | ||
| 141 | +422_residual_compound_warp_nolr_16f.obu c422=256 vert48=0 | ||
| 142 | +440_request_is_422.obu c422=9 vert48=7 <-- the only one | ||
| 143 | +W_intrabc.obu c422=391 vert48=0 | ||
| 144 | +X_intrabc_tiled.obu c422=333 vert48=0 | ||
| 145 | +Y_intrabc_10b.obu c422=539 vert48=0 | ||
| 146 | +s422_12bit_160x128.obu c422=185 vert48=0 | ||
| 147 | +s422_320x246.obu c422=162 vert48=0 | ||
| 148 | +s422_322x240.obu c422=195 vert48=0 | ||
| 149 | +s422_322x246.obu c422=155 vert48=0 | ||
| 150 | +s422_352x242_10b.obu c422=169 vert48=0 | ||
| 151 | +s422_416x242_10b.obu c422=176 vert48=0 | ||
| 152 | +s422_416x250_10b.obu c422=198 vert48=0 | ||
| 153 | +s422_grain_160x128.obu c422=45 vert48=0 | ||
| 154 | +s422_superres_160x128.obu c422=45 vert48=0 | ||
| 155 | +``` | ||
| 156 | + | ||
| 157 | +3528 real `sub8_leaf_chroma422` invocations across the 4:2:2 corpus, **zero** of | ||
| 158 | +the `leaf=(4, 8)` shape. So: | ||
| 159 | + | ||
| 160 | +* the DEFECT is not corpus-faked — the arm is heavily used and every other shape | ||
| 161 | + is right; | ||
| 162 | +* the defect is latent, not observed, on valid streams, because no committed | ||
| 163 | + 4:2:2 stream codes an 8x8 block with `PARTITION_HORZ`. | ||
| 164 | + | ||
| 165 | +**Latent does not mean absent.** AV1's 8x8 partition set is the full | ||
| 166 | +`PARTITION_TYPES` (`partition_cdf_length`, `av1_common_int.h:1555-1560`: `bsize | ||
| 167 | +<= BLOCK_8X8` gets all eight), so `PARTITION_HORZ` at 8x8 is codable, and libaom | ||
| 168 | +decodes it through exactly the path below. The witness's tile is a genuine 4:2:0 | ||
| 169 | +key frame's tile, so the `PARTITION_HORZ` groups it carries are ordinary legal | ||
| 170 | +partition symbols — the header/tile chroma mismatch changes only the geometry | ||
| 171 | +they are decoded against. | ||
| 172 | + | ||
| 173 | +### 2.3 What libaom does here (the derivation, from source) | ||
| 174 | + | ||
| 175 | +1. `av1/decoder/decodeframe.c`, `decode_partition` -> `parse_decode_block` | ||
| 176 | + (`decodeframe.c:1229`) runs once **per leaf**, so a `PARTITION_HORZ` 8x8 group | ||
| 177 | + reaches `decode_token_recon_block(pbi, td, r, BLOCK_4X8)` once per leaf. | ||
| 178 | +2. `decode_token_recon_block` (`:993-1041`) skips the chroma planes when | ||
| 179 | + `!xd->is_chroma_ref`. `is_chroma_reference` (`av1_common_int.h:1454-1461`) is | ||
| 180 | + `((mi_row & 1) || !(bh & 1) || !ss_y) && ((mi_col & 1) || !(bw & 1) || !ss_x)`. | ||
| 181 | + For `BLOCK_4X8` at ss (1,0): `bw=1` -> the column clause is `mi_col & 1`, so | ||
| 182 | + **only the odd-column leaf codes chroma**; the row clause is `true` because | ||
| 183 | + `!ss_y`. That is the crate's `!vert || i == 1` in `decode_leaf_rect8`, and it | ||
| 184 | + is right. | ||
| 185 | +3. For the chroma reference leaf, `tx_size = av1_get_tx_size(1, xd)` | ||
| 186 | + (`blockd.h:1381-1388`) = `av1_get_max_uv_txsize(BLOCK_4X8, 1, 0)` | ||
| 187 | + (`blockd.h:1372-1379`) = `max_txsize_rect_lookup[get_plane_block_size( | ||
| 188 | + BLOCK_4X8, 1, 0)]`. `get_plane_block_size` takes the **per-axis MIN** of the | ||
| 189 | + two `av1_ss_size_lookup` entries, so `min(BLOCK_INVALID, BLOCK_4X8)` = | ||
| 190 | + `BLOCK_4X8`, and `max_txsize_rect_lookup[BLOCK_4X8]` (`common_data.h:126-127`) | ||
| 191 | + is **`TX_4X8`**. (At lossless, `av1_get_tx_size`'s first line returns `TX_4X4` | ||
| 192 | + on every plane, `blockd.h:1383`.) | ||
| 193 | +4. The walk loop at `:1011-1033` with `tx_size = TX_4X8`: | ||
| 194 | + `max_block_wide/high` are in MI units (`blockd.h:1565-1594`) = 1 and 2; | ||
| 195 | + `tx_size_high_unit[TX_4X8] = 2`, `stepc = tx_size_wide_unit[TX_4X8] = 1` | ||
| 196 | + (`common_data.h:246-253`). `blk_row = 0` only, `blk_col = 0` only: | ||
| 197 | + **one `TX_4X8` unit covering the whole 4x8 chroma plane block.** | ||
| 198 | + | ||
| 199 | +This decoder instead emitted a single `TX_4X4` (`read_plane(..., 4, TX4, ...)` | ||
| 200 | +then `push_intra(..., 4, ...)`) — half the plane block. At lossless the existing | ||
| 201 | +square model is the *correct* one (`TX_4X4` per unit, two stacked units), which | ||
| 202 | +is why the arm's `leaf=(4, 4)` path and the `decode_leaf_split4` route are | ||
| 203 | +untouched by this fix. | ||
| 204 | + | ||
| 205 | +--- | ||
| 206 | + | ||
| 207 | +## 3. The fix | ||
| 208 | + | ||
| 209 | +`crates/ec-av1/src/decode.rs`, `sub8_leaf_chroma422`, one new branch: | ||
| 210 | + | ||
| 211 | +```rust | ||
| 212 | +let rect48 = leaf_shape == (4, 8) && !lossless(fctx); | ||
| 213 | +``` | ||
| 214 | + | ||
| 215 | +When it holds, the arm hands the PAIR's whole 4x8 chroma plane block to | ||
| 216 | +`leaf8_chroma422_unit` — the port that already exists for a `BLOCK_8X8` 4:2:2 | ||
| 217 | +leaf (`TxbSet::ChromaRect8x4` + `SCAN_4X8` + `read_coeffs_rect(4, 8, ..)` + | ||
| 218 | +`dequant_and_inverse_typed_wh(4, 8, ..)` + `push_intra_rect(.., 4, 8, ..)`, whose | ||
| 219 | +own doc cites the identical `av1_get_max_uv_txsize` derivation). The two intrabc | ||
| 220 | +shapes hand their frame copy over through that function's existing | ||
| 221 | +`pred_override` parameter, which is how the `BLOCK_8X8` leaf passes the same two | ||
| 222 | +cases. Alongside it, three sub-8-specific inputs follow the unit's new height: | ||
| 223 | +the reach (`tx_h = 8 << ss_y`), the entropy context | ||
| 224 | +(`around_mi_422_chroma(ctx_mi, 8, 8)`) and the CfL AC span | ||
| 225 | +(`cfl_src_rect(floored_x, py, 8, 8)`). | ||
| 226 | + | ||
| 227 | +The three existing square arms stay for `leaf=(4, 4)` (the `decode_leaf_split4` | ||
| 228 | +route, one `TX_4X4` per odd-column leaf, which tiles 4x8 correctly) and for | ||
| 229 | +lossless (two stacked `TX_4X4`, which is what libaom walks there). | ||
| 230 | + | ||
| 231 | +**Why a real fix and not a detection/padding.** Refusal is not available: the | ||
| 232 | +sequence header is self-consistent AV1 and the partition/mode syntax is | ||
| 233 | +subsampling-independent, so the tile parses with no signal that the header and | ||
| 234 | +the tile disagree — there is nothing to detect. Pre-filling the plane with 0 or | ||
| 235 | +with a mid-grey would hide the class and still emit wrong pixels. Making the | ||
| 236 | +walk cover the block it was handed is the only real answer, and the walk's own | ||
| 237 | +libaom derivation says what "cover" is: one `TX_4X8`. | ||
| 238 | + | ||
| 239 | +### 3.1 After the fix | ||
| 240 | + | ||
| 241 | +``` | ||
| 242 | +$ EC_AV1_PLANE_SENTINEL=1 EC_AV1_SENTINEL_CENSUS=1 \ | ||
| 243 | + ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu 2>&1 >/dev/null | ||
| 244 | +SENTINEL_CENSUS idx=0 plane=Y extent=64x64 unwritten=0 | ||
| 245 | +SENTINEL_CENSUS idx=0 plane=U extent=32x64 unwritten=0 | ||
| 246 | +SENTINEL_CENSUS idx=0 plane=V extent=32x64 unwritten=0 | ||
| 247 | + | ||
| 248 | +$ for i in 1 2 3 4 5; do EC_AV1_FINAL_DUMP=/tmp/wt_aw/w$i \ | ||
| 249 | + ./target/debug/examples/decode_probe crates/ec-av1/fixtures/440_request_is_422.obu >/dev/null 2>&1; \ | ||
| 250 | + sha256sum /tmp/wt_aw/w$i.f0; done | ||
| 251 | +3823d219ba99c28c904d3a4f6f695fe56fa6cd5b7f26da5919e525b36478d7df ... (x5, identical) | ||
| 252 | +``` | ||
| 253 | + | ||
| 254 | +Five runs, one hash. | ||
| 255 | + | ||
| 256 | +--- | ||
| 257 | + | ||
| 258 | +## 4. The gate | ||
| 259 | + | ||
| 260 | +`crates/ec-av1/src/stream.rs`, `a_422_header_over_a_420_tile_leaves_no_sample_unwritten`: | ||
| 261 | + | ||
| 262 | +* pins the same fixture through the existing `read_pin` (2014 bytes, | ||
| 263 | + fnv1a64 `0x98a1378df976253d`); | ||
| 264 | +* turns the sentinel on through the new `decode::set_plane_sentinel` (a thread | ||
| 265 | + local, because this crate snapshots the environment once per process and a | ||
| 266 | + gate cannot set a process-constant env var) and turns it off again through a | ||
| 267 | + `Drop` guard; | ||
| 268 | +* decodes it and asserts `decode::take_unwritten_samples() == 0`; | ||
| 269 | +* asserts `decode::take_census_scanned() >= 64*64 + 2*32*64`, so a census that | ||
| 270 | + scanned nothing cannot pass as a census that found nothing | ||
| 271 | + (`vacuous-test-assertions`). | ||
| 272 | + | ||
| 273 | +``` | ||
| 274 | +$ cargo test -p ec-av1 --features gate-counters --lib a_422_header_over_a_420_tile_leaves_no_sample_unwritten | ||
| 275 | +test stream::tests::a_422_header_over_a_420_tile_leaves_no_sample_unwritten ... ok | ||
| 276 | +test result: ok. 1 passed; 0 failed; ... | ||
| 277 | +``` | ||
| 278 | + | ||
| 279 | +### 4.1 Mutation: the gate bites | ||
| 280 | + | ||
| 281 | +`let rect48 = false && leaf_shape == (4, 8) && !lossless(fctx);` — the fix | ||
| 282 | +disabled, nothing else: | ||
| 283 | + | ||
| 284 | +``` | ||
| 285 | +thread 'stream::tests::a_422_header_over_a_420_tile_leaves_no_sample_unwritten' panicked at | ||
| 286 | + crates/ec-av1/src/stream.rs:2912:9: | ||
| 287 | +assertion `left == right` failed: a_422_header_over_a_420_tile_leaves_no_sample_unwritten: | ||
| 288 | +224 samples of the frame were handed to the tile walk and never written, so they reach the output | ||
| 289 | +as whatever the allocator left there (the five different dump hashes this pin used to give) | ||
| 290 | +test result: FAILED. 0 passed; 1 failed | ||
| 291 | +``` | ||
| 292 | + | ||
| 293 | +224 = 112 (U) + 112 (V), the §1.1 census exactly. Reverted, gate green again. | ||
| 294 | + | ||
| 295 | +--- | ||
| 296 | + | ||
| 297 | +## 5. Regression evidence | ||
| 298 | + | ||
| 299 | +* **Whole-corpus output equality, pre-fix vs post-fix.** Every fixture decoded | ||
| 300 | + with `EC_AV1_FINAL_DUMP` on both trees, all `.f*` files hashed: the two hash | ||
| 301 | + lists differ **only** for `440_request_is_422.obu`. Every 4:2:0 / 4:4:4 / | ||
| 302 | + 4:2:2 committed stream produces byte-identical output, which is what §2.2's | ||
| 303 | + reach measurement predicts (the `leaf=(4, 8)` shape never fires on them). | ||
| 304 | +* **Whole-corpus sentinel sweep re-run after the fix**: `non-clean fixtures: | ||
| 305 | + 0 / 127`. The witness's 112+112 is gone and the other 126 are unchanged, | ||
| 306 | + which is what §2.2's reach measurement predicts. | ||
| 307 | + | ||
| 308 | +--- | ||
| 309 | + | ||
| 310 | +## 6. What this lane did NOT do, and why | ||
| 311 | + | ||
| 312 | +* No oracle comparison for the fix's pixels. The `TX_4X8` chroma unit is | ||
| 313 | + derived from libaom's source (§2.3) and reuses the crate's already-pinned | ||
| 314 | + port of the identical unit, but **no committed valid stream reaches the | ||
| 315 | + shape**, so there is no byte-exact claim to make and none is made. A 4:2:2 | ||
| 316 | + stream whose 8x8 blocks code `PARTITION_HORZ` is the fixture this fix still | ||
| 317 | + wants; building one needs an encoder that emits that partition, which this | ||
| 318 | + crate's encoder does not. | ||
| 319 | +* `film_grain.rs`, the reserved 4:2:0 group-tail chroma SKIP arm and | ||
| 320 | + `decode_rect4_16_intrabc` were not touched. The cause is not in them. | ||
| 321 | +* The census instrument (`census_unwritten`, `set_plane_sentinel`, | ||
| 322 | + `take_unwritten_samples`, `take_census_scanned`) and the | ||
| 323 | + `PlaneBuf::plane` field are additions; the field is what lets the census and | ||
| 324 | + any future write-trace name the plane from the buffer instead of from the | ||
| 325 | + call site. | ||
| \ No newline at end of file | \ No newline at end of file | ||