use crate::error::{HiveGpuError, Result};
pub struct MetalShaderManager {
shader_source: String,
}
impl MetalShaderManager {
pub fn new() -> Self {
Self {
shader_source: Self::load_metal_shaders(),
}
}
pub fn get_shader_source(&self) -> &str {
&self.shader_source
}
fn load_metal_shaders() -> String {
include_str!("../shaders/metal_hnsw.metal").to_string()
}
pub fn validate_shader(&self) -> Result<()> {
if self.shader_source.is_empty() {
return Err(HiveGpuError::ShaderCompilationFailed(
"Empty shader source".to_string(),
));
}
let required_functions = [
"cosine_similarity",
"euclidean_distance",
"dot_product",
"hnsw_construction",
"hnsw_search",
];
for function in &required_functions {
if !self.shader_source.contains(function) {
return Err(HiveGpuError::ShaderCompilationFailed(format!(
"Missing required function: {}",
function
)));
}
}
Ok(())
}
}
impl Default for MetalShaderManager {
fn default() -> Self {
Self::new()
}
}