Conversation
Summary of ChangesHello @TrueDoctor, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly optimizes memory management within the rendering pipeline by implementing a texture pooling system. By leveraging Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a texture pool to the render cache node, aimed at reducing memory consumption and allocation overhead, particularly for WASM-based viewport rendering. By wrapping wgpu::Texture in std::sync::Arc and tracking strong reference counts, the system can now reuse textures that are no longer in use by the editor or previous frames. The implementation is clean and leverages Rust's ownership model effectively to manage GPU resource lifetimes without explicit manual pooling logic in most places. The identified redundant comment should be removed to maintain code clarity.
There was a problem hiding this comment.
2 issues found across 7 files
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="editor/src/node_graph_executor/runtime.rs">
<violation number="1" location="editor/src/node_graph_executor/runtime.rs:63">
P2: `current_viewport_texture` is written but never read anywhere in the codebase. This field stores a cloned `ImageTexture` every frame (keeping a GPU texture alive via `Arc`) without any code that recycles or accesses it. This is dead code that increases memory consumption — the opposite of the PR's stated goal of reducing memory pressure.</violation>
</file>
<file name="node-graph/nodes/gstd/src/render_cache.rs">
<violation number="1" location="node-graph/nodes/gstd/src/render_cache.rs:238">
P2: Reused textures from the pool retain stale pixel data from the previous frame. Unlike a freshly allocated texture, a pooled texture contains actual rendered content. Since `composite_cached_regions` does not clear the output texture before copying regions into it, any uncovered pixels (e.g., from sub-pixel rounding gaps between tiles) will show ghost artifacts from the previous frame. Consider adding a clear pass (e.g., a `render_pass` with a clear color) before compositing, or using `encoder.clear_texture()` to zero the texture upon reuse.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| /// Cached surface for WASM viewport rendering (reused across frames) | ||
| #[cfg(all(target_family = "wasm", feature = "gpu"))] | ||
| wasm_viewport_surface: Option<wgpu_executor::WgpuSurface>, | ||
| current_viewport_texture: Option<ImageTexture>, |
There was a problem hiding this comment.
P2: current_viewport_texture is written but never read anywhere in the codebase. This field stores a cloned ImageTexture every frame (keeping a GPU texture alive via Arc) without any code that recycles or accesses it. This is dead code that increases memory consumption — the opposite of the PR's stated goal of reducing memory pressure.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At editor/src/node_graph_executor/runtime.rs, line 63:
<comment>`current_viewport_texture` is written but never read anywhere in the codebase. This field stores a cloned `ImageTexture` every frame (keeping a GPU texture alive via `Arc`) without any code that recycles or accesses it. This is dead code that increases memory consumption — the opposite of the PR's stated goal of reducing memory pressure.</comment>
<file context>
@@ -59,6 +60,7 @@ pub struct NodeRuntime {
/// Cached surface for WASM viewport rendering (reused across frames)
#[cfg(all(target_family = "wasm", feature = "gpu"))]
wasm_viewport_surface: Option<wgpu_executor::WgpuSurface>,
+ current_viewport_texture: Option<ImageTexture>,
}
</file context>
There was a problem hiding this comment.
This is precisely in place such that the texture is not destroyed while it is still in use by the frontend
There was a problem hiding this comment.
Thanks for the feedback! I've saved this as a new learning to improve future reviews.
| self.texture_cache.1.truncate(5); | ||
| for texture in &self.texture_cache.1 { | ||
| if Arc::strong_count(&texture) == 1 { | ||
| return Arc::clone(texture); |
There was a problem hiding this comment.
P2: Reused textures from the pool retain stale pixel data from the previous frame. Unlike a freshly allocated texture, a pooled texture contains actual rendered content. Since composite_cached_regions does not clear the output texture before copying regions into it, any uncovered pixels (e.g., from sub-pixel rounding gaps between tiles) will show ghost artifacts from the previous frame. Consider adding a clear pass (e.g., a render_pass with a clear color) before compositing, or using encoder.clear_texture() to zero the texture upon reuse.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At node-graph/nodes/gstd/src/render_cache.rs, line 238:
<comment>Reused textures from the pool retain stale pixel data from the previous frame. Unlike a freshly allocated texture, a pooled texture contains actual rendered content. Since `composite_cached_regions` does not clear the output texture before copying regions into it, any uncovered pixels (e.g., from sub-pixel rounding gaps between tiles) will show ghost artifacts from the previous frame. Consider adding a clear pass (e.g., a `render_pass` with a clear color) before compositing, or using `encoder.clear_texture()` to zero the texture upon reuse.</comment>
<file context>
@@ -224,6 +226,36 @@ impl TileCacheImpl {
+ self.texture_cache.1.truncate(5);
+ for texture in &self.texture_cache.1 {
+ if Arc::strong_count(&texture) == 1 {
+ return Arc::clone(texture);
+ }
+ }
</file context>
Reuse existing but no longer used viewport textures to reduce memory consumption while waiting for a gc on web