Skip to content

Commit 674b3a2

Browse files
Extract pipelines from WgpuExecutor into scope-provided pipeline nodes (#4210)
* Implement generic pipeline caching * Fix WIP * Fix * Fix * Fix * Fix bench * Migrations * Review
1 parent 3bf3244 commit 674b3a2

29 files changed

Lines changed: 629 additions & 443 deletions

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop/src/render/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) struct RenderState {
2929
impl RenderState {
3030
pub(crate) fn new(window: &Window, context: WgpuContext, present_mode: Option<PresentMode>) -> Self {
3131
let size = window.surface_size();
32-
let surface = window.create_surface(context.instance.clone());
32+
let surface = window.create_surface(&context.instance);
3333

3434
let surface_caps = surface.get_capabilities(&context.adapter);
3535
let surface_format = surface_caps.formats.iter().find(|f| f.is_srgb()).copied().unwrap_or(surface_caps.formats[0]);

desktop/src/window.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl Window {
8686
self.winit_window.request_redraw();
8787
}
8888

89-
pub(crate) fn create_surface(&self, instance: Arc<wgpu::Instance>) -> wgpu::Surface<'static> {
89+
pub(crate) fn create_surface(&self, instance: &wgpu::Instance) -> wgpu::Surface<'static> {
9090
instance.create_surface(self.winit_window.clone()).unwrap()
9191
}
9292

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
922922
exports: vec![NodeInput::node(NodeId(1), 0)],
923923
nodes: [
924924
DocumentNode {
925-
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::scope("editor-api"), NodeInput::import(concrete!(String), 1)],
925+
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::import(concrete!(String), 1)],
926926
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::load_resource::IDENTIFIER),
927927
..Default::default()
928928
},
@@ -1249,22 +1249,17 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
12491249
node_template: NodeTemplate {
12501250
document_node: DocumentNode {
12511251
implementation: DocumentNodeImplementation::Network(NodeNetwork {
1252-
exports: vec![NodeInput::node(NodeId(2), 0)],
1252+
exports: vec![NodeInput::node(NodeId(1), 0)],
12531253
nodes: [
12541254
DocumentNode {
1255-
inputs: vec![NodeInput::scope("editor-api")],
1256-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<&WgpuExecutor>")),
1257-
..Default::default()
1258-
},
1259-
DocumentNode {
1260-
inputs: vec![NodeInput::import(concrete!(List<Raster<CPU>>), 0), NodeInput::node(NodeId(0), 0)],
1255+
inputs: vec![NodeInput::import(concrete!(List<Raster<CPU>>), 0), NodeInput::scope(platform_application_io::wgpu_executor::IDENTIFIER)],
12611256
call_argument: generic!(T),
12621257
implementation: DocumentNodeImplementation::ProtoNode(wgpu_executor::texture_conversion::upload_texture::IDENTIFIER),
12631258
..Default::default()
12641259
},
12651260
DocumentNode {
12661261
call_argument: generic!(T),
1267-
inputs: vec![NodeInput::node(NodeId(1), 0)],
1262+
inputs: vec![NodeInput::node(NodeId(0), 0)],
12681263
implementation: DocumentNodeImplementation::ProtoNode(memo::memoize::IDENTIFIER),
12691264
..Default::default()
12701265
},

editor/src/messages/portfolio/document_migration.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,28 @@ fn migrate_node(node_id: &NodeId, node: &DocumentNode, network_path: &[NodeId],
23622362
}
23632363
}
23642364

2365+
// `load_resource` no longer takes the `editor-api`
2366+
if reference == DefinitionIdentifier::ProtoNode(graphene_std::platform_application_io::load_resource::IDENTIFIER) && inputs_count == 3 {
2367+
let mut node_template = resolve_document_node_type(&reference)?.default_node_template();
2368+
let old_inputs = document.network_interface.replace_inputs(node_id, network_path, &mut node_template)?;
2369+
2370+
document.network_interface.set_input(&InputConnector::node(*node_id, 0), old_inputs[0].clone(), network_path);
2371+
document.network_interface.set_input(&InputConnector::node(*node_id, 1), old_inputs[2].clone(), network_path);
2372+
}
2373+
2374+
// `wgpu-executor` scope was removed, change to the auto injected scope node `graphene_std::platform_application_io::wgpu_executor`
2375+
for (i, input) in node.inputs.iter().enumerate() {
2376+
if let NodeInput::Scope(name) = input
2377+
&& *name == "wgpu-executor"
2378+
{
2379+
document.network_interface.set_input(
2380+
&InputConnector::node(*node_id, i),
2381+
NodeInput::Scope("graphene_std::platform_application_io::WgpuExecutorNode".into()),
2382+
network_path,
2383+
);
2384+
}
2385+
}
2386+
23652387
// ==================================
23662388
// PUT ALL MIGRATIONS ABOVE THIS LINE
23672389
// ==================================

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use graphene_application_io::ApplicationIo;
99
#[derive(Default)]
1010
pub struct PlatformApplicationIo {
1111
#[cfg(feature = "wgpu")]
12-
pub(crate) gpu_executor: Option<WgpuExecutor>,
12+
gpu_executor: Option<WgpuExecutor>,
1313
resources: Option<Box<dyn resource::LoadResource>>,
1414
}
1515

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
127127

128128
// Get reference to wgpu executor and clone device handle
129129
let wgpu_executor_ref = application_io_arc.gpu_executor().unwrap();
130-
let device = wgpu_executor_ref.context.device.clone();
130+
let device = wgpu_executor_ref.context().device.clone();
131131

132132
let preferences = EditorPreferences {
133133
max_render_region_size: EditorPreferences::default().max_render_region_size,

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
201201
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => ListDyn, Context => graphene_std::ContextFeatures]),
202202
#[cfg(target_family = "wasm")]
203203
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => CanvasHandle, Context => graphene_std::ContextFeatures]),
204+
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => &PlatformEditorApi, Context => graphene_std::ContextFeatures]),
205+
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => &wgpu_executor::WgpuExecutor, Context => graphene_std::ContextFeatures]),
206+
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => Option<&wgpu_executor::WgpuExecutor>, Context => graphene_std::ContextFeatures]),
207+
async_node!(graphene_core::context_modification::ContextModificationNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache, Context => graphene_std::ContextFeatures]),
204208
// ==========
205209
// MEMO NODES
206210
// ==========
@@ -286,6 +290,9 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
286290
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => graphene_std::transform::ScaleType]),
287291
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => graphene_std::vector::misc::InterpolationDistribution]),
288292
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => RenderIntermediate]),
293+
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => &wgpu_executor::WgpuExecutor]),
294+
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => Option<&wgpu_executor::WgpuExecutor>]),
295+
async_node!(graphene_core::memo::MemoizeNode<_, _>, input: Context, fn_params: [Context => wgpu_executor::WgpuPipelineCache]),
289296
];
290297
// =============
291298
// CONVERT NODES

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use graph_craft::ProtoNodeIdentifier;
21
use graph_craft::application_io::PlatformEditorApi;
32
use graph_craft::concrete;
43
use graph_craft::document::value::TaggedValue;
@@ -8,7 +7,6 @@ use graphene_std::Context;
87
use graphene_std::ContextFeatures;
98
use graphene_std::uuid::NodeId;
109
use std::sync::Arc;
11-
use wgpu_executor::WgpuExecutor;
1210

1311
pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEditorApi>) -> NodeNetwork {
1412
let inner_network = DocumentNode {
@@ -40,7 +38,7 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
4038
},
4139
DocumentNode {
4240
call_argument: concrete!(Context),
43-
inputs: vec![NodeInput::scope("editor-api"), NodeInput::node(NodeId(0), 0)],
41+
inputs: vec![NodeInput::scope(graphene_std::platform_application_io::try_wgpu_executor::IDENTIFIER), NodeInput::node(NodeId(0), 0)],
4442
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render::IDENTIFIER),
4543
context_features: graphene_std::ContextDependencies {
4644
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
@@ -50,7 +48,11 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
5048
},
5149
DocumentNode {
5250
call_argument: concrete!(Context),
53-
inputs: vec![NodeInput::scope("editor-api"), NodeInput::node(NodeId(1), 0)],
51+
inputs: vec![
52+
NodeInput::scope(graphene_std::platform_application_io::try_wgpu_executor::IDENTIFIER),
53+
NodeInput::scope(graphene_std::platform_application_io::editor_api::IDENTIFIER),
54+
NodeInput::node(NodeId(1), 0),
55+
],
5456
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_cache::render_output_cache::IDENTIFIER),
5557
context_features: graphene_std::ContextDependencies {
5658
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
@@ -60,8 +62,8 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
6062
},
6163
DocumentNode {
6264
call_argument: concrete!(Context),
63-
inputs: vec![NodeInput::scope("editor-api"), NodeInput::node(NodeId(2), 0)],
64-
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::pixel_preview::pixel_preview::IDENTIFIER),
65+
inputs: vec![NodeInput::scope(graphene_std::render_pixel_preview::pixel_preview_pipeline::IDENTIFIER), NodeInput::node(NodeId(2), 0)],
66+
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_pixel_preview::render_pixel_preview::IDENTIFIER),
6567
context_features: graphene_std::ContextDependencies {
6668
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
6769
inject: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
@@ -70,8 +72,11 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
7072
},
7173
DocumentNode {
7274
call_argument: concrete!(Context),
73-
inputs: vec![NodeInput::scope("editor-api"), NodeInput::node(NodeId(3), 0)],
74-
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_node::render_background::IDENTIFIER),
75+
inputs: vec![
76+
NodeInput::scope(graphene_std::render_background::composite_background_pipeline::IDENTIFIER),
77+
NodeInput::node(NodeId(3), 0),
78+
],
79+
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_background::render_background::IDENTIFIER),
7580
context_features: graphene_std::ContextDependencies {
7681
extract: ContextFeatures::FOOTPRINT | ContextFeatures::VARARGS,
7782
inject: ContextFeatures::empty(),
@@ -100,7 +105,7 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
100105
};
101106

102107
// wrap the inner network in a scope
103-
let mut nodes = vec![
108+
let nodes = vec![
104109
inner_network,
105110
render_node,
106111
DocumentNode {
@@ -109,16 +114,7 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
109114
..Default::default()
110115
},
111116
];
112-
let mut scope_injections = vec![("editor-api".to_string(), (NodeId(2), concrete!(&PlatformEditorApi)))];
113-
114-
if cfg!(feature = "gpu") {
115-
nodes.push(DocumentNode {
116-
implementation: DocumentNodeImplementation::ProtoNode(ProtoNodeIdentifier::new("graphene_core::ops::IntoNode<&WgpuExecutor>")),
117-
inputs: vec![NodeInput::node(NodeId(2), 0)],
118-
..Default::default()
119-
});
120-
scope_injections.push(("wgpu-executor".to_string(), (NodeId(3), concrete!(&WgpuExecutor))));
121-
}
117+
let scope_injections = vec![("editor-api".to_string(), (NodeId(2), concrete!(&PlatformEditorApi)))];
122118

123119
NodeNetwork {
124120
exports: vec![NodeInput::node(NodeId(1), 0)],

node-graph/libraries/canvas-utils/src/wasm.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl CanvasSurfaceHandle {
6262
if self.1.is_none() {
6363
let canvas = self.0.get().canvas.clone();
6464
let surface = executor
65-
.context
65+
.context()
6666
.instance
6767
.create_surface(wgpu::SurfaceTarget::Canvas(canvas))
6868
.expect("Failed to create surface from canvas");
@@ -86,21 +86,23 @@ impl Canvas for CanvasSurfaceHandle {
8686
#[cfg(feature = "wgpu")]
8787
impl CanvasSurface for CanvasSurfaceHandle {
8888
fn present(&mut self, image_texture: &ImageTexture, executor: &WgpuExecutor) {
89+
let context = executor.context();
90+
8991
let source_texture: &wgpu::Texture = image_texture.as_ref();
9092

9193
let surface = self.surface(executor);
9294

9395
// Blit the texture to the surface
94-
let mut encoder = executor.context.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
96+
let mut encoder = context.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
9597
label: Some("Texture to Surface Blit"),
9698
});
9799

98100
let size = source_texture.size();
99101

100102
// Configure the surface at physical resolution (for HiDPI displays)
101-
let surface_caps = surface.get_capabilities(&executor.context.adapter);
103+
let surface_caps = surface.get_capabilities(&context.adapter);
102104
surface.configure(
103-
&executor.context.device,
105+
&context.device,
104106
&wgpu::SurfaceConfiguration {
105107
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST,
106108
format: wgpu::TextureFormat::Rgba8Unorm,
@@ -134,7 +136,7 @@ impl CanvasSurface for CanvasSurfaceHandle {
134136
source_texture.size(),
135137
);
136138

137-
executor.context.queue.submit([encoder.finish()]);
139+
context.queue.submit([encoder.finish()]);
138140
surface_texture.present();
139141
}
140142
}

0 commit comments

Comments
 (0)