After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756142 - Bring back support for legacy OpenGL contexts
Bring back support for legacy OpenGL contexts
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkGLArea
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-10-06 20:38 UTC by Emmanuele Bassi (:ebassi)
Modified: 2015-10-07 15:23 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gdk: Allow querying if a GL context is in legacy mode (3.88 KB, patch)
2015-10-06 20:38 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
gl: Store the legacy bit in the GL program data (1.36 KB, patch)
2015-10-06 20:38 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
gl: Use older GLSL shaders with legacy contexts (4.30 KB, patch)
2015-10-06 20:38 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
x11: Create legacy GLX contexts (5.43 KB, patch)
2015-10-06 20:38 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
x11: Control legacy GL context via environment variable (1.12 KB, patch)
2015-10-06 20:38 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
fixup! x11: Create legacy GLX contexts (1.81 KB, patch)
2015-10-06 20:50 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
Allow testglarea to work with legacy GL contexts (2.88 KB, patch)
2015-10-06 21:00 UTC, Emmanuele Bassi (:ebassi)
none Details | Review
gdk: Allow querying if a GL context is in legacy mode - v2 (3.88 KB, patch)
2015-10-07 07:59 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
gl: Store the legacy bit in the GL program data - v2 (1.36 KB, patch)
2015-10-07 07:59 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
gl: Use older GLSL shaders with legacy contexts (4.39 KB, patch)
2015-10-07 08:00 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
x11: Create legacy GLX contexts - v2 (5.66 KB, patch)
2015-10-07 08:00 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
x11: Control legacy GL context via environment variable (1.63 KB, patch)
2015-10-07 08:00 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
Allow testglarea to work with legacy GL contexts - v2 (2.88 KB, patch)
2015-10-07 08:01 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
docs: Improve description of gdk_gl_context_is_legacy() (1.45 KB, patch)
2015-10-07 08:01 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review
wayland: Allow falling back to compatibility EGL contexts (3.03 KB, patch)
2015-10-07 14:29 UTC, Emmanuele Bassi (:ebassi)
committed Details | Review

Description Emmanuele Bassi (:ebassi) 2015-10-06 20:38:03 UTC
We can sneak back in support for legacy GL contexts, as a fallback in case the underlying GL implementation does not support core 3.2 profiles.

The important part is to ensure that any GL contexts created after the first one — i.e. the paint context for a GdkWindow — follow the same version of GL; if the paint context uses the legacy GL, then all GL contexts that are sharing resources with it must be legacy ones.
Comment 1 Emmanuele Bassi (:ebassi) 2015-10-06 20:38:32 UTC
Created attachment 312759 [details] [review]
gdk: Allow querying if a GL context is in legacy mode

We want to have the ability to fall back to legacy GL contexts when
creating them. In order to do so, we need to store the legacy bit on the
GdkGLContext, as well as being able to query it.

Setting the legacy bit from outside GDK is not possible; we cannot
create GL contexts in 3.2 core profile *and* compatibility modes at the
same time, and if we allowed users to select the legacy mode themselves,
it would break the creation of the GdkWindow's paint GL context.

What we do allow is falling back to legacy GL context if the platform
does not support 3.2 core profiles — for instance, on older GPUs or
inside virtualized environments.

We are also going to use the legacy bit internally, to choose which GL
API we can use when drawing GL content.
Comment 2 Emmanuele Bassi (:ebassi) 2015-10-06 20:38:39 UTC
Created attachment 312760 [details] [review]
gl: Store the legacy bit in the GL program data

We need to know if we're using a legacy GL context in various places.
Comment 3 Emmanuele Bassi (:ebassi) 2015-10-06 20:38:44 UTC
Created attachment 312761 [details] [review]
gl: Use older GLSL shaders with legacy contexts

If we're using modern GLSL, then we should stop using deprecated
modifiers, like 'varying' and 'attribute', as well as deprecated global
variables, like 'gl_FragColor'.

On the other hand, with legacy contexts we should be using older GLSL
shaders, to maximize compatibility.
Comment 4 Emmanuele Bassi (:ebassi) 2015-10-06 20:38:50 UTC
Created attachment 312762 [details] [review]
x11: Create legacy GLX contexts

If GLX has support for the GLX_ARB_create_context_profile extension,
then we use the GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; if it does
not, we fall back to the old glXCreateNewContext() API.

We use the shared GdkGLContext to decide whether the GLX context should
use the legacy bit or not.
Comment 5 Emmanuele Bassi (:ebassi) 2015-10-06 20:38:59 UTC
Created attachment 312763 [details] [review]
x11: Control legacy GL context via environment variable

For testing purposes, we may want to force the creation of legacy GLX
contexts via an environment variable.
Comment 6 Emmanuele Bassi (:ebassi) 2015-10-06 20:50:53 UTC
Created attachment 312765 [details] [review]
fixup! x11: Create legacy GLX contexts
Comment 7 Emmanuele Bassi (:ebassi) 2015-10-06 21:00:57 UTC
Created attachment 312767 [details] [review]
Allow testglarea to work with legacy GL contexts

Use the 1.30 GLSL shading language for the fragment and vertex shaders.
Comment 8 Emmanuele Bassi (:ebassi) 2015-10-06 21:07:44 UTC
I pushed the rebased patch set to wip/ebassi/legacy-gl.

With these patches, I can run testglarea using a GLX context created in legacy mode, and it works reasonably well.

I haven't done Wayland — though it'd be pretty similar. I can very likely resurrect the changes needed to get legacy GL contexts on Windows from pre-3.16 master, but I wouldn't be able to test it.
Comment 9 Matthias Clasen 2015-10-07 02:17:46 UTC
Review of attachment 312759 [details] [review]:

::: gdk/gdkglcontext.c
@@ +560,3 @@
+ * @context: a #GdkGLContext
+ *
+ * Whether the #GdkGLContext is in legacy mode or not.

I think there should be some explanation here (or in the long desc) what legacy mode actually means.
Comment 10 Matthias Clasen 2015-10-07 02:18:24 UTC
Review of attachment 312760 [details] [review]:

ok
Comment 11 Matthias Clasen 2015-10-07 02:25:12 UTC
Review of attachment 312761 [details] [review]:

::: gdk/gdkgl.c
@@ +151,2 @@
     "#version 150\n"
     "uniform sampler2D map;"

Missing \n ? I know these are probably optional, but if you have them everywhere else...

@@ +207,2 @@
     "#version 150\n"
     "uniform sampler2DRect map;"

Missing \n ?

@@ +223,3 @@
+  static const char *vertex_shader_code_130 =
+    "#version 130\n"
+    "uniform sampler2DRect map;"

Missing \n ?
Comment 12 Matthias Clasen 2015-10-07 02:26:45 UTC
Review of attachment 312762 [details] [review]:

looks ok
Comment 13 Matthias Clasen 2015-10-07 02:30:10 UTC
Review of attachment 312762 [details] [review]:

::: gdk/x11/gdkglcontext-x11.c
@@ +682,3 @@
+    {
+      context_x11->glx_context = create_legacy_context (display, context_x11->glx_config, share);
+      legacy_bit = TRUE;

Here you change the legacy_bit after you've already printed "legacy no" further up. Might be better to move the GDK_NOTE down and print the data for the gl context we actually ended up with ?
Comment 14 Matthias Clasen 2015-10-07 02:31:25 UTC
Review of attachment 312763 [details] [review]:

::: gdk/x11/gdkglcontext-x11.c
@@ +639,3 @@
   /* If there is no glXCreateContextAttribsARB() then we default to legacy */
+  legacy_bit = !GDK_X11_DISPLAY (display)->has_glx_create_context ||
+               g_getenv ("GDK_GL_USE_LEGACY") != NULL;

I would prefer to extend the existing GDK_GL env var instead of adding more one-offs.
Comment 15 Matthias Clasen 2015-10-07 02:32:26 UTC
Review of attachment 312765 [details] [review]:

I guess this answers my comment on the earlier patch
Comment 16 Matthias Clasen 2015-10-07 02:33:53 UTC
Review of attachment 312767 [details] [review]:

not that I can read that GLSL code, but sure...
Comment 17 Alexander Larsson 2015-10-07 07:21:53 UTC
This looks ok to me, and somewhat important.
Comment 18 Emmanuele Bassi (:ebassi) 2015-10-07 07:59:24 UTC
Created attachment 312791 [details] [review]
gdk: Allow querying if a GL context is in legacy mode - v2
Comment 19 Emmanuele Bassi (:ebassi) 2015-10-07 07:59:39 UTC
Created attachment 312792 [details] [review]
gl: Store the legacy bit in the GL program data - v2
Comment 20 Emmanuele Bassi (:ebassi) 2015-10-07 08:00:14 UTC
Created attachment 312793 [details] [review]
gl: Use older GLSL shaders with legacy contexts

- v2: Fixed the missing newlines
Comment 21 Emmanuele Bassi (:ebassi) 2015-10-07 08:00:29 UTC
Created attachment 312794 [details] [review]
x11: Create legacy GLX contexts - v2
Comment 22 Emmanuele Bassi (:ebassi) 2015-10-07 08:00:59 UTC
Created attachment 312795 [details] [review]
x11: Control legacy GL context via environment variable

- v2: Ported to use GDK_GL instead of an ad hoc envvar
Comment 23 Emmanuele Bassi (:ebassi) 2015-10-07 08:01:21 UTC
Created attachment 312796 [details] [review]
Allow testglarea to work with legacy GL contexts - v2
Comment 24 Emmanuele Bassi (:ebassi) 2015-10-07 08:01:33 UTC
Created attachment 312797 [details] [review]
docs: Improve description of gdk_gl_context_is_legacy()

Explain why this function is available, and why you may need it.
Comment 25 Matthias Clasen 2015-10-07 14:12:53 UTC
Looks all good to me now
Comment 26 Emmanuele Bassi (:ebassi) 2015-10-07 14:29:51 UTC
Created attachment 312831 [details] [review]
wayland: Allow falling back to compatibility EGL contexts

If the shared context is in legacy mode, or if the creation of a core
profile context failed, we fall back to an EGL context in compatibility
mode.

Since we're relying on a fairly new EGL implementation for Wayland, we
don't fall back to the older EGL API, and instead we always require the
EGL_KHR_create_context extension.
Comment 27 Emmanuele Bassi (:ebassi) 2015-10-07 14:51:10 UTC
Had to do a couple of fixup runs because I'm dumb, and I was setting the compatibility bit on the flags instead of using it in the profile.

By default, when I run testglarea on my Mesa 10.6.1 with GDK_DEBUG=opengl, I get:

  Realized GLX context[0x172a390], direct
  Making GLX context current to drawable 39845899
→ OpenGL version: 3.3
  Extensions checked:
   - GL_ARB_texture_non_power_of_two: yes
   - GL_ARB_texture_rectangle: yes
   - GL_EXT_framebuffer_blit: yes
   - GL_GREMEDY_frame_terminator: no

When forcing legacy GL via GDK_GL=legacy, I get:

  Realized GLX context[0x2ff5a90], direct
  Making GLX context current to drawable 39845900
→ OpenGL version: 3.0
  Extensions checked:
   - GL_ARB_texture_non_power_of_two: yes
   - GL_ARB_texture_rectangle: yes
   - GL_EXT_framebuffer_blit: yes
   - GL_GREMEDY_frame_terminator: no
Comment 28 Emmanuele Bassi (:ebassi) 2015-10-07 15:23:08 UTC
Pushed the latest wip/ebassi/legacy-gl branch to master.