Skip to main content

vk/mem/
import.rs

1//! External accounting supplied at the unsafe native import boundary.
2use crate as vk;
3
4/// Resource-specific native dedication for an imported payload.
5/// The resource remains caller-owned; this record never destroys it.
6#[derive(Clone, Copy, Debug, PartialEq, Eq)]
7pub enum ImportResource {
8	Buffer(vk::Buffer),
9	Image(vk::Image),
10}
11
12/// Actual external backing extent and compatible types for one import.
13///
14/// Attach through [`super::AllocationChain::new_from_record_with_import`].
15/// This is Rust metadata, not a Vulkan ABI record or a support query.
16/// All bytes are charged to the selected heap even when Vulkan ignores the size.
17#[derive(Clone, Copy, Debug)]
18pub struct ImportMemoryInfo {
19	/// Exact backing size from native external properties or authoritative OS metadata.
20	pub allocation_size: u64,
21	/// Compatible native types for this exact device and payload; never inferred from PFNs.
22	pub memory_type_bits: u32,
23	/// Exact resource when dedication is required or pre-bind requirements cannot be queried.
24	/// Its requirements must fit the supplied extent and type mask. Binding remains explicit.
25	pub resource: Option<ImportResource>,
26}
27
28impl ImportMemoryInfo {
29	/// Describe explicit backing size/types without resource-specific dedication.
30	/// The unsafe import operation still requires authoritative payload/device metadata.
31	#[inline]
32	#[must_use]
33	pub fn new(allocation_size: u64, memory_type_bits: u32) -> Self {
34		Self {
35			allocation_size,
36			memory_type_bits,
37			resource: None,
38		}
39	}
40
41	/// Set [`allocation_size`](Self::allocation_size) and return the updated record.
42	#[inline]
43	#[must_use]
44	pub fn set_allocation_size(mut self, value: u64) -> Self {
45		self.allocation_size = value;
46		self
47	}
48
49	/// Set [`memory_type_bits`](Self::memory_type_bits) and return the updated record.
50	#[inline]
51	#[must_use]
52	pub fn set_memory_type_bits(mut self, value: u32) -> Self {
53		self.memory_type_bits = value;
54		self
55	}
56
57	/// Set [`resource`](Self::resource) and return the updated record.
58	#[inline]
59	#[must_use]
60	pub fn set_resource(mut self, value: Option<ImportResource>) -> Self {
61		self.resource = value;
62		self
63	}
64}