Poll wgpu execution externally

This commit is contained in:
Dennis Kobert
2023-06-17 18:10:55 +02:00
committed by Keavon Chambers
parent 21c62ace64
commit 15ce06f714
4 changed files with 28 additions and 10 deletions

1
Cargo.lock generated
View File

@@ -1769,6 +1769,7 @@ dependencies = [
"test-case",
"tokio",
"wasm-bindgen",
"wgpu",
"wgpu-executor",
]

View File

@@ -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"

View File

@@ -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<dyn Error>> {
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);

View File

@@ -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<Option<SurfaceConfiguration>>,
}
@@ -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(())
}