This simple glsl function kills Safari + WebGL via Metal dead

573 views
Skip to first unread message

Richard Davey

unread,
Oct 17, 2022, 3:14:37 PM10/17/22
to WebGL Dev List
Hi,

Would love to know if anyone can shed some light on why this code performs so adversely on Safari 16.0 (macOS Monterey v12.6). Tested on an iMac M1.

glsl1.png
For context, uMainSampler is a sampler2D array, and this function is called from main such as:

vec4 texture = getSampler(int(outTexId), outTexCoord)

Using this approach we're seeing fps rates no higher than 13fps with a single sprite on-screen and it drags Safari performance really low with it.

If we disable 'WebGL via Metal' it's a solid 60 fps.

If we use Chrome or Firefox, it's a solid 60 fps.

So this is 100% Metal related.

If we use the following function instead, we also get 60 fps:

glsl2.png
If the first approach performed badly on all browsers, I could understand the issue was just with the function, but to see it only tank on Safari with Metal must point to something more specific to how it's handled in the back end.

In the meantime, we'll work around it with the if/else approach, but it'd be great to know if this is a common issue (and has a fix upstream?)

Cheers,

Rich

Ivan Popelyshev

unread,
Oct 25, 2022, 4:32:40 AM10/25/22
to WebGL Dev List
Obligatory stupid comment: "You should use texture arrays!!!111!!!11!!!" . 

Done. Now, no one will pester you about it )

I can also remind usual answer: different size.

Now seriously: that's the first time I see that trick and I like it. Look what I have to do without it: https://github.com/sciner/webcraft/blob/5ce5d81af89210d61260bbf987afb097d8cb9a75/www/shaders/shader.blocks.glsl#L389-L445

понедельник, 17 октября 2022 г. в 22:14:37 UTC+3, rda...@gmail.com:

Ken Russell

unread,
Oct 25, 2022, 5:26:32 PM10/25/22
to webgl-d...@googlegroups.com
In order for browser implementers to make progress on this, a small and self-contained test case would be needed. You can file this on bugs.webkit.org , or perhaps more ideally on anglebug.com if you can reproduce this on Chrome Canary with "Choose ANGLE graphics backend" set to "Metal" in about:flags.

-Ken



--
You received this message because you are subscribed to the Google Groups "WebGL Dev List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to webgl-dev-lis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/webgl-dev-list/1b8964ce-1160-4c62-867d-db85e7bc7e61n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages