All-zero-CBF early out for the RQT split trial
Browse files at this commit4275e272d109ce92b680ee2135eb18b8aaa9828bParent: 24a3573- feat
- all-zero-CBF early out for the RQT split trial
2 changed files +38 -2
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 its | 851 | // 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 pins | 48 | /// 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 ever | 49 | /// 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 | } |