Skip to content

Commit

Permalink
UBO layer bind optimization (#2335)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcristici authored Apr 26, 2024
1 parent 84ec4f8 commit 6ebbc3d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
24 changes: 18 additions & 6 deletions src/mbgl/gl/layer_group_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,7 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
const auto debugGroupRender = parameters.encoder->createDebugGroup(label_render.c_str());
#endif

bindUniformBuffers();

bool bindUBOs = false;
visitDrawables([&](gfx::Drawable& drawable) {
if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) {
return;
Expand All @@ -121,10 +120,17 @@ void TileLayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters)
context.setStencilMode(drawable.getEnableStencil() ? stencilMode3d : gfx::StencilMode::disabled());
}

if (!bindUBOs) {
bindUniformBuffers();
bindUBOs = true;
}

drawable.draw(parameters);
});

unbindUniformBuffers();
if (bindUBOs) {
unbindUniformBuffers();
}
}

void TileLayerGroupGL::bindUniformBuffers() const {
Expand Down Expand Up @@ -178,8 +184,7 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) {
return;
}

bindUniformBuffers();

bool bindUBOs = false;
visitDrawables([&](gfx::Drawable& drawable) {
if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) {
return;
Expand All @@ -193,10 +198,17 @@ void LayerGroupGL::render(RenderOrchestrator&, PaintParameters& parameters) {
tweaker->execute(drawable, parameters);
}

if (!bindUBOs) {
bindUniformBuffers();
bindUBOs = true;
}

drawable.draw(parameters);
});

unbindUniformBuffers();
if (bindUBOs) {
unbindUniformBuffers();
}
}

void LayerGroupGL::bindUniformBuffers() const {
Expand Down
12 changes: 9 additions & 3 deletions src/mbgl/mtl/layer_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
auto& context = static_cast<Context&>(parameters.context);
auto& renderPass = static_cast<RenderPass&>(*parameters.renderPass);

bindUniformBuffers(renderPass);

bool bindUBOs = false;
visitDrawables([&](gfx::Drawable& drawable) {
if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) {
return;
Expand All @@ -57,10 +56,17 @@ void LayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
tweaker->execute(drawable, parameters);
}

if (!bindUBOs) {
bindUniformBuffers(renderPass);
bindUBOs = true;
}

drawable.draw(parameters);
});

unbindUniformBuffers(renderPass);
if (bindUBOs) {
unbindUniformBuffers(renderPass);
}
}

void LayerGroup::bindUniformBuffers(RenderPass& renderPass) const noexcept {
Expand Down
12 changes: 9 additions & 3 deletions src/mbgl/mtl/tile_layer_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
parameters.renderTileClippingMasks(stencilTiles);
}

bindUniformBuffers(renderPass);

bool bindUBOs = false;
visitDrawables([&](gfx::Drawable& drawable) {
if (!drawable.getEnabled() || !drawable.hasRenderPass(parameters.pass)) {
return;
Expand All @@ -139,10 +138,17 @@ void TileLayerGroup::render(RenderOrchestrator&, PaintParameters& parameters) {
renderPass.setDepthStencilState(state);
}

if (!bindUBOs) {
bindUniformBuffers(renderPass);
bindUBOs = true;
}

drawable.draw(parameters);
});

unbindUniformBuffers(renderPass);
if (bindUBOs) {
unbindUniformBuffers(renderPass);
}
}

void TileLayerGroup::bindUniformBuffers(RenderPass& renderPass) const noexcept {
Expand Down

0 comments on commit 6ebbc3d

Please sign in to comment.