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; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 10 | use std::marker::PhantomData; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 11 | use std::sync::{Arc, Mutex}; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 12 | |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 13 | pub(crate) enum Memory { |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 14 | Allocated(Allocation), |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 15 | /// Memory imported from a dmabuf, owned directly. |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 16 | Imported(vk::DeviceMemory), |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 17 | } |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 18 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 19 | pub(crate) struct ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 20 | pub shared: Arc<Shared>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 21 | pub image: vk::Image, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 22 | pub view: vk::ImageView, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 23 | pub memory: Mutex<Option<Memory>>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 24 | pub fourcc: Fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 25 | pub format: vk::Format, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 26 | pub width: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 27 | pub height: u32, |
f0e45b059808 | atagen | 2026-10-19 07:34 UTC | 28 | pub usage: vk::ImageUsageFlags, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 29 | pub layout: Mutex<vk::ImageLayout>, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 30 | /// Shared with other devices or processes through a dmabuf. Every use |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 31 | /// acquires the image from the foreign queue family and releases it after. |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 32 | pub external: bool, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 33 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 34 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 35 | impl fmt::Debug for ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 36 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 37 | f.debug_struct("ImageInner") |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 38 | .field("image", &self.image) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 39 | .field("fourcc", &self.fourcc) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 40 | .field("size", &(self.width, self.height)) |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 41 | .field("external", &self.external) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 42 | .finish() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 43 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 44 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 45 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 46 | impl Drop for ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 47 | fn drop(&mut self) { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 48 | let d = &self.shared.device.device; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 49 | unsafe { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 50 | d.destroy_image_view(self.view, None); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 51 | d.destroy_image(self.image, None); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 52 | } |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 53 | match self.memory.lock().unwrap_or_else(|e| e.into_inner()).take() { |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 54 | Some(Memory::Allocated(a)) => { |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 55 | let _ = self |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 56 | .shared |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 57 | .allocator |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 58 | .lock() |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 59 | .unwrap_or_else(|e| e.into_inner()) |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 60 | .free(a); |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 61 | } |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 62 | Some(Memory::Imported(m)) => unsafe { d.free_memory(m, None) }, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 63 | None => {} |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 64 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 65 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 66 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 67 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 68 | impl ImageInner { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 69 | pub fn create( |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 70 | shared: &Arc<Shared>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 71 | fourcc: Fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 72 | width: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 73 | height: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 74 | usage: vk::ImageUsageFlags, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 75 | ) -> Result<Arc<Self>, Error> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 76 | let fmt = vk_format(fourcc).ok_or(Error::UnsupportedFormat(fourcc))?; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 77 | if width == 0 || height == 0 { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 78 | return Err(Error::InvalidSize(width as i32, height as i32)); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 79 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 80 | let d = &shared.device.device; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 81 | let info = vk::ImageCreateInfo::default() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 82 | .image_type(vk::ImageType::TYPE_2D) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 83 | .format(fmt.format) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 84 | .extent(vk::Extent3D { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 85 | width, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 86 | height, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 87 | depth: 1, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 88 | }) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 89 | .mip_levels(1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 90 | .array_layers(1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 91 | .samples(vk::SampleCountFlags::TYPE_1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 92 | .tiling(vk::ImageTiling::OPTIMAL) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 93 | .usage(usage) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 94 | .initial_layout(vk::ImageLayout::UNDEFINED); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 95 | let image = unsafe { d.create_image(&info, None)? }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 96 | let requirements = unsafe { d.get_image_memory_requirements(image) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 97 | let allocation = shared |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 98 | .allocator |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 99 | .lock() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 100 | .unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 101 | .allocate(&AllocationCreateDesc { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 102 | name: "image", |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 103 | requirements, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 104 | location: MemoryLocation::GpuOnly, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 105 | linear: false, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 106 | allocation_scheme: AllocationScheme::GpuAllocatorManaged, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 107 | }); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 108 | let allocation = match allocation { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 109 | Ok(a) => a, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 110 | Err(e) => { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 111 | unsafe { d.destroy_image(image, None) }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 112 | return Err(e.into()); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 113 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 114 | }; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 115 | let memory = Memory::Allocated(allocation); |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 116 | let (mem, offset) = match &memory { |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 117 | Memory::Allocated(a) => (unsafe { a.memory() }, a.offset()), |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 118 | Memory::Imported(m) => (*m, 0), |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 119 | }; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 120 | Self::finish( |
f0e45b059808 | atagen | 2026-10-19 07:34 UTC | 121 | shared, image, memory, mem, offset, fourcc, width, height, usage, false, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 122 | ) |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 123 | } |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 124 | |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 125 | /// Binds memory, creates the view and wraps everything up. Takes |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 126 | /// ownership of `image` and `memory`, releasing both on failure. |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 127 | #[expect(clippy::too_many_arguments)] |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 128 | pub fn finish( |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 129 | shared: &Arc<Shared>, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 130 | image: vk::Image, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 131 | memory: Memory, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 132 | mem: vk::DeviceMemory, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 133 | offset: u64, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 134 | fourcc: Fourcc, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 135 | width: u32, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 136 | height: u32, |
f0e45b059808 | atagen | 2026-10-19 07:34 UTC | 137 | usage: vk::ImageUsageFlags, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 138 | external: bool, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 139 | ) -> Result<Arc<Self>, Error> { |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 140 | let fmt = vk_format(fourcc).ok_or(Error::UnsupportedFormat(fourcc))?; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 141 | let d = &shared.device.device; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 142 | let mut inner = Self { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 143 | shared: shared.clone(), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 144 | image, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 145 | view: vk::ImageView::null(), |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 146 | memory: Mutex::new(Some(memory)), |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 147 | fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 148 | format: fmt.format, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 149 | width, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 150 | height, |
f0e45b059808 | atagen | 2026-10-19 07:34 UTC | 151 | usage, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 152 | layout: Mutex::new(if external { |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 153 | vk::ImageLayout::GENERAL |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 154 | } else { |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 155 | vk::ImageLayout::UNDEFINED |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 156 | }), |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 157 | external, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 158 | }; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 159 | unsafe { d.bind_image_memory(image, mem, offset)? }; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 160 | let view_info = vk::ImageViewCreateInfo::default() |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 161 | .image(image) |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 162 | .view_type(vk::ImageViewType::TYPE_2D) |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 163 | .format(fmt.format) |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 164 | .components(components(fmt.opaque)) |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 165 | .subresource_range(color_range()); |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 166 | inner.view = unsafe { d.create_image_view(&view_info, None)? }; |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 167 | Ok(Arc::new(inner)) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 168 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 169 | |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 170 | /// Whether sampling the image always gives alpha one. |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 171 | pub fn opaque(&self) -> bool { |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 172 | vk_format(self.fourcc).is_some_and(|f| f.opaque) |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 173 | } |
c0caa658decf | atagen | 2026-10-19 07:37 UTC | 174 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 175 | pub fn layout(&self) -> vk::ImageLayout { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 176 | *self.layout.lock().unwrap_or_else(|e| e.into_inner()) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 177 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 178 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 179 | pub fn set_layout(&self, layout: vk::ImageLayout) { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 180 | *self.layout.lock().unwrap_or_else(|e| e.into_inner()) = layout; |
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 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 184 | pub(crate) fn color_range() -> vk::ImageSubresourceRange { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 185 | vk::ImageSubresourceRange::default() |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 186 | .aspect_mask(vk::ImageAspectFlags::COLOR) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 187 | .level_count(1) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 188 | .layer_count(1) |
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 | /// A sampled texture. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 192 | #[derive(Clone, Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 193 | pub struct VulkanTexture(pub(crate) Arc<ImageInner>); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 194 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 195 | /// An image the renderer can draw into, from [`smithay::backend::renderer::Offscreen`]. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 196 | #[derive(Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 197 | pub struct VulkanImage(pub(crate) Arc<ImageInner>); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 198 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 199 | impl VulkanImage { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 200 | /// The image's contents as a texture, for drawing it elsewhere. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 201 | pub fn texture(&self) -> VulkanTexture { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 202 | VulkanTexture(self.0.clone()) |
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 | |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 206 | /// A bound render target, borrowing whatever it was bound from. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 207 | #[derive(Debug)] |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 208 | pub struct VulkanTarget<'a>( |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 209 | pub(crate) Arc<ImageInner>, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 210 | pub(crate) PhantomData<&'a mut ()>, |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 211 | ); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 212 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 213 | /// Pixels read back from the GPU. |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 214 | #[derive(Debug)] |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 215 | pub struct VulkanMapping { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 216 | pub(crate) data: Vec<u8>, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 217 | pub(crate) width: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 218 | pub(crate) height: u32, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 219 | pub(crate) fourcc: Fourcc, |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 220 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 221 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 222 | macro_rules! texture_impl { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 223 | ($t:ty, |$s:ident| $inner:expr) => { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 224 | impl Texture for $t { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 225 | fn width(&self) -> u32 { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 226 | let $s = self; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 227 | $inner.width |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 228 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 229 | fn height(&self) -> u32 { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 230 | let $s = self; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 231 | $inner.height |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 232 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 233 | fn format(&self) -> Option<Fourcc> { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 234 | let $s = self; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 235 | Some($inner.fourcc) |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 236 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 237 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 238 | }; |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 239 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 240 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 241 | texture_impl!(VulkanTexture, |s| s.0); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 242 | texture_impl!(VulkanImage, |s| s.0); |
7de49c2aa70b | atagen | 2026-10-16 09:27 UTC | 243 | texture_impl!(VulkanTarget<'_>, |s| s.0); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 244 | texture_impl!(VulkanMapping, |s| s); |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 245 | |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 246 | impl TextureMapping for VulkanMapping { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 247 | fn flipped(&self) -> bool { |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 248 | false |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 249 | } |
824bf02b6e55 | atagen | 2026-10-16 09:15 UTC | 250 | } |