From 1e17afbefa3fac34c1dd3f76a12cc2a6d849d072 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Mon, 13 Jun 2022 17:26:01 -0700 Subject: [PATCH] small optimization that helps avoid bindUniformBufferRange calls a lot of primitive may use the same UBO slot, if they happen to be in a sequence, we don't need to rebind the UBO. --- filament/src/RenderPass.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/filament/src/RenderPass.cpp b/filament/src/RenderPass.cpp index fc93dd2f75..c577bde701 100644 --- a/filament/src/RenderPass.cpp +++ b/filament/src/RenderPass.cpp @@ -601,6 +601,7 @@ void RenderPass::Executor::recordDriverCommands(FEngine& engine, backend::Driver Handle uboHandle = mUboHandle; FMaterialInstance const* UTILS_RESTRICT mi = nullptr; FMaterial const* UTILS_RESTRICT ma = nullptr; + uint32_t uboDataIndex = std::numeric_limits::max(); auto customCommands = mCustomCommands.data(); first--; @@ -637,9 +638,13 @@ void RenderPass::Executor::recordDriverCommands(FEngine& engine, backend::Driver } pipeline.program = ma->getProgram(info.materialVariant); - size_t offset = info.index * sizeof(PerRenderableData); - driver.bindUniformBufferRange(BindingPoints::PER_RENDERABLE, - uboHandle, offset, sizeof(PerRenderableUib)); + + if (uboDataIndex != info.index) { + uboDataIndex = info.index; + driver.bindUniformBufferRange(BindingPoints::PER_RENDERABLE, + uboHandle, uboDataIndex * sizeof(PerRenderableData), + sizeof(PerRenderableUib)); + } if (UTILS_UNLIKELY(info.skinningHandle)) { // note: we can't bind less than sizeof(PerRenderableBoneUib) due to glsl limitations