Fix formatting of previous commit
This commit is contained in:
parent
d09f023618
commit
0c2dbd411b
|
|
@ -2,7 +2,7 @@
|
||||||
name = "dyn-any"
|
name = "dyn-any"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Dennis Kobert <dennis@kobert.dev>"]
|
authors = ["Graphite Authors <contact@graphite.rs>"]
|
||||||
|
|
||||||
|
|
||||||
description = "An Any trait that works for arbitrary lifetimes"
|
description = "An Any trait that works for arbitrary lifetimes"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
name = "dyn-any-derive"
|
name = "dyn-any-derive"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Dennis Kobert"]
|
authors = ["Graphite Authors <contact@graphite.rs>"]
|
||||||
|
|
||||||
description = "#[derive(DynAny<'a>)]"
|
description = "#[derive(DynAny<'a>)]"
|
||||||
documentation = "https://docs.rs/dyn-any-derive"
|
documentation = "https://docs.rs/dyn-any-derive"
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ name = "graphene-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "API definitions for Graphene"
|
description = "API definitions for Graphene"
|
||||||
authors = ["Dennis Kobert <dennis@kobert.dev>"]
|
authors = ["Graphite Authors <contact@graphite.rs>"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
@ -17,5 +17,5 @@ nightly = []
|
||||||
[dependencies]
|
[dependencies]
|
||||||
dyn-any = {path = "../../libraries/dyn-any", features = ["derive"], optional = true}
|
dyn-any = {path = "../../libraries/dyn-any", features = ["derive"], optional = true}
|
||||||
|
|
||||||
spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu", features = ["glam"] , optional = true}
|
spirv-std = { git = "https://github.com/EmbarkStudios/rust-gpu", features = ["glam"] , optional = true}
|
||||||
async-trait = {version = "0.1", optional = true}
|
async-trait = {version = "0.1", optional = true}
|
||||||
|
|
|
||||||
|
|
@ -3,98 +3,93 @@ use core::marker::PhantomData;
|
||||||
use crate::Node;
|
use crate::Node;
|
||||||
|
|
||||||
pub struct ComposeNode<'n, Inter, First, Second> {
|
pub struct ComposeNode<'n, Inter, First, Second> {
|
||||||
first: &'n First,
|
first: &'n First,
|
||||||
second: &'n Second,
|
second: &'n Second,
|
||||||
_phantom: PhantomData<&'n Input>,
|
_phantom: PhantomData<&'n Input>,
|
||||||
_phantom2: PhantomData<Inter>,
|
_phantom2: PhantomData<Inter>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input>
|
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input> for ComposeNode<'n, Input, Inter, First, Second>
|
||||||
for ComposeNode<'n, Input, Inter, First, Second>
|
|
||||||
where
|
where
|
||||||
First: Node<'n, Input, Output = Inter>,
|
First: Node<'n, Input, Output = Inter>,
|
||||||
Second: Node<'n, Inter>, /*+ Node<<First as Node<Input>>::Output<'n>>*/
|
Second: Node<'n, Inter>, /*+ Node<<First as Node<Input>>::Output<'n>>*/
|
||||||
{
|
{
|
||||||
type Output = <Second as Node<'n, Inter>>::Output;
|
type Output = <Second as Node<'n, Inter>>::Output;
|
||||||
|
|
||||||
fn eval(&'n self, input: Input) -> Self::Output {
|
fn eval(&'n self, input: Input) -> Self::Output {
|
||||||
// evaluate the first node with the given input
|
// evaluate the first node with the given input
|
||||||
// and then pipe the result from the first computation
|
// and then pipe the result from the first computation
|
||||||
// into the second node
|
// into the second node
|
||||||
let arg: Inter = self.first.eval(input);
|
let arg: Inter = self.first.eval(input);
|
||||||
self.second.eval(arg)
|
self.second.eval(arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'n, Input, Inter, FIRST, SECOND> ComposeNode<'n, Input, Inter, FIRST, SECOND>
|
impl<'n, Input, Inter, FIRST, SECOND> ComposeNode<'n, Input, Inter, FIRST, SECOND>
|
||||||
where
|
where
|
||||||
FIRST: Node<'n, Input>,
|
FIRST: Node<'n, Input>,
|
||||||
{
|
{
|
||||||
pub const fn new(first: &'n FIRST, second: &'n SECOND) -> Self {
|
pub const fn new(first: &'n FIRST, second: &'n SECOND) -> Self {
|
||||||
ComposeNode::<'n, Input, Inter, FIRST, SECOND> {
|
ComposeNode::<'n, Input, Inter, FIRST, SECOND> {
|
||||||
first,
|
first,
|
||||||
second,
|
second,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
_phantom2: PhantomData,
|
_phantom2: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct ComposeNodeOwned<'n, Input, Inter, FIRST, SECOND> {
|
pub struct ComposeNodeOwned<'n, Input, Inter, FIRST, SECOND> {
|
||||||
first: FIRST,
|
first: FIRST,
|
||||||
second: SECOND,
|
second: SECOND,
|
||||||
_phantom: PhantomData<&'n Input>,
|
_phantom: PhantomData<&'n Input>,
|
||||||
_phantom2: PhantomData<Inter>,
|
_phantom2: PhantomData<Inter>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input>
|
impl<'n, Input: 'n, Inter: 'n, First, Second> Node<'n, Input> for ComposeNodeOwned<'n, Input, Inter, First, Second>
|
||||||
for ComposeNodeOwned<'n, Input, Inter, First, Second>
|
|
||||||
where
|
where
|
||||||
First: Node<'n, Input, Output = Inter>,
|
First: Node<'n, Input, Output = Inter>,
|
||||||
Second: Node<'n, Inter>,
|
Second: Node<'n, Inter>,
|
||||||
{
|
{
|
||||||
type Output = <Second as Node<'n, Inter>>::Output;
|
type Output = <Second as Node<'n, Inter>>::Output;
|
||||||
|
|
||||||
fn eval(&'n self, input: Input) -> Self::Output {
|
fn eval(&'n self, input: Input) -> Self::Output {
|
||||||
// evaluate the first node with the given input
|
// evaluate the first node with the given input
|
||||||
// and then pipe the result from the first computation
|
// and then pipe the result from the first computation
|
||||||
// into the second node
|
// into the second node
|
||||||
let arg: Inter = self.first.eval(input);
|
let arg: Inter = self.first.eval(input);
|
||||||
self.second.eval(arg)
|
self.second.eval(arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'n, Input, Inter, First: 'n, Second> ComposeNodeOwned<'n, Input, Inter, First, Second>
|
impl<'n, Input, Inter, First: 'n, Second> ComposeNodeOwned<'n, Input, Inter, First, Second>
|
||||||
where
|
where
|
||||||
First: Node<'n, Input, Output = Inter>,
|
First: Node<'n, Input, Output = Inter>,
|
||||||
{
|
{
|
||||||
#[cfg(feature = "nightly")]
|
#[cfg(feature = "nightly")]
|
||||||
pub const fn new(first: First, second: Second) -> Self {
|
pub const fn new(first: First, second: Second) -> Self {
|
||||||
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
|
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
|
||||||
first,
|
first,
|
||||||
second,
|
second,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
_phantom2: PhantomData,
|
_phantom2: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "nightly"))]
|
#[cfg(not(feature = "nightly"))]
|
||||||
pub fn new(first: First, second: Second) -> Self {
|
pub fn new(first: First, second: Second) -> Self {
|
||||||
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
|
ComposeNodeOwned::<'n, Input, Inter, First, Second> {
|
||||||
first,
|
first,
|
||||||
second,
|
second,
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
_phantom2: PhantomData,
|
_phantom2: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait After<I>: Sized {
|
pub trait After<I>: Sized {
|
||||||
fn after<'n, First: Node<'n, I>>(
|
fn after<'n, First: Node<'n, I>>(&'n self, first: &'n First) -> ComposeNode<'n, I, <First as Node<'n, I>>::Output, First, Self> {
|
||||||
&'n self,
|
ComposeNode::new(first, self)
|
||||||
first: &'n First,
|
}
|
||||||
) -> ComposeNode<'n, I, <First as Node<'n, I>>::Output, First, Self> {
|
|
||||||
ComposeNode::new(first, self)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
impl<Second: for<'n> Node<'n, I>, I> After<I> for Second {}
|
impl<Second: for<'n> Node<'n, I>, I> After<I> for Second {}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ name = "graphene-std"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Graphene standard library"
|
description = "Graphene standard library"
|
||||||
authors = ["Dennis Kobert <dennis@kobert.dev>"]
|
authors = ["Graphite Authors <contact@graphite.rs>"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|
@ -22,11 +22,11 @@ dyn-any = {path = "../../libraries/dyn-any", features = ["derive"]}
|
||||||
graph-proc-macros = {path = "../proc-macro", optional = true}
|
graph-proc-macros = {path = "../proc-macro", optional = true}
|
||||||
once_cell = {version= "1.10", optional = true}
|
once_cell = {version= "1.10", optional = true}
|
||||||
ide = { version = "*", package = "ra_ap_ide", optional = true }
|
ide = { version = "*", package = "ra_ap_ide", optional = true }
|
||||||
ide_db = { version = "*", package = "ra_ap_ide_db" , optional = true }
|
ide_db = { version = "*", package = "ra_ap_ide_db", optional = true }
|
||||||
storage-map = { version = "*", optional = true }
|
storage-map = { version = "*", optional = true }
|
||||||
lock_api = { version= "*", optional = true }
|
lock_api = { version= "*", optional = true }
|
||||||
parking_lot = { version = "*", optional = true }
|
parking_lot = { version = "*", optional = true }
|
||||||
#pretty-token-stream = {path = "../../pretty-token-stream"}
|
#pretty-token-stream = {path = "../../pretty-token-stream"}
|
||||||
syn = {version = "1.0", default-features = false, features = ["parsing", "printing"]}
|
syn = {version = "1.0", default-features = false, features = ["parsing", "printing"]}
|
||||||
proc-macro2 = {version = "1.0", default-features = false, features = ["proc-macro"]}
|
proc-macro2 = {version = "1.0", default-features = false, features = ["proc-macro"]}
|
||||||
quote = {version = "1.0", default-features = false }
|
quote = {version = "1.0", default-features = false }
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
use parking_lot::RawRwLock;
|
use parking_lot::RawRwLock;
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
borrow::Borrow,
|
borrow::Borrow,
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
collections::{hash_map::DefaultHasher, HashMap},
|
collections::{hash_map::DefaultHasher, HashMap},
|
||||||
hash::{Hash, Hasher},
|
hash::{Hash, Hasher},
|
||||||
iter,
|
iter,
|
||||||
iter::Sum,
|
iter::Sum,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
};
|
};
|
||||||
use storage_map::{StorageMap, StorageMapGuard};
|
use storage_map::{StorageMap, StorageMapGuard};
|
||||||
|
|
||||||
|
|
@ -16,33 +16,29 @@ use graphene_api::{DynamicInput, Node};
|
||||||
/// Caches the output of a given Node and acts as a proxy
|
/// Caches the output of a given Node and acts as a proxy
|
||||||
/// Automatically resets if it receives different input
|
/// Automatically resets if it receives different input
|
||||||
pub struct SmartCacheNode<'n, 'c, NODE: Node + 'c> {
|
pub struct SmartCacheNode<'n, 'c, NODE: Node + 'c> {
|
||||||
node: &'n NODE,
|
node: &'n NODE,
|
||||||
map: StorageMap<RawRwLock, HashMap<u64, CacheNode<'n, 'c, NODE>>>,
|
map: StorageMap<RawRwLock, HashMap<u64, CacheNode<'n, 'c, NODE>>>,
|
||||||
}
|
}
|
||||||
impl<'n: 'c, 'c, NODE: Node + 'c> Node for SmartCacheNode<'n, 'c, NODE>
|
impl<'n: 'c, 'c, NODE: Node + 'c> Node for SmartCacheNode<'n, 'c, NODE>
|
||||||
where
|
where
|
||||||
for<'a> NODE::Input<'a>: Hash,
|
for<'a> NODE::Input<'a>: Hash,
|
||||||
{
|
{
|
||||||
type Input<'a> = NODE::Input<'a> where Self: 'a, 'c : 'a;
|
type Input<'a> = NODE::Input<'a> where Self: 'a, 'c : 'a;
|
||||||
type Output<'a> = StorageMapGuard<'a, RawRwLock, CacheNode<'n, 'c, NODE>> where Self: 'a, 'c: 'a;
|
type Output<'a> = StorageMapGuard<'a, RawRwLock, CacheNode<'n, 'c, NODE>> where Self: 'a, 'c: 'a;
|
||||||
fn eval<'a, I: Borrow<Self::Input<'a>>>(&'a self, input: I) -> Self::Output<'a> {
|
fn eval<'a, I: Borrow<Self::Input<'a>>>(&'a self, input: I) -> Self::Output<'a> {
|
||||||
let mut hasher = DefaultHasher::new();
|
let mut hasher = DefaultHasher::new();
|
||||||
input.borrow().hash(&mut hasher);
|
input.borrow().hash(&mut hasher);
|
||||||
let hash = hasher.finish();
|
let hash = hasher.finish();
|
||||||
|
|
||||||
self.map
|
self.map.get_or_create_with(&hash, || CacheNode::new(self.node))
|
||||||
.get_or_create_with(&hash, || CacheNode::new(self.node))
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'n, 'c, NODE: Node> SmartCacheNode<'n, 'c, NODE> {
|
impl<'n, 'c, NODE: Node> SmartCacheNode<'n, 'c, NODE> {
|
||||||
pub fn clear(&'n mut self) {
|
pub fn clear(&'n mut self) {
|
||||||
self.map = StorageMap::default();
|
self.map = StorageMap::default();
|
||||||
}
|
}
|
||||||
pub fn new(node: &'n NODE) -> SmartCacheNode<'n, 'c, NODE> {
|
pub fn new(node: &'n NODE) -> SmartCacheNode<'n, 'c, NODE> {
|
||||||
SmartCacheNode {
|
SmartCacheNode { node, map: StorageMap::default() }
|
||||||
node,
|
}
|
||||||
map: StorageMap::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ pub type DynNode<'n, T> = &'n (dyn Node<'n, Output = T> + 'n);
|
||||||
pub type DynAnyNode<'n> = &'n (dyn Node<'n, Output = &'n dyn DynAny<'n>> + 'n);
|
pub type DynAnyNode<'n> = &'n (dyn Node<'n, Output = &'n dyn DynAny<'n>> + 'n);
|
||||||
|
|
||||||
pub trait DynamicInput<'n> {
|
pub trait DynamicInput<'n> {
|
||||||
fn set_kwarg_by_name(&mut self, name: &str, value: DynAnyNode<'n>);
|
fn set_kwarg_by_name(&mut self, name: &str, value: DynAnyNode<'n>);
|
||||||
fn set_arg_by_index(&mut self, index: usize, value: DynAnyNode<'n>);
|
fn set_arg_by_index(&mut self, index: usize, value: DynAnyNode<'n>);
|
||||||
}
|
}
|
||||||
|
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
|
|
@ -25,89 +25,89 @@ use syn::{Expr, ExprPath, Type};
|
||||||
/// on the gpu an fn node is constructed that takes a value
|
/// on the gpu an fn node is constructed that takes a value
|
||||||
/// node as input
|
/// node as input
|
||||||
pub struct NodeGraph {
|
pub struct NodeGraph {
|
||||||
/// Collection of nodes with their corresponding inputs.
|
/// Collection of nodes with their corresponding inputs.
|
||||||
/// The first node always always has to be an Input Node.
|
/// The first node always always has to be an Input Node.
|
||||||
pub nodes: Vec<NodeKind>,
|
pub nodes: Vec<NodeKind>,
|
||||||
pub output: Type,
|
pub output: Type,
|
||||||
pub input: Type,
|
pub input: Type,
|
||||||
}
|
}
|
||||||
pub enum NodeKind {
|
pub enum NodeKind {
|
||||||
Value(Expr),
|
Value(Expr),
|
||||||
Input,
|
Input,
|
||||||
Node(ExprPath, Vec<usize>),
|
Node(ExprPath, Vec<usize>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NodeGraph {
|
impl NodeGraph {
|
||||||
pub fn serialize_function(&self) -> proc_macro2::TokenStream {
|
pub fn serialize_function(&self) -> proc_macro2::TokenStream {
|
||||||
let output_type = &self.output;
|
let output_type = &self.output;
|
||||||
let input_type = &self.input;
|
let input_type = &self.input;
|
||||||
|
|
||||||
fn nid(id: &usize) -> syn::Ident {
|
fn nid(id: &usize) -> syn::Ident {
|
||||||
let str = format!("n{id}");
|
let str = format!("n{id}");
|
||||||
syn::Ident::new(str.as_str(), proc_macro2::Span::call_site())
|
syn::Ident::new(str.as_str(), proc_macro2::Span::call_site())
|
||||||
}
|
}
|
||||||
let mut nodes = Vec::new();
|
let mut nodes = Vec::new();
|
||||||
for (ref id, node) in self.nodes.iter().enumerate() {
|
for (ref id, node) in self.nodes.iter().enumerate() {
|
||||||
let id = nid(id).clone();
|
let id = nid(id).clone();
|
||||||
let line = match node {
|
let line = match node {
|
||||||
NodeKind::Value(val) => {
|
NodeKind::Value(val) => {
|
||||||
quote! {let #id = graphene_core::value::ValueNode::new(#val);}
|
quote! {let #id = graphene_core::value::ValueNode::new(#val);}
|
||||||
}
|
}
|
||||||
NodeKind::Node(node, ids) => {
|
NodeKind::Node(node, ids) => {
|
||||||
let ids = ids.iter().map(nid).collect::<Vec<_>>();
|
let ids = ids.iter().map(nid).collect::<Vec<_>>();
|
||||||
quote! {let #id = #node::new((#(&#ids),*));}
|
quote! {let #id = #node::new((#(&#ids),*));}
|
||||||
}
|
}
|
||||||
NodeKind::Input => {
|
NodeKind::Input => {
|
||||||
quote! { let n0 = graphene_core::value::ValueNode::new(input);}
|
quote! { let n0 = graphene_core::value::ValueNode::new(input);}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
nodes.push(line)
|
nodes.push(line)
|
||||||
}
|
}
|
||||||
let last_id = self.nodes.len() - 1;
|
let last_id = self.nodes.len() - 1;
|
||||||
let last_id = nid(&last_id);
|
let last_id = nid(&last_id);
|
||||||
let ret = quote! { #last_id.eval() };
|
let ret = quote! { #last_id.eval() };
|
||||||
let function = quote! {
|
let function = quote! {
|
||||||
fn node_graph(input: #input_type) -> #output_type {
|
fn node_graph(input: #input_type) -> #output_type {
|
||||||
#(#nodes)*
|
#(#nodes)*
|
||||||
#ret
|
#ret
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
function
|
function
|
||||||
}
|
}
|
||||||
pub fn serialize_gpu(&self, name: &str) -> proc_macro2::TokenStream {
|
pub fn serialize_gpu(&self, name: &str) -> proc_macro2::TokenStream {
|
||||||
let function = self.serialize_function();
|
let function = self.serialize_function();
|
||||||
let output_type = &self.output;
|
let output_type = &self.output;
|
||||||
let input_type = &self.input;
|
let input_type = &self.input;
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
#[cfg(target_arch = "spirv")]
|
#[cfg(target_arch = "spirv")]
|
||||||
pub mod gpu {
|
pub mod gpu {
|
||||||
//#![deny(warnings)]
|
//#![deny(warnings)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct PushConsts {
|
pub struct PushConsts {
|
||||||
n: u32,
|
n: u32,
|
||||||
node: u32,
|
node: u32,
|
||||||
}
|
}
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
use spirv_std::glam::UVec3;
|
use spirv_std::glam::UVec3;
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
#[spirv(compute(threads(64)))]
|
#[spirv(compute(threads(64)))]
|
||||||
pub fn #name(
|
pub fn #name(
|
||||||
#[spirv(global_invocation_id)] global_id: UVec3,
|
#[spirv(global_invocation_id)] global_id: UVec3,
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] a: &[#input_type],
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 0)] a: &[#input_type],
|
||||||
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] y: &mut [#output_type],
|
#[spirv(storage_buffer, descriptor_set = 0, binding = 1)] y: &mut [#output_type],
|
||||||
#[spirv(push_constant)] push_consts: &PushConsts,
|
#[spirv(push_constant)] push_consts: &PushConsts,
|
||||||
) {
|
) {
|
||||||
#function
|
#function
|
||||||
let gid = global_id.x as usize;
|
let gid = global_id.x as usize;
|
||||||
// Only process up to n, which is the length of the buffers.
|
// Only process up to n, which is the length of the buffers.
|
||||||
if global_id.x < push_consts.n {
|
if global_id.x < push_consts.n {
|
||||||
y[gid] = node_graph(a[gid]);
|
y[gid] = node_graph(a[gid]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,36 +4,36 @@ use std::marker::PhantomData;
|
||||||
|
|
||||||
/// Caches the output of a given Node and acts as a proxy
|
/// Caches the output of a given Node and acts as a proxy
|
||||||
pub struct CacheNode<'n, CachedNode: Node<'n>> {
|
pub struct CacheNode<'n, CachedNode: Node<'n>> {
|
||||||
node: CachedNode,
|
node: CachedNode,
|
||||||
cache: OnceCell<CachedNode::Output>,
|
cache: OnceCell<CachedNode::Output>,
|
||||||
_phantom: PhantomData<&'n ()>,
|
_phantom: PhantomData<&'n ()>,
|
||||||
}
|
}
|
||||||
impl<'n, CashedNode: Node<'n>> Node<'n> for CacheNode<'n, CashedNode>
|
impl<'n, CashedNode: Node<'n>> Node<'n> for CacheNode<'n, CashedNode>
|
||||||
where
|
where
|
||||||
CashedNode::Output: 'n,
|
CashedNode::Output: 'n,
|
||||||
{
|
{
|
||||||
type Output = &'n CashedNode::Output;
|
type Output = &'n CashedNode::Output;
|
||||||
fn eval(&'n self) -> Self::Output {
|
fn eval(&'n self) -> Self::Output {
|
||||||
self.cache.get_or_init(|| self.node.eval())
|
self.cache.get_or_init(|| self.node.eval())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'n, CachedNode: Node<'n>> CacheNode<'n, CachedNode> {
|
impl<'n, CachedNode: Node<'n>> CacheNode<'n, CachedNode> {
|
||||||
pub fn clear(&'n mut self) {
|
pub fn clear(&'n mut self) {
|
||||||
self.cache = OnceCell::new();
|
self.cache = OnceCell::new();
|
||||||
}
|
}
|
||||||
pub fn new(node: CachedNode) -> CacheNode<'n, CachedNode> {
|
pub fn new(node: CachedNode) -> CacheNode<'n, CachedNode> {
|
||||||
CacheNode {
|
CacheNode {
|
||||||
node,
|
node,
|
||||||
cache: OnceCell::new(),
|
cache: OnceCell::new(),
|
||||||
_phantom: PhantomData,
|
_phantom: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'n, CachedNode: Node<'n>> Cache for CacheNode<'n, CachedNode> {
|
impl<'n, CachedNode: Node<'n>> Cache for CacheNode<'n, CachedNode> {
|
||||||
fn clear(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.cache = OnceCell::new();
|
self.cache = OnceCell::new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*use dyn_any::{DynAny, StaticType};
|
/*use dyn_any::{DynAny, StaticType};
|
||||||
|
|
|
||||||
|
|
@ -7,43 +7,43 @@ use dyn_any::{DynAny, StaticType, StaticTypeSized};
|
||||||
pub struct AnyRefNode<'n, N: Node<'n>>(N, PhantomData<&'n ()>);
|
pub struct AnyRefNode<'n, N: Node<'n>>(N, PhantomData<&'n ()>);
|
||||||
|
|
||||||
impl<'n, N: Node<'n, Output = &'n O>, O: DynAny<'n> + 'n> Node<'n> for AnyRefNode<'n, N> {
|
impl<'n, N: Node<'n, Output = &'n O>, O: DynAny<'n> + 'n> Node<'n> for AnyRefNode<'n, N> {
|
||||||
type Output = &'n (dyn DynAny<'n>);
|
type Output = &'n (dyn DynAny<'n>);
|
||||||
fn eval(&'n self) -> Self::Output {
|
fn eval(&'n self) -> Self::Output {
|
||||||
let value: &O = self.0.eval();
|
let value: &O = self.0.eval();
|
||||||
value
|
value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'n, N: Node<'n, Output = &'n O>, O: 'n + ?Sized> AnyRefNode<'n, N> {
|
impl<'n, N: Node<'n, Output = &'n O>, O: 'n + ?Sized> AnyRefNode<'n, N> {
|
||||||
pub fn new(n: N) -> AnyRefNode<'n, N> {
|
pub fn new(n: N) -> AnyRefNode<'n, N> {
|
||||||
AnyRefNode(n, PhantomData)
|
AnyRefNode(n, PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StorageNode<'n>(&'n dyn Node<'n, Output = &'n dyn DynAny<'n>>);
|
pub struct StorageNode<'n>(&'n dyn Node<'n, Output = &'n dyn DynAny<'n>>);
|
||||||
|
|
||||||
impl<'n> Node<'n> for StorageNode<'n> {
|
impl<'n> Node<'n> for StorageNode<'n> {
|
||||||
type Output = &'n (dyn DynAny<'n>);
|
type Output = &'n (dyn DynAny<'n>);
|
||||||
fn eval(&'n self) -> Self::Output {
|
fn eval(&'n self) -> Self::Output {
|
||||||
self.0.eval()
|
self.0.eval()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<'n> StorageNode<'n> {
|
impl<'n> StorageNode<'n> {
|
||||||
pub fn new<N: Node<'n, Output = &'n dyn DynAny<'n>>>(n: &'n N) -> StorageNode<'n> {
|
pub fn new<N: Node<'n, Output = &'n dyn DynAny<'n>>>(n: &'n N) -> StorageNode<'n> {
|
||||||
StorageNode(n)
|
StorageNode(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct AnyValueNode<'n, T>(T, PhantomData<&'n ()>);
|
pub struct AnyValueNode<'n, T>(T, PhantomData<&'n ()>);
|
||||||
impl<'n, T: 'n + DynAny<'n>> Node<'n> for AnyValueNode<'n, T> {
|
impl<'n, T: 'n + DynAny<'n>> Node<'n> for AnyValueNode<'n, T> {
|
||||||
type Output = &'n dyn DynAny<'n>;
|
type Output = &'n dyn DynAny<'n>;
|
||||||
fn eval(&'n self) -> &'n dyn DynAny<'n> {
|
fn eval(&'n self) -> &'n dyn DynAny<'n> {
|
||||||
&self.0
|
&self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'n, T> AnyValueNode<'n, T> {
|
impl<'n, T> AnyValueNode<'n, T> {
|
||||||
pub const fn new(value: T) -> AnyValueNode<'n, T> {
|
pub const fn new(value: T) -> AnyValueNode<'n, T> {
|
||||||
AnyValueNode(value, PhantomData)
|
AnyValueNode(value, PhantomData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "graph-proc-macros"
|
name = "graph-proc-macros"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Dennis Kobert <dennis@kobert.dev>"]
|
authors = ["Graphite Authors <contact@graphite.rs>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,9 @@ pub fn to_node(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
let string = item.to_string();
|
let string = item.to_string();
|
||||||
let item2 = item;
|
let item2 = item;
|
||||||
let parsed = parse_macro_input!(item2 as ItemFn); // 3
|
let parsed = parse_macro_input!(item2 as ItemFn); // 3
|
||||||
//item.extend(generate_to_string(parsed, string)); // 4
|
|
||||||
//item
|
//item.extend(generate_to_string(parsed, string)); // 4
|
||||||
|
//item
|
||||||
generate_to_string(parsed, string)
|
generate_to_string(parsed, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +41,8 @@ fn generate_to_string(parsed: ItemFn, string: String) -> TokenStream {
|
||||||
let whole_function = parsed.clone();
|
let whole_function = parsed.clone();
|
||||||
//let fn_body = parsed.block; // function body
|
//let fn_body = parsed.block; // function body
|
||||||
let sig = parsed.sig; // function signature
|
let sig = parsed.sig; // function signature
|
||||||
//let vis = parsed.vis; // visibility, pub or not
|
|
||||||
|
//let vis = parsed.vis; // visibility, pub or not
|
||||||
let generics = sig.generics;
|
let generics = sig.generics;
|
||||||
let fn_args = sig.inputs; // comma separated args
|
let fn_args = sig.inputs; // comma separated args
|
||||||
let fn_return_type = sig.output; // return type
|
let fn_return_type = sig.output; // return type
|
||||||
|
|
@ -78,19 +80,18 @@ fn generate_to_string(parsed: ItemFn, string: String) -> TokenStream {
|
||||||
}
|
}
|
||||||
fn #node_fn_name #generics() -> Node<'static> {
|
fn #node_fn_name #generics() -> Node<'static> {
|
||||||
Node { func: Box::new(move |x| {
|
Node { func: Box::new(move |x| {
|
||||||
let args = x.downcast::<(#(#types,)*)>().expect(#error);
|
let args = x.downcast::<(#(#types,)*)>().expect(#error);
|
||||||
let (#(#idents,)*) = *args;
|
let (#(#idents,)*) = *args;
|
||||||
#whole_function
|
#whole_function
|
||||||
|
|
||||||
Box::new(#fn_name(#(#idents,)*))
|
Box::new(#fn_name(#(#idents,)*))
|
||||||
}),
|
}),
|
||||||
code: #string.to_string(),
|
code: #string.to_string(),
|
||||||
return_type: #return_type_string.trim().to_string(),
|
return_type: #return_type_string.trim().to_string(),
|
||||||
args: format!("({})",#arg_type_string.trim()),
|
args: format!("({})",#arg_type_string.trim()),
|
||||||
position: (0., 0.),
|
position: (0., 0.),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
//panic!("{}\n{:?}", x.to_string(), x);
|
//panic!("{}\n{:?}", x.to_string(), x);
|
||||||
x.into()
|
x.into()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue