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
use log::warn;
use std::env::var;
pub use wgpu::{BackendBit, PowerPreference};
#[derive(Clone, PartialEq, Hash)]
pub struct Options {
pub power_preference: PowerPreference,
pub backends: BackendBit,
}
impl Default for Options {
fn default() -> Self {
Options {
power_preference: PowerPreference::LowPower,
backends: BackendBit::PRIMARY,
}
}
}
impl Options {
pub fn from_env() -> Self {
let mut options = Options::default();
if let Ok(mut v) = var("KAS_POWER_PREFERENCE") {
v.make_ascii_uppercase();
options.power_preference = match v.as_str() {
"DEFAULT" => PowerPreference::Default,
"LOWPOWER" => PowerPreference::LowPower,
"HIGHPERFORMANCE" => PowerPreference::HighPerformance,
other => {
warn!(
"Unexpected environment value: KAS_POWER_PREFERENCE={}",
other
);
options.power_preference
}
}
}
if let Ok(mut v) = var("KAS_BACKENDS") {
v.make_ascii_uppercase();
options.backends = match v.as_str() {
"VULKAN" => BackendBit::VULKAN,
"GL" => BackendBit::GL,
"METAL" => BackendBit::METAL,
"DX11" => BackendBit::DX11,
"DX12" => BackendBit::DX12,
"PRIMARY" => BackendBit::PRIMARY,
"SECONDARY" => BackendBit::SECONDARY,
other => {
warn!("Unexpected environment value: KAS_BACKENDS={}", other);
options.backends
}
}
}
options
}
pub(crate) fn adapter_options(&self) -> wgpu::RequestAdapterOptions {
wgpu::RequestAdapterOptions {
power_preference: self.power_preference,
compatible_surface: None,
}
}
pub(crate) fn backend(&self) -> BackendBit {
self.backends
}
}