Skip to content

Commit cfd993e

Browse files
WIP
1 parent e3b81a2 commit cfd993e

10 files changed

Lines changed: 24 additions & 19 deletions

File tree

editor/src/node_graph_executor/runtime.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,13 @@ impl NodeRuntime {
345345
None
346346
}
347347

348-
async fn update_network(&mut self, mut graph: NodeNetwork) -> Result<ResolvedDocumentNodeTypesDelta, (ResolvedDocumentNodeTypesDelta, String)> {
349-
if let Err(e) = self.preprocessor.expand_network(&mut graph, &self.resources) {
348+
async fn update_network(&mut self, graph: NodeNetwork) -> Result<ResolvedDocumentNodeTypesDelta, (ResolvedDocumentNodeTypesDelta, String)> {
349+
let mut scoped_network = wrap_network_in_scope(graph, self.editor_api.clone());
350+
351+
if let Err(e) = self.preprocessor.expand_network(&mut scoped_network, &self.resources) {
350352
return Err((ResolvedDocumentNodeTypesDelta::default(), e.to_string()));
351353
}
352354

353-
let scoped_network = wrap_network_in_scope(graph, self.editor_api.clone());
354-
355355
// We assume only one output
356356
assert_eq!(scoped_network.exports.len(), 1, "Graph with multiple outputs not yet handled");
357357

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,15 +785,21 @@ impl NodeNetwork {
785785
}
786786

787787
pub fn resolve_scope_inputs(&mut self) {
788+
let mut import_ids = Vec::new();
788789
for node in self.nodes.values_mut() {
789790
for input in node.inputs.iter_mut() {
790791
if let NodeInput::Scope(key) = input {
791792
let (import_id, _ty) = self.scope_injections.get(key.as_ref()).expect("Tried to import a non existent key from scope");
793+
794+
import_ids.push(*import_id);
792795
// TODO use correct output index
793796
*input = NodeInput::node(*import_id, 0);
794797
}
795798
}
796799
}
800+
if !import_ids.iter().all(|id| self.nodes.contains_key(id)) {
801+
log::error!("Scope injections refer to non existent node ids {import_ids:?}");
802+
}
797803
}
798804

799805
/// Remove all nodes that contain [`DocumentNodeImplementation::Network`] by moving the nested nodes into the parent network.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,9 @@ fn compile_graph(document_string: String, editor_api: Arc<PlatformEditorApi>) ->
242242
let mut network = load_network(&document_string);
243243
fix_nodes(&mut network);
244244

245+
let mut wrapped_network = wrap_network_in_scope(network, editor_api);
245246
let preprocessor = preprocessor::Preprocessor::new();
246-
preprocessor.expand_network(&mut network, &ResourceRegistry::default()).expect("Failed to expand network"); // TODO: actually load the resources from the document
247-
248-
let wrapped_network = wrap_network_in_scope(network.clone(), editor_api);
247+
preprocessor.expand_network(&mut wrapped_network, &ResourceRegistry::default()).expect("Failed to expand network"); // TODO: actually load the resources from the document
249248

250249
let compiler = Compiler {};
251250
compiler.compile_single(wrapped_network).map_err(|x| x.into())

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ use interpreted_executor::dynamic_executor::DynamicExecutor;
99
use interpreted_executor::util::wrap_network_in_scope;
1010

1111
pub fn setup_network(name: &str) -> (DynamicExecutor, ProtoNetwork) {
12-
let mut network = load_from_name(name);
12+
let network = load_from_name(name);
1313
let editor_api = std::sync::Arc::new(EditorApi::default());
14+
let mut network = wrap_network_in_scope(network, editor_api);
1415
let preprocessor = preprocessor::Preprocessor::new();
1516
preprocessor.expand_network(&mut network, &ResourceRegistry::default()).unwrap();
16-
let network = wrap_network_in_scope(network, editor_api);
1717
let proto_network = compile(network);
1818
let executor = block_on(DynamicExecutor::new(proto_network.clone())).unwrap();
1919
(executor, proto_network)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
202202
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => CanvasHandle, Context => graphene_std::ContextFeatures]),
203203
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache<graphene_std::render_pixel_preview::PixelPreview>, Context => graphene_std::ContextFeatures]),
204204
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache<graphene_std::render_background::BackgroundCompositor>, Context => graphene_std::ContextFeatures]),
205-
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuExecutor, Context => graphene_std::ContextFeatures]),
205+
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => &wgpu_executor::WgpuExecutor, Context => graphene_std::ContextFeatures]),
206206
// ==========
207207
// MEMO NODES
208208
// ==========
@@ -290,7 +290,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
290290
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => RenderIntermediate]),
291291
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache<graphene_std::render_pixel_preview::PixelPreview>]),
292292
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache<graphene_std::render_background::BackgroundCompositor>]),
293-
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuExecutor]),
293+
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => &wgpu_executor::WgpuExecutor]),
294294
];
295295
// =============
296296
// CONVERT NODES

node-graph/nodes/gstd/src/platform_application_io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,6 @@ pub async fn resource<'a: 'n>(_: impl Ctx, hash: ResourceHash, #[scope("editor-a
270270
}
271271

272272
#[node_macro::node(category(""), inject_scope)]
273-
pub async fn wgpu_executor<'a: 'n>(_: impl Ctx, #[scope("editor-api")] editor_api: &'a PlatformEditorApi) -> ::wgpu_executor::WgpuExecutor {
274-
editor_api.application_io.as_ref().unwrap().gpu_executor().expect("GPU executor not available").clone()
273+
pub async fn wgpu_executor<'a: 'n>(_: impl Ctx, #[scope("editor-api")] editor_api: &'a PlatformEditorApi) -> &'a ::wgpu_executor::WgpuExecutor {
274+
editor_api.application_io.as_ref().unwrap().gpu_executor().expect("GPU executor not available")
275275
}

node-graph/nodes/gstd/src/render_background.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ async fn render_background<'a: 'n>(
118118
}
119119

120120
#[node_macro::node(category(""), inject_scope)]
121-
async fn background_compositor_pipeline(
121+
async fn background_compositor_pipeline<'a: 'n>(
122122
_ctx: impl Ctx,
123-
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: WgpuExecutor,
123+
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: &'a WgpuExecutor,
124124
#[data] pipeline: WgpuPipelineCache<BackgroundCompositor>,
125125
) -> WgpuPipelineCache<BackgroundCompositor> {
126126
executor.pipeline_init(pipeline);

node-graph/nodes/gstd/src/render_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn flood_fill(start: &TileCoord, tile_set: &HashSet<TileCoord>, visited: &mut Ha
326326
#[node_macro::node(category(""))]
327327
pub async fn render_output_cache<'a: 'n>(
328328
ctx: impl Ctx + ExtractAll + CloneVarArgs + ExtractRealTime + ExtractAnimationTime + ExtractPointerPosition + Sync,
329-
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: WgpuExecutor,
329+
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: &'a WgpuExecutor,
330330
#[scope("editor-api")] editor_api: &'a PlatformEditorApi,
331331
data: impl Node<Context<'static>, Output = RenderOutput> + Send + Sync,
332332
#[data] tile_cache: TileCache,

node-graph/nodes/gstd/src/render_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ async fn render_intermediate<'a: 'n, T: 'static + Render + WasmNotSend + Send +
7575
#[node_macro::node(category(""))]
7676
async fn render<'a: 'n>(
7777
ctx: impl Ctx + ExtractFootprint + ExtractVarArgs,
78-
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: WgpuExecutor,
78+
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: &'a WgpuExecutor,
7979
data: RenderIntermediate,
8080
) -> RenderOutput {
8181
let footprint = ctx.footprint();

node-graph/nodes/gstd/src/render_pixel_preview.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ pub async fn render_pixel_preview<'a: 'n>(
7575
}
7676

7777
#[node_macro::node(category(""), inject_scope)]
78-
async fn pixel_preview_pipeline(
78+
async fn pixel_preview_pipeline<'a: 'n>(
7979
_ctx: impl Ctx,
80-
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: WgpuExecutor,
80+
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: &'a WgpuExecutor,
8181
#[data] pipeline: WgpuPipelineCache<PixelPreview>,
8282
) -> WgpuPipelineCache<PixelPreview> {
8383
executor.pipeline_init(pipeline);

0 commit comments

Comments
 (0)