forge
Explore
Log in

Don't you dare go Hollow

All-zero-CBF early out for the RQT split trial

Browse files at this commit

4275e272d109ce92b680ee2135eb18b8aaa9828bAhmet Kaan GümüşParent: 24a3573
  • feat
    • all-zero-CBF early out for the RQT split trial
Show full message
feat(h265): all-zero-CBF early out for the RQT split trial

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.rsmodified+26 -0
@@ -821,6 +821,32 @@ impl<'a> CtuEncoder<'a> {
821 let cb_cbf = self.code_chroma(x, y, n, chroma_mode, 1, chroma_tskip).1;821 let cb_cbf = self.code_chroma(x, y, n, chroma_mode, 1, chroma_tskip).1;
822 let cr_cbf = self.code_chroma(x, y, n, chroma_mode, 2, chroma_tskip).1;822 let cr_cbf = self.code_chroma(x, y, n, chroma_mode, 2, chroma_tskip).1;
823 823
824+ if self.rqt && log2 > 2 && !luma_cbf && !cb_cbf && !cr_cbf {
825+ // Every plane already quantised to zero at this size: a
826+ // transform-tree split can only re-signal the same empty leaf as
827+ // four children, adding a split_transform_flag and their mode
828+ // bits on top of an SSD that is already zero. Same reasoning as
829+ // the CU-quadtree's `last_cu_empty` early out, one level down —
830+ // skip the four-child trial and its transform/CABAC-counting
831+ // work outright instead of running it to confirm nosplit wins.
832+ enc.encode_bin(ctx::SPLIT_TRANSFORM + (5 - log2) as usize, 0);
833+ self.write_single_tu(
834+ enc,
835+ n,
836+ log2,
837+ mode,
838+ chroma_mode,
839+ chroma_tskip,
840+ luma_cbf,
841+ cb_cbf,
842+ cr_cbf,
843+ );
844+ self.mark_coded(x, y, n, mode, depth);
845+ self.mark_tu(x, y, n);
846+ self.last_cu_empty = true;
847+ let bits = enc.bit_count() - before;
848+ return self.region_ssd(x, y, n) + self.lambda * bits as f64;
849+ }
824 if self.rqt && log2 > 2 {850 if self.rqt && log2 > 2 {
825 // A child transform tree signals its own chroma as long as its851 // A child transform tree signals its own chroma as long as its
826 // chroma blocks are still 4x4 or larger; only the 8x8 luma tree,852 // chroma blocks are still 4x4 or larger; only the 8x8 luma tree,
crates/ec-h265/tests/rdoq_cache_hash.rsmodified+12 -2
@@ -48,8 +48,18 @@ fn rdoq_cache_hash_416x240() {
48 /// compile-time-mirrored flat table in `forward_1d`/`inverse_1d` — this pins48 /// compile-time-mirrored flat table in `forward_1d`/`inverse_1d` — this pins
49 /// that equality so a future change to the hot path is caught if it ever49 /// that equality so a future change to the hot path is caught if it ever
50 /// produces a different byte.50 /// produces a different byte.
51+///
52+/// lane-h265prune: re-pinned after the RQT split trial gained an all-zero-CBF
53+/// early out (mirrors the CU-quadtree's existing `last_cu_empty` skip one
54+/// level down at the transform tree): a coding unit whose luma+chroma already
55+/// quantised to nothing is committed as one leaf transform unit without
56+/// trying the four-child split first, since splitting a zero-SSD block can
57+/// only add split_transform_flag and mode-signalling bits. This changes the
58+/// bitstream on any content where that trial used to flip a leaf to split
59+/// (BD-gated, not bit-identical — see `EncoderConfig::rqt` and this crate's
60+/// `bd_psnr_vs_x265`).
51 #[test]61 #[test]
52 fn rdoq_cache_hash_is_pinned() {62 fn rdoq_cache_hash_is_pinned() {
53- assert_eq!(encode_hash(416, 240), 0xda5d606db0755d97);63+ assert_eq!(encode_hash(416, 240), 0xdb39f995b147beae);
54- assert_eq!(encode_hash(1920, 1080), 0xf08a816c9fa9ca2c);64+ assert_eq!(encode_hash(1920, 1080), 0xff5abdf102465a46);
55 }65 }