1#![allow(clippy::too_many_arguments, clippy::type_complexity, clippy::needless_range_loop)]
13
14mod stats;
15pub use stats::TransferStats;
16
17#[cfg(backend_metal)]
18pub mod metal;
19#[cfg(backend_metal)]
20mod surface;
21pub mod vulkan;
22
23#[cfg(backend_metal)]
24pub use metal::{
25 Bindings, Buffer, BufferBinding, CommandList, Device, Draw, DrawPipeline, DrawTarget, Kernel, Library, Submitted,
26 Texture,
27};
28#[cfg(backend_metal)]
29pub use surface::{Drawable, Surface};
30#[cfg(backend_vulkan)]
31pub use vulkan::ExportedMemory;
32#[cfg(backend_vulkan)]
33pub use vulkan::{
34 Bindings, Buffer, BufferBinding, CommandList, Device, Draw, DrawPipeline, DrawTarget, Kernel, Library, Submitted,
35 Texture,
36};
37#[cfg(all(backend_vulkan, windows))]
38pub use vulkan::{Drawable, Surface};
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub enum Blend {
43 Opaque,
45 Over,
47 Add,
49}
50
51#[cfg(backend_metal)]
53pub const BACKEND: &str = "metal";
54#[cfg(backend_vulkan)]
55pub const BACKEND: &str = "vulkan";
56
57#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
58pub enum PixelFormat {
59 Rgba16Float,
61 Rgba8Unorm,
63 Bgra8Unorm,
65 R32Float,
67 R16Float,
69 Rgba32Float,
71 Depth32Float,
73}
74
75impl PixelFormat {
76 pub fn bytes_per_pixel(self) -> usize {
77 match self {
78 PixelFormat::Rgba16Float => 8,
79 PixelFormat::Rgba8Unorm | PixelFormat::Bgra8Unorm | PixelFormat::R32Float | PixelFormat::Depth32Float => 4,
80 PixelFormat::R16Float => 2,
81 PixelFormat::Rgba32Float => 16,
82 }
83 }
84}
85
86#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
87pub struct TextureDesc {
88 pub width: u32,
89 pub height: u32,
90 pub format: PixelFormat,
91 pub cpu_readable: bool,
94}
95
96#[derive(Debug, Clone, Copy, Default)]
98pub struct GpuTiming {
99 pub gpu_ms: f64,
100}
101
102#[derive(Debug, thiserror::Error)]
103pub enum GpuError {
104 #[error("no GPU device available")]
105 NoDevice,
106 #[error("shader compile failed: {0}")]
107 ShaderCompile(String),
108 #[error("kernel `{0}` not found")]
109 NoSuchKernel(String),
110 #[error("pipeline creation failed for `{0}`: {1}")]
111 Pipeline(String, String),
112 #[error("command buffer failed: {0}")]
113 Execution(String),
114}