-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
WebGPURenderer: improve caches for skinning meshes #32609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR resolves shader caching issues in WebGPURenderer and its WebGL fallback by ensuring skinned meshes with identical configurations generate identical shader code. Previously, each skinned mesh instance created a unique shader due to non-deterministic uniform buffer naming.
Key changes:
- Modified
ReferenceNodeto generate deterministic names based on properties instead of unique IDs - Updated shader builders to prioritize node names over IDs when generating uniform buffer names
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/nodes/accessors/ReferenceNode.js | Sets deterministic name for ReferenceNode based on properties |
| src/renderers/webgpu/nodes/WGSLNodeBuilder.js | Updates uniform naming logic to use node.name when available |
| src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js | Updates buffer naming to use node.name when available |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * @default null | ||
| */ | ||
| this.name = null; | ||
| this.name = 'ref_' + this.properties.join( '_' ); |
Copilot
AI
Dec 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this.properties is an array containing objects or other non-primitive values, join('_') will produce non-deterministic names (e.g., '[object Object]'). Consider sanitizing the properties or using a stable serialization method to ensure deterministic naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* The property name might have dots so nested properties can be referred.
* The hierarchy of the names is stored inside this array.
*
* @type {Array<string>}
*/
this.properties = property.split( '.' );this.properties has to be Array<string>
Related issue: #32527
Description
This PR addresses an issue where
WebGPURenderer(and the WebGL fallback) would generate a unique shader for every skinned mesh instance, preventing shader reuse.Problem
Previously,
ReferenceNodedid not have a name, causing the Node Builders (GLSLNodeBuilderandWGSLNodeBuilder) to generate uniform buffer names based on the node's uniqueid(e.g.,NodeBuffer_1179). This resulted in different shader source code for every skinned mesh, forcing the renderer to recompile shaders unnecessarily.Solution
ReferenceNodeto generate a deterministicnamebased on its properties (e.g.,ref_...).GLSLNodeBuilderandWGSLNodeBuilderto prioritize usingnode.namewhen generating uniform names, falling back toidonly if no name is present.This ensures that skinned meshes with the same configuration generate identical shader code, allowing the renderer to cache and reuse the programs effectively.
Known Limitations
There are still two scenarios where meshes sharing the same material will generate different shaders: