pub mod cpu;
pub mod vulkan;
pub use cpu::CpuBackend;
pub use vulkan::VulkanBackend;
use crate::Result;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum BackendType {
Vulkan,
Metal,
DX12,
CPU,
}
impl BackendType {
#[must_use]
pub fn name(self) -> &'static str {
match self {
Self::Vulkan => "Vulkan",
Self::Metal => "Metal",
Self::DX12 => "DirectX 12",
Self::CPU => "CPU SIMD",
}
}
#[must_use]
pub fn is_gpu(self) -> bool {
!matches!(self, Self::CPU)
}
}
#[derive(Debug, Clone)]
pub struct BackendCapabilities {
pub backend_type: BackendType,
pub max_workgroup_size: (u32, u32, u32),
pub max_workgroup_invocations: u32,
pub max_buffer_size: u64,
pub compute_shaders: bool,
pub subgroups: bool,
pub push_constants: bool,
}
impl Default for BackendCapabilities {
fn default() -> Self {
Self {
backend_type: BackendType::Vulkan,
max_workgroup_size: (256, 256, 64),
max_workgroup_invocations: 256,
max_buffer_size: 1024 * 1024 * 1024, compute_shaders: true,
subgroups: false,
push_constants: false,
}
}
}
pub trait Backend {
fn capabilities(&self) -> &BackendCapabilities;
fn backend_type(&self) -> BackendType {
self.capabilities().backend_type
}
fn is_available() -> bool
where
Self: Sized;
fn initialize() -> Result<Self>
where
Self: Sized;
}