diff --git a/CHANGELOG.md b/CHANGELOG.md index bf049ed786..ba85e6cf66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,8 @@ Bottom level categories: #### Misc Breaking Changes - Change `AdapterInfo::{device,vendor}` to be `u32` instead of `usize`. By @ameknite in [#3760](https://github.com/gfx-rs/wgpu/pull/3760) -- Remove the `backend_bits` parameter in `initialize_adapter_from_env` and `initialize_adapter_from_env_or_default` - use [InstanceDescriptor::backends](https://docs.rs/wgpu/latest/wgpu/struct.InstanceDescriptor.html#structfield.backends) instead. By @fornwall in [#3904](https://github.com/gfx-rs/wgpu/pull/3904) +- Remove the `backend_bits` parameter in `initialize_adapter_from_env` and `initialize_adapter_from_env_or_default` - use [InstanceDescriptor::backends](https://docs.rs/wgpu/latest/wgpu/struct.InstanceDescriptor.html#structfield.backends) instead. By @fornwall in [#3904](https://github.com/gfx-rs/wgpu/pull/3904) +- Add a `compatible_surface` parameter to `initialize_adapter_from_env` and use that to make `initialize_adapter_from_env_or_default` always respect its `compatible_surface` parameter. By @fornwall in [#3905](https://github.com/gfx-rs/wgpu/pull/3905) #### Vulkan diff --git a/wgpu/src/util/init.rs b/wgpu/src/util/init.rs index e47a08a304..9d186b685a 100644 --- a/wgpu/src/util/init.rs +++ b/wgpu/src/util/init.rs @@ -37,7 +37,10 @@ pub fn power_preference_from_env() -> Option { /// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable. #[cfg(not(target_arch = "wasm32"))] -pub fn initialize_adapter_from_env(instance: &Instance) -> Option { +pub fn initialize_adapter_from_env( + instance: &Instance, + compatible_surface: Option<&Surface>, +) -> Option { let desired_adapter_name = std::env::var("WGPU_ADAPTER_NAME") .as_deref() .map(str::to_lowercase) @@ -49,6 +52,12 @@ pub fn initialize_adapter_from_env(instance: &Instance) -> Option { for adapter in adapters { let info = adapter.get_info(); + if let Some(surface) = compatible_surface { + if !adapter.is_surface_supported(surface) { + continue; + } + } + if info.name.to_lowercase().contains(&desired_adapter_name) { chosen_adapter = Some(adapter); break; @@ -60,7 +69,10 @@ pub fn initialize_adapter_from_env(instance: &Instance) -> Option { /// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable. #[cfg(target_arch = "wasm32")] -pub fn initialize_adapter_from_env(_instance: &Instance) -> Option { +pub fn initialize_adapter_from_env( + _instance: &Instance, + _compatible_surface: Option<&Surface>, +) -> Option { None } @@ -69,7 +81,7 @@ pub async fn initialize_adapter_from_env_or_default( instance: &Instance, compatible_surface: Option<&Surface>, ) -> Option { - match initialize_adapter_from_env(instance) { + match initialize_adapter_from_env(instance, compatible_surface) { Some(a) => Some(a), None => { instance