#![allow(clippy::too_many_arguments, clippy::type_complexity, clippy::needless_range_loop)]
mod stats;
pub use stats::TransferStats;
#[cfg(backend_metal)]
pub mod metal;
#[cfg(backend_metal)]
mod surface;
pub mod vulkan;
#[cfg(backend_metal)]
pub use metal::{
Bindings, Buffer, BufferBinding, CommandList, Device, Draw, DrawPipeline, DrawTarget, Kernel, Library, Submitted,
Texture,
};
#[cfg(backend_metal)]
pub use surface::{Drawable, Surface};
#[cfg(backend_vulkan)]
pub use vulkan::ExportedMemory;
#[cfg(backend_vulkan)]
pub use vulkan::{
Bindings, Buffer, BufferBinding, CommandList, Device, Draw, DrawPipeline, DrawTarget, Kernel, Library, Submitted,
Texture,
};
#[cfg(all(backend_vulkan, windows))]
pub use vulkan::{Drawable, Surface};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Blend {
Opaque,
Over,
Add,
}
#[cfg(backend_metal)]
pub const BACKEND: &str = "metal";
#[cfg(backend_vulkan)]
pub const BACKEND: &str = "vulkan";
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum PixelFormat {
Rgba16Float,
Rgba8Unorm,
Bgra8Unorm,
R32Float,
R16Float,
Rgba32Float,
Depth32Float,
}
impl PixelFormat {
pub fn bytes_per_pixel(self) -> usize {
match self {
PixelFormat::Rgba16Float => 8,
PixelFormat::Rgba8Unorm | PixelFormat::Bgra8Unorm | PixelFormat::R32Float | PixelFormat::Depth32Float => 4,
PixelFormat::R16Float => 2,
PixelFormat::Rgba32Float => 16,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct TextureDesc {
pub width: u32,
pub height: u32,
pub format: PixelFormat,
pub cpu_readable: bool,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct GpuTiming {
pub gpu_ms: f64,
}
#[derive(Debug, thiserror::Error)]
pub enum GpuError {
#[error("no GPU device available")]
NoDevice,
#[error("shader compile failed: {0}")]
ShaderCompile(String),
#[error("kernel `{0}` not found")]
NoSuchKernel(String),
#[error("pipeline creation failed for `{0}`: {1}")]
Pipeline(String, String),
#[error("command buffer failed: {0}")]
Execution(String),
}