Skip to content

Implement generic pipeline caching in WgpuExecutor#4210

Open
timon-schelling wants to merge 10 commits into
masterfrom
gp-wgpu-pipeline-cache
Open

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

Conversation

@timon-schelling
Copy link
Copy Markdown
Member

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
Copy link
Copy Markdown
Contributor

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

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
Copy link
Copy Markdown
Contributor

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

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.
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/libraries/wgpu-executor/src/pipeline.rs">

<violation number="1" location="node-graph/libraries/wgpu-executor/src/pipeline.rs:35">
P2: Pipeline dispatch now boxes every async run, adding per-call heap allocation in a hot executor path.</violation>
</file>

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
}

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.

P2: Pipeline dispatch now boxes every async run, adding per-call heap allocation in a hot executor path.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At node-graph/libraries/wgpu-executor/src/pipeline.rs, line 35:

<comment>Pipeline dispatch now boxes every async run, adding per-call heap allocation in a hot executor path.</comment>

<file context>
@@ -0,0 +1,37 @@
+	}
+
+	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))
+	}
+}
</file context>

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.

likely blocked by

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)

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.

Thanks for the heads-up — that looks like a blocking compiler limitation.

Comment thread node-graph/nodes/gstd/src/render_background.rs
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
Copy link
Copy Markdown
Contributor

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

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/libraries/wgpu-executor/src/lib.rs">

<violation number="1" location="node-graph/libraries/wgpu-executor/src/lib.rs:103">
P2: `P::create()` now executes while the `pipelines` write lock is held, introducing avoidable lock contention during expensive pipeline construction.</violation>
</file>

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

Re-trigger cubic

.write()
.unwrap()
.entry(key)
.or_insert_with(|| Arc::new(P::create(&self.context)))
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.

P2: P::create() now executes while the pipelines write lock is held, introducing avoidable lock contention during expensive pipeline construction.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At node-graph/libraries/wgpu-executor/src/lib.rs, line 103:

<comment>`P::create()` now executes while the `pipelines` write lock is held, introducing avoidable lock contention during expensive pipeline construction.</comment>

<file context>
@@ -91,17 +91,16 @@ impl WgpuExecutor {
 			.unwrap()
 			.entry(key)
-			.or_insert(built)
+			.or_insert_with(|| Arc::new(P::create(&self.context)))
 			.clone()
 			.downcast::<P>()
</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