Skip to content

Commit

Permalink
Fix cases in which instance creation may not create any context (#5059)
Browse files Browse the repository at this point in the history
* Fix cases in which instance creation may not create any context

* split condition steps on picking webgpu instance

* comment formulation fix on backend availability

Co-authored-by: daxpedda <[email protected]>

---------

Co-authored-by: daxpedda <[email protected]>
  • Loading branch information
Wumpf and daxpedda authored Jan 15, 2024
1 parent c5a0b0b commit 1da093f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,7 @@ impl Instance {
///
/// Which feature makes this method return true depends on the target platform:
/// * MacOS/iOS: `metal`, `vulkan-portability` or `angle`
/// * Wasm32: `webgpu`, `webgl` or Emscripten target.
/// * All other: Always returns true
///
/// TODO: Right now it's otherwise not possible yet to opt-out of all features on most platforms.
Expand All @@ -1735,7 +1736,7 @@ impl Instance {
|| cfg!(feature = "angle")
// On the web, either WebGPU or WebGL must be enabled.
} else if cfg!(target_arch = "wasm32") {
cfg!(feature = "webgpu") || cfg!(feature = "webgl")
cfg!(feature = "webgpu") || cfg!(feature = "webgl") || cfg!(target_os = "emscripten")
} else {
true
}
Expand Down Expand Up @@ -1771,12 +1772,17 @@ impl Instance {
}

#[cfg(webgpu)]
if _instance_desc.backends.contains(Backends::BROWSER_WEBGPU)
&& crate::backend::get_browser_gpu_property().map_or(false, |gpu| !gpu.is_undefined())
{
return Self {
context: Arc::from(crate::backend::ContextWebGpu::init(_instance_desc)),
};
let is_only_available_backend = !cfg!(wgpu_core);
let requested_webgpu = _instance_desc.backends.contains(Backends::BROWSER_WEBGPU);
let support_webgpu =
crate::backend::get_browser_gpu_property().map_or(false, |gpu| !gpu.is_undefined());

if is_only_available_backend || (requested_webgpu && support_webgpu) {
return Self {
context: Arc::from(crate::backend::ContextWebGpu::init(_instance_desc)),
};
}
}

#[cfg(wgpu_core)]
Expand Down

0 comments on commit 1da093f

Please sign in to comment.