Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL: Monotonic UBO allocator #1911

Merged
merged 22 commits into from
Dec 12, 2023
Merged

Conversation

mwilsnd
Copy link
Collaborator

@mwilsnd mwilsnd commented Dec 4, 2023

Addresses a major performance regression when using UBOs: each buffer instance allocating its own buffer from the API.

This PR creates a new buffer sub-allocation scheme and a means to pool and recycle larger pages of buffer memory. This notably accelerates UBO performance by streaming unsynchronized writes to memory guaranteed to be unused by the GPU, eliminating the possibility of a pipeline stall during buffer updates.

How it works:

  • A UBO is created or attempts to update its contents
  • The allocator locates the next free block of memory, maps that buffer region in unsynchronized fashion and writes
  • That memory region is marked as occupied and a strong reference linking the memory region and UBO together is created
  • Once a buffer page fills up, it gets moved to an 'in-flight' list where it waits to either become free, or -
  • De-fragmentation happens on a set interval to reclaim buffers with poor occupancy. This has a pretty important implication: buffers must be relocatable and must be bound every frame.

@mwilsnd mwilsnd self-assigned this Dec 4, 2023
@TimSylvester
Copy link
Collaborator

Would it be practical to have RelocatableBuffer be a member rather than a base of UniformBufferGL, maybe via a mandatory getRelocatableBuffer on OwnerClass types?

Copy link

github-actions bot commented Dec 4, 2023

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.2%  +302Ki  +0.2% +67.7Ki    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-1911-compared-to-main.txt

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +19% +21.6Mi  +400% +23.9Mi    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-1911-compared-to-legacy.txt

@mwilsnd
Copy link
Collaborator Author

mwilsnd commented Dec 4, 2023

Would it be practical to have RelocatableBuffer be a member rather than a base of UniformBufferGL, maybe via a mandatory getRelocatableBuffer on OwnerClass types?

Sure, we can do that. I made it a base mostly out of convenience.

@louwers
Copy link
Collaborator

louwers commented Dec 8, 2023

!benchmark android

@mwilsnd mwilsnd marked this pull request as ready for review December 11, 2023 20:33
@mwilsnd mwilsnd merged commit 8b2c748 into maplibre:main Dec 12, 2023
24 of 30 checks passed
louwers added a commit to louwers/maplibre-native that referenced this pull request Dec 12, 2023
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bart Louwers <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants