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

Replace rather than update Metal buffers #1842

Merged
merged 9 commits into from
Nov 20, 2023
Merged

Replace rather than update Metal buffers #1842

merged 9 commits into from
Nov 20, 2023

Conversation

TimSylvester
Copy link
Collaborator

With #1831, small non-index buffers (<= 4KiB) are encoded directly into the render command encoder rather than referenced as buffers. This should eliminate sequencing problems where the buffer is updated while the previous frame rendering is still using them.

In order to avoid the same problem with larger buffers (e.g., vertex attributes), this change makes buffer updates allocate a new Metal buffer instead of modifying an existing one. Index buffers were already being replaced rather than updating.

The effect on performance in the benchmarks seems minimal, but cases where the vertex buffers are large and changing regularly (e.g., symbols with layout in dense areas) there may be a more significant effect.

The previous buffers will remain allocated until they are no longer referenced, so memory utilization will increase somewhat.

Before:
Average frame encoding time: 2.6382 ms
Average frame rendering time: 14.5671 ms

Average frame encoding time: 2.6830 ms
Average frame rendering time: 14.5455 ms

Average frame encoding time: 2.5971 ms
Average frame rendering time: 14.5503 ms

---

After:
Average frame encoding time: 2.6585 ms
Average frame rendering time: 14.5019 ms

Average frame encoding time: 2.6152 ms
Average frame rendering time: 14.5189 ms

Average frame encoding time: 2.6410 ms
Average frame rendering time: 14.5200 ms

Copy link
Collaborator

@sjg-wdw sjg-wdw left a comment

Choose a reason for hiding this comment

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

What a nice, small change.

Copy link

codecov bot commented Nov 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (4150c8b) 85.83% compared to head (3cecfc7) 85.85%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1842      +/-   ##
==========================================
+ Coverage   85.83%   85.85%   +0.02%     
==========================================
  Files         568      568              
  Lines       27975    27986      +11     
==========================================
+ Hits        24012    24028      +16     
+ Misses       3963     3958       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Nov 6, 2023

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  +0.0%    +384  -0.0%     -16    TOTAL

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

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +19% +22.4Mi  +403% +24.0Mi    TOTAL

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

@stefankarschti
Copy link
Collaborator

After some panning & zooming the street name labels are drawn in the wrong place. Maybe some UBO buffer is not getting updated and the matrix is wrong?

RPReplay_1842.MP4

Replace Metal-specific `Context::clear` with common `performCleanup`.
Add stats logging to the end of benchmarking.
Simplify stats checking in stencil test.
@TimSylvester
Copy link
Collaborator Author

About 1/3 of buffers above the 4k threshold in the benchmark, but only 11K of 1.8M = 0.6% of updates are to large buffers.

totalBuffers = 48322
totalBufferObjs = 15239
bufferUpdates = 1769897
bufferObjUpdates = 10878
bufferUpdateBytes = 296601088
uniformUpdateBytes = 107493168

@TimSylvester TimSylvester marked this pull request as draft November 10, 2023 16:13
@TimSylvester TimSylvester marked this pull request as ready for review November 17, 2023 20:14
@louwers louwers requested a review from mwilsnd November 19, 2023 16:39
@louwers louwers merged commit ffcf132 into main Nov 20, 2023
36 checks passed
@louwers louwers deleted the metal-buffer-updates branch November 20, 2023 20:58
louwers pushed a commit to louwers/maplibre-native that referenced this pull request Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants