forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits

rdoq_cache_hash.rs71 lines, 2.9 KiBHistoryRawDownload
1//! lane-h265rdoq r3: the sub-block frozen-prefix cursor must not change a
2//! single output byte. Hashes two natural-content encodes (1920x1080 and
3//! 416x240) with FNV-1a; the number itself means nothing, only that it is the
4//! same before and after this round's change to `rdoq()` (checked by hand:
5//! stash `residual.rs`, rerun, compare).
6
7mod common;
8
9use common::natural_frame;
10use ec_h265::encoder::{Encoder, EncoderConfig, RateControl};
11
12fn fnv1a(bytes: &[u8]) -> u64 {
13 let mut hash = 0xcbf29ce484222325u64;
14 for &b in bytes {
15 hash ^= b as u64;
16 hash = hash.wrapping_mul(0x100000001b3);
17 }
18 hash
19}
20
21fn encode_hash(width: u32, height: u32) -> u64 {
22 let mut cfg = EncoderConfig::new(width, height);
23 cfg.rate_control = RateControl::ConstantQp(24);
24 cfg.threads = 1;
25 let encoder = Encoder::new(cfg).expect("encoder");
26 let mut all = Vec::new();
27 for i in 0..3u32 {
28 let frame = natural_frame(width, height, i * 5);
29 all.extend(encoder.encode_idr(&frame).expect("encode").au);
30 }
31 fnv1a(&all)
32}
33
34#[test]
35fn rdoq_cache_hash_1920x1080() {
36 println!("hash 1920x1080 = {:016x}", encode_hash(1920, 1080));
37}
38
39#[test]
40fn rdoq_cache_hash_416x240() {
41 println!("hash 416x240 = {:016x}", encode_hash(416, 240));
42}
43
44/// lane-h265simd: pinned bit-identity gate for the transform's hot path. The
45/// value is the same hash the two tests above print, verified by hand
46/// (`git stash` the transform.rs change, rerun, compare) to be identical
47/// before and after replacing `m32()`'s per-element branch with a
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
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`).
61///
62/// lane-h265rdoq: re-pinned after RDOQ's trial costing switched from exact
63/// per-trial CABAC replay to an estimated per-context fracbits table
64/// (`EncoderConfig::rdoq_estimate`, now on by default) — deliberately
65/// bit-different, not exact-mode-preserving; see that field's doc comment
66/// for the BD/speed numbers that justified flipping the default.
67#[test]
68fn rdoq_cache_hash_is_pinned() {
69 assert_eq!(encode_hash(416, 240), 0x3dc2876c9104b7b3);
70 assert_eq!(encode_hash(1920, 1080), 0x03188155f21c2174);
71}