editor: wire hardware video decode + NV12 preview compositing (Stage 3c-preview)
Make the dormant core HW-decode engine live for the preview path: - hw_video.rs: editor's HwVideoImporter — maps a decoded VAAPI surface to a DRM-PRIME DMA-BUF and imports it as wgpu NV12 plane textures on the *shared* device (the only one with the import extensions). install() creates the VAAPI device and injects it + the importer into the VideoManager. - main.rs: track whether the shared device is actually in use; only then (Linux, not LB_NO_SHARED_DEVICE) install hardware decode, using the CreationContext's shared device + adapter. - nv12_blit.rs + nv12_blit.wgsl: NV12 plane textures → BT.709 → sRGB-encoded → linear, written straight into the Rgba16Float HDR layer (no CPU upload). Colour math mirrors the software path so HW/SW video match; honours full_range. - stage.rs: the preview Video arm branches on inst.gpu (NV12 blit) vs rgba_data (existing upload+blit_straight); sets render_hardware_ok = !cpu_renderer so the CPU fallback still gets software frames. - video_exporter.rs: sets render_hardware_ok(false) before both compositing passes — export composites on the encoder's separate device, so a hardware decoder downloads to CPU instead (export stays software, correct). - dmabuf.rs: imported plane textures now also carry SAMPLED/TEXTURE_BINDING so they can be sampled by the NV12 blit (they were render-target-only); into_planes hands the textures to the longer-lived GpuVideoFrame. - video.rs: cache-key the GPU/CPU representation on want_gpu (HW-configured AND render_hardware_ok) so software-only decode keeps a single cache entry. Preview only this pass; export GPU-residency is the 3c-export follow-up. Untested at runtime here (no GPU/display in container) — both crates compile.
This commit is contained in:
@@ -875,11 +875,13 @@ impl VideoManager {
|
||||
/// [`set_render_hardware_ok`](Self::set_render_hardware_ok), set per render pass (true for the
|
||||
/// preview, false for export, which composites on a different device).
|
||||
pub fn get_frame(&mut self, clip_id: &Uuid, timestamp: f64, target_w: u32, target_h: u32) -> Option<Arc<VideoFrame>> {
|
||||
let hardware_ok = self.render_hardware_ok;
|
||||
// The cache key includes (target size, hardware_ok): preview (GPU, preview res) and export
|
||||
// Whether this pass wants (and can produce) a GPU frame. Gated on HW being configured at all
|
||||
// so that with software-only decode preview and export share one cache entry (no double-cache).
|
||||
let want_gpu = self.render_hardware_ok && self.hw_device.is_some();
|
||||
// The cache key includes (target size, want_gpu): preview (GPU, preview res) and export
|
||||
// (CPU, export res) request the same clip/time and must not collide or cross representation.
|
||||
let timestamp_ms = (timestamp * 1000.0) as i64;
|
||||
let cache_key = (*clip_id, timestamp_ms, target_w, target_h, hardware_ok);
|
||||
let cache_key = (*clip_id, timestamp_ms, target_w, target_h, want_gpu);
|
||||
|
||||
// Check frame cache first
|
||||
if let Some(cached_frame) = self.frame_cache.get(&cache_key) {
|
||||
@@ -892,7 +894,7 @@ impl VideoManager {
|
||||
let mut decoder = decoder_arc.lock().ok()?;
|
||||
|
||||
// Decode the frame at the requested target (capped to native by the decoder).
|
||||
let decoded = decoder.get_frame(timestamp, target_w, target_h, hardware_ok).ok()?;
|
||||
let decoded = decoder.get_frame(timestamp, target_w, target_h, want_gpu).ok()?;
|
||||
drop(decoder); // release the lock before touching `self`
|
||||
|
||||
// Create VideoFrame and cache it.
|
||||
|
||||
Reference in New Issue
Block a user