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 49c171b419
commit f6e4dbf3e3
11 changed files with 232 additions and 52 deletions

View File

@@ -1,38 +1,38 @@
use core::{borrow::Borrow, marker::PhantomData};
use core::marker::PhantomData;
use crate::Node;
pub struct FnNode<T: Fn(&In) -> O, In, O>(T, PhantomData<In>, PhantomData<O>);
impl<'n, T: Fn(&In) -> O, In, O: 'n> Node<'n, In> for FnNode<T, In, O> {
pub struct FnNode<T: Fn(In) -> O, In, O>(T, PhantomData<In>, PhantomData<O>);
impl<'n, T: Fn(In) -> O, In, O: 'n> Node<'n, In> for FnNode<T, In, O> {
type Output = O;
fn eval(&'n self, input: &'n In) -> Self::Output {
self.0(input.borrow())
fn eval(&'n self, input: In) -> Self::Output {
self.0(input)
}
}
impl<T: Fn(&In) -> O, In, O> FnNode<T, In, O> {
impl<T: Fn(In) -> O, In, O> FnNode<T, In, O> {
pub fn new(f: T) -> Self {
FnNode(f, PhantomData::default(), PhantomData::default())
}
}
pub struct FnNodeWithState<T: Fn(&In, &State) -> O, In, O, State>(
pub struct FnNodeWithState<T: Fn(In, &State) -> O, In, O, State>(
T,
State,
PhantomData<In>,
PhantomData<O>,
);
impl<'n, T: Fn(&In, &State) -> O, In, O: 'n, State> Node<'n, In>
impl<'n, T: Fn(In, &State) -> O, In, O: 'n, State> Node<'n, In>
for FnNodeWithState<T, In, O, State>
{
type Output = O;
fn eval(&'n self, input: &'n In) -> Self::Output {
self.0(input.borrow(), &self.1)
fn eval(&'n self, input: In) -> Self::Output {
self.0(input, &self.1)
}
}
impl<T: Fn(&In, &State) -> O, In, O, State> FnNodeWithState<T, In, O, State> {
impl<T: Fn(In, &State) -> O, In, O, State> FnNodeWithState<T, In, O, State> {
pub fn new(f: T, state: State) -> Self {
FnNodeWithState(f, state, PhantomData::default(), PhantomData::default())
}