szeged / webrender

A GPU-based renderer for the web
https://doc.servo.org/webrender/
Mozilla Public License 2.0
45 stars 7 forks source link

Dynamically allocate render targets #348

Open kvark opened 4 years ago

kvark commented 4 years ago

We are currently spending insane amount of time in creation and destruction of render targets per frame (~ 1/3 of the whole CPU time on the Renderer). WebRender upstream tries really hard to re-use previously created targets, in order to avoid the allocation. Fortunately, in Vulkan world we separate the allocation from render target creation, therefore we should be able to re-create the necessary targets every frame.

Here is roughly what we can do. Have a relatively large memory chunk for most (if not all) render targets needed this frame. We'll need to be able to manage multiple such chunks, but for the purpose of explanation here let's assume everything fits into one.

The general approach of WebRender is ping-pong: once a render pass is done, it serves as input to the next pass, after which the target can be safely re-used. The new implementation could start a frame with the full memory chunk available to targets.

This can be better than the current GL implementation because we don't need to try hard to re-use the existing targets. Moreover, we can re-use memory if, say, a format has changed, or the size is slightly different.