Skip to content

Commit a40cbfb

Browse files
committed
Prewarm composite pipeline and shared WGPU device
1 parent 639078d commit a40cbfb

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

crates/rendering/src/decoder/media_foundation.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,6 @@ impl MFDecoder {
408408
}
409409
}
410410

411-
#[cfg(target_os = "windows")]
412-
let readahead_frames = 12u32;
413-
#[cfg(not(target_os = "windows"))]
414411
let readahead_frames = 30u32;
415412
let readahead_target = requested_frame + readahead_frames;
416413
if frame_number >= readahead_target || frame_number > cache_max {

crates/rendering/src/lib.rs

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,21 @@ use std::{collections::HashMap, sync::Arc};
2020
use std::{path::PathBuf, time::Instant};
2121
use tokio::sync::mpsc;
2222

23-
mod composite_frame;
23+
static PRECOMPILED_COMPOSITE_PIPELINE: std::sync::OnceLock<
24+
Arc<composite_frame::CompositeVideoFramePipeline>,
25+
> = std::sync::OnceLock::new();
26+
27+
pub fn prewarm_composite_pipeline(device: &wgpu::Device) {
28+
let pipeline = composite_frame::CompositeVideoFramePipeline::new(device);
29+
let _ = PRECOMPILED_COMPOSITE_PIPELINE.set(Arc::new(pipeline));
30+
}
31+
32+
pub fn get_precompiled_composite_pipeline()
33+
-> Option<Arc<composite_frame::CompositeVideoFramePipeline>> {
34+
PRECOMPILED_COMPOSITE_PIPELINE.get().cloned()
35+
}
36+
37+
pub mod composite_frame;
2438
mod coord;
2539
pub mod cpu_yuv;
2640
mod cursor_interpolation;
@@ -963,7 +977,46 @@ pub struct RenderVideoConstants {
963977
pub is_software_adapter: bool,
964978
}
965979

980+
pub struct SharedWgpuDevice {
981+
pub instance: wgpu::Instance,
982+
pub adapter: wgpu::Adapter,
983+
pub device: wgpu::Device,
984+
pub queue: wgpu::Queue,
985+
pub is_software_adapter: bool,
986+
}
987+
966988
impl RenderVideoConstants {
989+
pub fn new_with_device(
990+
shared: SharedWgpuDevice,
991+
segments: &[SegmentRecordings],
992+
recording_meta: RecordingMeta,
993+
meta: StudioRecordingMeta,
994+
) -> Result<Self, RenderingError> {
995+
let first_segment = segments.first().ok_or(RenderingError::NoSegments)?;
996+
997+
let options = RenderOptions {
998+
screen_size: XY::new(first_segment.display.width, first_segment.display.height),
999+
camera_size: first_segment
1000+
.camera
1001+
.as_ref()
1002+
.map(|c| XY::new(c.width, c.height)),
1003+
};
1004+
1005+
let background_textures = Arc::new(tokio::sync::RwLock::new(HashMap::new()));
1006+
1007+
Ok(Self {
1008+
_instance: shared.instance,
1009+
_adapter: shared.adapter,
1010+
device: shared.device,
1011+
queue: shared.queue,
1012+
options,
1013+
background_textures,
1014+
meta,
1015+
recording_meta,
1016+
is_software_adapter: shared.is_software_adapter,
1017+
})
1018+
}
1019+
9671020
pub async fn new(
9681021
segments: &[SegmentRecordings],
9691022
recording_meta: RecordingMeta,
@@ -1040,9 +1093,14 @@ impl RenderVideoConstants {
10401093
(software_adapter, true)
10411094
};
10421095

1096+
let mut required_features = wgpu::Features::empty();
1097+
if adapter.features().contains(wgpu::Features::PIPELINE_CACHE) {
1098+
required_features |= wgpu::Features::PIPELINE_CACHE;
1099+
}
1100+
10431101
let device_descriptor = wgpu::DeviceDescriptor {
10441102
label: Some("cap-rendering-device"),
1045-
required_features: wgpu::Features::empty(),
1103+
required_features,
10461104
..Default::default()
10471105
};
10481106

@@ -2463,7 +2521,11 @@ impl RendererLayers {
24632521
) -> Self {
24642522
let shared_yuv_pipelines = Arc::new(yuv_converter::YuvConverterPipelines::new(device));
24652523
let shared_composite_pipeline =
2466-
Arc::new(composite_frame::CompositeVideoFramePipeline::new(device));
2524+
if let Some(precompiled) = get_precompiled_composite_pipeline() {
2525+
precompiled
2526+
} else {
2527+
Arc::new(composite_frame::CompositeVideoFramePipeline::new(device))
2528+
};
24672529

24682530
Self {
24692531
background: BackgroundLayer::new(device),

0 commit comments

Comments
 (0)