Skip to content

Commit fc21991

Browse files
committed
Remove type from NodeInput::Network
1 parent ff8fec6 commit fc21991

File tree

14 files changed

+53
-54
lines changed

14 files changed

+53
-54
lines changed

editor/src/messages/portfolio/document/utility_types/network_interface.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,10 +3421,7 @@ impl NodeNetworkInterface {
34213421
pub fn create_wire(&mut self, output_connector: &OutputConnector, input_connector: &InputConnector, network_path: &[NodeId]) {
34223422
let input = match output_connector {
34233423
OutputConnector::Node { node_id, output_index } => NodeInput::node(*node_id, *output_index),
3424-
OutputConnector::Import(import_index) => NodeInput::Network {
3425-
import_type: graph_craft::generic!(T),
3426-
import_index: *import_index,
3427-
},
3424+
OutputConnector::Import(import_index) => NodeInput::Network { import_index: *import_index },
34283425
};
34293426

34303427
self.set_input(input_connector, input, network_path);

editor/src/node_graph_executor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl NodeRuntime {
229229
// We assume only one output
230230
assert_eq!(scoped_network.exports.len(), 1, "Graph with multiple outputs not yet handled");
231231
let c = Compiler {};
232-
let proto_network = match c.compile_single(scoped_network) {
232+
let proto_network = match c.compile_single(scoped_network, &[concrete!(RenderConfig)]) {
233233
Ok(network) => network,
234234
Err(e) => return Err(e),
235235
};

frontend/src/components/widgets/inputs/NumberInput.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// Number presentation
3131
export let displayDecimalPlaces = 2;
3232
export let unit = "";
33+
$: console.info("new unit", unit);
3334
export let unitIsHiddenWhenEditing = true;
3435
3536
// Mode behavior

node-graph/compilation-client/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ fn main() {
1313

1414
let network = add_network();
1515
let compiler = graph_craft::graphene_compiler::Compiler {};
16-
let proto_network = compiler.compile_single(network).unwrap();
16+
let input_types = vec![concrete!(Color), concrete!(Color), concrete!(u32)];
17+
let proto_network = compiler.compile_single(network, &input_types).unwrap();
1718

1819
let io = ShaderIO {
1920
inputs: vec![
@@ -25,7 +26,7 @@ fn main() {
2526
output: ShaderInput::OutputBuffer((), concrete!(Color)),
2627
};
2728

28-
let compile_request = CompileRequest::new(vec![proto_network], vec![concrete!(Color), concrete!(Color), concrete!(u32)], vec![concrete!(Color)], io);
29+
let compile_request = CompileRequest::new(vec![proto_network], input_types, vec![concrete!(Color)], io);
2930
let response = client
3031
.post("http://localhost:3000/compile/spirv")
3132
.timeout(Duration::from_secs(30))

node-graph/graph-craft/benches/compile_demo_art_criterion.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
use criterion::{black_box, criterion_group, criterion_main, Criterion};
22
use graph_craft::util::DEMO_ART;
33
fn compile_to_proto(c: &mut Criterion) {
4-
use graph_craft::util::{compile, load_from_name};
4+
use graph_craft::util::{compile_with_render_config, load_from_name};
55
let mut c = c.benchmark_group("Compile Network cold");
66

77
for name in DEMO_ART {
88
let network = load_from_name(name);
9-
c.bench_function(name, |b| b.iter_batched(|| network.clone(), |network| compile(black_box(network)), criterion::BatchSize::SmallInput));
9+
c.bench_function(name, |b| {
10+
b.iter_batched(|| network.clone(), |network| compile_with_render_config(black_box(network)), criterion::BatchSize::SmallInput)
11+
});
1012
}
1113
}
1214

node-graph/graph-craft/benches/compile_demo_art_iai.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use iai_callgrind::{black_box, library_benchmark, library_benchmark_group, main}
55
#[library_benchmark]
66
#[benches::with_setup(args = ["isometric-fountain", "painted-dreams", "procedural-string-lights", "red-dress", "valley-of-spires"], setup = load_from_name)]
77
pub fn compile_to_proto(_input: NodeNetwork) {
8-
black_box(compile(_input));
8+
black_box(compile_with_render_config(_input));
99
}
1010

1111
library_benchmark_group!(name = compile_group; benchmarks = compile_to_proto);

node-graph/graph-craft/src/document.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl DocumentNode {
286286
}
287287
}
288288

289-
fn resolve_proto_node(mut self) -> ProtoNode {
289+
fn resolve_proto_node(mut self, global_import_types: &[Type]) -> ProtoNode {
290290
assert!(!self.inputs.is_empty() || self.manual_composition.is_some(), "Resolving document node {self:#?} with no inputs");
291291
let DocumentNodeImplementation::ProtoNode(fqn) = self.implementation else {
292292
unreachable!("tried to resolve not flattened node on resolved node {self:?}");
@@ -311,7 +311,10 @@ impl DocumentNode {
311311
let node = if lambda { ProtoNodeInput::NodeLambda(node_id) } else { ProtoNodeInput::Node(node_id) };
312312
(node, ConstructionArgs::Nodes(vec![]))
313313
}
314-
NodeInput::Network { import_type, .. } => (ProtoNodeInput::ManualComposition(import_type), ConstructionArgs::Nodes(vec![])),
314+
NodeInput::Network { import_index } => {
315+
let ty = global_import_types.get(import_index).expect("import index in global_import_types").clone();
316+
(ProtoNodeInput::ManualComposition(ty), ConstructionArgs::Nodes(vec![]))
317+
}
315318
NodeInput::Inline(inline) => (ProtoNodeInput::None, ConstructionArgs::Inline(inline)),
316319
NodeInput::Scope(_) => unreachable!("Scope input was not resolved"),
317320
NodeInput::Reflection(_) => unreachable!("Reflection input was not resolved"),
@@ -355,9 +358,8 @@ pub enum NodeInput {
355358
/// A hardcoded value that can't change after the graph is compiled. Gets converted into a value node during graph compilation.
356359
Value { tagged_value: MemoHash<TaggedValue>, exposed: bool },
357360

358-
// TODO: Remove import_type and get type from parent node input
359361
/// Input that is provided by the parent network to this document node, instead of from a hardcoded value or another node within the same network.
360-
Network { import_type: Type, import_index: usize },
362+
Network { import_index: usize },
361363

362364
/// Input that is extracted from the parent scopes the node resides in. The string argument is the key.
363365
Scope(Cow<'static, str>),
@@ -403,8 +405,8 @@ impl NodeInput {
403405
Self::Value { tagged_value, exposed }
404406
}
405407

406-
pub const fn network(import_type: Type, import_index: usize) -> Self {
407-
Self::Network { import_type, import_index }
408+
pub fn network(_import_type: Type, import_index: usize) -> Self {
409+
Self::Network { import_index }
408410
}
409411

410412
pub fn scope(key: impl Into<Cow<'static, str>>) -> Self {
@@ -447,7 +449,7 @@ impl NodeInput {
447449
match self {
448450
NodeInput::Node { .. } => unreachable!("ty() called on NodeInput::Node"),
449451
NodeInput::Value { tagged_value, .. } => tagged_value.ty(),
450-
NodeInput::Network { import_type, .. } => import_type.clone(),
452+
NodeInput::Network { .. } => unreachable!("ty() called on NodeInput::Network"),
451453
NodeInput::Inline(_) => panic!("ty() called on NodeInput::Inline"),
452454
NodeInput::Scope(_) => unreachable!("ty() called on NodeInput::Scope"),
453455
NodeInput::Reflection(_) => concrete!(Metadata),
@@ -1312,8 +1314,8 @@ impl NodeNetwork {
13121314
}
13131315

13141316
/// Creates a proto network for evaluating each output of this network.
1315-
pub fn into_proto_networks(self) -> impl Iterator<Item = ProtoNetwork> {
1316-
let nodes: Vec<_> = self.nodes.into_iter().map(|(id, node)| (id, node.resolve_proto_node())).collect();
1317+
pub fn into_proto_networks(self, global_import_types: &[Type]) -> impl Iterator<Item = ProtoNetwork> {
1318+
let nodes: Vec<_> = self.nodes.into_iter().map(|(id, node)| (id, node.resolve_proto_node(global_import_types))).collect();
13171319

13181320
// Create a network to evaluate each output
13191321
if self.exports.len() == 1 {
@@ -1507,7 +1509,7 @@ mod test {
15071509
..Default::default()
15081510
};
15091511

1510-
let proto_node = document_node.resolve_proto_node();
1512+
let proto_node = document_node.resolve_proto_node(&[concrete!(u32)]);
15111513
let reference = ProtoNode {
15121514
identifier: "graphene_core::structural::ConsNode".into(),
15131515
input: ProtoNodeInput::ManualComposition(concrete!(u32)),
@@ -1577,7 +1579,7 @@ mod test {
15771579
.collect(),
15781580
};
15791581
let network = flat_network();
1580-
let mut resolved_network = network.into_proto_networks().collect::<Vec<_>>();
1582+
let mut resolved_network = network.into_proto_networks(&[concrete!(u32)]).collect::<Vec<_>>();
15811583
resolved_network[0].nodes.sort_unstable_by_key(|(id, _)| *id);
15821584

15831585
println!("{:#?}", resolved_network[0]);

node-graph/graph-craft/src/graphene_compiler.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::proto::{LocalFuture, ProtoNetwork};
66
pub struct Compiler {}
77

88
impl Compiler {
9-
pub fn compile(&self, mut network: NodeNetwork) -> impl Iterator<Item = Result<ProtoNetwork, String>> {
9+
pub fn compile(&self, mut network: NodeNetwork, global_import_types: &[crate::Type]) -> impl Iterator<Item = Result<ProtoNetwork, String>> {
1010
let node_ids = network.nodes.keys().copied().collect::<Vec<_>>();
1111
network.populate_dependants();
1212
for id in node_ids {
@@ -15,17 +15,17 @@ impl Compiler {
1515
network.resolve_scope_inputs();
1616
network.remove_redundant_id_nodes();
1717
// network.remove_dead_nodes(0);
18-
let proto_networks = network.into_proto_networks();
18+
let proto_networks = network.into_proto_networks(global_import_types);
1919

2020
proto_networks.map(move |mut proto_network| {
2121
proto_network.resolve_inputs()?;
2222
proto_network.generate_stable_node_ids();
2323
Ok(proto_network)
2424
})
2525
}
26-
pub fn compile_single(&self, network: NodeNetwork) -> Result<ProtoNetwork, String> {
26+
pub fn compile_single(&self, network: NodeNetwork, global_import_types: &[crate::Type]) -> Result<ProtoNetwork, String> {
2727
assert_eq!(network.exports.len(), 1, "Graph with multiple outputs not yet handled");
28-
let Some(proto_network) = self.compile(network).next() else {
28+
let Some(proto_network) = self.compile(network, global_import_types).next() else {
2929
return Err("Failed to convert graph into proto graph".to_string());
3030
};
3131
proto_network

node-graph/graph-craft/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ pub fn load_network(document_string: &str) -> NodeNetwork {
77
serde_json::from_value::<NodeNetwork>(document["network_interface"]["network"].clone()).expect("Failed to parse document")
88
}
99

10-
pub fn compile(network: NodeNetwork) -> ProtoNetwork {
10+
pub fn compile_with_render_config(network: NodeNetwork) -> ProtoNetwork {
1111
let compiler = Compiler {};
12-
compiler.compile_single(network).unwrap()
12+
compiler.compile_single(network, &[concrete!(graphene_core::application_io::RenderConfig)]).unwrap()
1313
}
1414

1515
pub fn load_from_name(name: &str) -> NodeNetwork {

node-graph/graphene-cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use graph_craft::document::*;
21
use graph_craft::graphene_compiler::{Compiler, Executor};
32
use graph_craft::util::load_network;
43
use graph_craft::wasm_application_io::EditorPreferences;
4+
use graph_craft::{concrete, document::*};
55
use graphene_core::application_io::{ApplicationIo, NodeGraphUpdateSender};
66
use graphene_core::text::FontCache;
77
use graphene_std::wasm_application_io::{WasmApplicationIo, WasmEditorApi};
@@ -105,7 +105,7 @@ fn create_executor(document_string: String, editor_api: Arc<WasmEditorApi>) -> R
105105

106106
let wrapped_network = wrap_network_in_scope(network.clone(), editor_api);
107107
let compiler = Compiler {};
108-
let protograph = compiler.compile_single(wrapped_network)?;
108+
let protograph = compiler.compile_single(wrapped_network, &[concrete!(graphene_core::application_io::RenderConfig)])?;
109109
let executor = block_on(DynamicExecutor::new(protograph)).unwrap();
110110
Ok(executor)
111111
}

node-graph/gstd/src/gpu_nodes.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,17 @@ use crate::wasm_application_io::WasmApplicationIo;
1818

1919
// TODO: Move to graph-craft
2020
#[node_macro::node(category("Debug: GPU"))]
21-
async fn compile_gpu<'a: 'n>(_: (), node: &'a DocumentNode, typing_context: TypingContext, io: ShaderIO) -> Result<compilation_client::Shader, String> {
21+
async fn compile_gpu<'a: 'n>(_: (), node: &'a DocumentNode, typing_context: TypingContext, input_types: Vec<Type>, io: ShaderIO) -> Result<compilation_client::Shader, String> {
2222
let mut typing_context = typing_context;
2323
let compiler = graph_craft::graphene_compiler::Compiler {};
2424
let DocumentNodeImplementation::Network(ref network) = node.implementation else { panic!() };
25-
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone()).collect();
25+
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone(), &input_types).collect();
2626
let proto_networks = proto_networks?;
2727

2828
for network in proto_networks.iter() {
2929
typing_context.update(network).expect("Failed to type check network");
3030
}
3131
// TODO: do a proper union
32-
let input_types = proto_networks[0]
33-
.inputs
34-
.iter()
35-
.map(|id| typing_context.type_of(*id).unwrap())
36-
.map(|node_io| node_io.return_value.clone())
37-
.collect();
3832
let output_types = proto_networks.iter().map(|network| typing_context.type_of(network.output).unwrap().return_value.clone()).collect();
3933

4034
Ok(compilation_client::compile(proto_networks, input_types, output_types, io).await.unwrap())
@@ -187,11 +181,12 @@ async fn create_compute_pass_descriptor<T: Clone + Pixel + StaticTypeSized>(node
187181
..Default::default()
188182
};
189183
log::debug!("compiling network");
190-
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone()).collect();
184+
let global_input_types = vec![concrete!(u32), concrete!(Color)];
185+
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone(), &global_input_types).collect();
191186
log::debug!("compiling shader");
192187
let shader = compilation_client::compile(
193188
proto_networks?,
194-
vec![concrete!(u32), concrete!(Color)],
189+
global_input_types,
195190
vec![concrete!(Color)],
196191
ShaderIO {
197192
inputs: vec![
@@ -317,7 +312,15 @@ async fn blend_gpu_image(_: (), foreground: ImageFrame<Color>, background: Image
317312
..Default::default()
318313
};
319314
log::debug!("compiling network");
320-
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone()).collect();
315+
let global_input_types = vec![
316+
concrete!(u32),
317+
concrete!(Color),
318+
concrete!(Color),
319+
concrete!(u32),
320+
concrete_with_name!(Mat2, "Mat2"),
321+
concrete_with_name!(Vec2, "Vec2"),
322+
];
323+
let proto_networks: Result<Vec<_>, _> = compiler.compile(network.clone(), &global_input_types).collect();
321324
let Ok(proto_networks_result) = proto_networks else {
322325
log::error!("Error compiling network in 'blend_gpu_image()");
323326
return ImageFrame::empty();
@@ -327,14 +330,7 @@ async fn blend_gpu_image(_: (), foreground: ImageFrame<Color>, background: Image
327330

328331
let shader = compilation_client::compile(
329332
proto_networks,
330-
vec![
331-
concrete!(u32),
332-
concrete!(Color),
333-
concrete!(Color),
334-
concrete!(u32),
335-
concrete_with_name!(Mat2, "Mat2"),
336-
concrete_with_name!(Vec2, "Vec2"),
337-
],
333+
global_input_types,
338334
vec![concrete!(Color)],
339335
ShaderIO {
340336
inputs: vec![

node-graph/interpreted-executor/benches/benchmark_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use criterion::{measurement::Measurement, BenchmarkGroup};
22
use futures::executor::block_on;
33
use graph_craft::{
44
proto::ProtoNetwork,
5-
util::{compile, load_from_name, DEMO_ART},
5+
util::{compile_with_render_config, load_from_name, DEMO_ART},
66
};
77
use interpreted_executor::dynamic_executor::DynamicExecutor;
88

99
pub fn setup_network(name: &str) -> (DynamicExecutor, ProtoNetwork) {
1010
let network = load_from_name(name);
11-
let proto_network = compile(network);
11+
let proto_network = compile_with_render_config(network);
1212
let executor = block_on(DynamicExecutor::new(proto_network.clone())).unwrap();
1313
(executor, proto_network)
1414
}

node-graph/interpreted-executor/benches/run_demo_art_criterion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use criterion::{black_box, criterion_group, criterion_main, measurement::Measure
22
use graph_craft::{
33
graphene_compiler::Executor,
44
proto::ProtoNetwork,
5-
util::{compile, load_from_name, DEMO_ART},
5+
util::{compile_with_render_config, load_from_name, DEMO_ART},
66
};
77
use graphene_std::transform::Footprint;
88
use interpreted_executor::dynamic_executor::DynamicExecutor;
99

1010
fn update_executor<M: Measurement>(name: &str, c: &mut BenchmarkGroup<M>) {
1111
let network = load_from_name(name);
12-
let proto_network = compile(network);
12+
let proto_network = compile_with_render_config(network);
1313
let empty = ProtoNetwork::default();
1414

1515
let executor = futures::executor::block_on(DynamicExecutor::new(empty)).unwrap();
@@ -32,7 +32,7 @@ fn update_executor_demo(c: &mut Criterion) {
3232

3333
fn run_once<M: Measurement>(name: &str, c: &mut BenchmarkGroup<M>) {
3434
let network = load_from_name(name);
35-
let proto_network = compile(network);
35+
let proto_network = compile_with_render_config(network);
3636

3737
let executor = futures::executor::block_on(DynamicExecutor::new(proto_network)).unwrap();
3838
let footprint = Footprint::default();

node-graph/interpreted-executor/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ mod tests {
4444
use graph_craft::graphene_compiler::Compiler;
4545

4646
let compiler = Compiler {};
47-
let protograph = compiler.compile_single(network).expect("Graph should be generated");
47+
let protograph = compiler.compile_single(network, &[concrete!(u32)]).expect("Graph should be generated");
4848

4949
let _exec = block_on(DynamicExecutor::new(protograph)).map(|_e| panic!("The network should not type check ")).unwrap_err();
5050
}

0 commit comments

Comments
 (0)