Compile node graph description to GPU code

This commit is contained in:
Dennis
2022-06-08 09:52:58 +02:00
committed by Keavon Chambers
parent 41a602bba9
commit 089a3f5684
10 changed files with 498 additions and 76 deletions

View File

@@ -1,4 +1,6 @@
use core::marker::PhantomData;
use core::mem::MaybeUninit;
use core::sync::atomic::AtomicBool;
use crate::Node;
@@ -18,8 +20,7 @@ impl<'n, T: 'n> Node<'n> for ValueNode<T> {
&self.0
}
}
impl<'n, T> ValueNode<T> {
impl<T> ValueNode<T> {
pub const fn new(value: T) -> ValueNode<T> {
ValueNode(value)
}
@@ -33,8 +34,29 @@ impl<'n, T: Default + 'n> Node<'n> for DefaultNode<T> {
T::default()
}
}
impl<T> DefaultNode<T> {
pub const fn new() -> DefaultNode<T> {
DefaultNode(PhantomData)
#[repr(C)]
/// Return the unit value
pub struct UnitNode;
impl<'n> Node<'n> for UnitNode {
type Output = ();
fn eval(&'n self) -> Self::Output {}
}
pub struct InputNode<T>(MaybeUninit<T>, AtomicBool);
impl<'n, T: 'n> Node<'n> for InputNode<T> {
type Output = &'n T;
fn eval(&'n self) -> Self::Output {
if self.1.load(core::sync::atomic::Ordering::SeqCst) {
unsafe { self.0.assume_init_ref() }
} else {
panic!("tried to access an input before setting it")
}
}
}
impl<T> InputNode<T> {
pub const fn new() -> InputNode<T> {
InputNode(MaybeUninit::uninit(), AtomicBool::new(false))
}
}