question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SRGB8_ALPHA8 blocks the main thread

See original GitHub issue

Describe the bug

The introduction of SRGB8_ALPHA8 in #22551 improved the render quality of sRGB textures, but also added significant synchronous conversion times that block the main thread. Every sRGB texture adds to the total blocking time, resulting in a poor user experience, especially when the scene contains many textures.

To Reproduce

Steps to reproduce the behavior:

  1. Set encoding of any Uint8 RGBA texture to sRGBEncoding. (WebGL 2 context is required.)
  2. Render a scene that uses the texture.
  3. See the main thread being blocked for a noticeable period of time during the first frame.

Code

The following example loads a cube map and sets its encoding to sRGBEncoding: https://codesandbox.io/s/srgb8-alpha8-wv3jf?runonclick=1&file=/index.js

Live example

The blocking behaviour can also be observed in live examples that load GLTF models, such as https://threejs.org/examples/?q=gltf#webgl_loader_gltf.

Expected behavior

Ideally, the main thread should not be blocked at all. Blocking time should at least be reduced as much as possible.

Screenshots

With LinearEncoding or sRGBEncoding pre r133 With sRGBEncoding since r133
Longest blocking time = 160 ms Longest blocking time = 1496 ms

Platform:

  • Device: Desktop
  • OS: Windows
  • Browser: Chrome, Brave, Firefox
  • Three.js version: r133

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:18 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
tojicommented, Nov 5, 2021

As I’ve mentioned on https://bugs.chromium.org/p/chromium/issues/detail?id=1256340 this appears to be an issue with how ANGLE generates mipmaps for sRGB textures.

An effective workaround for this bug (while an ANGLE fix is pending) would be to either:

A) Not use gl.generateMipmaps() with sRGB textures or B) Use texStorage2D when creating the textures.

For those with an affected system, you can see the issue with this (non-Three.js) test page: https://toji.github.io/web-texture-tool/demo/srgb-test.html

Generally I see that it runs fine with the exception of when I select sRGB textures, have it generate mipmaps, and turn off useTexStorage, at which point it janks like crazy.

2reactions
kenrussellcommented, Oct 4, 2021

Yes, please file on https://crbug.com/ . The problem might be on the Chromium or ANGLE side, so filing under Chromium is more general. Please include about:gpu in your report, and the zip archive you posted above, and post the bug ID here once filed - thanks in advance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

1256340 - SRGB8_ALPHA8 blocks the main thread - Monorail
Usage of SRGB8_ALPHA8 adds significant synchronous conversion times that block the main thread. Every sRGB texture adds to the total ...
Read more >
Understanding System Trace's Main Thread 'Blocked'
Using the 'System Trace' tool, we can clearly see on the Main Thread some 'blocked' states. However, I'm finding it difficult to pinpoint...
Read more >
C++ Thread blocks Main-Thread - Stack Overflow
Problem: When the ExecuteQueue Function get's called there's already two existing Packets in Queue and they get called correctly (printed to ...
Read more >
Which Task block the main thread? - Using Swift - Swift Forums
My understanding is, the work Data(contentsOf is synchronously blocking so it blocks whatever thread it is executed on. ContentView.fetch is ...
Read more >
Minimize main thread work - Chrome Developers
Learn about the browser's main thread and how you can optimize your web page to reduce main thread load and improve performance.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found