mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Deprecate LetNodes in favor of new scope API (#1814)
* WIP * Start deprecating let nodes * Replace WasmEditorApi network imports with new Scope input * Add missing unwrap * Add #[serde(default)] to scope_injections * Restructure WasmEditorApi definition to be available as a TaggedValue * Fix text node * Use stable toolchain in nix shell again * Code review * FIx text node and remove all remaining warnings * Require executor input to be 'static --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -15,7 +15,6 @@ gpu-executor = { path = "../gpu-executor" }
|
||||
|
||||
# Workspace dependencies
|
||||
graphene-core = { workspace = true, features = ["std", "alloc", "gpu"] }
|
||||
graph-craft = { workspace = true }
|
||||
dyn-any = { workspace = true, features = ["log-bad-types", "rc", "glam"] }
|
||||
num-traits = { workspace = true }
|
||||
log = { workspace = true }
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
use super::context::Context;
|
||||
|
||||
use dyn_any::StaticTypeSized;
|
||||
|
||||
use bytemuck::Pod;
|
||||
use std::borrow::Cow;
|
||||
use std::error::Error;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use std::{borrow::Cow, error::Error};
|
||||
use wgpu::util::DeviceExt;
|
||||
|
||||
use super::context::Context;
|
||||
use bytemuck::Pod;
|
||||
use dyn_any::StaticTypeSized;
|
||||
use graph_craft::{graphene_compiler::Executor, proto::LocalFuture};
|
||||
pub type LocalFuture<'n, T> = Pin<Box<dyn core::future::Future<Output = T> + 'n>>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GpuExecutor<'a, I: StaticTypeSized, O> {
|
||||
@@ -15,7 +19,7 @@ pub struct GpuExecutor<'a, I: StaticTypeSized, O> {
|
||||
_phantom: std::marker::PhantomData<(I, O)>,
|
||||
}
|
||||
|
||||
impl<'a, I: StaticTypeSized, O> GpuExecutor<'a, I, O> {
|
||||
impl<'a, I: StaticTypeSized + Sync + Pod + Send, O: StaticTypeSized + Send + Sync + Pod> GpuExecutor<'a, I, O> {
|
||||
pub fn new(context: Context, shader: Cow<'a, [u32]>, entry_point: String) -> anyhow::Result<Self> {
|
||||
Ok(Self {
|
||||
context,
|
||||
@@ -24,10 +28,8 @@ impl<'a, I: StaticTypeSized, O> GpuExecutor<'a, I, O> {
|
||||
_phantom: std::marker::PhantomData,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I: StaticTypeSized + Sync + Pod + Send, O: StaticTypeSized + Send + Sync + Pod> Executor<Vec<I>, Vec<O>> for GpuExecutor<'a, I, O> {
|
||||
fn execute(&self, input: Vec<I>) -> LocalFuture<Result<Vec<O>, Box<dyn Error>>> {
|
||||
pub fn execute(&self, input: Vec<I>) -> LocalFuture<Result<Vec<O>, Box<dyn Error>>> {
|
||||
let context = &self.context;
|
||||
let future = execute_shader(context.device.clone(), context.queue.clone(), self.shader.to_vec(), input, self.entry_point.clone());
|
||||
Box::pin(async move {
|
||||
|
||||
@@ -4,19 +4,19 @@ mod executor;
|
||||
pub use context::Context;
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
pub use executor::GpuExecutor;
|
||||
pub use gpu_executor::ShaderIO;
|
||||
use gpu_executor::{ComputePassDimensions, Shader, ShaderInput, StorageBufferOptions, TextureBufferOptions, TextureBufferType, ToStorageBuffer, ToUniformBuffer};
|
||||
use graph_craft::Type;
|
||||
use graphene_core::Type;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use futures::Future;
|
||||
use graphene_core::application_io::{ApplicationIo, EditorApi, SurfaceHandle};
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
|
||||
use wgpu::util::DeviceExt;
|
||||
use wgpu::{Buffer, BufferDescriptor, CommandBuffer, ShaderModule, SurfaceConfiguration, SurfaceError, Texture, TextureView};
|
||||
use wgpu::{Buffer, BufferDescriptor, CommandBuffer, ShaderModule, SurfaceError, Texture, TextureView};
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
use web_sys::HtmlCanvasElement;
|
||||
@@ -25,7 +25,6 @@ use web_sys::HtmlCanvasElement;
|
||||
pub struct WgpuExecutor {
|
||||
pub context: Context,
|
||||
render_configuration: RenderConfiguration,
|
||||
surface_config: Cell<Option<SurfaceConfiguration>>,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for WgpuExecutor {
|
||||
@@ -37,9 +36,9 @@ impl std::fmt::Debug for WgpuExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: ApplicationIo<Executor = WgpuExecutor>> From<EditorApi<'a, T>> for &'a WgpuExecutor {
|
||||
fn from(editor_api: EditorApi<'a, T>) -> Self {
|
||||
editor_api.application_io.gpu_executor().unwrap()
|
||||
impl<'a, T: ApplicationIo<Executor = WgpuExecutor>> From<&'a EditorApi<T>> for &'a WgpuExecutor {
|
||||
fn from(editor_api: &'a EditorApi<T>) -> Self {
|
||||
editor_api.application_io.as_ref().unwrap().gpu_executor().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,9 +295,8 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
||||
log::warn!("No surface formats available");
|
||||
// return Ok(());
|
||||
}
|
||||
let Some(config) = self.surface_config.take() else { return Ok(()) };
|
||||
let new_config = config.clone();
|
||||
self.surface_config.replace(Some(config));
|
||||
// let new_config = config.clone();
|
||||
// self.surface_config.replace(Some(config));
|
||||
let output = match result {
|
||||
Err(SurfaceError::Timeout) => {
|
||||
log::warn!("Timeout when getting current texture");
|
||||
@@ -307,7 +305,7 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
||||
Err(SurfaceError::Lost) => {
|
||||
log::warn!("Surface lost");
|
||||
|
||||
surface.configure(&self.context.device, &new_config);
|
||||
// surface.configure(&self.context.device, &new_config);
|
||||
return Ok(());
|
||||
}
|
||||
Err(SurfaceError::OutOfMemory) => {
|
||||
@@ -316,7 +314,7 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
||||
}
|
||||
Err(SurfaceError::Outdated) => {
|
||||
log::warn!("Surface outdated");
|
||||
surface.configure(&self.context.device, &new_config);
|
||||
// surface.configure(&self.context.device, &new_config);
|
||||
return Ok(());
|
||||
}
|
||||
Ok(surface) => surface,
|
||||
@@ -472,7 +470,6 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
||||
desired_maximum_frame_latency: 2,
|
||||
};
|
||||
surface.configure(&self.context.device, &config);
|
||||
self.surface_config.set(Some(config));
|
||||
|
||||
let surface_id = window.surface_id;
|
||||
Ok(SurfaceHandle { surface_id, surface })
|
||||
@@ -591,11 +588,7 @@ impl WgpuExecutor {
|
||||
sampler,
|
||||
};
|
||||
|
||||
Some(Self {
|
||||
context,
|
||||
render_configuration,
|
||||
surface_config: Cell::new(None),
|
||||
})
|
||||
Some(Self { context, render_configuration })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user