Skip to content

buffer update opt: Some optimizations - #9438

Merged
show50726 merged 6 commits into
mainfrom
dw/uboMgr-opt
Nov 20, 2025
Merged

buffer update opt: Some optimizations#9438
show50726 merged 6 commits into
mainfrom
dw/uboMgr-opt

Conversation

@show50726

Copy link
Copy Markdown
Contributor

Changes

  • Early return in allocateOnDemand when previous allocation has already failed
  • Core frame functions now remove large instance map argument and the logic in each function becomes simpler.
  • Instead, UboManager now internally manages material instances which have batching enabled
  • allocateOnDemand uses the new internal list
  • Add tracing calls monitor performance of memory allocation

I'd like to know your thoughts about managing a separate list for batching-enabled material instances.

The benefit of this is that the logic inside functions become clearer. For allocateOnDemand, the logic becomes simpler and potentially more efficient as well since it only traverses required material instances. The downside of this is that it requires additional memory to maintain a separate list.

@show50726 show50726 added the internal Issue/PR does not affect clients label Nov 17, 2025
@pixelflinger

Copy link
Copy Markdown
Collaborator

I'd like to know your thoughts about managing a separate list for batching-enabled material instances.

The benefit of this is that the logic inside functions become clearer. For allocateOnDemand, the logic becomes simpler and potentially more efficient as well since it only traverses required material instances. The downside of this is that it requires additional memory to maintain a separate list.

That seems like a good change. I would assume that adding/removing materialinstance is a low frequency operation. the extra memory seems okay, but we need to make sure those lists are updated when a MaterialInstance is destroyed.

Comment thread filament/src/details/MaterialInstance.cpp
Comment thread filament/src/details/UboManager.cpp Outdated
Comment thread filament/src/details/UboManager.cpp Outdated
Comment thread filament/src/details/UboManager.cpp Outdated
Comment on lines 196 to 197
if (!BufferAllocator::isValid(id))
return;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does that mean here that the isValid() could be false? Shouldn't we remove the material instance from the list anyway? should this be an assert? or is this a valid case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you create a material instance and destroy it immediately, the id here would be invalid (though it should be rare).

And you're right, we still need to remove it from the list, but should not retire this slot since the id is invalid. I moved this check after the erase. Thanks for the catch!

Comment thread filament/src/details/UboManager.cpp Outdated
Comment thread filament/src/details/UboManager.cpp
Comment thread filament/src/details/UboManager.cpp Outdated
Comment thread filament/src/details/UboManager.cpp Outdated
Comment thread filament/src/details/Engine.cpp Outdated
Comment thread filament/src/details/UboManager.cpp Outdated
Comment thread filament/src/details/UboManager.cpp Outdated
@show50726
show50726 enabled auto-merge (squash) November 20, 2025 00:38
@show50726
show50726 merged commit d4bbb7c into main Nov 20, 2025
17 checks passed
@show50726
show50726 deleted the dw/uboMgr-opt branch November 20, 2025 00:52
j1george pushed a commit to Fieldwire/filament that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Issue/PR does not affect clients

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants