Bug 222790 - WebGL2: Red flickering when using copyTexImage2D()
Summary: WebGL2: Red flickering when using copyTexImage2D()
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebGL (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kimmo Kinnunen
URL:
Keywords: InRadar
Depends on: 222964
Blocks: webgl2conformance
  Show dependency treegraph
 
Reported: 2021-03-05 02:25 PST by Michael Herzog
Modified: 2021-03-09 00:54 PST (History)
8 users (show)

See Also:


Attachments
Patch (15.57 KB, patch)
2021-03-08 05:26 PST, Kimmo Kinnunen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Herzog 2021-03-05 02:25:17 PST
I've enabled WebGL 2 in Safari Technology Preview Release 121 (Safari 14.2, WebKit 15612.1.4.3) on macOS 10.15.7.

Please open https://threejs.org/examples/#webgl_framebuffer_texture

The demo renders a scene and then copies a portion of the framebuffer into a texture (via copyTexImage2D()). This texture is then used for a sprite which is rendered at the top-left corner of the screen with an additional render pass.

When you now hover with the mouse over the links in the left menu bar, the sprite starts to flicker red.

This does not happen when using WebGL1 and not with latest Firefox and Chrome.

When using stable Safari (Version 14.0 15610.1.28.1.9, 15610) and WebGL 2, there is only a signle red flicker right when loading the page (but not when hovering links).

My system:

iMac (Retina 5K, 27'', ultimo 2014)
4 GHz Quad-Core Intel Core i7
16 GB 1600 MHz DDR3
AMD Radeon R9 M295X 4 GB
Comment 1 Kenneth Russell 2021-03-05 21:09:15 PST
On my machine (2017 15" MacBook Pro, Intel HD 630 / AMD Radeon 560), the sprite flickers to black while hovering over the links on the left.

The texture copying code looks correct - it's doing the copy inside the requestAnimationFrame callback. Otherwise I might have guessed it was relying on undefined behavior, if preserveDrawingBuffer is set to the default false (haven't checked).

The behavior is quite strange. I don't know how other rendering work the browser is doing could interfere with the WebGL rendering in this way.

Could this have something to do with how the WebGLLayer publishes its textures to the compositor? Kimmo, can you reproduce?
Comment 2 Kimmo Kinnunen 2021-03-08 05:26:08 PST
Created attachment 422557 [details]
Patch
Comment 3 Kimmo Kinnunen 2021-03-08 05:28:19 PST
Red is the uninitialized IOSurface contents visible due to multisample resolve blit erroring out.
Comment 4 Kenneth Russell 2021-03-08 16:07:17 PST
Comment on attachment 422557 [details]
Patch

Looks good. Would you please consider putting up a pull request enhancing the associated tests in the WebGL conformance suite? Please see https://github.com/KhronosGroup/WebGL/issues/3255 . Thanks. r+
Comment 5 EWS 2021-03-09 00:53:36 PST
Committed r274141: <https://commits.webkit.org/r274141>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 422557 [details].
Comment 6 Radar WebKit Bug Importer 2021-03-09 00:54:15 PST
<rdar://problem/75207365>