Summary: | Dynamic indexing into a fixed-size uniform array with GLSL makes the Safari tab hang | ||||||
---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Rob Swain <robert.swain> | ||||
Component: | WebGL | Assignee: | Nobody <webkit-unassigned> | ||||
Status: | NEW --- | ||||||
Severity: | Normal | CC: | arvid.lunnemark, dino, johncunningham, josh, kbr, kevinrogovin, kkinnunen, kpiddington, mockersf, robert.swain, sabi, webkit-bug-importer | ||||
Priority: | P1 | Keywords: | InRadar | ||||
Version: | Safari 15 | ||||||
Hardware: | Mac (Apple Silicon) | ||||||
OS: | macOS 12 | ||||||
Bug Depends on: | |||||||
Bug Blocks: | 231180 | ||||||
Attachments: |
|
Description
Rob Swain
2022-01-06 10:34:13 PST
I'm bumping this to P1 because the bug reporting guidelines say that if the issue is something that worked in previous versions of WebKit and it has regressed, then bumping to P1 is OK. So I hope that is indeed OK. :) I tested this with "WebGL via Metal" and my understanding is that Safari 15.1 introduced using ANGLE for supporting WebGL on top of Metal. (In reply to Rob Swain from comment #1) > I tested this with "WebGL via Metal" and my understanding is that Safari > 15.1 introduced using ANGLE for supporting WebGL on top of Metal. Sorry, that was supposed to read: I tested this with "WebGL via Metal" **disabled** and the problematic code worked fine. Please provide a self-contained test case demonstrating the problem. Without one, it will be impossible to investigate this further. Created attachment 448578 [details]
3d scene example that reproduces the problem
The problem I am experiencing is implemented as WGSL shader code in the open source bevy game engine. As mentioned, the naga library is parsing WGSL and outputting GLSL for consumption by WebGL2 APIs. I am not currently writing any WebGL2/GLSL code myself, rather I am writing Rust/WGSL and compiling it to wasm.
However, I tried to implement a small test case which used a fullscreen triangle and the uniform buffer, structs, and function as described above, and I was unable to reproduce but I'm not sure I'm doing everything in the same way as in the code where I can reproduce the problem 100% consistently.
In the interest of providing you all a way of reproducing the problem, I have attached a zip file containing a directory containing some html, js, and wasm that is a simple scene with a ground plane, a cube, camera, and a light. If you unpack this somewhere, and serve the directory, then open the 3d_scene.html in Safari 15.2 with "WebGL via Metal" enabled (i.e. default configuration) then you should only see a white background with diagonal black lines (some CSS style that makes it easier to see when the canvas is actually being rendered to) and the tab hangs. If I disabled "WebGL via Metal", close Safari (I don't know if this is necessary when changing the configuration but I thought it might be), open it again and open the page, after maybe 15s or so, the scene renders correctly.
Let me know if that is enough or if you need something more. Hopefully it suffices. Thank you for the support!
This is certainly an issue with the translator, I think the uniform struct might be too big post-saturation modification. I'm not sure why it's causing a full tab-stall though... (In reply to Kyle Piddington from comment #6) > This is certainly an issue with the translator, I think the uniform struct > might be too big post-saturation modification. I'm not sure why it's causing > a full tab-stall though... What is the maximum size of the uniform struct through WebGL2 in Safari and how much overhead does the 'post-saturation modification' add? I can test this. I tried reducing the binding size to 16000 bytes, and even to 8000 bytes, and that did not help. It still hangs. I have the same issue on both an M1 and AMD GPU on MacOS in a complicated application when WebGL2 is configured to be translated to Metal. I work-around the issue by using usampler2D(then the application works, but less efficiently than it would with a uniform buffer object). In my application the UBO's in question are of the form: ``` uniform UBO { uvec4 data[N]; }; ``` and access is dynamic on the index into `data`. As a side note, Safari from around a year ago did work with this code (but I think I needed to configure it to use the GL backend, but the GL backend is even more broken because even with the work around the tab crashes). (In reply to Kevin Rogovin from comment #9) > I have the same issue on both an M1 and AMD GPU on MacOS in a complicated > application when WebGL2 is configured to be translated to Metal. I > work-around the issue by using usampler2D(then the application works, but > less efficiently than it would with a uniform buffer object). In my > application the UBO's in question are of the form: > > ``` > uniform UBO > { > uvec4 data[N]; > }; > ``` > > and access is dynamic on the index into `data`. > > As a side note, Safari from around a year ago did work with this code (but I > think I needed to configure it to use the GL backend, but the GL backend is > even more broken because even with the work around the tab crashes). One more thing, which I forgot to mention, the value of N is made so that the size of the UBO does not exceed GL_MAX_UNIFORM_BLOCK_SIZE This is still a problem and is preventing bevy, a Rust game engine, to have working 3D in Safari where it works fine in Chrome and Firefox. We now have a set of examples online here: https://bevyengine.org/examples/ A good 3D example containing the problematic code (which may have changed slightly since the bug was initially created but is mostly the same) that does not work in Safari Version 15.6.1 (17613.3.9.1.16) nor Release 151 (Safari 16.0, WebKit 17615.1.1.2) is: https://bevyengine.org/examples/3d/lighting/ I can reproduce this on M1 Pro. Bumping this! We're experiencing the same problem when calling WebGLRenderingContext.framebufferTexture2D with attachment=gl.COLOR_ATTACHMENT4 (or gl.COLOR_ATTACHMENT5, gl.COLOR_ATTACHMENT6, gl.COLOR_ATTACHMENT7). Our code works in Chrome and Firefox, but not in the latest Safari on M1 processors. If we uncheck "WebGL with Metal" it works again. Would love to see an update here! Let me know if there are any details that would be helpful for me to provide. @Arvid: please provide as small and self-contained a test case as you can. Zip it up and attach it to this bug. It's the only way we'll be able to make progress diagnosing what is happening. |