mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Make initialize_adapter_from_env take a compatible surface (#3905)
* Make initialize_adapter_from_env take a compatible surface 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. --------- Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
parent
a885840a49
commit
89f721f882
@ -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
|
||||
|
||||
|
@ -37,7 +37,10 @@ pub fn power_preference_from_env() -> Option<PowerPreference> {
|
||||
|
||||
/// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn initialize_adapter_from_env(instance: &Instance) -> Option<Adapter> {
|
||||
pub fn initialize_adapter_from_env(
|
||||
instance: &Instance,
|
||||
compatible_surface: Option<&Surface>,
|
||||
) -> Option<Adapter> {
|
||||
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<Adapter> {
|
||||
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<Adapter> {
|
||||
|
||||
/// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn initialize_adapter_from_env(_instance: &Instance) -> Option<Adapter> {
|
||||
pub fn initialize_adapter_from_env(
|
||||
_instance: &Instance,
|
||||
_compatible_surface: Option<&Surface>,
|
||||
) -> Option<Adapter> {
|
||||
None
|
||||
}
|
||||
|
||||
@ -69,7 +81,7 @@ pub async fn initialize_adapter_from_env_or_default(
|
||||
instance: &Instance,
|
||||
compatible_surface: Option<&Surface>,
|
||||
) -> Option<Adapter> {
|
||||
match initialize_adapter_from_env(instance) {
|
||||
match initialize_adapter_from_env(instance, compatible_surface) {
|
||||
Some(a) => Some(a),
|
||||
None => {
|
||||
instance
|
||||
|
Loading…
Reference in New Issue
Block a user