Bug 315419 - Enabling color correction from kcm results in kwin crash if kwin_gles is used
Summary: Enabling color correction from kcm results in kwin crash if kwin_gles is used
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: colorcorrection (show other bugs)
Version: git master
Platform: Other Linux
: NOR crash
Target Milestone: ---
Assignee: Casian Andrei
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-18 21:48 UTC by Dario Cambié
Modified: 2013-07-28 14:45 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Patch that should trigger error when enabling color correction with GLES < 3.0 (957 bytes, patch)
2013-04-19 20:25 UTC, Casian Andrei
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dario Cambié 2013-02-18 21:48:24 UTC
Backtrace:

Application: KWin (kwin_gles), signal: Segmentation fault
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Current thread is 1 (Thread 0x7fddc9d75880 (LWP 19892))]

Thread 4 (Thread 0x7fddbfdde700 (LWP 19893)):
#0  pthread_cond_timedwait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:215
#1  0x00007fddd9504fa7 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#2  0x00007fddd94f854f in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#3  0x00007fddd9504aec in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#4  0x00007fddc982e2e4 in ?? () from /usr/lib/nvidia-experimental-310/libGL.so.1
#5  0x00007fddd9273e9a in start_thread (arg=0x7fddbfdde700) at pthread_create.c:308
#6  0x00007fdddea32ccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#7  0x0000000000000000 in ?? ()

Thread 3 (Thread 0x7fddbed89700 (LWP 19894)):
#0  pthread_cond_timedwait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:215
#1  0x00007fddd9504fa7 in QWaitCondition::wait(QMutex*, unsigned long) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#2  0x00007fddd94f854f in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#3  0x00007fddd9504aec in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#4  0x00007fddc982e2e4 in ?? () from /usr/lib/nvidia-experimental-310/libGL.so.1
#5  0x00007fddd9273e9a in start_thread (arg=0x7fddbed89700) at pthread_create.c:308
#6  0x00007fdddea32ccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#7  0x0000000000000000 in ?? ()

Thread 2 (Thread 0x7fddbde3a700 (LWP 19895)):
#0  pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:162
#1  0x00007fdddaa98cd7 in ?? () from /usr/lib/x86_64-linux-gnu/libQtScript.so.4
#2  0x00007fdddaa98d09 in ?? () from /usr/lib/x86_64-linux-gnu/libQtScript.so.4
#3  0x00007fddc982e2e4 in ?? () from /usr/lib/nvidia-experimental-310/libGL.so.1
#4  0x00007fddd9273e9a in start_thread (arg=0x7fddbde3a700) at pthread_create.c:308
#5  0x00007fdddea32ccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#6  0x0000000000000000 in ?? ()

Thread 1 (Thread 0x7fddc9d75880 (LWP 19892)):
[KCrash Handler]
#6  KWin::GLShader::resolveLocations (this=this@entry=0x0) at /home/kde/kdesrc/kde/kde-workspace/kwin/libkwineffects/kwinglutils.cpp:431
#7  0x00007fddda2bb1e1 in KWin::GLShader::setUniform (this=0x0, uniform=KWin::GLShader::Offset, value=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/libkwineffects/kwinglutils.cpp:463
#8  0x00007fdddedcd8bf in KWin::SceneOpenGL2::doPaintBackground (this=<optimized out>, vertices=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/scene_opengl.cpp:560
#9  0x00007fdddedd03f8 in KWin::SceneOpenGL::paintBackground (this=this@entry=0x1df5260, region=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/scene_opengl.cpp:328
#10 0x00007fdddedc1663 in KWin::Scene::paintSimpleScreen (this=this@entry=0x1df5260, orig_mask=orig_mask@entry=8, region=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/scene.cpp:328
#11 0x00007fdddedbf39d in KWin::Scene::finalPaintScreen (this=0x1df5260, mask=8, region=..., data=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/scene.cpp:183
#12 0x00007fdddeddfdd4 in KWin::EffectsHandlerImpl::paintScreen (this=0x20cb530, mask=mask@entry=8, region=..., data=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/effects.cpp:363
#13 0x00007fdddd1a3c97 in KWin::Effect::paintScreen (this=this@entry=0x21f6af0, mask=mask@entry=8, region=..., data=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/libkwineffects/kwineffects.cpp:490
#14 0x00007fdddeddfd98 in KWin::EffectsHandlerImpl::paintScreen (this=0x20cb530, mask=mask@entry=8, region=..., data=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/effects.cpp:360
#15 0x00007fdddd1a3c97 in KWin::Effect::paintScreen (this=this@entry=0x16607a0, mask=mask@entry=8, region=..., data=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/libkwineffects/kwineffects.cpp:490
#16 0x00007fdddeddfd98 in KWin::EffectsHandlerImpl::paintScreen (this=0x20cb530, mask=8, region=..., data=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/effects.cpp:360
#17 0x00007fdddedc0c01 in KWin::Scene::paintScreen (this=0x1df5260, mask=0x7fff35754b2c, region=0x7fff35754c00) at /home/kde/kdesrc/kde/kde-workspace/kwin/scene.cpp:137
#18 0x00007fdddedd51c4 in KWin::SceneOpenGL::paint (this=0x1df5260, damage=..., toplevels=...) at /home/kde/kdesrc/kde/kde-workspace/kwin/scene_opengl.cpp:272
#19 0x00007fdddedba548 in KWin::Compositor::performCompositing (this=0x1679f90) at /home/kde/kdesrc/kde/kde-workspace/kwin/composite.cpp:574
#20 0x00007fddd961626c in QObject::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#21 0x00007fddd878ae9c in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#22 0x00007fddd878f30a in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#23 0x00007fddde519456 in KApplication::notify (this=0x7fff35755900, receiver=0x1679f90, event=0x7fff35755340) at /home/kde/kdesrc/kde/kdelibs/kdeui/kernel/kapplication.cpp:311
#24 0x00007fddd960156e in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#25 0x00007fddd9632462 in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#26 0x00007fddd9632618 in QEventDispatcherUNIX::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#27 0x00007fddd8830a3f in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#28 0x00007fddd96002bf in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#29 0x00007fddd9600548 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#30 0x00007fddd9605708 in QCoreApplication::exec() () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#31 0x00007fddded74c04 in kdemain (argc=2, argv=0x7fff35755a48) at /home/kde/kdesrc/kde/kde-workspace/kwin/main.cpp:536
#32 0x00007fddde96076d in __libc_start_main (main=0x4006a0 <main(int, char**)>, argc=2, ubp_av=0x7fff35755a48, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fff35755a38) at libc-start.c:226
#33 0x00000000004006d1 in _start ()

Reproducible: Always

Steps to Reproduce:
1. kwin_gles --replace &
2. kcmshell4 kwincompositing -> Enable CC
3. Dr. Konqi :)


Expected Results:  
If CC isn't supported with gles the checkbox could be disabled
Comment 1 Thomas Lübking 2013-02-18 22:02:18 UTC
did you get a "Color Scene Shader is not valid" konsole (1212) debug out?
Comment 2 Dario Cambié 2013-02-18 22:04:11 UTC
I got this:

kwin(20267): Failed to compile fragment shader: 
"0:12(36): error: invalid type `sampler3D' in declaration of `u_ccLookupTexture'
0:27(47): error: `u_ccLookupTexture' undeclared
0:0(0): error: no matching function for call to `texture3D(, vec3)'
0:27(88): error: type mismatch
0:27(104): error: Operands to arithmetic operators must be numeric

Application::crashHandler() called with signal 11; recent crashes: 1
KCrash: Application 'kwin_gles' crashing...
KCrash: Attempting to start /home/kde/kde4/lib/kde4/libexec/drkonqi from kdeinit
Comment 3 Thomas Lübking 2013-02-18 22:10:19 UTC
Yupp, basically the colorcorrection shader doesn't compile.
I guess we've to deactivate it for gles unless this is a mesa bug.

Nevertheless, the direct problem is the unconditional use of (this?) shader.
Either needs testing or dummy shader.
Comment 4 Martin Flöser 2013-02-19 07:06:27 UTC
it's to be expected. Only OpenGL ES 3.0 supports supports 3D textures or through an extension. So for GLES we should probably check the extension.
Comment 5 Martin Flöser 2013-02-22 06:54:41 UTC
*** Bug 315607 has been marked as a duplicate of this bug. ***
Comment 6 Casian Andrei 2013-03-10 16:04:19 UTC
I think the best solution would be to try to compile a dummy shader when initializing color correction, and if it does not work out, disable the color correction. It should not be difficult to do. I will get to it sometime soon.
Comment 7 Martin Flöser 2013-03-10 18:03:03 UTC
(In reply to comment #6)
> I think the best solution would be to try to compile a dummy shader when
> initializing color correction, and if it does not work out, disable the
> color correction. It should not be difficult to do. I will get to it
> sometime soon.
No, that's the wrong solution. It just needs to properly handle the 3D texture case for GLES by checking for the extension.
Comment 8 Casian Andrei 2013-03-11 05:39:28 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > I think the best solution would be to try to compile a dummy shader when
> > initializing color correction, and if it does not work out, disable the
> > color correction. It should not be difficult to do. I will get to it
> > sometime soon.
> No, that's the wrong solution. It just needs to properly handle the 3D
> texture case for GLES by checking for the extension.

Ok. How about doing both? Trying to compile a shader with a sampler3D would be an additional check, that may provide robustness to the code (that would be a separate review request).
Comment 9 Martin Flöser 2013-03-11 06:47:30 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > (In reply to comment #6)
> > > I think the best solution would be to try to compile a dummy shader when
> > > initializing color correction, and if it does not work out, disable the
> > > color correction. It should not be difficult to do. I will get to it
> > > sometime soon.
> > No, that's the wrong solution. It just needs to properly handle the 3D
> > texture case for GLES by checking for the extension.
> 
> Ok. How about doing both? Trying to compile a shader with a sampler3D would
> be an additional check, that may provide robustness to the code (that would
> be a separate review request).
We nowhere do just compile a shader to test capabilities. It means some overhead at setup time which I don't like.
Comment 10 Casian Andrei 2013-04-19 20:25:35 UTC
Created attachment 79047 [details]
Patch that should trigger error when enabling color correction with GLES < 3.0

Does this patch avoid the crash?

I do not have a GLES implementation that works with KWin it seems - complains about missing support to bind pixmaps to EGLImages. So I am unable to test on my system now.

There was a "if" check for GLES 3.0, but it only printed an error message, and it was forgeting to abort color correction init. That's why I opted for this 2-line patch instead of checking for the extension, even if that would have been nicer.
Comment 11 Dario Cambié 2013-04-20 15:02:52 UTC
Works for me :)
Comment 12 Casian Andrei 2013-07-23 16:52:34 UTC
Git commit 68c68ee3c2b54f968c4d8275f1e8a2e0ccc90dd7 by Casian Andrei.
Committed on 24/06/2013 at 20:41.
Pushed by casianandrei into branch 'master'.

Fix many color correction problems with OpenGL ES

On GLES, check for OES_texture_3D extension for color correction

Remove a block of ugly hack code that was supposedly needed to build
with OpenGL ES.

Convert the lookup texture data to uint8 on OpenGL ES before sending it
via glTexImage3D, because uint16 is not supported.

Check if the shaders have been reinitialized successfuly when trying to
activate color correction, prevent black screens when there are issues
with the shaders.
REVIEW: 111225

M  +29   -25   kwin/libkwineffects/kwinglcolorcorrection.cpp
M  +9    -0    kwin/libkwineffects/kwinglutils_funcs.cpp
M  +6    -0    kwin/libkwineffects/kwinglutils_funcs.h

http://commits.kde.org/kde-workspace/68c68ee3c2b54f968c4d8275f1e8a2e0ccc90dd7
Comment 13 Casian Andrei 2013-07-28 14:45:11 UTC
Git commit 2dba9dc11341d5746dbcb04c1c689f2fae5f411f by Casian Andrei.
Committed on 24/06/2013 at 20:41.
Pushed by casianandrei into branch 'KDE/4.11'.

Fix many color correction problems with OpenGL ES

On GLES, check for OES_texture_3D extension for color correction

Remove a block of ugly hack code that was supposedly needed to build
with OpenGL ES.

Convert the lookup texture data to uint8 on OpenGL ES before sending it
via glTexImage3D, because uint16 is not supported.

Check if the shaders have been reinitialized successfuly when trying to
activate color correction, prevent black screens when there are issues
with the shaders.
REVIEW: 111225
(cherry picked from commit 68c68ee3c2b54f968c4d8275f1e8a2e0ccc90dd7)

M  +29   -25   kwin/libkwineffects/kwinglcolorcorrection.cpp
M  +9    -0    kwin/libkwineffects/kwinglutils_funcs.cpp
M  +6    -0    kwin/libkwineffects/kwinglutils_funcs.h

http://commits.kde.org/kde-workspace/2dba9dc11341d5746dbcb04c1c689f2fae5f411f