use crate::{
buffer, device, display, external_memory, format, image, memory,
queue::{QueueGroup, QueuePriority},
Backend, Features, PhysicalDeviceProperties,
};
use std::{any::Any, fmt};
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MemoryType {
pub properties: memory::Properties,
pub heap_index: usize,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MemoryHeap {
pub size: u64,
pub flags: memory::HeapFlags,
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct MemoryProperties {
pub memory_types: Vec<MemoryType>,
pub memory_heaps: Vec<MemoryHeap>,
}
#[derive(Debug)]
pub struct Gpu<B: Backend> {
pub device: B::Device,
pub queue_groups: Vec<QueueGroup<B>>,
}
pub trait PhysicalDevice<B: Backend>: fmt::Debug + Any + Send + Sync {
unsafe fn open(
&self,
families: &[(&B::QueueFamily, &[QueuePriority])],
requested_features: Features,
) -> Result<Gpu<B>, device::CreationError>;
fn format_properties(&self, format: Option<format::Format>) -> format::Properties;
fn image_format_properties(
&self,
format: format::Format,
dimensions: u8,
tiling: image::Tiling,
usage: image::Usage,
view_caps: image::ViewCapabilities,
) -> Option<image::FormatProperties>;
fn memory_properties(&self) -> MemoryProperties;
fn external_buffer_properties(
&self,
usage: buffer::Usage,
sparse: memory::SparseFlags,
memory_type: external_memory::ExternalMemoryType,
) -> external_memory::ExternalMemoryProperties;
fn external_image_properties(
&self,
format: format::Format,
dimensions: u8,
tiling: image::Tiling,
usage: image::Usage,
view_caps: image::ViewCapabilities,
external_memory_type: external_memory::ExternalMemoryType,
) -> Result<external_memory::ExternalMemoryProperties, external_memory::ExternalImagePropertiesError>;
fn features(&self) -> Features;
fn properties(&self) -> PhysicalDeviceProperties;
fn is_valid_cache(&self, _cache: &[u8]) -> bool {
false
}
unsafe fn enumerate_displays(&self) -> Vec<display::Display<B>>;
unsafe fn enumerate_compatible_planes(
&self,
display: &display::Display<B>,
) -> Vec<display::Plane>;
unsafe fn create_display_mode(
&self,
display: &display::Display<B>,
resolution: (u32, u32),
refresh_rate: u32,
) -> Result<display::DisplayMode<B>, display::DisplayModeError>;
unsafe fn create_display_plane<'a>(
&self,
display: &'a display::DisplayMode<B>,
plane: &'a display::Plane,
) -> Result<display::DisplayPlane<'a, B>, device::OutOfMemory>;
}
#[derive(Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum DeviceType {
Other = 0,
IntegratedGpu = 1,
DiscreteGpu = 2,
VirtualGpu = 3,
Cpu = 4,
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct AdapterInfo {
pub name: String,
pub vendor: usize,
pub device: usize,
pub device_type: DeviceType,
}
#[derive(Debug)]
pub struct Adapter<B: Backend> {
pub info: AdapterInfo,
pub physical_device: B::PhysicalDevice,
pub queue_families: Vec<B::QueueFamily>,
}