Add WGPU adapter selection using WGPU_ADAPTER

This commit is contained in:
Daniil Nemtsev 2021-08-13 12:39:44 +00:00
parent 5e7e560c10
commit a5ec81844f
2 changed files with 34 additions and 6 deletions

View File

@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add server setting with PvE/PvP switch - Add server setting with PvE/PvP switch
- Can now tilt glider while only wielding it - Can now tilt glider while only wielding it
- Experimental terrain persistence (see server documentation) - Experimental terrain persistence (see server documentation)
- Add GPU filtering using WGPU_ADAPTER environment variable
### Changed ### Changed

View File

@ -224,11 +224,38 @@ impl Renderer {
#[allow(unsafe_code)] #[allow(unsafe_code)]
let surface = unsafe { instance.create_surface(window) }; let surface = unsafe { instance.create_surface(window) };
let adapter = runtime let adapters = instance
.block_on(instance.request_adapter(&wgpu::RequestAdapterOptionsBase { .enumerate_adapters(backend_bit)
.enumerate()
.collect::<Vec<_>>();
for (i, adapter) in adapters.iter() {
let info = adapter.get_info();
info!(
?info.name,
?info.vendor,
?info.backend,
?info.device,
?info.device_type,
"graphics device #{}", i,
);
}
let adapter = match std::env::var("WGPU_ADAPTER").ok() {
Some(filter) if !filter.is_empty() => adapters.into_iter().find_map(|(i, adapter)| {
let info = adapter.get_info();
let full_name = format!("#{} {} {:?}", i, info.name, info.device_type,);
full_name.contains(&filter).then(|| adapter)
}),
Some(_) | None => {
runtime.block_on(instance.request_adapter(&wgpu::RequestAdapterOptionsBase {
power_preference: wgpu::PowerPreference::HighPerformance, power_preference: wgpu::PowerPreference::HighPerformance,
compatible_surface: Some(&surface), compatible_surface: Some(&surface),
})) }))
},
}
.ok_or(RenderError::CouldNotFindAdapter)?; .ok_or(RenderError::CouldNotFindAdapter)?;
let info = adapter.get_info(); let info = adapter.get_info();