The DPB shares one Arc per picture instead of copying it per slot
Browse files at this commit68c67bf9b2c11830fc5a391a5d89d4e2e7b16ae2Parent: b83300d- perf
- the DPB shares one Arc per picture instead of copying it per slot
1 changed file +14 -7
- crates/ec-av1/src/stream.rs +14 -7
crates/ec-av1/src/stream.rsmodified+14 -7
| @@ -281,7 +281,11 @@ pub fn decode_stream_with( | ||
| 281 | 281 | // luma-only (chroma coincidentally shares this fixture's flat regions) |
| 282 | 282 | // and small-magnitude (the two pictures mostly agree), which is exactly |
| 283 | 283 | // what made it look like a rounding bug rather than a wrong reference. |
| 284 | - let mut ref_slots: [Option<Picture>; NUM_REF_FRAMES] = std::array::from_fn(|_| None); | |
| 284 | + // lane-perf9: the DPB holds each picture behind an `Arc`, so a frame whose | |
| 285 | + // `refresh_frame_flags` names several slots (a key frame names all eight) | |
| 286 | + // stores eight pointers instead of eight ~25 MB 4K picture copies. | |
| 287 | + let mut ref_slots: [Option<std::sync::Arc<Picture>>; NUM_REF_FRAMES] = | |
| 288 | + std::array::from_fn(|_| None); | |
| 285 | 289 | // lane-av1tmvp: each of the 8 reference slots' own saved temporal motion |
| 286 | 290 | // field (spec 7.9's per-frame `MotionFieldMvs` storage, libaom |
| 287 | 291 | // `cur_frame->mvs`) plus the `OrderHint` the picture in that slot was |
| @@ -371,7 +375,7 @@ pub fn decode_stream_with( | ||
| 371 | 375 | bit_depth as u32, |
| 372 | 376 | ) |
| 373 | 377 | } else { |
| 374 | - picture | |
| 378 | + (*picture).clone() | |
| 375 | 379 | }; |
| 376 | 380 | sink(&output, pictures_decoded, true)?; |
| 377 | 381 | pictures_shown += 1; |
| @@ -851,7 +855,7 @@ pub fn decode_stream_with( | ||
| 851 | 855 | } else { |
| 852 | 856 | ref_slots |
| 853 | 857 | .get(header.ref_frame_idx[ref_frame - 1] as usize) |
| 854 | - .and_then(Option::as_ref) | |
| 858 | + .and_then(|slot| slot.as_deref()) | |
| 855 | 859 | } |
| 856 | 860 | }); |
| 857 | 861 | // spec 7.9's own driver, `av1_setup_motion_field`: only run when |
| @@ -923,6 +927,9 @@ pub fn decode_stream_with( | ||
| 923 | 927 | )?; |
| 924 | 928 | (picture, end_cdfs, motion_field) |
| 925 | 929 | }; |
| 930 | + // lane-perf9: one allocation per decoded frame, then every reference | |
| 931 | + // slot this frame refreshes (and the sink) shares it. | |
| 932 | + let picture = std::sync::Arc::new(picture); | |
| 926 | 933 | // lane-lr r4: the Wiener/self-guided pixel filters are wired |
| 927 | 934 | // (`decode.rs::apply_loop_restoration`) -- no more refusal here, |
| 928 | 935 | // `uses_lr` frames now decode all the way to pixels. |
| @@ -1029,16 +1036,16 @@ pub fn decode_stream_with( | ||
| 1029 | 1036 | let mc_identity = parser |
| 1030 | 1037 | .sequence_header() |
| 1031 | 1038 | .is_some_and(|seq| seq.color_config.matrix_coefficients == 0); |
| 1032 | - crate::film_grain::apply_grain( | |
| 1039 | + Some(crate::film_grain::apply_grain( | |
| 1033 | 1040 | &picture, |
| 1034 | 1041 | &header.film_grain, |
| 1035 | 1042 | mc_identity, |
| 1036 | 1043 | bit_depth as u32, |
| 1037 | - ) | |
| 1044 | + )) | |
| 1038 | 1045 | } else { |
| 1039 | - picture | |
| 1046 | + None | |
| 1040 | 1047 | }; |
| 1041 | - sink(&output, pictures_decoded - 1, true)?; | |
| 1048 | + sink(output.as_ref().unwrap_or(&picture), pictures_decoded - 1, true)?; | |
| 1042 | 1049 | pictures_shown += 1; |
| 1043 | 1050 | } else { |
| 1044 | 1051 | // Hidden (alt-ref/forward-key) frames never reach |