de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 1 | use crate::image::{ImageInner, color_range}; |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 2 | use ash::vk; |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 3 | |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 4 | /// A full barrier between all earlier and later work on the image, optionally |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 5 | /// transferring ownership between queue families. Coarse, but correct for |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 6 | /// every transition the renderer makes. |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 7 | pub(crate) unsafe fn barrier( |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 8 | d: &ash::Device, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 9 | cmd: vk::CommandBuffer, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 10 | image: vk::Image, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 11 | old: vk::ImageLayout, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 12 | new: vk::ImageLayout, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 13 | src_family: u32, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 14 | dst_family: u32, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 15 | ) { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 16 | let b = [vk::ImageMemoryBarrier2::default() |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 17 | .src_stage_mask(vk::PipelineStageFlags2::ALL_COMMANDS) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 18 | .src_access_mask(vk::AccessFlags2::MEMORY_WRITE) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 19 | .dst_stage_mask(vk::PipelineStageFlags2::ALL_COMMANDS) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 20 | .dst_access_mask(vk::AccessFlags2::MEMORY_READ | vk::AccessFlags2::MEMORY_WRITE) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 21 | .old_layout(old) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 22 | .new_layout(new) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 23 | .src_queue_family_index(src_family) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 24 | .dst_queue_family_index(dst_family) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 25 | .image(image) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 26 | .subresource_range(color_range())]; |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 27 | unsafe { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 28 | d.cmd_pipeline_barrier2( |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 29 | cmd, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 30 | &vk::DependencyInfo::default().image_memory_barriers(&b), |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 31 | ) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 32 | }; |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 33 | } |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 34 | |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 35 | /// Moves an image into `layout` for use on this queue. Dmabuf images come |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 36 | /// from the foreign queue family in the general layout, others continue from |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 37 | /// their tracked layout. |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 38 | pub(crate) unsafe fn acquire( |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 39 | d: &ash::Device, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 40 | cmd: vk::CommandBuffer, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 41 | family: u32, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 42 | image: &ImageInner, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 43 | layout: vk::ImageLayout, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 44 | ) { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 45 | if image.external { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 46 | unsafe { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 47 | barrier( |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 48 | d, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 49 | cmd, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 50 | image.image, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 51 | vk::ImageLayout::GENERAL, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 52 | layout, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 53 | vk::QUEUE_FAMILY_FOREIGN_EXT, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 54 | family, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 55 | ) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 56 | }; |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 57 | } else { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 58 | let old = image.layout(); |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 59 | if old != layout { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 60 | unsafe { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 61 | barrier( |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 62 | d, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 63 | cmd, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 64 | image.image, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 65 | old, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 66 | layout, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 67 | vk::QUEUE_FAMILY_IGNORED, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 68 | vk::QUEUE_FAMILY_IGNORED, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 69 | ) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 70 | }; |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 71 | image.set_layout(layout); |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 72 | } |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 73 | } |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 74 | } |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 75 | |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 76 | /// Hands a dmabuf image back to the foreign queue family after use. |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 77 | pub(crate) unsafe fn release( |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 78 | d: &ash::Device, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 79 | cmd: vk::CommandBuffer, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 80 | family: u32, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 81 | image: &ImageInner, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 82 | layout: vk::ImageLayout, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 83 | ) { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 84 | if image.external { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 85 | unsafe { |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 86 | barrier( |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 87 | d, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 88 | cmd, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 89 | image.image, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 90 | layout, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 91 | vk::ImageLayout::GENERAL, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 92 | family, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 93 | vk::QUEUE_FAMILY_FOREIGN_EXT, |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 94 | ) |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 95 | }; |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 96 | } |
de1e9f21296c | atagen | 2026-10-17 04:49 UTC | 97 | } |