oximedia_gpu/backend/
mod.rs1pub mod cpu;
4pub mod vulkan;
5
6pub use cpu::CpuBackend;
7pub use vulkan::VulkanBackend;
8
9use crate::Result;
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13pub enum BackendType {
14 Vulkan,
16 Metal,
18 DX12,
20 CPU,
22}
23
24impl BackendType {
25 #[must_use]
27 pub fn name(self) -> &'static str {
28 match self {
29 Self::Vulkan => "Vulkan",
30 Self::Metal => "Metal",
31 Self::DX12 => "DirectX 12",
32 Self::CPU => "CPU SIMD",
33 }
34 }
35
36 #[must_use]
38 pub fn is_gpu(self) -> bool {
39 !matches!(self, Self::CPU)
40 }
41}
42
43#[derive(Debug, Clone)]
45pub struct BackendCapabilities {
46 pub backend_type: BackendType,
48 pub max_workgroup_size: (u32, u32, u32),
50 pub max_workgroup_invocations: u32,
52 pub max_buffer_size: u64,
54 pub compute_shaders: bool,
56 pub subgroups: bool,
58 pub push_constants: bool,
60}
61
62impl Default for BackendCapabilities {
63 fn default() -> Self {
64 Self {
65 backend_type: BackendType::Vulkan,
66 max_workgroup_size: (256, 256, 64),
67 max_workgroup_invocations: 256,
68 max_buffer_size: 1024 * 1024 * 1024, compute_shaders: true,
70 subgroups: false,
71 push_constants: false,
72 }
73 }
74}
75
76pub trait Backend {
78 fn capabilities(&self) -> &BackendCapabilities;
80
81 fn backend_type(&self) -> BackendType {
83 self.capabilities().backend_type
84 }
85
86 fn is_available() -> bool
88 where
89 Self: Sized;
90
91 fn initialize() -> Result<Self>
93 where
94 Self: Sized;
95}