Skip to content

Implement generic pipeline caching in WgpuExecutor#4210

Open
timon-schelling wants to merge 1 commit into
masterfrom
gp-wgpu-pipeline-cache
Open

Implement generic pipeline caching in WgpuExecutor#4210
timon-schelling wants to merge 1 commit into
masterfrom
gp-wgpu-pipeline-cache

Conversation

@timon-schelling

@timon-schelling timon-schelling commented Jun 7, 2026

Copy link
Copy Markdown
Member

depends on #4235

changing shader nodes to work with this will be done in a followup PR, for now they keep the separate ShaderRuntime.

@timon-schelling timon-schelling marked this pull request as ready for review June 7, 2026 23:33

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the WGPU pipeline execution model by introducing a dynamic, generic Pipeline trait system. Hardcoded compositor and resampler fields in WgpuExecutor are replaced with a thread-safe pipelines map that caches and runs pipelines dynamically. Additionally, the render_background and pixel_preview (renamed to render_pixel_preview) nodes have been refactored to use this new system. Feedback on these changes suggests adding an early return in render_background when viewport_zoom <= 0.0 to prevent uninitialized texture returns, simplifying the Pipeline trait using impl Future to avoid boxed future allocations, releasing the RwLockReadGuard earlier during pipeline retrieval, and cleaning up a verbose type signature in BackgroundCompositor::run.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread node-graph/nodes/gstd/src/render_background.rs Outdated
Comment on lines +8 to +37
pub trait Pipeline: std::any::Any + Send + Sync + Sized {
type Args<'a>;
type Out: Send;

fn create(context: &WgpuContext) -> Self;

fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> PipelineFuture<'a, Self::Out>;
}

pub trait AsyncPipeline: std::any::Any + Send + Sync + Sized {
type Args<'a>;
type Out: Send;

fn create(context: &WgpuContext) -> Self;

fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> impl Future<Output = Self::Out> + Send + 'a;
}

impl<P: AsyncPipeline> Pipeline for P {
type Args<'a> = <P as AsyncPipeline>::Args<'a>;
type Out = <P as AsyncPipeline>::Out;

fn create(context: &WgpuContext) -> Self {
<P as AsyncPipeline>::create(context)
}

fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> PipelineFuture<'a, Self::Out> {
Box::pin(<P as AsyncPipeline>::run(self, executor, args))
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since WgpuExecutor::run_pipeline always downcasts to the concrete pipeline type P, there is no need for a trait object or boxed futures. We can leverage Rust's support for impl Future in traits to define a single Pipeline trait without any boxing, eliminating the Box::pin allocation on every pipeline execution.

Suggested change
pub trait Pipeline: std::any::Any + Send + Sync + Sized {
type Args<'a>;
type Out: Send;
fn create(context: &WgpuContext) -> Self;
fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> PipelineFuture<'a, Self::Out>;
}
pub trait AsyncPipeline: std::any::Any + Send + Sync + Sized {
type Args<'a>;
type Out: Send;
fn create(context: &WgpuContext) -> Self;
fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> impl Future<Output = Self::Out> + Send + 'a;
}
impl<P: AsyncPipeline> Pipeline for P {
type Args<'a> = <P as AsyncPipeline>::Args<'a>;
type Out = <P as AsyncPipeline>::Out;
fn create(context: &WgpuContext) -> Self {
<P as AsyncPipeline>::create(context)
}
fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> PipelineFuture<'a, Self::Out> {
Box::pin(<P as AsyncPipeline>::run(self, executor, args))
}
}
pub trait Pipeline: std::any::Any + Send + Sync + Sized {
type Args<'a>;
type Out: Send;
fn create(context: &WgpuContext) -> Self;
fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> impl Future<Output = Self::Out> + Send + 'a;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

error: lifetime bound not satisfied
  --> node-graph/nodes/gstd/src/render_background.rs:17:1
   |
17 | #[node_macro::node(category(""))]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
   = note: this error originates in the attribute macro `node_macro::node` (in Nightly builds, run with -Z macro-backtrace for more info)

error: lifetime bound not satisfied
  --> node-graph/nodes/gstd/src/render_pixel_preview.rs:13:1
   |
13 | #[node_macro::node(category(""))]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
   = note: this error originates in the attribute macro `node_macro::node` (in Nightly builds, run with -Z macro-backtrace for more info)

Comment thread node-graph/libraries/wgpu-executor/src/lib.rs Outdated
Comment thread node-graph/nodes/gstd/src/render_background.rs Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7 issues found across 15 files

Confidence score: 2/5

  • There is a concrete user-facing regression risk in node-graph/nodes/gstd/src/render_background.rs: the zoom <= 0 early return can skip compositing/copying and produce a blank render output.
  • Several high-confidence panic paths were introduced (unwrap/expect and unwrapped application_io) across node-graph/nodes/gstd/src/render_background.rs and node-graph/libraries/wgpu-executor/src/lib.rs, which can crash runtime/executor flows instead of failing gracefully.
  • Additional executor-path concerns in node-graph/libraries/wgpu-executor/src/pipeline.rs and node-graph/libraries/wgpu-executor/src/lib.rs (per-call boxing in a hot path, eager duplicate pipeline creation, and longer-than-needed lock scope) increase performance/concurrency risk but are secondary to correctness issues.
  • Pay close attention to node-graph/nodes/gstd/src/render_background.rs, node-graph/libraries/wgpu-executor/src/lib.rs, node-graph/libraries/wgpu-executor/src/pipeline.rs - potential blank output, panic-on-error behavior, and executor hot-path regressions.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread node-graph/nodes/gstd/src/render_background.rs
Comment thread node-graph/libraries/wgpu-executor/src/lib.rs Outdated
Comment thread node-graph/libraries/wgpu-executor/src/lib.rs Outdated
Comment thread node-graph/libraries/wgpu-executor/src/pipeline.rs
Comment thread node-graph/nodes/gstd/src/render_background.rs Outdated
Comment thread node-graph/nodes/gstd/src/render_background.rs
Comment thread node-graph/libraries/wgpu-executor/src/lib.rs Outdated
@timon-schelling timon-schelling changed the title Implement generic pipeline caching for WgpuExecutor Implement generic pipeline caching in WgpuExecutor Jun 8, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread node-graph/libraries/wgpu-executor/src/lib.rs Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="node-graph/graph-craft/src/document.rs">

<violation number="1" location="node-graph/graph-craft/src/document.rs:663">
P1: Top-level scope resolution now panics on unresolved keys. This can crash graph compilation instead of failing gracefully with a recoverable error.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

pub fn resolve_scope_inputs(&mut self) {
let mut leftover = Vec::new();
self.resolve_scope_inputs_with(None, &mut leftover);
assert!(leftover.is_empty(), "Unresolved scope keys at top level: {leftover:?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Top-level scope resolution now panics on unresolved keys. This can crash graph compilation instead of failing gracefully with a recoverable error.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At node-graph/graph-craft/src/document.rs, line 663:

<comment>Top-level scope resolution now panics on unresolved keys. This can crash graph compilation instead of failing gracefully with a recoverable error.</comment>

<file context>
@@ -655,6 +655,59 @@ impl NodeNetwork {
+	pub fn resolve_scope_inputs(&mut self) {
+		let mut leftover = Vec::new();
+		self.resolve_scope_inputs_with(None, &mut leftover);
+		assert!(leftover.is_empty(), "Unresolved scope keys at top level: {leftover:?}");
+	}
+
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant