hive_gpu/shaders/
metal_shaders.rs1use crate::error::{Result, HiveGpuError};
6
7pub struct MetalShaderManager {
9 shader_source: String,
11}
12
13impl MetalShaderManager {
14 pub fn new() -> Self {
16 Self {
17 shader_source: Self::load_metal_shaders(),
18 }
19 }
20
21 pub fn get_shader_source(&self) -> &str {
23 &self.shader_source
24 }
25
26 fn load_metal_shaders() -> String {
28 include_str!("../shaders/metal_hnsw.metal").to_string()
31 }
32
33 pub fn validate_shader(&self) -> Result<()> {
35 if self.shader_source.is_empty() {
36 return Err(HiveGpuError::ShaderCompilationFailed("Empty shader source".to_string()));
37 }
38
39 let required_functions = [
41 "cosine_similarity",
42 "euclidean_distance",
43 "dot_product",
44 "hnsw_construction",
45 "hnsw_search"
46 ];
47
48 for function in &required_functions {
49 if !self.shader_source.contains(function) {
50 return Err(HiveGpuError::ShaderCompilationFailed(
51 format!("Missing required function: {}", function)
52 ));
53 }
54 }
55
56 Ok(())
57 }
58}
59
60impl Default for MetalShaderManager {
61 fn default() -> Self {
62 Self::new()
63 }
64}