concinnity_core/platform.rs
1//! The shader `Platform` vocabulary: which compiled shader form a rendering
2//! backend consumes. The enum is pure data with no ambient resolution of its
3//! own, so it sits in the runtime foundation and every caller states the
4//! platform it means -- the engine names the backend it was built for, and the
5//! build pipeline is told the backend it cooks for.
6
7/// The shader targets the engine compiles for. Each variant matches one render
8/// backend: Metal (MSL), DirectX (DXIL), or Vulkan (SPIR-V).
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
10pub enum Platform {
11 /// The Metal backend.
12 Metal,
13 /// The DirectX backend.
14 Hlsl,
15 /// The Vulkan backend.
16 Glsl,
17}
18
19impl Platform {
20 /// The short name a cook cache key and an export stamp record the backend under.
21 pub fn key(self) -> &'static str {
22 match self {
23 Platform::Metal => "metal",
24 Platform::Hlsl => "hlsl",
25 Platform::Glsl => "glsl",
26 }
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use super::*;
33
34 #[test]
35 fn every_platform_has_a_distinct_key() {
36 assert_eq!(Platform::Metal.key(), "metal");
37 assert_eq!(Platform::Hlsl.key(), "hlsl");
38 assert_eq!(Platform::Glsl.key(), "glsl");
39 }
40}