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-23 16:19:44 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent 0893ac49a6
commit fad289804a
7 changed files with 39 additions and 18 deletions
Generated
+1
View File
@@ -2300,6 +2300,7 @@ dependencies = [
"tokio", "tokio",
"url", "url",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-futures",
"web-sys", "web-sys",
"wgpu-executor", "wgpu-executor",
"winit", "winit",
@@ -45,12 +45,18 @@ impl PreferencesDialogMessageHandler {
}) })
.widget_holder(), .widget_holder(),
]; ];
let vello_tooltip = "Use the experimental Vello renderer (your browser must support WebGPU)";
let use_vello = vec![ let use_vello = vec![
TextLabel::new("Renderer").min_width(60).italic(true).widget_holder(), TextLabel::new("Renderer").min_width(60).italic(true).widget_holder(),
TextLabel::new("Vello (Experimental)").table_align(true).widget_holder(), TextLabel::new("Vello (Experimental)")
.table_align(true)
.tooltip(vello_tooltip)
.disabled(!preferences.supports_wgpu())
.widget_holder(),
Separator::new(SeparatorType::Unrelated).widget_holder(), Separator::new(SeparatorType::Unrelated).widget_holder(),
CheckboxInput::new(preferences.use_vello) CheckboxInput::new(preferences.use_vello && preferences.supports_wgpu())
.tooltip("Use the experimental Vello renderer (your browser must support WebGPU)") .tooltip(vello_tooltip)
.disabled(!preferences.supports_wgpu())
.on_update(|checkbox_input: &CheckboxInput| PreferencesMessage::UseVello { use_vello: checkbox_input.checked }.into()) .on_update(|checkbox_input: &CheckboxInput| PreferencesMessage::UseVello { use_vello: checkbox_input.checked }.into())
.widget_holder(), .widget_holder(),
]; ];
@@ -642,6 +642,7 @@ impl MessageHandler<PortfolioMessage, PortfolioMessageData<'_>> for PortfolioMes
responses.add(FrontendMessage::UpdateOpenDocumentsList { open_documents }); responses.add(FrontendMessage::UpdateOpenDocumentsList { open_documents });
} }
PortfolioMessage::UpdateVelloPreference => { PortfolioMessage::UpdateVelloPreference => {
responses.add(NodeGraphMessage::RunDocumentGraph);
self.persistent_data.use_vello = preferences.use_vello; self.persistent_data.use_vello = preferences.use_vello;
} }
} }
@@ -14,9 +14,13 @@ impl PreferencesMessageHandler {
pub fn editor_preferences(&self) -> EditorPreferences { pub fn editor_preferences(&self) -> EditorPreferences {
EditorPreferences { EditorPreferences {
imaginate_hostname: self.imaginate_server_hostname.clone(), imaginate_hostname: self.imaginate_server_hostname.clone(),
use_vello: self.use_vello, use_vello: self.use_vello && self.supports_wgpu(),
} }
} }
pub fn supports_wgpu(&self) -> bool {
graph_craft::wasm_application_io::wgpu_available().unwrap_or_default()
}
} }
impl Default for PreferencesMessageHandler { impl Default for PreferencesMessageHandler {
+9 -11
View File
@@ -153,7 +153,15 @@ impl NodeRuntime {
} }
pub async fn run(&mut self) { pub async fn run(&mut self) {
// TODO: Currently we still render the document after we submit the node graph execution request. This should be avoided in the future. if self.editor_api.application_io.is_none() {
self.editor_api = WasmEditorApi {
application_io: Some(WasmApplicationIo::new().await.into()),
font_cache: self.editor_api.font_cache.clone(),
node_graph_message_sender: Box::new(self.sender.clone()),
editor_preferences: Box::new(self.editor_preferences.clone()),
}
.into();
}
let mut font = None; let mut font = None;
let mut preferences = None; let mut preferences = None;
@@ -232,16 +240,6 @@ impl NodeRuntime {
} }
async fn update_network(&mut self, graph: NodeNetwork) -> Result<(), String> { async fn update_network(&mut self, graph: NodeNetwork) -> Result<(), String> {
if self.editor_api.application_io.is_none() {
self.editor_api = WasmEditorApi {
application_io: Some(WasmApplicationIo::new().await.into()),
font_cache: self.editor_api.font_cache.clone(),
node_graph_message_sender: Box::new(self.sender.clone()),
editor_preferences: Box::new(self.editor_preferences.clone()),
}
.into();
}
let scoped_network = wrap_network_in_scope(graph, self.editor_api.clone()); let scoped_network = wrap_network_in_scope(graph, self.editor_api.clone());
self.monitor_nodes = scoped_network self.monitor_nodes = scoped_network
.recursive_nodes() .recursive_nodes()
+1
View File
@@ -43,6 +43,7 @@ tokio = { workspace = true, optional = true }
web-sys = { workspace = true } web-sys = { workspace = true }
js-sys = { workspace = true } js-sys = { workspace = true }
wasm-bindgen = { workspace = true } wasm-bindgen = { workspace = true }
wasm-bindgen-futures = { workspace = true }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# Workspace dependencies # Workspace dependencies
@@ -1,7 +1,6 @@
use dyn_any::StaticType; use dyn_any::StaticType;
use graphene_core::application_io::SurfaceHandleFrame; use graphene_core::application_io::SurfaceHandleFrame;
use graphene_core::application_io::{ApplicationError, ApplicationIo, ResourceFuture, SurfaceHandle, SurfaceId}; use graphene_core::application_io::{ApplicationError, ApplicationIo, ResourceFuture, SurfaceHandle, SurfaceId};
#[cfg(feature = "wgpu")]
use wgpu_executor::WgpuExecutor; use wgpu_executor::WgpuExecutor;
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
@@ -34,9 +33,19 @@ pub struct WasmApplicationIo {
pub resources: HashMap<String, Arc<[u8]>>, 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 { impl WasmApplicationIo {
pub async fn new() -> Self { 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 executor = if let Some(gpu) = web_sys::window().map(|w| w.navigator().gpu()) {
let request_adapter = || { let request_adapter = || {
let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).ok()?; let request_adapter = js_sys::Reflect::get(&gpu, &wasm_bindgen::JsValue::from_str("requestAdapter")).ok()?;
@@ -51,8 +60,9 @@ impl WasmApplicationIo {
} else { } else {
None None
}; };
#[cfg(all(feature = "wgpu", not(target_arch = "wasm32")))] #[cfg(not(target_arch = "wasm32"))]
let executor = WgpuExecutor::new().await; let executor = WgpuExecutor::new().await;
WGPU_AVAILABLE.store(executor.is_some() as i8, ::std::sync::atomic::Ordering::SeqCst);
let mut io = Self { let mut io = Self {
#[cfg(target_arch = "wasm32")] #[cfg(target_arch = "wasm32")]
ids: AtomicU64::new(0), ids: AtomicU64::new(0),