Disable Vello renderer checkbox in preferences if browser doesn't support WebGPU (#1844)

* Disable vello checkbox if no wgpu support is available

* Fix compile error

* Check wgpu status on every diagogue open

* Execute graph on settings change

* Remove tooltip and disabled status from settings category

---------

Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
Dennis Kobert
2024-07-24 01:19:44 +02:00
committed by GitHub
parent 0893ac49a6
commit fad289804a
7 changed files with 39 additions and 18 deletions

View File

@@ -43,6 +43,7 @@ tokio = { workspace = true, optional = true }
web-sys = { workspace = true }
js-sys = { workspace = true }
wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# Workspace dependencies

View File

@@ -1,7 +1,6 @@
use dyn_any::StaticType;
use graphene_core::application_io::SurfaceHandleFrame;
use graphene_core::application_io::{ApplicationError, ApplicationIo, ResourceFuture, SurfaceHandle, SurfaceId};
#[cfg(feature = "wgpu")]
use wgpu_executor::WgpuExecutor;
#[cfg(target_arch = "wasm32")]
@@ -34,9 +33,19 @@ pub struct WasmApplicationIo {
pub resources: HashMap<String, Arc<[u8]>>,
}
static WGPU_AVAILABLE: std::sync::atomic::AtomicI8 = std::sync::atomic::AtomicI8::new(-1);
pub fn wgpu_available() -> Option<bool> {
match WGPU_AVAILABLE.load(::std::sync::atomic::Ordering::SeqCst) {
-1 => None,
0 => Some(false),
_ => Some(true),
}
}
impl WasmApplicationIo {
pub async fn new() -> Self {
#[cfg(all(feature = "wgpu", target_arch = "wasm32"))]
#[cfg(target_arch = "wasm32")]
let executor = if let Some(gpu) = web_sys::window().map(|w| w.navigator().gpu()) {
let request_adapter = || {
let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).ok()?;
@@ -51,8 +60,9 @@ impl WasmApplicationIo {
} else {
None
};
#[cfg(all(feature = "wgpu", not(target_arch = "wasm32")))]
#[cfg(not(target_arch = "wasm32"))]
let executor = WgpuExecutor::new().await;
WGPU_AVAILABLE.store(executor.is_some() as i8, ::std::sync::atomic::Ordering::SeqCst);
let mut io = Self {
#[cfg(target_arch = "wasm32")]
ids: AtomicU64::new(0),