824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 1 | use crate::Error; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 2 | use crate::device::Shared; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 3 | use crate::format::{components, vk_format}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 4 | use ash::vk; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 5 | use gpu_allocator::MemoryLocation; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 6 | use gpu_allocator::vulkan::{Allocation, AllocationCreateDesc, AllocationScheme}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 7 | use smithay::backend::allocator::Fourcc; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 8 | use smithay::backend::renderer::{Texture, TextureMapping}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 9 | use std::fmt; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 10 | use std::sync::{Arc, Mutex}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 11 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 12 | pub(crate) struct ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 13 | pub shared: Arc<Shared>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 14 | pub image: vk::Image, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 15 | pub view: vk::ImageView, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 16 | pub allocation: Mutex<Option<Allocation>>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 17 | pub fourcc: Fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 18 | pub format: vk::Format, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 19 | pub width: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 20 | pub height: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 21 | pub layout: Mutex<vk::ImageLayout>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 22 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 23 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 24 | impl fmt::Debug for ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 25 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 26 | f.debug_struct("ImageInner") |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 27 | .field("image", &self.image) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 28 | .field("fourcc", &self.fourcc) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 29 | .field("size", &(self.width, self.height)) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 30 | .finish() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 31 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 32 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 33 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 34 | impl Drop for ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 35 | fn drop(&mut self) { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 36 | let d = &self.shared.device.device; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 37 | unsafe { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 38 | d.destroy_image_view(self.view, None); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 39 | d.destroy_image(self.image, None); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 40 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 41 | if let Some(a) = self |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 42 | .allocation |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 43 | .lock() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 44 | .unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 45 | .take() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 46 | { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 47 | let _ = self |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 48 | .shared |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 49 | .allocator |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 50 | .lock() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 51 | .unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 52 | .free(a); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 53 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 54 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 55 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 56 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 57 | impl ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 58 | pub fn create( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 59 | shared: &Arc<Shared>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 60 | fourcc: Fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 61 | width: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 62 | height: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 63 | usage: vk::ImageUsageFlags, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 64 | ) -> Result<Arc<Self>, Error> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 65 | let fmt = vk_format(fourcc).ok_or(Error::UnsupportedFormat(fourcc))?; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 66 | if width == 0 || height == 0 { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 67 | return Err(Error::InvalidSize(width as i32, height as i32)); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 68 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 69 | let d = &shared.device.device; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 70 | let info = vk::ImageCreateInfo::default() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 71 | .image_type(vk::ImageType::TYPE_2D) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 72 | .format(fmt.format) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 73 | .extent(vk::Extent3D { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 74 | width, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 75 | height, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 76 | depth: 1, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 77 | }) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 78 | .mip_levels(1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 79 | .array_layers(1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 80 | .samples(vk::SampleCountFlags::TYPE_1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 81 | .tiling(vk::ImageTiling::OPTIMAL) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 82 | .usage(usage) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 83 | .initial_layout(vk::ImageLayout::UNDEFINED); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 84 | let image = unsafe { d.create_image(&info, None)? }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 85 | let requirements = unsafe { d.get_image_memory_requirements(image) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 86 | let allocation = shared |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 87 | .allocator |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 88 | .lock() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 89 | .unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 90 | .allocate(&AllocationCreateDesc { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 91 | name: "image", |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 92 | requirements, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 93 | location: MemoryLocation::GpuOnly, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 94 | linear: false, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 95 | allocation_scheme: AllocationScheme::GpuAllocatorManaged, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 96 | }); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 97 | let allocation = match allocation { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 98 | Ok(a) => a, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 99 | Err(e) => { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 100 | unsafe { d.destroy_image(image, None) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 101 | return Err(e.into()); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 102 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 103 | }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 104 | unsafe { d.bind_image_memory(image, allocation.memory(), allocation.offset())? }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 105 | let view_info = vk::ImageViewCreateInfo::default() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 106 | .image(image) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 107 | .view_type(vk::ImageViewType::TYPE_2D) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 108 | .format(fmt.format) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 109 | .components(components(fmt.opaque)) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 110 | .subresource_range(color_range()); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 111 | let view = unsafe { d.create_image_view(&view_info, None)? }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 112 | Ok(Arc::new(Self { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 113 | shared: shared.clone(), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 114 | image, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 115 | view, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 116 | allocation: Mutex::new(Some(allocation)), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 117 | fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 118 | format: fmt.format, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 119 | width, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 120 | height, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 121 | layout: Mutex::new(vk::ImageLayout::UNDEFINED), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 122 | })) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 123 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 124 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 125 | pub fn layout(&self) -> vk::ImageLayout { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 126 | *self.layout.lock().unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 127 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 128 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 129 | pub fn set_layout(&self, layout: vk::ImageLayout) { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 130 | *self.layout.lock().unwrap_or_else(|e| e.into_inner()) = layout; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 131 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 132 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 133 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 134 | pub(crate) fn color_range() -> vk::ImageSubresourceRange { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 135 | vk::ImageSubresourceRange::default() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 136 | .aspect_mask(vk::ImageAspectFlags::COLOR) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 137 | .level_count(1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 138 | .layer_count(1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 139 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 140 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 141 | /// A host-visible buffer for uploads and readbacks. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 142 | pub(crate) struct Staging { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 143 | pub shared: Arc<Shared>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 144 | pub buffer: vk::Buffer, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 145 | pub allocation: Option<Allocation>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 146 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 147 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 148 | impl Staging { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 149 | pub fn new( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 150 | shared: &Arc<Shared>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 151 | size: usize, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 152 | usage: vk::BufferUsageFlags, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 153 | location: MemoryLocation, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 154 | ) -> Result<Self, Error> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 155 | let d = &shared.device.device; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 156 | let buffer = unsafe { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 157 | d.create_buffer( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 158 | &vk::BufferCreateInfo::default() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 159 | .size(size as u64) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 160 | .usage(usage), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 161 | None, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 162 | )? |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 163 | }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 164 | let requirements = unsafe { d.get_buffer_memory_requirements(buffer) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 165 | let allocation = shared |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 166 | .allocator |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 167 | .lock() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 168 | .unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 169 | .allocate(&AllocationCreateDesc { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 170 | name: "staging", |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 171 | requirements, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 172 | location, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 173 | linear: true, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 174 | allocation_scheme: AllocationScheme::GpuAllocatorManaged, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 175 | }); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 176 | let allocation = match allocation { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 177 | Ok(a) => a, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 178 | Err(e) => { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 179 | unsafe { d.destroy_buffer(buffer, None) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 180 | return Err(e.into()); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 181 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 182 | }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 183 | unsafe { d.bind_buffer_memory(buffer, allocation.memory(), allocation.offset())? }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 184 | Ok(Self { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 185 | shared: shared.clone(), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 186 | buffer, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 187 | allocation: Some(allocation), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 188 | }) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 189 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 190 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 191 | pub fn bytes(&self) -> &[u8] { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 192 | self.allocation |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 193 | .as_ref() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 194 | .and_then(|a| a.mapped_slice()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 195 | .unwrap_or(&[]) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 196 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 197 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 198 | pub fn bytes_mut(&mut self) -> &mut [u8] { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 199 | self.allocation |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 200 | .as_mut() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 201 | .and_then(|a| a.mapped_slice_mut()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 202 | .unwrap_or(&mut []) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 203 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 204 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 205 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 206 | impl Drop for Staging { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 207 | fn drop(&mut self) { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 208 | unsafe { self.shared.device.device.destroy_buffer(self.buffer, None) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 209 | if let Some(a) = self.allocation.take() { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 210 | let _ = self |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 211 | .shared |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 212 | .allocator |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 213 | .lock() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 214 | .unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 215 | .free(a); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 216 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 217 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 218 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 219 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 220 | /// A sampled texture. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 221 | #[derive(Clone, Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 222 | pub struct VulkanTexture(pub(crate) Arc<ImageInner>); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 223 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 224 | /// An image the renderer can draw into, from [`smithay::backend::renderer::Offscreen`]. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 225 | #[derive(Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 226 | pub struct VulkanImage(pub(crate) Arc<ImageInner>); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 227 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 228 | impl VulkanImage { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 229 | /// The image's contents as a texture, for drawing it elsewhere. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 230 | pub fn texture(&self) -> VulkanTexture { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 231 | VulkanTexture(self.0.clone()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 232 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 233 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 234 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 235 | /// A bound render target. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 236 | #[derive(Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 237 | pub struct VulkanTarget<'a>(pub(crate) &'a mut VulkanImage); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 238 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 239 | /// Pixels read back from the GPU. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 240 | #[derive(Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 241 | pub struct VulkanMapping { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 242 | pub(crate) data: Vec<u8>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 243 | pub(crate) width: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 244 | pub(crate) height: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 245 | pub(crate) fourcc: Fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 246 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 247 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 248 | macro_rules! texture_impl { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 249 | ($t:ty, |$s:ident| $inner:expr) => { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 250 | impl Texture for $t { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 251 | fn width(&self) -> u32 { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 252 | let $s = self; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 253 | $inner.width |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 254 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 255 | fn height(&self) -> u32 { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 256 | let $s = self; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 257 | $inner.height |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 258 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 259 | fn format(&self) -> Option<Fourcc> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 260 | let $s = self; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 261 | Some($inner.fourcc) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 262 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 263 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 264 | }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 265 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 266 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 267 | texture_impl!(VulkanTexture, |s| s.0); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 268 | texture_impl!(VulkanImage, |s| s.0); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 269 | texture_impl!(VulkanTarget<'_>, |s| s.0.0); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 270 | texture_impl!(VulkanMapping, |s| s); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 271 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 272 | impl TextureMapping for VulkanMapping { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 273 | fn flipped(&self) -> bool { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 274 | false |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 275 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 276 | } |