Skip to content

Commit

Permalink
Prevent OpenGL from taking preference over Vulkan (#2853)
Browse files Browse the repository at this point in the history
* Prevent OpenGL from taking preference over Vulkan

* update changelog

* fix wasm build of example
  • Loading branch information
Craig-Macomber authored and cwfitzgerald committed Jul 14, 2022
1 parent 00df880 commit 2881c45
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Bottom level categories:
## Unreleased

### Bug Fixes
- Prefer `DeviceType::DiscreteGpu` over `DeviceType::Other` for `PowerPreference::LowPower` so Vulkan is preferred over OpenGL again by @Craig-Macomber in [#2853](https://github.com/gfx-rs/wgpu/pull/2853)

#### DX12
- `DownlevelCapabilities::default()` now returns the `ANISOTROPIC_FILTERING` flag set to true so DX12 lists `ANISOTROPIC_FILTERING` as true again by @cwfitzgerald in [#2851](https://github.com/gfx-rs/wgpu/pull/2851)
Expand Down Expand Up @@ -134,7 +135,7 @@ is an under-documented area that we hope to improve in the future.
```diff
- let future = buffer.slice(..).map_async(MapMode::Read);
+ buffer.slice(..).map_async(MapMode::Read, || {
+ // Called when buffer is mapped.
+ // Called when buffer is mapped.
+ })
```

Expand Down
6 changes: 5 additions & 1 deletion wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,11 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}

let preferred_gpu = match desc.power_preference {
PowerPreference::LowPower => integrated.or(other).or(discrete).or(virt).or(cpu),
// Since devices of type "Other" might really be "Unknown" and come from APIs like OpenGL that don't specify device type,
// Prefer more Specific types over Other.
// This means that backends which do provide accurate device types will be preferred
// if their device type indicates an actual hardware GPU (integrated or discrete).
PowerPreference::LowPower => integrated.or(discrete).or(other).or(virt).or(cpu),
PowerPreference::HighPerformance => discrete.or(integrated).or(other).or(virt).or(cpu),
};

Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/gles/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ impl super::Adapter {
} else if strings_that_imply_cpu.iter().any(|&s| renderer.contains(s)) {
wgt::DeviceType::Cpu
} else {
// At this point the Device type is Unknown.
// It's most likely DiscreteGpu, but we do not know for sure.
// Use "Other" to avoid possibly making incorrect assumptions.
// Note that if this same device is available under some other API (ex: Vulkan),
// It will mostly likely get a different device type (probably DiscreteGpu).
wgt::DeviceType::Other
};

Expand Down
2 changes: 1 addition & 1 deletion wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ pub enum ShaderModel {
#[cfg_attr(feature = "trace", derive(serde::Serialize))]
#[cfg_attr(feature = "replay", derive(serde::Deserialize))]
pub enum DeviceType {
/// Other.
/// Other or Unknown.
Other,
/// Integrated GPU with shared CPU/GPU memory.
IntegratedGpu,
Expand Down
8 changes: 6 additions & 2 deletions wgpu/examples/hello/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ cargo run --example hello
## Example output

```
# You might see different output as it depends on your graphics card
AdapterInfo { name: "Intel(R) UHD Graphics 630", vendor: 0, device: 0, device_type: IntegratedGpu, backend: Metal }
# You might see different output as it depends on your graphics card and drivers
Available adapters:
AdapterInfo { name: "AMD RADV VEGA10", vendor: 4098, device: 26751, device_type: DiscreteGpu, backend: Vulkan }
AdapterInfo { name: "llvmpipe (LLVM 12.0.0, 256 bits)", vendor: 65541, device: 0, device_type: Cpu, backend: Vulkan }
AdapterInfo { name: "Radeon RX Vega (VEGA10, DRM 3.41.0, 5.13.0-52-generic, LLVM 12.0.0)", vendor: 4098, device: 0, device_type: Other, backend: Gl }
Selected adapter: AdapterInfo { name: "AMD RADV VEGA10", vendor: 4098, device: 26751, device_type: DiscreteGpu, backend: Vulkan }
```
20 changes: 15 additions & 5 deletions wgpu/examples/hello/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
/// This example shows how to describe the adapter in use.
async fn run() {
#[cfg_attr(target_arch = "wasm32", allow(unused_variables))]
let adapter = wgpu::Instance::new(wgpu::Backends::all())
.request_adapter(&wgpu::RequestAdapterOptions::default())
.await
.unwrap();
let adapter = {
let instance = wgpu::Instance::new(wgpu::Backends::all());
#[cfg(not(target_arch = "wasm32"))]
{
println!("Available adapters:");
for a in instance.enumerate_adapters(wgpu::Backends::all()) {
println!(" {:?}", a.get_info())
}
}
instance
.request_adapter(&wgpu::RequestAdapterOptions::default())
.await
.unwrap()
};

#[cfg(not(target_arch = "wasm32"))]
println!("{:?}", adapter.get_info())
println!("Selected adapter: {:?}", adapter.get_info())
}

fn main() {
Expand Down

0 comments on commit 2881c45

Please sign in to comment.