Visitar URL original
WebGPURenderer: Share node builds between structurally identical materials by gkjohnson · Pull Request #34693 · mrdoob/three.js · GitHub
Skip to content

WebGPURenderer: Share node builds between structurally identical materials - #34693

Draft
gkjohnson wants to merge 6 commits into
mrdoob:devfrom
gkjohnson:webgpu/shared-node-builds
Draft

gkjohnson wants to merge 6 commits into
mrdoob:devfrom
gkjohnson:webgpu/shared-node-builds

Conversation

@gkjohnson

Copy link
Copy Markdown
Collaborator

Related issue: #33821, #34684

Description

This is a primarily AI-driven prototype put together based on some of the write-ups from #34684. It aims to share node builds between detected structurally identical materials to avoid a full node build for a material where the program is already present. The local e2e runs fail on both dev and this branch identically, so we'll see if it passes everything here.

Here are some timings from this branch vs the other using Case 1 from #33821. The proxy material skips the graph walk for the cache key and uniform gather, which can account for some of the timing differences. So there's still some benefit to other workarounds so far, but this kind of change should help with all node material build times:

WebGPU dev ProxyNodeMaterial (#34684) This PR WebGLRenderer
timing 1928.8 ms 254.5 ms 380.8 ms 128.3 ms
timing improvement - -86.80% -80.26% -93.35%

I don't expect this to be merged as-is, since I'm not familiar enough with all of the internals, but hopefully serve as a demonstration of something that could be done.

gkjohnson and others added 2 commits September 28, 2026 23:39
…rials

Key nodes by type and settings instead of id so materials that only differ in uniform values reuse a single node build. Each render object maps the shared build's uniforms to its own material's uniform nodes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
Core 390.08
102.3
390.08
102.3
+0 B
+0 B
WebGL 372.73
87.14
372.73
87.14
+0 B
+0 B
WebGPU 428.41
115.47
428.94
115.62
+533 B
+152 B
WebGPU Nodes 716.04
196.75
717.88
197.31
+1.84 kB
+559 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 517.46
124.27
517.46
124.27
+0 B
+0 B
WebGPU 768.68
206.01
770.45
206.48
+1.76 kB
+475 B
WebGPU Nodes 714.54
192.52
716.3
193.01
+1.76 kB
+486 B

gkjohnson and others added 4 commits September 29, 2026 01:07
Node.traverse() revisits shared subgraphs once per path, which never finishes on large MaterialX graphs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🖼️ E2E screenshot tests

❌ 1 example(s) failed (full artifacts).

Example Expected Actual Diff
webgpu_camera

@mrdoob

mrdoob commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

This reminds me of the good old debate on whether WebGLRenderer should automatically use instancing when the same mesh is repeated in the graph vs teaching people to use InstancedMesh.

I feel like #34684 is the right approach (just needs a better name).

@gkjohnson

gkjohnson commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator Author

I feel like #34684 is the right approach (just needs a #34684 (comment)).

I completely disagree and I don't think enough is understood about the problem to say this... I will be less available for the next few weeks but please give me some time to write up what the issues are. #34684 does not fix my problems around dynamically extended materials (as in adding "layers" like fade effects or other visualizations to user-provided node materials), which 3DTilesRendererJS and other projects make heavy use of. In WebGLRenderer extending materials with "onBeforeCompile" to add new effects was a common pattern - which worked with multiple nested functions - and it was fast.

There's no fast to dynamically extend a material in TSL and there's no reason there shouldn't be.

This branch has not been deployed

No deployments
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.

2 participants