Skip to content

Increase the maximum size of glyph atlas - #2930

Merged
amyleew merged 1 commit into
masterfrom
cjk-overflow
Aug 11, 2016
Merged

amyleew merged 1 commit into
masterfrom
cjk-overflow

Conversation

@xrwang

@xrwang xrwang commented Aug 2, 2016

Copy link
Copy Markdown
Contributor

Enlarging the glyph sheet allows CJK characters to render and not overflow. Works with mapbox/mapbox-gl-test-suite#131 tests.

Performance of this PR on bench:
Buffer, 803 ms
FPS, 60 frames per second

cc @amyleew

@bhousel

bhousel commented Aug 2, 2016

Copy link
Copy Markdown
Contributor

Yay! Been waiting a long time for this..

  1. I think this might necessitate a corresponding change in https://github.com/mapbox/mapbox-gl-shaders
  2. If you're going to do this, I'd raise the limit to 4096x4096.

Comment thread debug/cjk.html Outdated
map.on('load', function () {
map.addSource("points", {
"type": "geojson",
"data": 'https://raw.githubusercontent.com/mapbox/mapbox-gl-test-suite/cjk-overflow/data/cjkPts.geojson'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can change this line to mapbox-gl-test-suite/cjk-overflow/data/cjkPts.geojson

@lucaswoj

lucaswoj commented Aug 2, 2016

Copy link
Copy Markdown
Contributor

@lucaswoj

lucaswoj commented Aug 2, 2016

Copy link
Copy Markdown
Contributor

Performance of this PR on bench:
Buffer, 803 ms
FPS, 60 frames per second

These benchmarks are machine-specific and therefore relative numbers. Can you re-run these benchmarks against both this branch and master? (This'll be easier when we get around to #2405)

@lucaswoj lucaswoj self-assigned this Aug 2, 2016
@bhousel

bhousel commented Aug 3, 2016

Copy link
Copy Markdown
Contributor

Fortunately, shaders are not coupled to the bit-width of these attributes. https://github.com/mapbox/mapbox-gl-shaders/blob/master/src/icon.vertex.glsl#L11-L12

Isn't the glyph shader
https://github.com/mapbox/mapbox-gl-shaders/blob/master/src/sdf.vertex.glsl

But either way, that is helpful that the bit width doesn't need to change in the shader code.

The size of this array has a huge effect on GL JS performance.

There are a couple of members of data1 that don't need their size increased and no members of data2 that need their size increased.

If performance is a concern, could we dynamically adjust layoutVertexArrayType from Uint8 to Uint16 in realtime as the atlas increases in size? We only need it to be Uint16 for very large symbol and glyph atlases.

@lucaswoj

lucaswoj commented Aug 3, 2016

Copy link
Copy Markdown
Contributor

If performance is a concern, could we dynamically adjust layoutVertexArrayType from Uint8 to Uint16 in realtime as the atlas increases in size? We only need it to be Uint16 for very large symbol and glyph atlases.

This is a great idea and is theoretically possible. Implementing it will require some bigger architectural changes. Let's keep this idea in our back pocket.

@xrwang

xrwang commented Aug 3, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for all the detailed feedback! Updated this PR per comments. Bench results on master versus branch below. Please let me know if I've missed / misunderstood something : )

master

buffer: 795 ms

fps: 60 frames per second

frame-duration:
5.4 ms per frame at zoom 4. 0% of frames took longer than 16ms.
5.2 ms per frame at zoom 8. 0% of frames took longer than 16ms.
7 ms per frame at zoom 11. 0% of frames took longer than 16ms.
8.6 ms per frame at zoom 13. 0% of frames took longer than 16ms.
8.3 ms per frame at zoom 15. 0% of frames took longer than 16ms.
5.6 ms per frame at zoom 17. 0% of frames took longer than 16ms.

avg: 6.7 ms per frame. 0% of frames took longer than 16ms.

this pr

buffer: 833 ms

fps: 60 frames per second

frame-duration:
5.5 ms per frame at zoom 4. 0% of frames took longer than 16ms.
5.2 ms per frame at zoom 8. 0% of frames took longer than 16ms.
7.1 ms per frame at zoom 11. 0% of frames took longer than 16ms.
9.3 ms per frame at zoom 13. 0% of frames took longer than 16ms.
8.1 ms per frame at zoom 15. 0% of frames took longer than 16ms.
5.2 ms per frame at zoom 17. 0% of frames took longer than 16ms.

avg: 6.7 ms per frame. 0% of frames took longer than 16ms.

@lucaswoj

lucaswoj commented Aug 3, 2016

Copy link
Copy Markdown
Contributor

This is looking great @xrwang! A 5% slowdown in buffer creation time (795 ms -> 833 ms) is a good starting point. Do you think there's anything we can do to make the slowdown even smaller? Did you verify that the slowdown is related to the increase in StructArray size?

@xrwang

xrwang commented Aug 3, 2016 •

Copy link
Copy Markdown
Contributor Author

@lucaswoj, yup, I can definitely confirm that the slow down is related to the increase in StructArray size. Though from benching several times, it might also be related to the glyph atlas size itself, ie 2048 vs 4096? Although technically that shouldn't affect it, only the StructArray size should ? Anyhow, happy to keep it at 2048 for now to veer on the cautious side. benched several times below, and this branch with uint16, 2048 seems very close to the master branch's buffer time.

benching sequence, results in order*

  1. master, buffer: 774ms
  2. this branch, with uint 16, 4096 glyph atlas, buffer: 830ms
  3. this branch, with uint 8, 4096 glyph atlas, buffer: 777 ms
  4. this branch, with uint16, 2048 glyph atlas, buffer: 766 ms *
  5. master, buffer: 765 ms
  6. this branch with uint16, 2048 glyph atlas, buffer: 792 ms *
  7. master, buffer: 784 ms

@lucaswoj

lucaswoj commented Aug 3, 2016 •

Copy link
Copy Markdown
Contributor

This looks great! Thank you for doing these benchmarks @xrwang.

Though from benching several times, it might also be related to the glyph atlas size itself, ie 2048 vs 4096? Although technically that shouldn't affect it, only the StructArray size should ?

It is possible and looks to be the case that the glyph atlas size has a large effect on performance too. If a width of 2048 is enough for real world usage with CJK fonts then I'm happy with this result and almost ready to ship this PR.

Next Steps

See below 👇

Comment thread js/data/bucket/symbol_bucket.js Outdated
@@ -61,11 +61,11 @@ var layoutVertexArrayType = new Bucket.VertexArrayType([{
type: 'Int16'
}, {
name: 'a_data1',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you think about renaming this to something more self-documenting like a_texture_pos?

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.

👍 sounds good, it'll be clearer that way.

@xrwang

xrwang commented Aug 5, 2016

Copy link
Copy Markdown
Contributor Author

cool, updated per comments. The name change for a_texture_pos is over here: mapbox/mapbox-gl-shaders#22

Tests over on mapbox/mapbox-gl-test-suite#131 should be ready.

Benched with the resizing by 4 (instead of 2) and performance improved a lot!

master
806 ms

this branch
796 ms

master
814 ms

this-branch
822 ms

@brunoabinader brunoabinader mentioned this pull request Aug 5, 2016
2 tasks done
@brunoabinader

Copy link
Copy Markdown
Contributor

Created mapbox/mapbox-gl-native#5873 to track these changes in GL native 👍

@lucaswoj

lucaswoj commented Aug 11, 2016 •

Copy link
Copy Markdown
Contributor

Next Steps

  • squash & rebase mapbox-gl-test-suite
  • update test-suite SHA in GL JS
  • rename a_data2 attribute to a_data
  • squash & rebase mapbox-gl-shaders
  • update shaders SHA in GL JS
  • code review
  • squash & rebase GL JS
  • 🍏
  • run benchmarks
  • do a manual test of GL JS on debug pages
  • update mapbox-gl-native PR with new SHAs and shader changes
    • 🚢

Related PRs

@lucaswoj lucaswoj changed the title CJK overflow Increase the maximum allowable size of glyph atlas Aug 11, 2016
@lucaswoj lucaswoj changed the title Increase the maximum allowable size of glyph atlas Increase the maximum size of glyph atlas Aug 11, 2016
@lucaswoj

Copy link
Copy Markdown
Contributor

Pushing squashed & based version. Previous HEAD was db7c0d8

@lucaswoj

Copy link
Copy Markdown
Contributor

Branch Benchmarks

buffer: 960 ms
fps: 60 fps
frame-duration: 7 ms, 0% > 16ms
query-point: 0.67 ms
query-box: 50.55 ms
geojson-setdata-small: 11 ms
geojson-setdata-large: 114 ms

master Benchmarks

buffer: 922 ms
fps: 60 fps
frame-duration: 6.9 ms, 0% > 16ms
query-point: 0.71 ms
query-box: 50.73 ms
geojson-setdata-small: 11 ms
geojson-setdata-large: 111 ms

Comment thread js/symbol/glyph_source.js
this.stacks[fontstack] = {};
}
if (this.atlases[fontstack] === undefined) {
this.atlases[fontstack] = new GlyphAtlas(128, 128);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please leave this as 128,128.. most latin alphabets fit in this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bhousel It's still 128! I moved this constant inside GlyphAtlas because there are some tricky dependencies between the default size, growth factor, and max size. Having them all in one place makes that clearer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh sorry!! you're right! :)

@amyleew
amyleew merged commit a84083b into master Aug 11, 2016
@amyleew
amyleew deleted the cjk-overflow branch August 11, 2016 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants