Default 4x4 transform skip to the per-block RD decision
Browse files at this commitc7b678361602f3440784248dc0429fa0837df55aParent: a9d41bf- feat
- default 4x4 transform skip to the per-block RD decision
3 changed files +34 -4
- crates/ec-h265/src/ctu.rs +6 -1
- crates/ec-h265/src/encoder.rs +21 -1
- crates/ec-h265/tests/rdoq_cache_hash.rs +7 -2
crates/ec-h265/src/ctu.rsmodified+6 -1
| @@ -1553,7 +1553,12 @@ impl<'a> CtuEncoder<'a> { | |||
| 1553 | for (i, &sample) in source[..n * n].iter().enumerate() { | 1553 | for (i, &sample) in source[..n * n].iter().enumerate() { |
| 1554 | self.scratch.residual[i] = i32::from(sample) - i32::from(self.scratch.pred[i]); | 1554 | self.scratch.residual[i] = i32::from(sample) - i32::from(self.scratch.pred[i]); |
| 1555 | } | 1555 | } |
| 1556 | - let skip = n == 4 && if self.ts_rd { self.ts_luma } else { self.transform_skip }; | 1556 | + let skip = n == 4 |
| 1557 | + && if self.ts_rd { | ||
| 1558 | + self.ts_luma | ||
| 1559 | + } else { | ||
| 1560 | + self.transform_skip | ||
| 1561 | + }; | ||
| 1557 | let dst = uses_dst(n, true); | 1562 | let dst = uses_dst(n, true); |
| 1558 | if skip { | 1563 | if skip { |
| 1559 | forward_transform_skip(&self.scratch.residual, &mut self.scratch.coeffs, n); | 1564 | forward_transform_skip(&self.scratch.residual, &mut self.scratch.coeffs, n); |
crates/ec-h265/src/encoder.rsmodified+21 -1
| @@ -183,6 +183,26 @@ pub struct EncoderConfig { | |||
| 183 | /// loss. `false` restores exact per-trial CABAC replay for A/B. | 183 | /// loss. `false` restores exact per-trial CABAC replay for A/B. |
| 184 | pub rdoq_estimate: bool, | 184 | pub rdoq_estimate: bool, |
| 185 | /// Whether 4x4 TUs may skip the integer transform. | 185 | /// Whether 4x4 TUs may skip the integer transform. |
| 186 | + /// | ||
| 187 | + /// `Rd` by default: the tool is the screen-content lever, and it wants a | ||
| 188 | + /// per-block decision, not a switch. BD-PSNR luma / all-plane against x265 | ||
| 189 | + /// at matched features over the four-QP ladder (`EC_H265_TSKIP=0|always|rd` | ||
| 190 | + /// in `bd_psnr_vs_x265`, real clips, 24 pictures each): | ||
| 191 | + /// | ||
| 192 | + /// | clip | `Off` | `AlwaysFor4x4` | `Rd` | | ||
| 193 | + /// |------|-------|----------------|------| | ||
| 194 | + /// | 1440p screen capture A | -0.381 / -0.438 | +1.485 / +1.373 | +1.034 / +0.918 | | ||
| 195 | + /// | 1440p screen capture B | +0.716 / +0.561 | +0.783 / +0.222 | +1.133 / +0.781 | | ||
| 196 | + /// | 1440p screen capture C | +0.213 / +0.099 | | +0.124 / +0.008 | | ||
| 197 | + /// | 1080p film | +0.584 / +0.468 | | +0.580 / +0.460 | | ||
| 198 | + /// | ||
| 199 | + /// Unconditional skip is worth +1.8 dB all-plane on A and -0.34 dB on B, so | ||
| 200 | + /// neither setting of a switch is right; the per-block trial takes A's win | ||
| 201 | + /// without B's loss and leaves film where it was (-0.008 dB, the estimate | ||
| 202 | + /// proxy's noise). The cost is the second quantise-and-reconstruct pass on | ||
| 203 | + /// every committed 4x4 luma block: the whole four-QP ladder went 111s -> | ||
| 204 | + /// 290s on screen capture A and 427s -> 494s on film. Set `Off` to buy that | ||
| 205 | + /// time back. | ||
| 186 | pub transform_skip: TransformSkip, | 206 | pub transform_skip: TransformSkip, |
| 187 | /// Whether the transform tree may split once (rate-quantisation transform): | 207 | /// Whether the transform tree may split once (rate-quantisation transform): |
| 188 | /// the luma TU of a 2Nx2N coding unit may be coded as four half-size | 208 | /// the luma TU of a 2Nx2N coding unit may be coded as four half-size |
| @@ -243,7 +263,7 @@ impl EncoderConfig { | |||
| 243 | sign_hiding: false, | 263 | sign_hiding: false, |
| 244 | rdoq: true, | 264 | rdoq: true, |
| 245 | rdoq_estimate: true, | 265 | rdoq_estimate: true, |
| 246 | - transform_skip: TransformSkip::Off, | 266 | + transform_skip: TransformSkip::Rd, |
| 247 | rqt: true, | 267 | rqt: true, |
| 248 | cu64: true, | 268 | cu64: true, |
| 249 | video_signal_type: None, | 269 | video_signal_type: None, |
crates/ec-h265/tests/rdoq_cache_hash.rsmodified+7 -2
| @@ -64,8 +64,13 @@ fn rdoq_cache_hash_416x240() { | |||
| 64 | /// (`EncoderConfig::rdoq_estimate`, now on by default) — deliberately | 64 | /// (`EncoderConfig::rdoq_estimate`, now on by default) — deliberately |
| 65 | /// bit-different, not exact-mode-preserving; see that field's doc comment | 65 | /// bit-different, not exact-mode-preserving; see that field's doc comment |
| 66 | /// for the BD/speed numbers that justified flipping the default. | 66 | /// for the BD/speed numbers that justified flipping the default. |
| 67 | +/// | ||
| 68 | +/// lane-h265screen: re-pinned after every committed 4x4 luma block gained a | ||
| 69 | +/// rate-distortion decision on `transform_skip_flag` (`TransformSkip::Rd`, now | ||
| 70 | +/// the default) — deliberately bit-different; see that field's doc comment for | ||
| 71 | +/// the BD numbers per clip. | ||
| 67 | #[test] | 72 | #[test] |
| 68 | fn rdoq_cache_hash_is_pinned() { | 73 | fn rdoq_cache_hash_is_pinned() { |
| 69 | - assert_eq!(encode_hash(416, 240), 0x3dc2876c9104b7b3); | 74 | + assert_eq!(encode_hash(416, 240), 0x39d93f8b600b072e); |
| 70 | - assert_eq!(encode_hash(1920, 1080), 0x03188155f21c2174); | 75 | + assert_eq!(encode_hash(1920, 1080), 0x8c5e05c6f65515c8); |
| 71 | } | 76 | } |