diff --git a/crates/ec-h265/src/ctu.rs b/crates/ec-h265/src/ctu.rs index 746a8218..1b5bc8ee 100644 --- a/crates/ec-h265/src/ctu.rs +++ b/crates/ec-h265/src/ctu.rs @@ -821,6 +821,32 @@ impl<'a> CtuEncoder<'a> { let cb_cbf = self.code_chroma(x, y, n, chroma_mode, 1, chroma_tskip).1; let cr_cbf = self.code_chroma(x, y, n, chroma_mode, 2, chroma_tskip).1; + if self.rqt && log2 > 2 && !luma_cbf && !cb_cbf && !cr_cbf { + // Every plane already quantised to zero at this size: a + // transform-tree split can only re-signal the same empty leaf as + // four children, adding a split_transform_flag and their mode + // bits on top of an SSD that is already zero. Same reasoning as + // the CU-quadtree's `last_cu_empty` early out, one level down — + // skip the four-child trial and its transform/CABAC-counting + // work outright instead of running it to confirm nosplit wins. + enc.encode_bin(ctx::SPLIT_TRANSFORM + (5 - log2) as usize, 0); + self.write_single_tu( + enc, + n, + log2, + mode, + chroma_mode, + chroma_tskip, + luma_cbf, + cb_cbf, + cr_cbf, + ); + self.mark_coded(x, y, n, mode, depth); + self.mark_tu(x, y, n); + self.last_cu_empty = true; + let bits = enc.bit_count() - before; + return self.region_ssd(x, y, n) + self.lambda * bits as f64; + } if self.rqt && log2 > 2 { // A child transform tree signals its own chroma as long as its // chroma blocks are still 4x4 or larger; only the 8x8 luma tree, diff --git a/crates/ec-h265/tests/rdoq_cache_hash.rs b/crates/ec-h265/tests/rdoq_cache_hash.rs index 3519942c..8eaca77e 100644 --- a/crates/ec-h265/tests/rdoq_cache_hash.rs +++ b/crates/ec-h265/tests/rdoq_cache_hash.rs @@ -48,8 +48,18 @@ fn rdoq_cache_hash_416x240() { /// compile-time-mirrored flat table in `forward_1d`/`inverse_1d` — this pins /// that equality so a future change to the hot path is caught if it ever /// produces a different byte. +/// +/// lane-h265prune: re-pinned after the RQT split trial gained an all-zero-CBF +/// early out (mirrors the CU-quadtree's existing `last_cu_empty` skip one +/// level down at the transform tree): a coding unit whose luma+chroma already +/// quantised to nothing is committed as one leaf transform unit without +/// trying the four-child split first, since splitting a zero-SSD block can +/// only add split_transform_flag and mode-signalling bits. This changes the +/// bitstream on any content where that trial used to flip a leaf to split +/// (BD-gated, not bit-identical — see `EncoderConfig::rqt` and this crate's +/// `bd_psnr_vs_x265`). #[test] fn rdoq_cache_hash_is_pinned() { - assert_eq!(encode_hash(416, 240), 0xda5d606db0755d97); - assert_eq!(encode_hash(1920, 1080), 0xf08a816c9fa9ca2c); + assert_eq!(encode_hash(416, 240), 0xdb39f995b147beae); + assert_eq!(encode_hash(1920, 1080), 0xff5abdf102465a46); }