Merge branch 'lane-av1blend': ref-frame ctx counts both compound-neighbour refs; interp_filter read order
Browse files at this commit3 changed files +554 -91
- crates/ec-av1/src/decode.rs +323 -58
- crates/ec-av1/src/mvstack.rs +87 -29
- crates/ec-av1/src/stream.rs +144 -4
crates/ec-av1/src/decode.rsmodified+323 -58
| @@ -2499,6 +2499,12 @@ fn cdef_filter_block( | |||
| 2499 | // aomdec's EC_AV1_PREFILT_DUMP/EC_AV1_POSTFILT_DUMP) to `$var.f$idx` when | 2499 | // aomdec's EC_AV1_PREFILT_DUMP/EC_AV1_POSTFILT_DUMP) to `$var.f$idx` when |
| 2500 | // `var` is set. Remove with the rest of the r17 bisect scaffolding. | 2500 | // `var` is set. Remove with the rest of the r17 bisect scaffolding. |
| 2501 | static R17_DUMP_FRAME_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | 2501 | static R17_DUMP_FRAME_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); |
| 2502 | +// r17 bisect scratch accessor for stream.rs's own debug prints -- shares the | ||
| 2503 | +// same counter block-decode already reads. Remove with the rest of the r17 | ||
| 2504 | +// bisect scaffolding. | ||
| 2505 | +pub fn r17_dump_frame_idx() -> usize { | ||
| 2506 | + R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed) | ||
| 2507 | +} | ||
| 2502 | fn r17_dump(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, idx: usize) { | 2508 | fn r17_dump(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, idx: usize) { |
| 2503 | let Ok(base) = std::env::var(var) else { | 2509 | let Ok(base) = std::env::var(var) else { |
| 2504 | return; | 2510 | return; |
| @@ -3877,25 +3883,32 @@ fn read_inter_plane( | |||
| 3877 | /// `reference_select` set before this is ever called, so that read is never | 3883 | /// `reference_select` set before this is ever called, so that read is never |
| 3878 | /// needed here). `above_ref`/`left_ref` are `-1` for an intra/unavailable | 3884 | /// needed here). `above_ref`/`left_ref` are `-1` for an intra/unavailable |
| 3879 | /// neighbour, else the `1..=7` reference that neighbour coded (lane-av1refs). | 3885 | /// neighbour, else the `1..=7` reference that neighbour coded (lane-av1refs). |
| 3880 | -fn read_single_ref(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, above_ref: i8, left_ref: i8) -> i8 { | 3886 | +fn read_single_ref( |
| 3887 | + dec: &mut SymbolDecoder, | ||
| 3888 | + cdfs: &mut Cdfs, | ||
| 3889 | + above_ref: i8, | ||
| 3890 | + above_ref1: Option<i8>, | ||
| 3891 | + left_ref: i8, | ||
| 3892 | + left_ref1: Option<i8>, | ||
| 3893 | +) -> i8 { | ||
| 3881 | let above = (above_ref > 0).then_some(above_ref); | 3894 | let above = (above_ref > 0).then_some(above_ref); |
| 3882 | let left = (left_ref > 0).then_some(left_ref); | 3895 | let left = (left_ref > 0).then_some(left_ref); |
| 3883 | - let p1 = dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, left)][0]); | 3896 | + let p1 = dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, above_ref1, left, left_ref1)][0]); |
| 3884 | let ref_frame = if p1 == 1 { | 3897 | let ref_frame = if p1 == 1 { |
| 3885 | - let p2 = dec.symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, left)][1]); | 3898 | + let p2 = dec.symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, above_ref1, left, left_ref1)][1]); |
| 3886 | if p2 == 1 { | 3899 | if p2 == 1 { |
| 3887 | ALTREF_FRAME | 3900 | ALTREF_FRAME |
| 3888 | } else { | 3901 | } else { |
| 3889 | - let p6 = dec.symbol(&mut cdfs.single_ref[single_ref_p6_ctx(above, left)][5]); | 3902 | + let p6 = dec.symbol(&mut cdfs.single_ref[single_ref_p6_ctx(above, above_ref1, left, left_ref1)][5]); |
| 3890 | if p6 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } | 3903 | if p6 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } |
| 3891 | } | 3904 | } |
| 3892 | } else { | 3905 | } else { |
| 3893 | - let p3 = dec.symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, left)][2]); | 3906 | + let p3 = dec.symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, above_ref1, left, left_ref1)][2]); |
| 3894 | if p3 == 1 { | 3907 | if p3 == 1 { |
| 3895 | - let p5 = dec.symbol(&mut cdfs.single_ref[single_ref_p5_ctx(above, left)][4]); | 3908 | + let p5 = dec.symbol(&mut cdfs.single_ref[single_ref_p5_ctx(above, above_ref1, left, left_ref1)][4]); |
| 3896 | if p5 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } | 3909 | if p5 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } |
| 3897 | } else { | 3910 | } else { |
| 3898 | - let p4 = dec.symbol(&mut cdfs.single_ref[single_ref_p4_ctx(above, left)][3]); | 3911 | + let p4 = dec.symbol(&mut cdfs.single_ref[single_ref_p4_ctx(above, above_ref1, left, left_ref1)][3]); |
| 3899 | if p4 == 1 { LAST2_FRAME } else { LAST_FRAME } | 3912 | if p4 == 1 { LAST2_FRAME } else { LAST_FRAME } |
| 3900 | } | 3913 | } |
| 3901 | }; | 3914 | }; |
| @@ -4051,19 +4064,26 @@ fn read_compound_ref_frames( | |||
| 4051 | ) -> (i8, i8) { | 4064 | ) -> (i8, i8) { |
| 4052 | let a = (above_ref > 0).then_some(above_ref); | 4065 | let a = (above_ref > 0).then_some(above_ref); |
| 4053 | let l = (left_ref > 0).then_some(left_ref); | 4066 | let l = (left_ref > 0).then_some(left_ref); |
| 4067 | + // libaom `av1_collect_neighbors_ref_counts` counts BOTH of a compound | ||
| 4068 | + // neighbour's references, not just its first -- `a1`/`l1` carry that | ||
| 4069 | + // second reference through to every vote below (lane-av1blend r6: a | ||
| 4070 | + // missing `a1`/`l1` here was decoding `compound_idx` off the wrong CDF | ||
| 4071 | + // row for a block sitting under a skip_mode-forced compound neighbour). | ||
| 4072 | + let a1 = above.and_then(|n| n.ref1); | ||
| 4073 | + let l1 = left.and_then(|n| n.ref1); | ||
| 4054 | let type_ctx = comp_reference_type_ctx(above, left); | 4074 | let type_ctx = comp_reference_type_ctx(above, left); |
| 4055 | let unidir = dec.symbol(&mut cdfs.comp_ref_type[type_ctx]) == 0; | 4075 | let unidir = dec.symbol(&mut cdfs.comp_ref_type[type_ctx]) == 0; |
| 4056 | if unidir { | 4076 | if unidir { |
| 4057 | // uni_comp_ref (p0): forward vs. backward -- av1_get_pred_context_- | 4077 | // uni_comp_ref (p0): forward vs. backward -- av1_get_pred_context_- |
| 4058 | // uni_comp_ref_p is single_ref_p1's own forward/backward vote. | 4078 | // uni_comp_ref_p is single_ref_p1's own forward/backward vote. |
| 4059 | - let bit = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p1_ctx(a, l)][0]); | 4079 | + let bit = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p1_ctx(a, a1, l, l1)][0]); |
| 4060 | if bit == 1 { | 4080 | if bit == 1 { |
| 4061 | (BWDREF_FRAME, ALTREF_FRAME) | 4081 | (BWDREF_FRAME, ALTREF_FRAME) |
| 4062 | } else { | 4082 | } else { |
| 4063 | - let p1 = dec.symbol(&mut cdfs.uni_comp_ref[uni_comp_ref_p1_ctx(a, l)][1]); | 4083 | + let p1 = dec.symbol(&mut cdfs.uni_comp_ref[uni_comp_ref_p1_ctx(a, a1, l, l1)][1]); |
| 4064 | if p1 == 1 { | 4084 | if p1 == 1 { |
| 4065 | // uni_comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5. | 4085 | // uni_comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5. |
| 4066 | - let p2 = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p5_ctx(a, l)][2]); | 4086 | + let p2 = dec.symbol(&mut cdfs.uni_comp_ref[single_ref_p5_ctx(a, a1, l, l1)][2]); |
| 4067 | if p2 == 1 { | 4087 | if p2 == 1 { |
| 4068 | (LAST_FRAME, GOLDEN_FRAME) | 4088 | (LAST_FRAME, GOLDEN_FRAME) |
| 4069 | } else { | 4089 | } else { |
| @@ -4075,21 +4095,21 @@ fn read_compound_ref_frames( | |||
| 4075 | } | 4095 | } |
| 4076 | } else { | 4096 | } else { |
| 4077 | // comp_ref (p0): LAST/LAST2 vs. LAST3/GOLDEN, same vote as single_ref_p3. | 4097 | // comp_ref (p0): LAST/LAST2 vs. LAST3/GOLDEN, same vote as single_ref_p3. |
| 4078 | - let bit0 = dec.symbol(&mut cdfs.comp_ref[single_ref_p3_ctx(a, l)][0]); | 4098 | + let bit0 = dec.symbol(&mut cdfs.comp_ref[single_ref_p3_ctx(a, a1, l, l1)][0]); |
| 4079 | let ref0 = if bit0 == 0 { | 4099 | let ref0 = if bit0 == 0 { |
| 4080 | // comp_ref_p1: LAST vs. LAST2, same vote as single_ref_p4. | 4100 | // comp_ref_p1: LAST vs. LAST2, same vote as single_ref_p4. |
| 4081 | - let p1 = dec.symbol(&mut cdfs.comp_ref[single_ref_p4_ctx(a, l)][1]); | 4101 | + let p1 = dec.symbol(&mut cdfs.comp_ref[single_ref_p4_ctx(a, a1, l, l1)][1]); |
| 4082 | if p1 == 1 { LAST2_FRAME } else { LAST_FRAME } | 4102 | if p1 == 1 { LAST2_FRAME } else { LAST_FRAME } |
| 4083 | } else { | 4103 | } else { |
| 4084 | // comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5. | 4104 | // comp_ref_p2: LAST3 vs. GOLDEN, same vote as single_ref_p5. |
| 4085 | - let p2 = dec.symbol(&mut cdfs.comp_ref[single_ref_p5_ctx(a, l)][2]); | 4105 | + let p2 = dec.symbol(&mut cdfs.comp_ref[single_ref_p5_ctx(a, a1, l, l1)][2]); |
| 4086 | if p2 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } | 4106 | if p2 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } |
| 4087 | }; | 4107 | }; |
| 4088 | // comp_bwdref (p0): BWDREF/ALTREF2 vs. ALTREF, same vote as single_ref_p2. | 4108 | // comp_bwdref (p0): BWDREF/ALTREF2 vs. ALTREF, same vote as single_ref_p2. |
| 4089 | - let bit1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p2_ctx(a, l)][0]); | 4109 | + let bit1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p2_ctx(a, a1, l, l1)][0]); |
| 4090 | let ref1 = if bit1 == 0 { | 4110 | let ref1 = if bit1 == 0 { |
| 4091 | // comp_bwdref_p1: BWDREF vs. ALTREF2, same vote as single_ref_p6. | 4111 | // comp_bwdref_p1: BWDREF vs. ALTREF2, same vote as single_ref_p6. |
| 4092 | - let p1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p6_ctx(a, l)][1]); | 4112 | + let p1 = dec.symbol(&mut cdfs.comp_bwdref[single_ref_p6_ctx(a, a1, l, l1)][1]); |
| 4093 | if p1 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } | 4113 | if p1 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } |
| 4094 | } else { | 4114 | } else { |
| 4095 | ALTREF_FRAME | 4115 | ALTREF_FRAME |
| @@ -4293,6 +4313,14 @@ fn decode_inter_block( | |||
| 4293 | let (cpx, cpy) = (px / 2, py / 2); | 4313 | let (cpx, cpy) = (px / 2, py / 2); |
| 4294 | let chroma_side = side / 2; | 4314 | let chroma_side = side / 2; |
| 4295 | 4315 | ||
| 4316 | + if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | ||
| 4317 | + eprintln!( | ||
| 4318 | + "BITPOS_BLK_START mi_row={} mi_col={} bitpos={}", | ||
| 4319 | + py / 4, | ||
| 4320 | + px / 4, | ||
| 4321 | + dec.debug_bitpos() | ||
| 4322 | + ); | ||
| 4323 | + } | ||
| 4296 | let skip_mode_ctx = | 4324 | let skip_mode_ctx = |
| 4297 | usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); | 4325 | usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); |
| 4298 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; | 4326 | let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; |
| @@ -4412,16 +4440,6 @@ fn decode_inter_block( | |||
| 4412 | } else { | 4440 | } else { |
| 4413 | [3, 3] | 4441 | [3, 3] |
| 4414 | }; | 4442 | }; |
| 4415 | - let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | ||
| 4416 | - dec, | ||
| 4417 | - cdfs, | ||
| 4418 | - interp_fixed, | ||
| 4419 | - enable_dual_filter, | ||
| 4420 | - is_globalmv, | ||
| 4421 | - above_filter_ctx, | ||
| 4422 | - left_filter_ctx, | ||
| 4423 | - ); | ||
| 4424 | - block_filter = resolved_filter; | ||
| 4425 | globalmv_for_lf = is_globalmv; | 4443 | globalmv_for_lf = is_globalmv; |
| 4426 | ref_frame_for_lf = ref0; | 4444 | ref_frame_for_lf = ref0; |
| 4427 | mode_for_tx = 0; | 4445 | mode_for_tx = 0; |
| @@ -4466,33 +4484,193 @@ fn decode_inter_block( | |||
| 4466 | weighted/simple-average combine only, lane-av1comp", | 4484 | weighted/simple-average combine only, lane-av1comp", |
| 4467 | )); | 4485 | )); |
| 4468 | } | 4486 | } |
| 4469 | - // corner-cut (lane-av1comp r16/r17): a real aomenc stream | 4487 | + // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17 |
| 4470 | - // (fixtures/av1comp-r16-compound-mismatch.obu, seed 42) proved | 4488 | + // called this a `predict_compound_intermediate`/`combine_compound` |
| 4471 | - // predict_compound_intermediate/combine_compound wrong by up to | 4489 | + // reconstruction defect. r1 FALSIFIED that hypothesis outright: |
| 4472 | - // 4/255 in a 32x32 quadrant, spilling a few pixels into | 4490 | + // unmasking and running the real gates |
| 4473 | - // neighbours. r16 called this "loop-filter-shaped"; r17 | 4491 | + // (a_real_aomenc_stream_with_reference_select_reads_comp_mode_correctly, |
| 4474 | - // FALSIFIED that -- dumping this decoder's own pre-deblock | 4492 | + // a_real_aomenc_stream_with_compound_references_decodes_pixel_exact) |
| 4475 | - // frame buffer (`r17_dump`, `EC_AV1_PREFILT_DUMP`) against | 4493 | + // shows the plain-average blend is bit-exact *most of the time* |
| 4476 | - // aomdec's own `EC_AV1_PREFILT_DUMP` shows the same 32x32- | 4494 | + // -- `combine_compound`'s two-shift-in-one round2 was proven |
| 4477 | - // quadrant mismatch already present *before* either decoder's | 4495 | + // algebraically identical to libaom's separate |
| 4478 | - // loop filter runs (898/1024 px, rows 32-63 cols 32-63 of a | 4496 | + // `>>DIST_PRECISION_BITS`-then-`ROUND_POWER_OF_TWO` sequence |
| 4479 | - // 64x64 luma plane, frame index 2 zero-based / this decoder's | 4497 | + // (av1_dist_wtd_convolve_2d_c, convolve.c:402-415) for every |
| 4480 | - // 3rd frame) -- this is a `predict_compound_intermediate`/ | 4498 | + // input, and a whole-pel zero-MV compound block (mv0=mv1=(0,0), |
| 4481 | - // `combine_compound` reconstruction defect, not a deblock | 4499 | + // the common case a lag-in-frames GOP's hidden altref frames |
| 4482 | - // interaction. DRL/assign_compound_mv/dist_wtd_comp_weight_assign | 4500 | + // hit) reproduces aomdec's own pre-deblock `EC_AV1_PREFILT_DUMP` |
| 4483 | - // stay cross-checked bit-for-bit against libaom decodemv.c/ | 4501 | + // byte-for-byte for several consecutive frames. |
| 4484 | - // reconinter.c (r16). Root cause still not isolated within this | 4502 | + // |
| 4485 | - // arithmetic; refuse by name rather than ship a non-pixel-exact | 4503 | + // The real defect a live gate run isolated (seed 49, |
| 4486 | - // compound blend. Ceiling: r13/r14's MC plumbing above this line | 4504 | + // `fixtures/av1blend-r1-mismatch.obu`): decode-order frame 0 |
| 4505 | + // (keyframe) and frame 1 (first hidden altref, `ref1 == | ||
| 4506 | + // ALTREF_FRAME`) match aomdec's own pre-deblock dump byte for | ||
| 4507 | + // byte; decode-order frame 2 -- same shape, same zero MV, only | ||
| 4508 | + // difference `ref1 == BWDREF_FRAME` instead of `ALTREF_FRAME` -- | ||
| 4509 | + // is the *first* frame to diverge (881/6144 luma+chroma bytes). | ||
| 4510 | + // Every later frame up through decode-order 9 also mismatches, | ||
| 4511 | + // *including* frame 8, whose four blocks are back to | ||
| 4512 | + // `ref1 == ALTREF_FRAME` only -- ruling out "BWDREF_FRAME's MC | ||
| 4513 | + // math is wrong" (that block's own math is proven exact) in | ||
| 4514 | + // favour of "the picture sitting in some DPB slot is already | ||
| 4515 | + // wrong by the time frame 2 reads it, and the corruption | ||
| 4516 | + // propagates through refresh_frame_flags into every later | ||
| 4517 | + // reference regardless of which named ref a later block picks". | ||
| 4518 | + // Frames 10 through 18 (once the GOP's lineage stops tracing | ||
| 4519 | + // back through the bad slot) are bit-exact again. This points at | ||
| 4520 | + // reference-slot bookkeeping (`ref_slots`/`refresh_frame_flags` | ||
| 4521 | + // in `stream.rs`'s `decode_stream`, or `ref_order_hints`/DPB | ||
| 4522 | + // indexing feeding `dist_wtd_comp_weight_assign`) around | ||
| 4523 | + // BWDREF_FRAME specifically, not at the MC/blend arithmetic in | ||
| 4524 | + // mc.rs. Not isolated further within lane-av1blend's budget -- | ||
| 4525 | + // refuse by name rather than ship a blend that is right only | ||
| 4526 | + // sometimes. Ceiling: r13/r14's MC plumbing above this line | ||
| 4487 | // stays -- only the plain-average reconstruct is masked off | 4527 | // stays -- only the plain-average reconstruct is masked off |
| 4488 | - // again. Upgrade: bisect predict_compound_intermediate itself | 4528 | + // again. Upgrade: instrument `ref_slots`/`refresh_frame_flags` |
| 4489 | - // (subpel filter taps / rounding) against the pinned fixture's | 4529 | + // per decode-order frame (which slot each `Frame` OBU refreshes, |
| 4490 | - // 3rd frame, quadrant rows 32-63 cols 32-63. | 4530 | + // and which slot each `ref_frame_idx[BWDREF_FRAME - LAST_FRAME]` |
| 4531 | + // reads) against aomdec's own `RefCntBuffer` bookkeeping on | ||
| 4532 | + // `fixtures/av1blend-r1-mismatch.obu`, starting at decode-order | ||
| 4533 | + // frame 2. | ||
| 4534 | + // | ||
| 4535 | + // r2 (fresh fixture, seed 45, same recipe -- the original r1 | ||
| 4536 | + // fixture is gitignored and could not be regenerated byte-exact): | ||
| 4537 | + // static review of `stream.rs`'s `ref_slots`/`refresh_frame_flags`/ | ||
| 4538 | + // `cdf_slots` bookkeeping and the `show_existing_frame` refresh | ||
| 4539 | + // arm (spec 7.21: only refreshes on a shown KEY frame, which the | ||
| 4540 | + // parser already enforces at `frame.rs:791/815` -- `refresh_frame_flags` | ||
| 4541 | + // is forced 0 on every non-key `show_existing_frame`) turned up | ||
| 4542 | + // nothing wrong; `other_refs`/`ref_planes` slot indexing for | ||
| 4543 | + // `BWDREF_FRAME` is spec-correct too. A live unmasked run | ||
| 4544 | + // isolated a *different, smaller* shape than r1's: decode-order | ||
| 4545 | + // frame 3 (a `ref1 == BWDREF_FRAME`, zero-MV, simple-average | ||
| 4546 | + // compound block) is the first to diverge from ffmpeg (worst | ||
| 4547 | + // delta 1, luma only, clustered at 32-pixel block edges) even | ||
| 4548 | + // though BOTH its compound inputs -- the key frame and | ||
| 4549 | + // decode-order frame 2's own picture (`ref1 == ALTREF_FRAME`, | ||
| 4550 | + // itself proven bit-exact: it is later re-shown via | ||
| 4551 | + // `show_existing_frame` and matches ffmpeg exactly) -- are | ||
| 4552 | + // independently pixel-exact, and the blend arithmetic is the | ||
| 4553 | + // same proven-exact formula. That rules out "wrong slot"/"stale | ||
| 4554 | + // picture" for this fixture: the inputs are right, so the defect | ||
| 4555 | + // is in decode-order frame 3's *own* per-block decode (entropy | ||
| 4556 | + // desync from compound-CDF adaptation carried across a slot, or | ||
| 4557 | + // the compound mode/MV read itself) -- not in `ref_slots`/ | ||
| 4558 | + // `refresh_frame_flags`. Not isolated further within budget. | ||
| 4559 | + // Upgrade: bisect decode-order frame 3's tile decode against a | ||
| 4560 | + // synced `EC_TOK`/`EC_PART` trace from the instrumented aomdec | ||
| 4561 | + // build (`/tmp/libaom-src/build/decoder-debug/aomdec`) on | ||
| 4562 | + // `fixtures/av1blend-r1-mismatch.obu` (seed 45 now, not seed 49) | ||
| 4563 | + // -- the pre-deblock `EC_AV1_PREFILT_DUMP` frame-index alignment | ||
| 4564 | + // between this crate and that aomdec build is NOT 1:1 on this | ||
| 4565 | + // fixture (23 dumps here vs 24 there), so calibrate that first. | ||
| 4566 | + // r3 (this round): pre-deblock buffers were bisected byte-for-byte | ||
| 4567 | + // against an instrumented aomdec build (EC_AV1_PREFILT_DUMP, | ||
| 4568 | + // frame-index alignment recalibrated via content-hash matching | ||
| 4569 | + // rather than the raw dump count -- the keyframe never calls this | ||
| 4570 | + // crate's own `r17_dump` at all, since only `decode_inter_frame_ | ||
| 4571 | + // tile` does, which is the whole "23 vs 24" gap, not a real bug). | ||
| 4572 | + // Decode-order frame 3 (`fixtures/av1blend-r1-mismatch.obu`, | ||
| 4573 | + // seed 45) is still the first divergence: PRE-deblock differs | ||
| 4574 | + // from aomdec's own pre-deblock dump by up to 1, on ~20% of | ||
| 4575 | + // luma pixels, clustered where its two compound inputs' pixel | ||
| 4576 | + // values disagree by more than a couple of levels -- both | ||
| 4577 | + // inputs (the keyframe and decode-order frame 2's own picture) | ||
| 4578 | + // are independently proven bit-exact (pre- and post-deblock) | ||
| 4579 | + // against aomdec, and `decodemv`'s own EC_TRACE (mode/mv/skip) | ||
| 4580 | + // matches this decoder's block loop exactly for every block in | ||
| 4581 | + // this frame. Solving `aomval = (key*w0 + bwd*w1 + 8) >> 4` for | ||
| 4582 | + // every mismatching pixel against `key`/`bwd` (both known-exact) | ||
| 4583 | + // picks out `w0=9, w1=7` for the majority (525/846) with zero | ||
| 4584 | + // matches for the plain average this decoder actually emits or | ||
| 4585 | + // the reversed `w0=7, w1=9` -- i.e. `compound_idx` is being | ||
| 4586 | + // decoded as `1` (simple average, spec `COMPOUND_AVERAGE`) when | ||
| 4587 | + // the real bitstream encoded `0` (`COMPOUND_DISTWTD`, | ||
| 4588 | + // `dist_wtd_comp_weight_assign`'s own weights for this frame's | ||
| 4589 | + // order-hint distances 2/3 land on exactly `(9, 7)` -- this | ||
| 4590 | + // decoder's own `dist_wtd_comp_weight_assign` was independently | ||
| 4591 | + // re-verified against `QUANT_DIST_WEIGHT`/`QUANT_DIST_LOOKUP_TABLE` | ||
| 4592 | + // by hand for these distances and gives the same `(9, 7)`). | ||
| 4593 | + // `get_comp_index_context` was checked line-for-line against | ||
| 4594 | + // libaom's `pred_common.h` (the `fwd`/`bck` distance halves, the | ||
| 4595 | + // `above_mi`/`left_mi` `has_second_ref`/`ALTREF_FRAME` fallback, | ||
| 4596 | + // the `3 * offset` term) and matches; `Default_Compound_Idx_Cdf` | ||
| 4597 | + // (`cdf.rs`'s `COMPOUND_IDX`) matches `entropymode.c`'s | ||
| 4598 | + // `default_compound_idx_cdfs` value-for-value; the read is | ||
| 4599 | + // gated on `!skip_mode && enable_jnt_comp`, matching libaom's | ||
| 4600 | + // `has_second_ref(mbmi) && !mbmi->skip_mode` outer guard plus | ||
| 4601 | + // `order_hint_info.enable_dist_wtd_comp` inner guard. The | ||
| 4602 | + // remaining 321/846 mismatched pixels do NOT fit `(9, 7)` | ||
| 4603 | + // either -- some blocks in this frame plausibly decode a | ||
| 4604 | + // genuinely different (correct, context-dependent) compound_idx | ||
| 4605 | + // than block (0,0)'s own -- so this is not simply "always wrong | ||
| 4606 | + // the same way": table/context/gate are all individually | ||
| 4607 | + // verified correct, yet the decoded VALUE at this specific | ||
| 4608 | + // symbol is wrong at least once in this frame. Not isolated | ||
| 4609 | + // further within budget. Upgrade: instrument `dec.symbol`'s own | ||
| 4610 | + // range/bit state (`rng`/`tell`, matching aomdec's own EC_PART | ||
| 4611 | + // trace fields) immediately before and after the `compound_idx` | ||
| 4612 | + // read specifically, not just the surrounding mode/mv/skip | ||
| 4613 | + // trace which does match -- the desync (if any) is local to | ||
| 4614 | + // this one read, not a wider stream desync. | ||
| 4615 | + // | ||
| 4616 | + // r5 (this round): the `resolve_interp_filter` call used to sit | ||
| 4617 | + // right here, ahead of `comp_group_idx`/`compound_idx` -- spec | ||
| 4618 | + // 5.11.19/libaom `decodemv.c:1575` reads `interp_filter` AFTER | ||
| 4619 | + // `read_compound_type`, not before, so that was a genuine | ||
| 4620 | + // ordering bug for a Switchable-filter frame (moved below, past | ||
| 4621 | + // the `compound_ctx = Some(...)` line). It does NOT explain this | ||
| 4622 | + // fixture's own mismatch, though: `av1blend-r1-mismatch.obu`'s | ||
| 4623 | + // header carries a *fixed* interpolation filter | ||
| 4624 | + // (`interp_fixed = Some(Regular)`, confirmed live via a | ||
| 4625 | + // one-off dump), so `resolve_interp_filter` never read a symbol | ||
| 4626 | + // in either position -- zero bits moved, decoded values | ||
| 4627 | + // unchanged before and after the reorder. Kept anyway: it is a | ||
| 4628 | + // real spec-order fix for the next Switchable-filter compound | ||
| 4629 | + // stream, independently correct regardless of this fixture. | ||
| 4630 | + // | ||
| 4631 | + // Also ruled out this round: comparing this crate's own | ||
| 4632 | + // `SymbolDecoder::debug_bitpos()` against aomdec's | ||
| 4633 | + // `aom_reader_tell()` at the block boundary is NOT a valid | ||
| 4634 | + // desync probe -- they are different quantities (raw consumed | ||
| 4635 | + // input bits vs. an entropy-cost estimate that advances without | ||
| 4636 | + // a literal byte fetch), so equal/unequal bitpos proves nothing | ||
| 4637 | + // either way. Do not repeat that comparison; instead trace | ||
| 4638 | + // `range`/`value` (this crate) against libaom's own internal | ||
| 4639 | + // `dif`/`rng` (needs new instrumentation in both) immediately | ||
| 4640 | + // after each read *upstream* of this one in the same block: | ||
| 4641 | + // `read_comp_mode`, `read_compound_ref_frames` (comp_ref_type/ | ||
| 4642 | + // uni_comp_ref/comp_ref/comp_bwdref), `read_inter_compound_mode`, | ||
| 4643 | + // and the DRL loop. All of those independently decoded the SAME | ||
| 4644 | + // values this crate and aomdec both show (ref0=1, ref1=5, mode | ||
| 4645 | + // NEAREST_NEARESTMV, mv=(0,0)) -- but an upstream *context* | ||
| 4646 | + // miscomputation can still decode the identical symbol value off | ||
| 4647 | + // a slightly different CDF, narrowing `range` by a different | ||
| 4648 | + // amount than aomdec without changing the decoded value itself, | ||
| 4649 | + // and only surface as a wrong decode a few reads later exactly | ||
| 4650 | + // like this. `get_comp_index_context` and the `COMPOUND_IDX` | ||
| 4651 | + // table were independently re-verified again this round and are | ||
| 4652 | + // still correct; the four candidates above were not re-audited | ||
| 4653 | + // this round. Refusing here (rather than shipping a value-exact- | ||
| 4654 | + // most-of-the-time blend) until one of them is found wrong. | ||
| 4655 | + // r6/r7: found and fixed one real bug (mvstack.rs ref_ctx family | ||
| 4656 | + // undercounted compound neighbours in the single_ref_p*/comp_ref*/ | ||
| 4657 | + // comp_bwdref* context reads -- kept, real fix). Unmasking on | ||
| 4658 | + // that fix alone and running the wide gate sweep (many seeds, | ||
| 4659 | + // `a_real_aomenc_stream_with_compound_references_decodes_pixel_exact`/ | ||
| 4660 | + // `a_real_aomenc_stream_with_reference_select_reads_comp_mode_correctly`, | ||
| 4661 | + // cq-level=45) still mismatches roughly half the time, at | ||
| 4662 | + // different frames each run for the SAME seed -- aomenc's own | ||
| 4663 | + // cpu-used=0 RD search is run-to-run nondeterministic (noted | ||
| 4664 | + // above), so this is a second, still-unfound compound_idx defect, | ||
| 4665 | + // not the one r6/r7 fixed. r6's own residual-mismatch note (321/ | ||
| 4666 | + // 846 pixels not fitting the (9,7)-vs-plain-average hypothesis | ||
| 4667 | + // either) already flagged more than one bug here. Re-masking: | ||
| 4668 | + // do not ship a blend that is right only sometimes. | ||
| 4491 | return Err(unsupported( | 4669 | return Err(unsupported( |
| 4492 | - "a COMPOUND_REFERENCE block using the plain/distance-weighted \ | 4670 | + "a COMPOUND_REFERENCE 16x16 leaf using the plain/distance-weighted \ |
| 4493 | - average blend (comp_group_idx == 0) -- proven non-pixel-exact \ | 4671 | + average blend (comp_group_idx == 0) -- proven non-pixel-exact against \ |
| 4494 | - against a real aomenc stream (lane-av1comp r16, see \ | 4672 | + real aomenc streams beyond the one bug lane-av1blend r6/r7 fixed \ |
| 4495 | - av1comp-r16-compound-mismatch.obu)", | 4673 | + (lane-av1blend r7, wide gate sweep)", |
| 4496 | )); | 4674 | )); |
| 4497 | #[allow(unreachable_code)] | 4675 | #[allow(unreachable_code)] |
| 4498 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 4676 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { |
| @@ -4505,7 +4683,25 @@ fn decode_inter_block( | |||
| 4505 | ref_order_hints[(ref0 - LAST_FRAME) as usize], | 4683 | ref_order_hints[(ref0 - LAST_FRAME) as usize], |
| 4506 | ref_order_hints[(ref1 - LAST_FRAME) as usize], | 4684 | ref_order_hints[(ref1 - LAST_FRAME) as usize], |
| 4507 | ); | 4685 | ); |
| 4686 | + if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | ||
| 4687 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | ||
| 4688 | + eprintln!( | ||
| 4689 | + "COMPIDX_BLK fidx={fidx} mi_row={} mi_col={} ctx={idx_ctx} cdf0={} \ | ||
| 4690 | + ref0={ref0} ref1={ref1}", | ||
| 4691 | + py / 4, | ||
| 4692 | + px / 4, | ||
| 4693 | + cdfs.compound_idx[idx_ctx][0] | ||
| 4694 | + ); | ||
| 4695 | + } | ||
| 4508 | let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); | 4696 | let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); |
| 4697 | + if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | ||
| 4698 | + eprintln!( | ||
| 4699 | + "COMPIDX_VAL mi_row={} mi_col={} decoded={idx} bitpos={}", | ||
| 4700 | + py / 4, | ||
| 4701 | + px / 4, | ||
| 4702 | + dec.debug_bitpos() | ||
| 4703 | + ); | ||
| 4704 | + } | ||
| 4509 | if idx == 1 { | 4705 | if idx == 1 { |
| 4510 | (8, 8, 1u8) | 4706 | (8, 8, 1u8) |
| 4511 | } else { | 4707 | } else { |
| @@ -4522,6 +4718,31 @@ fn decode_inter_block( | |||
| 4522 | }; | 4718 | }; |
| 4523 | compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx)); | 4719 | compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx)); |
| 4524 | 4720 | ||
| 4721 | + // spec 5.11.19/libaom `decodemv.c` 1575: `read_mb_interp_filter` | ||
| 4722 | + // comes AFTER `read_compound_type` (the `comp_group_idx`/ | ||
| 4723 | + // `compound_idx` reads just above), not before -- moved here | ||
| 4724 | + // (lane-av1blend r5) from its old position ahead of those reads, | ||
| 4725 | + // which stole their bits for a Switchable-filter compound block | ||
| 4726 | + // and desynced every symbol read after it in the tile. | ||
| 4727 | + if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | ||
| 4728 | + eprintln!( | ||
| 4729 | + "IFILTER_PRE mi_row={} mi_col={} interp_fixed={:?} is_globalmv={is_globalmv}", | ||
| 4730 | + py / 4, | ||
| 4731 | + px / 4, | ||
| 4732 | + interp_fixed | ||
| 4733 | + ); | ||
| 4734 | + } | ||
| 4735 | + let (h_filter, v_filter, resolved_filter) = resolve_interp_filter( | ||
| 4736 | + dec, | ||
| 4737 | + cdfs, | ||
| 4738 | + interp_fixed, | ||
| 4739 | + enable_dual_filter, | ||
| 4740 | + is_globalmv, | ||
| 4741 | + above_filter_ctx, | ||
| 4742 | + left_filter_ctx, | ||
| 4743 | + ); | ||
| 4744 | + block_filter = resolved_filter; | ||
| 4745 | + | ||
| 4525 | let mut inter0_y = vec![0i32; side * side]; | 4746 | let mut inter0_y = vec![0i32; side * side]; |
| 4526 | mc::predict_compound_intermediate( | 4747 | mc::predict_compound_intermediate( |
| 4527 | &py0.data, | 4748 | &py0.data, |
| @@ -4553,6 +4774,20 @@ fn decode_inter_block( | |||
| 4553 | let mut pred_y = vec![0u8; side * side]; | 4774 | let mut pred_y = vec![0u8; side * side]; |
| 4554 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 4775 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); |
| 4555 | 4776 | ||
| 4777 | + // r17 bisect scratch: dump per-block compound state when this | ||
| 4778 | + // block overlaps the pinned fixture's bad quadrant (frame 2, | ||
| 4779 | + // rows 32-63 cols 32-63). Remove with the rest of the scaffolding. | ||
| 4780 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 4781 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | ||
| 4782 | + eprintln!( | ||
| 4783 | + "leaf16 fidx={fidx} px={px} py={py} side={side} ref0={ref0} ref1={ref1} \ | ||
| 4784 | + mv0={mv0:?} mv1={mv1:?} filter={resolved_filter:?} \ | ||
| 4785 | + fwd={fwd_offset} bck={bck_offset} compound_idx={compound_idx} \ | ||
| 4786 | + pred_y[0..4]={:?}", | ||
| 4787 | + &pred_y[0..4.min(pred_y.len())] | ||
| 4788 | + ); | ||
| 4789 | + } | ||
| 4790 | + | ||
| 4556 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; | 4791 | let mut inter0_u = vec![0i32; chroma_side * chroma_side]; |
| 4557 | mc::predict_compound_intermediate( | 4792 | mc::predict_compound_intermediate( |
| 4558 | &pu0.data, | 4793 | &pu0.data, |
| @@ -4684,7 +4919,14 @@ fn decode_inter_block( | |||
| 4684 | } | 4919 | } |
| 4685 | } else { | 4920 | } else { |
| 4686 | let ref_frame = | 4921 | let ref_frame = |
| 4687 | - read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]); | 4922 | + read_single_ref( |
| 4923 | + dec, | ||
| 4924 | + cdfs, | ||
| 4925 | + neighbours.above_ref[c], | ||
| 4926 | + neighbours.above_ref1[c], | ||
| 4927 | + neighbours.left_ref[r], | ||
| 4928 | + neighbours.left_ref1[r], | ||
| 4929 | + ); | ||
| 4688 | ref_frame_for_lf = ref_frame; | 4930 | ref_frame_for_lf = ref_frame; |
| 4689 | // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own | 4931 | // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own |
| 4690 | // stacked defects (lf_level ref/mode-delta forwarding, the | 4932 | // stacked defects (lf_level ref/mode-delta forwarding, the |
| @@ -5327,16 +5569,22 @@ fn decode_inter_block8( | |||
| 5327 | weighted/simple-average combine only, lane-av1comp", | 5569 | weighted/simple-average combine only, lane-av1comp", |
| 5328 | )); | 5570 | )); |
| 5329 | } | 5571 | } |
| 5330 | - // corner-cut (lane-av1comp r16/r17): same non-pixel-exact | 5572 | + // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same |
| 5331 | - // plain-average reconstruction defect as the 16x16 leaf's | 5573 | + // reference-slot defect as the 16x16 leaf's own mask above |
| 5332 | - // own mask above (r17: falsified as loop-filter-shaped, | 5574 | + // (r1: falsified as an MC/blend math bug, isolated to a DPB |
| 5333 | - // isolated to predict_compound_intermediate/combine_compound | 5575 | + // slot/refresh_frame_flags issue around BWDREF_FRAME) -- see |
| 5334 | - // itself) -- see that comment. | 5576 | + // that comment. |
| 5577 | + // r3: same defect as the 16x16 leaf's own mask above -- see | ||
| 5578 | + // that comment (compound_idx's decoded value, not the blend | ||
| 5579 | + // math or reference-slot bookkeeping). r6/r7: same re-mask | ||
| 5580 | + // as the 16x16 leaf above -- one real bug found and fixed | ||
| 5581 | + // (mvstack.rs ref_ctx family), a second, still-unfound | ||
| 5582 | + // compound_idx defect surfaces on the wide gate sweep. | ||
| 5335 | return Err(unsupported( | 5583 | return Err(unsupported( |
| 5336 | "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \ | 5584 | "a COMPOUND_REFERENCE 8x8 leaf using the plain/distance-weighted \ |
| 5337 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ | 5585 | average blend (comp_group_idx == 0) -- proven non-pixel-exact \ |
| 5338 | - against a real aomenc stream (lane-av1comp r16, see \ | 5586 | + against real aomenc streams beyond the one bug lane-av1blend \ |
| 5339 | - av1comp-r16-compound-mismatch.obu)", | 5587 | + r6/r7 fixed (lane-av1blend r7, wide gate sweep)", |
| 5340 | )); | 5588 | )); |
| 5341 | #[allow(unreachable_code)] | 5589 | #[allow(unreachable_code)] |
| 5342 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { | 5590 | let (fwd_offset, bck_offset, compound_idx) = if !skip_mode && enable_jnt_comp { |
| @@ -5424,6 +5672,15 @@ fn decode_inter_block8( | |||
| 5424 | let mut pred_y = vec![0u8; SIDE * SIDE]; | 5672 | let mut pred_y = vec![0u8; SIDE * SIDE]; |
| 5425 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); | 5673 | mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); |
| 5426 | 5674 | ||
| 5675 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 5676 | + let fidx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | ||
| 5677 | + eprintln!( | ||
| 5678 | + "leaf8 fidx={fidx} px={px} py={py} ref0={ref0} ref1={ref1} \ | ||
| 5679 | + mv0={mv0:?} mv1={mv1:?} fwd={fwd_offset} bck={bck_offset} \ | ||
| 5680 | + compound_idx={compound_idx} pred_y={pred_y:?}" | ||
| 5681 | + ); | ||
| 5682 | + } | ||
| 5683 | + | ||
| 5427 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; | 5684 | let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; |
| 5428 | mc::predict_compound_intermediate( | 5685 | mc::predict_compound_intermediate( |
| 5429 | &pu0.data, | 5686 | &pu0.data, |
| @@ -6105,6 +6362,14 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 6105 | let scan4 = default_scan(TX4); | 6362 | let scan4 = default_scan(TX4); |
| 6106 | 6363 | ||
| 6107 | let mut cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx))); | 6364 | let mut cdfs = initial_cdfs.unwrap_or_else(|| Cdfs::new(q_ctx_of(base_q_idx))); |
| 6365 | + if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { | ||
| 6366 | + let idx = R17_DUMP_FRAME_IDX.load(std::sync::atomic::Ordering::Relaxed); | ||
| 6367 | + eprint!("COMPIDX_PRE fidx={} (aomdec fidx={})", idx, idx + 1); | ||
| 6368 | + for (c, row) in cdfs.compound_idx.iter().enumerate() { | ||
| 6369 | + eprint!(" ctx{c}={}", row[0]); | ||
| 6370 | + } | ||
| 6371 | + eprintln!(); | ||
| 6372 | + } | ||
| 6108 | let mut dec = SymbolDecoder::new(data); | 6373 | let mut dec = SymbolDecoder::new(data); |
| 6109 | let mut neighbours = Neighbours::new( | 6374 | let mut neighbours = Neighbours::new( |
| 6110 | cols as usize * 2, | 6375 | cols as usize * 2, |
crates/ec-av1/src/mvstack.rsmodified+87 -29
| @@ -1697,17 +1697,24 @@ pub(crate) const ALTREF_FRAME: i8 = 7; | |||
| 1697 | /// `left_mbmi`) coded a reference in `a_set` vs. `b_set`, and compare: fewer | 1697 | /// `left_mbmi`) coded a reference in `a_set` vs. `b_set`, and compare: fewer |
| 1698 | /// `a`s than `b`s is context 0, equal is 1 (also every unavailable-neighbour | 1698 | /// `a`s than `b`s is context 0, equal is 1 (also every unavailable-neighbour |
| 1699 | /// case, both counts zero), more `a`s is 2. | 1699 | /// case, both counts zero), more `a`s is 2. |
| 1700 | -fn ref_ctx(above: Option<i8>, left: Option<i8>, a_set: &[i8], b_set: &[i8]) -> usize { | 1700 | +// libaom `av1_collect_neighbors_ref_counts` (mvref_common.h): a neighbour |
| 1701 | - let a = [above, left] | 1701 | +// contributes ONE count per reference frame it actually names, which for a |
| 1702 | - .into_iter() | 1702 | +// compound neighbour is BOTH `ref_frame[0]` and `ref_frame[1]` -- not just |
| 1703 | - .flatten() | 1703 | +// its first. Every one of these vote functions takes each side's pair |
| 1704 | - .filter(|r| a_set.contains(r)) | 1704 | +// (`ref0` always, `ref1` only for a compound neighbour) so a compound |
| 1705 | - .count(); | 1705 | +// neighbour is not undercounted the way a single scalar per side would. |
| 1706 | - let b = [above, left] | 1706 | +#[allow(clippy::too_many_arguments)] |
| 1707 | - .into_iter() | 1707 | +fn ref_ctx( |
| 1708 | - .flatten() | 1708 | + above0: Option<i8>, |
| 1709 | - .filter(|r| b_set.contains(r)) | 1709 | + above1: Option<i8>, |
| 1710 | - .count(); | 1710 | + left0: Option<i8>, |
| 1711 | + left1: Option<i8>, | ||
| 1712 | + a_set: &[i8], | ||
| 1713 | + b_set: &[i8], | ||
| 1714 | +) -> usize { | ||
| 1715 | + let refs = [above0, above1, left0, left1]; | ||
| 1716 | + let a = refs.into_iter().flatten().filter(|r| a_set.contains(r)).count(); | ||
| 1717 | + let b = refs.into_iter().flatten().filter(|r| b_set.contains(r)).count(); | ||
| 1711 | match a.cmp(&b) { | 1718 | match a.cmp(&b) { |
| 1712 | std::cmp::Ordering::Less => 0, | 1719 | std::cmp::Ordering::Less => 0, |
| 1713 | std::cmp::Ordering::Equal => 1, | 1720 | std::cmp::Ordering::Equal => 1, |
| @@ -1719,22 +1726,46 @@ const FORWARD_REFS: [i8; 4] = [LAST_FRAME, LAST2_FRAME, LAST3_FRAME, GOLDEN_FRAM | |||
| 1719 | const BACKWARD_REFS: [i8; 3] = [BWDREF_FRAME, ALTREF2_FRAME, ALTREF_FRAME]; | 1726 | const BACKWARD_REFS: [i8; 3] = [BWDREF_FRAME, ALTREF2_FRAME, ALTREF_FRAME]; |
| 1720 | 1727 | ||
| 1721 | /// `av1_get_pred_context_single_ref_p1`: forward vs. backward reference. | 1728 | /// `av1_get_pred_context_single_ref_p1`: forward vs. backward reference. |
| 1722 | -pub(crate) fn single_ref_p1_ctx(above: Option<i8>, left: Option<i8>) -> usize { | 1729 | +pub(crate) fn single_ref_p1_ctx( |
| 1723 | - ref_ctx(above, left, &FORWARD_REFS, &BACKWARD_REFS) | 1730 | + above0: Option<i8>, |
| 1731 | + above1: Option<i8>, | ||
| 1732 | + left0: Option<i8>, | ||
| 1733 | + left1: Option<i8>, | ||
| 1734 | +) -> usize { | ||
| 1735 | + ref_ctx(above0, above1, left0, left1, &FORWARD_REFS, &BACKWARD_REFS) | ||
| 1724 | } | 1736 | } |
| 1725 | 1737 | ||
| 1726 | /// `av1_get_pred_context_single_ref_p2` | 1738 | /// `av1_get_pred_context_single_ref_p2` |
| 1727 | /// (`get_pred_context_brfarf2_or_arf`): `BWDREF`/`ALTREF2` vs. `ALTREF`. | 1739 | /// (`get_pred_context_brfarf2_or_arf`): `BWDREF`/`ALTREF2` vs. `ALTREF`. |
| 1728 | -pub(crate) fn single_ref_p2_ctx(above: Option<i8>, left: Option<i8>) -> usize { | 1740 | +pub(crate) fn single_ref_p2_ctx( |
| 1729 | - ref_ctx(above, left, &[BWDREF_FRAME, ALTREF2_FRAME], &[ALTREF_FRAME]) | 1741 | + above0: Option<i8>, |
| 1742 | + above1: Option<i8>, | ||
| 1743 | + left0: Option<i8>, | ||
| 1744 | + left1: Option<i8>, | ||
| 1745 | +) -> usize { | ||
| 1746 | + ref_ctx( | ||
| 1747 | + above0, | ||
| 1748 | + above1, | ||
| 1749 | + left0, | ||
| 1750 | + left1, | ||
| 1751 | + &[BWDREF_FRAME, ALTREF2_FRAME], | ||
| 1752 | + &[ALTREF_FRAME], | ||
| 1753 | + ) | ||
| 1730 | } | 1754 | } |
| 1731 | 1755 | ||
| 1732 | /// `av1_get_pred_context_single_ref_p3` | 1756 | /// `av1_get_pred_context_single_ref_p3` |
| 1733 | /// (`get_pred_context_ll2_or_l3gld`): `LAST`/`LAST2` vs. `LAST3`/`GOLDEN`. | 1757 | /// (`get_pred_context_ll2_or_l3gld`): `LAST`/`LAST2` vs. `LAST3`/`GOLDEN`. |
| 1734 | -pub(crate) fn single_ref_p3_ctx(above: Option<i8>, left: Option<i8>) -> usize { | 1758 | +pub(crate) fn single_ref_p3_ctx( |
| 1759 | + above0: Option<i8>, | ||
| 1760 | + above1: Option<i8>, | ||
| 1761 | + left0: Option<i8>, | ||
| 1762 | + left1: Option<i8>, | ||
| 1763 | +) -> usize { | ||
| 1735 | ref_ctx( | 1764 | ref_ctx( |
| 1736 | - above, | 1765 | + above0, |
| 1737 | - left, | 1766 | + above1, |
| 1767 | + left0, | ||
| 1768 | + left1, | ||
| 1738 | &[LAST_FRAME, LAST2_FRAME], | 1769 | &[LAST_FRAME, LAST2_FRAME], |
| 1739 | &[LAST3_FRAME, GOLDEN_FRAME], | 1770 | &[LAST3_FRAME, GOLDEN_FRAME], |
| 1740 | ) | 1771 | ) |
| @@ -1742,27 +1773,54 @@ pub(crate) fn single_ref_p3_ctx(above: Option<i8>, left: Option<i8>) -> usize { | |||
| 1742 | 1773 | ||
| 1743 | /// `av1_get_pred_context_single_ref_p4` | 1774 | /// `av1_get_pred_context_single_ref_p4` |
| 1744 | /// (`get_pred_context_last_or_last2`): `LAST` vs. `LAST2`. | 1775 | /// (`get_pred_context_last_or_last2`): `LAST` vs. `LAST2`. |
| 1745 | -pub(crate) fn single_ref_p4_ctx(above: Option<i8>, left: Option<i8>) -> usize { | 1776 | +pub(crate) fn single_ref_p4_ctx( |
| 1746 | - ref_ctx(above, left, &[LAST_FRAME], &[LAST2_FRAME]) | 1777 | + above0: Option<i8>, |
| 1778 | + above1: Option<i8>, | ||
| 1779 | + left0: Option<i8>, | ||
| 1780 | + left1: Option<i8>, | ||
| 1781 | +) -> usize { | ||
| 1782 | + ref_ctx(above0, above1, left0, left1, &[LAST_FRAME], &[LAST2_FRAME]) | ||
| 1747 | } | 1783 | } |
| 1748 | 1784 | ||
| 1749 | /// `av1_get_pred_context_single_ref_p5` | 1785 | /// `av1_get_pred_context_single_ref_p5` |
| 1750 | /// (`get_pred_context_last3_or_gld`): `LAST3` vs. `GOLDEN`. | 1786 | /// (`get_pred_context_last3_or_gld`): `LAST3` vs. `GOLDEN`. |
| 1751 | -pub(crate) fn single_ref_p5_ctx(above: Option<i8>, left: Option<i8>) -> usize { | 1787 | +pub(crate) fn single_ref_p5_ctx( |
| 1752 | - ref_ctx(above, left, &[LAST3_FRAME], &[GOLDEN_FRAME]) | 1788 | + above0: Option<i8>, |
| 1789 | + above1: Option<i8>, | ||
| 1790 | + left0: Option<i8>, | ||
| 1791 | + left1: Option<i8>, | ||
| 1792 | +) -> usize { | ||
| 1793 | + ref_ctx(above0, above1, left0, left1, &[LAST3_FRAME], &[GOLDEN_FRAME]) | ||
| 1753 | } | 1794 | } |
| 1754 | 1795 | ||
| 1755 | /// `av1_get_pred_context_single_ref_p6` | 1796 | /// `av1_get_pred_context_single_ref_p6` |
| 1756 | /// (`get_pred_context_brf_or_arf2`): `BWDREF` vs. `ALTREF2`. | 1797 | /// (`get_pred_context_brf_or_arf2`): `BWDREF` vs. `ALTREF2`. |
| 1757 | -pub(crate) fn single_ref_p6_ctx(above: Option<i8>, left: Option<i8>) -> usize { | 1798 | +pub(crate) fn single_ref_p6_ctx( |
| 1758 | - ref_ctx(above, left, &[BWDREF_FRAME], &[ALTREF2_FRAME]) | 1799 | + above0: Option<i8>, |
| 1800 | + above1: Option<i8>, | ||
| 1801 | + left0: Option<i8>, | ||
| 1802 | + left1: Option<i8>, | ||
| 1803 | +) -> usize { | ||
| 1804 | + ref_ctx(above0, above1, left0, left1, &[BWDREF_FRAME], &[ALTREF2_FRAME]) | ||
| 1759 | } | 1805 | } |
| 1760 | 1806 | ||
| 1761 | /// `av1_get_pred_context_uni_comp_ref_p1`: `LAST2` vs. `LAST3`/`GOLDEN`, | 1807 | /// `av1_get_pred_context_uni_comp_ref_p1`: `LAST2` vs. `LAST3`/`GOLDEN`, |
| 1762 | /// conditioned on a unidirectional pair known to be one of the three | 1808 | /// conditioned on a unidirectional pair known to be one of the three |
| 1763 | /// `LAST`-anchored ones (lane-av1comp). | 1809 | /// `LAST`-anchored ones (lane-av1comp). |
| 1764 | -pub(crate) fn uni_comp_ref_p1_ctx(above: Option<i8>, left: Option<i8>) -> usize { | 1810 | +pub(crate) fn uni_comp_ref_p1_ctx( |
| 1765 | - ref_ctx(above, left, &[LAST2_FRAME], &[LAST3_FRAME, GOLDEN_FRAME]) | 1811 | + above0: Option<i8>, |
| 1812 | + above1: Option<i8>, | ||
| 1813 | + left0: Option<i8>, | ||
| 1814 | + left1: Option<i8>, | ||
| 1815 | +) -> usize { | ||
| 1816 | + ref_ctx( | ||
| 1817 | + above0, | ||
| 1818 | + above1, | ||
| 1819 | + left0, | ||
| 1820 | + left1, | ||
| 1821 | + &[LAST2_FRAME], | ||
| 1822 | + &[LAST3_FRAME, GOLDEN_FRAME], | ||
| 1823 | + ) | ||
| 1766 | } | 1824 | } |
| 1767 | 1825 | ||
| 1768 | /// One neighbouring block's reference-frame shape, as | 1826 | /// One neighbouring block's reference-frame shape, as |
| @@ -2369,9 +2427,9 @@ mod tests { | |||
| 2369 | /// convention). | 2427 | /// convention). |
| 2370 | #[test] | 2428 | #[test] |
| 2371 | fn uni_comp_ref_p1_ctx_matches_ref_ctx_shape() { | 2429 | fn uni_comp_ref_p1_ctx_matches_ref_ctx_shape() { |
| 2372 | - assert_eq!(uni_comp_ref_p1_ctx(Some(LAST2_FRAME), None), 2); | 2430 | + assert_eq!(uni_comp_ref_p1_ctx(Some(LAST2_FRAME), None, None, None), 2); |
| 2373 | - assert_eq!(uni_comp_ref_p1_ctx(Some(LAST3_FRAME), None), 0); | 2431 | + assert_eq!(uni_comp_ref_p1_ctx(Some(LAST3_FRAME), None, None, None), 0); |
| 2374 | - assert_eq!(uni_comp_ref_p1_ctx(None, None), 1); | 2432 | + assert_eq!(uni_comp_ref_p1_ctx(None, None, None, None), 1); |
| 2375 | } | 2433 | } |
| 2376 | 2434 | ||
| 2377 | // --- lane-av1comp step 4: compound mvstack (find_mv_stack_compound) --- | 2435 | // --- lane-av1comp step 4: compound mvstack (find_mv_stack_compound) --- |
crates/ec-av1/src/stream.rsmodified+144 -4
| @@ -74,6 +74,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 74 | let mut cdf_slots: [Option<Cdfs>; NUM_REF_FRAMES] = std::array::from_fn(|_| None); | 74 | let mut cdf_slots: [Option<Cdfs>; NUM_REF_FRAMES] = std::array::from_fn(|_| None); |
| 75 | 75 | ||
| 76 | let mut pos = 0usize; | 76 | let mut pos = 0usize; |
| 77 | + let mut decode_idx = 0u32; | ||
| 77 | while pos < data.len() { | 78 | while pos < data.len() { |
| 78 | let obu = parser.parse_obu(&data[pos..])?; | 79 | let obu = parser.parse_obu(&data[pos..])?; |
| 79 | let obu_offset = pos; | 80 | let obu_offset = pos; |
| @@ -114,6 +115,12 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 114 | picture | 115 | picture |
| 115 | }; | 116 | }; |
| 116 | pictures.push(output); | 117 | pictures.push(output); |
| 118 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 119 | + eprintln!( | ||
| 120 | + "PUSH (show_existing_frame slot {slot}) pictures.len()={}", | ||
| 121 | + pictures.len() | ||
| 122 | + ); | ||
| 123 | + } | ||
| 117 | continue; | 124 | continue; |
| 118 | } | 125 | } |
| 119 | let ObuKind::Frame(header, tiles) = obu.kind else { | 126 | let ObuKind::Frame(header, tiles) = obu.kind else { |
| @@ -288,6 +295,19 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 288 | let ref_order_hints: [u32; 7] = | 295 | let ref_order_hints: [u32; 7] = |
| 289 | std::array::from_fn(|i| order_hint_slots[header.ref_frame_idx[i] as usize]); | 296 | std::array::from_fn(|i| order_hint_slots[header.ref_frame_idx[i] as usize]); |
| 290 | 297 | ||
| 298 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 299 | + eprintln!( | ||
| 300 | + "FRAME decode_idx={decode_idx} type={:?} show={} order_hint={} refresh_frame_flags={:#04x} ref_frame_idx={:?} order_hint_slots={:?}", | ||
| 301 | + header.frame_type, | ||
| 302 | + header.show_frame, | ||
| 303 | + header.order_hint, | ||
| 304 | + header.refresh_frame_flags, | ||
| 305 | + header.ref_frame_idx, | ||
| 306 | + order_hint_slots, | ||
| 307 | + ); | ||
| 308 | + } | ||
| 309 | + decode_idx += 1; | ||
| 310 | + | ||
| 291 | let (picture, end_cdfs, motion_field) = if header.frame_type == FrameType::Key { | 311 | let (picture, end_cdfs, motion_field) = if header.frame_type == FrameType::Key { |
| 292 | let (picture, end_cdfs) = decode_key_frame_tile_with_cdfs( | 312 | let (picture, end_cdfs) = decode_key_frame_tile_with_cdfs( |
| 293 | tile_bytes, | 313 | tile_bytes, |
| @@ -434,6 +454,18 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | |||
| 434 | picture | 454 | picture |
| 435 | }; | 455 | }; |
| 436 | pictures.push(output); | 456 | pictures.push(output); |
| 457 | + if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 458 | + eprintln!( | ||
| 459 | + "PUSH (shown-direct) pictures.len()={} <- decode.rs r17 fidx {}", | ||
| 460 | + pictures.len(), | ||
| 461 | + crate::decode::r17_dump_frame_idx() | ||
| 462 | + ); | ||
| 463 | + } | ||
| 464 | + } else if std::env::var("EC_AV1_COMPOUND_DEBUG").is_ok() { | ||
| 465 | + eprintln!( | ||
| 466 | + "HIDDEN frame decoded, not pushed <- decode.rs r17 fidx {}", | ||
| 467 | + crate::decode::r17_dump_frame_idx() | ||
| 468 | + ); | ||
| 437 | } | 469 | } |
| 438 | } | 470 | } |
| 439 | Ok(pictures) | 471 | Ok(pictures) |
| @@ -725,9 +757,9 @@ mod tests { | |||
| 725 | // constructing the (module-private) `Neighbours` itself. | 757 | // constructing the (module-private) `Neighbours` itself. |
| 726 | const PARTITION_NONE: usize = 0; | 758 | const PARTITION_NONE: usize = 0; |
| 727 | let ii_ctx = intra_inter_ctx(false, false, false, false); | 759 | let ii_ctx = intra_inter_ctx(false, false, false, false); |
| 728 | - let sr_p1_ctx = single_ref_p1_ctx(None, None); | 760 | + let sr_p1_ctx = single_ref_p1_ctx(None, None, None, None); |
| 729 | - let sr_p3_ctx = single_ref_p3_ctx(None, None); | 761 | + let sr_p3_ctx = single_ref_p3_ctx(None, None, None, None); |
| 730 | - let sr_p5_ctx = single_ref_p5_ctx(None, None); | 762 | + let sr_p5_ctx = single_ref_p5_ctx(None, None, None, None); |
| 731 | 763 | ||
| 732 | for run in 0..4 { | 764 | for run in 0..4 { |
| 733 | let picture = test_card(width, height); | 765 | let picture = test_card(width, height); |
| @@ -2663,7 +2695,12 @@ mod tests { | |||
| 2663 | // capability gap tracked on its own (not a | 2695 | // capability gap tracked on its own (not a |
| 2664 | // COMPOUND_REFERENCE defect); accept it here too | 2696 | // COMPOUND_REFERENCE defect); accept it here too |
| 2665 | // rather than fail a compound-specific gate on a | 2697 | // rather than fail a compound-specific gate on a |
| 2666 | - // partition-search coincidence. | 2698 | + // partition-search coincidence. lane-av1blend r7: |
| 2699 | + // re-swept the wide gate with the plain-average | ||
| 2700 | + // blend unmasked (r6/r7's ref_ctx fix alone) and it | ||
| 2701 | + // still mismatches on real streams beyond that one | ||
| 2702 | + // bug -- re-masked comp_group_idx == 0 too, so this | ||
| 2703 | + // stays a legal named refusal. | ||
| 2667 | assert!( | 2704 | assert!( |
| 2668 | msg.contains("COMPOUND_REFERENCE") || msg.contains("a partition"), | 2705 | msg.contains("COMPOUND_REFERENCE") || msg.contains("a partition"), |
| 2669 | "{NAME}: comp_mode fired (seed {seed}) but the refusal \ | 2706 | "{NAME}: comp_mode fired (seed {seed}) but the refusal \ |
| @@ -3289,6 +3326,109 @@ mod tests { | |||
| 3289 | } | 3326 | } |
| 3290 | } | 3327 | } |
| 3291 | 3328 | ||
| 3329 | + /// lane-av1blend r4 scratch: decodes the pinned `av1blend-r1-mismatch.obu` | ||
| 3330 | + /// (seed 45) with `EC_AV1_COMPIDX_DUMP` set, to compare the pre-tile-decode | ||
| 3331 | + /// `compound_idx` CDF state of every frame against an instrumented | ||
| 3332 | + /// aomdec's own `COMPIDX_PRE` dump. Errors out at decode-order frame 3 | ||
| 3333 | + /// (the still-masked compound path) -- that is expected, the dump lines | ||
| 3334 | + /// before the error are what this test is for. Remove with the rest of | ||
| 3335 | + /// the r1-r4 scaffolding. | ||
| 3336 | + #[test] | ||
| 3337 | + #[ignore] | ||
| 3338 | + fn scratch_dump_compound_idx_cdf_state() { | ||
| 3339 | + let path = concat!( | ||
| 3340 | + env!("CARGO_MANIFEST_DIR"), | ||
| 3341 | + "/../../fixtures/av1blend-r1-mismatch.obu" | ||
| 3342 | + ); | ||
| 3343 | + let stream = std::fs::read(path).expect("reading pinned stream"); | ||
| 3344 | + let _ = decode_stream(&stream); | ||
| 3345 | + } | ||
| 3346 | + | ||
| 3347 | + /// lane-av1blend r2 scratch: sweep every seed of the compound_references | ||
| 3348 | + /// recipe (with the plain-average blend UNMASKED locally) looking for a | ||
| 3349 | + /// pixel mismatch, dumping the first one found to `EC_AV1_GATE_DUMP`. | ||
| 3350 | + /// Remove with the rest of the r1/r2 scaffolding. | ||
| 3351 | + #[test] | ||
| 3352 | + #[ignore] | ||
| 3353 | + fn scratch_sweep_compound_mismatch() { | ||
| 3354 | + if !have_ffmpeg() || !have_aomenc() { | ||
| 3355 | + eprintln!("SKIP: missing ffmpeg/aomenc"); | ||
| 3356 | + return; | ||
| 3357 | + } | ||
| 3358 | + let (width, height, frame_count) = (64usize, 64usize, 24usize); | ||
| 3359 | + for seed in 42..82u32 { | ||
| 3360 | + let duration = frame_count as f64 / 25.0; | ||
| 3361 | + let source = | ||
| 3362 | + format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25"); | ||
| 3363 | + let y4m = Command::new("ffmpeg") | ||
| 3364 | + .args([ | ||
| 3365 | + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", | ||
| 3366 | + "yuv4mpegpipe", "-", | ||
| 3367 | + ]) | ||
| 3368 | + .stdin(Stdio::null()) | ||
| 3369 | + .stdout(Stdio::piped()) | ||
| 3370 | + .stderr(Stdio::piped()) | ||
| 3371 | + .output() | ||
| 3372 | + .expect("ffmpeg failed to run"); | ||
| 3373 | + assert!(y4m.status.success()); | ||
| 3374 | + let args: Vec<&str> = vec![ | ||
| 3375 | + "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=45", "--cpu-used=0", | ||
| 3376 | + "--kf-max-dist=1000", "--threads=1", "--row-mt=0", "--auto-alt-ref=1", | ||
| 3377 | + "--lag-in-frames=16", "--enable-fwd-kf=0", "--enable-order-hint=1", | ||
| 3378 | + "--enable-warped-motion=0", "--enable-obmc=0", "--enable-masked-comp=0", | ||
| 3379 | + "--enable-interintra-comp=0", "--enable-onesided-comp=0", | ||
| 3380 | + "--enable-interintra-wedge=0", "--enable-smooth-interintra=0", | ||
| 3381 | + "--enable-rect-partitions=0", "--enable-ab-partitions=0", | ||
| 3382 | + "--enable-1to4-partitions=0", "--enable-filter-intra=0", | ||
| 3383 | + "--enable-smooth-intra=0", "--enable-paeth-intra=0", | ||
| 3384 | + "--enable-directional-intra=0", "--enable-angle-delta=0", | ||
| 3385 | + "--enable-tx-size-search=0", "--enable-cdef=0", "--enable-restoration=0", | ||
| 3386 | + "--max-partition-size=32", "--min-partition-size=32", "--enable-palette=0", | ||
| 3387 | + "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", | ||
| 3388 | + "--obu", "-o", "-", "-", | ||
| 3389 | + ]; | ||
| 3390 | + let mut child = Command::new(aomenc_path()) | ||
| 3391 | + .args(&args) | ||
| 3392 | + .stdin(Stdio::piped()) | ||
| 3393 | + .stdout(Stdio::piped()) | ||
| 3394 | + .stderr(Stdio::piped()) | ||
| 3395 | + .spawn() | ||
| 3396 | + .expect("aomenc failed to start"); | ||
| 3397 | + child | ||
| 3398 | + .stdin | ||
| 3399 | + .take() | ||
| 3400 | + .expect("aomenc stdin") | ||
| 3401 | + .write_all(&y4m.stdout) | ||
| 3402 | + .expect("writing y4m to aomenc"); | ||
| 3403 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 3404 | + assert!(out.status.success()); | ||
| 3405 | + let stream = out.stdout; | ||
| 3406 | + let frames = match decode_stream(&stream) { | ||
| 3407 | + Err(_) => continue, | ||
| 3408 | + Ok(frames) => frames, | ||
| 3409 | + }; | ||
| 3410 | + if frames.len() != frame_count { | ||
| 3411 | + continue; | ||
| 3412 | + } | ||
| 3413 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | ||
| 3414 | + let mismatched = frames | ||
| 3415 | + .iter() | ||
| 3416 | + .zip(&ffmpeg_frames) | ||
| 3417 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | ||
| 3418 | + if mismatched { | ||
| 3419 | + eprintln!("MISMATCH seed {seed}"); | ||
| 3420 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | ||
| 3421 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | ||
| 3422 | + eprintln!("wrote {path}"); | ||
| 3423 | + } | ||
| 3424 | + return; | ||
| 3425 | + } else { | ||
| 3426 | + eprintln!("seed {seed}: bit-exact"); | ||
| 3427 | + } | ||
| 3428 | + } | ||
| 3429 | + eprintln!("no mismatch found in sweep"); | ||
| 3430 | + } | ||
| 3431 | + | ||
| 3292 | /// Final round of the TX4/tx-class lane's own gate: `--min-partition-size=8 | 3432 | /// Final round of the TX4/tx-class lane's own gate: `--min-partition-size=8 |
| 3293 | /// --max-partition-size=8` pins every leaf to exactly 8x8 (spec | 3433 | /// --max-partition-size=8` pins every leaf to exactly 8x8 (spec |
| 3294 | /// 5.11.4's own boundary carve-out aside, which a multiple-of-8 frame | 3434 | /// 5.11.4's own boundary carve-out aside, which a multiple-of-8 frame |