Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Optimize Extrusion drawing #9286

Closed
kkaefer opened this issue Jun 16, 2017 · 3 comments · Fixed by #9931
Closed

Optimize Extrusion drawing #9286

kkaefer opened this issue Jun 16, 2017 · 3 comments · Fixed by #9931
Assignees
Labels
Core The cross-platform C++ core, aka mbgl rendering

Comments

@kkaefer
Copy link
Contributor

kkaefer commented Jun 16, 2017

We should move the extrusion texture step to the beginning of a frame to improve rendering performance.

Right now, the workflow of a frame is like this:

  • (main framebuffer is bound)
  • Clear main framebuffer (✅ first operation is clear -> no restore)
  • Render some layers
  • Render extrusion layer
    • Bind extrusions framebuffer
    • Clear extrusions framebuffer (✅ first operation is clear -> no restore)
    • Draw extrusions
    • Bind main framebuffer
  • Draw extrusions texture (:warning: FBO restore)
  • Render remaining layers

When binding a framebuffer and rendering operations on it, the GPU has to restore the contents of the framebuffer. The driver can optimize that when we do a clear as the first drawing operation (since that discards the contents of the framebuffer). Therefore, drawing to the main framebuffer, then binding a different framebuffer, and rebinding the main framebuffer triggers a framebuffer load on the first draw call.

Instead, we could do all operations that require binding a separate framebuffer (i.e. drawing the extrusions texture) as the first thing when rendering a frame (i.e. before calling clear on the main framebuffer) and have the following order:

  • (main framebuffer is bound)
  • Create extrusion texture
    • Bind extrusions framebuffer
    • Clear extrusions framebuffer (✅ first operation is clear -> no restore)
    • Draw extrusions
    • Bind main framebuffer
  • Clear main framebuffer (✅ first operation is clear -> no restore)
  • Render some layers
  • Render extrusion texture
  • Render remaining layers

In addition to that, the iOS OpenGL inspector reports these issues when drawing extrusions:

  • Depth testing enabled without an attached depth buffer: Your app rendered with DEPTH_TEST enabled into a framebuffer without an attached depth buffer.
  • Missing framebuffer attachments: Framebuffer Lines #2 has no attachments and therefore is not usable in its current state.

These two errors may be the reason for #9279

@kkaefer kkaefer added Core The cross-platform C++ core, aka mbgl rendering labels Jun 16, 2017
@mourner
Copy link
Member

mourner commented Jun 16, 2017

GL JS would benefit from this too, right?

@kkaefer
Copy link
Contributor Author

kkaefer commented Jun 16, 2017

Yep

@lbud
Copy link
Contributor

lbud commented Jun 16, 2017

This sounds good. The one tradeoff here is that we may need to create and store multiple OffscreenTextures if there are multiple extrusion layers, but it sounds like the benefits here outweigh that.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Core The cross-platform C++ core, aka mbgl rendering
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants