Skip to main content

gaia_assembler/backends/spirv/
mod.rs

1//! SPIR-V (Standard Portable Intermediate Representation - V) backend compiler
2
3use std::collections::HashMap;
4
5use crate::{config::GaiaConfig, program::GaiaModule, Backend, GeneratedFiles};
6use gaia_types::{
7    helpers::{AbiCompatible, ApiCompatible, Architecture, ArtifactType, CompilationTarget},
8    Result,
9};
10
11/// SPIR-V Backend implementation
12#[derive(Default)]
13pub struct SpirvBackend {}
14
15impl Backend for SpirvBackend {
16    fn name(&self) -> &'static str {
17        "SPIR-V"
18    }
19
20    fn primary_target(&self) -> CompilationTarget {
21        CompilationTarget { build: Architecture::Unknown, host: AbiCompatible::SPIRV, target: ApiCompatible::Unknown }
22    }
23
24    fn artifact_type(&self) -> ArtifactType {
25        ArtifactType::Binary
26    }
27
28    fn match_score(&self, target: &CompilationTarget) -> f32 {
29        if target.host == AbiCompatible::SPIRV {
30            return 95.0;
31        }
32        0.0
33    }
34
35    fn generate(&self, _program: &GaiaModule, config: &GaiaConfig) -> Result<GeneratedFiles> {
36        #[cfg(feature = "spirv-assembler")]
37        {
38            Ok(GeneratedFiles { artifact_type: ArtifactType::Binary, files: HashMap::new(), custom: None, diagnostics: vec![] })
39        }
40        #[cfg(not(feature = "spirv-assembler"))]
41        {
42            Err(gaia_types::GaiaError::custom_error("SPIR-V feature is not enabled"))
43        }
44    }
45}