diff --git a/shims/vk-video-ffi/examples/dmabuf_smoke.rs b/shims/vk-video-ffi/examples/dmabuf_smoke.rs index 3c48073a..fe722868 100644 --- a/shims/vk-video-ffi/examples/dmabuf_smoke.rs +++ b/shims/vk-video-ffi/examples/dmabuf_smoke.rs @@ -540,12 +540,53 @@ fn run(gpu: &Gpu, name: &str, host: &[u8], linear: &Export, tiled: &E } } -fn run_planar(gpu: &Gpu, name: &str, pattern: &Pattern, exports: &[&Export]) { - let format = if pattern.bits == 8 { +fn planar_format(pattern: &Pattern) -> DmaBufFormat { + if pattern.bits == 8 { DmaBufFormat::Nv12 } else { DmaBufFormat::P010 - }; + } +} + +fn split_planes(a: &Export, b: &Export) -> [DmaBufPlane; 2] { + [ + DmaBufPlane { fd: 0, ..a.planes[0] }, + DmaBufPlane { fd: 1, ..b.planes[1] }, + ] +} + +fn run_split(gpu: &Gpu, name: &str, pattern: &Pattern, pairs: &[(Export, Export)]) { + let format = planar_format(pattern); + for (a_export, b_export) in pairs { + let mut a = S::open(gpu, (W, H), pattern.bits).expect("encoder"); + let mut b = S::open(gpu, (W, H), pattern.bits).expect("encoder"); + let fds = [a_export.fd.as_fd(), b_export.fd.as_fd()]; + let planes = split_planes(a_export, b_export); + let src = DmaBuf { + fds: &fds, + planes: &planes, + width: W, + height: H, + modifier: a_export.modifier, + format, + }; + let mut left = Vec::new(); + let mut right = Vec::new(); + for i in 0..FRAMES { + left.extend(a.planar(pattern, i).expect("encode")); + right.extend(b.dma(&src, i).expect("encode_dmabuf")); + } + let verdict = if left == right { + "identical" + } else { + "DIFFERENT" + }; + println!("{name} split {:#x} {W}x{H} {verdict}", a_export.modifier); + } +} + +fn run_planar(gpu: &Gpu, name: &str, pattern: &Pattern, exports: &[&Export]) { + let format = planar_format(pattern); for export in exports { let mut a = S::open(gpu, (W, H), pattern.bits).expect("encoder"); let mut b = S::open(gpu, (W, H), pattern.bits).expect("encoder"); @@ -636,6 +677,50 @@ fn main() { run_planar::(&gpu, "av1 nv12", &nv12, &nv12_set); run_planar::(&gpu, "av1 p010", &p010, &p010_set); + let pair = |format, pattern: &Pattern, modifier| { + ( + export_planar(instance, physical, d, queue, family, format, modifier, pattern), + export_planar(instance, physical, d, queue, family, format, modifier, pattern), + ) + }; + let nv12_pairs: Vec<(Export, Export)> = [Some(0), pick_modifier(instance, physical, NV12, 2)] + .into_iter() + .flatten() + .map(|m| pair(NV12, &nv12, m)) + .collect(); + let p010_pairs: Vec<(Export, Export)> = [Some(0), pick_modifier(instance, physical, P010, 2)] + .into_iter() + .flatten() + .map(|m| pair(P010, &p010, m)) + .collect(); + run_split::(&gpu, "h264 nv12", &nv12, &nv12_pairs); + run_split::(&gpu, "h265 nv12", &nv12, &nv12_pairs); + run_split::(&gpu, "h265 p010", &p010, &p010_pairs); + run_split::(&gpu, "av1 nv12", &nv12, &nv12_pairs); + run_split::(&gpu, "av1 p010", &p010, &p010_pairs); + + let mut split_cache = ::open(&gpu, (W, H), 8).expect("encoder"); + let (sa, sb) = &nv12_pairs[0]; + let fds = [sa.fd.as_fd(), sb.fd.as_fd()]; + let planes = split_planes(sa, sb); + let src = DmaBuf { + fds: &fds, + planes: &planes, + width: W, + height: H, + modifier: sa.modifier, + format: DmaBufFormat::Nv12, + }; + for pass in 1..=2 { + for i in 0..FRAMES { + split_cache.dma(&src, i).expect("encode_dmabuf"); + } + println!( + "cache h265 nv12 split pass {pass} {FRAMES} frames same fds imports {}", + split_cache.dmabuf_imports() + ); + } + let mut cache = ::open(&gpu, (W, H), 8).expect("encoder"); let fds = [nv12_linear.fd.as_fd()]; let src = DmaBuf { @@ -661,4 +746,8 @@ fn main() { for e in &exports { e.destroy(d); } + for (a, b) in nv12_pairs.iter().chain(&p010_pairs) { + a.destroy(d); + b.destroy(d); + } } diff --git a/shims/vk-video-ffi/src/dmabuf.rs b/shims/vk-video-ffi/src/dmabuf.rs index 5ca84032..5ce6aa53 100644 --- a/shims/vk-video-ffi/src/dmabuf.rs +++ b/shims/vk-video-ffi/src/dmabuf.rs @@ -217,6 +217,7 @@ impl Key { pub(crate) struct Import { pub(crate) image: vk::Image, + planes: Option<[vk::Image; 2]>, id: u64, memories: Vec, } @@ -225,60 +226,23 @@ impl Import { fn new(gpu: &Gpu, src: &DmaBuf, id: u64) -> Result { check(gpu)?; validate(src)?; - let d = gpu.device(); - let format = match src.format { - DmaBufFormat::Bgrx => vk::Format::B8G8R8A8_UNORM, - DmaBufFormat::Rgbx => vk::Format::R8G8B8A8_UNORM, - DmaBufFormat::Nv12 => NV12, - DmaBufFormat::P010 => P010, - }; - let layouts: Vec = src - .planes - .iter() - .map(|p| vk::SubresourceLayout { - offset: p.offset as u64, - size: 0, - row_pitch: p.pitch as u64, - array_pitch: 0, - depth_pitch: 0, - }) - .collect(); - let mut explicit = vk::ImageDrmFormatModifierExplicitCreateInfoEXT::builder() - .drm_format_modifier(src.modifier) - .plane_layouts(&layouts) - .build(); - let mut external = vk::ExternalMemoryImageCreateInfo::builder() - .handle_types(vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) - .build(); - let flags = if src.fds.len() == 2 { - vk::ImageCreateFlags::DISJOINT - } else { - vk::ImageCreateFlags::empty() - }; - let info = vk::ImageCreateInfo::builder() - .flags(flags) - .image_type(vk::ImageType::_2D) - .format(format) - .extent(vk::Extent3D { - width: src.width, - height: src.height, - depth: 1, - }) - .mip_levels(1) - .array_layers(1) - .samples(vk::SampleCountFlags::_1) - .tiling(vk::ImageTiling::DRM_FORMAT_MODIFIER_EXT) - .usage(vk::ImageUsageFlags::TRANSFER_SRC) - .sharing_mode(vk::SharingMode::EXCLUSIVE) - .initial_layout(vk::ImageLayout::UNDEFINED) - .push_next(&mut external) - .push_next(&mut explicit) - .build(); - let image = unsafe { vk(d.create_image(&info, None), "vkCreateImage")? }; - match bind(gpu, image, src) { - Ok(memories) => Ok(Import { image, id, memories }), + let mut images = Vec::new(); + let mut memories = Vec::new(); + match build(gpu, src, &mut images, &mut memories) { + Ok((image, planes)) => Ok(Import { + image, + planes, + id, + memories, + }), Err(e) => { - unsafe { d.destroy_image(image, None) }; + let d = gpu.device(); + for m in &memories { + unsafe { d.free_memory(*m, None) }; + } + for i in &images { + unsafe { d.destroy_image(*i, None) }; + } Err(e) } } @@ -287,6 +251,9 @@ impl Import { fn destroy(&self, d: &Device) { unsafe { d.destroy_image(self.image, None); + for p in self.planes.iter().flatten() { + d.destroy_image(*p, None); + } for m in &self.memories { d.free_memory(*m, None); } @@ -294,6 +261,129 @@ impl Import { } } +fn build( + gpu: &Gpu, + src: &DmaBuf, + images: &mut Vec, + memories: &mut Vec, +) -> Result<(vk::Image, Option<[vk::Image; 2]>), Error> { + if src.fds.len() == 1 { + let format = match src.format { + DmaBufFormat::Bgrx => vk::Format::B8G8R8A8_UNORM, + DmaBufFormat::Rgbx => vk::Format::R8G8B8A8_UNORM, + DmaBufFormat::Nv12 => NV12, + DmaBufFormat::P010 => P010, + }; + let image = explicit_image(gpu, format, (src.width, src.height), src.modifier, src.planes)?; + images.push(image); + memories.push(import_memory(gpu, image, src.fds[0])?); + return Ok((image, None)); + } + let (plane_format, chroma_format, internal_format) = match src.format { + DmaBufFormat::P010 => (vk::Format::R16_UNORM, vk::Format::R16G16_UNORM, P010), + _ => (vk::Format::R8_UNORM, vk::Format::R8G8_UNORM, NV12), + }; + if !single_plane(gpu, plane_format, src.modifier) + || !single_plane(gpu, chroma_format, src.modifier) + { + return Err(Error::Unsupported( + "DMA-BUF two-object import: modifier lacks single-plane formats".into(), + )); + } + let (w, h) = (src.width, src.height); + let y = explicit_image(gpu, plane_format, (w, h), src.modifier, &src.planes[..1])?; + images.push(y); + memories.push(import_memory(gpu, y, src.fds[0])?); + let uv = explicit_image(gpu, chroma_format, (w / 2, h / 2), src.modifier, &src.planes[1..])?; + images.push(uv); + memories.push(import_memory(gpu, uv, src.fds[1])?); + let internal = device_image(gpu, internal_format, (w, h))?; + images.push(internal); + memories.push(device_memory(gpu, internal)?); + Ok((internal, Some([y, uv]))) +} + +fn explicit_image( + gpu: &Gpu, + format: vk::Format, + (width, height): (u32, u32), + modifier: u64, + planes: &[DmaBufPlane], +) -> Result { + let d = gpu.device(); + let layouts: Vec = planes + .iter() + .map(|p| vk::SubresourceLayout { + offset: p.offset as u64, + size: 0, + row_pitch: p.pitch as u64, + array_pitch: 0, + depth_pitch: 0, + }) + .collect(); + let mut explicit = vk::ImageDrmFormatModifierExplicitCreateInfoEXT::builder() + .drm_format_modifier(modifier) + .plane_layouts(&layouts) + .build(); + let mut external = vk::ExternalMemoryImageCreateInfo::builder() + .handle_types(vk::ExternalMemoryHandleTypeFlags::DMA_BUF_EXT) + .build(); + let info = vk::ImageCreateInfo::builder() + .image_type(vk::ImageType::_2D) + .format(format) + .extent(vk::Extent3D { + width, + height, + depth: 1, + }) + .mip_levels(1) + .array_layers(1) + .samples(vk::SampleCountFlags::_1) + .tiling(vk::ImageTiling::DRM_FORMAT_MODIFIER_EXT) + .usage(vk::ImageUsageFlags::TRANSFER_SRC) + .sharing_mode(vk::SharingMode::EXCLUSIVE) + .initial_layout(vk::ImageLayout::UNDEFINED) + .push_next(&mut external) + .push_next(&mut explicit) + .build(); + unsafe { vk(d.create_image(&info, None), "vkCreateImage") } +} + +fn device_image(gpu: &Gpu, format: vk::Format, (width, height): (u32, u32)) -> Result { + let info = vk::ImageCreateInfo::builder() + .image_type(vk::ImageType::_2D) + .format(format) + .extent(vk::Extent3D { + width, + height, + depth: 1, + }) + .mip_levels(1) + .array_layers(1) + .samples(vk::SampleCountFlags::_1) + .tiling(vk::ImageTiling::OPTIMAL) + .usage(vk::ImageUsageFlags::TRANSFER_SRC | vk::ImageUsageFlags::TRANSFER_DST) + .sharing_mode(vk::SharingMode::EXCLUSIVE) + .initial_layout(vk::ImageLayout::UNDEFINED); + unsafe { vk(gpu.device().create_image(&info, None), "vkCreateImage") } +} + +fn device_memory(gpu: &Gpu, image: vk::Image) -> Result { + let d = gpu.device(); + let req = unsafe { d.get_image_memory_requirements(image) }; + let index = memory_type(gpu, req.memory_type_bits, vk::MemoryPropertyFlags::DEVICE_LOCAL)?; + let alloc = vk::MemoryAllocateInfo::builder() + .allocation_size(req.size) + .memory_type_index(index) + .build(); + let memory = unsafe { vk(d.allocate_memory(&alloc, None), "vkAllocateMemory")? }; + if let Err(e) = unsafe { vk(d.bind_image_memory(image, memory, 0), "vkBindImageMemory") } { + unsafe { d.free_memory(memory, None) }; + return Err(e); + } + Ok(memory) +} + #[derive(Default)] pub(crate) struct ImportCache { entries: Vec<(Key, Import)>, @@ -302,7 +392,12 @@ pub(crate) struct ImportCache { } impl ImportCache { - pub(crate) fn get(&mut self, gpu: &Gpu, src: &DmaBuf, busy: &[u64]) -> Result<(vk::Image, u64), Error> { + pub(crate) fn get( + &mut self, + gpu: &Gpu, + src: &DmaBuf, + busy: &[u64], + ) -> Result<(vk::Image, Option<[vk::Image; 2]>, u64), Error> { validate(src)?; let key = Key::new(src)?; match self.entries.iter().position(|(k, _)| *k == key) { @@ -328,7 +423,7 @@ impl ImportCache { } self.entries .last() - .map(|(_, import)| (import.image, import.id)) + .map(|(_, import)| (import.image, import.planes, import.id)) .ok_or_else(|| Error::Invalid("DMA-BUF import cache".into())) } @@ -339,28 +434,9 @@ impl ImportCache { } } -fn allocate( - gpu: &Gpu, - image: vk::Image, - plane: Option, - fd: BorrowedFd, -) -> Result { +fn import_memory(gpu: &Gpu, image: vk::Image, fd: BorrowedFd) -> Result { let d = gpu.device(); - let req = match plane { - None => unsafe { d.get_image_memory_requirements(image) }, - Some(aspect) => { - let mut plane_info = vk::ImagePlaneMemoryRequirementsInfo::builder() - .plane_aspect(aspect) - .build(); - let info = vk::ImageMemoryRequirementsInfo2::builder() - .image(image) - .push_next(&mut plane_info) - .build(); - let mut out = vk::MemoryRequirements2::default(); - unsafe { d.get_image_memory_requirements2(&info, &mut out) }; - out.memory_requirements - } - }; + let req = unsafe { d.get_image_memory_requirements(image) }; let owned = fd .try_clone_to_owned() .map_err(|_| Error::Invalid("DMA-BUF descriptor".into()))?; @@ -387,82 +463,22 @@ fn allocate( let mut dedicated = vk::MemoryDedicatedAllocateInfo::builder() .image(image) .build(); - let alloc = if plane.is_some() { - vk::MemoryAllocateInfo::builder() - .allocation_size(req.size) - .memory_type_index(index) - .push_next(&mut import) - .build() - } else { - vk::MemoryAllocateInfo::builder() - .allocation_size(req.size) - .memory_type_index(index) - .push_next(&mut dedicated) - .push_next(&mut import) - .build() - }; + let alloc = vk::MemoryAllocateInfo::builder() + .allocation_size(req.size) + .memory_type_index(index) + .push_next(&mut dedicated) + .push_next(&mut import) + .build(); let memory = unsafe { vk(d.allocate_memory(&alloc, None), "vkAllocateMemory")? }; let _ = owned.into_raw_fd(); - Ok(memory) -} - -fn bind(gpu: &Gpu, image: vk::Image, src: &DmaBuf) -> Result, Error> { - let d = gpu.device(); - let free = |memories: &[vk::DeviceMemory]| { - for m in memories { - unsafe { d.free_memory(*m, None) }; - } - }; - if src.fds.len() == 1 { - let memory = allocate(gpu, image, None, src.fds[0])?; - let bound = unsafe { vk(d.bind_image_memory(image, memory, 0), "vkBindImageMemory") }; - if let Err(e) = bound { - free(&[memory]); - return Err(e); - } - return Ok(vec![memory]); - } - let aspects = [vk::ImageAspectFlags::PLANE_0, vk::ImageAspectFlags::PLANE_1]; - let mut memories = Vec::with_capacity(2); - for (fd, aspect) in src.fds.iter().zip(aspects) { - match allocate(gpu, image, Some(aspect), *fd) { - Ok(memory) => memories.push(memory), - Err(e) => { - free(&memories); - return Err(e); - } - } - } - let mut plane_infos: Vec = aspects - .iter() - .map(|&plane_aspect| { - vk::BindImagePlaneMemoryInfo::builder() - .plane_aspect(plane_aspect) - .build() - }) - .collect(); - let binds: Vec = memories - .iter() - .zip(plane_infos.iter_mut()) - .map(|(memory, info)| { - vk::BindImageMemoryInfo::builder() - .image(image) - .memory(*memory) - .memory_offset(0) - .push_next(info) - .build() - }) - .collect(); - let bound = unsafe { vk(d.bind_image_memory2(&binds), "vkBindImageMemory2") }; - if let Err(e) = bound { - free(&memories); + if let Err(e) = unsafe { vk(d.bind_image_memory(image, memory, 0), "vkBindImageMemory") } { + unsafe { d.free_memory(memory, None) }; return Err(e); } - Ok(memories) + Ok(memory) } -/// Every DRM format modifier that can be a transfer destination for `format`. -fn export_modifiers(gpu: &Gpu, format: vk::Format) -> Vec { +fn modifier_properties(gpu: &Gpu, format: vk::Format) -> Vec { let instance = gpu.instance(); let mut count = vk::DrmFormatModifierPropertiesListEXT::builder().build(); let mut props = vk::FormatProperties2::builder().push_next(&mut count).build(); @@ -474,7 +490,13 @@ fn export_modifiers(gpu: &Gpu, format: vk::Format) -> Vec { .build(); let mut props = vk::FormatProperties2::builder().push_next(&mut full).build(); unsafe { instance.get_physical_device_format_properties2(gpu.physical(), format, &mut props) }; - list.iter() + list +} + +/// Every DRM format modifier that can be a transfer destination for `format`. +fn export_modifiers(gpu: &Gpu, format: vk::Format) -> Vec { + modifier_properties(gpu, format) + .iter() .filter(|m| { m.drm_format_modifier_tiling_features .contains(vk::FormatFeatureFlags::TRANSFER_DST | vk::FormatFeatureFlags::TRANSFER_SRC) @@ -483,6 +505,15 @@ fn export_modifiers(gpu: &Gpu, format: vk::Format) -> Vec { .collect() } +fn single_plane(gpu: &Gpu, format: vk::Format, modifier: u64) -> bool { + modifier_properties(gpu, format).iter().any(|m| { + m.drm_format_modifier == modifier + && m.drm_format_modifier_plane_count == 1 + && m.drm_format_modifier_tiling_features + .contains(vk::FormatFeatureFlags::TRANSFER_SRC) + }) +} + /// A ring slot's DMA-BUF: the one memory object, exported once, and its plane layout. pub(crate) struct Export { pub(crate) fd: OwnedFd, @@ -702,25 +733,10 @@ pub fn read_dmabuf(gpu: &Gpu, desc: &DmaBufExport) -> Result<(Vec, Vec), .push_next(&mut explicit) .build(); let image = unsafe { vk(d.create_image(&info, None), "vkCreateImage")? }; - let fds = [desc.fd.as_fd()]; - let src = DmaBuf { - fds: &fds, - planes: &desc.planes, - width: w, - height: h, - modifier: desc.modifier, - format: if desc.p010 { - DmaBufFormat::P010 - } else { - DmaBufFormat::Nv12 - }, - }; - let result = match bind(gpu, image, &src) { - Ok(memories) => { + let result = match import_memory(gpu, image, desc.fd.as_fd()) { + Ok(memory) => { let out = read_image(gpu, image, (w, h), bytes); - for m in memories { - unsafe { d.free_memory(m, None) }; - } + unsafe { d.free_memory(memory, None) }; out } Err(e) => Err(e), diff --git a/shims/vk-video-ffi/src/session.rs b/shims/vk-video-ffi/src/session.rs index 4b4f162f..71704aee 100644 --- a/shims/vk-video-ffi/src/session.rs +++ b/shims/vk-video-ffi/src/session.rs @@ -19,6 +19,8 @@ pub(crate) const P010: vk::Format = vk::Format::G10X6_B10X6R10X6_2PLANE_420_UNOR pub(crate) const DPB_SLOTS: usize = 2; pub(crate) const PLANE_0: vk::ImageAspectFlags = vk::ImageAspectFlags::PLANE_0; pub(crate) const PLANE_1: vk::ImageAspectFlags = vk::ImageAspectFlags::PLANE_1; +#[cfg(target_os = "linux")] +const COLOR: vk::ImageAspectFlags = vk::ImageAspectFlags::COLOR; pub(crate) type Stage = (vk::ImageLayout, vk::PipelineStageFlags2, vk::AccessFlags2); @@ -231,6 +233,28 @@ pub(crate) fn plane_copy( } } +#[cfg(target_os = "linux")] +fn split_copy(aspect: vk::ImageAspectFlags, (width, height): (u32, u32)) -> vk::ImageCopy { + let layers = |aspect_mask| vk::ImageSubresourceLayers { + aspect_mask, + mip_level: 0, + base_array_layer: 0, + layer_count: 1, + }; + let origin = vk::Offset3D { x: 0, y: 0, z: 0 }; + vk::ImageCopy { + src_subresource: layers(COLOR), + src_offset: origin, + dst_subresource: layers(aspect), + dst_offset: origin, + extent: vk::Extent3D { + width, + height, + depth: 1, + }, + } +} + pub(crate) fn copy_region( offset: u64, aspect: vk::ImageAspectFlags, @@ -1095,16 +1119,19 @@ impl Encoder { DmaBufFormat::Nv12 | DmaBufFormat::P010 => self.check_planar(src)?, } let busy: Vec = self.slots.iter().filter_map(|s| s.import).collect(); - let (image, id) = self.imports.get(&gpu, src, &busy)?; + let (image, planes, id) = self.imports.get(&gpu, src, &busy)?; let k = self.next; - let result = match src.format { - DmaBufFormat::Bgrx | DmaBufFormat::Rgbx => self.upload(Input::DmaBuf { + let result = match (src.format, planes) { + (DmaBufFormat::Bgrx | DmaBufFormat::Rgbx, _) => self.upload(Input::DmaBuf { image, width, height, bgr: src.format == DmaBufFormat::Bgrx, }), - DmaBufFormat::Nv12 | DmaBufFormat::P010 => self.copy_planes(image), + (_, Some(planes)) => self + .copy_split(planes, image) + .and_then(|()| self.copy_planes(image, false)), + (_, None) => self.copy_planes(image, true), }; if result.is_ok() { self.slots[k].import = Some(id); @@ -1127,7 +1154,77 @@ impl Encoder { } #[cfg(target_os = "linux")] - fn copy_planes(&mut self, image: vk::Image) -> Result<(), Error> { + fn copy_split(&mut self, planes: [vk::Image; 2], image: vk::Image) -> Result<(), Error> { + let gpu = self.vs.gpu.clone(); + let d = gpu.device(); + let (w, h) = (self.input.0 as u32, self.input.1 as u32); + let slot = &self.slots[self.next]; + let cb = slot.upload.cb; + let family = slot.upload.family; + let none = vk::QUEUE_FAMILY_IGNORED; + slot.upload.begin()?; + acquire(d, cb, planes[0], &[COLOR], family); + acquire(d, cb, planes[1], &[COLOR], family); + transfer( + d, + cb, + image, + ( + vk::ImageLayout::UNDEFINED, + vk::PipelineStageFlags2::NONE, + vk::AccessFlags2::NONE, + none, + ), + ( + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + vk::PipelineStageFlags2::COPY, + vk::AccessFlags2::TRANSFER_WRITE, + none, + ), + ); + unsafe { + d.cmd_copy_image( + cb, + planes[0], + vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + image, + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + &[split_copy(PLANE_0, (w, h))], + ); + d.cmd_copy_image( + cb, + planes[1], + vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + image, + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + &[split_copy(PLANE_1, (w / 2, h / 2))], + ); + } + transfer( + d, + cb, + image, + ( + vk::ImageLayout::TRANSFER_DST_OPTIMAL, + vk::PipelineStageFlags2::COPY, + vk::AccessFlags2::TRANSFER_WRITE, + none, + ), + ( + vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + vk::PipelineStageFlags2::COPY, + vk::AccessFlags2::TRANSFER_READ, + none, + ), + ); + release(d, cb, planes[0], &[COLOR]); + release(d, cb, planes[1], &[COLOR]); + slot.upload.end()?; + slot.upload.submit() + } + + #[cfg(target_os = "linux")] + fn copy_planes(&mut self, image: vk::Image, foreign: bool) -> Result<(), Error> { let gpu = self.vs.gpu.clone(); let d = gpu.device(); let k = self.next; @@ -1141,7 +1238,9 @@ impl Encoder { plane_copy(PLANE_1, (0, 0), (w / 2, h / 2)), ]; slot.upload.begin()?; - acquire(d, cb, image, &aspects, slot.upload.family); + if foreign { + acquire(d, cb, image, &aspects, slot.upload.family); + } unsafe { barrier( d,