Fixes framebuffer caching with multiple references of different sizes#32690
Conversation
65169bc to
17ae2b6
Compare
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
17ae2b6 to
0f44cd5
Compare
538f416 to
a5ceff2
Compare
23d839d to
c7dd472
Compare
c2b2888 to
2806820
Compare
|
I cleaned up all the slop. This should be minimal and pretty clean implementation fixing the bug. Ready for review! |
2806820 to
addc6ce
Compare
addc6ce to
b25bbd4
Compare
|
I also added tests (generated by Opus 4.5) ViewportDepthTextureNode.tests.js Let me know if this is needed. From what I can tell, it tests for the correct edge case. |
| @@ -1312,7 +1311,7 @@ class Renderer { | |||
|
|
|||
| frameBufferTarget.isPostProcessingRenderTarget = true; | |||
|
|
|||
| this._frameBufferTarget = frameBufferTarget; | |||
| this._frameBufferTargets.set( canvasTarget, frameBufferTarget ); | |||
There was a problem hiding this comment.
Could we add an individual dispose event for each CanvasTarget?
|
While working on some viewport/scissor related logic, I have found out this PR broke webgpu_multiple_canvas. You see the same mesh everywhere instead of different ones like in prod: https://threejs.org/examples/webgpu_multiple_canvas Right before this PR, |
|
@Mugen87 interesting. Ili take a look. Curious why screenshot tests didn’t pick this up? |
|
|
|
I would prefer if @sunag decides for a solution here 😇 . He knows this part of the library best. |
|
@arodic Thanks for the PRs, I implemented a solution similar to yours but caching the Quads; the problem with caching the nodes after all the changes was the need to revalidate the shader, which made it a bit less efficient. |
#Change summary
The Root Cause of #32689
ViewportDepthTextureNode: Uses a singleton _sharedDepthbuffer that is shared across all RenderTargets/CanvasTargets. This causes brute-force destruction and re-creation of depth buffer per reference on every rendered frame if references are not exactly the same size. This affects both CanvasTarget and RenderTargetViewporTextureNodeDoes not consider CanvasTarget as a reference. It simply does not do caching for CanvasTargetsRenderer: Uses a single _frameBufferTarget that resizes for each canvas (if not exactly the same size), triggeringdepthTexture.needsUpdate = true and causing texture recreation
The Fix for #32689
ViewportDepthTextureNoderemoved getTextureForReference() override to allow texture caching. Now it caches depth textures per referenceViewportTextureNodeAdded check for CanvasTarget. Previous implementation considered RenderTargets only.RendererChanged _frameBufferTarget to _frameBufferTargets (Map<CanvasTarget, RenderTarget>). Each canvas target now gets its own framebuffer target instead of sharing oneThis allows multi-canvas rendering with different sizes and tone mapping enabled without constant texture buffer recreation.