diff --git a/crates/ec-h265/src/decode.rs b/crates/ec-h265/src/decode.rs index 3e646d58..8b441f4a 100644 --- a/crates/ec-h265/src/decode.rs +++ b/crates/ec-h265/src/decode.rs @@ -512,10 +512,25 @@ impl CtuDecoder { mode }; modes[part] = mode; - // Mode only, so the next partition's MPM sees it; pixels follow - // once the residual syntax below is read. + // Mode and availability, so the next partition's `mpm_at` sees + // this one as a real coded neighbour — the encoder's own + // mode-decide loop calls `mark_coded` (which flips availability) + // immediately per partition for exactly this reason (8.4.2: an + // NxN CU's later partitions see its earlier ones as available). + // Marking modes here without also marking `decoded` left the + // second/third/fourth partition's left/above neighbour reading + // as unavailable (substituted DC) on the decoder side while the + // encoder's MPM saw the real mode, decoding the wrong MPM triple + // and desyncing every bin after it — this is what an NxN CU + // forced into existence by a boundary split (rather than chosen + // by `intra_nxn`'s RD search) actually exercises differently: + // the RD search rarely keeps NxN once a real neighbour is + // available on all four sides, so the bug went unseen until a + // picture edge forced it. let stride = self.width / 4; - self.modes[(py / 4) * stride + px / 4] = mode; + let idx = (py / 4) * stride + px / 4; + self.modes[idx] = mode; + self.decoded[idx] = true; } let chroma_mode = self.decode_chroma_mode(dec, modes[0]); diff --git a/crates/ec-h265/tests/decode.rs b/crates/ec-h265/tests/decode.rs index 7c2b9c6e..4afb9f58 100644 --- a/crates/ec-h265/tests/decode.rs +++ b/crates/ec-h265/tests/decode.rs @@ -56,32 +56,16 @@ fn decode_matches_the_encoders_own_reconstruction_over_several_ctbs() { } #[test] -#[ignore = "r3 checkpoint: fails with 'end_of_slice_segment_flag 0 at CTB (2,1), \ -expected 1' — narrowed (not yet root-caused) to the interaction of the NxN \ -intra partition (PART_NxN, an 8x8 CU split into four 4x4 PUs) with a \ -boundary-forced coding-unit: forcing every 8x8 leaf to code as 2Nx2N \ -(`intra_nxn: false`) round-trips clean; forcing every 8x8 leaf to NxN \ -(EC_H265_FORCE_NXN local hack, removed) round-trips clean on an exact-CTB-\ -multiple picture (64x64, ctb 64) but reproduces this same failure on a \ -picture whose last CTU is boundary-forced-split down to 8x8 (40x50, ctb 64, \ -no WPP — cols=1 rules out the WPP substream code entirely). So: NxN syntax \ -itself is right (it round-trips away from a picture edge); the bug is in \ -what an 8x8 CU sees or does differently when the quadtree reached it via \ -the boundary force-split path (7.3.8.4, no split_cu_flag bin) rather than \ -via a decoded split_cu_flag==0 — likely `mpm_at`/`available`'s neighbour \ -lookup, since that is the only per-CU state NxN reads that a forced-split \ -ancestor could leave in a different shape than a normal split would. Next \ -round: trace `available()`/`mode_at()` at the forced-split leaf specifically \ -(cheap, no RD-search noise, since EC_H265_FORCE_NXN made this deterministic \ -without touching the passing 2Nx2N path)."] fn decode_matches_the_encoders_own_reconstruction_at_an_odd_padded_size() { roundtrip_at(70, 50); } #[test] -#[ignore = "r3 checkpoint: same root cause as \ -decode_matches_the_encoders_own_reconstruction_at_an_odd_padded_size — NxN \ -at a boundary-forced 8x8 leaf; see that test's ignore reason."] fn decode_matches_the_encoders_own_reconstruction_at_another_odd_size() { roundtrip_at(150, 94); } + +#[test] +fn decode_matches_the_encoders_own_reconstruction_at_an_extreme_odd_size() { + roundtrip_at(41, 33); +}