Reduce heap allocations in multi-pass scene rendering#9545
Reduce heap allocations in multi-pass scene rendering#9545aardgoose wants to merge 7 commits intomrdoob:devfrom
Conversation
RenderItem creation every frame when multiple differently sized scenes are repeatedly rendered with the same renderer. Exhibited by the rtt example.
src/renderers/WebGLRenderer.js
Outdated
|
|
||
| opaqueObjectsLastIndex = - 1; | ||
| transparentObjectsLastIndex = - 1; | ||
| if ( scene._opaqueObjects === undefined ) { |
There was a problem hiding this comment.
Instead of polluting the scene object I would have a internal object in WebGLRenderer like renderLists[ scene.id ]. We used to pollute the scene graph like this. It's handy, but it becomes messy very quickly.
|
Modified as requested. |
merge upstream
|
Thanks! |
|
@tschw what do you think about this approach? |
|
Basically seems a very good idea to me. As already addressed, the renderer should own the data, then it will still work with multiple renderers rendering different views of the same scene. Is there a Also, I think we should use the |
|
Ok, I realised I need to attach a dispose handler to the scene. I'll respin with that and WebGLProperties, still learning the code base... the dispose handler will be basically properties.delete( scene ) in that case unless I am mistaken. |
|
Ended up doing a similar implementation, but also for scene+camera. |
|
Thanks though! |
I know this issue is a few years old but do you remember the motivation behind including the camera? I've refactored At first sight, it seems including the camera is not necessary since render items are defined by 3D objects which are only present in the scene. Even if multiple cameras render the same scene and discard certain objects because of view frustum culling or different layers configuration, there is no additional GC overhead (because render items are internally cached). |
|
I think it was because renderlists size woulc change multiple times per frame when rendering from different cameras (ie. mirrors). The stack approach is definitely a better solution for that 👍 |
|
The commit looks good! Thanks for doing that clean up. We should try merging it soon so we can test it 🙏 |
Use separate render lists for each scene to avoid array resize and
RenderItem creation every frame when multiple differently sized scenes are
repeatedly rendered with the same renderer.
Exhibited by the rtt example.