mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-23 07:35:02 +00:00
Evaluate extract node before flattening the network
This commit is contained in:
parent
069af07d32
commit
59e70cd812
5 changed files with 29 additions and 35 deletions
|
@ -1761,7 +1761,9 @@ impl DocumentNodeType {
|
||||||
|
|
||||||
let inner_network = match &self.identifier {
|
let inner_network = match &self.identifier {
|
||||||
NodeImplementation::DocumentNode(network) => network.clone(),
|
NodeImplementation::DocumentNode(network) => network.clone(),
|
||||||
NodeImplementation::ProtoNode(ident) => {
|
|
||||||
|
NodeImplementation::ProtoNode(ident) => return DocumentNodeImplementation::Unresolved(ident.clone()),
|
||||||
|
/*
|
||||||
NodeNetwork {
|
NodeNetwork {
|
||||||
inputs: (0..num_inputs).map(|_| 0).collect(),
|
inputs: (0..num_inputs).map(|_| 0).collect(),
|
||||||
outputs: vec![NodeOutput::new(0, 0)],
|
outputs: vec![NodeOutput::new(0, 0)],
|
||||||
|
@ -1779,23 +1781,10 @@ impl DocumentNodeType {
|
||||||
.collect(),
|
.collect(),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
NodeImplementation::Extract => NodeNetwork {
|
*/
|
||||||
inputs: (0..num_inputs).map(|_| 0).collect(),
|
NodeImplementation::Extract => return DocumentNodeImplementation::Extract,
|
||||||
outputs: vec![NodeOutput::new(0, 0)],
|
|
||||||
nodes: [(
|
|
||||||
0,
|
|
||||||
DocumentNode {
|
|
||||||
name: "ExtractNode".to_string(),
|
|
||||||
implementation: DocumentNodeImplementation::Extract,
|
|
||||||
inputs: self.inputs.iter().map(|i| NodeInput::Network(i.default.ty())).collect(),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
)]
|
|
||||||
.into_iter()
|
|
||||||
.collect(),
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DocumentNodeImplementation::Network(inner_network)
|
DocumentNodeImplementation::Network(inner_network)
|
||||||
|
@ -1824,9 +1813,11 @@ impl DocumentNodeType {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wrap_network_in_scope(mut network: NodeNetwork) -> NodeNetwork {
|
pub fn wrap_network_in_scope(mut network: NodeNetwork) -> NodeNetwork {
|
||||||
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
|
||||||
|
|
||||||
network.generate_node_paths(&[]);
|
network.generate_node_paths(&[]);
|
||||||
|
network.resolve_extract_nodes();
|
||||||
|
|
||||||
|
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
||||||
for id in node_ids {
|
for id in node_ids {
|
||||||
network.flatten(id);
|
network.flatten(id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,13 +321,6 @@ fn grayscale_color_node(color: Color, tint: Color, reds: f64, yellows: f64, gree
|
||||||
color.to_linear_srgb()
|
color.to_linear_srgb()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "spirv"))]
|
|
||||||
pub use hue_shift::HueSaturationNode;
|
|
||||||
|
|
||||||
// TODO: Make this work on GPU so it can be removed from the wrapper module that excludes GPU (it doesn't work because of the modulo)
|
|
||||||
#[cfg(not(target_arch = "spirv"))]
|
|
||||||
mod hue_shift {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct HueSaturationNode<Hue, Saturation, Lightness> {
|
pub struct HueSaturationNode<Hue, Saturation, Lightness> {
|
||||||
|
@ -353,7 +346,6 @@ mod hue_shift {
|
||||||
|
|
||||||
color.to_linear_srgb()
|
color.to_linear_srgb()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct InvertRGBNode;
|
pub struct InvertRGBNode;
|
||||||
|
|
|
@ -99,7 +99,7 @@ impl DocumentNode {
|
||||||
document_node_path: self.path.unwrap_or(Vec::new()),
|
document_node_path: self.path.unwrap_or(Vec::new()),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unreachable!("tried to resolve not flattened node on resolved node");
|
unreachable!("tried to resolve not flattened node on resolved node {:?}", self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,6 +665,7 @@ impl NodeNetwork {
|
||||||
self.nodes.insert(id, node);
|
self.nodes.insert(id, node);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
log::debug!("Flattening node {:?}", &node);
|
||||||
|
|
||||||
// replace value inputs with value nodes
|
// replace value inputs with value nodes
|
||||||
for input in &mut node.inputs {
|
for input in &mut node.inputs {
|
||||||
|
@ -706,6 +707,8 @@ impl NodeNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
if let DocumentNodeImplementation::Network(mut inner_network) = node.implementation {
|
if let DocumentNodeImplementation::Network(mut inner_network) = node.implementation {
|
||||||
|
// Resolve all extract nodes in the inner network
|
||||||
|
inner_network.resolve_extract_nodes();
|
||||||
// Connect all network inputs to either the parent network nodes, or newly created value nodes.
|
// Connect all network inputs to either the parent network nodes, or newly created value nodes.
|
||||||
inner_network.map_ids(|inner_id| map_ids(id, inner_id));
|
inner_network.map_ids(|inner_id| map_ids(id, inner_id));
|
||||||
let new_nodes = inner_network.nodes.keys().cloned().collect::<Vec<_>>();
|
let new_nodes = inner_network.nodes.keys().cloned().collect::<Vec<_>>();
|
||||||
|
@ -717,8 +720,10 @@ impl NodeNetwork {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
node.inputs.len(),
|
node.inputs.len(),
|
||||||
inner_network.inputs.len(),
|
inner_network.inputs.len(),
|
||||||
"The number of inputs to the node and the inner network must be the same {}",
|
"The number of inputs to the node and the inner network must be the same for {}. The node has {:?} inputs, the network has {:?} inputs.",
|
||||||
node.name
|
node.name,
|
||||||
|
node.inputs,
|
||||||
|
inner_network.inputs
|
||||||
);
|
);
|
||||||
// Match the document node input and the inputs of the inner network
|
// Match the document node input and the inputs of the inner network
|
||||||
for (document_input, network_input) in node.inputs.into_iter().zip(inner_network.inputs.iter()) {
|
for (document_input, network_input) in node.inputs.into_iter().zip(inner_network.inputs.iter()) {
|
||||||
|
@ -829,21 +834,27 @@ impl NodeNetwork {
|
||||||
self.nodes.retain(|_, node| !matches!(node.implementation, DocumentNodeImplementation::Extract));
|
self.nodes.retain(|_, node| !matches!(node.implementation, DocumentNodeImplementation::Extract));
|
||||||
|
|
||||||
for (_, node) in &mut extraction_nodes {
|
for (_, node) in &mut extraction_nodes {
|
||||||
|
log::info!("extraction network: {:#?}", &self);
|
||||||
if let DocumentNodeImplementation::Extract = node.implementation {
|
if let DocumentNodeImplementation::Extract = node.implementation {
|
||||||
assert_eq!(node.inputs.len(), 1);
|
assert_eq!(node.inputs.len(), 1);
|
||||||
|
log::debug!("Resolving extract node {:?}", node);
|
||||||
let NodeInput::Node { node_id, output_index, .. } = node.inputs.pop().unwrap() else {
|
let NodeInput::Node { node_id, output_index, .. } = node.inputs.pop().unwrap() else {
|
||||||
panic!("Extract node has no input");
|
panic!("Extract node has no input, inputs: {:?}", node.inputs);
|
||||||
};
|
};
|
||||||
assert_eq!(output_index, 0);
|
assert_eq!(output_index, 0);
|
||||||
// TODO: check if we can readd lambda checking
|
// TODO: check if we can readd lambda checking
|
||||||
let mut input_node = self.nodes.remove(&node_id).unwrap();
|
let mut input_node = self.nodes.remove(&node_id).unwrap();
|
||||||
node.implementation = DocumentNodeImplementation::Unresolved("graphene_core::value::ValueNode".into());
|
node.implementation = DocumentNodeImplementation::Unresolved("graphene_core::value::ValueNode".into());
|
||||||
|
if let Some(input) = input_node.inputs.get_mut(0) {
|
||||||
|
*input = NodeInput::Network(input.ty());
|
||||||
|
}
|
||||||
|
|
||||||
for input in input_node.inputs.iter_mut() {
|
for input in input_node.inputs.iter_mut() {
|
||||||
match input {
|
if let NodeInput::Node { .. } = input {
|
||||||
NodeInput::Node { .. } | NodeInput::Value { .. } => *input = NodeInput::Network(generic!(T)),
|
*input = NodeInput::Network(generic!(T))
|
||||||
_ => (),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log::debug!("Extract node {:?} resolved to {:?}", node, input_node);
|
||||||
node.inputs = vec![NodeInput::value(TaggedValue::DocumentNode(input_node), false)];
|
node.inputs = vec![NodeInput::value(TaggedValue::DocumentNode(input_node), false)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ impl Compiler {
|
||||||
pub fn compile(&self, mut network: NodeNetwork, resolve_inputs: bool) -> impl Iterator<Item = ProtoNetwork> {
|
pub fn compile(&self, mut network: NodeNetwork, resolve_inputs: bool) -> impl Iterator<Item = ProtoNetwork> {
|
||||||
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
|
||||||
println!("flattening");
|
println!("flattening");
|
||||||
|
network.resolve_extract_nodes();
|
||||||
for id in node_ids {
|
for id in node_ids {
|
||||||
network.flatten(id);
|
network.flatten(id);
|
||||||
}
|
}
|
||||||
network.remove_redundant_id_nodes();
|
network.remove_redundant_id_nodes();
|
||||||
network.resolve_extract_nodes();
|
|
||||||
network.remove_dead_nodes();
|
network.remove_dead_nodes();
|
||||||
let proto_networks = network.into_proto_networks();
|
let proto_networks = network.into_proto_networks();
|
||||||
proto_networks.map(move |mut proto_network| {
|
proto_networks.map(move |mut proto_network| {
|
||||||
|
|
|
@ -287,7 +287,7 @@ impl gpu_executor::GpuExecutor for WgpuExecutor {
|
||||||
log::warn!("No surface formats available");
|
log::warn!("No surface formats available");
|
||||||
//return Ok(());
|
//return Ok(());
|
||||||
}
|
}
|
||||||
let config = self.surface_config.take().unwrap();
|
let Some(config) = self.surface_config.take() else {return Ok(())};
|
||||||
let new_config = config.clone();
|
let new_config = config.clone();
|
||||||
self.surface_config.replace(Some(config));
|
self.surface_config.replace(Some(config));
|
||||||
let output = match result {
|
let output = match result {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue