Implement node graph gpu execution via vulkano and rust gpu (#870)

* Add Executor abstraction

* Resolve inputs for proto nodes by adding compose nodes

* Add infrastructure for compiling gpu code

* Integrate nodegraph gpu execution into graph-crafter

* Extract graphene core path from env vars

* Make Color struct usable for gpu code
This commit is contained in:
TrueDoctor
2022-12-05 12:56:36 +01:00
committed by Keavon Chambers
parent 33d5db76c0
commit 57a1f653e1
26 changed files with 2140 additions and 620 deletions

View File

@@ -0,0 +1,54 @@
use std::error::Error;
use borrow_stack::{BorrowStack, FixedSizeStack};
use graphene_core::Node;
use graphene_std::any::{Any, TypeErasedNode};
use crate::{document::NodeNetwork, node_registry::push_node, proto::ProtoNetwork};
pub struct Compiler {}
impl Compiler {
pub fn compile(&self, mut network: NodeNetwork, resolve_inputs: bool) -> ProtoNetwork {
let node_count = network.nodes.len();
println!("flattening");
for id in 0..node_count {
network.flatten(id as u64);
}
let mut proto_network = network.into_proto_network();
if resolve_inputs {
println!("resolving inputs");
proto_network.resolve_inputs();
}
println!("reordering ids");
proto_network.reorder_ids();
proto_network
}
}
pub trait Executor {
fn execute(&self, input: Any<'static>) -> Result<Any<'static>, Box<dyn Error>>;
}
pub struct DynamicExecutor {
stack: FixedSizeStack<TypeErasedNode<'static>>,
}
impl DynamicExecutor {
pub fn new(proto_network: ProtoNetwork) -> Self {
assert_eq!(proto_network.inputs.len(), 1);
let node_count = proto_network.nodes.len();
let stack = FixedSizeStack::new(node_count);
for (_id, node) in proto_network.nodes {
push_node(node, &stack);
}
Self { stack }
}
}
impl Executor for DynamicExecutor {
fn execute(&self, input: Any<'static>) -> Result<Any<'static>, Box<dyn Error>> {
let result = unsafe { self.stack.get().last().unwrap().eval(input) };
Ok(result)
}
}