Implement generic pipeline caching in WgpuExecutor#4210
Implement generic pipeline caching in WgpuExecutor#4210timon-schelling wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
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.
| 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)) | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| 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; | |
| } |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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: thezoom <= 0early return can skip compositing/copying and produce a blank render output. - Several high-confidence panic paths were introduced (
unwrap/expectand unwrappedapplication_io) acrossnode-graph/nodes/gstd/src/render_background.rsandnode-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.rsandnode-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
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…ributes with graphic List<T> types (#4111) * Add conversion from Fill to Table<Graphic> * Refactor Vector vello renderer for Gradient / Color # Conflicts: # node-graph/libraries/rendering/src/renderer.rs * Refactor Vector SVG renderer for Gradient / Color * Fix conflicts * Add basic clipping-based fill for SVG rendering * Use Cow to avoid cloning graphic list for fill * Cleanup for Cow usage * format code * Use `<pattern>` instead of `<clipPath>` for clip This simplifies the future implementation of clipping-based rendering for strokes, as the stroke does not support the use of a clip path but rather paint sources from a paint server. * Move svg pattern rendering function to RenderExt * Fix comment * Fix empty fill list rendering as default black Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> * Move opaque check function to Graphic impl * Add color converter and debug node to use graphic * WIP: Use List<Graphic> to render Color & Gradient * Use `Arc<List<Vector>>` for vector_data metadata This exposes List's attributes to message handlers, enabling them to access the necessary attribute data such as ATTR_STROKE_PAINT_GRAPHIC as `Fill` and `Stroke` will not have paint information in the future. * Recurse opacity checks on nested `Graphic` Also extracts `fill_graphic_list_at` / `stroke_paint_graphic_list_at` to share the row-attribute lookup across the existing call sites. * Fix fill and stroke visibility check degradation * Fix clipping based stroke paint positioning * Refactor vello renderer for stroke to use graphic * Reduce `Fill` / `Stroke.color` to `List<Graphic>` allocations * Revert "Use `Arc<List<Vector>>` for vector_data metadata" This reverts commit 4285243 * Expose paint row attributes as dedicated metadata for vectors Add `fill_attributes` / `stroke_paint_attributes` to `DocumentMetadata` so the `ExpandFillStrokeOnSelectedLayers` handler can read row paint visibility without exposing entire `List<Vector>`. * Fix transparency check to consider fill opacity * Fix consistency of gradient placement for SVG stroke * Rename `stroke_paint_..` to `stroke_..` * Remove debug nodes * Allow to use any graphic type without casting * Rename `fill_graphic` / `stroke_graphic` to `fill` / `stroke` * Fix SVG pattern placement when stroke transform differs from item transform * Fix click target fill check for empty list in graphic * Fix blank fill/stroke attribute masking legacy style * Fix SVG's paint order trick for vector/raster fills * Add zero-division guard for pattern wraparound prevention * Code review --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This reverts commit e941bec.
a3efae0 to
181408e
Compare
changing shader nodes to work with this will be done in a followup PR, for now they keep the separate
ShaderRuntime.