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
#[cfg(feature = "use-compiled-tools")]
pub mod compiled;
#[cfg(feature = "use-installed-tools")]
pub mod tool;
pub use spirv_tools_sys::opt::Passes;
#[derive(Default, Clone)]
pub struct Options {
pub validator_options: Option<crate::val::ValidatorOptions>,
pub max_id_bound: Option<u32>,
pub preserve_bindings: bool,
pub preserve_spec_constants: bool,
}
pub trait Optimizer {
fn with_env(target_env: crate::TargetEnv) -> Self;
fn optimize<MC: crate::error::MessageCallback>(
&self,
input: impl AsRef<[u32]>,
msg_callback: &mut MC,
options: Option<Options>,
) -> Result<crate::binary::Binary, crate::Error>;
fn register_pass(&mut self, pass: Passes) -> &mut Self;
fn register_performance_passes(&mut self) -> &mut Self;
fn register_size_passes(&mut self) -> &mut Self;
fn register_hlsl_legalization_passes(&mut self) -> &mut Self;
}
pub fn create(te: Option<crate::TargetEnv>) -> impl Optimizer {
let target_env = te.unwrap_or_default();
#[cfg(feature = "use-compiled-tools")]
{
compiled::CompiledOptimizer::with_env(target_env)
}
#[cfg(all(feature = "use-installed-tools", not(feature = "use-compiled-tools")))]
{
tool::ToolOptimizer::with_env(target_env)
}
}