mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 23:08:05 +08:00
Add document nodes for gpu pipeline nodes (#1292)
* Add document nodes for gpu pipeline nodes * Load existing frame instead of clearing it * Feature gate gpu imports
This commit is contained in:
@@ -485,10 +485,10 @@ async fn read_output_buffer_node<'a: 'input, E: 'a + GpuExecutor>(buffer: Arc<Sh
|
||||
pub struct CreateGpuSurfaceNode {}
|
||||
|
||||
#[node_macro::node_fn(CreateGpuSurfaceNode)]
|
||||
async fn create_gpu_surface<'a: 'input, E: 'a + GpuExecutor<Window = Io::Surface>, Io: ApplicationIo<Executor = E>>(editor_api: EditorApi<'a, Io>) -> SurfaceHandle<E::Surface> {
|
||||
async fn create_gpu_surface<'a: 'input, E: 'a + GpuExecutor<Window = Io::Surface>, Io: ApplicationIo<Executor = E>>(editor_api: EditorApi<'a, Io>) -> Arc<SurfaceHandle<E::Surface>> {
|
||||
let canvas = editor_api.application_io.create_surface();
|
||||
let executor = editor_api.application_io.gpu_executor().unwrap();
|
||||
executor.create_surface(canvas).unwrap()
|
||||
Arc::new(executor.create_surface(canvas).unwrap())
|
||||
}
|
||||
|
||||
pub struct RenderTextureNode<Surface, EditorApi> {
|
||||
@@ -496,12 +496,20 @@ pub struct RenderTextureNode<Surface, EditorApi> {
|
||||
executor: EditorApi,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ShaderInputFrame<E: GpuExecutor + ?Sized> {
|
||||
shader_input: Arc<ShaderInput<E>>,
|
||||
transform: DAffine2,
|
||||
}
|
||||
|
||||
impl<E: GpuExecutor + ?Sized> Clone for ShaderInputFrame<E> {
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
shader_input: self.shader_input.clone(),
|
||||
transform: self.transform,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl<E: GpuExecutor + ?Sized + StaticType> StaticType for ShaderInputFrame<E>
|
||||
where
|
||||
E::Static: GpuExecutor,
|
||||
|
||||
@@ -384,25 +384,25 @@ impl ProtoNetwork {
|
||||
pub fn topological_sort(&self) -> Vec<NodeId> {
|
||||
let mut sorted = Vec::new();
|
||||
let inwards_edges = self.collect_inwards_edges();
|
||||
fn visit(node_id: NodeId, temp_marks: &mut HashSet<NodeId>, sorted: &mut Vec<NodeId>, inwards_edges: &HashMap<NodeId, Vec<NodeId>>) {
|
||||
fn visit(node_id: NodeId, temp_marks: &mut HashSet<NodeId>, sorted: &mut Vec<NodeId>, inwards_edges: &HashMap<NodeId, Vec<NodeId>>, network: &ProtoNetwork) {
|
||||
if sorted.contains(&node_id) {
|
||||
return;
|
||||
};
|
||||
if temp_marks.contains(&node_id) {
|
||||
panic!("Cycle detected");
|
||||
panic!("Cycle detected {:#?}, {:#?}", &inwards_edges, &network);
|
||||
}
|
||||
|
||||
if let Some(dependencies) = inwards_edges.get(&node_id) {
|
||||
temp_marks.insert(node_id);
|
||||
for &dependant in dependencies {
|
||||
visit(dependant, temp_marks, sorted, inwards_edges);
|
||||
visit(dependant, temp_marks, sorted, inwards_edges, network);
|
||||
}
|
||||
temp_marks.remove(&node_id);
|
||||
}
|
||||
sorted.push(node_id);
|
||||
}
|
||||
assert!(self.nodes.iter().any(|(id, _)| *id == self.output), "Output id {} does not exist", self.output);
|
||||
visit(self.output, &mut HashSet::new(), &mut sorted, &inwards_edges);
|
||||
visit(self.output, &mut HashSet::new(), &mut sorted, &inwards_edges, self);
|
||||
|
||||
sorted
|
||||
}
|
||||
|
||||
@@ -461,6 +461,11 @@ fn node_registry() -> HashMap<NodeIdentifier, HashMap<NodeIOTypes, NodeConstruct
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: (), output: QuantizationChannels, params: [QuantizationChannels]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: (), output: Vec<DVec2>, params: [Vec<DVec2>]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: (), output: Arc<WasmSurfaceHandle>, params: [Arc<WasmSurfaceHandle>]),
|
||||
#[cfg(feature = "gpu")]
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: (), output: ShaderInputFrame<WgpuExecutor>, params: [ShaderInputFrame<WgpuExecutor>]),
|
||||
#[cfg(feature = "gpu")]
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: (), output: wgpu_executor::WgpuSurface, params: [wgpu_executor::WgpuSurface]),
|
||||
async_node!(graphene_core::memo::MemoNode<_, _>, input: (), output: SurfaceFrame, params: [SurfaceFrame]),
|
||||
register_node!(graphene_core::structural::ConsNode<_, _>, input: Image<Color>, params: [&str]),
|
||||
register_node!(graphene_std::raster::ImageFrameNode<_, _>, input: Image<Color>, params: [DAffine2]),
|
||||
#[cfg(feature = "quantization")]
|
||||
|
||||
@@ -32,6 +32,8 @@ impl<'a, T: ApplicationIo<Executor = WgpuExecutor>> From<EditorApi<'a, T>> for &
|
||||
}
|
||||
}
|
||||
|
||||
pub type WgpuSurface = Arc<SurfaceHandle<wgpu::Surface>>;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
struct Vertex {
|
||||
@@ -292,7 +294,7 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
||||
view: &view,
|
||||
resolve_target: None,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
|
||||
load: wgpu::LoadOp::Load,
|
||||
store: true,
|
||||
},
|
||||
})],
|
||||
|
||||
Reference in New Issue
Block a user