From 4275e272d109ce92b680ee2135eb18b8aaa9828b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 28 Aug 2026 00:00:45 +0300 Subject: [PATCH] feat(h265): all-zero-CBF early out for the RQT split trial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mirror the CU-quadtree's existing last_cu_empty skip one level down at the transform tree: when a coding unit's luma and both chroma planes already quantised to nothing, commit it as one leaf transform unit without running the four-child split trial (which can only add split_transform_flag and mode-signalling bits on top of an SSD floor that split cannot beat). Measured neutral-to-positive, not a double-digit speedup: -0.02% instructions on a synthetic 1080p gradient/texture profile clip (the CU-level early out already catches most flat regions before this code path is reached), BD-PSNR vs x265 +0.003 dB luma / +0.004 dB YUV on a 1080p film clip and flat / +0.025 dB YUV on a 2560x1440 screen capture (both real library files, no regression on either). Kept because it's exactly the lever the charter named and is bit-safe-by-construction, not because it clears the lane's own >10%-instructions bar — flagged honestly in the report. Re-pins rdoq_cache_hash_is_pinned: this intentionally changes output on any content where the RQT trial used to flip a leaf to split. --- crates/ec-h265/src/ctu.rs | 26 +++++++++++++++++++++++++ crates/ec-h265/tests/rdoq_cache_hash.rs | 14 +++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) 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); }