glx: Lift sending the MakeCurrent request to top-level code

Somewhat terrifyingly, we never sent this for direct contexts, which
means the server never knew the context/drawable bindings. To handle
this sanely, pull the request code up out of the indirect backend, and
rewrite the context switch path to call it as appropriate.  This
attempts to preserve the existing behavior of not calling unbind() on
the context if its refcount would not drop to zero.

Of course, you can't just do this indiscriminately, because this is GLX
and extant X servers have bugs and everything is terrible. To wit:

- For 1.20.x prior to 1.20.6, you can bind a direct context once, but
the second time you try to modify the context's binding you will get
GLXBadContextTag. This includes unbinding the context. And "deleting"
the context will leak memory, because it will still appear to be
current.

- For 1.19 and earlier, glXMakeCurrent(dpy, None, ctx) should be legal
for GL 3.0+ contexts, but the server will throw BadMatch.

To guard against this, we only send the request for indirect contexts
unless the server is known good, and only mention one context at a time
in such a request; if switching between contexts, we first unbind the
old, and then bind the new. Note that the second VendorRelease() version
is to catch XFree86 4.x and Xorg [67].x, which almost certainly have the
above bugs. Other servers might report different version numbers here,
but we can't do direct rendering against them, so this should be safe.

Fixes: #4418
Acked-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <!9992>
117 jobs for !9992 with glx-cleanup in 31 minutes and 55 seconds (queued for 6 seconds)
latest detached
Status Job ID Name Coverage
  Sanity
passed sanity #8842183

00:00:23

 
  Container
passed arm_build #8842189
aarch64

00:00:29

passed windows_build_vs2019 #8842191
windows shell 1809 mesa

00:00:09

passed x86_build-base #8842185

00:00:21

passed x86_test-base #8842187

00:00:21

 
  Container 2
passed android_build #8842206

00:00:20

passed i386_build #8842201

00:00:21

passed kernel+rootfs_amd64 #8842193

00:00:24

passed kernel+rootfs_arm64 #8842195
aarch64

00:00:24

passed kernel+rootfs_arm64-baremetal #8842211
aarch64

00:00:19

passed kernel+rootfs_armhf #8842197
aarch64

00:01:03

passed kernel+rootfs_armhf-baremetal #8842213
aarch64

00:00:19

passed ppc64el_build #8842202

00:00:21

passed s390x_build #8842204

00:00:19

passed x86_build #8842199

00:00:20

passed x86_test-gl #8842208

00:00:18

passed x86_test-vk #8842209

00:00:19

 
  Meson X86 64
passed meson-clang #8842223

00:02:28

passed meson-clover #8842225

00:03:16

passed meson-clover-testing #8842218

00:01:52

passed meson-gallium #8842220

00:09:06

passed meson-release #8842222

00:03:59

passed meson-testing #8842215

00:03:01

passed meson-testing-asan #8842217

00:04:39

passed meson-vulkan #8842227

00:03:41

 
  Build Misc
passed arm_test #8842229

00:00:22

passed meson-android #8842230

00:01:01

passed meson-arm64 #8842234
aarch64

00:02:24

passed meson-arm64-asan #8842236
aarch64

00:04:08

passed meson-arm64-build-test #8842238
aarch64

00:01:24

passed meson-armhf #8842232
aarch64

00:02:20

passed meson-i386 #8842243

00:01:51

passed meson-mingw32-x86_64 #8842251

00:01:59

passed meson-ppc64el #8842248
kvm

00:02:21

passed meson-s390x #8842245
kvm

00:05:28

passed meson-windows-vs2019 #8842240
mesa windows docker 1809

00:07:54

 
  Amd
passed radeonsi-stoney-gles31:amd64 #8842254
mesa-ci-aarch64-lava-collabora

00:08:46

passed radeonsi-stoney-traces:amd64 #8842256
mesa-ci-aarch64-lava-collabora

00:10:17

passed radv-fossils #8842252

00:09:57

 
  Arm
passed panfrost-g52-gles2:arm64 #8842272
mesa-ci-aarch64-lava-collabora

00:03:33

passed panfrost-g52-gles3:arm64 #8842274
mesa-ci-aarch64-lava-collabora

00:09:15

passed panfrost-t720-gles2:arm64 #8842258
mesa-ci-aarch64-lava-collabora

00:19:47

passed panfrost-t760-gles2:armhf #8842260
mesa-ci-aarch64-lava-collabora

00:06:49

passed panfrost-t760-traces:armhf #8842262
mesa-ci-aarch64-lava-collabora

00:06:11

passed panfrost-t860-gles2:arm64 #8842264
mesa-ci-aarch64-lava-collabora

00:03:52

passed panfrost-t860-gles3:arm64 1/2 #8842266
mesa-ci-aarch64-lava-collabora

00:09:22

passed panfrost-t860-gles3:arm64 2/2 #8842268
mesa-ci-aarch64-lava-collabora

00:09:05

passed panfrost-t860-traces:arm64 #8842270
mesa-ci-aarch64-lava-collabora

00:13:10

 
  Broadcom
passed v3d-rpi4-gles2:armhf #8842300
igalia-rpi4

00:06:48

passed v3d-rpi4-gles31:armhf 1/2 #8842285
igalia-rpi4

00:09:31

passed v3d-rpi4-gles31:armhf 2/2 #8842288
igalia-rpi4

00:09:50

passed v3d-rpi4-gles3:armhf 1/4 #8842290
igalia-rpi4

00:09:18

passed v3d-rpi4-gles3:armhf 2/4 #8842293
igalia-rpi4

00:09:37

passed v3d-rpi4-gles3:armhf 3/4 #8842295
igalia-rpi4

00:07:39

passed v3d-rpi4-gles3:armhf 4/4 #8842297
igalia-rpi4

00:08:20

passed v3dv-rpi4-vk:armhf 1/6 #8842302
igalia-rpi4

00:07:17

passed v3dv-rpi4-vk:armhf 2/6 #8842305
igalia-rpi4

00:07:23

passed v3dv-rpi4-vk:armhf 3/6 #8842307
igalia-rpi4

00:07:06

passed v3dv-rpi4-vk:armhf 4/6 #8842309
igalia-rpi4

00:07:31

passed v3dv-rpi4-vk:armhf 5/6 #8842312
igalia-rpi4

00:07:21

passed v3dv-rpi4-vk:armhf 6/6 #8842314
igalia-rpi4

00:07:17

passed vc4-rpi3-gles2:armhf 1/4 #8842276
igalia-rpi3

00:03:57

passed vc4-rpi3-gles2:armhf 2/4 #8842278
igalia-rpi3

00:03:38

passed vc4-rpi3-gles2:armhf 3/4 #8842280
igalia-rpi3

00:03:54

passed vc4-rpi3-gles2:armhf 4/4 #8842283
igalia-rpi3

00:03:41

 
  Freedreno
passed a306_gles2 #8842317
google-freedreno-db410c

00:04:42

passed a306_gles3 1/3 #8842319
google-freedreno-db410c

00:10:00

passed a306_gles3 2/3 #8842322
google-freedreno-db410c

00:09:59

passed a306_gles3 3/3 #8842324
google-freedreno-db410c

00:10:04

passed a306_gles3_options #8842326
google-freedreno-db410c

00:03:48

passed a306-traces #8842328
google-freedreno-db410c

00:09:15

passed a530_gles2 #8842329
google-freedreno-db820c

00:06:45

passed a530_gles31 1/2 #8842332
google-freedreno-db820c

00:06:21

passed a530_gles3 1/2 #8842330
google-freedreno-db820c

00:09:25

passed a530_gles31 2/2 #8842333
google-freedreno-db820c

00:08:38

passed a530_gles3 2/2 #8842331
google-freedreno-db820c

00:08:24

passed a530_piglit_gl #8842334
google-freedreno-db820c

00:10:17

passed a530_piglit_shader #8842335
google-freedreno-db820c

00:09:13

passed a530-traces #8842336
google-freedreno-db820c

00:14:16

passed a630_gl #8842340
google-freedreno-cheza

00:02:38

passed a630_gles2 #8842337
google-freedreno-cheza

00:02:44

passed a630_gles3 #8842339
google-freedreno-cheza

00:06:05

passed a630_gles31 #8842338
google-freedreno-cheza

00:05:16

passed a630_gles_others #8842341
google-freedreno-cheza

00:03:54

passed a630_piglit_gl #8842345
google-freedreno-cheza

00:06:15

passed a630_piglit_shader #8842346
google-freedreno-cheza

00:05:13

passed a630-traces #8842347
google-freedreno-cheza

00:07:07

passed a630_vk 1/2 #8842342
google-freedreno-cheza

00:08:37

passed a630_vk 2/2 #8842343
google-freedreno-cheza

00:08:04

passed a630_vk_sysmem #8842344
google-freedreno-cheza

00:02:14

 
  Software Renderer
passed lavapipe-vk #8842361

00:04:42

passed llvmpipe-gles2 #8842353

00:01:34

passed llvmpipe-piglit-cl #8842348

00:02:42

passed llvmpipe-piglit-glslparser #8842350

00:05:11

passed llvmpipe-piglit-quick_gl #8842349

00:07:37

passed llvmpipe-piglit-quick_shader #8842351

00:04:42

passed llvmpipe-traces #8842352

00:01:56

passed softpipe-asan-gles31 #8842358

00:02:09

passed softpipe-gl #8842360

00:00:38

passed softpipe-gles2 #8842354

00:00:47

passed softpipe-gles3 #8842355

00:08:34

passed softpipe-gles31 1/2 #8842356

00:02:56

passed softpipe-gles31 2/2 #8842357

00:03:08

passed softpipe-piglit-quick #8842359

00:06:04

 
  Layered Backends
passed test-d3d12-windows #8842374
windows docker 1809 mesa

00:03:34

passed virgl-gl30-on-gl #8842366

00:00:24

passed virgl-gl31-on-gl #8842367

00:01:10

passed virgl-gl32-on-gl #8842368

00:01:12

passed virgl-gles2-on-gl #8842362

00:01:18

passed virgl-gles31-on-gl 1/2 #8842364

00:03:19

passed virgl-gles31-on-gl 2/2 #8842365

00:03:14

passed virgl-gles3-on-gl #8842363

00:03:08

passed virgl-traces #8842369

00:00:38

passed zink-lvp-gl #8842373

00:02:21

passed zink-lvp-gles2 #8842371

00:01:41

passed zink-lvp-gles3 #8842372

00:01:23

passed zink-piglit-quick_gl #8842370

00:06:44