1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use std::hash::Hash;
#[cfg(feature = "serde-support")]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxShaderPackageMetal {
Src(String),
#[cfg_attr(feature = "serde-support", serde(with = "serde_bytes"))]
LibBytes(Vec<u8>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub enum RafxShaderPackageVulkan {
#[cfg_attr(feature = "serde-support", serde(with = "serde_bytes"))]
SpvBytes(Vec<u8>),
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
#[doc(hidden)]
pub enum RafxShaderPackageEmpty {
Empty,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
#[cfg_attr(feature = "serde-support", derive(Serialize, Deserialize))]
pub struct RafxShaderPackage {
pub metal: Option<RafxShaderPackageMetal>,
pub vk: Option<RafxShaderPackageVulkan>,
}
impl RafxShaderPackage {
#[cfg(feature = "rafx-metal")]
pub fn metal_module_def(&self) -> Option<RafxShaderModuleDefMetal> {
if let Some(metal) = self.metal.as_ref() {
Some(match metal {
RafxShaderPackageMetal::Src(src) => RafxShaderModuleDefMetal::MetalSrc(src),
RafxShaderPackageMetal::LibBytes(lib) => {
RafxShaderModuleDefMetal::MetalLibBytes(lib)
}
})
} else {
None
}
}
#[cfg(feature = "rafx-vulkan")]
pub fn vulkan_module_def(&self) -> Option<RafxShaderModuleDefVulkan> {
if let Some(vk) = self.vk.as_ref() {
Some(match vk {
RafxShaderPackageVulkan::SpvBytes(bytes) => {
RafxShaderModuleDefVulkan::VkSpvBytes(bytes)
}
})
} else {
None
}
}
#[cfg(any(
feature = "rafx-empty",
not(any(feature = "rafx-metal", feature = "rafx-vulkan"))
))]
#[doc(hidden)]
pub fn empty_module_def(&self) -> Option<RafxShaderModuleDefEmpty> {
Some(RafxShaderModuleDefEmpty::Empty(Default::default()))
}
pub fn module_def(&self) -> RafxShaderModuleDef {
RafxShaderModuleDef {
#[cfg(feature = "rafx-metal")]
metal: self.metal_module_def(),
#[cfg(feature = "rafx-vulkan")]
vk: self.vulkan_module_def(),
#[cfg(any(
feature = "rafx-empty",
not(any(feature = "rafx-metal", feature = "rafx-vulkan"))
))]
#[doc(hidden)]
empty: self.empty_module_def(),
}
}
}
#[derive(Copy, Clone, Hash)]
#[cfg(feature = "rafx-metal")]
pub enum RafxShaderModuleDefMetal<'a> {
MetalSrc(&'a str),
MetalLibBytes(&'a [u8]),
}
#[derive(Copy, Clone, Hash)]
#[cfg(feature = "rafx-vulkan")]
pub enum RafxShaderModuleDefVulkan<'a> {
VkSpvBytes(&'a [u8]),
VkSpvPrepared(&'a [u32]),
}
#[cfg(any(
feature = "rafx-empty",
not(any(feature = "rafx-metal", feature = "rafx-vulkan"))
))]
#[derive(Copy, Clone, Hash)]
#[doc(hidden)]
pub enum RafxShaderModuleDefEmpty<'a> {
Empty(std::marker::PhantomData<&'a u32>),
}
#[derive(Copy, Clone, Hash)]
pub struct RafxShaderModuleDef<'a> {
#[cfg(feature = "rafx-metal")]
pub metal: Option<RafxShaderModuleDefMetal<'a>>,
#[cfg(feature = "rafx-vulkan")]
pub vk: Option<RafxShaderModuleDefVulkan<'a>>,
#[cfg(any(
feature = "rafx-empty",
not(any(feature = "rafx-metal", feature = "rafx-vulkan"))
))]
#[doc(hidden)]
pub empty: Option<RafxShaderModuleDefEmpty<'a>>,
}