forge
Explore
Log in

Don't you dare go Hollow

A wheel notch on the budget opens no encoder

Browse files at this commit

24934ba180ebeff6c499c5b41b7ace8df4736f87Ahmet Kaan GümüşParent: 388faa6
  • perf
    • a wheel notch on the budget opens no encoder
Show full message
⚡️ perf(app): a wheel notch on the budget opens no encoder

The export moment's seat probe was keyed on the whole export settings, bitrate included, so every notch of the wheel invalidated it and opened a real VA-API encoder to ask the seat again — ten opens for ten notches, 5–32 ms of GPU work each, beside the player's own decoder. The bitrate decides none of that answer, so the probe is asked and keyed without it: one probe when the moment opens, none while the wheel turns.
crates/app/src/export_ui.rsmodified+15 -0
@@ -663,6 +663,21 @@ pub(crate) fn export_settings(
663 }663 }
664 }664 }
665 665
666+/// The same settings with the budget taken out -- what the seat probe is asked
667+/// and keyed on ([`crate::Player::cache_export_seat`]). A bitrate does not
668+/// decide whether this machine has a VA-API seat or whether the picture's
669+/// packets can be copied; leaving it in the key meant every wheel notch on the
670+/// budget row invalidated the answer and opened a real VA-API encoder to ask it
671+/// again -- measured at ten opens for ten notches, 5-32 ms of GPU work each,
672+/// against the player's own decoder, which is the "freezes a little" this row
673+/// was reported for.
674+pub(crate) fn probe_settings(format: Format, audio_kbps: u32, seat: EncoderSeat) -> ExportSettings {
675+ ExportSettings {
676+ bitrate: None,
677+ ..export_settings(0, format, audio_kbps, seat)
678+ }
679+}
680+
666 /// The budget's bounds, the engine's own (`engine::export`'s `MIN_BITRATE`681 /// The budget's bounds, the engine's own (`engine::export`'s `MIN_BITRATE`
667 /// and `MAX_EXPLICIT_BITRATE`): a number outside them would be written as a682 /// and `MAX_EXPLICIT_BITRATE`): a number outside them would be written as a
668 /// different one, so the lever and the field clamp to exactly these.683 /// different one, so the lever and the field clamp to exactly these.
crates/app/src/player/export.rsmodified+1 -6
@@ -351,12 +351,7 @@ impl Player {
351 let Some(session) = &self.session else {351 let Some(session) = &self.session else {
352 return;352 return;
353 };353 };
354- let settings = export_settings(354+ let settings = probe_settings(self.format, self.audio_kbps, self.encoder_seat());
355- self.budget_bps(),
356- self.format,
357- self.audio_kbps,
358- self.encoder_seat(),
359- );
360 if !self.export_open {355 if !self.export_open {
361 return;356 return;
362 }357 }
crates/app/src/tests/cards.rsmodified+29 -0
@@ -2006,3 +2006,32 @@ fn toggle_proxy_wakes_the_asked_phase_it_stops() {
2006 "a stop asked during Asked no longer sets the flag the header read polls"2006 "a stop asked during Asked no longer sets the flag the header read polls"
2007 );2007 );
2008 }2008 }
2009+
2010+/// A wheel notch on the budget must not re-ask the seat probe. The probe opens
2011+/// a real VA-API encoder (ten opens for ten notches before this, 5-32 ms of GPU
2012+/// work each, against the player's own decoder) and its answer -- GPU seat or
2013+/// software, copy or encode -- does not depend on the bitrate at all. So the
2014+/// settings it is keyed on carry no budget, and the budget still reaches the
2015+/// export itself, which is the one place it changes a file.
2016+#[test]
2017+fn the_seat_probe_is_not_keyed_on_the_budget() {
2018+ let seat = EncoderSeat::default();
2019+ let asked = crate::probe_settings(Format::Mp4, DEFAULT_AUDIO_KBPS, seat);
2020+ assert_eq!(asked.bitrate, None, "no budget is in the probe's question");
2021+ // What still *is* a new question: the format the file is written in.
2022+ assert_ne!(
2023+ asked,
2024+ crate::probe_settings(Format::Av1, DEFAULT_AUDIO_KBPS, seat),
2025+ "a format change must re-probe"
2026+ );
2027+ let cache = fn_body("cache_export_seat");
2028+ assert!(
2029+ cache.contains("probe_settings(") && !cache.contains("budget_bps()"),
2030+ "the seat cache is keyed on the budget again"
2031+ );
2032+ // ...and the number the wheel moves is still what the export is given.
2033+ assert!(
2034+ fn_body("start_export").contains("self.budget_bps()"),
2035+ "the export no longer writes at the budget on the row"
2036+ );
2037+}