Bug 245476

Summary: REGRESSION (iOS 16): WebGL 2 crashing on glReadPixels
Product: WebKit Reporter: George <george>
Component: WebGLAssignee: Kimmo Kinnunen <kkinnunen>
Status: RESOLVED FIXED    
Severity: Major CC: dino, kbr, kkinnunen, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari 15   
Hardware: iPhone / iPad   
OS: iOS 16   
See Also: https://bugs.webkit.org/show_bug.cgi?id=250565

Description George 2022-09-21 06:49:44 PDT
Hallo,

We have just updated to IOS 16 and found a serious issue in WebGL2 glReadPixels function call from our wasm module.
glReadPixes either crashes on bigger files or becomes very slow on smaller files. 

Everything was working nice and fast on IOS 15.5, until we updated to IOS 16.0 (and Safari 16.0 I suppose).

To reproduce the crashing issue (on IOS 16.0 only) please do as follows, for reference I have tried on iPhone 12.

1. Open this URL: https://tinyurl.com/mry9mkrj  
2. The page will load a mid-size 3D Model
3. Now try to rotate it (this will make a call to glReadPixels to get a pivot)
4. BSOD Crash: WebGL: context lost. readPixels

To reproduce the slow glReadPixels function issue (on IOS 16.0 only) please do as follows, for reference I have tried on iPhone 12.

1. Open this URL: https://tinyurl.com/2unkf9kx   
2. The page will load a small 3D Model that rotates now fast

Now we can start sending many glReadPixels to notice major drop in FPS.
To do that follow below steps:

3. Click on Pick Mode and select length
4. Use the thumb widget to measure some distance length and see how slowly it responds to glReadPixels 

Everything was working fine in IOS 15, looks like a major issue as glReadPixels is a core WebGL2 call.

Thanks
Comment 1 Radar WebKit Bug Importer 2022-09-21 19:35:50 PDT
<rdar://problem/100252324>
Comment 2 George 2022-09-21 21:55:05 PDT
This is also the code inside my wasm module, if it helps...

glBindFramebuffer(GL_READ_FRAMEBUFFER, m_GbufferES.fbo);
glReadBuffer(m_GbufferES.color_depth_buffer);

// SLOW or CRASHING STEP (IOS 16):
glReadPixels(x, y, dim.x, dim.y, GL_RGBA_INTEGER, GL_INT, depth_pixel_v);
depth_pixel = depth_pixel_v[0];
glBindFramebuffer(GL_FRAMEBUFFER, 0);
Comment 3 Kimmo Kinnunen 2022-12-01 17:29:01 PST
Thanks for the report.
This seems to be a out-of-memory in our GPU process due to the lack of owner attribution for read pixels memory.

While we fix this, you can see if you can reduce the amount of pixels read.
I'm observing:
 - one 1x1 read pixels which likely is not the problem. 
 - one fullscreen read pixels, which likely is the problem.
Comment 4 George 2022-12-06 01:12:16 PST
Hallo and thanks for the reply,

I am not sure what lack of owner attribution is but I double tested my code and it looks like all calls are 1x1 and still getting the same issue.

We are waiting for the fix! Thanks!
Comment 5 Kimmo Kinnunen 2022-12-15 08:10:01 PST
Pull request: https://github.com/WebKit/WebKit/pull/7688
Comment 6 Kimmo Kinnunen 2022-12-19 04:05:53 PST
Pull request: https://github.com/WebKit/WebKit/pull/7842
Comment 7 EWS 2022-12-19 23:59:27 PST
Committed 258127@main (5192197861cf): <https://commits.webkit.org/258127@main>

Reviewed commits have been landed. Closing PR #7842 and removing active labels.