Bug 426458 - Shaders in kqtquickcharts 5.74.0 don't work with OpenGL ES3
Summary: Shaders in kqtquickcharts 5.74.0 don't work with OpenGL ES3
Status: RESOLVED FIXED
Alias: None
Product: kqtquickcharts
Classification: Frameworks and Libraries
Component: general (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Sebastian Gottfried
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-12 23:03 UTC by Bernhard Rosenkränzer
Modified: 2020-09-14 08:56 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bernhard Rosenkränzer 2020-09-12 23:03:29 UTC
SUMMARY
On Qt built with OpenGL ES2 rather than desktop OpenGL, kqtquickcharts fails with

Sep 13 00:48:38 ryzen9 plasmashell[2200]: QOpenGLShader::compile(Vertex): 0:40(1): error: illegal use of reserved word `attribute'
0:40(1): error: syntax error, unexpected ERROR_TOK, expecting end of file
Sep 13 00:48:38 ryzen9 plasmashell[2200]: *** Problematic Vertex shader source code ***
#version 300 es
#line 1
// Important: The line above _must_ be the first line in this file.

/*
 * This file is part of KQuickCharts
 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

// This file contains common directives needed for the shaders to work.
// It is included as the very first bit in the shader.
// Important: If a specific GLSL version is needed, it should be set in this
// file.

// This file is intended for OpenGLES version 2.0 or greater.

#extension GL_OES_standard_derivatives : enable
#define API_ES3
/*
 * This file is part of KQuickCharts
 * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

uniform highp mat4 matrix;
uniform lowp vec2 aspect;

#ifdef LEGACY_STAGE_INOUT
attribute highp vec4 in_vertex;
attribute mediump vec2 in_uv;
varying mediump vec2 uv;
#else
in highp vec4 in_vertex;
in mediump vec2 in_uv;
out mediump vec2 uv;
#endif
attribute highp float _qt_order;
uniform highp float _qt_zRange;
void main() {
    uv = (-1.0 + 2.0 * in_uv) * aspect;
    uv.y *= -1.0;
    gl_Position = matrix * in_vertex;
    gl_Position.z = (gl_Position.z * _qt_zRange + _qt_order) * gl_Position.w;
}

***



STEPS TO REPRODUCE
1. Build Qt with OpenGL ES
2. Run anything that uses kqtquickcharts


OBSERVED RESULT
Crash with log given before


EXPECTED RESULT
Works


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: OpenMandriva Cooker
KDE Plasma Version: 5.19.5
KDE Frameworks Version: 5.74.0
Qt Version: 5.15.1
Comment 1 Bernhard Rosenkränzer 2020-09-12 23:05:53 UTC
Not too familiar with OpenGL shaders, but looks to me like something defines
Comment 2 Bernhard Rosenkränzer 2020-09-12 23:09:18 UTC
[sorry, previous comment submitted prematurely - dog tried to jump on my lap and hit the keyboard ;) ]

So, looks like something defines LEGACY_STAGE_INOUT even for ES3, or the "attribute highp float _qt_order;" needs to go into the ifdef
Comment 3 Bernhard Rosenkränzer 2020-09-14 02:35:00 UTC
Looking at it a bit more, the problem is that the code injected by qtquick (src/quick/scenegraph/coreapi/qsgshaderrewriter.cpp, around line 192) isn't compatible with the gles3 boilerplate put in by kqtquickcharts.

Forching the use of header_es2.glsl instead of header_es3.glsl even when OpenGL ES 3.x is supported (comment out the GLES3 chunk in SDFShader::setShaders) "fixes" the problem.
Comment 4 Arjen Hiemstra 2020-09-14 08:55:30 UTC
Yeah Qt does not support proper GLES3 at all. I ran into that when trying to set this up, but I seem to recall I did not even get a GLES3 context, just a 2.1, which is probably why I left the check in there.
Comment 5 Arjen Hiemstra 2020-09-14 08:56:15 UTC
Git commit eeb4ab08ef9fc14b64202bd42ffc2b83bd98ecf9 by Arjen Hiemstra.
Committed on 14/09/2020 at 08:54.
Pushed by ahiemstra into branch 'master'.

Remove check for GLES3 in SDFShader

Qt doesn't actually support GLES3 and will insert incorrect stuff into
the shader if we use GLSL 300. So remove the check for now and instead
just always use GLES2.

M  +1    -5    src/scenegraph/SDFShader.cpp

https://invent.kde.org/frameworks/kquickcharts/commit/eeb4ab08ef9fc14b64202bd42ffc2b83bd98ecf9