mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-02 20:28:11 +08:00
Poll wgpu execution externally
This commit is contained in:
committed by
Keavon Chambers
parent
21c62ace64
commit
15ce06f714
Generated
+1
@@ -1769,6 +1769,7 @@ dependencies = [
|
|||||||
"test-case",
|
"test-case",
|
||||||
"tokio",
|
"tokio",
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
|
"wgpu",
|
||||||
"wgpu-executor",
|
"wgpu-executor",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,15 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[features]
|
[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"]
|
default = ["wgpu"]
|
||||||
wgpu = ["wgpu-executor", "gpu"]
|
wgpu = ["wgpu-executor", "gpu", "graphene-std/wgpu"]
|
||||||
wayland = ["graphene-std/wayland"]
|
wayland = ["graphene-std/wayland"]
|
||||||
|
|
||||||
|
|
||||||
@@ -39,6 +45,7 @@ futures = "0.3.28"
|
|||||||
fern = { version = "0.6.2", features = ["colored"] }
|
fern = { version = "0.6.2", features = ["colored"] }
|
||||||
chrono = "0.4.26"
|
chrono = "0.4.26"
|
||||||
tokio = { version = "1.28.2", features = ["macros", "rt"] }
|
tokio = { version = "1.28.2", features = ["macros", "rt"] }
|
||||||
|
wgpu = "0.16.1"
|
||||||
|
|
||||||
[dependencies.document-legacy]
|
[dependencies.document-legacy]
|
||||||
path = "../../document-legacy"
|
path = "../../document-legacy"
|
||||||
|
|||||||
@@ -13,7 +13,12 @@ use graph_craft::{
|
|||||||
imaginate_input::ImaginatePreferences,
|
imaginate_input::ImaginatePreferences,
|
||||||
NodeIdentifier, Type, TypeDescriptor,
|
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 graphene_std::wasm_application_io::{WasmApplicationIo, WasmEditorApi};
|
||||||
use interpreted_executor::dynamic_executor::DynamicExecutor;
|
use interpreted_executor::dynamic_executor::DynamicExecutor;
|
||||||
|
|
||||||
@@ -35,14 +40,23 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
let executor = create_executor(document_string)?;
|
let executor = create_executor(document_string)?;
|
||||||
println!("creating gpu context",);
|
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 {
|
let editor_api = WasmEditorApi {
|
||||||
image_frame: None,
|
image_frame: None,
|
||||||
font_cache: &FontCache::default(),
|
font_cache: &FontCache::default(),
|
||||||
application_io: &block_on(WasmApplicationIo::new()),
|
application_io,
|
||||||
node_graph_message_sender: &UpdateLogger {},
|
node_graph_message_sender: &UpdateLogger {},
|
||||||
imaginate_preferences: &ImaginatePreferences::default(),
|
imaginate_preferences: &ImaginatePreferences::default(),
|
||||||
};
|
};
|
||||||
for i in 0..100 {
|
|
||||||
|
loop {
|
||||||
//println!("executing");
|
//println!("executing");
|
||||||
let result = (&executor).execute(editor_api.clone()).await?;
|
let result = (&executor).execute(editor_api.clone()).await?;
|
||||||
//println!("result: {:?}", result);
|
//println!("result: {:?}", result);
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ use web_sys::HtmlCanvasElement;
|
|||||||
|
|
||||||
#[derive(dyn_any::DynAny)]
|
#[derive(dyn_any::DynAny)]
|
||||||
pub struct WgpuExecutor {
|
pub struct WgpuExecutor {
|
||||||
context: Context,
|
pub context: Context,
|
||||||
render_configuration: RenderConfiguration,
|
render_configuration: RenderConfiguration,
|
||||||
surface_config: Cell<Option<SurfaceConfiguration>>,
|
surface_config: Cell<Option<SurfaceConfiguration>>,
|
||||||
}
|
}
|
||||||
@@ -363,10 +363,6 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
|||||||
fn execute_compute_pipeline(&self, encoder: Self::CommandBuffer) -> Result<()> {
|
fn execute_compute_pipeline(&self, encoder: Self::CommandBuffer) -> Result<()> {
|
||||||
self.context.queue.submit(Some(encoder.0));
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user