use {
core::fmt::{self, Debug},
gpu_alloc_types::{MemoryPropertyFlags, MemoryType},
};
bitflags::bitflags! { /// Memory usage type. /// Bits set define intended usage for requested memory. #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pubstruct UsageFlags: u8 { /// Hints for allocator to find memory with faster device access. /// If no flags is specified than `FAST_DEVICE_ACCESS` is implied. const FAST_DEVICE_ACCESS = 0x01;
/// Memory will be accessed from host. /// This flags guarantees that host memory operations will be available. /// Otherwise implementation is encouraged to use non-host-accessible memory. const HOST_ACCESS = 0x02;
/// Hints allocator that memory will be used for data downloading. /// Allocator will strongly prefer host-cached memory. /// Implies `HOST_ACCESS` flag. const DOWNLOAD = 0x04;
/// Hints allocator that memory will be used for data uploading. /// If `DOWNLOAD` flag is not set then allocator will assume that /// host will access memory in write-only manner and may /// pick not host-cached. /// Implies `HOST_ACCESS` flag. const UPLOAD = 0x08;
/// Hints allocator that memory will be used for short duration /// allowing to use faster algorithm with less memory overhead. /// If use holds returned memory block for too long then /// effective memory overhead increases instead. /// Best use case is for staging buffer for single batch of operations. const TRANSIENT = 0x10;
/// Requests memory that can be addressed with `u64`. /// Allows fetching device address for resources bound to that memory. const DEVICE_ADDRESS = 0x20;
}
}
for usage in0..64 {
mfu.usages[usage as usize] =
one_usage(UsageFlags::from_bits_truncate(usage), memory_types);
}
mfu
}
/// Returns mask with bits set for memory type indices that support the /// usage. pubfn mask(&self, usage: UsageFlags) -> u32 { self.usages[usage.bits() as usize].mask
}
/// Returns slice of memory type indices that support the usage. /// Earlier memory type has priority over later. pubfn types(&self, usage: UsageFlags) -> &[u32] { let usage = &self.usages[usage.bits() as usize];
&usage.types[..usage.types_count as usize]
}
}
for (index, mt) in memory_types.iter().enumerate() { if compatible(usage, mt.props) {
types[types_count as usize] = index as u32;
types_count += 1;
}
}
types[..types_count as usize]
.sort_unstable_by_key(|&index| reverse_priority(usage, memory_types[index as usize].props));
let mask = types[..types_count as usize]
.iter()
.fold(0u32, |mask, index| mask | 1u32 << index);
/// Returns reversed priority of memory with specified flags for specified usage. /// Lesser value returned = more prioritized. fn reverse_priority(usage: UsageFlags, flags: MemoryPropertyFlags) -> u32 { type Flags = MemoryPropertyFlags;
// Highly prefer device local memory when `FAST_DEVICE_ACCESS` usage is specified // or usage is empty. let device_local: bool = flags.contains(Flags::DEVICE_LOCAL)
^ (usage.is_empty() || usage.contains(UsageFlags::FAST_DEVICE_ACCESS));
// Prefer non-host-visible memory when host access is not required. let host_visible: bool = flags.contains(Flags::HOST_VISIBLE)
^ usage.intersects(UsageFlags::HOST_ACCESS | UsageFlags::UPLOAD | UsageFlags::DOWNLOAD);
// Prefer cached memory for downloads. // Or non-cached if downloads are not expected. let host_cached: bool =
flags.contains(Flags::HOST_CACHED) ^ usage.contains(UsageFlags::DOWNLOAD);
// Prefer coherent for both uploads and downloads. // Prefer non-coherent if neither flags is set. let host_coherent: bool = flags.contains(Flags::HOST_COHERENT)
^ (usage.intersects(UsageFlags::UPLOAD | UsageFlags::DOWNLOAD));
// Each boolean is false if flags are preferred.
device_local as u32 * 8
+ host_visible as u32 * 4
+ host_cached as u32 * 2
+ host_coherent as u32
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.