Created attachment 437756 [details]
Repo test of a iOS15 WebGL2 problem
Testing Unity WebGL2 builds on iOS 15 Beta 8, there are draw calls being used by Unity's UI system that cause WebGL2 to go into a bad state. It stops rendering, takes over 5000ms to complete a frame, usually crashing the page before too long.
The repo test runs correctly on MacOS Safari 15, and on Android mobiles. The issue only happens on iOS 15, tested on an iPhone XS and iPad.
In the repo test, there are three lines:
gl.drawElements(4, 174, 5123, 0); // Original from Unity, BAD
//gl.drawElements(4, 159, 5123, 0); // BAD
//gl.drawElements(4, 158, 5123, 0); // GOOD
If I change the drawElements count to 158, the problem goes away. At count 159, the problem appears.
In the real, non repo test, the shader and drawElements are generated from Unity, not manually authored.
I can confirm iPhone 12, WebGL via Metal: repros.
No repro on OpenGL.
Error during command buffer execution
Thanks so much Kimmo for investigating and confirming.
Do you think you might be able to take this bug since only someone from Apple can really debug it? Do you think it's something ANGLE's Metal backend is doing wrong and that's the cause of the command buffer execution error?
The vertex and element array buffers in this example are being allocated with DYNAMIC_DRAW. UNSIGNED_SHORT indices are being used. All of the data is zeroed out, so all of the triangles being drawn are degenerate. (All zero indices, all 0.0 vertices.)
Thanks to both of you.
Please don't get hung up on the zero index and vertex buffers, and the resulting degenerate triangles. I just didn't include the array data to avoid including the giant arrays, since it still seemed to have the effect without the data. If the degenerate triangles are throwing off testing, I can include that data.
I was wondering if there was any progress identifying the issue as it will be a significant problem for Unity WebGL builds running on iOS15.
(In reply to Brendan Duncan from comment #7)
> I was wondering if there was any progress identifying the issue as it will
> be a significant problem for Unity WebGL builds running on iOS15.
Thank you for the ping on this. I'll have a chance to look this week on what can be causing our perf issue. Our submission issue is due to a page fault in the shader. Perhaps we're not allocating enough space for our index buffer?
Created attachment 438868 [details]
Repo test of a iOS15 WebGL2 problem -- Draw One Triangle
Created attachment 438875 [details]
Repo test of a iOS15 WebGL2 problem - Draw No Vertex Buffer
Created attachment 438877 [details]
Repo test of a iOS15 WebGL2 problem - Draw Bigger Vertex Buffer
Adjusting the vertex array from 16384 to 16385, or to smaller (144) seem to work,
In addition to adjusting the drawElements call from 158 to 159.
(In reply to Kyle Piddington from comment #12)
> From debugging:
> Adjusting the vertex array from 16384 to 16385, or to smaller (144) seem to
I misread this: This isn't the vertex array. It's the index array.
I think something's gone wrong with allocating exactly 4k indices. How that relates to drawing less or more, I haven't figured out yet.
(In reply to Kyle Piddington from comment #13)
> I think something's gone wrong with allocating exactly 4k indices. How that
> relates to drawing less or more, I haven't figured out yet.
And by 4k, I meant 16k. (0x4000, got my wires crossed)
Issue appears to be in the provoking vertex index rewrite. I just spotted that the UI elements uses flat shading. Disabling index rewrite causes this to work.
Created attachment 438905 [details]
Note that there are important steps to take when updating ANGLE. See https://trac.webkit.org/wiki/UpdatingANGLE
This is great! Thank you Kyle!
Comment on attachment 438905 [details]
Looks good for what I understand.
I think we "guess" that `pipelineState.maxTotalThreadsPerThreadgroup >= 64`?
For obligatory nits, the first hunk is unnecessary and the second hunk you could have formatted with the command..
Created attachment 438963 [details]
Comment on attachment 438963 [details]
Great find and fix Kyle! I defer to Dean's earlier review.
Created attachment 439094 [details]
Patch for landing
Committed r283014 (242079@main): <https://commits.webkit.org/242079@main>
All reviewed patches have been landed. Closing bug and clearing flags on attachment 439094 [details].