Skip to content

Commit

Permalink
Allow controlling the graphics backend & power preference through sta…
Browse files Browse the repository at this point in the history
…ndard wgpu env vars (rerun-io#1332)

* Control wgpu backend via standard environment variable
* allow to configure gpu power preference through standard wgpu env var
  • Loading branch information
Wumpf authored Feb 16, 2023
1 parent afb9cae commit 6c2b291
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions crates/re_renderer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,20 @@ pub struct RenderContextConfig {
///
/// Other backend might work as well, but lack of support isn't regarded as a bug.
pub fn supported_backends() -> wgpu::Backends {
// Native - we primarily test Vulkan & Metal
// DX12 is added since as of writing some Windows VMs provide DX12 but no Vulkan drivers.
// We want to keep this list small in order to keep variance low!
// Native.
// Only use Vulkan & Metal unless explicitly told so since this reduces surfaces and thus surprises.
//
// Bunch of cases where it's still useful to switch though:
// * Some Windows VMs only provide DX12 drivers, observed with Parallels on Apple Silicon
// * May run into Linux issues that warrant trying out the GL backend.
//
// For changing the backend we use standard wgpu env var, i.e. WGPU_BACKEND.
#[cfg(not(target_arch = "wasm32"))]
{
wgpu::Backends::VULKAN | wgpu::Backends::DX12 | wgpu::Backends::METAL
wgpu::util::backend_bits_from_env()
.unwrap_or(wgpu::Backends::VULKAN | wgpu::Backends::METAL)
}
// Web - we support only WebGL right now!
// Web - we support only WebGL right now, WebGPU should work but hasn't been tested.
#[cfg(target_arch = "wasm32")]
{
wgpu::Backends::GL
Expand Down
2 changes: 2 additions & 0 deletions crates/re_viewer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ pub(crate) fn wgpu_options() -> egui_wgpu::WgpuConfiguration {
}),
backends: re_renderer::config::supported_backends(),
device_descriptor: crate::hardware_tier().device_descriptor(),
// TODO(andreas): This should be the default for egui-wgpu.
power_preference: wgpu::util::power_preference_from_env().unwrap_or(wgpu::PowerPreference::HighPerformance),
..Default::default()
}
}
Expand Down

0 comments on commit 6c2b291

Please sign in to comment.