-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
WebGPURenderer: Per "texture set" bindGroup caching. #29845
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
src/renderers/common/Bindings.js
Outdated
|
||
} else { | ||
|
||
cacheIndex = cacheIndex * 10 + texture.id * 10 + texture.version; |
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.
What is the purpose of * 10
?
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.
Maybe some hash test that could use the NodeUtils hashArray()
or hash()
?
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.
?10 just to stop obvious collisions as a proof of concept. I am trying to avoid more string creation on a fairly hot path. A cheap hash would be better.
Nice! I thought about something similar but the issue with this it that it's stacking To complete your approach, a cleanup strategy for unused |
Re garbage collection on resize. yes, it is an obvious issue. I just wanted to get a basic working approach to start with. After a bind group has been created, the only way to destroy it is to drop references to it AFAICS, so maybe we need a two part cacheId so that the version changes would cause a cached bindGroup to be overwritten? It is something I considered earlier. |
This new two part cacheId is an awesome solution and fixes the issue. Great PR! |
@aardgoose Is this PR ready for review? |
Related issue: #29198, #27447
Alternative mechanism to avoid excessive bindGroup creation. Use a cache keyed by a value derived from the texture(s) used in a bindGroup to handle the situation where a material alternates between two or more textures. This caching only takes place for bindGroups that would be updated after the first pass.
BindGroups referencing defaultTextures or external textures are not cached.