Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow controlling the graphics backend & power preference through standard wgpu env vars #1332

Merged
merged 3 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Member

@emilk emilk Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wgpu docs are quite lacking here in what WGPU_BACKEND expects, but reading the code it seems like it would be:

WGPU_BACKEND=gl,metal ?

Please add a comment here so that the next reader can just use the env-var instead of having to dig into the wgpu code!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. yes I'll sneak that in some future PR. Also I'll create a PR for our troubleshooting doc page.

For everyone stumbling in here. This makes us support:

WGPU_BACKEND with a comma separated list of the backends you want to use: vulkan, metal, dx12, dx11, or gl).

WGPU_POWER_PREF with the power preference to choose when a specific adapter name isn't specified - high or low

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[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