Skip to content
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

Unnecessary memory allocations when using multisampled render targets #30765

Open
codedpalette opened this issue Mar 20, 2025 · 1 comment
Open
Labels

Comments

@codedpalette
Copy link

codedpalette commented Mar 20, 2025

Description

I'm using EffectComposer to render to WebGLRenderTarget with samples > 0. My understanding is that it should create 2 render targets, and for each of them it should create 1 framebuffer, and two renderbuffers (1 color and 1 depth). However, when I inspect allocated memory with https://github.com/greggman/webgl-memory, I see that each render target creates 2 framebuffers, 3 renderbuffers and 1 texture. Looking at the code of WebGLTextures.setupRenderTarget I see there are two separate framebuffers, __webglFramebuffer and __webglMultisampleFramebuffer, with 2 multisample render buffers bound to the latter, and texture and regular depth buffer bound to the former. Yet when I look at the code in WebGLRenderer I see that __webglFramebuffer is never bound to anything when using multisample render target. My question is: is it a bug? Am I missing something?

Solution

Multisample render target should only allocate 1 framebuffer and 2 multisample render buffers

Alternatives

Additional context

No response

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 22, 2025

Yet when I look at the code in WebGLRenderer I see that __webglFramebuffer is never bound to anything when using multisample render target.

It is bound, e.g. in updateMultisampleRenderTarget():

state.bindFramebuffer( _gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer );
state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );

Without it, a resolve won't work unless WEBGL_multisampled_render_to_texture is supported.

If you think the resolve uses redundant resources, feel free to file a PR that demonstrated you suggested changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants