diff --git a/Cargo.lock b/Cargo.lock index d1fd603e04..22cdd5e082 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1769,6 +1769,7 @@ dependencies = [ "test-case", "tokio", "wasm-bindgen", + "wgpu", "wgpu-executor", ] diff --git a/node-graph/graphene-cli/Cargo.toml b/node-graph/graphene-cli/Cargo.toml index 5f0f53a9c5..3e155b4aab 100644 --- a/node-graph/graphene-cli/Cargo.toml +++ b/node-graph/graphene-cli/Cargo.toml @@ -6,9 +6,15 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [features] -gpu = ["interpreted-executor/gpu", "graphene-std/gpu", "graphene-core/gpu", "wgpu-executor", "gpu-executor"] +gpu = [ + "interpreted-executor/gpu", + "graphene-std/gpu", + "graphene-core/gpu", + "wgpu-executor", + "gpu-executor", +] default = ["wgpu"] -wgpu = ["wgpu-executor", "gpu"] +wgpu = ["wgpu-executor", "gpu", "graphene-std/wgpu"] wayland = ["graphene-std/wayland"] @@ -39,6 +45,7 @@ futures = "0.3.28" fern = { version = "0.6.2", features = ["colored"] } chrono = "0.4.26" tokio = { version = "1.28.2", features = ["macros", "rt"] } +wgpu = "0.16.1" [dependencies.document-legacy] path = "../../document-legacy" diff --git a/node-graph/graphene-cli/src/main.rs b/node-graph/graphene-cli/src/main.rs index 723c6fd269..b00aabc9a7 100644 --- a/node-graph/graphene-cli/src/main.rs +++ b/node-graph/graphene-cli/src/main.rs @@ -13,7 +13,12 @@ use graph_craft::{ imaginate_input::ImaginatePreferences, NodeIdentifier, Type, TypeDescriptor, }; -use graphene_core::{application_io::NodeGraphUpdateSender, raster::ImageFrame, text::FontCache, Cow}; +use graphene_core::{ + application_io::{self, ApplicationIo, NodeGraphUpdateSender}, + raster::ImageFrame, + text::FontCache, + Cow, +}; use graphene_std::wasm_application_io::{WasmApplicationIo, WasmEditorApi}; use interpreted_executor::dynamic_executor::DynamicExecutor; @@ -35,14 +40,23 @@ async fn main() -> Result<(), Box> { let executor = create_executor(document_string)?; println!("creating gpu context",); + let application_io = &block_on(WasmApplicationIo::new()); + + let device = application_io.gpu_executor().unwrap().context.device.clone(); + std::thread::spawn(move || loop { + std::thread::sleep(std::time::Duration::from_millis(1)); + device.poll(wgpu::Maintain::Poll); + }); + let editor_api = WasmEditorApi { image_frame: None, font_cache: &FontCache::default(), - application_io: &block_on(WasmApplicationIo::new()), + application_io, node_graph_message_sender: &UpdateLogger {}, imaginate_preferences: &ImaginatePreferences::default(), }; - for i in 0..100 { + + loop { //println!("executing"); let result = (&executor).execute(editor_api.clone()).await?; //println!("result: {:?}", result); diff --git a/node-graph/wgpu-executor/src/lib.rs b/node-graph/wgpu-executor/src/lib.rs index 30d563c048..c943b5a1f8 100644 --- a/node-graph/wgpu-executor/src/lib.rs +++ b/node-graph/wgpu-executor/src/lib.rs @@ -23,7 +23,7 @@ use web_sys::HtmlCanvasElement; #[derive(dyn_any::DynAny)] pub struct WgpuExecutor { - context: Context, + pub context: Context, render_configuration: RenderConfiguration, surface_config: Cell>, } @@ -363,10 +363,6 @@ impl gpu_executor::GpuExecutor for WgpuExecutor { fn execute_compute_pipeline(&self, encoder: Self::CommandBuffer) -> Result<()> { self.context.queue.submit(Some(encoder.0)); - // Poll the device in a blocking manner so that our future resolves. - // In an actual application, `device.poll(...)` should - // be called in an event loop or on another thread. - self.context.device.poll(wgpu::Maintain::Wait); Ok(()) }