forge
Explore
Log in

Don't you dare go Hollow

Repeated identical PipeWire format no longer renegotiates buffers or logs twice, Vulkan encode check reuses the startup probe instead of initializing VA-API again

Browse files at this commit

51bbfe8a8f657e505895b17e709e8acf8dc1c34eAhmet Kaan GümüşParent: dbc5912
  • fix
    • repeated identical PipeWire format no longer renegotiates buffers or logs twice, Vulkan encode check reuses the startup probe instead of initializing VA-API again
Show full message
🐛 fix: repeated identical PipeWire format no longer renegotiates buffers or logs twice, Vulkan encode check reuses the startup probe instead of initializing VA-API again
crates/client/src/share/capture.rsmodified+18 -2
@@ -190,10 +190,13 @@ fn text(error: impl std::fmt::Display) -> String {
190 error.to_string()190 error.to_string()
191 }191 }
192 192
193+type Applied = (bool, u64, u32, u32, u32);
194+
193 struct State {195 struct State {
194 format: VideoInfoRaw,196 format: VideoInfoRaw,
195 size: (u32, u32),197 size: (u32, u32),
196 modifiers: Vec<u64>,198 modifiers: Vec<u64>,
199+ applied: Option<Applied>,
197 stop: Arc<AtomicBool>,200 stop: Arc<AtomicBool>,
198 started: Instant,201 started: Instant,
199 negotiated: SyncSender<Negotiated>,202 negotiated: SyncSender<Negotiated>,
@@ -237,6 +240,7 @@ fn run(
237 format: VideoInfoRaw::new(),240 format: VideoInfoRaw::new(),
238 size: (0, 0),241 size: (0, 0),
239 modifiers: modifiers.clone(),242 modifiers: modifiers.clone(),
243+ applied: None,
240 stop: stop.clone(),244 stop: stop.clone(),
241 started: Instant::now(),245 started: Instant::now(),
242 negotiated,246 negotiated,
@@ -446,14 +450,26 @@ fn on_param(stream: &pw::stream::Stream, state: &mut State, id: u32, param: Opti
446 return;450 return;
447 }451 }
448 let gpu = offered.is_some();452 let gpu = offered.is_some();
449- tracing::info!(gpu, modifier = state.format.modifier(), format = ?state.format.format(), "share capture format");453+ let size = state.format.size();
454+ let modifier = if gpu { state.format.modifier() } else { 0 };
455+ let applied = (
456+ gpu,
457+ modifier,
458+ state.format.format().as_raw(),
459+ size.width,
460+ size.height,
461+ );
462+ if state.applied == Some(applied) {
463+ return;
464+ }
465+ state.applied = Some(applied);
466+ tracing::info!(gpu, modifier, format = ?state.format.format(), "share capture format");
450 if let Some(buffers) = buffers_values(gpu)467 if let Some(buffers) = buffers_values(gpu)
451 && let Some(buffers) = Pod::from_bytes(&buffers)468 && let Some(buffers) = Pod::from_bytes(&buffers)
452 {469 {
453 let _ = stream.update_params(&mut [buffers]);470 let _ = stream.update_params(&mut [buffers]);
454 }471 }
455 472
456- let size = state.format.size();
457 let fps = state.format.max_framerate();473 let fps = state.format.max_framerate();
458 let refresh = fps474 let refresh = fps
459 .num475 .num
crates/client/src/share/encode.rsmodified+10 -20
@@ -23,12 +23,13 @@ pub struct Capabilities {
23 struct Probe {23 struct Probe {
24 capabilities: Capabilities,24 capabilities: Capabilities,
25 hardware: Vec<Codec>,25 hardware: Vec<Codec>,
26+ vulkan: Vec<Codec>,
26 }27 }
27 28
28 fn probe() -> &'static Probe {29 fn probe() -> &'static Probe {
29 static PROBE: OnceLock<Probe> = OnceLock::new();30 static PROBE: OnceLock<Probe> = OnceLock::new();
30 PROBE.get_or_init(|| {31 PROBE.get_or_init(|| {
31- let hardware = hardware::probe();32+ let (hardware, vulkan) = hardware::probe();
32 let codecs: Vec<Codec> = hardware.iter().map(|(codec, _)| *codec).collect();33 let codecs: Vec<Codec> = hardware.iter().map(|(codec, _)| *codec).collect();
33 let max_height = hardware34 let max_height = hardware
34 .iter()35 .iter()
@@ -46,6 +47,7 @@ fn probe() -> &'static Probe {
46 max_height,47 max_height,
47 },48 },
48 hardware: codecs,49 hardware: codecs,
50+ vulkan,
49 }51 }
50 })52 })
51 }53 }
@@ -300,8 +302,9 @@ mod hardware {
300 }302 }
301 }303 }
302 304
303- pub fn probe() -> Vec<(Codec, u32)> {305+ pub fn probe() -> (Vec<(Codec, u32)>, Vec<Codec>) {
304 let mut found: Vec<(Codec, u32)> = Vec::new();306 let mut found: Vec<(Codec, u32)> = Vec::new();
307+ let mut vulkan = Vec::new();
305 for capability in ec_hw::capabilities() {308 for capability in ec_hw::capabilities() {
306 if capability.direction != ec_hw::Direction::Encode {309 if capability.direction != ec_hw::Direction::Encode {
307 continue;310 continue;
@@ -309,32 +312,19 @@ mod hardware {
309 let Some(codec) = codec(capability.codec) else {312 let Some(codec) = codec(capability.codec) else {
310 continue;313 continue;
311 };314 };
315+ if capability.backend == ec_hw::Backend::Vk && !vulkan.contains(&codec) {
316+ vulkan.push(codec);
317+ }
312 match found.iter_mut().find(|(known, _)| *known == codec) {318 match found.iter_mut().find(|(known, _)| *known == codec) {
313 Some((_, height)) => *height = (*height).max(capability.max_height),319 Some((_, height)) => *height = (*height).max(capability.max_height),
314 None => found.push((codec, capability.max_height)),320 None => found.push((codec, capability.max_height)),
315 }321 }
316 }322 }
317- found323+ (found, vulkan)
318- }
319-
320- fn vulkan_encodes(wanted: Codec) -> bool {
321- static VULKAN: std::sync::OnceLock<Vec<Codec>> = std::sync::OnceLock::new();
322- VULKAN
323- .get_or_init(|| {
324- ec_hw::capabilities()
325- .into_iter()
326- .filter(|capability| {
327- capability.direction == ec_hw::Direction::Encode
328- && capability.backend == ec_hw::Backend::Vk
329- })
330- .filter_map(|capability| codec(capability.codec))
331- .collect()
332- })
333- .contains(&wanted)
334 }324 }
335 325
336 fn open_vulkan(config: ec_hw::EncoderConfig, wanted: Codec) -> Option<ec_hw::HwEncoder> {326 fn open_vulkan(config: ec_hw::EncoderConfig, wanted: Codec) -> Option<ec_hw::HwEncoder> {
337- if !vulkan_encodes(wanted) {327+ if !super::probe().vulkan.contains(&wanted) {
338 return None;328 return None;
339 }329 }
340 for attempt in 1..=VULKAN_ATTEMPTS {330 for attempt in 1..=VULKAN_ATTEMPTS {