kronos_compute/api/
mod.rs1use crate::core::*;
8use crate::sys::*;
9use crate::ffi::VkResult;
10use crate::implementation;
11use thiserror::Error;
12
13pub mod context;
14pub mod buffer;
15pub mod pipeline;
16pub mod command;
17pub mod sync;
18
19#[cfg(test)]
20mod tests;
21
22pub use context::ComputeContext;
23pub use buffer::{Buffer, BufferUsage};
24pub use pipeline::{Pipeline, Shader, PipelineConfig, BufferBinding};
25pub use command::CommandBuilder;
26pub use sync::{Fence, Semaphore};
27
28pub type Result<T> = std::result::Result<T, KronosError>;
30
31#[derive(Error, Debug)]
33pub enum KronosError {
34 #[error("Initialization failed: {0}")]
35 InitializationFailed(String),
36
37 #[error("Device not found")]
38 DeviceNotFound,
39
40 #[error("Shader compilation failed: {0}")]
41 ShaderCompilationFailed(String),
42
43 #[error("Buffer creation failed: {0}")]
44 BufferCreationFailed(String),
45
46 #[error("Command execution failed: {0}")]
47 CommandExecutionFailed(String),
48
49 #[error("Synchronization error: {0}")]
50 SynchronizationError(String),
51
52 #[error("Vulkan error: {0:?}")]
53 VulkanError(VkResult),
54
55 #[error("Implementation error: {0}")]
56 ImplementationError(#[from] implementation::error::IcdError),
57}
58
59impl From<VkResult> for KronosError {
60 fn from(result: VkResult) -> Self {
61 KronosError::VulkanError(result)
62 }
63}
64
65#[derive(Default)]
67pub struct ContextConfig {
68 pub app_name: String,
70 pub enable_validation: bool,
72 pub preferred_vendor: Option<String>,
74}
75
76pub struct ContextBuilder {
78 config: ContextConfig,
79}
80
81impl ContextBuilder {
82 pub fn new() -> Self {
83 Self {
84 config: ContextConfig::default(),
85 }
86 }
87
88 pub fn app_name(mut self, name: impl Into<String>) -> Self {
89 self.config.app_name = name.into();
90 self
91 }
92
93 pub fn enable_validation(mut self) -> Self {
94 self.config.enable_validation = true;
95 self
96 }
97
98 pub fn prefer_vendor(mut self, vendor: impl Into<String>) -> Self {
99 self.config.preferred_vendor = Some(vendor.into());
100 self
101 }
102
103 pub fn build(self) -> Result<ComputeContext> {
104 ComputeContext::new_with_config(self.config)
105 }
106}
107
108impl ComputeContext {
120 pub fn new() -> Result<Self> {
122 Self::builder().build()
123 }
124
125 pub fn builder() -> ContextBuilder {
127 ContextBuilder::new()
128 }
129}