Bug 445179

Summary: Krita crashes when opening a file with 16-bit int depth
Product: [Applications] krita Reporter: Anna Medonosova <anna.medonosova>
Component: OpenGL CanvasAssignee: sh_zam <shzam>
Status: RESOLVED FIXED    
Severity: normal CC: amy, halla
Priority: NOR Keywords: regression
Version: git master (please specify the git hash!)   
Target Milestone: ---   
Platform: Android   
OS: Android 11.x   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: backtrace of the crash
test file
system information for bug reports (android)

Description Anna Medonosova 2021-11-08 21:46:29 UTC
Created attachment 143351 [details]
backtrace of the crash

SUMMARY
When I try to open a file with 16-bit int depth color profile, Krita crashes upon loading the file. 8-bit documents are opened correctly. I'm attaching a test file triggering the crash and a backtrace.

STEPS TO REPRODUCE
1. Open a file with 16-bit depth profile

OBSERVED RESULT
Krita crashes.

EXPECTED RESULT
The file is opened.
Comment 1 Anna Medonosova 2021-11-08 21:46:50 UTC
Created attachment 143352 [details]
test file
Comment 2 Halla Rempt 2021-11-09 07:11:57 UTC
Hm, this is android specific and it's an assert on the availability of opengl es. Sharaf, can you take a look?
Comment 3 sh_zam 2021-11-09 09:59:26 UTC
This seems to have been caused by: https://invent.kde.org/graphics/krita/-/commit/c6c82dda15037869b26a02e19f3f7900a06cce3b. It seems the `GL_EXT_texture_storage` is not available on Android's OpenGL ES2/3 implementation. 

I'm not sure whether all implementations are guaranteed to have this extension or not, CCing amyspark.
Comment 4 Bug Janitor Service 2021-11-26 06:36:49 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1179
Comment 5 amyspark 2021-11-27 13:51:35 UTC
(In reply to sh_zam from comment #3)
> I'm not sure whether all implementations are guaranteed to have this
> extension or not, CCing amyspark.

I need to revise my spam filters...

`GL_EXT_texture_storage` not only is a prerequisite for using any float textures in GLES 2, it's also widely available on hardware (judging from a Google search here). My changes also log the available extensions at launch, so Sharaf or Anna, can you post here what your tablets support? The data should be available in Help / Show system information for bug reports.
Comment 6 Anna Medonosova 2021-11-27 14:58:45 UTC
Created attachment 144002 [details]
system information for bug reports (android)

I'm attaching the system information. The device is a Samsung Galaxy Tab S6, if that's relevant. Thanks for looking into it :)
Comment 7 amyspark 2021-11-27 22:23:50 UTC
Thanks Anna! I now know what the problem is; you're running an ES3 device, for which GL_EXT_texture_storage is indeed not required (as it's provided for by the standard). Previously, it didn't crash because the ES3 case was covered by the desktop OpenGL clauses in initializeRGBA16FTextures; however, it would've crashed later if your device didn't have EXT_color_buffer_float.

I'll send the corrections to Sharaf's patch as soon as I have tested them here.
Comment 8 amyspark 2021-11-29 23:58:03 UTC
Git commit eb920fadf553ca827b4ff783ff6f82395bc88144 by L. E. Segovia, on behalf of Sharaf Zaman.
Committed on 29/11/2021 at 23:57.
Pushed by lsegovia into branch 'merge-requests/1179'.

Fix opengl es initialization for different formats

|     | GLES 2                 | GLES 3                               | DesktopGL  | Windows (ANGLE)        |
|-----|------------------------|--------------------------------------|------------|------------------------|
| 16i | GL_EXT_texture_storage | GL_EXT_texture_norm16                | GL_RGBA16  | GL_EXT_texture_storage |
| 16f | GL_EXT_texture_storage | GL_RGBA16F (!GL_EXT_texture_storage) | GL_RGBA16F | GL_EXT_texture_storage |
| 32f | GL_EXT_texture_storage | GL_RGBA16F (!GL_EXT_texture_storage) | GL_RGBA16F | GL_EXT_texture_storage |

Co-Authored-By: L. E. Segovia <amy@amyspark.me>

M  +92   -66   libs/ui/opengl/kis_opengl_image_textures.cpp

https://invent.kde.org/graphics/krita/commit/eb920fadf553ca827b4ff783ff6f82395bc88144
Comment 9 amyspark 2021-11-30 00:01:49 UTC
Git commit 803193d4bf3e85bc8915eab0099ab5678a3a4bac by L. E. Segovia, on behalf of Sharaf Zaman.
Committed on 30/11/2021 at 00:01.
Pushed by lsegovia into branch 'krita/5.0'.

Fix opengl es initialization for different formats

|     | GLES 2                 | GLES 3                               | DesktopGL  | Windows (ANGLE)        |
|-----|------------------------|--------------------------------------|------------|------------------------|
| 16i | GL_EXT_texture_storage | GL_EXT_texture_norm16                | GL_RGBA16  | GL_EXT_texture_storage |
| 16f | GL_EXT_texture_storage | GL_RGBA16F (!GL_EXT_texture_storage) | GL_RGBA16F | GL_EXT_texture_storage |
| 32f | GL_EXT_texture_storage | GL_RGBA16F (!GL_EXT_texture_storage) | GL_RGBA16F | GL_EXT_texture_storage |

Co-Authored-By: L. E. Segovia <amy@amyspark.me>
(cherry picked from commit eb920fadf553ca827b4ff783ff6f82395bc88144)

M  +92   -66   libs/ui/opengl/kis_opengl_image_textures.cpp

https://invent.kde.org/graphics/krita/commit/803193d4bf3e85bc8915eab0099ab5678a3a4bac
Comment 10 Bug Janitor Service 2021-12-28 17:11:41 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1262
Comment 11 amyspark 2022-01-06 14:12:36 UTC
Git commit 7480e580c11a007452d6df0983da322ee697807c by L. E. Segovia.
Committed on 06/01/2022 at 14:10.
Pushed by lsegovia into branch 'master'.

Fix OpenGL ES initialization for OCIO pipeline too

M  +16   -8    plugins/dockers/lut/ocio_display_filter_vfx2020.cpp
M  +21   -12   plugins/dockers/lut/ocio_display_filter_vfx2021.cpp

https://invent.kde.org/graphics/krita/commit/7480e580c11a007452d6df0983da322ee697807c
Comment 12 amyspark 2023-02-27 08:02:05 UTC
Git commit 47054a85d7a18001a2d6a1ce5fc555b9dcf19d3d by L. E. Segovia.
Committed on 21/02/2023 at 21:12.
Pushed by lsegovia into branch 'master'.

OpenGL: fix broken usage of OpenGL ES U16 surface

Back in eb920fadf553ca827b4ff783ff6f82395bc88144, I added this fallback
for ES2 clients that did provide U16 surfaces. However, I forgot to
specify that the texture format has to be RGBA.

This slipped past my testing at the time because selecting OpenGL ES on
desktops wasn't available until 5464b09830.

M  +2    -0    libs/ui/opengl/kis_opengl_image_textures.cpp
M  +0    -3    libs/ui/opengl/kis_texture_tile.cpp

https://invent.kde.org/graphics/krita/commit/47054a85d7a18001a2d6a1ce5fc555b9dcf19d3d