Add GPU support for node graph

This commit is contained in:
Dennis
2022-04-24 11:58:31 +02:00
committed by Keavon Chambers
parent bfe21cb179
commit aa5e6f43f6
11 changed files with 232 additions and 52 deletions

View File

@@ -5,25 +5,20 @@ use crate::Node;
pub struct IntNode<const N: u32>;
impl<'n, const N: u32> Node<'n, ()> for IntNode<N> {
type Output = u32;
fn eval(&self, _input: &()) -> u32 {
fn eval(&self, _input: ()) -> u32 {
N
}
}
use dyn_any::{DynAny, StaticType, StaticTypeSized};
#[derive(Default)]
pub struct ValueNode<'n, T>(T, PhantomData<&'n ()>);
impl<'n, T: 'n> Node<'n, ()> for ValueNode<'n, T> {
type Output = &'n T;
fn eval(&self, _input: &()) -> &T {
fn eval(&self, _input: ()) -> &T {
&self.0
}
}
impl<'n, T: StaticTypeSized> StaticType for ValueNode<'n, T> {
type Static = ValueNode<'static, <T as StaticTypeSized>::Static>;
}
impl<'n, T> ValueNode<'n, T> {
pub const fn new(value: T) -> ValueNode<'n, T> {
ValueNode(value, PhantomData)
@@ -34,7 +29,7 @@ impl<'n, T> ValueNode<'n, T> {
pub struct DefaultNode<T>(PhantomData<T>);
impl<'n, T: Default + 'n> Node<'n, ()> for DefaultNode<T> {
type Output = T;
fn eval(&self, _input: &()) -> T {
fn eval(&self, _input: ()) -> T {
T::default()
}
}
@@ -47,8 +42,8 @@ impl<T> DefaultNode<T> {
pub struct DefaultRefNode<'n, T>(ValueNode<'n, T>);
impl<'n, T: 'n> Node<'n, ()> for DefaultRefNode<'n, T> {
type Output = &'n T;
fn eval(&'n self, _input: &'n ()) -> &'n T {
self.0.eval(&())
fn eval(&'n self, _input: ()) -> &'n T {
self.0.eval(())
}
}
impl<'n, T: Default> Default for DefaultRefNode<'n, T> {