summaryrefslogtreecommitdiff
path: root/repo/x11
diff options
context:
space:
mode:
Diffstat (limited to 'repo/x11')
-rw-r--r--repo/x11/adwaita-icon-theme/adwaita-icon-theme.xibuild (renamed from repo/x11/adwaita-icon-theme.xibuild)0
-rw-r--r--repo/x11/berry/berry.xibuild (renamed from repo/x11/berry.xibuild)0
-rw-r--r--repo/x11/bspwm/bspwm.xibuild (renamed from repo/x11/bspwm.xibuild)0
-rw-r--r--repo/x11/dmenu/dmenu.xibuild (renamed from repo/x11/dmenu.xibuild)0
-rw-r--r--repo/x11/gdk-pixbuf/disable-tests.patch13
-rw-r--r--repo/x11/gdk-pixbuf/gdk-pixbuf.xibuild (renamed from repo/x11/gdk-pixbuf.xibuild)0
-rw-r--r--repo/x11/graphite/cmake.patch23
-rw-r--r--repo/x11/graphite/graphite.xibuild (renamed from repo/x11/graphite.xibuild)0
-rw-r--r--repo/x11/gsettings-desktop-schemas/gsettings-desktop-schemas.xibuild (renamed from repo/x11/gsettings-desktop-schemas.xibuild)0
-rw-r--r--repo/x11/gtk2/gtk2.xibuild (renamed from repo/x11/gtk2.xibuild)0
-rw-r--r--repo/x11/gtk3/gtk3.xibuild (renamed from repo/x11/gtk3.xibuild)0
-rw-r--r--repo/x11/harfbuzz/harfbuzz.xibuild (renamed from repo/x11/harfbuzz.xibuild)0
-rw-r--r--repo/x11/hicolor-icon-theme/hicolor-icon-theme.xibuild (renamed from repo/x11/hicolor-icon-theme.xibuild)0
-rw-r--r--repo/x11/iceauth/iceauth.xibuild (renamed from repo/x11/iceauth.xibuild)0
-rw-r--r--repo/x11/intel-vaapi-driver/intel-vaapi-driver.xibuild (renamed from repo/x11/intel-vaapi-driver.xibuild)0
-rw-r--r--repo/x11/libdmx/libdmx.xibuild (renamed from repo/x11/libdmx.xibuild)0
-rw-r--r--repo/x11/libdrm/libdrm.xibuild (renamed from repo/x11/libdrm.xibuild)0
-rw-r--r--repo/x11/libepoxy/libepoxy.xibuild (renamed from repo/x11/libepoxy.xibuild)0
-rw-r--r--repo/x11/libevdev/libevdev.xibuild (renamed from repo/x11/libevdev.xibuild)0
-rw-r--r--repo/x11/libfontenc/libfontenc.xibuild (renamed from repo/x11/libfontenc.xibuild)0
-rw-r--r--repo/x11/libfs/libfs.xibuild (renamed from repo/x11/libfs.xibuild)0
-rw-r--r--repo/x11/libice/libice.xibuild (renamed from repo/x11/libice.xibuild)0
-rw-r--r--repo/x11/libinput/libinput.xibuild (renamed from repo/x11/libinput.xibuild)0
-rw-r--r--repo/x11/libpciaccess/libpciaccess.xibuild (renamed from repo/x11/libpciaccess.xibuild)0
-rw-r--r--repo/x11/libsm/libsm.xibuild (renamed from repo/x11/libsm.xibuild)0
-rw-r--r--repo/x11/libva/libva.xibuild (renamed from repo/x11/libva.xibuild)0
-rw-r--r--repo/x11/libvdpau-va-gl/libvdpau-va-gl.xibuild (renamed from repo/x11/libvdpau-va-gl.xibuild)0
-rw-r--r--repo/x11/libvdpau/libvdpau.xibuild (renamed from repo/x11/libvdpau.xibuild)0
-rw-r--r--repo/x11/libwacom/libwacom.xibuild (renamed from repo/x11/libwacom.xibuild)0
-rw-r--r--repo/x11/libx11/libx11.xibuild (renamed from repo/x11/libx11.xibuild)0
-rw-r--r--repo/x11/libxau/libxau.xibuild (renamed from repo/x11/libxau.xibuild)0
-rw-r--r--repo/x11/libxaw/libxaw.xibuild (renamed from repo/x11/libxaw.xibuild)0
-rw-r--r--repo/x11/libxcb/libxcb.xibuild (renamed from repo/x11/libxcb.xibuild)0
-rw-r--r--repo/x11/libxcomposite/libxcomposite.xibuild (renamed from repo/x11/libxcomposite.xibuild)0
-rw-r--r--repo/x11/libxcursor/libxcursor.xibuild (renamed from repo/x11/libxcursor.xibuild)0
-rw-r--r--repo/x11/libxcvt/libxcvt.xibuild (renamed from repo/x11/libxcvt.xibuild)0
-rw-r--r--repo/x11/libxdamage/libxdamage.xibuild (renamed from repo/x11/libxdamage.xibuild)0
-rw-r--r--repo/x11/libxdmcp/libxdmcp.xibuild (renamed from repo/x11/libxdmcp.xibuild)0
-rw-r--r--repo/x11/libxext/libxext.xibuild (renamed from repo/x11/libxext.xibuild)0
-rw-r--r--repo/x11/libxfixes/libxfixes.xibuild (renamed from repo/x11/libxfixes.xibuild)0
-rw-r--r--repo/x11/libxfont2/libxfont2.xibuild (renamed from repo/x11/libxfont2.xibuild)0
-rw-r--r--repo/x11/libxft/libxft.xibuild (renamed from repo/x11/libxft.xibuild)0
-rw-r--r--repo/x11/libxi/libxi.xibuild (renamed from repo/x11/libxi.xibuild)0
-rw-r--r--repo/x11/libxinerama/libxinerama.xibuild (renamed from repo/x11/libxinerama.xibuild)0
-rw-r--r--repo/x11/libxkbcommon/libxkbcommon.xibuild (renamed from repo/x11/libxkbcommon.xibuild)0
-rw-r--r--repo/x11/libxkbfile/libxkbfile.xibuild (renamed from repo/x11/libxkbfile.xibuild)0
-rw-r--r--repo/x11/libxmu/libxmu.xibuild (renamed from repo/x11/libxmu.xibuild)0
-rw-r--r--repo/x11/libxpm/libxpm.xibuild (renamed from repo/x11/libxpm.xibuild)0
-rw-r--r--repo/x11/libxrandr/libxrandr.xibuild (renamed from repo/x11/libxrandr.xibuild)0
-rw-r--r--repo/x11/libxrender/libxrender.xibuild (renamed from repo/x11/libxrender.xibuild)0
-rw-r--r--repo/x11/libxres/libxres.xibuild (renamed from repo/x11/libxres.xibuild)0
-rw-r--r--repo/x11/libxscrnsaver/libxscrnsaver.xibuild (renamed from repo/x11/libxscrnsaver.xibuild)0
-rw-r--r--repo/x11/libxshmfence/libxshmfence.xibuild (renamed from repo/x11/libxshmfence.xibuild)0
-rw-r--r--repo/x11/libxt/libxt.xibuild (renamed from repo/x11/libxt.xibuild)0
-rw-r--r--repo/x11/libxtst/libxtst.xibuild (renamed from repo/x11/libxtst.xibuild)0
-rw-r--r--repo/x11/libxv/libxv.xibuild (renamed from repo/x11/libxv.xibuild)0
-rw-r--r--repo/x11/libxvmc/libxvmc.xibuild (renamed from repo/x11/libxvmc.xibuild)0
-rw-r--r--repo/x11/libxxf86dga/libxxf86dga.xibuild (renamed from repo/x11/libxxf86dga.xibuild)0
-rw-r--r--repo/x11/libxxf86vm/libxxf86vm.xibuild (renamed from repo/x11/libxxf86vm.xibuild)0
-rw-r--r--repo/x11/luit/luit.xibuild (renamed from repo/x11/luit.xibuild)0
-rw-r--r--repo/x11/maim/maim.xibuild (renamed from repo/x11/maim.xibuild)0
-rw-r--r--repo/x11/mesa/0001-radeonsi-On-Aarch64-force-persistent-buffers-to-GTT.patch38
-rw-r--r--repo/x11/mesa/add-use-elf-tls.patch29
-rw-r--r--repo/x11/mesa/disable-rgb10-by-default.patch25
-rw-r--r--repo/x11/mesa/mesa-21.3.7-add_xdemos-1.patch3197
-rw-r--r--repo/x11/mesa/mesa-21.3.7-nouveau_fixes-1.patch2878
-rw-r--r--repo/x11/mesa/mesa.xibuild (renamed from repo/x11/mesa.xibuild)0
-rw-r--r--repo/x11/mesa/musl-fix-includes.patch13
-rw-r--r--repo/x11/mkfontscale/mkfontscale.xibuild (renamed from repo/x11/mkfontscale.xibuild)0
-rw-r--r--repo/x11/motif/02-fix-format-security.patch607
-rw-r--r--repo/x11/motif/03-no-demos.patch53
-rw-r--r--repo/x11/motif/06-cast-size_t-to-int.patch17
-rw-r--r--repo/x11/motif/07-fix_lintian_reported_manpage_typos.patch118
-rw-r--r--repo/x11/motif/08-fix_hyphen_in_man_pages.patch156
-rw-r--r--repo/x11/motif/09-fix_typo_in_libxm.patch25
-rw-r--r--repo/x11/motif/10-fix_manpage-has-bad-whatis-entry.patch49
-rw-r--r--repo/x11/motif/11-fix_underlinking.patch564
-rw-r--r--repo/x11/motif/13-fix_hardcoded_x11rgb_path.patch54
-rw-r--r--repo/x11/motif/15-link_uil_against_libuil.patch29
-rw-r--r--repo/x11/motif/16-fix-undefined-use-of-sprintf.patch17
-rw-r--r--repo/x11/motif/17-switch-to-system-iswspace.patch384
-rw-r--r--repo/x11/motif/18-option-main.patch9
-rw-r--r--repo/x11/motif/motif.xibuild (renamed from repo/x11/motif.xibuild)0
-rw-r--r--repo/x11/pango/disable-broken-test.patch15
-rw-r--r--repo/x11/pango/pango.xibuild (renamed from repo/x11/pango.xibuild)0
-rw-r--r--repo/x11/picom/picom.xibuild (renamed from repo/x11/picom.xibuild)0
-rw-r--r--repo/x11/pixman/pixman.xibuild (renamed from repo/x11/pixman.xibuild)0
-rw-r--r--repo/x11/rofi/rofi-sensible-terminal-use-sh.patch23
-rw-r--r--repo/x11/rofi/rofi.xibuild (renamed from repo/x11/rofi.xibuild)0
-rw-r--r--repo/x11/rofi/scrollbar-test.patch31
-rw-r--r--repo/x11/sdl2/directfb-cflags.patch10
-rw-r--r--repo/x11/sdl2/sdl2.xibuild (renamed from repo/x11/sdl2.xibuild)0
-rw-r--r--repo/x11/sessreg/sessreg.xibuild (renamed from repo/x11/sessreg.xibuild)0
-rw-r--r--repo/x11/setxkbmap/setxkbmap.xibuild (renamed from repo/x11/setxkbmap.xibuild)0
-rw-r--r--repo/x11/slock/slock.xibuild (renamed from repo/x11/slock.xibuild)0
-rw-r--r--repo/x11/slop/slop.xibuild (renamed from repo/x11/slop.xibuild)0
-rw-r--r--repo/x11/smproxy/smproxy.xibuild (renamed from repo/x11/smproxy.xibuild)0
-rw-r--r--repo/x11/spice-protocol/spice-protocol.xibuild (renamed from repo/x11/spice-protocol.xibuild)0
-rw-r--r--repo/x11/sxhkd/sxhkd.xibuild (renamed from repo/x11/sxhkd.xibuild)0
-rw-r--r--repo/x11/wayland-protocols/wayland-protocols.xibuild (renamed from repo/x11/wayland-protocols.xibuild)0
-rw-r--r--repo/x11/wayland/wayland.xibuild (renamed from repo/x11/wayland.xibuild)0
-rw-r--r--repo/x11/x11perf/x11perf.xibuild (renamed from repo/x11/x11perf.xibuild)0
-rw-r--r--repo/x11/xauth/xauth.xibuild (renamed from repo/x11/xauth.xibuild)0
-rw-r--r--repo/x11/xautolock/processwait.patch33
-rw-r--r--repo/x11/xautolock/xautolock.xibuild (renamed from repo/x11/xautolock.xibuild)0
-rw-r--r--repo/x11/xbacklight/xbacklight.xibuild (renamed from repo/x11/xbacklight.xibuild)0
-rw-r--r--repo/x11/xbitmaps/xbitmaps.xibuild (renamed from repo/x11/xbitmaps.xibuild)0
-rw-r--r--repo/x11/xcb-proto/xcb-proto.xibuild (renamed from repo/x11/xcb-proto.xibuild)0
-rw-r--r--repo/x11/xcb-util-cursor/xcb-util-cursor.xibuild (renamed from repo/x11/xcb-util-cursor.xibuild)0
-rw-r--r--repo/x11/xcb-util-image/xcb-util-image.xibuild (renamed from repo/x11/xcb-util-image.xibuild)0
-rw-r--r--repo/x11/xcb-util-keysyms/xcb-util-keysyms.xibuild (renamed from repo/x11/xcb-util-keysyms.xibuild)0
-rw-r--r--repo/x11/xcb-util-renderutil/xcb-util-renderutil.xibuild (renamed from repo/x11/xcb-util-renderutil.xibuild)0
-rw-r--r--repo/x11/xcb-util-wm/xcb-util-wm.xibuild (renamed from repo/x11/xcb-util-wm.xibuild)0
-rw-r--r--repo/x11/xcb-util/xcb-util.xibuild (renamed from repo/x11/xcb-util.xibuild)0
-rw-r--r--repo/x11/xclip/xclip.xibuild (renamed from repo/x11/xclip.xibuild)0
-rw-r--r--repo/x11/xclock/xclock.xibuild (renamed from repo/x11/xclock.xibuild)0
-rw-r--r--repo/x11/xcmsdb/xcmsdb.xibuild (renamed from repo/x11/xcmsdb.xibuild)0
-rw-r--r--repo/x11/xcursor-themes/xcursor-themes.xibuild (renamed from repo/x11/xcursor-themes.xibuild)0
-rw-r--r--repo/x11/xcursorgen/xcursorgen.xibuild (renamed from repo/x11/xcursorgen.xibuild)0
-rw-r--r--repo/x11/xdg-utils/xdg-screensaver-mv-T.patch25
-rw-r--r--repo/x11/xdg-utils/xdg-utils.xibuild (renamed from repo/x11/xdg-utils.xibuild)0
-rw-r--r--repo/x11/xdpyinfo/xdpyinfo.xibuild (renamed from repo/x11/xdpyinfo.xibuild)0
-rw-r--r--repo/x11/xdriinfo/xdriinfo.xibuild (renamed from repo/x11/xdriinfo.xibuild)0
-rw-r--r--repo/x11/xev/xev.xibuild (renamed from repo/x11/xev.xibuild)0
-rw-r--r--repo/x11/xeyes/xeyes.xibuild (renamed from repo/x11/xeyes.xibuild)0
-rw-r--r--repo/x11/xf86-input-evdev/xf86-input-evdev.xibuild (renamed from repo/x11/xf86-input-evdev.xibuild)0
-rw-r--r--repo/x11/xf86-input-libinput/xf86-input-libinput.xibuild (renamed from repo/x11/xf86-input-libinput.xibuild)0
-rw-r--r--repo/x11/xf86-input-synaptics/xf86-input-synaptics.xibuild (renamed from repo/x11/xf86-input-synaptics.xibuild)0
-rw-r--r--repo/x11/xf86-input-wacom/xf86-input-wacom.xibuild (renamed from repo/x11/xf86-input-wacom.xibuild)0
-rw-r--r--repo/x11/xf86-video-amdgpu/xf86-video-amdgpu.xibuild (renamed from repo/x11/xf86-video-amdgpu.xibuild)0
-rw-r--r--repo/x11/xf86-video-ati/xf86-video-ati.xibuild (renamed from repo/x11/xf86-video-ati.xibuild)0
-rw-r--r--repo/x11/xf86-video-fbdev/xf86-video-fbdev.xibuild (renamed from repo/x11/xf86-video-fbdev.xibuild)0
-rw-r--r--repo/x11/xf86-video-intel/xf86-video-intel.xibuild (renamed from repo/x11/xf86-video-intel.xibuild)0
-rw-r--r--repo/x11/xf86-video-nouveau/xf86-video-nouveau.xibuild (renamed from repo/x11/xf86-video-nouveau.xibuild)0
-rw-r--r--repo/x11/xf86-video-nouveau/xorg-server-21.1.patch50
-rw-r--r--repo/x11/xf86-video-qxl/buildfix.patch101
-rw-r--r--repo/x11/xf86-video-qxl/convert-xspice-python3.patch154
-rw-r--r--repo/x11/xf86-video-qxl/xf86-video-qxl.xibuild (renamed from repo/x11/xf86-video-qxl.xibuild)0
-rw-r--r--repo/x11/xf86-video-vmware/xf86-video-vmware.xibuild (renamed from repo/x11/xf86-video-vmware.xibuild)0
-rw-r--r--repo/x11/xgamma/xgamma.xibuild (renamed from repo/x11/xgamma.xibuild)0
-rw-r--r--repo/x11/xhost/xhost.xibuild (renamed from repo/x11/xhost.xibuild)0
-rw-r--r--repo/x11/xinput/xinput.xibuild (renamed from repo/x11/xinput.xibuild)0
-rw-r--r--repo/x11/xkbcomp/xkbcomp.xibuild (renamed from repo/x11/xkbcomp.xibuild)0
-rw-r--r--repo/x11/xkbevd/xkbevd.xibuild (renamed from repo/x11/xkbevd.xibuild)0
-rw-r--r--repo/x11/xkbutils/xkbutils.xibuild (renamed from repo/x11/xkbutils.xibuild)0
-rw-r--r--repo/x11/xkeyboardconfig/xkeyboardconfig.xibuild (renamed from repo/x11/xkeyboardconfig.xibuild)0
-rw-r--r--repo/x11/xkill/xkill.xibuild (renamed from repo/x11/xkill.xibuild)0
-rw-r--r--repo/x11/xlsatoms/xlsatoms.xibuild (renamed from repo/x11/xlsatoms.xibuild)0
-rw-r--r--repo/x11/xlsclients/xlsclients.xibuild (renamed from repo/x11/xlsclients.xibuild)0
-rw-r--r--repo/x11/xmessage/xmessage.xibuild (renamed from repo/x11/xmessage.xibuild)0
-rw-r--r--repo/x11/xmodmap/xmodmap.xibuild (renamed from repo/x11/xmodmap.xibuild)0
-rw-r--r--repo/x11/xorg-libs/xorg-libs.xibuild (renamed from repo/x11/xorg-libs.xibuild)0
-rw-r--r--repo/x11/xorg-server/xorg-server.xibuild (renamed from repo/x11/xorg-server.xibuild)0
-rw-r--r--repo/x11/xorg-util-macros/xorg-util-macros.xibuild (renamed from repo/x11/xorg-util-macros.xibuild)0
-rw-r--r--repo/x11/xorg-xinit/xorg-xinit.xibuild (renamed from repo/x11/xorg-xinit.xibuild)0
-rw-r--r--repo/x11/xorgproto/xorgproto.xibuild (renamed from repo/x11/xorgproto.xibuild)0
-rw-r--r--repo/x11/xpr/xpr.xibuild (renamed from repo/x11/xpr.xibuild)0
-rw-r--r--repo/x11/xprop/xprop.xibuild (renamed from repo/x11/xprop.xibuild)0
-rw-r--r--repo/x11/xrandr/xrandr.xibuild (renamed from repo/x11/xrandr.xibuild)0
-rw-r--r--repo/x11/xrdb/xrdb.xibuild (renamed from repo/x11/xrdb.xibuild)0
-rw-r--r--repo/x11/xrefresh/xrefresh.xibuild (renamed from repo/x11/xrefresh.xibuild)0
-rw-r--r--repo/x11/xsel/xsel.xibuild (renamed from repo/x11/xsel.xibuild)0
-rw-r--r--repo/x11/xset/xset.xibuild (renamed from repo/x11/xset.xibuild)0
-rw-r--r--repo/x11/xsetroot/xsetroot.xibuild (renamed from repo/x11/xsetroot.xibuild)0
-rw-r--r--repo/x11/xtrans/xtrans.xibuild (renamed from repo/x11/xtrans.xibuild)0
-rw-r--r--repo/x11/xvinfo/xvinfo.xibuild (renamed from repo/x11/xvinfo.xibuild)0
-rw-r--r--repo/x11/xwd/xwd.xibuild (renamed from repo/x11/xwd.xibuild)0
-rw-r--r--repo/x11/xwininfo/xwininfo.xibuild (renamed from repo/x11/xwininfo.xibuild)0
-rw-r--r--repo/x11/xwud/xwud.xibuild (renamed from repo/x11/xwud.xibuild)0
169 files changed, 8740 insertions, 0 deletions
diff --git a/repo/x11/adwaita-icon-theme.xibuild b/repo/x11/adwaita-icon-theme/adwaita-icon-theme.xibuild
index c87bd79..c87bd79 100644
--- a/repo/x11/adwaita-icon-theme.xibuild
+++ b/repo/x11/adwaita-icon-theme/adwaita-icon-theme.xibuild
diff --git a/repo/x11/berry.xibuild b/repo/x11/berry/berry.xibuild
index 5b4fe5e..5b4fe5e 100644
--- a/repo/x11/berry.xibuild
+++ b/repo/x11/berry/berry.xibuild
diff --git a/repo/x11/bspwm.xibuild b/repo/x11/bspwm/bspwm.xibuild
index 7887321..7887321 100644
--- a/repo/x11/bspwm.xibuild
+++ b/repo/x11/bspwm/bspwm.xibuild
diff --git a/repo/x11/dmenu.xibuild b/repo/x11/dmenu/dmenu.xibuild
index 0356f4e..0356f4e 100644
--- a/repo/x11/dmenu.xibuild
+++ b/repo/x11/dmenu/dmenu.xibuild
diff --git a/repo/x11/gdk-pixbuf/disable-tests.patch b/repo/x11/gdk-pixbuf/disable-tests.patch
new file mode 100644
index 0000000..01ee3a6
--- /dev/null
+++ b/repo/x11/gdk-pixbuf/disable-tests.patch
@@ -0,0 +1,13 @@
+Index: meson.build
+--- a/meson.build
++++ b/meson.build
+@@ -398,7 +398,9 @@ endif
+ subdir('po')
+
+ if not meson.is_cross_build()
+- subdir('tests')
++ if get_option('installed_tests')
++ subdir('tests')
++ endif
+ subdir('thumbnailer')
+ endif
diff --git a/repo/x11/gdk-pixbuf.xibuild b/repo/x11/gdk-pixbuf/gdk-pixbuf.xibuild
index fe704e9..fe704e9 100644
--- a/repo/x11/gdk-pixbuf.xibuild
+++ b/repo/x11/gdk-pixbuf/gdk-pixbuf.xibuild
diff --git a/repo/x11/graphite/cmake.patch b/repo/x11/graphite/cmake.patch
new file mode 100644
index 0000000..2b21d6b
--- /dev/null
+++ b/repo/x11/graphite/cmake.patch
@@ -0,0 +1,23 @@
+diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
+index b6ac26b..0371b0c 100644
+--- a/src/CMakeLists.txt
++++ b/src/CMakeLists.txt
+@@ -120,11 +120,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
+ if (${CMAKE_CXX_COMPILER} MATCHES ".*mingw.*")
+ target_link_libraries(graphite2 kernel32 msvcr90 mingw32 gcc user32)
+ else (${CMAKE_CXX_COMPILER} MATCHES ".*mingw.*")
+- if (GRAPHITE2_SANITIZERS)
+- target_link_libraries(graphite2 c gcc_s)
+- else ()
+- target_link_libraries(graphite2 c gcc)
+- endif ()
++ target_link_libraries(graphite2 c gcc_s -lssp_nonshared)
+ endif()
+ include(Graphite)
+ if (BUILD_SHARED_LIBS)
+@@ -156,4 +152,4 @@ endif()
+
+
+ install(TARGETS graphite2 EXPORT graphite2 LIBRARY DESTINATION lib${LIB_SUFFIX} ARCHIVE DESTINATION lib${LIB_SUFFIX} PUBLIC_HEADER DESTINATION include/graphite2 RUNTIME DESTINATION bin)
+-install(EXPORT graphite2 DESTINATION share/graphite2 NAMESPACE gr2_)
++install(EXPORT graphite2 DESTINATION lib${LIB_SUFFIX}/cmake/graphite2 NAMESPACE gr2_)
diff --git a/repo/x11/graphite.xibuild b/repo/x11/graphite/graphite.xibuild
index 5583086..5583086 100644
--- a/repo/x11/graphite.xibuild
+++ b/repo/x11/graphite/graphite.xibuild
diff --git a/repo/x11/gsettings-desktop-schemas.xibuild b/repo/x11/gsettings-desktop-schemas/gsettings-desktop-schemas.xibuild
index 72092d1..72092d1 100644
--- a/repo/x11/gsettings-desktop-schemas.xibuild
+++ b/repo/x11/gsettings-desktop-schemas/gsettings-desktop-schemas.xibuild
diff --git a/repo/x11/gtk2.xibuild b/repo/x11/gtk2/gtk2.xibuild
index 1798730..1798730 100644
--- a/repo/x11/gtk2.xibuild
+++ b/repo/x11/gtk2/gtk2.xibuild
diff --git a/repo/x11/gtk3.xibuild b/repo/x11/gtk3/gtk3.xibuild
index 14e4989..14e4989 100644
--- a/repo/x11/gtk3.xibuild
+++ b/repo/x11/gtk3/gtk3.xibuild
diff --git a/repo/x11/harfbuzz.xibuild b/repo/x11/harfbuzz/harfbuzz.xibuild
index d86a83e..d86a83e 100644
--- a/repo/x11/harfbuzz.xibuild
+++ b/repo/x11/harfbuzz/harfbuzz.xibuild
diff --git a/repo/x11/hicolor-icon-theme.xibuild b/repo/x11/hicolor-icon-theme/hicolor-icon-theme.xibuild
index 3d51994..3d51994 100644
--- a/repo/x11/hicolor-icon-theme.xibuild
+++ b/repo/x11/hicolor-icon-theme/hicolor-icon-theme.xibuild
diff --git a/repo/x11/iceauth.xibuild b/repo/x11/iceauth/iceauth.xibuild
index b197866..b197866 100644
--- a/repo/x11/iceauth.xibuild
+++ b/repo/x11/iceauth/iceauth.xibuild
diff --git a/repo/x11/intel-vaapi-driver.xibuild b/repo/x11/intel-vaapi-driver/intel-vaapi-driver.xibuild
index 4452392..4452392 100644
--- a/repo/x11/intel-vaapi-driver.xibuild
+++ b/repo/x11/intel-vaapi-driver/intel-vaapi-driver.xibuild
diff --git a/repo/x11/libdmx.xibuild b/repo/x11/libdmx/libdmx.xibuild
index 9380c76..9380c76 100644
--- a/repo/x11/libdmx.xibuild
+++ b/repo/x11/libdmx/libdmx.xibuild
diff --git a/repo/x11/libdrm.xibuild b/repo/x11/libdrm/libdrm.xibuild
index 5e9b11c..5e9b11c 100644
--- a/repo/x11/libdrm.xibuild
+++ b/repo/x11/libdrm/libdrm.xibuild
diff --git a/repo/x11/libepoxy.xibuild b/repo/x11/libepoxy/libepoxy.xibuild
index 3d79d77..3d79d77 100644
--- a/repo/x11/libepoxy.xibuild
+++ b/repo/x11/libepoxy/libepoxy.xibuild
diff --git a/repo/x11/libevdev.xibuild b/repo/x11/libevdev/libevdev.xibuild
index e5b822e..e5b822e 100644
--- a/repo/x11/libevdev.xibuild
+++ b/repo/x11/libevdev/libevdev.xibuild
diff --git a/repo/x11/libfontenc.xibuild b/repo/x11/libfontenc/libfontenc.xibuild
index 6f9c0c3..6f9c0c3 100644
--- a/repo/x11/libfontenc.xibuild
+++ b/repo/x11/libfontenc/libfontenc.xibuild
diff --git a/repo/x11/libfs.xibuild b/repo/x11/libfs/libfs.xibuild
index 2e635dd..2e635dd 100644
--- a/repo/x11/libfs.xibuild
+++ b/repo/x11/libfs/libfs.xibuild
diff --git a/repo/x11/libice.xibuild b/repo/x11/libice/libice.xibuild
index b819df4..b819df4 100644
--- a/repo/x11/libice.xibuild
+++ b/repo/x11/libice/libice.xibuild
diff --git a/repo/x11/libinput.xibuild b/repo/x11/libinput/libinput.xibuild
index 8996272..8996272 100644
--- a/repo/x11/libinput.xibuild
+++ b/repo/x11/libinput/libinput.xibuild
diff --git a/repo/x11/libpciaccess.xibuild b/repo/x11/libpciaccess/libpciaccess.xibuild
index 6af00dc..6af00dc 100644
--- a/repo/x11/libpciaccess.xibuild
+++ b/repo/x11/libpciaccess/libpciaccess.xibuild
diff --git a/repo/x11/libsm.xibuild b/repo/x11/libsm/libsm.xibuild
index 9e132d9..9e132d9 100644
--- a/repo/x11/libsm.xibuild
+++ b/repo/x11/libsm/libsm.xibuild
diff --git a/repo/x11/libva.xibuild b/repo/x11/libva/libva.xibuild
index 7d6c66b..7d6c66b 100644
--- a/repo/x11/libva.xibuild
+++ b/repo/x11/libva/libva.xibuild
diff --git a/repo/x11/libvdpau-va-gl.xibuild b/repo/x11/libvdpau-va-gl/libvdpau-va-gl.xibuild
index 074dece..074dece 100644
--- a/repo/x11/libvdpau-va-gl.xibuild
+++ b/repo/x11/libvdpau-va-gl/libvdpau-va-gl.xibuild
diff --git a/repo/x11/libvdpau.xibuild b/repo/x11/libvdpau/libvdpau.xibuild
index f36957f..f36957f 100644
--- a/repo/x11/libvdpau.xibuild
+++ b/repo/x11/libvdpau/libvdpau.xibuild
diff --git a/repo/x11/libwacom.xibuild b/repo/x11/libwacom/libwacom.xibuild
index 80dd536..80dd536 100644
--- a/repo/x11/libwacom.xibuild
+++ b/repo/x11/libwacom/libwacom.xibuild
diff --git a/repo/x11/libx11.xibuild b/repo/x11/libx11/libx11.xibuild
index 90b6d57..90b6d57 100644
--- a/repo/x11/libx11.xibuild
+++ b/repo/x11/libx11/libx11.xibuild
diff --git a/repo/x11/libxau.xibuild b/repo/x11/libxau/libxau.xibuild
index adb0567..adb0567 100644
--- a/repo/x11/libxau.xibuild
+++ b/repo/x11/libxau/libxau.xibuild
diff --git a/repo/x11/libxaw.xibuild b/repo/x11/libxaw/libxaw.xibuild
index e7e4788..e7e4788 100644
--- a/repo/x11/libxaw.xibuild
+++ b/repo/x11/libxaw/libxaw.xibuild
diff --git a/repo/x11/libxcb.xibuild b/repo/x11/libxcb/libxcb.xibuild
index 0a59eea..0a59eea 100644
--- a/repo/x11/libxcb.xibuild
+++ b/repo/x11/libxcb/libxcb.xibuild
diff --git a/repo/x11/libxcomposite.xibuild b/repo/x11/libxcomposite/libxcomposite.xibuild
index 5cf3082..5cf3082 100644
--- a/repo/x11/libxcomposite.xibuild
+++ b/repo/x11/libxcomposite/libxcomposite.xibuild
diff --git a/repo/x11/libxcursor.xibuild b/repo/x11/libxcursor/libxcursor.xibuild
index 4ae2314..4ae2314 100644
--- a/repo/x11/libxcursor.xibuild
+++ b/repo/x11/libxcursor/libxcursor.xibuild
diff --git a/repo/x11/libxcvt.xibuild b/repo/x11/libxcvt/libxcvt.xibuild
index 07e3766..07e3766 100644
--- a/repo/x11/libxcvt.xibuild
+++ b/repo/x11/libxcvt/libxcvt.xibuild
diff --git a/repo/x11/libxdamage.xibuild b/repo/x11/libxdamage/libxdamage.xibuild
index cc03c7f..cc03c7f 100644
--- a/repo/x11/libxdamage.xibuild
+++ b/repo/x11/libxdamage/libxdamage.xibuild
diff --git a/repo/x11/libxdmcp.xibuild b/repo/x11/libxdmcp/libxdmcp.xibuild
index 2a0a481..2a0a481 100644
--- a/repo/x11/libxdmcp.xibuild
+++ b/repo/x11/libxdmcp/libxdmcp.xibuild
diff --git a/repo/x11/libxext.xibuild b/repo/x11/libxext/libxext.xibuild
index f20a096..f20a096 100644
--- a/repo/x11/libxext.xibuild
+++ b/repo/x11/libxext/libxext.xibuild
diff --git a/repo/x11/libxfixes.xibuild b/repo/x11/libxfixes/libxfixes.xibuild
index 0f337ce..0f337ce 100644
--- a/repo/x11/libxfixes.xibuild
+++ b/repo/x11/libxfixes/libxfixes.xibuild
diff --git a/repo/x11/libxfont2.xibuild b/repo/x11/libxfont2/libxfont2.xibuild
index c2ba59d..c2ba59d 100644
--- a/repo/x11/libxfont2.xibuild
+++ b/repo/x11/libxfont2/libxfont2.xibuild
diff --git a/repo/x11/libxft.xibuild b/repo/x11/libxft/libxft.xibuild
index 3e2f91d..3e2f91d 100644
--- a/repo/x11/libxft.xibuild
+++ b/repo/x11/libxft/libxft.xibuild
diff --git a/repo/x11/libxi.xibuild b/repo/x11/libxi/libxi.xibuild
index 6741cfe..6741cfe 100644
--- a/repo/x11/libxi.xibuild
+++ b/repo/x11/libxi/libxi.xibuild
diff --git a/repo/x11/libxinerama.xibuild b/repo/x11/libxinerama/libxinerama.xibuild
index 047bdd0..047bdd0 100644
--- a/repo/x11/libxinerama.xibuild
+++ b/repo/x11/libxinerama/libxinerama.xibuild
diff --git a/repo/x11/libxkbcommon.xibuild b/repo/x11/libxkbcommon/libxkbcommon.xibuild
index 2675370..2675370 100644
--- a/repo/x11/libxkbcommon.xibuild
+++ b/repo/x11/libxkbcommon/libxkbcommon.xibuild
diff --git a/repo/x11/libxkbfile.xibuild b/repo/x11/libxkbfile/libxkbfile.xibuild
index 9825b82..9825b82 100644
--- a/repo/x11/libxkbfile.xibuild
+++ b/repo/x11/libxkbfile/libxkbfile.xibuild
diff --git a/repo/x11/libxmu.xibuild b/repo/x11/libxmu/libxmu.xibuild
index 5127ccc..5127ccc 100644
--- a/repo/x11/libxmu.xibuild
+++ b/repo/x11/libxmu/libxmu.xibuild
diff --git a/repo/x11/libxpm.xibuild b/repo/x11/libxpm/libxpm.xibuild
index cfdfadc..cfdfadc 100644
--- a/repo/x11/libxpm.xibuild
+++ b/repo/x11/libxpm/libxpm.xibuild
diff --git a/repo/x11/libxrandr.xibuild b/repo/x11/libxrandr/libxrandr.xibuild
index 8d8b790..8d8b790 100644
--- a/repo/x11/libxrandr.xibuild
+++ b/repo/x11/libxrandr/libxrandr.xibuild
diff --git a/repo/x11/libxrender.xibuild b/repo/x11/libxrender/libxrender.xibuild
index 55126aa..55126aa 100644
--- a/repo/x11/libxrender.xibuild
+++ b/repo/x11/libxrender/libxrender.xibuild
diff --git a/repo/x11/libxres.xibuild b/repo/x11/libxres/libxres.xibuild
index 0639324..0639324 100644
--- a/repo/x11/libxres.xibuild
+++ b/repo/x11/libxres/libxres.xibuild
diff --git a/repo/x11/libxscrnsaver.xibuild b/repo/x11/libxscrnsaver/libxscrnsaver.xibuild
index 27b710c..27b710c 100644
--- a/repo/x11/libxscrnsaver.xibuild
+++ b/repo/x11/libxscrnsaver/libxscrnsaver.xibuild
diff --git a/repo/x11/libxshmfence.xibuild b/repo/x11/libxshmfence/libxshmfence.xibuild
index 224612b..224612b 100644
--- a/repo/x11/libxshmfence.xibuild
+++ b/repo/x11/libxshmfence/libxshmfence.xibuild
diff --git a/repo/x11/libxt.xibuild b/repo/x11/libxt/libxt.xibuild
index 293683d..293683d 100644
--- a/repo/x11/libxt.xibuild
+++ b/repo/x11/libxt/libxt.xibuild
diff --git a/repo/x11/libxtst.xibuild b/repo/x11/libxtst/libxtst.xibuild
index 45093e1..45093e1 100644
--- a/repo/x11/libxtst.xibuild
+++ b/repo/x11/libxtst/libxtst.xibuild
diff --git a/repo/x11/libxv.xibuild b/repo/x11/libxv/libxv.xibuild
index c7fa2b6..c7fa2b6 100644
--- a/repo/x11/libxv.xibuild
+++ b/repo/x11/libxv/libxv.xibuild
diff --git a/repo/x11/libxvmc.xibuild b/repo/x11/libxvmc/libxvmc.xibuild
index 76b445c..76b445c 100644
--- a/repo/x11/libxvmc.xibuild
+++ b/repo/x11/libxvmc/libxvmc.xibuild
diff --git a/repo/x11/libxxf86dga.xibuild b/repo/x11/libxxf86dga/libxxf86dga.xibuild
index ba5a0b9..ba5a0b9 100644
--- a/repo/x11/libxxf86dga.xibuild
+++ b/repo/x11/libxxf86dga/libxxf86dga.xibuild
diff --git a/repo/x11/libxxf86vm.xibuild b/repo/x11/libxxf86vm/libxxf86vm.xibuild
index d45959e..d45959e 100644
--- a/repo/x11/libxxf86vm.xibuild
+++ b/repo/x11/libxxf86vm/libxxf86vm.xibuild
diff --git a/repo/x11/luit.xibuild b/repo/x11/luit/luit.xibuild
index 7a2beed..7a2beed 100644
--- a/repo/x11/luit.xibuild
+++ b/repo/x11/luit/luit.xibuild
diff --git a/repo/x11/maim.xibuild b/repo/x11/maim/maim.xibuild
index 4f93af0..4f93af0 100644
--- a/repo/x11/maim.xibuild
+++ b/repo/x11/maim/maim.xibuild
diff --git a/repo/x11/mesa/0001-radeonsi-On-Aarch64-force-persistent-buffers-to-GTT.patch b/repo/x11/mesa/0001-radeonsi-On-Aarch64-force-persistent-buffers-to-GTT.patch
new file mode 100644
index 0000000..ea855f6
--- /dev/null
+++ b/repo/x11/mesa/0001-radeonsi-On-Aarch64-force-persistent-buffers-to-GTT.patch
@@ -0,0 +1,38 @@
+From d72aa8ae74ffb7329003f9f23ffa05833af951ab Mon Sep 17 00:00:00 2001
+From: Jon Nettleton <jon@solid-run.com>
+Date: Fri, 14 Aug 2020 13:36:08 +0200
+Subject: [PATCH] radeonsi: On Aarch64 force persistent buffers to GTT
+
+This fixes a glamore corruption issue on the HoneyComb and by
+internet reports should also fix problems seen on Huaweii
+Kunpeng hardware.
+
+The root cause of the corruption needs to be worked out, but
+this patch also adds a noticable performance improvement. The
+aquarium webgl demo under chromium increases from 39-49 FPS
+when 5000 fish being rendered is selected. Glmark scores also
+improve by ~200 with no specific tests showing any regression.
+
+Signed-off-by: Jon Nettleton <jon@solid-run.com>
+---
+ src/gallium/drivers/radeonsi/si_buffer.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/src/gallium/drivers/radeonsi/si_buffer.c b/src/gallium/drivers/radeonsi/si_buffer.c
+index 6b58aebee2d..c9e983367a0 100644
+--- a/src/gallium/drivers/radeonsi/si_buffer.c
++++ b/src/gallium/drivers/radeonsi/si_buffer.c
+@@ -151,6 +151,11 @@ void si_init_resource_fields(struct si_screen *sscreen, struct si_resource *res,
+ */
+ if (!sscreen->info.kernel_flushes_hdp_before_ib || !sscreen->info.is_amdgpu)
+ res->domains = RADEON_DOMAIN_GTT;
++
++#if defined(PIPE_ARCH_AARCH64)
++ if (size <= 1024 * 512)
++ res->domains = RADEON_DOMAIN_GTT;
++#endif
+ }
+
+ /* Tiled textures are unmappable. Always put them in VRAM. */
+--
+2.26.2
diff --git a/repo/x11/mesa/add-use-elf-tls.patch b/repo/x11/mesa/add-use-elf-tls.patch
new file mode 100644
index 0000000..629c5ac
--- /dev/null
+++ b/repo/x11/mesa/add-use-elf-tls.patch
@@ -0,0 +1,29 @@
+diff --git a/meson.build b/meson.build
+index e1e94e7..b355f94 100644
+--- a/meson.build
++++ b/meson.build
+@@ -447,7 +447,9 @@ endif
+
+ # Android uses emutls for versions <= P/28. For USE_ELF_TLS we need ELF TLS.
+ use_elf_tls = false
+-if (not ['freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and
++with_use_elf_tls = get_option('use-elf-tls')
++if with_use_elf_tls and
++ (not ['freebsd', 'openbsd', 'haiku'].contains(host_machine.system()) and
+ (not with_platform_android or get_option('platform-sdk-version') >= 29) and
+ (not with_platform_windows or not with_shared_glapi))
+ pre_args += '-DUSE_ELF_TLS'
+diff --git a/meson_options.txt b/meson_options.txt
+index a7030ab..73bd28e 100644
+--- a/meson_options.txt
++++ b/meson_options.txt
+@@ -465,3 +465,9 @@ option(
+ value : true,
+ description : 'use msse2 flag for mingw x86. Default: true',
+ )
++option(
++ 'use-elf-tls',
++ type : 'boolean',
++ value : false,
++ description : 'Build support for initial-exec TLS model'
++)
diff --git a/repo/x11/mesa/disable-rgb10-by-default.patch b/repo/x11/mesa/disable-rgb10-by-default.patch
new file mode 100644
index 0000000..6e1158b
--- /dev/null
+++ b/repo/x11/mesa/disable-rgb10-by-default.patch
@@ -0,0 +1,25 @@
+From b33c8b56abcc4837f96f7f106b108681858482e0 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
+Date: Tue, 24 Apr 2018 09:46:41 +0200
+Subject: [PATCH] gallium: Disable rgb10 configs by default
+
+Applications tend to not handle rgb10 configs very well, so lets
+disable it for now.
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1560481
+---
+ src/gallium/auxiliary/pipe-loader/driinfo_gallium.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
+index 3b630f7..b542e0c 100644
+--- a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
++++ b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
+@@ -49,6 +49,6 @@ DRI_CONF_SECTION_MISCELLANEOUS
+ DRI_CONF_GLSL_ZERO_INIT(false)
+ DRI_CONF_VS_POSITION_ALWAYS_INVARIANT(false)
+ DRI_CONF_VS_POSITION_ALWAYS_PRECISE(false)
+- DRI_CONF_ALLOW_RGB10_CONFIGS(true)
++ DRI_CONF_ALLOW_RGB10_CONFIGS(false)
+ DRI_CONF_FORCE_INTEGER_TEX_NEAREST(false)
+ DRI_CONF_SECTION_END
diff --git a/repo/x11/mesa/mesa-21.3.7-add_xdemos-1.patch b/repo/x11/mesa/mesa-21.3.7-add_xdemos-1.patch
new file mode 100644
index 0000000..6b41e57
--- /dev/null
+++ b/repo/x11/mesa/mesa-21.3.7-add_xdemos-1.patch
@@ -0,0 +1,3197 @@
+Submitted By: DJ Lucas <dj@linuxfromscratch.org>
+ based on previous patches submitted
+ by Armin K and Fernando de Oliveira
+Date: 2020-10-16
+Initial Package Version: 19.0.4
+Upstream Status: Not applicable.
+Origin: Self.
+Description: This patch adds two OpenGL demos, glxinfo and
+ glxgears and respective man pages.
+
+diff -Naurp mesa-20.2.1-orig/src/glx/meson.build mesa-20.2.1/src/glx/meson.build
+--- mesa-20.2.1-orig/src/glx/meson.build 2020-10-14 12:19:10.623185200 -0500
++++ mesa-20.2.1/src/glx/meson.build 2020-10-15 23:06:45.823362439 -0500
+@@ -165,6 +165,8 @@ libgl = shared_library(
+ install : true,
+ )
+
++subdir('xdemos')
++
+ if with_tests
+ subdir('tests')
+ endif
+diff -Naurp mesa-20.2.1-orig/src/glx/xdemos/glinfo_common.c mesa-20.2.1/src/glx/xdemos/glinfo_common.c
+--- mesa-20.2.1-orig/src/glx/xdemos/glinfo_common.c 1969-12-31 18:00:00.000000000 -0600
++++ mesa-20.2.1/src/glx/xdemos/glinfo_common.c 2020-10-15 23:06:45.826695773 -0500
+@@ -0,0 +1,800 @@
++/*
++ * Copyright (C) 1999-2014 Brian Paul All Rights Reserved.
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a
++ * copy of this software and associated documentation files (the "Software"),
++ * to deal in the Software without restriction, including without limitation
++ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
++ * and/or sell copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included
++ * in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
++ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
++ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++#include <assert.h>
++#include <ctype.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include "glinfo_common.h"
++
++#ifdef _WIN32
++#define snprintf _snprintf
++#endif
++
++
++/**
++ * Return the GL enum name for a numeric value.
++ * We really only care about the compressed texture formats for now.
++ */
++static const char *
++enum_name(GLenum val)
++{
++ static const struct {
++ const char *name;
++ GLenum val;
++ } enums [] = {
++ { "GL_COMPRESSED_ALPHA", 0x84E9 },
++ { "GL_COMPRESSED_LUMINANCE", 0x84EA },
++ { "GL_COMPRESSED_LUMINANCE_ALPHA", 0x84EB },
++ { "GL_COMPRESSED_INTENSITY", 0x84EC },
++ { "GL_COMPRESSED_RGB", 0x84ED },
++ { "GL_COMPRESSED_RGBA", 0x84EE },
++ { "GL_COMPRESSED_TEXTURE_FORMATS", 0x86A3 },
++ { "GL_COMPRESSED_RGB", 0x84ED },
++ { "GL_COMPRESSED_RGBA", 0x84EE },
++ { "GL_COMPRESSED_TEXTURE_FORMATS", 0x86A3 },
++ { "GL_COMPRESSED_ALPHA", 0x84E9 },
++ { "GL_COMPRESSED_LUMINANCE", 0x84EA },
++ { "GL_COMPRESSED_LUMINANCE_ALPHA", 0x84EB },
++ { "GL_COMPRESSED_INTENSITY", 0x84EC },
++ { "GL_COMPRESSED_SRGB", 0x8C48 },
++ { "GL_COMPRESSED_SRGB_ALPHA", 0x8C49 },
++ { "GL_COMPRESSED_SLUMINANCE", 0x8C4A },
++ { "GL_COMPRESSED_SLUMINANCE_ALPHA", 0x8C4B },
++ { "GL_COMPRESSED_RED", 0x8225 },
++ { "GL_COMPRESSED_RG", 0x8226 },
++ { "GL_COMPRESSED_RED_RGTC1", 0x8DBB },
++ { "GL_COMPRESSED_SIGNED_RED_RGTC1", 0x8DBC },
++ { "GL_COMPRESSED_RG_RGTC2", 0x8DBD },
++ { "GL_COMPRESSED_SIGNED_RG_RGTC2", 0x8DBE },
++ { "GL_COMPRESSED_RGB8_ETC2", 0x9274 },
++ { "GL_COMPRESSED_SRGB8_ETC2", 0x9275 },
++ { "GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", 0x9276 },
++ { "GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", 0x9277 },
++ { "GL_COMPRESSED_RGBA8_ETC2_EAC", 0x9278 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", 0x9279 },
++ { "GL_COMPRESSED_R11_EAC", 0x9270 },
++ { "GL_COMPRESSED_SIGNED_R11_EAC", 0x9271 },
++ { "GL_COMPRESSED_RG11_EAC", 0x9272 },
++ { "GL_COMPRESSED_SIGNED_RG11_EAC", 0x9273 },
++ { "GL_COMPRESSED_ALPHA_ARB", 0x84E9 },
++ { "GL_COMPRESSED_LUMINANCE_ARB", 0x84EA },
++ { "GL_COMPRESSED_LUMINANCE_ALPHA_ARB", 0x84EB },
++ { "GL_COMPRESSED_INTENSITY_ARB", 0x84EC },
++ { "GL_COMPRESSED_RGB_ARB", 0x84ED },
++ { "GL_COMPRESSED_RGBA_ARB", 0x84EE },
++ { "GL_COMPRESSED_TEXTURE_FORMATS_ARB", 0x86A3 },
++ { "GL_COMPRESSED_RGBA_BPTC_UNORM_ARB", 0x8E8C },
++ { "GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB", 0x8E8D },
++ { "GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB", 0x8E8E },
++ { "GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB", 0x8E8F },
++ { "GL_COMPRESSED_RGBA_ASTC_4x4_KHR", 0x93B0 },
++ { "GL_COMPRESSED_RGBA_ASTC_5x4_KHR", 0x93B1 },
++ { "GL_COMPRESSED_RGBA_ASTC_5x5_KHR", 0x93B2 },
++ { "GL_COMPRESSED_RGBA_ASTC_6x5_KHR", 0x93B3 },
++ { "GL_COMPRESSED_RGBA_ASTC_6x6_KHR", 0x93B4 },
++ { "GL_COMPRESSED_RGBA_ASTC_8x5_KHR", 0x93B5 },
++ { "GL_COMPRESSED_RGBA_ASTC_8x6_KHR", 0x93B6 },
++ { "GL_COMPRESSED_RGBA_ASTC_8x8_KHR", 0x93B7 },
++ { "GL_COMPRESSED_RGBA_ASTC_10x5_KHR", 0x93B8 },
++ { "GL_COMPRESSED_RGBA_ASTC_10x6_KHR", 0x93B9 },
++ { "GL_COMPRESSED_RGBA_ASTC_10x8_KHR", 0x93BA },
++ { "GL_COMPRESSED_RGBA_ASTC_10x10_KHR", 0x93BB },
++ { "GL_COMPRESSED_RGBA_ASTC_12x10_KHR", 0x93BC },
++ { "GL_COMPRESSED_RGBA_ASTC_12x12_KHR", 0x93BD },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR", 0x93D0 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR", 0x93D1 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR", 0x93D2 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR", 0x93D3 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR", 0x93D4 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR", 0x93D5 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR", 0x93D6 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR", 0x93D7 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR", 0x93D8 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR", 0x93D9 },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR", 0x93DA },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR", 0x93DB },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR", 0x93DC },
++ { "GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR", 0x93DD },
++ { "GL_COMPRESSED_RGB_FXT1_3DFX", 0x86B0 },
++ { "GL_COMPRESSED_RGBA_FXT1_3DFX", 0x86B1 },
++ { "GL_COMPRESSED_LUMINANCE_LATC1_EXT", 0x8C70 },
++ { "GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT", 0x8C71 },
++ { "GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT", 0x8C72 },
++ { "GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT", 0x8C73 },
++ { "GL_COMPRESSED_RED_RGTC1_EXT", 0x8DBB },
++ { "GL_COMPRESSED_SIGNED_RED_RGTC1_EXT", 0x8DBC },
++ { "GL_COMPRESSED_RED_GREEN_RGTC2_EXT", 0x8DBD },
++ { "GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT", 0x8DBE },
++ { "GL_COMPRESSED_RGB_S3TC_DXT1_EXT", 0x83F0 },
++ { "GL_COMPRESSED_RGBA_S3TC_DXT1_EXT", 0x83F1 },
++ { "GL_COMPRESSED_RGBA_S3TC_DXT3_EXT", 0x83F2 },
++ { "GL_COMPRESSED_RGBA_S3TC_DXT5_EXT", 0x83F3 },
++ { "GL_COMPRESSED_SRGB_EXT", 0x8C48 },
++ { "GL_COMPRESSED_SRGB_ALPHA_EXT", 0x8C49 },
++ { "GL_COMPRESSED_SLUMINANCE_EXT", 0x8C4A },
++ { "GL_COMPRESSED_SLUMINANCE_ALPHA_EXT", 0x8C4B },
++ { "GL_COMPRESSED_SRGB_S3TC_DXT1_EXT", 0x8C4C },
++ { "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT", 0x8C4D },
++ { "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT", 0x8C4E },
++ { "GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT", 0x8C4F },
++ { "GL_PALETTE4_RGB8_OES", 0x8B90 },
++ { "GL_PALETTE4_RGBA8_OES", 0x8B91 },
++ { "GL_PALETTE4_R5_G6_B5_OES", 0x8B92 },
++ { "GL_PALETTE4_RGBA4_OES", 0x8B93 },
++ { "GL_PALETTE4_RGB5_A1_OES", 0x8B94 },
++ { "GL_PALETTE8_RGB8_OES", 0x8B95 },
++ { "GL_PALETTE8_RGBA8_OES", 0x8B96 },
++ { "GL_PALETTE8_R5_G6_B5_OES", 0x8B97 },
++ { "GL_PALETTE8_RGBA4_OES", 0x8B98 },
++ { "GL_PALETTE8_RGB5_A1_OES", 0x8B99 }
++ };
++ const int n = sizeof(enums) / sizeof(enums[0]);
++ static char buffer[100];
++ int i;
++ for (i = 0; i < n; i++) {
++ if (enums[i].val == val) {
++ return enums[i].name;
++ }
++ }
++ /* enum val not found, just print hexadecimal value into static buffer */
++ snprintf(buffer, sizeof(buffer), "0x%x", val);
++ return buffer;
++}
++
++
++/*
++ * qsort callback for string comparison.
++ */
++static int
++compare_string_ptr(const void *p1, const void *p2)
++{
++ return strcmp(* (char * const *) p1, * (char * const *) p2);
++}
++
++/*
++ * Print a list of extensions, with word-wrapping.
++ */
++void
++print_extension_list(const char *ext, GLboolean singleLine)
++{
++ char **extensions;
++ int num_extensions;
++ const char *indentString = " ";
++ const int indent = 4;
++ const int max = 79;
++ int width, i, j, k;
++
++ if (!ext || !ext[0])
++ return;
++
++ /* count the number of extensions, ignoring successive spaces */
++ num_extensions = 0;
++ j = 1;
++ do {
++ if ((ext[j] == ' ' || ext[j] == 0) && ext[j - 1] != ' ') {
++ ++num_extensions;
++ }
++ } while(ext[j++]);
++
++ /* copy individual extensions to an array */
++ extensions = malloc(num_extensions * sizeof *extensions);
++ if (!extensions) {
++ fprintf(stderr, "Error: malloc() failed\n");
++ exit(1);
++ }
++ i = j = k = 0;
++ while (1) {
++ if (ext[j] == ' ' || ext[j] == 0) {
++ /* found end of an extension name */
++ const int len = j - i;
++
++ if (len) {
++ assert(k < num_extensions);
++
++ extensions[k] = malloc(len + 1);
++ if (!extensions[k]) {
++ fprintf(stderr, "Error: malloc() failed\n");
++ exit(1);
++ }
++
++ memcpy(extensions[k], ext + i, len);
++ extensions[k][len] = 0;
++
++ ++k;
++ };
++
++ i += len + 1;
++
++ if (ext[j] == 0) {
++ break;
++ }
++ }
++ j++;
++ }
++ assert(k == num_extensions);
++
++ /* sort extensions alphabetically */
++ qsort(extensions, num_extensions, sizeof extensions[0], compare_string_ptr);
++
++ /* print the extensions */
++ width = indent;
++ printf("%s", indentString);
++ for (k = 0; k < num_extensions; ++k) {
++ const int len = strlen(extensions[k]);
++ if ((!singleLine) && (width + len > max)) {
++ /* start a new line */
++ printf("\n");
++ width = indent;
++ printf("%s", indentString);
++ }
++ /* print the extension name */
++ printf("%s", extensions[k]);
++
++ /* either we're all done, or we'll continue with next extension */
++ width += len + 1;
++
++ if (singleLine) {
++ printf("\n");
++ width = indent;
++ printf("%s", indentString);
++ }
++ else if (k < (num_extensions -1)) {
++ printf(", ");
++ width += 2;
++ }
++ }
++ printf("\n");
++
++ for (k = 0; k < num_extensions; ++k) {
++ free(extensions[k]);
++ }
++ free(extensions);
++}
++
++
++
++
++/**
++ * Get list of OpenGL extensions using core profile's glGetStringi().
++ */
++char *
++build_core_profile_extension_list(const struct ext_functions *extfuncs)
++{
++ GLint i, n, totalLen;
++ char *buffer;
++
++ glGetIntegerv(GL_NUM_EXTENSIONS, &n);
++
++ /* compute totalLen */
++ totalLen = 0;
++ for (i = 0; i < n; i++) {
++ const char *ext = (const char *) extfuncs->GetStringi(GL_EXTENSIONS, i);
++ if (ext)
++ totalLen += strlen(ext) + 1; /* plus a space */
++ }
++
++ if (!totalLen)
++ return NULL;
++
++ buffer = malloc(totalLen + 1);
++ if (buffer) {
++ int pos = 0;
++ for (i = 0; i < n; i++) {
++ const char *ext = (const char *) extfuncs->GetStringi(GL_EXTENSIONS, i);
++ strcpy(buffer + pos, ext);
++ pos += strlen(ext);
++ buffer[pos++] = ' ';
++ }
++ buffer[pos] = '\0';
++ }
++ return buffer;
++}
++
++
++/** Is extension 'ext' supported? */
++GLboolean
++extension_supported(const char *ext, const char *extensionsList)
++{
++ while (1) {
++ const char *p = strstr(extensionsList, ext);
++ if (p) {
++ /* check that next char is a space or end of string */
++ int extLen = strlen(ext);
++ if (p[extLen] == 0 || p[extLen] == ' ') {
++ return 1;
++ }
++ else {
++ /* We found a superset string, keep looking */
++ extensionsList += extLen;
++ }
++ }
++ else {
++ break;
++ }
++ }
++ return 0;
++}
++
++
++/**
++ * Is verNum >= verString?
++ * \param verString such as "2.1", "3.0", etc.
++ * \param verNum such as 20, 21, 30, 31, 32, etc.
++ */
++static GLboolean
++version_supported(const char *verString, int verNum)
++{
++ int v;
++
++ if (!verString ||
++ !isdigit(verString[0]) ||
++ verString[1] != '.' ||
++ !isdigit(verString[2])) {
++ return GL_FALSE;
++ }
++
++ v = (verString[0] - '0') * 10 + (verString[2] - '0');
++
++ return verNum >= v;
++}
++
++
++struct token_name
++{
++ GLenum token;
++ const char *name;
++};
++
++
++static void
++print_shader_limit_list(const struct token_name *lim)
++{
++ GLint max[1];
++ unsigned i;
++
++ for (i = 0; lim[i].token; i++) {
++ glGetIntegerv(lim[i].token, max);
++ if (glGetError() == GL_NO_ERROR) {
++ printf(" %s = %d\n", lim[i].name, max[0]);
++ }
++ }
++}
++
++
++/**
++ * Print interesting limits for vertex/fragment shaders.
++ */
++static void
++print_shader_limits(GLenum target)
++{
++ static const struct token_name vertex_limits[] = {
++ { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" },
++ { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" },
++ { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" },
++ { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
++ { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" },
++ { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" },
++ { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
++ { GL_MAX_VERTEX_OUTPUT_COMPONENTS , "GL_MAX_VERTEX_OUTPUT_COMPONENTS " },
++ { (GLenum) 0, NULL }
++ };
++ static const struct token_name fragment_limits[] = {
++ { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" },
++ { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" },
++ { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" },
++ { GL_MAX_FRAGMENT_INPUT_COMPONENTS , "GL_MAX_FRAGMENT_INPUT_COMPONENTS " },
++ { (GLenum) 0, NULL }
++ };
++ static const struct token_name geometry_limits[] = {
++ { GL_MAX_GEOMETRY_UNIFORM_COMPONENTS, "GL_MAX_GEOMETRY_UNIFORM_COMPONENTS" },
++ { GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, "GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS" },
++ { GL_MAX_GEOMETRY_OUTPUT_VERTICES , "GL_MAX_GEOMETRY_OUTPUT_VERTICES " },
++ { GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS, "GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS" },
++ { GL_MAX_GEOMETRY_INPUT_COMPONENTS , "GL_MAX_GEOMETRY_INPUT_COMPONENTS " },
++ { GL_MAX_GEOMETRY_OUTPUT_COMPONENTS, "GL_MAX_GEOMETRY_OUTPUT_COMPONENTS" },
++ { (GLenum) 0, NULL }
++ };
++
++ switch (target) {
++ case GL_VERTEX_SHADER:
++ printf(" GL_VERTEX_SHADER_ARB:\n");
++ print_shader_limit_list(vertex_limits);
++ break;
++
++ case GL_FRAGMENT_SHADER:
++ printf(" GL_FRAGMENT_SHADER_ARB:\n");
++ print_shader_limit_list(fragment_limits);
++ break;
++
++ case GL_GEOMETRY_SHADER:
++ printf(" GL_GEOMETRY_SHADER:\n");
++ print_shader_limit_list(geometry_limits);
++ break;
++ }
++}
++
++
++/**
++ * Print interesting limits for vertex/fragment programs.
++ */
++static void
++print_program_limits(GLenum target,
++ const struct ext_functions *extfuncs)
++{
++#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program)
++ struct token_name {
++ GLenum token;
++ const char *name;
++ };
++ static const struct token_name common_limits[] = {
++ { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" },
++ { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" },
++ { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" },
++ { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" },
++ { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" },
++ { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" },
++ { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" },
++ { (GLenum) 0, NULL }
++ };
++ static const struct token_name fragment_limits[] = {
++ { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" },
++ { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" },
++ { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" },
++ { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" },
++ { (GLenum) 0, NULL }
++ };
++
++ GLint max[1];
++ int i;
++
++ if (target == GL_VERTEX_PROGRAM_ARB) {
++ printf(" GL_VERTEX_PROGRAM_ARB:\n");
++ }
++ else if (target == GL_FRAGMENT_PROGRAM_ARB) {
++ printf(" GL_FRAGMENT_PROGRAM_ARB:\n");
++ }
++ else {
++ return; /* something's wrong */
++ }
++
++ for (i = 0; common_limits[i].token; i++) {
++ extfuncs->GetProgramivARB(target, common_limits[i].token, max);
++ if (glGetError() == GL_NO_ERROR) {
++ printf(" %s = %d\n", common_limits[i].name, max[0]);
++ }
++ }
++ if (target == GL_FRAGMENT_PROGRAM_ARB) {
++ for (i = 0; fragment_limits[i].token; i++) {
++ extfuncs->GetProgramivARB(target, fragment_limits[i].token, max);
++ if (glGetError() == GL_NO_ERROR) {
++ printf(" %s = %d\n", fragment_limits[i].name, max[0]);
++ }
++ }
++ }
++#endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */
++}
++
++
++/**
++ * Print interesting OpenGL implementation limits.
++ * \param version 20, 21, 30, 31, 32, etc.
++ */
++void
++print_limits(const char *extensions, const char *oglstring, int version,
++ const struct ext_functions *extfuncs)
++{
++ struct token_name {
++ GLuint count;
++ GLenum token;
++ const char *name;
++ const char *extension; /* NULL or GL extension name or version string */
++ };
++ static const struct token_name limits[] = {
++ { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH", NULL },
++ { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH", NULL },
++ { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES", NULL },
++ { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH", "GL_ARB_imaging" },
++ { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES", NULL },
++ { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES", NULL },
++ { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER", NULL },
++ { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS", NULL },
++ { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING", NULL },
++ { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH", NULL },
++ { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH", NULL },
++ { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE", NULL },
++ { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH", NULL },
++ { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH", NULL },
++ { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE", NULL },
++ { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE", NULL },
++#if defined(GL_EXT_texture_array)
++ { 1, GL_MAX_ARRAY_TEXTURE_LAYERS_EXT, "GL_MAX_ARRAY_TEXTURE_LAYERS", "GL_EXT_texture_array" },
++#endif
++ { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS", NULL },
++ { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE", NULL },
++ { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE", NULL },
++ { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE", NULL },
++ { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE", NULL },
++#if defined(GL_ARB_texture_cube_map)
++ { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB", "GL_ARB_texture_cube_map" },
++#endif
++#if defined(GL_NV_texture_rectangle)
++ { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV", "GL_NV_texture_rectangle" },
++#endif
++#if defined(GL_ARB_multitexture)
++ { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB", "GL_ARB_multitexture" },
++#endif
++#if defined(GL_EXT_texture_lod_bias)
++ { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT", "GL_EXT_texture_lod_bias" },
++#endif
++#if defined(GL_EXT_texture_filter_anisotropic)
++ { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT", "GL_EXT_texture_filter_anisotropic" },
++#endif
++#if defined(GL_ARB_draw_buffers)
++ { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB", "GL_ARB_draw_buffers" },
++#endif
++#if defined(GL_ARB_blend_func_extended)
++ { 1, GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, "GL_MAX_DUAL_SOURCE_DRAW_BUFFERS", "GL_ARB_blend_func_extended" },
++#endif
++#if defined (GL_ARB_framebuffer_object)
++ { 1, GL_MAX_RENDERBUFFER_SIZE, "GL_MAX_RENDERBUFFER_SIZE", "GL_ARB_framebuffer_object" },
++ { 1, GL_MAX_COLOR_ATTACHMENTS, "GL_MAX_COLOR_ATTACHMENTS", "GL_ARB_framebuffer_object" },
++ { 1, GL_MAX_SAMPLES, "GL_MAX_SAMPLES", "GL_ARB_framebuffer_object" },
++#endif
++#if defined (GL_EXT_transform_feedback)
++ { 1, GL_MAX_TRANSFORM_FEEDBACK_BUFFERS, "GL_MAX_TRANSFORM_FEEDBACK_BUFFERS", "GL_EXT_transform_feedback" },
++ { 1, GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS_EXT, "GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", "GL_EXT_transform_feedback" },
++ { 1, GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS_EXT, "GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", "GL_EXT_transform_feedback", },
++ { 1, GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS_EXT, "GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", "GL_EXT_transform_feedback" },
++#endif
++#if defined (GL_ARB_texture_buffer_object)
++ { 1, GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT, "GL_TEXTURE_BUFFER_OFFSET_ALIGNMENT", "GL_ARB_texture_buffer_object" },
++ { 1, GL_MAX_TEXTURE_BUFFER_SIZE, "GL_MAX_TEXTURE_BUFFER_SIZE", "GL_ARB_texture_buffer_object" },
++#endif
++#if defined (GL_ARB_texture_multisample)
++ { 1, GL_MAX_COLOR_TEXTURE_SAMPLES, "GL_MAX_COLOR_TEXTURE_SAMPLES", "GL_ARB_texture_multisample" },
++ { 1, GL_MAX_DEPTH_TEXTURE_SAMPLES, "GL_MAX_DEPTH_TEXTURE_SAMPLES", "GL_ARB_texture_multisample" },
++ { 1, GL_MAX_INTEGER_SAMPLES, "GL_MAX_INTEGER_SAMPLES", "GL_ARB_texture_multisample" },
++#endif
++#if defined (GL_ARB_uniform_buffer_object)
++ { 1, GL_MAX_VERTEX_UNIFORM_BLOCKS, "GL_MAX_VERTEX_UNIFORM_BLOCKS", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_FRAGMENT_UNIFORM_BLOCKS, "GL_MAX_FRAGMENT_UNIFORM_BLOCKS", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_GEOMETRY_UNIFORM_BLOCKS, "GL_MAX_GEOMETRY_UNIFORM_BLOCKS" , "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_COMBINED_UNIFORM_BLOCKS, "GL_MAX_COMBINED_UNIFORM_BLOCKS", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_UNIFORM_BUFFER_BINDINGS, "GL_MAX_UNIFORM_BUFFER_BINDINGS", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_UNIFORM_BLOCK_SIZE, "GL_MAX_UNIFORM_BLOCK_SIZE", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS, "GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS, "GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS, "GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS", "GL_ARB_uniform_buffer_object" },
++ { 1, GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, "GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT", "GL_ARB_uniform_buffer_object" },
++#endif
++#if defined (GL_ARB_vertex_attrib_binding)
++ { 1, GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET, "GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET", "GL_ARB_vertex_attrib_binding" },
++ { 1, GL_MAX_VERTEX_ATTRIB_BINDINGS, "GL_MAX_VERTEX_ATTRIB_BINDINGS", "GL_ARB_vertex_attrib_binding" },
++#endif
++#if defined(GL_VERSION_4_4)
++ { 1, GL_MAX_VERTEX_ATTRIB_STRIDE, "GL_MAX_VERTEX_ATTRIB_STRIDE", "4.4" },
++#endif
++ { 0, (GLenum) 0, NULL, NULL }
++ };
++ GLint i, max[2];
++
++ printf("%s limits:\n", oglstring);
++ for (i = 0; limits[i].count; i++) {
++ if (!limits[i].extension ||
++ version_supported(limits[i].extension, version) ||
++ extension_supported(limits[i].extension, extensions)) {
++ glGetIntegerv(limits[i].token, max);
++ if (glGetError() == GL_NO_ERROR) {
++ if (limits[i].count == 1)
++ printf(" %s = %d\n", limits[i].name, max[0]);
++ else /* XXX fix if we ever query something with more than 2 values */
++ printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]);
++ }
++ }
++ }
++
++ /* these don't fit into the above mechanism, unfortunately */
++ if (extension_supported("GL_ARB_imaging", extensions)) {
++ extfuncs->GetConvolutionParameteriv(GL_CONVOLUTION_2D,
++ GL_MAX_CONVOLUTION_WIDTH, max);
++ extfuncs->GetConvolutionParameteriv(GL_CONVOLUTION_2D,
++ GL_MAX_CONVOLUTION_HEIGHT, max+1);
++ printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]);
++ }
++
++ if (extension_supported("GL_ARB_texture_compression", extensions)) {
++ GLint i, n;
++ GLint *formats;
++ glGetIntegerv(GL_NUM_COMPRESSED_TEXTURE_FORMATS, &n);
++ printf(" GL_NUM_COMPRESSED_TEXTURE_FORMATS = %d\n", n);
++ formats = (GLint *) malloc(n * sizeof(GLint));
++ glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, formats);
++ for (i = 0; i < n; i++) {
++ printf(" %s\n", enum_name(formats[i]));
++ }
++ free(formats);
++ }
++#if defined(GL_ARB_vertex_program)
++ if (extension_supported("GL_ARB_vertex_program", extensions)) {
++ print_program_limits(GL_VERTEX_PROGRAM_ARB, extfuncs);
++ }
++#endif
++#if defined(GL_ARB_fragment_program)
++ if (extension_supported("GL_ARB_fragment_program", extensions)) {
++ print_program_limits(GL_FRAGMENT_PROGRAM_ARB, extfuncs);
++ }
++#endif
++ if (extension_supported("GL_ARB_vertex_shader", extensions)) {
++ print_shader_limits(GL_VERTEX_SHADER_ARB);
++ }
++ if (extension_supported("GL_ARB_fragment_shader", extensions)) {
++ print_shader_limits(GL_FRAGMENT_SHADER_ARB);
++ }
++ if (version >= 32) {
++ print_shader_limits(GL_GEOMETRY_SHADER);
++ }
++}
++
++
++
++/**
++ * Return string representation for bits in a bitmask.
++ */
++const char *
++bitmask_to_string(const struct bit_info bits[], int numBits, int mask)
++{
++ static char buffer[256], *p;
++ int i;
++
++ strcpy(buffer, "(none)");
++ p = buffer;
++ for (i = 0; i < numBits; i++) {
++ if (mask & bits[i].bit) {
++ if (p > buffer)
++ *p++ = ',';
++ strcpy(p, bits[i].name);
++ p += strlen(bits[i].name);
++ }
++ }
++
++ return buffer;
++}
++
++/**
++ * Return string representation for the bitmask returned by
++ * GL_CONTEXT_PROFILE_MASK (OpenGL 3.2 or later).
++ */
++const char *
++profile_mask_string(int mask)
++{
++ const static struct bit_info bits[] = {
++#ifdef GL_CONTEXT_CORE_PROFILE_BIT
++ { GL_CONTEXT_CORE_PROFILE_BIT, "core profile"},
++#endif
++#ifdef GL_CONTEXT_COMPATIBILITY_PROFILE_BIT
++ { GL_CONTEXT_COMPATIBILITY_PROFILE_BIT, "compatibility profile" }
++#endif
++ };
++
++ return bitmask_to_string(bits, ELEMENTS(bits), mask);
++}
++
++
++/**
++ * Return string representation for the bitmask returned by
++ * GL_CONTEXT_FLAGS (OpenGL 3.0 or later).
++ */
++const char *
++context_flags_string(int mask)
++{
++ const static struct bit_info bits[] = {
++#ifdef GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT
++ { GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT, "forward-compatible" },
++#endif
++#ifdef GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB
++ { GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB, "robust-access" },
++#endif
++ };
++
++ return bitmask_to_string(bits, ELEMENTS(bits), mask);
++}
++
++
++static void
++usage(void)
++{
++#ifdef _WIN32
++ printf("Usage: wglinfo [-v] [-t] [-h] [-b] [-l] [-s]\n");
++#else
++ printf("Usage: glxinfo [-v] [-t] [-h] [-b] [-l] [-s] [-i] [-display <dname>]\n");
++ printf("\t-display <dname>: Print GLX visuals on specified server.\n");
++ printf("\t-i: Force an indirect rendering context.\n");
++#endif
++ printf("\t-B: brief output, print only the basics.\n");
++ printf("\t-v: Print visuals info in verbose form.\n");
++ printf("\t-t: Print verbose table.\n");
++ printf("\t-h: This information.\n");
++ printf("\t-b: Find the 'best' visual and print its number.\n");
++ printf("\t-l: Print interesting OpenGL limits.\n");
++ printf("\t-s: Print a single extension per line.\n");
++}
++
++void
++parse_args(int argc, char *argv[], struct options *options)
++{
++ int i;
++
++ options->mode = Normal;
++ options->findBest = GL_FALSE;
++ options->limits = GL_FALSE;
++ options->singleLine = GL_FALSE;
++ options->displayName = NULL;
++ options->allowDirect = GL_TRUE;
++
++ for (i = 1; i < argc; i++) {
++#ifndef _WIN32
++ if (strcmp(argv[i], "-display") == 0 && i + 1 < argc) {
++ options->displayName = argv[i + 1];
++ i++;
++ }
++ else if (strcmp(argv[i], "-i") == 0) {
++ options->allowDirect = GL_FALSE;
++ }
++ else
++#endif
++ if (strcmp(argv[i], "-t") == 0) {
++ options->mode = Wide;
++ }
++ else if (strcmp(argv[i], "-v") == 0) {
++ options->mode = Verbose;
++ }
++ else if (strcmp(argv[i], "-B") == 0) {
++ options->mode = Brief;
++ }
++ else if (strcmp(argv[i], "-b") == 0) {
++ options->findBest = GL_TRUE;
++ }
++ else if (strcmp(argv[i], "-l") == 0) {
++ options->limits = GL_TRUE;
++ }
++ else if (strcmp(argv[i], "-h") == 0) {
++ usage();
++ exit(0);
++ }
++ else if(strcmp(argv[i], "-s") == 0) {
++ options->singleLine = GL_TRUE;
++ }
++ else {
++ printf("Unknown option `%s'\n", argv[i]);
++ usage();
++ exit(0);
++ }
++ }
++}
+diff -Naurp mesa-20.2.1-orig/src/glx/xdemos/glinfo_common.h mesa-20.2.1/src/glx/xdemos/glinfo_common.h
+--- mesa-20.2.1-orig/src/glx/xdemos/glinfo_common.h 1969-12-31 18:00:00.000000000 -0600
++++ mesa-20.2.1/src/glx/xdemos/glinfo_common.h 2020-10-15 23:06:45.826695773 -0500
+@@ -0,0 +1,142 @@
++/*
++ * Copyright (C) 1999-2014 Brian Paul All Rights Reserved.
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a
++ * copy of this software and associated documentation files (the "Software"),
++ * to deal in the Software without restriction, including without limitation
++ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
++ * and/or sell copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included
++ * in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
++ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
++ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/**
++ * Common code shared by glxinfo and wglinfo.
++ */
++
++#ifndef GLINFO_COMMON_H
++#define GLINFO_COMMON_H
++
++
++#ifdef _WIN32
++/* GL/glext.h is not commonly available on Windows. */
++#include <GL/glew.h>
++#else
++#include <GL/gl.h>
++#include <GL/glext.h>
++#endif
++
++typedef void (APIENTRY * GETPROGRAMIVARBPROC) (GLenum target, GLenum pname, GLint *params);
++typedef const GLubyte *(APIENTRY * GETSTRINGIPROC) (GLenum name, GLuint index);
++typedef void (APIENTRY * GETCONVOLUTIONPARAMETERIVPROC) (GLenum target, GLenum pname, GLint *params);
++
++
++/**
++ * Ext functions needed in common code but must be provided by
++ * glxinfo or wglinfo.
++ */
++struct ext_functions
++{
++ GETPROGRAMIVARBPROC GetProgramivARB;
++ GETSTRINGIPROC GetStringi;
++ GETCONVOLUTIONPARAMETERIVPROC GetConvolutionParameteriv;
++};
++
++
++#define ELEMENTS(array) (sizeof(array) / sizeof(array[0]))
++
++
++struct bit_info
++{
++ int bit;
++ const char *name;
++};
++
++
++typedef enum
++{
++ Normal,
++ Wide,
++ Verbose,
++ Brief
++} InfoMode;
++
++
++struct options
++{
++ InfoMode mode;
++ GLboolean findBest;
++ GLboolean limits;
++ GLboolean singleLine;
++ /* GLX only */
++ char *displayName;
++ GLboolean allowDirect;
++};
++
++
++/** list of known OpenGL versions */
++static const struct { int major, minor; } gl_versions[] = {
++ {4, 5},
++ {4, 4},
++ {4, 3},
++ {4, 2},
++ {4, 1},
++ {4, 0},
++
++ {3, 3},
++ {3, 2},
++ {3, 1},
++ {3, 0},
++
++ {2, 1},
++ {2, 0},
++
++ {1, 5},
++ {1, 4},
++ {1, 3},
++ {1, 2},
++ {1, 1},
++ {1, 0},
++
++ {0, 0} /* end of list */
++};
++
++
++void
++print_extension_list(const char *ext, GLboolean singleLine);
++
++char *
++build_core_profile_extension_list(const struct ext_functions *extfuncs);
++
++GLboolean
++extension_supported(const char *ext, const char *extensionsList);
++
++void
++print_limits(const char *extensions, const char *oglstring, int version,
++ const struct ext_functions *extfuncs);
++
++const char *
++bitmask_to_string(const struct bit_info bits[], int numBits, int mask);
++
++const char *
++profile_mask_string(int mask);
++
++const char *
++context_flags_string(int mask);
++
++
++void
++parse_args(int argc, char *argv[], struct options *options);
++
++
++#endif /* GLINFO_COMMON_H */
+diff -Naurp mesa-20.2.1-orig/src/glx/xdemos/glxgears.1 mesa-20.2.1/src/glx/xdemos/glxgears.1
+--- mesa-20.2.1-orig/src/glx/xdemos/glxgears.1 1969-12-31 18:00:00.000000000 -0600
++++ mesa-20.2.1/src/glx/xdemos/glxgears.1 2020-10-15 23:06:45.826695773 -0500
+@@ -0,0 +1,37 @@
++.TH glxgears 1 "2006-11-29"
++.SH NAME
++glxgears \- ``gears'' demo for GLX
++.SH SYNOPSIS
++.B glxgears
++.RI [ options ]
++.SH DESCRIPTION
++The \fIglxgears\fP program is a port of the ``gears'' demo to GLX. It displays
++a set of rotating gears and prints out the frame rate at regular intervals. It
++has become quite popular as basic benchmarking tool.
++.SH OPTIONS
++.TP 8
++.B \-display \fIdisplay\fP
++Specify which X display to run on.
++.TP 8
++.B \-stereo
++Use a stereo enabled GLX visual.
++.TP 8
++.B \-samples \fIN\fP
++Run in multisample mode with at least N samples.
++.TP 8
++.B \-fullscreen
++Run in fullscreen mode.
++.TP 8
++.B \-info
++Display OpenGL renderer information.
++.TP 8
++.B \-geometry \fIWxH+X+Y\fP
++Window geometry.
++.SH AUTHOR
++glxgears was written by Brian Paul <brian.paul@tungstengraphics.com>.
++.PP
++This manual page was written by Thierry Reding <thierry@gilfi.de>, for the
++Debian project and updated by Fernando de Oliveira <famobr at yahoo dot
++com dot br>, for the Linux From Scratch (LFS) project (but may be used by
++others).
++
+diff -Naurp mesa-20.2.1-orig/src/glx/xdemos/glxgears.c mesa-20.2.1/src/glx/xdemos/glxgears.c
+--- mesa-20.2.1-orig/src/glx/xdemos/glxgears.c 1969-12-31 18:00:00.000000000 -0600
++++ mesa-20.2.1/src/glx/xdemos/glxgears.c 2020-10-15 23:06:45.826695773 -0500
+@@ -0,0 +1,809 @@
++/*
++ * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a
++ * copy of this software and associated documentation files (the "Software"),
++ * to deal in the Software without restriction, including without limitation
++ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
++ * and/or sell copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included
++ * in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
++ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
++ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++/*
++ * This is a port of the infamous "gears" demo to straight GLX (i.e. no GLUT)
++ * Port by Brian Paul 23 March 2001
++ *
++ * See usage() below for command line options.
++ */
++
++
++#include <math.h>
++#include <stdlib.h>
++#include <stdio.h>
++#include <string.h>
++#include <X11/Xlib.h>
++#include <X11/keysym.h>
++#include <GL/gl.h>
++#include <GL/glx.h>
++#include <GL/glxext.h>
++
++#ifndef GLX_MESA_swap_control
++#define GLX_MESA_swap_control 1
++typedef int (*PFNGLXGETSWAPINTERVALMESAPROC)(void);
++#endif
++
++
++#define BENCHMARK
++
++#ifdef BENCHMARK
++
++/* XXX this probably isn't very portable */
++
++#include <sys/time.h>
++#include <unistd.h>
++
++/* return current time (in seconds) */
++static double
++current_time(void)
++{
++ struct timeval tv;
++#ifdef __VMS
++ (void) gettimeofday(&tv, NULL );
++#else
++ struct timezone tz;
++ (void) gettimeofday(&tv, &tz);
++#endif
++ return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
++}
++
++#else /*BENCHMARK*/
++
++/* dummy */
++static double
++current_time(void)
++{
++ /* update this function for other platforms! */
++ static double t = 0.0;
++ static int warn = 1;
++ if (warn) {
++ fprintf(stderr, "Warning: current_time() not implemented!!\n");
++ warn = 0;
++ }
++ return t += 1.0;
++}
++
++#endif /*BENCHMARK*/
++
++
++
++#ifndef M_PI
++#define M_PI 3.14159265
++#endif
++
++
++/** Event handler results: */
++#define NOP 0
++#define EXIT 1
++#define DRAW 2
++
++static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0;
++static GLint gear1, gear2, gear3;
++static GLfloat angle = 0.0;
++
++static GLboolean fullscreen = GL_FALSE; /* Create a single fullscreen window */
++static GLboolean stereo = GL_FALSE; /* Enable stereo. */
++static GLint samples = 0; /* Choose visual with at least N samples. */
++static GLboolean animate = GL_TRUE; /* Animation */
++static GLfloat eyesep = 5.0; /* Eye separation. */
++static GLfloat fix_point = 40.0; /* Fixation point distance. */
++static GLfloat left, right, asp; /* Stereo frustum params. */
++
++
++/*
++ *
++ * Draw a gear wheel. You'll probably want to call this function when
++ * building a display list since we do a lot of trig here.
++ *
++ * Input: inner_radius - radius of hole at center
++ * outer_radius - radius at center of teeth
++ * width - width of gear
++ * teeth - number of teeth
++ * tooth_depth - depth of tooth
++ */
++static void
++gear(GLfloat inner_radius, GLfloat outer_radius, GLfloat width,
++ GLint teeth, GLfloat tooth_depth)
++{
++ GLint i;
++ GLfloat r0, r1, r2;
++ GLfloat angle, da;
++ GLfloat u, v, len;
++
++ r0 = inner_radius;
++ r1 = outer_radius - tooth_depth / 2.0;
++ r2 = outer_radius + tooth_depth / 2.0;
++
++ da = 2.0 * M_PI / teeth / 4.0;
++
++ glShadeModel(GL_FLAT);
++
++ glNormal3f(0.0, 0.0, 1.0);
++
++ /* draw front face */
++ glBegin(GL_QUAD_STRIP);
++ for (i = 0; i <= teeth; i++) {
++ angle = i * 2.0 * M_PI / teeth;
++ glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
++ glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
++ if (i < teeth) {
++ glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
++ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
++ width * 0.5);
++ }
++ }
++ glEnd();
++
++ /* draw front sides of teeth */
++ glBegin(GL_QUADS);
++ da = 2.0 * M_PI / teeth / 4.0;
++ for (i = 0; i < teeth; i++) {
++ angle = i * 2.0 * M_PI / teeth;
++
++ glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
++ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
++ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
++ width * 0.5);
++ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
++ width * 0.5);
++ }
++ glEnd();
++
++ glNormal3f(0.0, 0.0, -1.0);
++
++ /* draw back face */
++ glBegin(GL_QUAD_STRIP);
++ for (i = 0; i <= teeth; i++) {
++ angle = i * 2.0 * M_PI / teeth;
++ glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
++ glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
++ if (i < teeth) {
++ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
++ -width * 0.5);
++ glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
++ }
++ }
++ glEnd();
++
++ /* draw back sides of teeth */
++ glBegin(GL_QUADS);
++ da = 2.0 * M_PI / teeth / 4.0;
++ for (i = 0; i < teeth; i++) {
++ angle = i * 2.0 * M_PI / teeth;
++
++ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
++ -width * 0.5);
++ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
++ -width * 0.5);
++ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
++ glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
++ }
++ glEnd();
++
++ /* draw outward faces of teeth */
++ glBegin(GL_QUAD_STRIP);
++ for (i = 0; i < teeth; i++) {
++ angle = i * 2.0 * M_PI / teeth;
++
++ glVertex3f(r1 * cos(angle), r1 * sin(angle), width * 0.5);
++ glVertex3f(r1 * cos(angle), r1 * sin(angle), -width * 0.5);
++ u = r2 * cos(angle + da) - r1 * cos(angle);
++ v = r2 * sin(angle + da) - r1 * sin(angle);
++ len = sqrt(u * u + v * v);
++ u /= len;
++ v /= len;
++ glNormal3f(v, -u, 0.0);
++ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), width * 0.5);
++ glVertex3f(r2 * cos(angle + da), r2 * sin(angle + da), -width * 0.5);
++ glNormal3f(cos(angle), sin(angle), 0.0);
++ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
++ width * 0.5);
++ glVertex3f(r2 * cos(angle + 2 * da), r2 * sin(angle + 2 * da),
++ -width * 0.5);
++ u = r1 * cos(angle + 3 * da) - r2 * cos(angle + 2 * da);
++ v = r1 * sin(angle + 3 * da) - r2 * sin(angle + 2 * da);
++ glNormal3f(v, -u, 0.0);
++ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
++ width * 0.5);
++ glVertex3f(r1 * cos(angle + 3 * da), r1 * sin(angle + 3 * da),
++ -width * 0.5);
++ glNormal3f(cos(angle), sin(angle), 0.0);
++ }
++
++ glVertex3f(r1 * cos(0), r1 * sin(0), width * 0.5);
++ glVertex3f(r1 * cos(0), r1 * sin(0), -width * 0.5);
++
++ glEnd();
++
++ glShadeModel(GL_SMOOTH);
++
++ /* draw inside radius cylinder */
++ glBegin(GL_QUAD_STRIP);
++ for (i = 0; i <= teeth; i++) {
++ angle = i * 2.0 * M_PI / teeth;
++ glNormal3f(-cos(angle), -sin(angle), 0.0);
++ glVertex3f(r0 * cos(angle), r0 * sin(angle), -width * 0.5);
++ glVertex3f(r0 * cos(angle), r0 * sin(angle), width * 0.5);
++ }
++ glEnd();
++}
++
++
++static void
++draw(void)
++{
++ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
++
++ glPushMatrix();
++ glRotatef(view_rotx, 1.0, 0.0, 0.0);
++ glRotatef(view_roty, 0.0, 1.0, 0.0);
++ glRotatef(view_rotz, 0.0, 0.0, 1.0);
++
++ glPushMatrix();
++ glTranslatef(-3.0, -2.0, 0.0);
++ glRotatef(angle, 0.0, 0.0, 1.0);
++ glCallList(gear1);
++ glPopMatrix();
++
++ glPushMatrix();
++ glTranslatef(3.1, -2.0, 0.0);
++ glRotatef(-2.0 * angle - 9.0, 0.0, 0.0, 1.0);
++ glCallList(gear2);
++ glPopMatrix();
++
++ glPushMatrix();
++ glTranslatef(-3.1, 4.2, 0.0);
++ glRotatef(-2.0 * angle - 25.0, 0.0, 0.0, 1.0);
++ glCallList(gear3);
++ glPopMatrix();
++
++ glPopMatrix();
++}
++
++
++static void
++draw_gears(void)
++{
++ if (stereo) {
++ /* First left eye. */
++ glDrawBuffer(GL_BACK_LEFT);
++
++ glMatrixMode(GL_PROJECTION);
++ glLoadIdentity();
++ glFrustum(left, right, -asp, asp, 5.0, 60.0);
++
++ glMatrixMode(GL_MODELVIEW);
++
++ glPushMatrix();
++ glTranslated(+0.5 * eyesep, 0.0, 0.0);
++ draw();
++ glPopMatrix();
++
++ /* Then right eye. */
++ glDrawBuffer(GL_BACK_RIGHT);
++
++ glMatrixMode(GL_PROJECTION);
++ glLoadIdentity();
++ glFrustum(-right, -left, -asp, asp, 5.0, 60.0);
++
++ glMatrixMode(GL_MODELVIEW);
++
++ glPushMatrix();
++ glTranslated(-0.5 * eyesep, 0.0, 0.0);
++ draw();
++ glPopMatrix();
++ }
++ else {
++ draw();
++ }
++}
++
++
++/** Draw single frame, do SwapBuffers, compute FPS */
++static void
++draw_frame(Display *dpy, Window win)
++{
++ static int frames = 0;
++ static double tRot0 = -1.0, tRate0 = -1.0;
++ double dt, t = current_time();
++
++ if (tRot0 < 0.0)
++ tRot0 = t;
++ dt = t - tRot0;
++ tRot0 = t;
++
++ if (animate) {
++ /* advance rotation for next frame */
++ angle += 70.0 * dt; /* 70 degrees per second */
++ if (angle > 3600.0)
++ angle -= 3600.0;
++ }
++
++ draw_gears();
++ glXSwapBuffers(dpy, win);
++
++ frames++;
++
++ if (tRate0 < 0.0)
++ tRate0 = t;
++ if (t - tRate0 >= 5.0) {
++ GLfloat seconds = t - tRate0;
++ GLfloat fps = frames / seconds;
++ printf("%d frames in %3.1f seconds = %6.3f FPS\n", frames, seconds,
++ fps);
++ fflush(stdout);
++ tRate0 = t;
++ frames = 0;
++ }
++}
++
++
++/* new window size or exposure */
++static void
++reshape(int width, int height)
++{
++ glViewport(0, 0, (GLint) width, (GLint) height);
++
++ if (stereo) {
++ GLfloat w;
++
++ asp = (GLfloat) height / (GLfloat) width;
++ w = fix_point * (1.0 / 5.0);
++
++ left = -5.0 * ((w - 0.5 * eyesep) / fix_point);
++ right = 5.0 * ((w + 0.5 * eyesep) / fix_point);
++ }
++ else {
++ GLfloat h = (GLfloat) height / (GLfloat) width;
++
++ glMatrixMode(GL_PROJECTION);
++ glLoadIdentity();
++ glFrustum(-1.0, 1.0, -h, h, 5.0, 60.0);
++ }
++
++ glMatrixMode(GL_MODELVIEW);
++ glLoadIdentity();
++ glTranslatef(0.0, 0.0, -40.0);
++}
++
++
++
++static void
++init(void)
++{
++ static GLfloat pos[4] = { 5.0, 5.0, 10.0, 0.0 };
++ static GLfloat red[4] = { 0.8, 0.1, 0.0, 1.0 };
++ static GLfloat green[4] = { 0.0, 0.8, 0.2, 1.0 };
++ static GLfloat blue[4] = { 0.2, 0.2, 1.0, 1.0 };
++
++ glLightfv(GL_LIGHT0, GL_POSITION, pos);
++ glEnable(GL_CULL_FACE);
++ glEnable(GL_LIGHTING);
++ glEnable(GL_LIGHT0);
++ glEnable(GL_DEPTH_TEST);
++
++ /* make the gears */
++ gear1 = glGenLists(1);
++ glNewList(gear1, GL_COMPILE);
++ glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
++ gear(1.0, 4.0, 1.0, 20, 0.7);
++ glEndList();
++
++ gear2 = glGenLists(1);
++ glNewList(gear2, GL_COMPILE);
++ glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
++ gear(0.5, 2.0, 2.0, 10, 0.7);
++ glEndList();
++
++ gear3 = glGenLists(1);
++ glNewList(gear3, GL_COMPILE);
++ glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
++ gear(1.3, 2.0, 0.5, 10, 0.7);
++ glEndList();
++
++ glEnable(GL_NORMALIZE);
++}
++
++
++/**
++ * Remove window border/decorations.
++ */
++static void
++no_border( Display *dpy, Window w)
++{
++ static const unsigned MWM_HINTS_DECORATIONS = (1 << 1);
++ static const int PROP_MOTIF_WM_HINTS_ELEMENTS = 5;
++
++ typedef struct
++ {
++ unsigned long flags;
++ unsigned long functions;
++ unsigned long decorations;
++ long inputMode;
++ unsigned long status;
++ } PropMotifWmHints;
++
++ PropMotifWmHints motif_hints;
++ Atom prop, proptype;
++ unsigned long flags = 0;
++
++ /* setup the property */
++ motif_hints.flags = MWM_HINTS_DECORATIONS;
++ motif_hints.decorations = flags;
++
++ /* get the atom for the property */
++ prop = XInternAtom( dpy, "_MOTIF_WM_HINTS", True );
++ if (!prop) {
++ /* something went wrong! */
++ return;
++ }
++
++ /* not sure this is correct, seems to work, XA_WM_HINTS didn't work */
++ proptype = prop;
++
++ XChangeProperty( dpy, w, /* display, window */
++ prop, proptype, /* property, type */
++ 32, /* format: 32-bit datums */
++ PropModeReplace, /* mode */
++ (unsigned char *) &motif_hints, /* data */
++ PROP_MOTIF_WM_HINTS_ELEMENTS /* nelements */
++ );
++}
++
++
++/*
++ * Create an RGB, double-buffered window.
++ * Return the window and context handles.
++ */
++static void
++make_window( Display *dpy, const char *name,
++ int x, int y, int width, int height,
++ Window *winRet, GLXContext *ctxRet, VisualID *visRet)
++{
++ int attribs[64];
++ int i = 0;
++
++ int scrnum;
++ XSetWindowAttributes attr;
++ unsigned long mask;
++ Window root;
++ Window win;
++ GLXContext ctx;
++ XVisualInfo *visinfo;
++
++ /* Singleton attributes. */
++ attribs[i++] = GLX_RGBA;
++ attribs[i++] = GLX_DOUBLEBUFFER;
++ if (stereo)
++ attribs[i++] = GLX_STEREO;
++
++ /* Key/value attributes. */
++ attribs[i++] = GLX_RED_SIZE;
++ attribs[i++] = 1;
++ attribs[i++] = GLX_GREEN_SIZE;
++ attribs[i++] = 1;
++ attribs[i++] = GLX_BLUE_SIZE;
++ attribs[i++] = 1;
++ attribs[i++] = GLX_DEPTH_SIZE;
++ attribs[i++] = 1;
++ if (samples > 0) {
++ attribs[i++] = GLX_SAMPLE_BUFFERS;
++ attribs[i++] = 1;
++ attribs[i++] = GLX_SAMPLES;
++ attribs[i++] = samples;
++ }
++
++ attribs[i++] = None;
++
++ scrnum = DefaultScreen( dpy );
++ root = RootWindow( dpy, scrnum );
++
++ visinfo = glXChooseVisual(dpy, scrnum, attribs);
++ if (!visinfo) {
++ printf("Error: couldn't get an RGB, Double-buffered");
++ if (stereo)
++ printf(", Stereo");
++ if (samples > 0)
++ printf(", Multisample");
++ printf(" visual\n");
++ exit(1);
++ }
++
++ /* window attributes */
++ attr.background_pixel = 0;
++ attr.border_pixel = 0;
++ attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone);
++ attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
++ /* XXX this is a bad way to get a borderless window! */
++ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
++
++ win = XCreateWindow( dpy, root, x, y, width, height,
++ 0, visinfo->depth, InputOutput,
++ visinfo->visual, mask, &attr );
++
++ if (fullscreen)
++ no_border(dpy, win);
++
++ /* set hints and properties */
++ {
++ XSizeHints sizehints;
++ sizehints.x = x;
++ sizehints.y = y;
++ sizehints.width = width;
++ sizehints.height = height;
++ sizehints.flags = USSize | USPosition;
++ XSetNormalHints(dpy, win, &sizehints);
++ XSetStandardProperties(dpy, win, name, name,
++ None, (char **)NULL, 0, &sizehints);
++ }
++
++ ctx = glXCreateContext( dpy, visinfo, NULL, True );
++ if (!ctx) {
++ printf("Error: glXCreateContext failed\n");
++ exit(1);
++ }
++
++ *winRet = win;
++ *ctxRet = ctx;
++ *visRet = visinfo->visualid;
++
++ XFree(visinfo);
++}
++
++
++/**
++ * Determine whether or not a GLX extension is supported.
++ */
++static int
++is_glx_extension_supported(Display *dpy, const char *query)
++{
++ const int scrnum = DefaultScreen(dpy);
++ const char *glx_extensions = NULL;
++ const size_t len = strlen(query);
++ const char *ptr;
++
++ if (glx_extensions == NULL) {
++ glx_extensions = glXQueryExtensionsString(dpy, scrnum);
++ }
++
++ ptr = strstr(glx_extensions, query);
++ return ((ptr != NULL) && ((ptr[len] == ' ') || (ptr[len] == '\0')));
++}
++
++
++/**
++ * Attempt to determine whether or not the display is synched to vblank.
++ */
++static void
++query_vsync(Display *dpy, GLXDrawable drawable)
++{
++ int interval = 0;
++
++#if defined(GLX_EXT_swap_control)
++ if (is_glx_extension_supported(dpy, "GLX_EXT_swap_control")) {
++ unsigned int tmp = -1;
++ glXQueryDrawable(dpy, drawable, GLX_SWAP_INTERVAL_EXT, &tmp);
++ interval = tmp;
++ } else
++#endif
++ if (is_glx_extension_supported(dpy, "GLX_MESA_swap_control")) {
++ PFNGLXGETSWAPINTERVALMESAPROC pglXGetSwapIntervalMESA =
++ (PFNGLXGETSWAPINTERVALMESAPROC)
++ glXGetProcAddressARB((const GLubyte *) "glXGetSwapIntervalMESA");
++
++ interval = (*pglXGetSwapIntervalMESA)();
++ } else if (is_glx_extension_supported(dpy, "GLX_SGI_swap_control")) {
++ /* The default swap interval with this extension is 1. Assume that it
++ * is set to the default.
++ *
++ * Many Mesa-based drivers default to 0, but all of these drivers also
++ * export GLX_MESA_swap_control. In that case, this branch will never
++ * be taken, and the correct result should be reported.
++ */
++ interval = 1;
++ }
++
++
++ if (interval > 0) {
++ printf("Running synchronized to the vertical refresh. The framerate should be\n");
++ if (interval == 1) {
++ printf("approximately the same as the monitor refresh rate.\n");
++ } else if (interval > 1) {
++ printf("approximately 1/%d the monitor refresh rate.\n",
++ interval);
++ }
++ }
++}
++
++/**
++ * Handle one X event.
++ * \return NOP, EXIT or DRAW
++ */
++static int
++handle_event(Display *dpy, Window win, XEvent *event)
++{
++ (void) dpy;
++ (void) win;
++
++ switch (event->type) {
++ case Expose:
++ return DRAW;
++ case ConfigureNotify:
++ reshape(event->xconfigure.width, event->xconfigure.height);
++ break;
++ case KeyPress:
++ {
++ char buffer[10];
++ int code;
++ code = XLookupKeysym(&event->xkey, 0);
++ if (code == XK_Left) {
++ view_roty += 5.0;
++ }
++ else if (code == XK_Right) {
++ view_roty -= 5.0;
++ }
++ else if (code == XK_Up) {
++ view_rotx += 5.0;
++ }
++ else if (code == XK_Down) {
++ view_rotx -= 5.0;
++ }
++ else {
++ XLookupString(&event->xkey, buffer, sizeof(buffer),
++ NULL, NULL);
++ if (buffer[0] == 27) {
++ /* escape */
++ return EXIT;
++ }
++ else if (buffer[0] == 'a' || buffer[0] == 'A') {
++ animate = !animate;
++ }
++ }
++ return DRAW;
++ }
++ }
++ return NOP;
++}
++
++
++static void
++event_loop(Display *dpy, Window win)
++{
++ while (1) {
++ int op;
++ while (!animate || XPending(dpy) > 0) {
++ XEvent event;
++ XNextEvent(dpy, &event);
++ op = handle_event(dpy, win, &event);
++ if (op == EXIT)
++ return;
++ else if (op == DRAW)
++ break;
++ }
++
++ draw_frame(dpy, win);
++ }
++}
++
++
++static void
++usage(void)
++{
++ printf("Usage:\n");
++ printf(" -display <displayname> set the display to run on\n");
++ printf(" -stereo run in stereo mode\n");
++ printf(" -samples N run in multisample mode with at least N samples\n");
++ printf(" -fullscreen run in fullscreen mode\n");
++ printf(" -info display OpenGL renderer info\n");
++ printf(" -geometry WxH+X+Y window geometry\n");
++}
++
++
++int
++main(int argc, char *argv[])
++{
++ unsigned int winWidth = 300, winHeight = 300;
++ int x = 0, y = 0;
++ Display *dpy;
++ Window win;
++ GLXContext ctx;
++ char *dpyName = NULL;
++ GLboolean printInfo = GL_FALSE;
++ VisualID visId;
++ int i;
++
++ for (i = 1; i < argc; i++) {
++ if (strcmp(argv[i], "-display") == 0) {
++ dpyName = argv[i+1];
++ i++;
++ }
++ else if (strcmp(argv[i], "-info") == 0) {
++ printInfo = GL_TRUE;
++ }
++ else if (strcmp(argv[i], "-stereo") == 0) {
++ stereo = GL_TRUE;
++ }
++ else if (i < argc-1 && strcmp(argv[i], "-samples") == 0) {
++ samples = strtod(argv[i+1], NULL );
++ ++i;
++ }
++ else if (strcmp(argv[i], "-fullscreen") == 0) {
++ fullscreen = GL_TRUE;
++ }
++ else if (i < argc-1 && strcmp(argv[i], "-geometry") == 0) {
++ XParseGeometry(argv[i+1], &x, &y, &winWidth, &winHeight);
++ i++;
++ }
++ else {
++ usage();
++ return -1;
++ }
++ }
++
++ dpy = XOpenDisplay(dpyName);
++ if (!dpy) {
++ printf("Error: couldn't open display %s\n",
++ dpyName ? dpyName : getenv("DISPLAY"));
++ return -1;
++ }
++
++ if (fullscreen) {
++ int scrnum = DefaultScreen(dpy);
++
++ x = 0; y = 0;
++ winWidth = DisplayWidth(dpy, scrnum);
++ winHeight = DisplayHeight(dpy, scrnum);
++ }
++
++ make_window(dpy, "glxgears", x, y, winWidth, winHeight, &win, &ctx, &visId);
++ XMapWindow(dpy, win);
++ glXMakeCurrent(dpy, win, ctx);
++ query_vsync(dpy, win);
++
++ if (printInfo) {
++ printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
++ printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
++ printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
++ printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS));
++ printf("VisualID %d, 0x%x\n", (int) visId, (int) visId);
++ }
++
++ init();
++
++ /* Set initial projection/viewing transformation.
++ * We can't be sure we'll get a ConfigureNotify event when the window
++ * first appears.
++ */
++ reshape(winWidth, winHeight);
++
++ event_loop(dpy, win);
++
++ glDeleteLists(gear1, 1);
++ glDeleteLists(gear2, 1);
++ glDeleteLists(gear3, 1);
++ glXMakeCurrent(dpy, None, NULL);
++ glXDestroyContext(dpy, ctx);
++ XDestroyWindow(dpy, win);
++ XCloseDisplay(dpy);
++
++ return 0;
++}
+diff -Naurp mesa-20.2.1-orig/src/glx/xdemos/glxinfo.1 mesa-20.2.1/src/glx/xdemos/glxinfo.1
+--- mesa-20.2.1-orig/src/glx/xdemos/glxinfo.1 1969-12-31 18:00:00.000000000 -0600
++++ mesa-20.2.1/src/glx/xdemos/glxinfo.1 2020-10-15 23:06:45.826695773 -0500
+@@ -0,0 +1,46 @@
++.TH glxinfo 1 "2006-11-29"
++.SH NAME
++glxinfo \- show information about the GLX implementation
++.SH SYNOPSIS
++.B glxinfo
++.RI [ options ]
++.SH DESCRIPTION
++The \fIglxinfo\fP program shows information about the OpenGL and GLX
++implementations running on a given X display.
++.PP
++The information includes details about the server- and client-side GLX
++implementation, the OpenGL and GLU implementations as well as a list
++of available GLX visuals.
++.SH OPTIONS
++.TP 8
++.B \-v
++Print visuals info in verbose form.
++.TP 8
++.B \-t
++Print verbose table.
++.TP 8
++.B \-display \fIdisplay\fP
++Specify the X display to interrogate.
++.TP 8
++.B \-h
++Print usage information.
++.TP 8
++.B \-i
++Force an indirect rendering context.
++.TP 8
++.B \-b
++Find the "best" visual and print its number.
++.TP 8
++.B \-l
++Print interesting OpenGL limits.
++.TP 8
++.B \-s
++Print a single extension per line.
++.SH AUTHOR
++glxinfo was written by Brian Paul <brian.paul@tungstengraphics.com>.
++.PP
++This manual page was written by Thierry Reding <thierry@gilfi.de>, for the
++Debian project and updated by Fernando de Oliveira <famobr at yahoo dot
++com dot br>, for the Linux From Scratch (LFS) project (but may be used by
++others).
++
+diff -Naurp mesa-20.2.1-orig/src/glx/xdemos/glxinfo.c mesa-20.2.1/src/glx/xdemos/glxinfo.c
+--- mesa-20.2.1-orig/src/glx/xdemos/glxinfo.c 1969-12-31 18:00:00.000000000 -0600
++++ mesa-20.2.1/src/glx/xdemos/glxinfo.c 2020-10-15 23:06:45.826695773 -0500
+@@ -0,0 +1,1281 @@
++/*
++ * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
++ *
++ * Permission is hereby granted, free of charge, to any person obtaining a
++ * copy of this software and associated documentation files (the "Software"),
++ * to deal in the Software without restriction, including without limitation
++ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
++ * and/or sell copies of the Software, and to permit persons to whom the
++ * Software is furnished to do so, subject to the following conditions:
++ *
++ * The above copyright notice and this permission notice shall be included
++ * in all copies or substantial portions of the Software.
++ *
++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
++ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
++ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
++ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
++ */
++
++
++/*
++ * This program is a work-alike of the IRIX glxinfo program.
++ * Command line options:
++ * -t print wide table
++ * -v print verbose information
++ * -display DisplayName specify the X display to interogate
++ * -B brief, print only the basics
++ * -b only print ID of "best" visual on screen 0
++ * -i use indirect rendering connection only
++ * -l print interesting OpenGL limits (added 5 Sep 2002)
++ *
++ * Brian Paul 26 January 2000
++ */
++
++#define GLX_GLXEXT_PROTOTYPES
++#define GL_GLEXT_PROTOTYPES
++
++#include <assert.h>
++#include <X11/Xlib.h>
++#include <X11/Xutil.h>
++#include <GL/gl.h>
++#include <GL/glx.h>
++#include <stdio.h>
++#include <string.h>
++#include <stdlib.h>
++#include "glinfo_common.h"
++
++
++#ifndef GLX_NONE_EXT
++#define GLX_NONE_EXT 0x8000
++#endif
++
++#ifndef GLX_TRANSPARENT_RGB
++#define GLX_TRANSPARENT_RGB 0x8008
++#endif
++
++#ifndef GLX_RGBA_BIT
++#define GLX_RGBA_BIT 0x00000001
++#endif
++
++#ifndef GLX_COLOR_INDEX_BIT
++#define GLX_COLOR_INDEX_BIT 0x00000002
++#endif
++
++
++struct visual_attribs
++{
++ /* X visual attribs */
++ int id; /* May be visual ID or FBConfig ID */
++ int vis_id; /* Visual ID. Only set for FBConfigs */
++ int klass;
++ int depth;
++ int redMask, greenMask, blueMask;
++ int colormapSize;
++ int bitsPerRGB;
++
++ /* GL visual attribs */
++ int supportsGL;
++ int drawableType;
++ int transparentType;
++ int transparentRedValue;
++ int transparentGreenValue;
++ int transparentBlueValue;
++ int transparentAlphaValue;
++ int transparentIndexValue;
++ int bufferSize;
++ int level;
++ int render_type;
++ int doubleBuffer;
++ int stereo;
++ int auxBuffers;
++ int redSize, greenSize, blueSize, alphaSize;
++ int depthSize;
++ int stencilSize;
++ int accumRedSize, accumGreenSize, accumBlueSize, accumAlphaSize;
++ int numSamples, numMultisample;
++ int visualCaveat;
++ int floatComponents;
++ int packedfloatComponents;
++ int srgb;
++};
++
++
++/**
++ * Version of the context that was created
++ *
++ * 20, 21, 30, 31, 32, etc.
++ */
++static int version;
++
++/**
++ * GL Error checking/warning.
++ */
++static void
++CheckError(int line)
++{
++ int n;
++ n = glGetError();
++ if (n)
++ printf("Warning: GL error 0x%x at line %d\n", n, line);
++}
++
++
++static void
++print_display_info(Display *dpy)
++{
++ printf("name of display: %s\n", DisplayString(dpy));
++}
++
++
++/**
++ * Choose a simple FB Config.
++ */
++static GLXFBConfig *
++choose_fb_config(Display *dpy, int scrnum)
++{
++ int fbAttribSingle[] = {
++ GLX_RENDER_TYPE, GLX_RGBA_BIT,
++ GLX_RED_SIZE, 1,
++ GLX_GREEN_SIZE, 1,
++ GLX_BLUE_SIZE, 1,
++ GLX_DOUBLEBUFFER, False,
++ None };
++ int fbAttribDouble[] = {
++ GLX_RENDER_TYPE, GLX_RGBA_BIT,
++ GLX_RED_SIZE, 1,
++ GLX_GREEN_SIZE, 1,
++ GLX_BLUE_SIZE, 1,
++ GLX_DOUBLEBUFFER, True,
++ None };
++ GLXFBConfig *configs;
++ int nConfigs;
++
++ configs = glXChooseFBConfig(dpy, scrnum, fbAttribSingle, &nConfigs);
++ if (!configs)
++ configs = glXChooseFBConfig(dpy, scrnum, fbAttribDouble, &nConfigs);
++
++ return configs;
++}
++
++
++static Bool CreateContextErrorFlag;
++
++static int
++create_context_error_handler(Display *dpy, XErrorEvent *error)
++{
++ (void) dpy;
++ (void) error->error_code;
++ CreateContextErrorFlag = True;
++ return 0;
++}
++
++
++/**
++ * Try to create a GLX context of the given version with flags/options.
++ * Note: A version number is required in order to get a core profile
++ * (at least w/ NVIDIA).
++ */
++static GLXContext
++create_context_flags(Display *dpy, GLXFBConfig fbconfig, int major, int minor,
++ int contextFlags, int profileMask, Bool direct)
++{
++#ifdef GLX_ARB_create_context
++ static PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB_func = 0;
++ static Bool firstCall = True;
++ int (*old_handler)(Display *, XErrorEvent *);
++ GLXContext context;
++ int attribs[20];
++ int n = 0;
++
++ if (firstCall) {
++ /* See if we have GLX_ARB_create_context_profile and get pointer to
++ * glXCreateContextAttribsARB() function.
++ */
++ const char *glxExt = glXQueryExtensionsString(dpy, 0);
++ if (extension_supported("GLX_ARB_create_context_profile", glxExt)) {
++ glXCreateContextAttribsARB_func = (PFNGLXCREATECONTEXTATTRIBSARBPROC)
++ glXGetProcAddress((const GLubyte *) "glXCreateContextAttribsARB");
++ }
++ firstCall = False;
++ }
++
++ if (!glXCreateContextAttribsARB_func)
++ return 0;
++
++ /* setup attribute array */
++ if (major) {
++ attribs[n++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
++ attribs[n++] = major;
++ attribs[n++] = GLX_CONTEXT_MINOR_VERSION_ARB;
++ attribs[n++] = minor;
++ }
++ if (contextFlags) {
++ attribs[n++] = GLX_CONTEXT_FLAGS_ARB;
++ attribs[n++] = contextFlags;
++ }
++#ifdef GLX_ARB_create_context_profile
++ if (profileMask) {
++ attribs[n++] = GLX_CONTEXT_PROFILE_MASK_ARB;
++ attribs[n++] = profileMask;
++ }
++#endif
++ attribs[n++] = 0;
++
++ /* install X error handler */
++ old_handler = XSetErrorHandler(create_context_error_handler);
++ CreateContextErrorFlag = False;
++
++ /* try creating context */
++ context = glXCreateContextAttribsARB_func(dpy,
++ fbconfig,
++ 0, /* share_context */
++ direct,
++ attribs);
++
++ /* restore error handler */
++ XSetErrorHandler(old_handler);
++
++ if (CreateContextErrorFlag)
++ context = 0;
++
++ if (context && direct) {
++ if (!glXIsDirect(dpy, context)) {
++ glXDestroyContext(dpy, context);
++ return 0;
++ }
++ }
++
++ return context;
++#else
++ return 0;
++#endif
++}
++
++
++/**
++ * Try to create a GLX context of the newest version.
++ */
++static GLXContext
++create_context_with_config(Display *dpy, GLXFBConfig config,
++ Bool coreProfile, Bool es2Profile, Bool direct)
++{
++ GLXContext ctx = 0;
++
++ if (coreProfile) {
++ /* Try to create a core profile, starting with the newest version of
++ * GL that we're aware of. If we don't specify the version
++ */
++ int i;
++ for (i = 0; gl_versions[i].major > 0; i++) {
++ /* don't bother below GL 3.0 */
++ if (gl_versions[i].major == 3 &&
++ gl_versions[i].minor == 0)
++ return 0;
++ ctx = create_context_flags(dpy, config,
++ gl_versions[i].major,
++ gl_versions[i].minor,
++ 0x0,
++ GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
++ direct);
++ if (ctx)
++ return ctx;
++ }
++ /* couldn't get core profile context */
++ return 0;
++ }
++
++ if (es2Profile) {
++#ifdef GLX_CONTEXT_ES2_PROFILE_BIT_EXT
++ if (extension_supported("GLX_EXT_create_context_es2_profile",
++ glXQueryExtensionsString(dpy, 0))) {
++ ctx = create_context_flags(dpy, config, 2, 0, 0x0,
++ GLX_CONTEXT_ES2_PROFILE_BIT_EXT,
++ direct);
++ return ctx;
++ }
++#endif
++ return 0;
++ }
++
++ /* GLX should return a context of the latest GL version that supports
++ * the full profile.
++ */
++ ctx = glXCreateNewContext(dpy, config, GLX_RGBA_TYPE, NULL, direct);
++
++ /* make sure the context is direct, if direct was requested */
++ if (ctx && direct) {
++ if (!glXIsDirect(dpy, ctx)) {
++ glXDestroyContext(dpy, ctx);
++ return 0;
++ }
++ }
++
++ return ctx;
++}
++
++
++static XVisualInfo *
++choose_xvisinfo(Display *dpy, int scrnum)
++{
++ int attribSingle[] = {
++ GLX_RGBA,
++ GLX_RED_SIZE, 1,
++ GLX_GREEN_SIZE, 1,
++ GLX_BLUE_SIZE, 1,
++ None };
++ int attribDouble[] = {
++ GLX_RGBA,
++ GLX_RED_SIZE, 1,
++ GLX_GREEN_SIZE, 1,
++ GLX_BLUE_SIZE, 1,
++ GLX_DOUBLEBUFFER,
++ None };
++ XVisualInfo *visinfo;
++
++ visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
++ if (!visinfo)
++ visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
++
++ return visinfo;
++}
++
++
++static void
++query_renderer(void)
++{
++#ifdef GLX_MESA_query_renderer
++ PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC queryInteger;
++ PFNGLXQUERYCURRENTRENDERERSTRINGMESAPROC queryString;
++ unsigned int v[3];
++
++ queryInteger = (PFNGLXQUERYCURRENTRENDERERINTEGERMESAPROC)
++ glXGetProcAddressARB((const GLubyte *)
++ "glXQueryCurrentRendererIntegerMESA");
++ queryString = (PFNGLXQUERYCURRENTRENDERERSTRINGMESAPROC)
++ glXGetProcAddressARB((const GLubyte *)
++ "glXQueryCurrentRendererStringMESA");
++
++ printf("Extended renderer info (GLX_MESA_query_renderer):\n");
++ queryInteger(GLX_RENDERER_VENDOR_ID_MESA, v);
++ printf(" Vendor: %s (0x%x)\n",
++ queryString(GLX_RENDERER_VENDOR_ID_MESA), *v);
++ queryInteger(GLX_RENDERER_DEVICE_ID_MESA, v);
++ printf(" Device: %s (0x%x)\n",
++ queryString(GLX_RENDERER_DEVICE_ID_MESA), *v);
++ queryInteger(GLX_RENDERER_VERSION_MESA, v);
++ printf(" Version: %d.%d.%d\n", v[0], v[1], v[2]);
++ queryInteger(GLX_RENDERER_ACCELERATED_MESA, v);
++ printf(" Accelerated: %s\n", *v ? "yes" : "no");
++ queryInteger(GLX_RENDERER_VIDEO_MEMORY_MESA, v);
++ printf(" Video memory: %dMB\n", *v);
++ queryInteger(GLX_RENDERER_UNIFIED_MEMORY_ARCHITECTURE_MESA, v);
++ printf(" Unified memory: %s\n", *v ? "yes" : "no");
++ queryInteger(GLX_RENDERER_PREFERRED_PROFILE_MESA, v);
++ printf(" Preferred profile: %s (0x%x)\n",
++ *v == GLX_CONTEXT_CORE_PROFILE_BIT_ARB ? "core" :
++ *v == GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB ? "compat" :
++ "unknown", *v);
++ queryInteger(GLX_RENDERER_OPENGL_CORE_PROFILE_VERSION_MESA, v);
++ printf(" Max core profile version: %d.%d\n", v[0], v[1]);
++ queryInteger(GLX_RENDERER_OPENGL_COMPATIBILITY_PROFILE_VERSION_MESA, v);
++ printf(" Max compat profile version: %d.%d\n", v[0], v[1]);
++ queryInteger(GLX_RENDERER_OPENGL_ES_PROFILE_VERSION_MESA, v);
++ printf(" Max GLES1 profile version: %d.%d\n", v[0], v[1]);
++ queryInteger(GLX_RENDERER_OPENGL_ES2_PROFILE_VERSION_MESA, v);
++ printf(" Max GLES[23] profile version: %d.%d\n", v[0], v[1]);
++#endif
++}
++
++
++static Bool
++print_screen_info(Display *dpy, int scrnum,
++ const struct options *opts,
++ Bool coreProfile, Bool es2Profile, Bool limits,
++ Bool coreWorked)
++{
++ Window win;
++ XSetWindowAttributes attr;
++ unsigned long mask;
++ Window root;
++ GLXContext ctx = NULL;
++ XVisualInfo *visinfo;
++ int width = 100, height = 100;
++ GLXFBConfig *fbconfigs;
++ const char *oglstring = coreProfile ? "OpenGL core profile" :
++ es2Profile ? "OpenGL ES profile" : "OpenGL";
++
++ root = RootWindow(dpy, scrnum);
++
++ /*
++ * Choose FBConfig or XVisualInfo and create a context.
++ */
++ fbconfigs = choose_fb_config(dpy, scrnum);
++ if (fbconfigs) {
++ ctx = create_context_with_config(dpy, fbconfigs[0],
++ coreProfile, es2Profile,
++ opts->allowDirect);
++ if (!ctx && opts->allowDirect && !coreProfile) {
++ /* try indirect */
++ ctx = create_context_with_config(dpy, fbconfigs[0],
++ coreProfile, es2Profile, False);
++ }
++
++ visinfo = glXGetVisualFromFBConfig(dpy, fbconfigs[0]);
++ XFree(fbconfigs);
++ }
++ else if (!coreProfile && !es2Profile) {
++ visinfo = choose_xvisinfo(dpy, scrnum);
++ if (visinfo)
++ ctx = glXCreateContext(dpy, visinfo, NULL, opts->allowDirect);
++ } else
++ visinfo = NULL;
++
++ if (!visinfo && !coreProfile && !es2Profile) {
++ fprintf(stderr, "Error: couldn't find RGB GLX visual or fbconfig\n");
++ return False;
++ }
++
++ if (!ctx) {
++ if (!coreProfile && !es2Profile)
++ fprintf(stderr, "Error: glXCreateContext failed\n");
++ XFree(visinfo);
++ return False;
++ }
++
++ /*
++ * Create a window so that we can just bind the context.
++ */
++ attr.background_pixel = 0;
++ attr.border_pixel = 0;
++ attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
++ attr.event_mask = StructureNotifyMask | ExposureMask;
++ mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
++ win = XCreateWindow(dpy, root, 0, 0, width, height,
++ 0, visinfo->depth, InputOutput,
++ visinfo->visual, mask, &attr);
++
++ if (glXMakeCurrent(dpy, win, ctx)) {
++ const char *serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
++ const char *serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
++ const char *serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
++ const char *clientVendor = glXGetClientString(dpy, GLX_VENDOR);
++ const char *clientVersion = glXGetClientString(dpy, GLX_VERSION);
++ const char *clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
++ const char *glxExtensions = glXQueryExtensionsString(dpy, scrnum);
++ const char *glVendor = (const char *) glGetString(GL_VENDOR);
++ const char *glRenderer = (const char *) glGetString(GL_RENDERER);
++ const char *glVersion = (const char *) glGetString(GL_VERSION);
++ char *glExtensions = NULL;
++ int glxVersionMajor = 0;
++ int glxVersionMinor = 0;
++ char *displayName = NULL;
++ char *colon = NULL, *period = NULL;
++ struct ext_functions extfuncs;
++
++ CheckError(__LINE__);
++
++ /* Get some ext functions */
++ extfuncs.GetProgramivARB = (GETPROGRAMIVARBPROC)
++ glXGetProcAddressARB((GLubyte *) "glGetProgramivARB");
++ extfuncs.GetStringi = (GETSTRINGIPROC)
++ glXGetProcAddressARB((GLubyte *) "glGetStringi");
++ extfuncs.GetConvolutionParameteriv = (GETCONVOLUTIONPARAMETERIVPROC)
++ glXGetProcAddressARB((GLubyte *) "glGetConvolutionParameteriv");
++
++ if (!glXQueryVersion(dpy, & glxVersionMajor, & glxVersionMinor)) {
++ fprintf(stderr, "Error: glXQueryVersion failed\n");
++ exit(1);
++ }
++
++ /* Get list of GL extensions */
++ if (coreProfile && extfuncs.GetStringi)
++ glExtensions = build_core_profile_extension_list(&extfuncs);
++ if (!glExtensions) {
++ coreProfile = False;
++ glExtensions = (char *) glGetString(GL_EXTENSIONS);
++ }
++
++ CheckError(__LINE__);
++
++ if (!coreWorked) {
++ /* Strip the screen number from the display name, if present. */
++ if (!(displayName = (char *) malloc(strlen(DisplayString(dpy)) + 1))) {
++ fprintf(stderr, "Error: malloc() failed\n");
++ exit(1);
++ }
++ strcpy(displayName, DisplayString(dpy));
++ colon = strrchr(displayName, ':');
++ if (colon) {
++ period = strchr(colon, '.');
++ if (period)
++ *period = '\0';
++ }
++
++ printf("display: %s screen: %d\n", displayName, scrnum);
++ free(displayName);
++ printf("direct rendering: ");
++ if (glXIsDirect(dpy, ctx)) {
++ printf("Yes\n");
++ }
++ else {
++ if (!opts->allowDirect) {
++ printf("No (-i specified)\n");
++ }
++ else if (getenv("LIBGL_ALWAYS_INDIRECT")) {
++ printf("No (LIBGL_ALWAYS_INDIRECT set)\n");
++ }
++ else {
++ printf("No (If you want to find out why, try setting "
++ "LIBGL_DEBUG=verbose)\n");
++ }
++ }
++ if (opts->mode != Brief) {
++ printf("server glx vendor string: %s\n", serverVendor);
++ printf("server glx version string: %s\n", serverVersion);
++ printf("server glx extensions:\n");
++ print_extension_list(serverExtensions, opts->singleLine);
++ printf("client glx vendor string: %s\n", clientVendor);
++ printf("client glx version string: %s\n", clientVersion);
++ printf("client glx extensions:\n");
++ print_extension_list(clientExtensions, opts->singleLine);
++ printf("GLX version: %u.%u\n", glxVersionMajor, glxVersionMinor);
++ printf("GLX extensions:\n");
++ print_extension_list(glxExtensions, opts->singleLine);
++ }
++ if (strstr(glxExtensions, "GLX_MESA_query_renderer"))
++ query_renderer();
++ printf("OpenGL vendor string: %s\n", glVendor);
++ printf("OpenGL renderer string: %s\n", glRenderer);
++ } else
++ printf("\n");
++
++ printf("%s version string: %s\n", oglstring, glVersion);
++
++ version = (glVersion[0] - '0') * 10 + (glVersion[2] - '0');
++
++ CheckError(__LINE__);
++
++#ifdef GL_VERSION_2_0
++ if (version >= 20) {
++ char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
++ printf("%s shading language version string: %s\n", oglstring, v);
++ }
++#endif
++ CheckError(__LINE__);
++#ifdef GL_VERSION_3_0
++ if (version >= 30 && !es2Profile) {
++ GLint flags;
++ glGetIntegerv(GL_CONTEXT_FLAGS, &flags);
++ printf("%s context flags: %s\n", oglstring, context_flags_string(flags));
++ }
++#endif
++ CheckError(__LINE__);
++#ifdef GL_VERSION_3_2
++ if (version >= 32 && !es2Profile) {
++ GLint mask;
++ glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
++ printf("%s profile mask: %s\n", oglstring, profile_mask_string(mask));
++ }
++#endif
++
++ CheckError(__LINE__);
++
++ if (opts->mode != Brief) {
++ printf("%s extensions:\n", oglstring);
++ print_extension_list(glExtensions, opts->singleLine);
++ }
++
++ if (limits) {
++ print_limits(glExtensions, oglstring, version, &extfuncs);
++ }
++
++ if (coreProfile)
++ free(glExtensions);
++ }
++ else {
++ fprintf(stderr, "Error: glXMakeCurrent failed\n");
++ }
++
++ glXDestroyContext(dpy, ctx);
++ XFree(visinfo);
++ XDestroyWindow(dpy, win);
++ XSync(dpy, 1);
++ return True;
++}
++
++
++static const char *
++visual_class_name(int cls)
++{
++ switch (cls) {
++ case StaticColor:
++ return "StaticColor";
++ case PseudoColor:
++ return "PseudoColor";
++ case StaticGray:
++ return "StaticGray";
++ case GrayScale:
++ return "GrayScale";
++ case TrueColor:
++ return "TrueColor";
++ case DirectColor:
++ return "DirectColor";
++ default:
++ return "";
++ }
++}
++
++static const char *
++visual_drawable_type(int type)
++{
++ const static struct bit_info bits[] = {
++ { GLX_WINDOW_BIT, "window" },
++ { GLX_PIXMAP_BIT, "pixmap" },
++ { GLX_PBUFFER_BIT, "pbuffer" }
++ };
++
++ return bitmask_to_string(bits, ELEMENTS(bits), type);
++}
++
++static const char *
++visual_class_abbrev(int cls)
++{
++ switch (cls) {
++ case StaticColor:
++ return "sc";
++ case PseudoColor:
++ return "pc";
++ case StaticGray:
++ return "sg";
++ case GrayScale:
++ return "gs";
++ case TrueColor:
++ return "tc";
++ case DirectColor:
++ return "dc";
++ default:
++ return "";
++ }
++}
++
++static const char *
++visual_render_type_name(int type)
++{
++ switch (type) {
++ case GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT:
++ return "ufloat";
++ case GLX_RGBA_FLOAT_BIT_ARB:
++ return "float";
++ case GLX_RGBA_BIT:
++ return "rgba";
++ case GLX_COLOR_INDEX_BIT:
++ return "ci";
++ case GLX_RGBA_BIT | GLX_COLOR_INDEX_BIT:
++ return "rgba|ci";
++ default:
++ return "";
++ }
++}
++
++static const char *
++caveat_string(int caveat)
++{
++ switch (caveat) {
++#ifdef GLX_EXT_visual_rating
++ case GLX_SLOW_VISUAL_EXT:
++ return "Slow";
++ case GLX_NON_CONFORMANT_VISUAL_EXT:
++ return "Ncon";
++ case GLX_NONE_EXT:
++ /* fall-through */
++#endif
++ case 0:
++ /* fall-through */
++ default:
++ return "None";
++ }
++}
++
++
++static Bool
++get_visual_attribs(Display *dpy, XVisualInfo *vInfo,
++ struct visual_attribs *attribs)
++{
++ const char *ext = glXQueryExtensionsString(dpy, vInfo->screen);
++ int rgba;
++
++ memset(attribs, 0, sizeof(struct visual_attribs));
++
++ attribs->id = vInfo->visualid;
++#if defined(__cplusplus) || defined(c_plusplus)
++ attribs->klass = vInfo->c_class;
++#else
++ attribs->klass = vInfo->class;
++#endif
++ attribs->depth = vInfo->depth;
++ attribs->redMask = vInfo->red_mask;
++ attribs->greenMask = vInfo->green_mask;
++ attribs->blueMask = vInfo->blue_mask;
++ attribs->colormapSize = vInfo->colormap_size;
++ attribs->bitsPerRGB = vInfo->bits_per_rgb;
++
++ if (glXGetConfig(dpy, vInfo, GLX_USE_GL, &attribs->supportsGL) != 0 ||
++ !attribs->supportsGL)
++ return False;
++ glXGetConfig(dpy, vInfo, GLX_BUFFER_SIZE, &attribs->bufferSize);
++ glXGetConfig(dpy, vInfo, GLX_LEVEL, &attribs->level);
++ glXGetConfig(dpy, vInfo, GLX_RGBA, &rgba);
++ if (rgba)
++ attribs->render_type = GLX_RGBA_BIT;
++ else
++ attribs->render_type = GLX_COLOR_INDEX_BIT;
++
++ glXGetConfig(dpy, vInfo, GLX_DRAWABLE_TYPE, &attribs->drawableType);
++ glXGetConfig(dpy, vInfo, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
++ glXGetConfig(dpy, vInfo, GLX_STEREO, &attribs->stereo);
++ glXGetConfig(dpy, vInfo, GLX_AUX_BUFFERS, &attribs->auxBuffers);
++ glXGetConfig(dpy, vInfo, GLX_RED_SIZE, &attribs->redSize);
++ glXGetConfig(dpy, vInfo, GLX_GREEN_SIZE, &attribs->greenSize);
++ glXGetConfig(dpy, vInfo, GLX_BLUE_SIZE, &attribs->blueSize);
++ glXGetConfig(dpy, vInfo, GLX_ALPHA_SIZE, &attribs->alphaSize);
++ glXGetConfig(dpy, vInfo, GLX_DEPTH_SIZE, &attribs->depthSize);
++ glXGetConfig(dpy, vInfo, GLX_STENCIL_SIZE, &attribs->stencilSize);
++ glXGetConfig(dpy, vInfo, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
++ glXGetConfig(dpy, vInfo, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
++ glXGetConfig(dpy, vInfo, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
++ glXGetConfig(dpy, vInfo, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
++
++ /* get transparent pixel stuff */
++ glXGetConfig(dpy, vInfo,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
++ if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
++ glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
++ glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
++ glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
++ glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
++ }
++ else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
++ glXGetConfig(dpy, vInfo, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
++ }
++
++ /* multisample attribs */
++#ifdef GLX_ARB_multisample
++ if (ext && strstr(ext, "GLX_ARB_multisample")) {
++ glXGetConfig(dpy, vInfo, GLX_SAMPLE_BUFFERS_ARB, &attribs->numMultisample);
++ glXGetConfig(dpy, vInfo, GLX_SAMPLES_ARB, &attribs->numSamples);
++ }
++#endif
++ else {
++ attribs->numSamples = 0;
++ attribs->numMultisample = 0;
++ }
++
++#if defined(GLX_EXT_visual_rating)
++ if (ext && strstr(ext, "GLX_EXT_visual_rating")) {
++ glXGetConfig(dpy, vInfo, GLX_VISUAL_CAVEAT_EXT, &attribs->visualCaveat);
++ }
++ else {
++ attribs->visualCaveat = GLX_NONE_EXT;
++ }
++#else
++ attribs->visualCaveat = 0;
++#endif
++
++#if defined(GLX_EXT_framebuffer_sRGB)
++ if (ext && strstr(ext, "GLX_EXT_framebuffer_sRGB")) {
++ glXGetConfig(dpy, vInfo, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, &attribs->srgb);
++ }
++#endif
++
++ return True;
++}
++
++#ifdef GLX_VERSION_1_3
++
++static int
++glx_token_to_visual_class(int visual_type)
++{
++ switch (visual_type) {
++ case GLX_TRUE_COLOR:
++ return TrueColor;
++ case GLX_DIRECT_COLOR:
++ return DirectColor;
++ case GLX_PSEUDO_COLOR:
++ return PseudoColor;
++ case GLX_STATIC_COLOR:
++ return StaticColor;
++ case GLX_GRAY_SCALE:
++ return GrayScale;
++ case GLX_STATIC_GRAY:
++ return StaticGray;
++ case GLX_NONE:
++ default:
++ return None;
++ }
++}
++
++static Bool
++get_fbconfig_attribs(Display *dpy, GLXFBConfig fbconfig,
++ struct visual_attribs *attribs)
++{
++ const char *ext = glXQueryExtensionsString(dpy, 0);
++ int visual_type;
++ XVisualInfo *vInfo;
++
++ memset(attribs, 0, sizeof(struct visual_attribs));
++
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_FBCONFIG_ID, &attribs->id);
++
++ vInfo = glXGetVisualFromFBConfig(dpy, fbconfig);
++
++ if (vInfo != NULL) {
++ attribs->vis_id = vInfo->visualid;
++ attribs->depth = vInfo->depth;
++ attribs->redMask = vInfo->red_mask;
++ attribs->greenMask = vInfo->green_mask;
++ attribs->blueMask = vInfo->blue_mask;
++ attribs->colormapSize = vInfo->colormap_size;
++ attribs->bitsPerRGB = vInfo->bits_per_rgb;
++ }
++
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_X_VISUAL_TYPE, &visual_type);
++ attribs->klass = glx_token_to_visual_class(visual_type);
++
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_DRAWABLE_TYPE, &attribs->drawableType);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_BUFFER_SIZE, &attribs->bufferSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_LEVEL, &attribs->level);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_RENDER_TYPE, &attribs->render_type);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_DOUBLEBUFFER, &attribs->doubleBuffer);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_STEREO, &attribs->stereo);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_AUX_BUFFERS, &attribs->auxBuffers);
++
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_RED_SIZE, &attribs->redSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_GREEN_SIZE, &attribs->greenSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_BLUE_SIZE, &attribs->blueSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ALPHA_SIZE, &attribs->alphaSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_DEPTH_SIZE, &attribs->depthSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_STENCIL_SIZE, &attribs->stencilSize);
++
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_RED_SIZE, &attribs->accumRedSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_GREEN_SIZE, &attribs->accumGreenSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_BLUE_SIZE, &attribs->accumBlueSize);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_ACCUM_ALPHA_SIZE, &attribs->accumAlphaSize);
++
++ /* get transparent pixel stuff */
++ glXGetFBConfigAttrib(dpy, fbconfig,GLX_TRANSPARENT_TYPE, &attribs->transparentType);
++ if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_RED_VALUE, &attribs->transparentRedValue);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_GREEN_VALUE, &attribs->transparentGreenValue);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_BLUE_VALUE, &attribs->transparentBlueValue);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_ALPHA_VALUE, &attribs->transparentAlphaValue);
++ }
++ else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_TRANSPARENT_INDEX_VALUE, &attribs->transparentIndexValue);
++ }
++
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLE_BUFFERS, &attribs->numMultisample);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_SAMPLES, &attribs->numSamples);
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_CONFIG_CAVEAT, &attribs->visualCaveat);
++
++#if defined(GLX_NV_float_buffer)
++ if (ext && strstr(ext, "GLX_NV_float_buffer")) {
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_FLOAT_COMPONENTS_NV, &attribs->floatComponents);
++ }
++#endif
++#if defined(GLX_ARB_fbconfig_float)
++ if (ext && strstr(ext, "GLX_ARB_fbconfig_float")) {
++ if (attribs->render_type & GLX_RGBA_FLOAT_BIT_ARB) {
++ attribs->floatComponents = True;
++ }
++ }
++#endif
++#if defined(GLX_EXT_fbconfig_packed_float)
++ if (ext && strstr(ext, "GLX_EXT_fbconfig_packed_float")) {
++ if (attribs->render_type & GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT) {
++ attribs->packedfloatComponents = True;
++ }
++ }
++#endif
++
++#if defined(GLX_EXT_framebuffer_sRGB)
++ if (ext && strstr(ext, "GLX_EXT_framebuffer_sRGB")) {
++ glXGetFBConfigAttrib(dpy, fbconfig, GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT, &attribs->srgb);
++ }
++#endif
++ return True;
++}
++
++#endif
++
++
++
++static void
++print_visual_attribs_verbose(const struct visual_attribs *attribs,
++ int fbconfigs)
++{
++ if (fbconfigs) {
++ printf("FBConfig ID: %x Visual ID=%x depth=%d class=%s, type=%s\n",
++ attribs->id, attribs->vis_id, attribs->depth,
++ visual_class_name(attribs->klass),
++ visual_drawable_type(attribs->drawableType));
++ }
++ else {
++ printf("Visual ID: %x depth=%d class=%s, type=%s\n",
++ attribs->id, attribs->depth, visual_class_name(attribs->klass),
++ visual_drawable_type(attribs->drawableType));
++ }
++ printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n",
++ attribs->bufferSize, attribs->level,
++ visual_render_type_name(attribs->render_type),
++ attribs->doubleBuffer, attribs->stereo);
++ printf(" rgba: redSize=%d greenSize=%d blueSize=%d alphaSize=%d float=%c sRGB=%c\n",
++ attribs->redSize, attribs->greenSize,
++ attribs->blueSize, attribs->alphaSize,
++ attribs->packedfloatComponents ? 'P' : attribs->floatComponents ? 'Y' : 'N',
++ attribs->srgb ? 'Y' : 'N');
++ printf(" auxBuffers=%d depthSize=%d stencilSize=%d\n",
++ attribs->auxBuffers, attribs->depthSize, attribs->stencilSize);
++ printf(" accum: redSize=%d greenSize=%d blueSize=%d alphaSize=%d\n",
++ attribs->accumRedSize, attribs->accumGreenSize,
++ attribs->accumBlueSize, attribs->accumAlphaSize);
++ printf(" multiSample=%d multiSampleBuffers=%d\n",
++ attribs->numSamples, attribs->numMultisample);
++#ifdef GLX_EXT_visual_rating
++ if (attribs->visualCaveat == GLX_NONE_EXT || attribs->visualCaveat == 0)
++ printf(" visualCaveat=None\n");
++ else if (attribs->visualCaveat == GLX_SLOW_VISUAL_EXT)
++ printf(" visualCaveat=Slow\n");
++ else if (attribs->visualCaveat == GLX_NON_CONFORMANT_VISUAL_EXT)
++ printf(" visualCaveat=Nonconformant\n");
++#endif
++ if (attribs->transparentType == GLX_NONE) {
++ printf(" Opaque.\n");
++ }
++ else if (attribs->transparentType == GLX_TRANSPARENT_RGB) {
++ printf(" Transparent RGB: Red=%d Green=%d Blue=%d Alpha=%d\n",attribs->transparentRedValue,attribs->transparentGreenValue,attribs->transparentBlueValue,attribs->transparentAlphaValue);
++ }
++ else if (attribs->transparentType == GLX_TRANSPARENT_INDEX) {
++ printf(" Transparent index=%d\n",attribs->transparentIndexValue);
++ }
++}
++
++
++static void
++print_visual_attribs_short_header(void)
++{
++ printf(" visual x bf lv rg d st colorbuffer sr ax dp st accumbuffer ms cav\n");
++ printf(" id dep cl sp sz l ci b ro r g b a F gb bf th cl r g b a ns b eat\n");
++ printf("----------------------------------------------------------------------------\n");
++}
++
++
++static void
++print_visual_attribs_short(const struct visual_attribs *attribs)
++{
++ const char *caveat = caveat_string(attribs->visualCaveat);
++
++ printf("0x%03x %2d %2s %2d %3d %2d %c%c %c %c %2d %2d %2d %2d %c %c %2d %2d %2d",
++ attribs->id,
++ attribs->depth,
++ visual_class_abbrev(attribs->klass),
++ attribs->transparentType != GLX_NONE,
++ attribs->bufferSize,
++ attribs->level,
++ (attribs->render_type & GLX_RGBA_BIT) ? 'r' : ' ',
++ (attribs->render_type & GLX_COLOR_INDEX_BIT) ? 'c' : ' ',
++ attribs->doubleBuffer ? 'y' : '.',
++ attribs->stereo ? 'y' : '.',
++ attribs->redSize, attribs->greenSize,
++ attribs->blueSize, attribs->alphaSize,
++ attribs->packedfloatComponents ? 'u' : attribs->floatComponents ? 'f' : '.',
++ attribs->srgb ? 's' : '.',
++ attribs->auxBuffers,
++ attribs->depthSize,
++ attribs->stencilSize
++ );
++
++ printf(" %2d %2d %2d %2d %2d %1d %s\n",
++ attribs->accumRedSize, attribs->accumGreenSize,
++ attribs->accumBlueSize, attribs->accumAlphaSize,
++ attribs->numSamples, attribs->numMultisample,
++ caveat
++ );
++}
++
++
++static void
++print_visual_attribs_long_header(void)
++{
++ printf("Vis Vis Visual Trans buff lev render DB ste r g b a s aux dep ste accum buffer MS MS \n");
++ printf(" ID Depth Type parent size el type reo sz sz sz sz flt rgb buf th ncl r g b a num bufs caveats\n");
++ printf("--------------------------------------------------------------------------------------------------------------------\n");
++}
++
++
++static void
++print_visual_attribs_long(const struct visual_attribs *attribs)
++{
++ const char *caveat = caveat_string(attribs->visualCaveat);
++
++ printf("0x%3x %2d %-11s %2d %3d %2d %4s %3d %3d %3d %3d %3d %3d",
++ attribs->id,
++ attribs->depth,
++ visual_class_name(attribs->klass),
++ attribs->transparentType != GLX_NONE,
++ attribs->bufferSize,
++ attribs->level,
++ visual_render_type_name(attribs->render_type),
++ attribs->doubleBuffer,
++ attribs->stereo,
++ attribs->redSize, attribs->greenSize,
++ attribs->blueSize, attribs->alphaSize
++ );
++
++ printf(" %c %c %3d %4d %2d %3d %3d %3d %3d %2d %2d %6s\n",
++ attribs->floatComponents ? 'f' : '.',
++ attribs->srgb ? 's' : '.',
++ attribs->auxBuffers,
++ attribs->depthSize,
++ attribs->stencilSize,
++ attribs->accumRedSize, attribs->accumGreenSize,
++ attribs->accumBlueSize, attribs->accumAlphaSize,
++ attribs->numSamples, attribs->numMultisample,
++ caveat
++ );
++}
++
++
++static void
++print_visual_info(Display *dpy, int scrnum, InfoMode mode)
++{
++ XVisualInfo theTemplate;
++ XVisualInfo *visuals;
++ int numVisuals, numGlxVisuals;
++ long mask;
++ int i;
++ struct visual_attribs attribs;
++
++ /* get list of all visuals on this screen */
++ theTemplate.screen = scrnum;
++ mask = VisualScreenMask;
++ visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
++
++ numGlxVisuals = 0;
++ for (i = 0; i < numVisuals; i++) {
++ if (get_visual_attribs(dpy, &visuals[i], &attribs))
++ numGlxVisuals++;
++ }
++
++ if (numGlxVisuals == 0)
++ return;
++
++ printf("%d GLX Visuals\n", numGlxVisuals);
++
++ if (mode == Normal)
++ print_visual_attribs_short_header();
++ else if (mode == Wide)
++ print_visual_attribs_long_header();
++
++ for (i = 0; i < numVisuals; i++) {
++ if (!get_visual_attribs(dpy, &visuals[i], &attribs))
++ continue;
++
++ if (mode == Verbose)
++ print_visual_attribs_verbose(&attribs, False);
++ else if (mode == Normal)
++ print_visual_attribs_short(&attribs);
++ else if (mode == Wide)
++ print_visual_attribs_long(&attribs);
++ }
++ printf("\n");
++
++ XFree(visuals);
++}
++
++#ifdef GLX_VERSION_1_3
++
++static void
++print_fbconfig_info(Display *dpy, int scrnum, InfoMode mode)
++{
++ int numFBConfigs = 0;
++ struct visual_attribs attribs;
++ GLXFBConfig *fbconfigs;
++ int i;
++
++ /* get list of all fbconfigs on this screen */
++ fbconfigs = glXGetFBConfigs(dpy, scrnum, &numFBConfigs);
++
++ if (numFBConfigs == 0) {
++ XFree(fbconfigs);
++ return;
++ }
++
++ printf("%d GLXFBConfigs:\n", numFBConfigs);
++ if (mode == Normal)
++ print_visual_attribs_short_header();
++ else if (mode == Wide)
++ print_visual_attribs_long_header();
++
++ for (i = 0; i < numFBConfigs; i++) {
++ get_fbconfig_attribs(dpy, fbconfigs[i], &attribs);
++
++ if (mode == Verbose)
++ print_visual_attribs_verbose(&attribs, True);
++ else if (mode == Normal)
++ print_visual_attribs_short(&attribs);
++ else if (mode == Wide)
++ print_visual_attribs_long(&attribs);
++ }
++ printf("\n");
++
++ XFree(fbconfigs);
++}
++
++#endif
++
++/*
++ * Stand-alone Mesa doesn't really implement the GLX protocol so it
++ * doesn't really know the GLX attributes associated with an X visual.
++ * The first time a visual is presented to Mesa's pseudo-GLX it
++ * attaches ancilliary buffers to it (like depth and stencil).
++ * But that usually only works if glXChooseVisual is used.
++ * This function calls glXChooseVisual() to sort of "prime the pump"
++ * for Mesa's GLX so that the visuals that get reported actually
++ * reflect what applications will see.
++ * This has no effect when using true GLX.
++ */
++static void
++mesa_hack(Display *dpy, int scrnum)
++{
++ static int attribs[] = {
++ GLX_RGBA,
++ GLX_RED_SIZE, 1,
++ GLX_GREEN_SIZE, 1,
++ GLX_BLUE_SIZE, 1,
++ GLX_DEPTH_SIZE, 1,
++ GLX_STENCIL_SIZE, 1,
++ GLX_ACCUM_RED_SIZE, 1,
++ GLX_ACCUM_GREEN_SIZE, 1,
++ GLX_ACCUM_BLUE_SIZE, 1,
++ GLX_ACCUM_ALPHA_SIZE, 1,
++ GLX_DOUBLEBUFFER,
++ None
++ };
++ XVisualInfo *visinfo;
++
++ visinfo = glXChooseVisual(dpy, scrnum, attribs);
++ if (visinfo)
++ XFree(visinfo);
++}
++
++
++/*
++ * Examine all visuals to find the so-called best one.
++ * We prefer deepest RGBA buffer with depth, stencil and accum
++ * that has no caveats.
++ */
++static int
++find_best_visual(Display *dpy, int scrnum)
++{
++ XVisualInfo theTemplate;
++ XVisualInfo *visuals;
++ int numVisuals;
++ long mask;
++ int i;
++ struct visual_attribs bestVis;
++
++ /* get list of all visuals on this screen */
++ theTemplate.screen = scrnum;
++ mask = VisualScreenMask;
++ visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals);
++
++ /* init bestVis with first visual info */
++ get_visual_attribs(dpy, &visuals[0], &bestVis);
++
++ /* try to find a "better" visual */
++ for (i = 1; i < numVisuals; i++) {
++ struct visual_attribs vis;
++
++ get_visual_attribs(dpy, &visuals[i], &vis);
++
++ /* always skip visuals with caveats */
++ if (vis.visualCaveat != GLX_NONE_EXT)
++ continue;
++
++ /* see if this vis is better than bestVis */
++ if ((!bestVis.supportsGL && vis.supportsGL) ||
++ (bestVis.visualCaveat != GLX_NONE_EXT) ||
++ (!(bestVis.render_type & GLX_RGBA_BIT) && (vis.render_type & GLX_RGBA_BIT)) ||
++ (!bestVis.doubleBuffer && vis.doubleBuffer) ||
++ (bestVis.redSize < vis.redSize) ||
++ (bestVis.greenSize < vis.greenSize) ||
++ (bestVis.blueSize < vis.blueSize) ||
++ (bestVis.alphaSize < vis.alphaSize) ||
++ (bestVis.depthSize < vis.depthSize) ||
++ (bestVis.stencilSize < vis.stencilSize) ||
++ (bestVis.accumRedSize < vis.accumRedSize)) {
++ /* found a better visual */
++ bestVis = vis;
++ }
++ }
++
++ XFree(visuals);
++
++ return bestVis.id;
++}
++
++
++int
++main(int argc, char *argv[])
++{
++ Display *dpy;
++ int numScreens, scrnum;
++ struct options opts;
++ Bool coreWorked;
++
++ parse_args(argc, argv, &opts);
++
++ dpy = XOpenDisplay(opts.displayName);
++ if (!dpy) {
++ fprintf(stderr, "Error: unable to open display %s\n",
++ XDisplayName(opts.displayName));
++ return -1;
++ }
++
++ if (opts.findBest) {
++ int b;
++ mesa_hack(dpy, 0);
++ b = find_best_visual(dpy, 0);
++ printf("%d\n", b);
++ }
++ else {
++ numScreens = ScreenCount(dpy);
++ print_display_info(dpy);
++ for (scrnum = 0; scrnum < numScreens; scrnum++) {
++ mesa_hack(dpy, scrnum);
++ coreWorked = print_screen_info(dpy, scrnum, &opts,
++ True, False, opts.limits, False);
++ print_screen_info(dpy, scrnum, &opts, False, False,
++ opts.limits, coreWorked);
++ print_screen_info(dpy, scrnum, &opts, False, True, False, True);
++
++ printf("\n");
++
++ if (opts.mode != Brief) {
++ print_visual_info(dpy, scrnum, opts.mode);
++#ifdef GLX_VERSION_1_3
++ print_fbconfig_info(dpy, scrnum, opts.mode);
++#endif
++ }
++
++ if (scrnum + 1 < numScreens)
++ printf("\n\n");
++ }
++ }
++
++ XCloseDisplay(dpy);
++
++ return 0;
++}
+diff -Naurp mesa-20.2.1-orig/src/glx/xdemos/meson.build mesa-20.2.1/src/glx/xdemos/meson.build
+--- mesa-20.2.1-orig/src/glx/xdemos/meson.build 1969-12-31 18:00:00.000000000 -0600
++++ mesa-20.2.1/src/glx/xdemos/meson.build 2020-10-15 23:07:14.486696790 -0500
+@@ -0,0 +1,32 @@
++inc_xdemos = include_directories('.')
++
++glxinfo_files = files(
++ 'glxinfo.c',
++ 'glinfo_common.c',
++)
++
++x11_dep = dependency('x11', required: true)
++
++executable('glxinfo', glxinfo_files,
++ install : true,
++ #c_args : gl_lib_cargs,
++ link_args : [ld_args_bsymbolic, ld_args_gc_sections, extra_ld_args_libgl, '-lm'],
++ link_with : libgl,
++ include_directories : [ inc_src, inc_include, inc_mesa, inc_glx],
++ dependencies : [x11_dep]
++)
++
++executable('glxgears', 'glxgears.c',
++ install : true,
++ #c_args : gl_lib_cargs,
++ link_args : [ld_args_bsymbolic, ld_args_gc_sections, extra_ld_args_libgl, '-lm'],
++ link_with : libgl,
++ include_directories : [inc_src, inc_include, inc_mesa, inc_glx],
++ dependencies : [x11_dep]
++)
++
++man_dir = get_option('prefix') + '/share/man/man1'
++install_data(['glxinfo.1', 'glxgears.1'],
++ install_dir : man_dir
++)
++
diff --git a/repo/x11/mesa/mesa-21.3.7-nouveau_fixes-1.patch b/repo/x11/mesa/mesa-21.3.7-nouveau_fixes-1.patch
new file mode 100644
index 0000000..ecf6008
--- /dev/null
+++ b/repo/x11/mesa/mesa-21.3.7-nouveau_fixes-1.patch
@@ -0,0 +1,2878 @@
+Submitted By: Douglas R. Reno <renodr at linuxfromscratch dot org>
+Date: 2022-02-11
+Initial Package Version: 21.3.6
+Upstream Status: Merge Request (Partial), Self
+Origin: Upstream MR (#10752) with modifications
+Description: Fixes several multi-threading related issues in the
+ Nouveau driver in Mesa. These issues can lead to
+ kernel panics and application crashes, and also cause
+ KDE Plasma in Wayland mode to instantly crash the system
+ once launched on a NVC0 or later card (NV50 is
+ unaffected). My changes include additional PUSH commands
+ to fix timing issues, which will be picked up upstream
+ shortly. Tested with KDE Plasma/Wayland, GNOME, VLC,
+ MPlayer, Minecraft, Discord, Zoom, XINE, and Kdenlive.
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_buffer.c mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_buffer.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_buffer.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_buffer.c 2022-02-11 16:51:08.220134863 -0600
+@@ -91,12 +91,8 @@ nouveau_buffer_release_gpu_storage(struc
+ {
+ assert(!(buf->status & NOUVEAU_BUFFER_STATUS_USER_PTR));
+
+- if (buf->fence && buf->fence->state < NOUVEAU_FENCE_STATE_FLUSHED) {
+- nouveau_fence_work(buf->fence, nouveau_fence_unref_bo, buf->bo);
+- buf->bo = NULL;
+- } else {
+- nouveau_bo_ref(NULL, &buf->bo);
+- }
++ nouveau_fence_work(buf->fence, nouveau_fence_unref_bo, buf->bo);
++ buf->bo = NULL;
+
+ if (buf->mm)
+ release_allocation(&buf->mm, buf->fence);
+@@ -172,7 +168,7 @@ nouveau_transfer_staging(struct nouveau_
+ nouveau_mm_allocate(nv->screen->mm_GART, size, &tx->bo, &tx->offset);
+ if (tx->bo) {
+ tx->offset += adj;
+- if (!nouveau_bo_map(tx->bo, 0, NULL))
++ if (!BO_MAP(nv->screen, tx->bo, 0, NULL))
+ tx->map = (uint8_t *)tx->bo->map + tx->offset;
+ }
+ }
+@@ -195,7 +191,7 @@ nouveau_transfer_read(struct nouveau_con
+ nv->copy_data(nv, tx->bo, tx->offset, NOUVEAU_BO_GART,
+ buf->bo, buf->offset + base, buf->domain, size);
+
+- if (nouveau_bo_wait(tx->bo, NOUVEAU_BO_RD, nv->client))
++ if (BO_WAIT(nv->screen, tx->bo, NOUVEAU_BO_RD, nv->client))
+ return false;
+
+ if (buf->data)
+@@ -233,8 +229,8 @@ nouveau_transfer_write(struct nouveau_co
+ else
+ nv->push_data(nv, buf->bo, buf->offset + base, buf->domain, size, data);
+
+- nouveau_fence_ref(nv->screen->fence.current, &buf->fence);
+- nouveau_fence_ref(nv->screen->fence.current, &buf->fence_wr);
++ nouveau_fence_ref(nv->fence, &buf->fence);
++ nouveau_fence_ref(nv->fence, &buf->fence_wr);
+ }
+
+ /* Does a CPU wait for the buffer's backing data to become reliably accessible
+@@ -303,10 +299,9 @@ nouveau_buffer_transfer_del(struct nouve
+ {
+ if (tx->map) {
+ if (likely(tx->bo)) {
+- nouveau_fence_work(nv->screen->fence.current,
+- nouveau_fence_unref_bo, tx->bo);
++ nouveau_fence_work(nv->fence, nouveau_fence_unref_bo, tx->bo);
+ if (tx->mm)
+- release_allocation(&tx->mm, nv->screen->fence.current);
++ release_allocation(&tx->mm, nv->fence);
+ } else {
+ align_free(tx->map -
+ (tx->base.box.x & NOUVEAU_MIN_BUFFER_MAP_ALIGN_MASK));
+@@ -475,9 +470,9 @@ nouveau_buffer_transfer_map(struct pipe_
+ * wait on the whole slab and instead use the logic below to return a
+ * reasonable buffer for that case.
+ */
+- ret = nouveau_bo_map(buf->bo,
+- buf->mm ? 0 : nouveau_screen_transfer_flags(usage),
+- nv->client);
++ ret = BO_MAP(nv->screen, buf->bo,
++ buf->mm ? 0 : nouveau_screen_transfer_flags(usage),
++ nv->client);
+ if (ret) {
+ FREE(tx);
+ return NULL;
+@@ -601,11 +596,11 @@ nouveau_copy_buffer(struct nouveau_conte
+ src->bo, src->offset + srcx, src->domain, size);
+
+ dst->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
+- nouveau_fence_ref(nv->screen->fence.current, &dst->fence);
+- nouveau_fence_ref(nv->screen->fence.current, &dst->fence_wr);
++ nouveau_fence_ref(nv->fence, &dst->fence);
++ nouveau_fence_ref(nv->fence, &dst->fence_wr);
+
+ src->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
+- nouveau_fence_ref(nv->screen->fence.current, &src->fence);
++ nouveau_fence_ref(nv->fence, &src->fence);
+ } else {
+ struct pipe_box src_box;
+ src_box.x = srcx;
+@@ -643,10 +638,10 @@ nouveau_resource_map_offset(struct nouve
+ unsigned rw;
+ rw = (flags & NOUVEAU_BO_WR) ? PIPE_MAP_WRITE : PIPE_MAP_READ;
+ nouveau_buffer_sync(nv, res, rw);
+- if (nouveau_bo_map(res->bo, 0, NULL))
++ if (BO_MAP(nv->screen, res->bo, 0, NULL))
+ return NULL;
+ } else {
+- if (nouveau_bo_map(res->bo, flags, nv->client))
++ if (BO_MAP(nv->screen, res->bo, flags, nv->client))
+ return NULL;
+ }
+ return (uint8_t *)res->bo->map + res->offset + offset;
+@@ -802,7 +797,7 @@ nouveau_buffer_data_fetch(struct nouveau
+ {
+ if (!nouveau_buffer_malloc(buf))
+ return false;
+- if (nouveau_bo_map(bo, NOUVEAU_BO_RD, nv->client))
++ if (BO_MAP(nv->screen, bo, NOUVEAU_BO_RD, nv->client))
+ return false;
+ memcpy(buf->data, (uint8_t *)bo->map + offset, size);
+ return true;
+@@ -827,7 +822,7 @@ nouveau_buffer_migrate(struct nouveau_co
+ if (new_domain == NOUVEAU_BO_GART && old_domain == 0) {
+ if (!nouveau_buffer_allocate(screen, buf, new_domain))
+ return false;
+- ret = nouveau_bo_map(buf->bo, 0, nv->client);
++ ret = BO_MAP(nv->screen, buf->bo, 0, nv->client);
+ if (ret)
+ return ret;
+ memcpy((uint8_t *)buf->bo->map + buf->offset, buf->data, size);
+@@ -853,9 +848,9 @@ nouveau_buffer_migrate(struct nouveau_co
+ nv->copy_data(nv, buf->bo, buf->offset, new_domain,
+ bo, offset, old_domain, buf->base.width0);
+
+- nouveau_fence_work(screen->fence.current, nouveau_fence_unref_bo, bo);
++ nouveau_fence_work(nv->fence, nouveau_fence_unref_bo, bo);
+ if (mm)
+- release_allocation(&mm, screen->fence.current);
++ release_allocation(&mm, nv->fence);
+ } else
+ if (new_domain == NOUVEAU_BO_VRAM && old_domain == 0) {
+ struct nouveau_transfer tx;
+@@ -897,7 +892,7 @@ nouveau_user_buffer_upload(struct nouvea
+ if (!nouveau_buffer_reallocate(screen, buf, NOUVEAU_BO_GART))
+ return false;
+
+- ret = nouveau_bo_map(buf->bo, 0, nv->client);
++ ret = BO_MAP(nv->screen, buf->bo, 0, nv->client);
+ if (ret)
+ return false;
+ memcpy((uint8_t *)buf->bo->map + buf->offset + base, buf->data + base, size);
+@@ -964,7 +959,7 @@ nouveau_scratch_runout_release(struct no
+ if (!nv->scratch.runout)
+ return;
+
+- if (!nouveau_fence_work(nv->screen->fence.current, nouveau_scratch_unref_bos,
++ if (!nouveau_fence_work(nv->fence, nouveau_scratch_unref_bos,
+ nv->scratch.runout))
+ return;
+
+@@ -993,7 +988,7 @@ nouveau_scratch_runout(struct nouveau_co
+
+ ret = nouveau_scratch_bo_alloc(nv, &nv->scratch.runout->bo[n], size);
+ if (!ret) {
+- ret = nouveau_bo_map(nv->scratch.runout->bo[n], 0, NULL);
++ ret = BO_MAP(nv->screen, nv->scratch.runout->bo[n], 0, NULL);
+ if (ret)
+ nouveau_bo_ref(NULL, &nv->scratch.runout->bo[--nv->scratch.runout->nr]);
+ }
+@@ -1031,7 +1026,7 @@ nouveau_scratch_next(struct nouveau_cont
+ nv->scratch.offset = 0;
+ nv->scratch.end = nv->scratch.bo_size;
+
+- ret = nouveau_bo_map(bo, NOUVEAU_BO_WR, nv->client);
++ ret = BO_MAP(nv->screen, bo, NOUVEAU_BO_WR, nv->client);
+ if (!ret)
+ nv->scratch.map = bo->map;
+ return !ret;
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_context.h mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_context.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_context.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_context.h 2022-02-11 16:51:52.682577582 -0600
+@@ -15,6 +15,7 @@ struct nouveau_context {
+
+ struct nouveau_client *client;
+ struct nouveau_pushbuf *pushbuf;
++ struct nouveau_fence *fence;
+ struct pipe_debug_callback debug;
+
+ bool vbo_dirty;
+@@ -66,7 +67,7 @@ void
+ nouveau_context_init_vdec(struct nouveau_context *);
+
+ void
+-nouveau_context_init(struct nouveau_context *);
++nouveau_context_init(struct nouveau_context *, struct nouveau_screen *);
+
+ void
+ nouveau_scratch_runout_release(struct nouveau_context *);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_fence.c mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_fence.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_fence.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_fence.c 2022-02-11 17:03:39.714131948 -0600
+@@ -21,6 +21,7 @@
+ */
+
+ #include "nouveau_screen.h"
++#include "nouveau_context.h"
+ #include "nouveau_winsys.h"
+ #include "nouveau_fence.h"
+ #include "util/os_time.h"
+@@ -30,13 +31,14 @@
+ #endif
+
+ bool
+-nouveau_fence_new(struct nouveau_screen *screen, struct nouveau_fence **fence)
++nouveau_fence_new(struct nouveau_context *nv, struct nouveau_fence **fence)
+ {
+ *fence = CALLOC_STRUCT(nouveau_fence);
+ if (!*fence)
+ return false;
+
+- (*fence)->screen = screen;
++ (*fence)->screen = nv->screen;
++ (*fence)->context = nv;
+ (*fence)->ref = 1;
+ list_inithead(&(*fence)->work);
+
+@@ -59,22 +61,25 @@ void
+ nouveau_fence_emit(struct nouveau_fence *fence)
+ {
+ struct nouveau_screen *screen = fence->screen;
++ struct nouveau_fence_list *fence_list = &screen->fence;
+
+- assert(fence->state == NOUVEAU_FENCE_STATE_AVAILABLE);
++ assert(fence->state != NOUVEAU_FENCE_STATE_EMITTING);
++ if (fence->state >= NOUVEAU_FENCE_STATE_EMITTED)
++ return;
+
+ /* set this now, so that if fence.emit triggers a flush we don't recurse */
+ fence->state = NOUVEAU_FENCE_STATE_EMITTING;
+
+ ++fence->ref;
+
+- if (screen->fence.tail)
+- screen->fence.tail->next = fence;
++ if (fence_list->tail)
++ fence_list->tail->next = fence;
+ else
+- screen->fence.head = fence;
++ fence_list->head = fence;
+
+- screen->fence.tail = fence;
++ fence_list->tail = fence;
+
+- screen->fence.emit(&screen->base, &fence->sequence);
++ fence_list->emit(&screen->base, &fence->sequence);
+
+ assert(fence->state == NOUVEAU_FENCE_STATE_EMITTING);
+ fence->state = NOUVEAU_FENCE_STATE_EMITTED;
+@@ -84,19 +89,19 @@ void
+ nouveau_fence_del(struct nouveau_fence *fence)
+ {
+ struct nouveau_fence *it;
+- struct nouveau_screen *screen = fence->screen;
++ struct nouveau_fence_list *fence_list = &fence->screen->fence;
+
+ if (fence->state == NOUVEAU_FENCE_STATE_EMITTED ||
+ fence->state == NOUVEAU_FENCE_STATE_FLUSHED) {
+- if (fence == screen->fence.head) {
+- screen->fence.head = fence->next;
+- if (!screen->fence.head)
+- screen->fence.tail = NULL;
++ if (fence == fence_list->head) {
++ fence_list->head = fence->next;
++ if (!fence_list->head)
++ fence_list->tail = NULL;
+ } else {
+- for (it = screen->fence.head; it && it->next != fence; it = it->next);
++ for (it = fence_list->head; it && it->next != fence; it = it->next);
+ it->next = fence->next;
+- if (screen->fence.tail == fence)
+- screen->fence.tail = it;
++ if (fence_list->tail == fence)
++ fence_list->tail = it;
+ }
+ }
+
+@@ -109,18 +114,19 @@ nouveau_fence_del(struct nouveau_fence *
+ }
+
+ void
+-nouveau_fence_cleanup(struct nouveau_screen *screen)
++nouveau_fence_cleanup(struct nouveau_context *nv)
+ {
+- if (screen->fence.current) {
++ struct nouveau_fence_list *fence_list = &nv->screen->fence;
++ if (nv->fence) {
+ struct nouveau_fence *current = NULL;
+
+ /* nouveau_fence_wait will create a new current fence, so wait on the
+ * _current_ one, and remove both.
+ */
+- nouveau_fence_ref(screen->fence.current, &current);
++ nouveau_fence_ref(nv->fence, &current);
+ nouveau_fence_wait(current, NULL);
+ nouveau_fence_ref(NULL, &current);
+- nouveau_fence_ref(NULL, &screen->fence.current);
++ nouveau_fence_ref(NULL, &nv->fence);
+ }
+ }
+
+@@ -129,13 +135,14 @@ nouveau_fence_update(struct nouveau_scre
+ {
+ struct nouveau_fence *fence;
+ struct nouveau_fence *next = NULL;
+- u32 sequence = screen->fence.update(&screen->base);
++ struct nouveau_fence_list *fence_list = &screen->fence;
++ u32 sequence = fence_list->update(&screen->base);
+
+- if (screen->fence.sequence_ack == sequence)
++ if (fence_list->sequence_ack == sequence)
+ return;
+- screen->fence.sequence_ack = sequence;
++ fence_list->sequence_ack = sequence;
+
+- for (fence = screen->fence.head; fence; fence = next) {
++ for (fence = fence_list->head; fence; fence = next) {
+ next = fence->next;
+ sequence = fence->sequence;
+
+@@ -144,12 +151,12 @@ nouveau_fence_update(struct nouveau_scre
+ nouveau_fence_trigger_work(fence);
+ nouveau_fence_ref(NULL, &fence);
+
+- if (sequence == screen->fence.sequence_ack)
++ if (sequence == fence_list->sequence_ack)
+ break;
+ }
+- screen->fence.head = next;
++ fence_list->head = next;
+ if (!next)
+- screen->fence.tail = NULL;
++ fence_list->tail = NULL;
+
+ if (flushed) {
+ for (fence = next; fence; fence = fence->next)
+@@ -178,25 +185,23 @@ static bool
+ nouveau_fence_kick(struct nouveau_fence *fence)
+ {
+ struct nouveau_screen *screen = fence->screen;
++ struct nouveau_fence_list *fence_list = &screen->fence;
++ bool current = !fence->sequence;
+
+ /* wtf, someone is waiting on a fence in flush_notify handler? */
+ assert(fence->state != NOUVEAU_FENCE_STATE_EMITTING);
+
+ if (fence->state < NOUVEAU_FENCE_STATE_EMITTED) {
+ PUSH_SPACE(screen->pushbuf, 8);
+- /* The space allocation might trigger a flush, which could emit the
+- * current fence. So check again.
+- */
+- if (fence->state < NOUVEAU_FENCE_STATE_EMITTED)
+- nouveau_fence_emit(fence);
++ nouveau_fence_emit(fence);
+ }
+
+ if (fence->state < NOUVEAU_FENCE_STATE_FLUSHED)
+ if (nouveau_pushbuf_kick(screen->pushbuf, screen->pushbuf->channel))
+ return false;
+
+- if (fence == screen->fence.current)
+- nouveau_fence_next(screen);
++ if (current)
++ nouveau_fence_next(fence->context);
+
+ nouveau_fence_update(screen, false);
+
+@@ -207,6 +212,7 @@ bool
+ nouveau_fence_wait(struct nouveau_fence *fence, struct pipe_debug_callback *debug)
+ {
+ struct nouveau_screen *screen = fence->screen;
++ struct nouveau_fence_list *fence_list = &screen->fence;
+ uint32_t spins = 0;
+ int64_t start = 0;
+
+@@ -237,24 +243,26 @@ nouveau_fence_wait(struct nouveau_fence
+
+ debug_printf("Wait on fence %u (ack = %u, next = %u) timed out !\n",
+ fence->sequence,
+- screen->fence.sequence_ack, screen->fence.sequence);
++ fence_list->sequence_ack, fence_list->sequence);
+
+ return false;
+ }
+
+ void
+-nouveau_fence_next(struct nouveau_screen *screen)
++nouveau_fence_next(struct nouveau_context *nv)
+ {
+- if (screen->fence.current->state < NOUVEAU_FENCE_STATE_EMITTING) {
+- if (screen->fence.current->ref > 1)
+- nouveau_fence_emit(screen->fence.current);
++ struct nouveau_fence_list *fence_list = &nv->screen->fence;
++
++ if (nv->fence->state < NOUVEAU_FENCE_STATE_EMITTING) {
++ if (nv->fence->ref > 1)
++ nouveau_fence_emit(nv->fence);
+ else
+ return;
+ }
+
+- nouveau_fence_ref(NULL, &screen->fence.current);
++ nouveau_fence_ref(NULL, &nv->fence);
+
+- nouveau_fence_new(screen, &screen->fence.current);
++ nouveau_fence_new(nv, &nv->fence);
+ }
+
+ void
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_fence.h mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_fence.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_fence.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_fence.h 2022-02-11 17:06:52.375811111 -0600
+@@ -22,6 +22,7 @@ struct nouveau_fence_work {
+ struct nouveau_fence {
+ struct nouveau_fence *next;
+ struct nouveau_screen *screen;
++ struct nouveau_context *context;
+ int state;
+ int ref;
+ uint32_t sequence;
+@@ -29,14 +30,23 @@ struct nouveau_fence {
+ struct list_head work;
+ };
+
++struct nouveau_fence_list {
++ struct nouveau_fence *head;
++ struct nouveau_fence *tail;
++ uint32_t sequence;
++ uint32_t sequence_ack;
++ void (*emit)(struct pipe_screen *, uint32_t *sequence);
++ uint32_t (*update)(struct pipe_screen *);
++};
++
+ void nouveau_fence_emit(struct nouveau_fence *);
+ void nouveau_fence_del(struct nouveau_fence *);
+
+-bool nouveau_fence_new(struct nouveau_screen *, struct nouveau_fence **);
+-void nouveau_fence_cleanup(struct nouveau_screen *);
++bool nouveau_fence_new(struct nouveau_context *, struct nouveau_fence **);
++void nouveau_fence_cleanup(struct nouveau_context *);
+ bool nouveau_fence_work(struct nouveau_fence *, void (*)(void *), void *);
+ void nouveau_fence_update(struct nouveau_screen *, bool flushed);
+-void nouveau_fence_next(struct nouveau_screen *);
++void nouveau_fence_next(struct nouveau_context *);
+ bool nouveau_fence_wait(struct nouveau_fence *, struct pipe_debug_callback *);
+ bool nouveau_fence_signalled(struct nouveau_fence *);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_mm.c mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_mm.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_mm.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_mm.c 2022-02-11 17:09:55.188637737 -0600
+@@ -1,6 +1,7 @@
+
+ #include <inttypes.h>
+
++#include "util/simple_mtx.h"
+ #include "util/u_inlines.h"
+ #include "util/u_memory.h"
+ #include "util/list.h"
+@@ -29,6 +30,7 @@ struct mm_bucket {
+ struct list_head used;
+ struct list_head full;
+ int num_free;
++ simple_mtx_t lock;
+ };
+
+ struct nouveau_mman {
+@@ -124,6 +126,8 @@ mm_slab_new(struct nouveau_mman *cache,
+ int words, ret;
+ const uint32_t size = mm_default_slab_size(chunk_order);
+
++ simple_mtx_assert_locked(&bucket->lock);
++
+ words = ((size >> chunk_order) + 31) / 32;
+ assert(words);
+
+@@ -151,7 +155,7 @@ mm_slab_new(struct nouveau_mman *cache,
+ assert(bucket == mm_bucket_by_order(cache, chunk_order));
+ list_add(&slab->head, &bucket->free);
+
+- cache->allocated += size;
++ p_atomic_add(&cache->allocated, size);
+
+ if (nouveau_mesa_debug)
+ debug_printf("MM: new slab, total memory = %"PRIu64" KiB\n",
+@@ -182,6 +186,11 @@ nouveau_mm_allocate(struct nouveau_mman
+ return NULL;
+ }
+
++ alloc = MALLOC_STRUCT(nouveau_mm_allocation);
++ if (!alloc)
++ return NULL;
++
++ simple_mtx_lock(&bucket->lock);
+ if (!list_is_empty(&bucket->used)) {
+ slab = LIST_ENTRY(struct mm_slab, bucket->used.next, head);
+ } else {
+@@ -196,16 +205,13 @@ nouveau_mm_allocate(struct nouveau_mman
+
+ *offset = mm_slab_alloc(slab) << slab->order;
+
+- alloc = MALLOC_STRUCT(nouveau_mm_allocation);
+- if (!alloc)
+- return NULL;
+-
+ nouveau_bo_ref(slab->bo, bo);
+
+ if (slab->free == 0) {
+ list_del(&slab->head);
+ list_add(&slab->head, &bucket->full);
+ }
++ simple_mtx_unlock(&bucket->lock);
+
+ alloc->offset = *offset;
+ alloc->priv = (void *)slab;
+@@ -229,6 +235,7 @@ nouveau_mm_free(struct nouveau_mm_alloca
+ list_del(&slab->head);
+ list_addtail(&slab->head, &bucket->used);
+ }
++ simple_mtx_unlock(&bucket->lock);
+
+ FREE(alloc);
+ }
+@@ -258,6 +265,7 @@ nouveau_mm_create(struct nouveau_device
+ list_inithead(&cache->bucket[i].free);
+ list_inithead(&cache->bucket[i].used);
+ list_inithead(&cache->bucket[i].full);
++ simple_mtx_init(&cache->bucket[i].lock, mtx_plain);
+ }
+
+ return cache;
+@@ -292,6 +300,7 @@ nouveau_mm_destroy(struct nouveau_mman *
+ nouveau_mm_free_slabs(&cache->bucket[i].free);
+ nouveau_mm_free_slabs(&cache->bucket[i].used);
+ nouveau_mm_free_slabs(&cache->bucket[i].full);
++ simple_mtx_destroy(&cache->bucket[i].lock);
+ }
+
+ FREE(cache);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_screen.c mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_screen.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_screen.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_screen.c 2022-02-11 17:11:30.951045828 -0600
+@@ -394,7 +394,11 @@ nouveau_set_debug_callback(struct pipe_c
+ }
+
+ void
+-nouveau_context_init(struct nouveau_context *context)
++nouveau_context_init(struct nouveau_context *context, struct nouveau_screen *screen)
+ {
+ context->pipe.set_debug_callback = nouveau_set_debug_callback;
++
++ context->screen = screen;
++ context->client = screen->client;
++ context->pushbuf = screen->pushbuf;
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_screen.h mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_screen.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_screen.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_screen.h 2022-02-11 17:12:22.999729379 -0600
+@@ -6,6 +6,8 @@
+ #include "util/u_atomic.h"
+ #include "util/u_memory.h"
+
++#include "nouveau_fence.h"
++
+ #ifndef NDEBUG
+ # define NOUVEAU_ENABLE_DRIVER_STATISTICS
+ #endif
+@@ -44,15 +46,7 @@ struct nouveau_screen {
+
+ uint16_t class_3d;
+
+- struct {
+- struct nouveau_fence *head;
+- struct nouveau_fence *tail;
+- struct nouveau_fence *current;
+- u32 sequence;
+- u32 sequence_ack;
+- void (*emit)(struct pipe_screen *, u32 *sequence);
+- u32 (*update)(struct pipe_screen *);
+- } fence;
++ struct nouveau_fence_list fence;
+
+ struct nouveau_mman *mm_VRAM;
+ struct nouveau_mman *mm_GART;
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_video.c mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_video.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_video.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_video.c 2022-02-11 17:13:47.703221196 -0600
+@@ -37,12 +37,12 @@ nouveau_vpe_init(struct nouveau_decoder
+ int ret;
+ if (dec->cmds)
+ return 0;
+- ret = nouveau_bo_map(dec->cmd_bo, NOUVEAU_BO_RDWR, dec->client);
++ ret = BO_MAP(dec->screen, dec->cmd_bo, NOUVEAU_BO_RDWR, dec->client);
+ if (ret) {
+ debug_printf("Mapping cmd bo: %s\n", strerror(-ret));
+ return ret;
+ }
+- ret = nouveau_bo_map(dec->data_bo, NOUVEAU_BO_RDWR, dec->client);
++ ret = BO_MAP(dec->screen, dec->data_bo, NOUVEAU_BO_RDWR, dec->client);
+ if (ret) {
+ debug_printf("Mapping data bo: %s\n", strerror(-ret));
+ return ret;
+@@ -73,7 +73,7 @@ nouveau_vpe_fini(struct nouveau_decoder
+ if (!dec->cmds)
+ return;
+
+- nouveau_pushbuf_space(push, 16, 2, 0);
++ PUSH_SPACE_EX(push, 16, 2, 0);
+ nouveau_bufctx_reset(dec->bufctx, NV31_VIDEO_BIND_CMD);
+
+ #define BCTX_ARGS dec->bufctx, NV31_VIDEO_BIND_CMD, NOUVEAU_BO_RD
+@@ -88,7 +88,7 @@ nouveau_vpe_fini(struct nouveau_decoder
+
+ #undef BCTX_ARGS
+
+- if (unlikely(nouveau_pushbuf_validate(dec->push)))
++ if (unlikely(PUSH_VAL(dec->push)))
+ return;
+
+ BEGIN_NV04(push, NV31_MPEG(EXEC), 1);
+@@ -582,13 +582,13 @@ nouveau_create_decoder(struct pipe_conte
+ 0, 4096, NULL, &dec->fence_bo);
+ if (ret)
+ goto fail;
+- nouveau_bo_map(dec->fence_bo, NOUVEAU_BO_RDWR, NULL);
++ BO_MAP(dec->fence_bo, NOUVEAU_BO_RDWR, NULL);
+ dec->fence_map = dec->fence_bo->map;
+ dec->fence_map[0] = 0;
+ #endif
+
+ nouveau_pushbuf_bufctx(dec->push, dec->bufctx);
+- nouveau_pushbuf_space(push, 32, 4, 0);
++ PUSH_SPACE_EX(push, 32, 4, 0);
+
+ BEGIN_NV04(push, SUBC_MPEG(NV01_SUBCHAN_OBJECT), 1);
+ PUSH_DATA (push, dec->mpeg->handle);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_vp3_video.c mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_vp3_video.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_vp3_video.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_vp3_video.c 2022-02-11 17:14:38.549919717 -0600
+@@ -27,6 +27,7 @@
+
+ #include <nvif/class.h>
+
++#include "nouveau_winsys.h"
+ #include "nouveau_screen.h"
+ #include "nouveau_context.h"
+ #include "nouveau_vp3_video.h"
+@@ -284,13 +285,14 @@ nouveau_vp3_load_firmware(struct nouveau
+ char path[PATH_MAX];
+ ssize_t r;
+ uint32_t *end, endval;
++ struct nouveau_screen *screen = nouveau_screen(dec->base.context->screen);
+
+ if (chipset >= 0xa3 && chipset != 0xaa && chipset != 0xac)
+ vp4_getpath(profile, path);
+ else
+ vp3_getpath(profile, path);
+
+- if (nouveau_bo_map(dec->fw_bo, NOUVEAU_BO_WR, dec->client))
++ if (BO_MAP(screen, dec->fw_bo, NOUVEAU_BO_WR, dec->client))
+ return 1;
+
+ fd = open(path, O_RDONLY | O_CLOEXEC);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_winsys.h mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_winsys.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nouveau_winsys.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nouveau_winsys.h 2022-02-11 17:17:15.566002822 -0600
+@@ -9,6 +9,8 @@
+ #include "drm-uapi/drm.h"
+ #include <nouveau.h>
+
++#include "nouveau_screen.h"
++
+ #ifndef NV04_PFIFO_MAX_PACKET_LEN
+ #define NV04_PFIFO_MAX_PACKET_LEN 2047
+ #endif
+@@ -23,12 +25,18 @@ PUSH_AVAIL(struct nouveau_pushbuf *push)
+ }
+
+ static inline bool
++PUSH_SPACE_EX(struct nouveau_pushbuf *push, uint32_t size, uint32_t relocs, uint32_t pushes)
++{
++ return nouveau_pushbuf_space(push, size, relocs, pushes) == 0;
++}
++
++static inline bool
+ PUSH_SPACE(struct nouveau_pushbuf *push, uint32_t size)
+ {
+ /* Provide a buffer so that fences always have room to be emitted */
+ size += 8;
+ if (PUSH_AVAIL(push) < size)
+- return nouveau_pushbuf_space(push, size, 0, 0) == 0;
++ return PUSH_SPACE_EX(push, size, 0, 0);
+ return true;
+ }
+
+@@ -66,6 +74,23 @@ PUSH_KICK(struct nouveau_pushbuf *push)
+ nouveau_pushbuf_kick(push, push->channel);
+ }
+
++static inline int
++PUSH_VAL(struct nouveau_pushbuf *push)
++{
++ return nouveau_pushbuf_validate(push);
++}
++
++static inline int
++BO_MAP(struct nouveau_screen *screen, struct nouveau_bo *bo, uint32_t access, struct nouveau_client *client)
++{
++ return nouveau_bo_map(bo, access, client);
++}
++
++static inline int
++BO_WAIT(struct nouveau_screen *screen, struct nouveau_bo *bo, uint32_t access, struct nouveau_client *client)
++{
++ return nouveau_bo_wait(bo, access, client);
++}
+
+ #define NOUVEAU_RESOURCE_FLAG_LINEAR (PIPE_RESOURCE_FLAG_DRV_PRIV << 0)
+ #define NOUVEAU_RESOURCE_FLAG_DRV_PRIV (PIPE_RESOURCE_FLAG_DRV_PRIV << 1)
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_clear.c mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_clear.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_clear.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_clear.c 2022-02-11 14:24:23.189190438 -0600
+@@ -128,7 +128,7 @@ nv30_clear_render_target(struct pipe_con
+
+ refn.bo = mt->base.bo;
+ refn.flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_WR;
+- if (nouveau_pushbuf_space(push, 32, 1, 0) ||
++ if (!PUSH_SPACE_EX(push, 32, 1, 0) ||
+ nouveau_pushbuf_refn (push, &refn, 1))
+ return;
+
+@@ -193,7 +193,7 @@ nv30_clear_depth_stencil(struct pipe_con
+
+ refn.bo = mt->base.bo;
+ refn.flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_WR;
+- if (nouveau_pushbuf_space(push, 32, 1, 0) ||
++ if (!PUSH_SPACE_EX(push, 32, 1, 0) ||
+ nouveau_pushbuf_refn (push, &refn, 1))
+ return;
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_context.c mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_context.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_context.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_context.c 2022-02-11 14:28:00.534301647 -0600
+@@ -45,7 +45,7 @@ nv30_context_kick_notify(struct nouveau_
+ nv30 = container_of(push->user_priv, struct nv30_context, bufctx);
+ screen = &nv30->screen->base;
+
+- nouveau_fence_next(screen);
++ nouveau_fence_next(&nv30->base);
+ nouveau_fence_update(screen, true);
+
+ if (push->bufctx) {
+@@ -53,13 +53,13 @@ nv30_context_kick_notify(struct nouveau_
+ LIST_FOR_EACH_ENTRY(bref, &push->bufctx->current, thead) {
+ struct nv04_resource *res = bref->priv;
+ if (res && res->mm) {
+- nouveau_fence_ref(screen->fence.current, &res->fence);
++ nouveau_fence_ref(nv30->base.fence, &res->fence);
+
+ if (bref->flags & NOUVEAU_BO_RD)
+ res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
+
+ if (bref->flags & NOUVEAU_BO_WR) {
+- nouveau_fence_ref(screen->fence.current, &res->fence_wr);
++ nouveau_fence_ref(nv30->base.fence, &res->fence_wr);
+ res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
+ NOUVEAU_BUFFER_STATUS_DIRTY;
+ }
+@@ -76,7 +76,7 @@ nv30_context_flush(struct pipe_context *
+ struct nouveau_pushbuf *push = nv30->base.pushbuf;
+
+ if (fence)
+- nouveau_fence_ref(nv30->screen->base.fence.current,
++ nouveau_fence_ref(nv30->base.fence,
+ (struct nouveau_fence **)fence);
+
+ PUSH_KICK(push);
+@@ -176,6 +176,7 @@ nv30_context_destroy(struct pipe_context
+ if (nv30->screen->cur_ctx == nv30)
+ nv30->screen->cur_ctx = NULL;
+
++ nouveau_fence_cleanup(&nv30->base);
+ nouveau_context_destroy(&nv30->base);
+ }
+
+@@ -191,7 +192,6 @@ nv30_context_create(struct pipe_screen *
+ {
+ struct nv30_screen *screen = nv30_screen(pscreen);
+ struct nv30_context *nv30 = CALLOC_STRUCT(nv30_context);
+- struct nouveau_pushbuf *push;
+ struct pipe_context *pipe;
+ int ret;
+
+@@ -199,7 +199,6 @@ nv30_context_create(struct pipe_screen *
+ return NULL;
+
+ nv30->screen = screen;
+- nv30->base.screen = &screen->base;
+ nv30->base.copy_data = nv30_transfer_copy_data;
+
+ pipe = &nv30->base.pipe;
+@@ -208,6 +207,9 @@ nv30_context_create(struct pipe_screen *
+ pipe->destroy = nv30_context_destroy;
+ pipe->flush = nv30_context_flush;
+
++ nouveau_context_init(&nv30->base, &screen->base);
++ nv30->base.pushbuf->kick_notify = nv30_context_kick_notify;
++
+ nv30->base.pipe.stream_uploader = u_upload_create_default(&nv30->base.pipe);
+ if (!nv30->base.pipe.stream_uploader) {
+ nv30_context_destroy(pipe);
+@@ -215,14 +217,6 @@ nv30_context_create(struct pipe_screen *
+ }
+ nv30->base.pipe.const_uploader = nv30->base.pipe.stream_uploader;
+
+- /*XXX: *cough* per-context client */
+- nv30->base.client = screen->base.client;
+-
+- /*XXX: *cough* per-context pushbufs */
+- push = screen->base.pushbuf;
+- nv30->base.pushbuf = push;
+- push->kick_notify = nv30_context_kick_notify;
+-
+ nv30->base.invalidate_resource_storage = nv30_invalidate_resource_storage;
+
+ ret = nouveau_bufctx_new(nv30->base.client, 64, &nv30->bufctx);
+@@ -244,7 +238,6 @@ nv30_context_create(struct pipe_screen *
+ if (debug_get_bool_option("NV30_SWTNL", false))
+ nv30->draw_flags |= NV30_NEW_SWTNL;
+
+- nouveau_context_init(&nv30->base);
+ nv30->sample_mask = 0xffff;
+ nv30_vbo_init(pipe);
+ nv30_query_init(pipe);
+@@ -265,6 +258,7 @@ nv30_context_create(struct pipe_screen *
+ }
+
+ nouveau_context_init_vdec(&nv30->base);
++ nouveau_fence_new(&nv30->base, &nv30->base.fence);
+
+ return pipe;
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_draw.c mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_draw.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_draw.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_draw.c 2022-02-11 14:28:44.868118544 -0600
+@@ -124,7 +124,7 @@ nv30_render_draw_elements(struct vbuf_re
+ {
+ struct nv30_render *r = nv30_render(render);
+ struct nv30_context *nv30 = r->nv30;
+- struct nouveau_pushbuf *push = nv30->screen->base.pushbuf;
++ struct nouveau_pushbuf *push = nv30->base.pushbuf;
+ unsigned i;
+
+ BEGIN_NV04(push, NV30_3D(VTXBUF(0)), r->vertex_info.num_attribs);
+@@ -280,7 +280,7 @@ nv30_render_validate(struct nv30_context
+ struct nv30_render *r = nv30_render(nv30->draw->render);
+ struct nv30_rasterizer_stateobj *rast = nv30->rast;
+ struct pipe_screen *pscreen = &nv30->screen->base.base;
+- struct nouveau_pushbuf *push = nv30->screen->base.pushbuf;
++ struct nouveau_pushbuf *push = nv30->base.pushbuf;
+ struct nouveau_object *eng3d = nv30->screen->eng3d;
+ struct nv30_vertprog *vp = nv30->vertprog.program;
+ struct vertex_info *vinfo = &r->vertex_info;
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_miptree.c mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_miptree.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_miptree.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_miptree.c 2022-02-11 14:29:22.740961717 -0600
+@@ -359,7 +359,7 @@ nv30_miptree_transfer_map(struct pipe_co
+ if (usage & PIPE_MAP_WRITE)
+ access |= NOUVEAU_BO_WR;
+
+- ret = nouveau_bo_map(tx->tmp.bo, access, nv30->base.client);
++ ret = BO_MAP(nv30->base.screen, tx->tmp.bo, access, nv30->base.client);
+ if (ret) {
+ pipe_resource_reference(&tx->base.resource, NULL);
+ FREE(tx);
+@@ -393,7 +393,7 @@ nv30_miptree_transfer_unmap(struct pipe_
+ }
+
+ /* Allow the copies above to finish executing before freeing the source */
+- nouveau_fence_work(nv30->screen->base.fence.current,
++ nouveau_fence_work(nv30->base.fence,
+ nouveau_fence_unref_bo, tx->tmp.bo);
+ } else {
+ nouveau_bo_ref(NULL, &tx->tmp.bo);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_screen.c mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_screen.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_screen.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_screen.c 2022-02-11 14:30:44.381622525 -0600
+@@ -508,8 +508,6 @@ nv30_screen_destroy(struct pipe_screen *
+ if (!nouveau_drm_screen_unref(&screen->base))
+ return;
+
+- nouveau_fence_cleanup(&screen->base);
+-
+ nouveau_bo_ref(NULL, &screen->notify);
+
+ nouveau_heap_destroy(&screen->query_heap);
+@@ -684,7 +682,7 @@ nv30_screen_create(struct nouveau_device
+
+ ret = nouveau_bo_wrap(screen->base.device, fifo->notify, &screen->notify);
+ if (ret == 0)
+- ret = nouveau_bo_map(screen->notify, 0, screen->base.client);
++ ret = BO_MAP(&screen->base, screen->notify, 0, screen->base.client);
+ if (ret)
+ FAIL_SCREEN_INIT("error mapping notifier memory: %d\n", ret);
+
+@@ -811,9 +809,7 @@ nv30_screen_create(struct nouveau_device
+ PUSH_DATA (push, screen->ntfy->handle);
+ BEGIN_NV04(push, NV05_SIFM(COLOR_CONVERSION), 1);
+ PUSH_DATA (push, NV05_SIFM_COLOR_CONVERSION_TRUNCATE);
++ PUSH_KICK (push);
+
+- nouveau_pushbuf_kick(push, push->channel);
+-
+- nouveau_fence_new(&screen->base, &screen->base.fence.current);
+ return &screen->base;
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_state_validate.c 2022-02-11 14:32:00.766303956 -0600
+@@ -463,7 +463,6 @@ nv30_state_context_switch(struct nv30_co
+ bool
+ nv30_state_validate(struct nv30_context *nv30, uint32_t mask, bool hwtnl)
+ {
+- struct nouveau_screen *screen = &nv30->screen->base;
+ struct nouveau_pushbuf *push = nv30->base.pushbuf;
+ struct nouveau_bufctx *bctx = nv30->bufctx;
+ struct nouveau_bufref *bref;
+@@ -499,7 +498,7 @@ nv30_state_validate(struct nv30_context
+ }
+
+ nouveau_pushbuf_bufctx(push, bctx);
+- if (nouveau_pushbuf_validate(push)) {
++ if (PUSH_VAL(push)) {
+ nouveau_pushbuf_bufctx(push, NULL);
+ return false;
+ }
+@@ -523,13 +522,13 @@ nv30_state_validate(struct nv30_context
+ LIST_FOR_EACH_ENTRY(bref, &bctx->current, thead) {
+ struct nv04_resource *res = bref->priv;
+ if (res && res->mm) {
+- nouveau_fence_ref(screen->fence.current, &res->fence);
++ nouveau_fence_ref(nv30->base.fence, &res->fence);
+
+ if (bref->flags & NOUVEAU_BO_RD)
+ res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
+
+ if (bref->flags & NOUVEAU_BO_WR) {
+- nouveau_fence_ref(screen->fence.current, &res->fence_wr);
++ nouveau_fence_ref(nv30->base.fence, &res->fence_wr);
+ res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING;
+ }
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_transfer.c mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_transfer.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv30/nv30_transfer.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv30/nv30_transfer.c 2022-02-11 14:35:05.786902168 -0600
+@@ -155,7 +155,7 @@ nv30_transfer_rect_blit(XFER_ARGS)
+ u32 texfmt, texswz;
+ u32 format, stride;
+
+- if (nouveau_pushbuf_space(push, 512, 8, 0) ||
++ if (!PUSH_SPACE_EX(push, 512, 8, 0) ||
+ nouveau_pushbuf_refn (push, refs, ARRAY_SIZE(refs)))
+ return;
+
+@@ -431,7 +431,7 @@ nv30_transfer_rect_sifm(XFER_ARGS)
+ si_arg |= NV03_SIFM_FORMAT_FILTER_BILINEAR;
+ }
+
+- if (nouveau_pushbuf_space(push, 64, 6, 0) ||
++ if (!PUSH_SPACE_EX(push, 64, 6, 0) ||
+ nouveau_pushbuf_refn (push, refs, 2))
+ return;
+
+@@ -516,7 +516,7 @@ nv30_transfer_rect_m2mf(XFER_ARGS)
+ while (h) {
+ unsigned lines = (h > 2047) ? 2047 : h;
+
+- if (nouveau_pushbuf_space(push, 32, 2, 0) ||
++ if (!PUSH_SPACE_EX(push, 32, 2, 0) ||
+ nouveau_pushbuf_refn (push, refs, 2))
+ return;
+
+@@ -635,8 +635,8 @@ nv30_transfer_rect_cpu(XFER_ARGS)
+ char *srcmap, *dstmap;
+ int x, y;
+
+- nouveau_bo_map(src->bo, NOUVEAU_BO_RD, nv30->base.client);
+- nouveau_bo_map(dst->bo, NOUVEAU_BO_WR, nv30->base.client);
++ BO_MAP(nv30->base.screen, src->bo, NOUVEAU_BO_RD, nv30->base.client);
++ BO_MAP(nv30->base.screen, dst->bo, NOUVEAU_BO_WR, nv30->base.client);
+ srcmap = src->bo->map + src->offset;
+ dstmap = dst->bo->map + dst->offset;
+
+@@ -708,7 +708,7 @@ nv30_transfer_copy_data(struct nouveau_c
+ lines = (pages > 2047) ? 2047 : pages;
+ pages -= lines;
+
+- if (nouveau_pushbuf_space(push, 32, 2, 0) ||
++ if (!PUSH_SPACE_EX(push, 32, 2, 0) ||
+ nouveau_pushbuf_refn (push, refs, 2))
+ return;
+
+@@ -732,7 +732,7 @@ nv30_transfer_copy_data(struct nouveau_c
+ }
+
+ if (size) {
+- if (nouveau_pushbuf_space(push, 32, 2, 0) ||
++ if (!PUSH_SPACE_EX(push, 32, 2, 0) ||
+ nouveau_pushbuf_refn (push, refs, 2))
+ return;
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_compute.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_compute.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_compute.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_compute.c 2022-02-11 14:39:27.849132704 -0600
+@@ -518,7 +518,7 @@ nv50_state_validate_cp(struct nv50_conte
+ nv50->bufctx_cp);
+
+ if (unlikely(nv50->state.flushed))
+- nv50_bufctx_fence(nv50->bufctx_cp, true);
++ nv50_bufctx_fence(nv50, nv50->bufctx_cp, true);
+ return ret;
+ }
+
+@@ -526,7 +526,7 @@ static void
+ nv50_compute_upload_input(struct nv50_context *nv50, const uint32_t *input)
+ {
+ struct nv50_screen *screen = nv50->screen;
+- struct nouveau_pushbuf *push = screen->base.pushbuf;
++ struct nouveau_pushbuf *push = nv50->base.pushbuf;
+ unsigned size = align(nv50->compprog->parm_size, 0x4);
+
+ BEGIN_NV04(push, NV50_CP(USER_PARAM_COUNT), 1);
+@@ -540,19 +540,19 @@ nv50_compute_upload_input(struct nv50_co
+ mm = nouveau_mm_allocate(screen->base.mm_GART, size, &bo, &offset);
+ assert(mm);
+
+- nouveau_bo_map(bo, 0, screen->base.client);
++ BO_MAP(&screen->base, bo, 0, nv50->base.client);
+ memcpy(bo->map + offset, input, size);
+
+ nouveau_bufctx_refn(nv50->bufctx, 0, bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);
+ nouveau_pushbuf_bufctx(push, nv50->bufctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+- nouveau_pushbuf_space(push, 0, 0, 1);
++ PUSH_SPACE_EX(push, 0, 0, 1);
+
+ BEGIN_NV04(push, NV50_CP(USER_PARAM(1)), size / 4);
+ nouveau_pushbuf_data(push, bo, offset, size);
+
+- nouveau_fence_work(screen->base.fence.current, nouveau_mm_free_work, mm);
++ nouveau_fence_work(nv50->base.fence, nouveau_mm_free_work, mm);
+ nouveau_bo_ref(NULL, &bo);
+ nouveau_bufctx_reset(nv50->bufctx, 0);
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_context.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_context.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_context.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_context.c 2022-02-11 17:44:52.706228555 -0600
+@@ -34,9 +34,10 @@ nv50_flush(struct pipe_context *pipe,
+ unsigned flags)
+ {
+ struct nouveau_screen *screen = nouveau_screen(pipe->screen);
++ struct nouveau_context *context = nouveau_context(pipe);
+
+ if (fence)
+- nouveau_fence_ref(screen->fence.current, (struct nouveau_fence **)fence);
++ nouveau_fence_ref(context->fence, (struct nouveau_fence **)fence);
+
+ PUSH_KICK(screen->pushbuf);
+
+@@ -135,12 +136,12 @@ void
+ nv50_default_kick_notify(struct nouveau_pushbuf *push)
+ {
+ struct nv50_screen *screen = push->user_priv;
++ struct nv50_context *context = screen->cur_ctx;
+
+- if (screen) {
+- nouveau_fence_next(&screen->base);
++ if (context) {
++ nouveau_fence_next(&context->base);
+ nouveau_fence_update(&screen->base, true);
+- if (screen->cur_ctx)
+- screen->cur_ctx->state.flushed = true;
++ context->state.flushed = true;
+ }
+ }
+
+@@ -193,12 +194,13 @@ nv50_destroy(struct pipe_context *pipe)
+ u_upload_destroy(nv50->base.pipe.stream_uploader);
+
+ nouveau_pushbuf_bufctx(nv50->base.pushbuf, NULL);
+- nouveau_pushbuf_kick(nv50->base.pushbuf, nv50->base.pushbuf->channel);
++ PUSH_KICK(nv50->base.pushbuf);
+
+ nv50_context_unreference_resources(nv50);
+
+ FREE(nv50->blit);
+
++ nouveau_fence_cleanup(&nv50->base);
+ nouveau_context_destroy(&nv50->base);
+ }
+
+@@ -312,20 +314,18 @@ nv50_create(struct pipe_screen *pscreen,
+ if (!nv50_blitctx_create(nv50))
+ goto out_err;
+
+- nv50->base.pushbuf = screen->base.pushbuf;
+- nv50->base.client = screen->base.client;
++ nouveau_context_init(&nv50->base, &screen->base);
+
+- ret = nouveau_bufctx_new(screen->base.client, 2, &nv50->bufctx);
++ ret = nouveau_bufctx_new(nv50->base.client, 2, &nv50->bufctx);
+ if (!ret)
+- ret = nouveau_bufctx_new(screen->base.client, NV50_BIND_3D_COUNT,
++ ret = nouveau_bufctx_new(nv50->base.client, NV50_BIND_3D_COUNT,
+ &nv50->bufctx_3d);
+ if (!ret)
+- ret = nouveau_bufctx_new(screen->base.client, NV50_BIND_CP_COUNT,
++ ret = nouveau_bufctx_new(nv50->base.client, NV50_BIND_CP_COUNT,
+ &nv50->bufctx_cp);
+ if (ret)
+ goto out_err;
+
+- nv50->base.screen = &screen->base;
+ nv50->base.copy_data = nv50_m2mf_copy_linear;
+ nv50->base.push_data = nv50_sifc_linear_u8;
+ nv50->base.push_cb = nv50_cb_push;
+@@ -360,7 +360,6 @@ nv50_create(struct pipe_screen *pscreen,
+ }
+ nv50->base.pushbuf->kick_notify = nv50_default_kick_notify;
+
+- nouveau_context_init(&nv50->base);
+ nv50_init_query_functions(nv50);
+ nv50_init_surface_functions(nv50);
+ nv50_init_state_functions(nv50);
+@@ -416,6 +415,8 @@ nv50_create(struct pipe_screen *pscreen,
+ // zero entry if it's not otherwise set.
+ nv50->dirty_3d |= NV50_NEW_3D_SAMPLERS;
+
++ nouveau_fence_new(&nv50->base, &nv50->base.fence);
++
+ return pipe;
+
+ out_err:
+@@ -433,7 +434,7 @@ out_err:
+ }
+
+ void
+-nv50_bufctx_fence(struct nouveau_bufctx *bufctx, bool on_flush)
++nv50_bufctx_fence(struct nv50_context *nv50, struct nouveau_bufctx *bufctx, bool on_flush)
+ {
+ struct nouveau_list *list = on_flush ? &bufctx->current : &bufctx->pending;
+ struct nouveau_list *it;
+@@ -442,7 +443,7 @@ nv50_bufctx_fence(struct nouveau_bufctx
+ struct nouveau_bufref *ref = (struct nouveau_bufref *)it;
+ struct nv04_resource *res = ref->priv;
+ if (res)
+- nv50_resource_validate(res, (unsigned)ref->priv_data);
++ nv50_resource_validate(nv50, res, (unsigned)ref->priv_data);
+ }
+ }
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_context.h mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_context.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_context.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_context.h 2022-02-11 14:48:38.488869249 -0600
+@@ -254,10 +254,28 @@ nv50_context_shader_stage(unsigned pipe)
+ }
+ }
+
++static inline void
++nv50_resource_validate(struct nv50_context *context, struct nv04_resource *res, uint32_t flags)
++{
++ if (likely(res->bo)) {
++ if (flags & NOUVEAU_BO_WR)
++ res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
++ NOUVEAU_BUFFER_STATUS_DIRTY;
++ if (flags & NOUVEAU_BO_RD)
++ res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
++
++ if (res->mm) {
++ nouveau_fence_ref(context->base.fence, &res->fence);
++ if (flags & NOUVEAU_BO_WR)
++ nouveau_fence_ref(context->base.fence, &res->fence_wr);
++ }
++ }
++}
++
+ /* nv50_context.c */
+ struct pipe_context *nv50_create(struct pipe_screen *, void *, unsigned flags);
+
+-void nv50_bufctx_fence(struct nouveau_bufctx *, bool on_flush);
++void nv50_bufctx_fence(struct nv50_context *, struct nouveau_bufctx *, bool on_flush);
+
+ void nv50_default_kick_notify(struct nouveau_pushbuf *);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_miptree.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_miptree.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_miptree.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_miptree.c 2022-02-11 14:49:23.116575689 -0600
+@@ -163,11 +163,7 @@ nv50_miptree_destroy(struct pipe_screen
+ {
+ struct nv50_miptree *mt = nv50_miptree(pt);
+
+- if (mt->base.fence && mt->base.fence->state < NOUVEAU_FENCE_STATE_FLUSHED)
+- nouveau_fence_work(mt->base.fence, nouveau_fence_unref_bo, mt->base.bo);
+- else
+- nouveau_bo_ref(NULL, &mt->base.bo);
+-
++ nouveau_fence_work(mt->base.fence, nouveau_fence_unref_bo, mt->base.bo);
+ nouveau_fence_ref(NULL, &mt->base.fence);
+ nouveau_fence_ref(NULL, &mt->base.fence_wr);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_query_hw.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_query_hw.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_query_hw.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_query_hw.c 2022-02-11 14:53:02.848195107 -0600
+@@ -52,7 +52,7 @@ nv50_hw_query_allocate(struct nv50_conte
+ if (hq->state == NV50_HW_QUERY_STATE_READY)
+ nouveau_mm_free(hq->mm);
+ else
+- nouveau_fence_work(screen->base.fence.current,
++ nouveau_fence_work(nv50->base.fence,
+ nouveau_mm_free_work, hq->mm);
+ }
+ }
+@@ -63,7 +63,7 @@ nv50_hw_query_allocate(struct nv50_conte
+ return false;
+ hq->offset = hq->base_offset;
+
+- ret = nouveau_bo_map(hq->bo, 0, screen->base.client);
++ ret = BO_MAP(&screen->base, hq->bo, 0, nv50->base.client);
+ if (ret) {
+ nv50_hw_query_allocate(nv50, q, 0);
+ return false;
+@@ -265,7 +265,7 @@ nv50_hw_end_query(struct nv50_context *n
+ break;
+ }
+ if (hq->is64bit)
+- nouveau_fence_ref(nv50->screen->base.fence.current, &hq->fence);
++ nouveau_fence_ref(nv50->base.fence, &hq->fence);
+ }
+
+ static bool
+@@ -294,7 +294,7 @@ nv50_hw_get_query_result(struct nv50_con
+ }
+ return false;
+ }
+- if (nouveau_bo_wait(hq->bo, NOUVEAU_BO_RD, nv50->screen->base.client))
++ if (BO_WAIT(&nv50->screen->base, hq->bo, NOUVEAU_BO_RD, nv50->base.client))
+ return false;
+ }
+ hq->state = NV50_HW_QUERY_STATE_READY;
+@@ -447,14 +447,15 @@ nv50_hw_get_driver_query_info(struct nv5
+ }
+
+ void
+-nv50_hw_query_pushbuf_submit(struct nouveau_pushbuf *push, uint16_t method,
++nv50_hw_query_pushbuf_submit(struct nv50_context *nv50, uint16_t method,
+ struct nv50_query *q, unsigned result_offset)
+ {
++ struct nouveau_pushbuf *push = nv50->base.pushbuf;
+ struct nv50_hw_query *hq = nv50_hw_query(q);
+
+ nv50_hw_query_update(q);
+ if (hq->state != NV50_HW_QUERY_STATE_READY)
+- nouveau_bo_wait(hq->bo, NOUVEAU_BO_RD, push->client);
++ BO_WAIT(&nv50->screen->base, hq->bo, NOUVEAU_BO_RD, push->client);
+ hq->state = NV50_HW_QUERY_STATE_READY;
+
+ BEGIN_NV04(push, SUBC_3D(method), 1);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_query_hw.h mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_query_hw.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_query_hw.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_query_hw.h 2022-02-11 14:53:21.749080536 -0600
+@@ -52,7 +52,7 @@ nv50_hw_get_driver_query_info(struct nv5
+ bool
+ nv50_hw_query_allocate(struct nv50_context *, struct nv50_query *, int);
+ void
+-nv50_hw_query_pushbuf_submit(struct nouveau_pushbuf *, uint16_t,
++nv50_hw_query_pushbuf_submit(struct nv50_context *, uint16_t,
+ struct nv50_query *, unsigned);
+ void
+ nv84_hw_query_fifo_wait(struct nouveau_pushbuf *, struct nv50_query *);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_query_hw_sm.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_query_hw_sm.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_query_hw_sm.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_query_hw_sm.c 2022-02-11 14:54:28.454680509 -0600
+@@ -321,7 +321,7 @@ nv50_hw_sm_query_read_data(uint32_t coun
+ if (hq->data[b + 4] != hq->sequence) {
+ if (!wait)
+ return false;
+- if (nouveau_bo_wait(hq->bo, NOUVEAU_BO_RD, nv50->base.client))
++ if (BO_WAIT(&nv50->screen->base, hq->bo, NOUVEAU_BO_RD, nv50->base.client))
+ return false;
+ }
+ count[p][c] = hq->data[b + hsq->ctr[c]];
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_screen.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_screen.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_screen.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_screen.c 2022-02-11 14:55:45.692224889 -0600
+@@ -595,8 +595,6 @@ nv50_screen_destroy(struct pipe_screen *
+ if (!nouveau_drm_screen_unref(&screen->base))
+ return;
+
+- nouveau_fence_cleanup(&screen->base);
+-
+ if (screen->base.pushbuf)
+ screen->base.pushbuf->user_priv = NULL;
+
+@@ -1074,7 +1072,7 @@ nv50_screen_create(struct nouveau_device
+ goto fail;
+ }
+
+- nouveau_bo_map(screen->fence.bo, 0, NULL);
++ BO_MAP(&screen->base, screen->fence.bo, 0, NULL);
+ screen->fence.map = screen->fence.bo->map;
+ screen->base.fence.emit = nv50_screen_fence_emit;
+ screen->base.fence.update = nv50_screen_fence_update;
+@@ -1217,8 +1215,6 @@ nv50_screen_create(struct nouveau_device
+ goto fail;
+ }
+
+- nouveau_fence_new(&screen->base, &screen->base.fence.current);
+-
+ return &screen->base;
+
+ fail:
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_screen.h mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_screen.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_screen.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_screen.h 2022-02-11 14:56:32.391952891 -0600
+@@ -133,32 +133,6 @@ int nv50_screen_tsc_alloc(struct nv50_sc
+
+ int nv50_screen_compute_setup(struct nv50_screen *, struct nouveau_pushbuf *);
+
+-static inline void
+-nv50_resource_fence(struct nv04_resource *res, uint32_t flags)
+-{
+- struct nv50_screen *screen = nv50_screen(res->base.screen);
+-
+- if (res->mm) {
+- nouveau_fence_ref(screen->base.fence.current, &res->fence);
+- if (flags & NOUVEAU_BO_WR)
+- nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
+- }
+-}
+-
+-static inline void
+-nv50_resource_validate(struct nv04_resource *res, uint32_t flags)
+-{
+- if (likely(res->bo)) {
+- if (flags & NOUVEAU_BO_WR)
+- res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
+- NOUVEAU_BUFFER_STATUS_DIRTY;
+- if (flags & NOUVEAU_BO_RD)
+- res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
+-
+- nv50_resource_fence(res, flags);
+- }
+-}
+-
+ struct nv50_format {
+ uint32_t rt;
+ struct {
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_shader_state.c 2022-02-11 14:56:59.654795192 -0600
+@@ -717,7 +717,7 @@ nv50_stream_output_validate(struct nv50_
+ PUSH_DATA(push, targ->pipe.buffer_size);
+ if (!targ->clean) {
+ assert(targ->pq);
+- nv50_hw_query_pushbuf_submit(push, NVA0_3D_STRMOUT_OFFSET(i),
++ nv50_hw_query_pushbuf_submit(nv50, NVA0_3D_STRMOUT_OFFSET(i),
+ nv50_query(targ->pq), 0x4);
+ } else {
+ BEGIN_NV04(push, NVA0_3D(STRMOUT_OFFSET(i)), 1);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_state_validate.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_state_validate.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_state_validate.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_state_validate.c 2022-02-11 14:58:09.012397327 -0600
+@@ -556,10 +556,10 @@ nv50_state_validate(struct nv50_context
+ PUSH_DATA (nv50->base.pushbuf, 0);
+ }
+
+- nv50_bufctx_fence(bufctx, false);
++ nv50_bufctx_fence(nv50, bufctx, false);
+ }
+ nouveau_pushbuf_bufctx(nv50->base.pushbuf, bufctx);
+- ret = nouveau_pushbuf_validate(nv50->base.pushbuf);
++ ret = PUSH_VAL(nv50->base.pushbuf);
+
+ return !ret;
+ }
+@@ -575,7 +575,7 @@ nv50_state_validate_3d(struct nv50_conte
+
+ if (unlikely(nv50->state.flushed)) {
+ nv50->state.flushed = false;
+- nv50_bufctx_fence(nv50->bufctx_3d, true);
++ nv50_bufctx_fence(nv50, nv50->bufctx_3d, true);
+ }
+ return ret;
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_surface.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_surface.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_surface.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_surface.c 2022-02-11 18:05:39.993075211 -0600
+@@ -257,7 +257,7 @@ nv50_resource_copy_region(struct pipe_co
+ BCTX_REFN(nv50->bufctx, 2D, nv04_resource(src), RD);
+ BCTX_REFN(nv50->bufctx, 2D, nv04_resource(dst), WR);
+ nouveau_pushbuf_bufctx(nv50->base.pushbuf, nv50->bufctx);
+- nouveau_pushbuf_validate(nv50->base.pushbuf);
++ PUSH_VAL(nv50->base.pushbuf);
+
+ for (; dst_layer < dstz + src_box->depth; ++dst_layer, ++src_layer) {
+ ret = nv50_2d_texture_do_copy(nv50->base.pushbuf,
+@@ -295,7 +295,7 @@ nv50_clear_render_target(struct pipe_con
+ PUSH_DATAf(push, color->f[2]);
+ PUSH_DATAf(push, color->f[3]);
+
+- if (nouveau_pushbuf_space(push, 64 + sf->depth, 1, 0))
++ if (!PUSH_SPACE_EX(push, 64 + sf->depth, 1, 0))
+ return;
+
+ PUSH_REFN(push, bo, mt->base.domain | NOUVEAU_BO_WR);
+@@ -394,7 +394,7 @@ nv50_clear_depth_stencil(struct pipe_con
+ mode |= NV50_3D_CLEAR_BUFFERS_S;
+ }
+
+- if (nouveau_pushbuf_space(push, 64 + sf->depth, 1, 0))
++ if (!PUSH_SPACE_EX(push, 64 + sf->depth, 1, 0))
+ return;
+
+ PUSH_REFN(push, bo, mt->base.domain | NOUVEAU_BO_WR);
+@@ -653,7 +653,7 @@ nv50_clear_buffer_push(struct pipe_conte
+
+ nouveau_bufctx_refn(nv50->bufctx, 0, buf->bo, buf->domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, nv50->bufctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ offset &= ~0xff;
+
+@@ -692,7 +692,7 @@ nv50_clear_buffer_push(struct pipe_conte
+ count -= nr;
+ }
+
+- nv50_resource_validate(buf, NOUVEAU_BO_WR);
++ nv50_resource_validate(nv50, buf, NOUVEAU_BO_WR);
+
+ nouveau_bufctx_reset(nv50->bufctx, 0);
+ }
+@@ -771,7 +771,7 @@ nv50_clear_buffer(struct pipe_context *p
+ PUSH_DATA (push, color.ui[2]);
+ PUSH_DATA (push, color.ui[3]);
+
+- if (nouveau_pushbuf_space(push, 64, 1, 0))
++ if (!PUSH_SPACE_EX(push, 64, 1, 0))
+ return;
+
+ PUSH_REFN(push, buf->bo, buf->domain | NOUVEAU_BO_WR);
+@@ -815,7 +815,7 @@ nv50_clear_buffer(struct pipe_context *p
+ BEGIN_NV04(push, NV50_3D(COND_MODE), 1);
+ PUSH_DATA (push, nv50->cond_condmode);
+
+- nv50_resource_validate(buf, NOUVEAU_BO_WR);
++ nv50_resource_validate(nv50, buf, NOUVEAU_BO_WR);
+
+ if (width * height != elements) {
+ offset += width * height * data_size;
+@@ -1639,7 +1639,7 @@ nv50_blit_eng2d(struct nv50_context *nv5
+ BCTX_REFN(nv50->bufctx, 2D, &dst->base, WR);
+ BCTX_REFN(nv50->bufctx, 2D, &src->base, RD);
+ nouveau_pushbuf_bufctx(nv50->base.pushbuf, nv50->bufctx);
+- if (nouveau_pushbuf_validate(nv50->base.pushbuf))
++ if (PUSH_VAL(nv50->base.pushbuf))
+ return;
+
+ for (i = 0; i < info->dst.box.depth; ++i) {
+@@ -1679,7 +1679,7 @@ nv50_blit_eng2d(struct nv50_context *nv5
+ PUSH_DATA (push, srcy >> 32);
+ }
+ }
+- nv50_bufctx_fence(nv50->bufctx, false);
++ nv50_bufctx_fence(nv50, nv50->bufctx, false);
+
+ nouveau_bufctx_reset(nv50->bufctx, NV50_BIND_2D);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_transfer.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_transfer.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_transfer.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_transfer.c 2022-02-11 15:02:10.331043100 -0600
+@@ -67,7 +67,7 @@ nv50_2d_transfer_rect(struct nv50_contex
+ nouveau_bufctx_refn(bctx, 0, src->bo, src->domain | NOUVEAU_BO_RD);
+ nouveau_bufctx_refn(bctx, 0, dst->bo, dst->domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, bctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ uint32_t format;
+ switch (cpp) {
+@@ -197,7 +197,7 @@ nv50_m2mf_transfer_rect(struct nv50_cont
+ nouveau_bufctx_refn(bctx, 0, src->bo, src->domain | NOUVEAU_BO_RD);
+ nouveau_bufctx_refn(bctx, 0, dst->bo, dst->domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, bctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ if (nouveau_bo_memtype(src->bo)) {
+ BEGIN_NV04(push, NV50_M2MF(LINEAR_IN), 6);
+@@ -284,7 +284,7 @@ nv50_sifc_linear_u8(struct nouveau_conte
+
+ nouveau_bufctx_refn(nv50->bufctx, 0, dst, domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, nv50->bufctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ offset &= ~0xff;
+
+@@ -337,7 +337,7 @@ nv50_m2mf_copy_linear(struct nouveau_con
+ nouveau_bufctx_refn(bctx, 0, src, srcdom | NOUVEAU_BO_RD);
+ nouveau_bufctx_refn(bctx, 0, dst, dstdom | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, bctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ BEGIN_NV04(push, NV50_M2MF(LINEAR_IN), 1);
+ PUSH_DATA (push, 1);
+@@ -375,7 +375,6 @@ nv50_miptree_transfer_map(struct pipe_co
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
+ {
+- struct nv50_screen *screen = nv50_screen(pctx->screen);
+ struct nv50_context *nv50 = nv50_context(pctx);
+ struct nouveau_device *dev = nv50->screen->base.device;
+ const struct nv50_miptree *mt = nv50_miptree(res);
+@@ -454,7 +453,7 @@ nv50_miptree_transfer_map(struct pipe_co
+ if (usage & PIPE_MAP_WRITE)
+ flags |= NOUVEAU_BO_WR;
+
+- ret = nouveau_bo_map(tx->rect[1].bo, flags, screen->base.client);
++ ret = BO_MAP(nv50->base.screen, tx->rect[1].bo, flags, nv50->base.client);
+ if (ret) {
+ nouveau_bo_ref(NULL, &tx->rect[1].bo);
+ FREE(tx);
+@@ -486,7 +485,7 @@ nv50_miptree_transfer_unmap(struct pipe_
+ }
+
+ /* Allow the copies above to finish executing before freeing the source */
+- nouveau_fence_work(nv50->screen->base.fence.current,
++ nouveau_fence_work(nv50->base.fence,
+ nouveau_fence_unref_bo, tx->rect[1].bo);
+ } else {
+ nouveau_bo_ref(NULL, &tx->rect[1].bo);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_vbo.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_vbo.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv50_vbo.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv50_vbo.c 2022-02-11 15:03:36.446568575 -0600
+@@ -624,14 +624,14 @@ nv50_draw_elements(struct nv50_context *
+ * the not-yet-written data. Ideally this wait would only happen on
+ * pushbuf submit, but it's probably not a big performance difference.
+ */
+- if (buf->fence_wr && !nouveau_fence_signalled(buf->fence_wr))
++ if (buf->fence_wr)
+ nouveau_fence_wait(buf->fence_wr, &nv50->base.debug);
+
+ while (instance_count--) {
+ BEGIN_NV04(push, NV50_3D(VERTEX_BEGIN_GL), 1);
+ PUSH_DATA (push, prim);
+
+- nouveau_pushbuf_space(push, 16, 0, 1);
++ PUSH_SPACE_EX(push, 16, 0, 1);
+ PUSH_REFN(push, buf->bo, NOUVEAU_BO_RD | buf->domain);
+
+ switch (index_size) {
+@@ -737,7 +737,7 @@ nva0_draw_stream_output(struct nv50_cont
+ PUSH_DATA (push, 0);
+ BEGIN_NV04(push, NVA0_3D(DRAW_TFB_STRIDE), 1);
+ PUSH_DATA (push, so->stride);
+- nv50_hw_query_pushbuf_submit(push, NVA0_3D_DRAW_TFB_BYTES,
++ nv50_hw_query_pushbuf_submit(nv50, NVA0_3D_DRAW_TFB_BYTES,
+ nv50_query(so->pq), 0x4);
+ BEGIN_NV04(push, NV50_3D(VERTEX_END_GL), 1);
+ PUSH_DATA (push, 0);
+@@ -752,8 +752,6 @@ nv50_draw_vbo_kick_notify(struct nouveau
+ struct nv50_screen *screen = chan->user_priv;
+
+ nouveau_fence_update(&screen->base, true);
+-
+- nv50_bufctx_fence(screen->cur_ctx->bufctx_3d, true);
+ }
+
+ void
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv84_video_bsp.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv84_video_bsp.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv84_video_bsp.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv84_video_bsp.c 2022-02-11 15:09:14.426111024 -0600
+@@ -89,6 +89,7 @@ nv84_decoder_bsp(struct nv84_decoder *de
+ const unsigned *num_bytes,
+ struct nv84_video_buffer *dest)
+ {
++ struct nouveau_screen *screen = nouveau_screen(dec->base.context->screen);
+ struct iparm params;
+ uint32_t more_params[0x44 / 4] = {0};
+ unsigned total_bytes = 0;
+@@ -103,7 +104,7 @@ nv84_decoder_bsp(struct nv84_decoder *de
+ { dec->fence, NOUVEAU_BO_RDWR | NOUVEAU_BO_VRAM },
+ };
+
+- nouveau_bo_wait(dec->fence, NOUVEAU_BO_RDWR, dec->client);
++ BO_WAIT(screen, dec->fence, NOUVEAU_BO_RDWR, dec->client);
+
+ STATIC_ASSERT(sizeof(struct iparm) == 0x530);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv84_video.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv84_video.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv84_video.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv84_video.c 2022-02-11 15:08:27.115135546 -0600
+@@ -69,6 +69,7 @@ nv84_load_firmwares(struct nouveau_devic
+ {
+ int ret, size1, size2 = 0;
+ struct nouveau_bo *fw;
++ struct nouveau_screen *screen = nouveau_screen(dec->base.context->screen);
+
+ size1 = filesize(fw1);
+ if (fw2)
+@@ -81,7 +82,7 @@ nv84_load_firmwares(struct nouveau_devic
+ ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, dec->vp_fw2_offset + size2, NULL, &fw);
+ if (ret)
+ return NULL;
+- ret = nouveau_bo_map(fw, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen, fw, NOUVEAU_BO_WR, dec->client);
+ if (ret)
+ goto error;
+
+@@ -183,11 +184,12 @@ nv84_decoder_begin_frame_mpeg12(struct p
+ struct pipe_video_buffer *target,
+ struct pipe_picture_desc *picture)
+ {
++ struct nouveau_screen *screen = nouveau_screen(decoder->context->screen);
+ struct nv84_decoder *dec = (struct nv84_decoder *)decoder;
+ struct pipe_mpeg12_picture_desc *desc = (struct pipe_mpeg12_picture_desc *)picture;
+ int i;
+
+- nouveau_bo_wait(dec->mpeg12_bo, NOUVEAU_BO_RDWR, dec->client);
++ BO_WAIT(screen, dec->mpeg12_bo, NOUVEAU_BO_RDWR, dec->client);
+ dec->mpeg12_mb_info = dec->mpeg12_bo->map + 0x100;
+ dec->mpeg12_data = dec->mpeg12_bo->map + 0x100 +
+ align(0x20 * mb(dec->base.width) * mb(dec->base.height), 0x100);
+@@ -406,14 +408,14 @@ nv84_create_decoder(struct pipe_context
+ NULL, &dec->bitstream);
+ if (ret)
+ goto fail;
+- ret = nouveau_bo_map(dec->bitstream, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen, dec->bitstream, NOUVEAU_BO_WR, dec->client);
+ if (ret)
+ goto fail;
+ ret = nouveau_bo_new(screen->device, NOUVEAU_BO_GART,
+ 0, 0x2000, NULL, &dec->vp_params);
+ if (ret)
+ goto fail;
+- ret = nouveau_bo_map(dec->vp_params, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen, dec->vp_params, NOUVEAU_BO_WR, dec->client);
+ if (ret)
+ goto fail;
+ }
+@@ -425,7 +427,7 @@ nv84_create_decoder(struct pipe_context
+ NULL, &dec->mpeg12_bo);
+ if (ret)
+ goto fail;
+- ret = nouveau_bo_map(dec->mpeg12_bo, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen,dec->mpeg12_bo, NOUVEAU_BO_WR, dec->client);
+ if (ret)
+ goto fail;
+ }
+@@ -434,7 +436,7 @@ nv84_create_decoder(struct pipe_context
+ 0, 0x1000, NULL, &dec->fence);
+ if (ret)
+ goto fail;
+- ret = nouveau_bo_map(dec->fence, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen, dec->fence, NOUVEAU_BO_WR, dec->client);
+ if (ret)
+ goto fail;
+ *(uint32_t *)dec->fence->map = 0;
+@@ -493,17 +495,17 @@ nv84_create_decoder(struct pipe_context
+ surf.offset = dec->vpring->size - 0x1000;
+ context->clear_render_target(context, &surf.base, &color, 0, 0, 1024, 1, false);
+
+- PUSH_SPACE(screen->pushbuf, 5);
+- PUSH_REFN(screen->pushbuf, dec->fence, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
++ PUSH_SPACE(nv50->base.pushbuf, 5);
++ PUSH_REFN(nv50->base.pushbuf, dec->fence, NOUVEAU_BO_VRAM | NOUVEAU_BO_RDWR);
+ /* The clear_render_target is done via 3D engine, so use it to write to a
+ * sempahore to indicate that it's done.
+ */
+- BEGIN_NV04(screen->pushbuf, NV50_3D(QUERY_ADDRESS_HIGH), 4);
+- PUSH_DATAh(screen->pushbuf, dec->fence->offset);
+- PUSH_DATA (screen->pushbuf, dec->fence->offset);
+- PUSH_DATA (screen->pushbuf, 1);
+- PUSH_DATA (screen->pushbuf, 0xf010);
+- PUSH_KICK (screen->pushbuf);
++ BEGIN_NV04(nv50->base.pushbuf, NV50_3D(QUERY_ADDRESS_HIGH), 4);
++ PUSH_DATAh(nv50->base.pushbuf, dec->fence->offset);
++ PUSH_DATA (nv50->base.pushbuf, dec->fence->offset);
++ PUSH_DATA (nv50->base.pushbuf, 1);
++ PUSH_DATA (nv50->base.pushbuf, 0xf010);
++ PUSH_KICK (nv50->base.pushbuf);
+
+ PUSH_SPACE(bsp_push, 2 + 12 + 2 + 4 + 3);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video_bsp.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video_bsp.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video_bsp.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video_bsp.c 2022-02-11 15:12:36.619828402 -0600
+@@ -39,6 +39,7 @@ nv98_decoder_bsp(struct nouveau_vp3_deco
+ unsigned *vp_caps, unsigned *is_ref,
+ struct nouveau_vp3_video_buffer *refs[16])
+ {
++ struct nouveau_screen *screen = nouveau_screen(dec->base.context->screen);
+ struct nouveau_pushbuf *push = dec->pushbuf[0];
+ enum pipe_video_format codec = u_reduce_video_profile(dec->base.profile);
+ uint32_t bsp_addr, comm_addr, inter_addr;
+@@ -95,7 +96,7 @@ nv98_decoder_bsp(struct nouveau_vp3_deco
+ bo_refs[1].bo = dec->inter_bo[comm_seq & 1] = inter_bo = tmp_bo;
+ }
+
+- ret = nouveau_bo_map(bsp_bo, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen, bsp_bo, NOUVEAU_BO_WR, dec->client);
+ if (ret) {
+ debug_printf("map failed: %i %s\n", ret, strerror(-ret));
+ return -1;
+@@ -107,7 +108,7 @@ nv98_decoder_bsp(struct nouveau_vp3_deco
+
+ nouveau_vp3_vp_caps(dec, desc, target, comm_seq, vp_caps, is_ref, refs);
+
+- nouveau_pushbuf_space(push, 32, num_refs, 0);
++ PUSH_SPACE_EX(push, 32, num_refs, 0);
+ nouveau_pushbuf_refn(push, bo_refs, num_refs);
+
+ bsp_addr = bsp_bo->offset >> 8;
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video.c 2022-02-11 15:11:41.428930690 -0600
+@@ -85,7 +85,8 @@ struct pipe_video_codec *
+ nv98_create_decoder(struct pipe_context *context,
+ const struct pipe_video_codec *templ)
+ {
+- struct nouveau_screen *screen = &((struct nv50_context *)context)->screen->base;
++ struct nv50_context *nv50 = nv50_context(context);
++ struct nouveau_screen *screen = &nv50->screen->base;
+ struct nouveau_vp3_decoder *dec;
+ struct nouveau_pushbuf **push;
+ struct nv04_fifo nv04_data = {.vram = 0xbeef0201, .gart = 0xbeef0202};
+@@ -106,7 +107,7 @@ nv98_create_decoder(struct pipe_context
+ dec = CALLOC_STRUCT(nouveau_vp3_decoder);
+ if (!dec)
+ return NULL;
+- dec->client = screen->client;
++ dec->client = nv50->base.client;
+ dec->base = *templ;
+ nouveau_vp3_decoder_init_common(&dec->base);
+
+@@ -119,7 +120,7 @@ nv98_create_decoder(struct pipe_context
+ &nv04_data, sizeof(nv04_data), &dec->channel[0]);
+
+ if (!ret)
+- ret = nouveau_pushbuf_new(screen->client, dec->channel[0], 4,
++ ret = nouveau_pushbuf_new(nv50->base.client, dec->channel[0], 4,
+ 32 * 1024, true, &dec->pushbuf[0]);
+
+ for (i = 1; i < 3; ++i) {
+@@ -268,13 +269,13 @@ nv98_create_decoder(struct pipe_context
+ if (ret)
+ goto fail;
+
+- nouveau_bo_map(dec->fence_bo, NOUVEAU_BO_RDWR, screen->client);
++ BO_MAP(dec->fence_bo, NOUVEAU_BO_RDWR, screen->client);
+ dec->fence_map = dec->fence_bo->map;
+ dec->fence_map[0] = dec->fence_map[4] = dec->fence_map[8] = 0;
+ dec->comm = (struct comm *)(dec->fence_map + (COMM_OFFSET/sizeof(*dec->fence_map)));
+
+ /* So lets test if the fence is working? */
+- nouveau_pushbuf_space(push[0], 16, 1, 0);
++ PUSH_SPACE_EX(push[0], 16, 1, 0);
+ PUSH_REFN (push[0], dec->fence_bo, NOUVEAU_BO_GART|NOUVEAU_BO_RDWR);
+ BEGIN_NV04(push[0], SUBC_BSP(0x240), 3);
+ PUSH_DATAh(push[0], dec->fence_bo->offset);
+@@ -285,7 +286,7 @@ nv98_create_decoder(struct pipe_context
+ PUSH_DATA (push[0], 0);
+ PUSH_KICK (push[0]);
+
+- nouveau_pushbuf_space(push[1], 16, 1, 0);
++ PUSH_SPACE_EX(push[1], 16, 1, 0);
+ PUSH_REFN (push[1], dec->fence_bo, NOUVEAU_BO_GART|NOUVEAU_BO_RDWR);
+ BEGIN_NV04(push[1], SUBC_VP(0x240), 3);
+ PUSH_DATAh(push[1], (dec->fence_bo->offset + 0x10));
+@@ -296,7 +297,7 @@ nv98_create_decoder(struct pipe_context
+ PUSH_DATA (push[1], 0);
+ PUSH_KICK (push[1]);
+
+- nouveau_pushbuf_space(push[2], 16, 1, 0);
++ PUSH_SPACE_EX(push[2], 16, 1, 0);
+ PUSH_REFN (push[2], dec->fence_bo, NOUVEAU_BO_GART|NOUVEAU_BO_RDWR);
+ BEGIN_NV04(push[2], SUBC_PPP(0x240), 3);
+ PUSH_DATAh(push[2], (dec->fence_bo->offset + 0x20));
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video_ppp.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video_ppp.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video_ppp.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video_ppp.c 2022-02-11 15:12:49.083803035 -0600
+@@ -94,7 +94,7 @@ nv98_decoder_ppp(struct nouveau_vp3_deco
+ struct nouveau_pushbuf *push = dec->pushbuf[2];
+ unsigned ppp_caps = 0x10;
+
+- nouveau_pushbuf_space(push, 32, 4, 0);
++ PUSH_SPACE_EX(push, 32, 4, 0);
+
+ switch (codec) {
+ case PIPE_VIDEO_FORMAT_MPEG12: {
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video_vp.c mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video_vp.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nv50/nv98_video_vp.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nv50/nv98_video_vp.c 2022-02-11 15:13:28.216718331 -0600
+@@ -44,7 +44,7 @@ static void dump_comm_vp(struct nouveau_
+
+ if ((comm->pvp_stage & 0xff) != 0xff) {
+ unsigned *map;
+- int ret = nouveau_bo_map(inter_bo, NOUVEAU_BO_RD|NOUVEAU_BO_NOBLOCK, dec->client);
++ int ret = BO_MAP(inter_bo, NOUVEAU_BO_RD|NOUVEAU_BO_NOBLOCK, dec->client);
+ assert(ret >= 0);
+ map = inter_bo->map;
+ for (i = 0; i < comm->byte_ofs + slice_size; i += 0x10) {
+@@ -111,7 +111,7 @@ nv98_decoder_vp(struct nouveau_vp3_decod
+ if (!is_ref && (dec->refs[target->valid_ref].decoded_top && dec->refs[target->valid_ref].decoded_bottom))
+ nv98_decoder_kick_ref(dec, target);
+
+- nouveau_pushbuf_space(push, 32 + codec_extra, num_refs, 0);
++ PUSH_SPACE_EX(push, 32 + codec_extra, num_refs, 0);
+
+ nouveau_pushbuf_refn(push, bo_refs, num_refs);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_compute.c 2022-02-11 15:16:25.426251672 -0600
+@@ -428,10 +428,11 @@ nvc0_launch_grid(struct pipe_context *pi
+ struct nvc0_program *cp = nvc0->compprog;
+ int ret;
+
++ simple_mtx_lock(&screen->state_lock);
+ ret = !nvc0_state_validate_cp(nvc0, ~0);
+ if (ret) {
+ NOUVEAU_ERR("Failed to launch grid !\n");
+- return;
++ goto out;
+ }
+
+ nvc0_compute_upload_input(nvc0, info);
+@@ -464,7 +465,7 @@ nvc0_launch_grid(struct pipe_context *pi
+ PUSH_DATA (push, (info->block[1] << 16) | info->block[0]);
+ PUSH_DATA (push, info->block[2]);
+
+- nouveau_pushbuf_space(push, 32, 2, 1);
++ PUSH_SPACE_EX(push, 32, 2, 1);
+ PUSH_REFN(push, screen->text, NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD);
+
+ if (unlikely(info->indirect)) {
+@@ -502,6 +503,9 @@ nvc0_launch_grid(struct pipe_context *pi
+ nvc0->images_dirty[5] |= nvc0->images_valid[5];
+
+ nvc0_update_compute_invocations_counter(nvc0, info);
++
++out:
++ simple_mtx_unlock(&screen->state_lock);
+ }
+
+ static void
+@@ -511,7 +515,7 @@ nvc0_compute_update_indirect_invocations
+ struct nv04_resource *res = nv04_resource(info->indirect);
+ uint32_t offset = res->offset + info->indirect_offset;
+
+- nouveau_pushbuf_space(push, 16, 0, 8);
++ PUSH_SPACE_EX(push, 16, 0, 8);
+ PUSH_REFN(push, res->bo, NOUVEAU_BO_RD | res->domain);
+ BEGIN_1IC0(push, NVC0_3D(MACRO_COMPUTE_COUNTER), 7);
+ PUSH_DATA(push, 6);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_context.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_context.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_context.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_context.c 2022-02-11 18:08:12.440206042 -0600
+@@ -81,10 +81,9 @@ nvc0_flush(struct pipe_context *pipe,
+ unsigned flags)
+ {
+ struct nvc0_context *nvc0 = nvc0_context(pipe);
+- struct nouveau_screen *screen = &nvc0->screen->base;
+
+ if (fence)
+- nouveau_fence_ref(screen->fence.current, (struct nouveau_fence **)fence);
++ nouveau_fence_ref(nvc0->base.fence, (struct nouveau_fence **)fence);
+
+ PUSH_KICK(nvc0->base.pushbuf); /* fencing handled in kick_notify */
+
+@@ -257,7 +256,7 @@ nvc0_destroy(struct pipe_context *pipe)
+ * Other contexts will always set their bufctx again on action calls.
+ */
+ nouveau_pushbuf_bufctx(nvc0->base.pushbuf, NULL);
+- nouveau_pushbuf_kick(nvc0->base.pushbuf, nvc0->base.pushbuf->channel);
++ PUSH_KICK(nvc0->base.pushbuf);
+
+ nvc0_context_unreference_resources(nvc0);
+ nvc0_blitctx_destroy(nvc0);
+@@ -272,6 +271,7 @@ nvc0_destroy(struct pipe_context *pipe)
+ free(pos);
+ }
+
++ nouveau_fence_cleanup(&nvc0->base);
+ nouveau_context_destroy(&nvc0->base);
+ }
+
+@@ -279,12 +279,12 @@ void
+ nvc0_default_kick_notify(struct nouveau_pushbuf *push)
+ {
+ struct nvc0_screen *screen = push->user_priv;
++ struct nvc0_context *nvc0 = screen->cur_ctx;
+
+- if (screen) {
+- nouveau_fence_next(&screen->base);
++ if (nvc0) {
++ nouveau_fence_next(&nvc0->base);
+ nouveau_fence_update(&screen->base, true);
+- if (screen->cur_ctx)
+- screen->cur_ctx->state.flushed = true;
++ nvc0->state.flushed = true;
+ NOUVEAU_DRV_STAT(&screen->base, pushbuf_count, 1);
+ }
+ }
+@@ -425,22 +425,19 @@ nvc0_create(struct pipe_screen *pscreen,
+ if (!nvc0_blitctx_create(nvc0))
+ goto out_err;
+
+- nvc0->base.pushbuf = screen->base.pushbuf;
+- nvc0->base.client = screen->base.client;
++ nouveau_context_init(&nvc0->base, &screen->base);
+
+- ret = nouveau_bufctx_new(screen->base.client, 2, &nvc0->bufctx);
++ ret = nouveau_bufctx_new(nvc0->base.client, 2, &nvc0->bufctx);
+ if (!ret)
+- ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_3D_COUNT,
++ ret = nouveau_bufctx_new(nvc0->base.client, NVC0_BIND_3D_COUNT,
+ &nvc0->bufctx_3d);
+ if (!ret)
+- ret = nouveau_bufctx_new(screen->base.client, NVC0_BIND_CP_COUNT,
++ ret = nouveau_bufctx_new(nvc0->base.client, NVC0_BIND_CP_COUNT,
+ &nvc0->bufctx_cp);
+ if (ret)
+ goto out_err;
+
+ nvc0->screen = screen;
+- nvc0->base.screen = &screen->base;
+-
+ pipe->screen = pscreen;
+ pipe->priv = priv;
+ pipe->stream_uploader = u_upload_create_default(pipe);
+@@ -464,7 +461,6 @@ nvc0_create(struct pipe_screen *pscreen,
+ pipe->emit_string_marker = nvc0_emit_string_marker;
+ pipe->get_device_reset_status = nvc0_get_device_reset_status;
+
+- nouveau_context_init(&nvc0->base);
+ nvc0_init_query_functions(nvc0);
+ nvc0_init_surface_functions(nvc0);
+ nvc0_init_state_functions(nvc0);
+@@ -553,6 +549,8 @@ nvc0_create(struct pipe_screen *pscreen,
+ nvc0->dirty_cp |= NVC0_NEW_CP_SAMPLERS;
+ }
+
++ nouveau_fence_new(&nvc0->base, &nvc0->base.fence);
++
+ return pipe;
+
+ out_err:
+@@ -583,7 +581,7 @@ nvc0_bufctx_fence(struct nvc0_context *n
+ struct nouveau_bufref *ref = (struct nouveau_bufref *)it;
+ struct nv04_resource *res = ref->priv;
+ if (res)
+- nvc0_resource_validate(res, (unsigned)ref->priv_data);
++ nvc0_resource_validate(nvc0, res, (unsigned)ref->priv_data);
+ NOUVEAU_DRV_STAT_IFD(count++);
+ }
+ NOUVEAU_DRV_STAT(&nvc0->screen->base, resource_validate_count, count);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_context.h mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_context.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_context.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_context.h 2022-02-11 15:23:13.508824215 -0600
+@@ -311,6 +311,30 @@ nvc0_shader_stage(unsigned pipe)
+ }
+
+
++static inline void
++nvc0_resource_fence(struct nvc0_context *nvc0, struct nv04_resource *res, uint32_t flags)
++{
++ if (res->mm) {
++ nouveau_fence_ref(nvc0->base.fence, &res->fence);
++ if (flags & NOUVEAU_BO_WR)
++ nouveau_fence_ref(nvc0->base.fence, &res->fence_wr);
++ }
++}
++
++static inline void
++nvc0_resource_validate(struct nvc0_context *nvc0, struct nv04_resource *res, uint32_t flags)
++{
++ if (likely(res->bo)) {
++ if (flags & NOUVEAU_BO_WR)
++ res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
++ NOUVEAU_BUFFER_STATUS_DIRTY;
++ if (flags & NOUVEAU_BO_RD)
++ res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
++
++ nvc0_resource_fence(nvc0, res, flags);
++ }
++}
++
+ /* nvc0_context.c */
+ struct pipe_context *nvc0_create(struct pipe_screen *, void *, unsigned flags);
+ void nvc0_bufctx_fence(struct nvc0_context *, struct nouveau_bufctx *,
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_program.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_program.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_program.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_program.c 2022-02-11 15:25:32.848266636 -0600
+@@ -884,6 +884,7 @@ nvc0_program_upload(struct nvc0_context
+ size += TU102_SHADER_HEADER_SIZE;
+ }
+
++ simple_mtx_assert_locked(&nvc0->screen->state_lock);
+ ret = nvc0_program_alloc_code(nvc0, prog);
+ if (ret) {
+ struct nouveau_heap *heap = screen->text_heap;
+@@ -990,8 +991,11 @@ nvc0_program_destroy(struct nvc0_context
+ const struct pipe_shader_state pipe = prog->pipe;
+ const ubyte type = prog->type;
+
+- if (prog->mem)
++ if (prog->mem) {
++ if (nvc0)
++ simple_mtx_assert_locked(&nvc0->screen->state_lock);
+ nouveau_heap_free(&prog->mem);
++ }
+ FREE(prog->code); /* may be 0 for hardcoded shaders */
+ FREE(prog->relocs);
+ FREE(prog->fixups);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw.c 2022-02-11 15:30:18.641058844 -0600
+@@ -44,7 +44,7 @@ nvc0_hw_query_allocate(struct nvc0_conte
+ if (hq->state == NVC0_HW_QUERY_STATE_READY)
+ nouveau_mm_free(hq->mm);
+ else
+- nouveau_fence_work(screen->base.fence.current,
++ nouveau_fence_work(nvc0->base.fence,
+ nouveau_mm_free_work, hq->mm);
+ }
+ }
+@@ -55,7 +55,7 @@ nvc0_hw_query_allocate(struct nvc0_conte
+ return false;
+ hq->offset = hq->base_offset;
+
+- ret = nouveau_bo_map(hq->bo, 0, screen->base.client);
++ ret = BO_MAP(&screen->base, hq->bo, 0, nvc0->base.client);
+ if (ret) {
+ nvc0_hw_query_allocate(nvc0, q, 0);
+ return false;
+@@ -129,7 +129,7 @@ nvc0_hw_query_write_compute_invocations(
+ {
+ struct nouveau_pushbuf *push = nvc0->base.pushbuf;
+
+- nouveau_pushbuf_space(push, 16, 0, 8);
++ PUSH_SPACE_EX(push, 16, 0, 8);
+ PUSH_REFN(push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_WR);
+ BEGIN_1IC0(push, NVC0_3D(MACRO_COMPUTE_COUNTER_TO_QUERY), 4);
+ PUSH_DATA (push, nvc0->compute_invocations);
+@@ -301,7 +301,7 @@ nvc0_hw_end_query(struct nvc0_context *n
+ break;
+ }
+ if (hq->is64bit)
+- nouveau_fence_ref(nvc0->screen->base.fence.current, &hq->fence);
++ nouveau_fence_ref(nvc0->base.fence, &hq->fence);
+ }
+
+ static bool
+@@ -319,7 +319,7 @@ nvc0_hw_get_query_result(struct nvc0_con
+ return hq->funcs->get_query_result(nvc0, hq, wait, result);
+
+ if (hq->state != NVC0_HW_QUERY_STATE_READY)
+- nvc0_hw_query_update(nvc0->screen->base.client, q);
++ nvc0_hw_query_update(nvc0->base.client, q);
+
+ if (hq->state != NVC0_HW_QUERY_STATE_READY) {
+ if (!wait) {
+@@ -330,7 +330,7 @@ nvc0_hw_get_query_result(struct nvc0_con
+ }
+ return false;
+ }
+- if (nouveau_bo_wait(hq->bo, NOUVEAU_BO_RD, nvc0->screen->base.client))
++ if (BO_WAIT(&nvc0->screen->base, hq->bo, NOUVEAU_BO_RD, nvc0->base.client))
+ return false;
+ NOUVEAU_DRV_STAT(&nvc0->screen->base, query_sync_count, 1);
+ }
+@@ -403,7 +403,7 @@ nvc0_hw_get_query_result_resource(struct
+ if (index == -1) {
+ /* TODO: Use a macro to write the availability of the query */
+ if (hq->state != NVC0_HW_QUERY_STATE_READY)
+- nvc0_hw_query_update(nvc0->screen->base.client, q);
++ nvc0_hw_query_update(nvc0->base.client, q);
+ uint32_t ready[2] = {hq->state == NVC0_HW_QUERY_STATE_READY};
+ nvc0->base.push_cb(&nvc0->base, buf, offset,
+ result_type >= PIPE_QUERY_TYPE_I64 ? 2 : 1,
+@@ -412,7 +412,7 @@ nvc0_hw_get_query_result_resource(struct
+ util_range_add(&buf->base, &buf->valid_buffer_range, offset,
+ offset + (result_type >= PIPE_QUERY_TYPE_I64 ? 8 : 4));
+
+- nvc0_resource_validate(buf, NOUVEAU_BO_WR);
++ nvc0_resource_validate(nvc0, buf, NOUVEAU_BO_WR);
+
+ return;
+ }
+@@ -420,7 +420,7 @@ nvc0_hw_get_query_result_resource(struct
+ /* If the fence guarding this query has not been emitted, that makes a lot
+ * of the following logic more complicated.
+ */
+- if (hq->is64bit && hq->fence->state < NOUVEAU_FENCE_STATE_EMITTED)
++ if (hq->is64bit)
+ nouveau_fence_emit(hq->fence);
+
+ /* We either need to compute a 32- or 64-bit difference between 2 values,
+@@ -430,12 +430,12 @@ nvc0_hw_get_query_result_resource(struct
+ * outputs the difference (no need to worry about 64-bit clamping).
+ */
+ if (hq->state != NVC0_HW_QUERY_STATE_READY)
+- nvc0_hw_query_update(nvc0->screen->base.client, q);
++ nvc0_hw_query_update(nvc0->base.client, q);
+
+ if (wait && hq->state != NVC0_HW_QUERY_STATE_READY)
+ nvc0_hw_query_fifo_wait(nvc0, q);
+
+- nouveau_pushbuf_space(push, 32, 2, 3);
++ PUSH_SPACE_EX(push, 32, 2, 3);
+ PUSH_REFN (push, hq->bo, NOUVEAU_BO_GART | NOUVEAU_BO_RD);
+ PUSH_REFN (push, buf->bo, buf->domain | NOUVEAU_BO_WR);
+ BEGIN_1IC0(push, NVC0_3D(MACRO_QUERY_BUFFER_WRITE), 9);
+@@ -511,7 +511,7 @@ nvc0_hw_get_query_result_resource(struct
+ util_range_add(&buf->base, &buf->valid_buffer_range, offset,
+ offset + (result_type >= PIPE_QUERY_TYPE_I64 ? 8 : 4));
+
+- nvc0_resource_validate(buf, NOUVEAU_BO_WR);
++ nvc0_resource_validate(nvc0, buf, NOUVEAU_BO_WR);
+ }
+
+ static const struct nvc0_query_funcs hw_query_funcs = {
+@@ -642,7 +642,7 @@ nvc0_hw_query_fifo_wait(struct nvc0_cont
+ unsigned offset = hq->offset;
+
+ /* ensure the query's fence has been emitted */
+- if (hq->is64bit && hq->fence->state < NOUVEAU_FENCE_STATE_EMITTED)
++ if (hq->is64bit)
+ nouveau_fence_emit(hq->fence);
+
+ PUSH_SPACE(push, 5);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw_sm.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw_sm.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw_sm.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_query_hw_sm.c 2022-02-11 15:31:39.237707036 -0600
+@@ -2636,7 +2636,7 @@ nvc0_hw_sm_query_read_data(uint32_t coun
+ if (hq->data[b + 8] != hq->sequence) {
+ if (!wait)
+ return false;
+- if (nouveau_bo_wait(hq->bo, NOUVEAU_BO_RD, nvc0->base.client))
++ if (BO_WAIT(&nvc0->screen->base, hq->bo, NOUVEAU_BO_RD, nvc0->base.client))
+ return false;
+ }
+ count[p][c] = hq->data[b + hsq->ctr[c]] * (1 << c);
+@@ -2664,7 +2664,7 @@ nve4_hw_sm_query_read_data(uint32_t coun
+ if (hq->data[b + 20 + d] != hq->sequence) {
+ if (!wait)
+ return false;
+- if (nouveau_bo_wait(hq->bo, NOUVEAU_BO_RD, nvc0->base.client))
++ if (BO_WAIT(&nvc0->screen->base, hq->bo, NOUVEAU_BO_RD, nvc0->base.client))
+ return false;
+ }
+ if (hsq->ctr[c] & ~0x3)
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_screen.c 2022-02-11 16:20:30.965275088 -0600
+@@ -701,8 +701,6 @@ nvc0_screen_destroy(struct pipe_screen *
+ if (!nouveau_drm_screen_unref(&screen->base))
+ return;
+
+- nouveau_fence_cleanup(&screen->base);
+-
+ if (screen->base.pushbuf)
+ screen->base.pushbuf->user_priv = NULL;
+
+@@ -733,6 +731,7 @@ nvc0_screen_destroy(struct pipe_screen *
+ nouveau_object_del(&screen->nvsw);
+
+ nouveau_screen_fini(&screen->base);
++ simple_mtx_destroy(&screen->state_lock);
+
+ FREE(screen);
+ }
+@@ -1058,6 +1057,8 @@ nvc0_screen_create(struct nouveau_device
+ return NULL;
+ pscreen = &screen->base.base;
+ pscreen->destroy = nvc0_screen_destroy;
++
++ simple_mtx_init(&screen->state_lock, mtx_plain);
+
+ ret = nouveau_screen_init(&screen->base, dev);
+ if (ret)
+@@ -1109,7 +1110,7 @@ nvc0_screen_create(struct nouveau_device
+ ret = nouveau_bo_new(dev, flags, 0, 4096, NULL, &screen->fence.bo);
+ if (ret)
+ FAIL_SCREEN_INIT("Error allocating fence BO: %d\n", ret);
+- nouveau_bo_map(screen->fence.bo, 0, NULL);
++ BO_MAP(&screen->base, screen->fence.bo, 0, NULL);
+ screen->fence.map = screen->fence.bo->map;
+ screen->base.fence.emit = nvc0_screen_fence_emit;
+ screen->base.fence.update = nvc0_screen_fence_update;
+@@ -1558,8 +1559,6 @@ nvc0_screen_create(struct nouveau_device
+ if (!nvc0_blitter_create(screen))
+ goto fail;
+
+- nouveau_fence_new(&screen->base, &screen->base.fence.current);
+-
+ return &screen->base;
+
+ fail:
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_screen.h 2022-02-11 16:21:46.650277251 -0600
+@@ -71,6 +71,7 @@ struct nvc0_screen {
+
+ struct nvc0_context *cur_ctx;
+ struct nvc0_graph_state save_state;
++ simple_mtx_t state_lock;
+
+ int num_occlusion_queries_active;
+
+@@ -157,32 +158,6 @@ int nvc0_screen_resize_text_area(struct
+ // 3D Only
+ void nvc0_screen_bind_cb_3d(struct nvc0_screen *, bool *, int, int, int, uint64_t);
+
+-static inline void
+-nvc0_resource_fence(struct nv04_resource *res, uint32_t flags)
+-{
+- struct nvc0_screen *screen = nvc0_screen(res->base.screen);
+-
+- if (res->mm) {
+- nouveau_fence_ref(screen->base.fence.current, &res->fence);
+- if (flags & NOUVEAU_BO_WR)
+- nouveau_fence_ref(screen->base.fence.current, &res->fence_wr);
+- }
+-}
+-
+-static inline void
+-nvc0_resource_validate(struct nv04_resource *res, uint32_t flags)
+-{
+- if (likely(res->bo)) {
+- if (flags & NOUVEAU_BO_WR)
+- res->status |= NOUVEAU_BUFFER_STATUS_GPU_WRITING |
+- NOUVEAU_BUFFER_STATUS_DIRTY;
+- if (flags & NOUVEAU_BO_RD)
+- res->status |= NOUVEAU_BUFFER_STATUS_GPU_READING;
+-
+- nvc0_resource_fence(res, flags);
+- }
+-}
+-
+ struct nvc0_format {
+ uint32_t rt;
+ struct {
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_shader_state.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_shader_state.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_shader_state.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_shader_state.c 2022-02-11 16:24:08.657161261 -0600
+@@ -71,6 +71,7 @@ nvc0_program_sp_start_id(struct nvc0_con
+ {
+ struct nouveau_pushbuf *push = nvc0->base.pushbuf;
+
++ simple_mtx_assert_locked(&nvc0->screen->state_lock);
+ if (nvc0->screen->eng3d->oclass < GV100_3D_CLASS) {
+ BEGIN_NVC0(push, NVC0_3D(SP_START_ID(stage)), 1);
+ PUSH_DATA (push, prog->code_base);
+@@ -338,6 +339,8 @@ nvc0_tfb_validate(struct nvc0_context *n
+ }
+ }
+ }
++
++ simple_mtx_assert_locked(&nvc0->screen->state_lock);
+ nvc0->state.tfb = tfb;
+
+ if (!(nvc0->dirty_3d & NVC0_NEW_3D_TFB_TARGETS))
+@@ -364,7 +367,7 @@ nvc0_tfb_validate(struct nvc0_context *n
+
+ if (!targ->clean)
+ nvc0_hw_query_fifo_wait(nvc0, nvc0_query(targ->pq));
+- nouveau_pushbuf_space(push, 0, 0, 1);
++ PUSH_SPACE_EX(push, 0, 0, 1);
+ BEGIN_NVC0(push, NVC0_3D(TFB_BUFFER_ENABLE(b)), 5);
+ PUSH_DATA (push, 1);
+ PUSH_DATAh(push, buf->address + targ->pipe.buffer_offset);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_state.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_state.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_state.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_state.c 2022-02-11 16:25:08.106073895 -0600
+@@ -635,9 +635,12 @@ nvc0_sp_state_create(struct pipe_context
+ static void
+ nvc0_sp_state_delete(struct pipe_context *pipe, void *hwcso)
+ {
++ struct nvc0_context *nvc0 = nvc0_context(pipe);
+ struct nvc0_program *prog = (struct nvc0_program *)hwcso;
+
++ simple_mtx_lock(&nvc0->screen->state_lock);
+ nvc0_program_destroy(nvc0_context(pipe), prog);
++ simple_mtx_unlock(&nvc0->screen->state_lock);
+
+ if (prog->pipe.type == PIPE_SHADER_IR_TGSI)
+ FREE((void *)prog->pipe.tokens);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_state_validate.c 2022-02-11 16:26:48.061884623 -0600
+@@ -253,7 +253,7 @@ nvc0_validate_fb(struct nvc0_context *nv
+ PUSH_DATA(push, 0);
+ PUSH_DATA(push, 0);
+
+- nvc0_resource_fence(res, NOUVEAU_BO_WR);
++ nvc0_resource_fence(nvc0, res, NOUVEAU_BO_WR);
+
+ assert(!fb->zsbuf);
+ }
+@@ -871,6 +871,7 @@ nvc0_switch_pipe_context(struct nvc0_con
+ struct nvc0_context *ctx_from = ctx_to->screen->cur_ctx;
+ unsigned s;
+
++ simple_mtx_assert_locked(&ctx_to->screen->state_lock);
+ if (ctx_from)
+ ctx_to->state = ctx_from->state;
+ else
+@@ -967,6 +968,8 @@ nvc0_state_validate(struct nvc0_context
+ int ret;
+ unsigned i;
+
++ simple_mtx_assert_locked(&nvc0->screen->state_lock);
++
+ if (nvc0->screen->cur_ctx != nvc0)
+ nvc0_switch_pipe_context(nvc0);
+
+@@ -985,7 +988,7 @@ nvc0_state_validate(struct nvc0_context
+ }
+
+ nouveau_pushbuf_bufctx(nvc0->base.pushbuf, bufctx);
+- ret = nouveau_pushbuf_validate(nvc0->base.pushbuf);
++ ret = PUSH_VAL(nvc0->base.pushbuf);
+
+ return !ret;
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_surface.c 2022-02-11 16:33:12.692802344 -0600
+@@ -267,7 +267,7 @@ nvc0_resource_copy_region(struct pipe_co
+ BCTX_REFN(nvc0->bufctx, 2D, nv04_resource(src), RD);
+ BCTX_REFN(nvc0->bufctx, 2D, nv04_resource(dst), WR);
+ nouveau_pushbuf_bufctx(nvc0->base.pushbuf, nvc0->bufctx);
+- nouveau_pushbuf_validate(nvc0->base.pushbuf);
++ PUSH_VAL(nvc0->base.pushbuf);
+
+ for (; dst_layer < dstz + src_box->depth; ++dst_layer, ++src_layer) {
+ ret = nvc0_2d_texture_do_copy(nvc0->base.pushbuf,
+@@ -348,7 +348,7 @@ nvc0_clear_render_target(struct pipe_con
+ IMMED_NVC0(push, NVC0_3D(MULTISAMPLE_MODE), 0);
+
+ /* tiled textures don't have to be fenced, they're not mapped directly */
+- nvc0_resource_fence(res, NOUVEAU_BO_WR);
++ nvc0_resource_fence(nvc0, res, NOUVEAU_BO_WR);
+ }
+
+ if (!render_condition_enabled)
+@@ -379,7 +379,7 @@ nvc0_clear_buffer_push_nvc0(struct pipe_
+
+ nouveau_bufctx_refn(nvc0->bufctx, 0, buf->bo, buf->domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, nvc0->bufctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ unsigned count = (size + 3) / 4;
+ unsigned data_words = data_size / 4;
+@@ -410,7 +410,7 @@ nvc0_clear_buffer_push_nvc0(struct pipe_
+ size -= nr * 4;
+ }
+
+- nvc0_resource_validate(buf, NOUVEAU_BO_WR);
++ nvc0_resource_validate(nvc0, buf, NOUVEAU_BO_WR);
+
+ nouveau_bufctx_reset(nvc0->bufctx, 0);
+ }
+@@ -428,7 +428,7 @@ nvc0_clear_buffer_push_nve4(struct pipe_
+
+ nouveau_bufctx_refn(nvc0->bufctx, 0, buf->bo, buf->domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, nvc0->bufctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ unsigned count = (size + 3) / 4;
+ unsigned data_words = data_size / 4;
+@@ -457,7 +457,7 @@ nvc0_clear_buffer_push_nve4(struct pipe_
+ size -= nr * 4;
+ }
+
+- nvc0_resource_validate(buf, NOUVEAU_BO_WR);
++ nvc0_resource_validate(nvc0, buf, NOUVEAU_BO_WR);
+
+ nouveau_bufctx_reset(nvc0->bufctx, 0);
+ }
+@@ -604,7 +604,7 @@ nvc0_clear_buffer(struct pipe_context *p
+
+ IMMED_NVC0(push, NVC0_3D(COND_MODE), nvc0->cond_condmode);
+
+- nvc0_resource_validate(buf, NOUVEAU_BO_WR);
++ nvc0_resource_validate(nvc0, buf, NOUVEAU_BO_WR);
+
+ if (width * height != elements) {
+ offset += width * height * data_size;
+@@ -700,9 +700,11 @@ nvc0_clear(struct pipe_context *pipe, un
+ unsigned i, j, k;
+ uint32_t mode = 0;
+
++ simple_mtx_lock(&nvc0->screen->state_lock);
++
+ /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */
+ if (!nvc0_state_validate_3d(nvc0, NVC0_NEW_3D_FRAMEBUFFER))
+- return;
++ goto out;
+
+ if (scissor_state) {
+ uint32_t minx = scissor_state->minx;
+@@ -710,7 +712,7 @@ nvc0_clear(struct pipe_context *pipe, un
+ uint32_t miny = scissor_state->miny;
+ uint32_t maxy = MIN2(fb->height, scissor_state->maxy);
+ if (maxx <= minx || maxy <= miny)
+- return;
++ goto out;
+
+ BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2);
+ PUSH_DATA (push, minx | (maxx - minx) << 16);
+@@ -781,6 +783,9 @@ nvc0_clear(struct pipe_context *pipe, un
+ PUSH_DATA (push, fb->width << 16);
+ PUSH_DATA (push, fb->height << 16);
+ }
++
++out:
++ simple_mtx_unlock(&nvc0->screen->state_lock);
+ }
+
+ static void
+@@ -789,8 +794,10 @@ gm200_evaluate_depth_buffer(struct pipe_
+ struct nvc0_context *nvc0 = nvc0_context(pipe);
+ struct nouveau_pushbuf *push = nvc0->base.pushbuf;
+
++ simple_mtx_lock(&nvc0->screen->state_lock);
+ nvc0_state_validate_3d(nvc0, NVC0_NEW_3D_FRAMEBUFFER);
+ IMMED_NVC0(push, SUBC_3D(0x11fc), 1);
++ simple_mtx_unlock(&nvc0->screen->state_lock);
+ }
+
+
+@@ -1327,7 +1334,7 @@ nvc0_blit_3d(struct nvc0_context *nvc0,
+ NOUVEAU_BO_GART | NOUVEAU_BO_RD, vtxbuf_bo);
+ BCTX_REFN_bo(nvc0->bufctx_3d, 3D_TEXT,
+ NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD, screen->text);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ BEGIN_NVC0(push, NVC0_3D(VERTEX_ARRAY_FETCH(0)), 4);
+ PUSH_DATA (push, NVC0_3D_VERTEX_ARRAY_FETCH_ENABLE | stride <<
+@@ -1549,7 +1556,7 @@ nvc0_blit_eng2d(struct nvc0_context *nvc
+ BCTX_REFN(nvc0->bufctx, 2D, &dst->base, WR);
+ BCTX_REFN(nvc0->bufctx, 2D, &src->base, RD);
+ nouveau_pushbuf_bufctx(nvc0->base.pushbuf, nvc0->bufctx);
+- if (nouveau_pushbuf_validate(nvc0->base.pushbuf))
++ if (PUSH_VAL(nvc0->base.pushbuf))
+ return;
+
+ for (i = 0; i < info->dst.box.depth; ++i) {
+@@ -1589,8 +1596,8 @@ nvc0_blit_eng2d(struct nvc0_context *nvc
+ PUSH_DATA (push, srcy >> 32);
+ }
+ }
+- nvc0_resource_validate(&dst->base, NOUVEAU_BO_WR);
+- nvc0_resource_validate(&src->base, NOUVEAU_BO_RD);
++ nvc0_resource_validate(nvc0, &dst->base, NOUVEAU_BO_WR);
++ nvc0_resource_validate(nvc0, &src->base, NOUVEAU_BO_RD);
+
+ nouveau_bufctx_reset(nvc0->bufctx, NVC0_BIND_2D);
+
+@@ -1684,6 +1691,7 @@ nvc0_blit(struct pipe_context *pipe, con
+ if (info->num_window_rectangles > 0 || info->window_rectangle_include)
+ eng3d = true;
+
++ simple_mtx_lock(&nvc0->screen->state_lock);
+ if (nvc0->screen->num_occlusion_queries_active)
+ IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 0);
+
+@@ -1694,6 +1702,7 @@ nvc0_blit(struct pipe_context *pipe, con
+
+ if (nvc0->screen->num_occlusion_queries_active)
+ IMMED_NVC0(push, NVC0_3D(SAMPLECNT_ENABLE), 1);
++ simple_mtx_unlock(&nvc0->screen->state_lock);
+
+ NOUVEAU_DRV_STAT(&nvc0->screen->base, tex_blit_count, 1);
+ }
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_transfer.c 2022-02-11 16:36:06.082194000 -0600
+@@ -32,7 +32,7 @@ nvc0_m2mf_transfer_rect(struct nvc0_cont
+ nouveau_bufctx_refn(bctx, 0, src->bo, src->domain | NOUVEAU_BO_RD);
+ nouveau_bufctx_refn(bctx, 0, dst->bo, dst->domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, bctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ if (nouveau_bo_memtype(src->bo)) {
+ BEGIN_NVC0(push, NVC0_M2MF(TILING_MODE_IN), 5);
+@@ -138,7 +138,7 @@ nve4_m2mf_transfer_rect(struct nvc0_cont
+ nouveau_bufctx_refn(bctx, 0, dst->bo, dst->domain | NOUVEAU_BO_WR);
+ nouveau_bufctx_refn(bctx, 0, src->bo, src->domain | NOUVEAU_BO_RD);
+ nouveau_pushbuf_bufctx(push, bctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ exec = NVE4_COPY_EXEC_SWIZZLE_ENABLE | NVE4_COPY_EXEC_2D_ENABLE | NVE4_COPY_EXEC_FLUSH | NVE4_COPY_EXEC_COPY_MODE_NON_PIPELINED;
+
+@@ -207,7 +207,7 @@ nvc0_m2mf_push_linear(struct nouveau_con
+
+ nouveau_bufctx_refn(nvc0->bufctx, 0, dst, domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, nvc0->bufctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ while (count) {
+ unsigned nr = MIN2(count, NV04_PFIFO_MAX_PACKET_LEN);
+@@ -249,7 +249,7 @@ nve4_p2mf_push_linear(struct nouveau_con
+
+ nouveau_bufctx_refn(nvc0->bufctx, 0, dst, domain | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, nvc0->bufctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ while (count) {
+ unsigned nr = MIN2(count, (NV04_PFIFO_MAX_PACKET_LEN - 1));
+@@ -289,7 +289,7 @@ nvc0_m2mf_copy_linear(struct nouveau_con
+ nouveau_bufctx_refn(bctx, 0, src, srcdom | NOUVEAU_BO_RD);
+ nouveau_bufctx_refn(bctx, 0, dst, dstdom | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, bctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ while (size) {
+ unsigned bytes = MIN2(size, 1 << 17);
+@@ -327,7 +327,7 @@ nve4_m2mf_copy_linear(struct nouveau_con
+ nouveau_bufctx_refn(bctx, 0, src, srcdom | NOUVEAU_BO_RD);
+ nouveau_bufctx_refn(bctx, 0, dst, dstdom | NOUVEAU_BO_WR);
+ nouveau_pushbuf_bufctx(push, bctx);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ BEGIN_NVC0(push, NVE4_COPY(SRC_ADDRESS_HIGH), 4);
+ PUSH_DATAh(push, src->offset + srcoff);
+@@ -362,7 +362,7 @@ nvc0_mt_sync(struct nvc0_context *nvc0,
+ if (!mt->base.mm) {
+ uint32_t access = (usage & PIPE_MAP_WRITE) ?
+ NOUVEAU_BO_WR : NOUVEAU_BO_RD;
+- return !nouveau_bo_wait(mt->base.bo, access, nvc0->base.client);
++ return !BO_WAIT(&nvc0->screen->base, mt->base.bo, access, nvc0->base.client);
+ }
+ if (usage & PIPE_MAP_WRITE)
+ return !mt->base.fence || nouveau_fence_wait(mt->base.fence, &nvc0->base.debug);
+@@ -388,7 +388,7 @@ nvc0_miptree_transfer_map(struct pipe_co
+ if (nvc0_mt_transfer_can_map_directly(mt)) {
+ ret = !nvc0_mt_sync(nvc0, mt, usage);
+ if (!ret)
+- ret = nouveau_bo_map(mt->base.bo, 0, NULL);
++ ret = BO_MAP(nvc0->base.screen, mt->base.bo, 0, NULL);
+ if (ret &&
+ (usage & PIPE_MAP_DIRECTLY))
+ return NULL;
+@@ -480,7 +480,7 @@ nvc0_miptree_transfer_map(struct pipe_co
+ if (usage & PIPE_MAP_WRITE)
+ flags |= NOUVEAU_BO_WR;
+
+- ret = nouveau_bo_map(tx->rect[1].bo, flags, nvc0->screen->base.client);
++ ret = BO_MAP(nvc0->base.screen, tx->rect[1].bo, flags, nvc0->screen->base.client);
+ if (ret) {
+ pipe_resource_reference(&tx->base.resource, NULL);
+ nouveau_bo_ref(NULL, &tx->rect[1].bo);
+@@ -521,7 +521,7 @@ nvc0_miptree_transfer_unmap(struct pipe_
+ NOUVEAU_DRV_STAT(&nvc0->screen->base, tex_transfers_wr, 1);
+
+ /* Allow the copies above to finish executing before freeing the source */
+- nouveau_fence_work(nvc0->screen->base.fence.current,
++ nouveau_fence_work(nvc0->base.fence,
+ nouveau_fence_unref_bo, tx->rect[1].bo);
+ } else {
+ nouveau_bo_ref(NULL, &tx->rect[1].bo);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_vbo.c 2022-02-11 16:37:55.523785563 -0600
+@@ -462,6 +462,7 @@ nvc0_vertex_arrays_validate(struct nvc0_
+ if (update_vertex) {
+ const unsigned n = MAX2(vertex->num_elements, nvc0->state.num_vtxelts);
+
++ simple_mtx_assert_locked(&nvc0->screen->state_lock);
+ nvc0->state.constant_vbos = const_vbos;
+ nvc0->state.constant_elts = 0;
+ nvc0->state.num_vtxelts = vertex->num_elements;
+@@ -788,7 +789,7 @@ nvc0_draw_stream_output(struct nvc0_cont
+ }
+
+ while (num_instances--) {
+- nouveau_pushbuf_space(push, 16, 0, 1);
++ PUSH_SPACE_EX(push, 16, 0, 1);
+ BEGIN_NVC0(push, NVC0_3D(VERTEX_BEGIN_GL), 1);
+ PUSH_DATA (push, mode);
+ BEGIN_NVC0(push, NVC0_3D(DRAW_TFB_BASE), 1);
+@@ -869,7 +870,7 @@ nvc0_draw_indirect(struct nvc0_context *
+ pushes = draws;
+ }
+
+- nouveau_pushbuf_space(push, 16, 0, pushes + !!buf_count);
++ PUSH_SPACE_EX(push, 16, 0, pushes + !!buf_count);
+ PUSH_REFN(push, buf->bo, NOUVEAU_BO_RD | buf->domain);
+ if (buf_count)
+ PUSH_REFN(push, buf_count->bo, NOUVEAU_BO_RD | buf_count->domain);
+@@ -1024,6 +1025,8 @@ nvc0_draw_vbo(struct pipe_context *pipe,
+ BCTX_REFN_bo(nvc0->bufctx_3d, 3D_TEXT, vram_domain | NOUVEAU_BO_RD,
+ screen->text);
+
++ simple_mtx_lock(&nvc0->screen->state_lock);
++
+ nvc0_state_validate_3d(nvc0, ~0);
+
+ if (nvc0->vertprog->vp.need_draw_parameters && (!indirect || indirect->count_from_stream_output)) {
+@@ -1131,6 +1134,8 @@ nvc0_draw_vbo(struct pipe_context *pipe,
+ }
+
+ cleanup:
++ simple_mtx_unlock(&nvc0->screen->state_lock);
++
+ push->kick_notify = nvc0_default_kick_notify;
+
+ nvc0_release_user_vbufs(nvc0);
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_vbo_translate.c 2022-02-11 16:38:16.159706821 -0600
+@@ -239,7 +239,7 @@ nvc0_push_setup_vertex_array(struct nvc0
+
+ BCTX_REFN_bo(nvc0->bufctx_3d, 3D_VTX_TMP, NOUVEAU_BO_GART | NOUVEAU_BO_RD,
+ bo);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ return dest;
+ }
+@@ -731,7 +731,7 @@ nvc0_push_upload_vertex_ids(struct push_
+
+ BCTX_REFN_bo(nvc0->bufctx_3d, 3D_VTX_TMP, NOUVEAU_BO_GART | NOUVEAU_BO_RD,
+ bo);
+- nouveau_pushbuf_validate(push);
++ PUSH_VAL(push);
+
+ if (info->index_size) {
+ if (!draw->index_bias) {
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video_bsp.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video_bsp.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video_bsp.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video_bsp.c 2022-02-11 16:42:26.561716987 -0600
+@@ -34,10 +34,11 @@ static void dump_comm_bsp(struct comm *c
+ unsigned
+ nvc0_decoder_bsp_begin(struct nouveau_vp3_decoder *dec, unsigned comm_seq)
+ {
++ struct nouveau_screen *screen = nouveau_screen(dec->base.context->screen);
+ struct nouveau_bo *bsp_bo = dec->bsp_bo[comm_seq % NOUVEAU_VP3_VIDEO_QDEPTH];
+ unsigned ret = 0;
+
+- ret = nouveau_bo_map(bsp_bo, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen, bsp_bo, NOUVEAU_BO_WR, dec->client);
+ if (ret) {
+ debug_printf("map failed: %i %s\n", ret, strerror(-ret));
+ return -1;
+@@ -53,6 +54,7 @@ nvc0_decoder_bsp_next(struct nouveau_vp3
+ unsigned comm_seq, unsigned num_buffers,
+ const void *const *data, const unsigned *num_bytes)
+ {
++ struct nouveau_screen *screen = nouveau_screen(dec->base.context->screen);
+ struct nouveau_bo *bsp_bo = dec->bsp_bo[comm_seq % NOUVEAU_VP3_VIDEO_QDEPTH];
+ struct nouveau_bo *inter_bo = dec->inter_bo[comm_seq & 1];
+ uint32_t bsp_size = 0;
+@@ -82,7 +84,7 @@ nvc0_decoder_bsp_next(struct nouveau_vp3
+ return -1;
+ }
+
+- ret = nouveau_bo_map(tmp_bo, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen,tmp_bo, NOUVEAU_BO_WR, dec->client);
+ if (ret) {
+ debug_printf("map failed: %i %s\n", ret, strerror(-ret));
+ return -1;
+@@ -114,7 +116,7 @@ nvc0_decoder_bsp_next(struct nouveau_vp3
+ return -1;
+ }
+
+- ret = nouveau_bo_map(tmp_bo, NOUVEAU_BO_WR, dec->client);
++ ret = BO_MAP(screen, tmp_bo, NOUVEAU_BO_WR, dec->client);
+ if (ret) {
+ debug_printf("map failed: %i %s\n", ret, strerror(-ret));
+ return -1;
+@@ -160,7 +162,7 @@ nvc0_decoder_bsp_end(struct nouveau_vp3_
+
+ nouveau_vp3_vp_caps(dec, desc, target, comm_seq, vp_caps, is_ref, refs);
+
+- nouveau_pushbuf_space(push, 32, num_refs, 0);
++ PUSH_SPACE_EX(push, 32, num_refs, 0);
+ nouveau_pushbuf_refn(push, bo_refs, num_refs);
+
+ bsp_addr = bsp_bo->offset >> 8;
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video.c 2022-02-11 18:09:21.787821149 -0600
+@@ -91,7 +91,8 @@ struct pipe_video_codec *
+ nvc0_create_decoder(struct pipe_context *context,
+ const struct pipe_video_codec *templ)
+ {
+- struct nouveau_screen *screen = &((struct nvc0_context *)context)->screen->base;
++ struct nvc0_context *nvc0 = nvc0_context(context);
++ struct nouveau_screen *screen = &nvc0->screen->base;
+ struct nouveau_vp3_decoder *dec;
+ struct nouveau_pushbuf **push;
+ union nouveau_bo_config cfg;
+@@ -116,7 +117,7 @@ nvc0_create_decoder(struct pipe_context
+ dec = CALLOC_STRUCT(nouveau_vp3_decoder);
+ if (!dec)
+ return NULL;
+- dec->client = screen->client;
++ dec->client = nvc0->base.client;
+ dec->base = *templ;
+ nouveau_vp3_decoder_init_common(&dec->base);
+
+@@ -160,7 +161,7 @@ nvc0_create_decoder(struct pipe_context
+ data, size, &dec->channel[i]);
+
+ if (!ret)
+- ret = nouveau_pushbuf_new(screen->client, dec->channel[i], 4,
++ ret = nouveau_pushbuf_new(nvc0->base.client, dec->channel[i], 4,
+ 32 * 1024, true, &dec->pushbuf[i]);
+ if (ret)
+ break;
+@@ -292,13 +293,13 @@ nvc0_create_decoder(struct pipe_context
+ if (ret)
+ goto fail;
+
+- nouveau_bo_map(dec->fence_bo, NOUVEAU_BO_RDWR, screen->client);
++ BO_MAP(dec->fence_bo, NOUVEAU_BO_RDWR, screen->client);
+ dec->fence_map = dec->fence_bo->map;
+ dec->fence_map[0] = dec->fence_map[4] = dec->fence_map[8] = 0;
+ dec->comm = (struct comm *)(dec->fence_map + (COMM_OFFSET/sizeof(*dec->fence_map)));
+
+ /* So lets test if the fence is working? */
+- nouveau_pushbuf_space(push[0], 16, 1, 0);
++ PUSH_SPACE_EX(push[0], 16, 1, 0);
+ PUSH_REFN (push[0], dec->fence_bo, NOUVEAU_BO_GART|NOUVEAU_BO_RDWR);
+ BEGIN_NVC0(push[0], SUBC_BSP(0x240), 3);
+ PUSH_DATAh(push[0], dec->fence_bo->offset);
+@@ -309,7 +310,7 @@ nvc0_create_decoder(struct pipe_context
+ PUSH_DATA (push[0], 0);
+ PUSH_KICK (push[0]);
+
+- nouveau_pushbuf_space(push[1], 16, 1, 0);
++ PUSH_SPACE_EX(push[1], 16, 1, 0);
+ PUSH_REFN (push[1], dec->fence_bo, NOUVEAU_BO_GART|NOUVEAU_BO_RDWR);
+ BEGIN_NVC0(push[1], SUBC_VP(0x240), 3);
+ PUSH_DATAh(push[1], (dec->fence_bo->offset + 0x10));
+@@ -320,7 +321,7 @@ nvc0_create_decoder(struct pipe_context
+ PUSH_DATA (push[1], 0);
+ PUSH_KICK (push[1]);
+
+- nouveau_pushbuf_space(push[2], 16, 1, 0);
++ PUSH_SPACE_EX(push[2], 16, 1, 0);
+ PUSH_REFN (push[2], dec->fence_bo, NOUVEAU_BO_GART|NOUVEAU_BO_RDWR);
+ BEGIN_NVC0(push[2], SUBC_PPP(0x240), 3);
+ PUSH_DATAh(push[2], (dec->fence_bo->offset + 0x20));
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video_ppp.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video_ppp.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video_ppp.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video_ppp.c 2022-02-11 16:42:38.048670313 -0600
+@@ -94,7 +94,7 @@ nvc0_decoder_ppp(struct nouveau_vp3_deco
+ struct nouveau_pushbuf *push = dec->pushbuf[2];
+ unsigned ppp_caps = 0x10;
+
+- nouveau_pushbuf_space(push, 32, 4, 0);
++ PUSH_SPACE_EX(push, 32, 4, 0);
+
+ switch (codec) {
+ case PIPE_VIDEO_FORMAT_MPEG12: {
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video_vp.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video_vp.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nvc0_video_vp.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nvc0_video_vp.c 2022-02-11 16:43:16.978511453 -0600
+@@ -44,7 +44,7 @@ static void dump_comm_vp(struct nouveau_
+
+ if ((comm->pvp_stage & 0xff) != 0xff) {
+ unsigned *map;
+- int ret = nouveau_bo_map(inter_bo, NOUVEAU_BO_RD|NOUVEAU_BO_NOBLOCK, dec->client);
++ int ret = BO_MAP(inter_bo, NOUVEAU_BO_RD|NOUVEAU_BO_NOBLOCK, dec->client);
+ assert(ret >= 0);
+ map = inter_bo->map;
+ for (i = 0; i < comm->byte_ofs + slice_size; i += 0x10) {
+@@ -111,7 +111,7 @@ nvc0_decoder_vp(struct nouveau_vp3_decod
+ if (!is_ref && (dec->refs[target->valid_ref].decoded_top && dec->refs[target->valid_ref].decoded_bottom))
+ nvc0_decoder_kick_ref(dec, target);
+
+- nouveau_pushbuf_space(push, 32 + codec_extra, num_refs, 0);
++ PUSH_SPACE_EX(push, 32 + codec_extra, num_refs, 0);
+
+ nouveau_pushbuf_refn(push, bo_refs, num_refs);
+
+diff -Naurp mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nve4_compute.c mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nve4_compute.c
+--- mesa-21.3.6.orig/src/gallium/drivers/nouveau/nvc0/nve4_compute.c 2022-02-09 14:10:39.000000000 -0600
++++ mesa-21.3.6/src/gallium/drivers/nouveau/nvc0/nve4_compute.c 2022-02-11 16:44:39.346172201 -0600
+@@ -545,7 +545,7 @@ nve4_compute_upload_input(struct nvc0_co
+ struct nv04_resource *res = nv04_resource(info->indirect);
+ uint32_t offset = res->offset + info->indirect_offset;
+
+- nouveau_pushbuf_space(push, 32, 0, 1);
++ PUSH_SPACE_EX(push, 32, 0, 1);
+ PUSH_REFN(push, res->bo, NOUVEAU_BO_RD | res->domain);
+
+ BEGIN_1IC0(push, NVE4_CP(UPLOAD_EXEC), 1 + 8);
+@@ -829,7 +829,7 @@ nve4_upload_indirect_desc(struct nouveau
+ PUSH_DATA (push, length);
+ PUSH_DATA (push, 1);
+
+- nouveau_pushbuf_space(push, 32, 0, 1);
++ PUSH_SPACE_EX(push, 32, 0, 1);
+ PUSH_REFN(push, res->bo, NOUVEAU_BO_RD | res->domain);
+
+ BEGIN_1IC0(push, NVE4_CP(UPLOAD_EXEC), 1 + (length / 4));
+@@ -867,9 +867,10 @@ nve4_launch_grid(struct pipe_context *pi
+ resident->flags);
+ }
+
++ simple_mtx_lock(&screen->state_lock);
+ ret = !nve4_state_validate_cp(nvc0, ~0);
+ if (ret)
+- goto out;
++ goto out_unlock;
+
+ if (nvc0->screen->compute->oclass >= GV100_COMPUTE_CLASS)
+ gv100_compute_setup_launch_desc(nvc0, desc, info);
+@@ -923,7 +924,7 @@ nve4_launch_grid(struct pipe_context *pi
+ }
+
+ /* upload descriptor and flush */
+- nouveau_pushbuf_space(push, 32, 1, 0);
++ PUSH_SPACE_EX(push, 32, 1, 0);
+ PUSH_REFN(push, screen->text, NV_VRAM_DOMAIN(&screen->base) | NOUVEAU_BO_RD);
+ BEGIN_NVC0(push, NVE4_CP(LAUNCH_DESC_ADDRESS), 1);
+ PUSH_DATA (push, desc_gpuaddr >> 8);
+@@ -934,6 +935,9 @@ nve4_launch_grid(struct pipe_context *pi
+
+ nvc0_update_compute_invocations_counter(nvc0, info);
+
++out_unlock:
++ simple_mtx_unlock(&screen->state_lock);
++
+ out:
+ if (ret)
+ NOUVEAU_ERR("Failed to launch grid !\n");
+@@ -1031,7 +1035,7 @@ nve4_compute_trap_info(struct nvc0_conte
+ volatile struct nve4_mp_trap_info *info;
+ uint8_t *map;
+
+- ret = nouveau_bo_map(bo, NOUVEAU_BO_RDWR, nvc0->base.client);
++ ret = BO_MAP(bo, NOUVEAU_BO_RDWR, nvc0->base.client);
+ if (ret)
+ return;
+ map = (uint8_t *)bo->map;
diff --git a/repo/x11/mesa.xibuild b/repo/x11/mesa/mesa.xibuild
index 1177345..1177345 100644
--- a/repo/x11/mesa.xibuild
+++ b/repo/x11/mesa/mesa.xibuild
diff --git a/repo/x11/mesa/musl-fix-includes.patch b/repo/x11/mesa/musl-fix-includes.patch
new file mode 100644
index 0000000..8553d44
--- /dev/null
+++ b/repo/x11/mesa/musl-fix-includes.patch
@@ -0,0 +1,13 @@
+diff --git a/src/util/rand_xor.c b/src/util/rand_xor.c
+index 81b64f1ea71..14e6c9d27c3 100644
+--- a/src/util/rand_xor.c
++++ b/src/util/rand_xor.c
+@@ -27,6 +27,8 @@
+ #if !DETECT_OS_WINDOWS
+ #if defined(HAVE_GETRANDOM)
+ #include <sys/random.h>
++#include <sys/types.h>
++#include <sys/stat.h>
+ #endif
+ #include <unistd.h>
+ #include <fcntl.h>
diff --git a/repo/x11/mkfontscale.xibuild b/repo/x11/mkfontscale/mkfontscale.xibuild
index 4f32c83..4f32c83 100644
--- a/repo/x11/mkfontscale.xibuild
+++ b/repo/x11/mkfontscale/mkfontscale.xibuild
diff --git a/repo/x11/motif/02-fix-format-security.patch b/repo/x11/motif/02-fix-format-security.patch
new file mode 100644
index 0000000..18c4abd
--- /dev/null
+++ b/repo/x11/motif/02-fix-format-security.patch
@@ -0,0 +1,607 @@
+Description: Fix unsafe uses of fprintf and sprintf
+ prevent 'format not a string literal and no format arguments' errors
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1574
+Author: Graham Inggs <graham@nerve.org.za>
+Last-Update: 2012-12-25
+--- a/lib/Mrm/Mrmhier.c
++++ b/lib/Mrm/Mrmhier.c
+@@ -264,10 +264,10 @@
+ case MrmSUCCESS:
+ break;
+ case MrmNOT_VALID:
+- sprintf (err_stg, _MrmMMsg_0113);
++ sprintf (err_stg, "%s", _MrmMMsg_0113);
+ break;
+ default:
+- sprintf (err_stg, _MrmMMsg_0114);
++ sprintf (err_stg, "%s", _MrmMMsg_0114);
+ break;
+ }
+ }
+--- a/lib/Mrm/Mrmicon.c
++++ b/lib/Mrm/Mrmicon.c
+@@ -1176,7 +1176,7 @@
+ }
+ break;
+ default:
+- sprintf(err_msg, _MrmMMsg_0040);
++ sprintf(err_msg, "%s", _MrmMMsg_0040);
+ return Urm__UT_Error ("Urm__RelizeColorTable",
+ err_msg, NULL, NULL, MrmFAILURE) ;
+ }
+@@ -1252,7 +1252,7 @@
+ break;
+ default:
+ result = MrmFAILURE;
+- sprintf (err_msg, _MrmMMsg_0040);
++ sprintf (err_msg, "%s", _MrmMMsg_0040);
+ Urm__UT_Error ("Urm__RelizeColorTable",
+ err_msg, NULL, NULL, MrmFAILURE) ;
+ }
+--- a/lib/Mrm/Mrmlread.c
++++ b/lib/Mrm/Mrmlread.c
+@@ -698,7 +698,7 @@
+ XBlackPixelOfScreen(XDefaultScreenOfDisplay(display)));
+ break;
+ default:
+- sprintf(err_msg, _MrmMMsg_0040);
++ sprintf(err_msg, "%s", _MrmMMsg_0040);
+ result = Urm__UT_Error ("MrmFetchColorLiteral",
+ err_msg, NULL, NULL, MrmFAILURE) ;
+ _MrmAppUnlock(app);
+--- a/lib/Mrm/Mrmwcrw.c
++++ b/lib/Mrm/Mrmwcrw.c
+@@ -1390,7 +1390,7 @@
+ }
+ break;
+ default:
+- sprintf (err_msg, _MrmMMsg_0040);
++ sprintf (err_msg, "%s", _MrmMMsg_0040);
+ result = Urm__UT_Error ("Urm__CW_ConvertValue",
+ err_msg, NULL, NULL, MrmFAILURE) ;
+ };
+@@ -2426,7 +2426,7 @@
+ }
+ break;
+ default:
+- sprintf(err_msg, _MrmMMsg_0040);
++ sprintf(err_msg, "%s", _MrmMMsg_0040);
+ return Urm__UT_Error ("Urm__CW_ConvertValue",
+ err_msg, NULL, NULL, MrmFAILURE) ;
+ };
+--- a/tools/wml/wmlouth.c
++++ b/tools/wml/wmlouth.c
+@@ -225,12 +225,12 @@
+ printf ("\nCouldn't open UilSymGen.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Write the sym_k..._object literals
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ for ( ndx=0 ; ndx<wml_obj_class_ptr->cnt ; ndx++ )
+ {
+ clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr;
+@@ -244,7 +244,7 @@
+ /*
+ * Define the sym_k_..._reason literals
+ */
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+ for ( ndx=0 ; ndx<wml_obj_reason_ptr->cnt ; ndx++ )
+ {
+ resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[ndx].objptr;
+@@ -258,7 +258,7 @@
+ /*
+ * Define the sym_k_..._arg literals
+ */
+-fprintf (outfil, canned4);
++fprintf (outfil, "%s", canned4);
+ for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
+ {
+ resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
+@@ -272,7 +272,7 @@
+ /*
+ * Define the sym_k_..._enumset structs and literals
+ */
+-fprintf (outfil, canned5);
++fprintf (outfil, "%s", canned5);
+ for ( ndx=0 ; ndx<wml_obj_enumset_ptr->cnt ; ndx++ )
+ {
+ enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr;
+@@ -286,7 +286,7 @@
+ /*
+ * Define the sym_k_..._enumval literals
+ */
+-fprintf (outfil, canned6);
++fprintf (outfil, "%s", canned6);
+ for ( ndx=0 ; ndx<wml_obj_enumval_ptr->cnt ; ndx++ )
+ {
+ enumvalobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr;
+@@ -301,7 +301,7 @@
+ * Define the sym_k_..._charsize literals
+ * Define the sym_k_..._charset literals
+ */
+-fprintf (outfil, canned7);
++fprintf (outfil, "%s", canned7);
+ for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
+ {
+ charsetobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
+@@ -315,7 +315,7 @@
+ /*
+ * Define the sym_k_..._child literals
+ */
+-fprintf (outfil, canned8);
++fprintf (outfil, "%s", canned8);
+ for ( ndx=0 ; ndx<wml_obj_child_ptr->cnt ; ndx++ )
+ {
+ childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr;
+@@ -379,12 +379,12 @@
+ printf ("\nCouldn't open UilSymChCL.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Create table entries, similar to writing sym_k...
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ for ( ndx=0 ; ndx<wml_obj_child_ptr->cnt ; ndx++ )
+ {
+ childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[ndx].objptr;
+@@ -392,7 +392,7 @@
+ fprintf (outfil, " sym_k_%s_object,\n",
+ classobj->tkname);
+ }
+-fprintf (outfil, canned1a);
++fprintf (outfil, "%s", canned1a);
+
+ /*
+ * close the output file
+@@ -446,12 +446,12 @@
+ printf ("\nCouldn't open UilSymArTy.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Create table entries, similar to writing sym_k...
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
+ {
+ resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
+@@ -459,7 +459,7 @@
+ fprintf (outfil, " sym_k_%s_value,\n",
+ datobj->tkname);
+ }
+-fprintf (outfil, canned1a);
++fprintf (outfil, "%s", canned1a);
+
+ /*
+ * close the output file
+@@ -509,19 +509,19 @@
+ printf ("\nCouldn't open UilSymRArg.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Create table entries, similar to writing sym_k...
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
+ {
+ resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
+ fprintf (outfil, " %d,\n",
+ resobj->related_code);
+ }
+-fprintf (outfil, canned1a);
++fprintf (outfil, "%s", canned1a);
+
+ /*
+ * close the output file
+@@ -621,12 +621,12 @@
+ printf ("\nCouldn't open UilUrmClas.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Write entries for widgets
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ for ( ndx=0 ; ndx<wml_obj_class_ptr->cnt ; ndx++ )
+ {
+ clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ndx].objptr;
+@@ -637,7 +637,7 @@
+ else
+ fprintf (outfil, " \"%s\",\t\n", synobj->convfunc);
+ }
+-fprintf (outfil, canned2);
++fprintf (outfil, "%s", canned2);
+
+ /*
+ * Write entries for gadget variants of widget classes
+@@ -661,7 +661,7 @@
+ synobj->name);
+ }
+ }
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+
+ /*
+ * Write entries for non-dialog widgets
+@@ -685,7 +685,7 @@
+ synobj->name);
+ }
+ }
+-fprintf (outfil, canned4);
++fprintf (outfil, "%s", canned4);
+
+ /*
+ * Write entries for the resource a widget's controls map to
+@@ -701,7 +701,7 @@
+ else
+ fprintf (outfil, " sym_k_%s_arg,\n", mapresobj->tkname);
+ }
+-fprintf (outfil, canned5);
++fprintf (outfil, "%s", canned5);
+
+ /*
+ * Write entries for arguments
+@@ -714,7 +714,7 @@
+ fprintf (outfil, " %s,\n",
+ synres->resliteral);
+ }
+-fprintf (outfil, canned6);
++fprintf (outfil, "%s", canned6);
+
+ /*
+ * Write entries for reasons
+@@ -727,7 +727,7 @@
+ fprintf (outfil, " %s,\n",
+ synres->resliteral);
+ }
+-fprintf (outfil, canned7);
++fprintf (outfil, "%s", canned7);
+
+ /*
+ * close the output file
+@@ -781,13 +781,13 @@
+ printf ("\nCouldn't open UilConst.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Process the arguments in code order. We start with 1, and write out
+ * the mask after processing 8 codes.
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ strcpy (maskbuf, "0");
+ for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
+ {
+@@ -805,7 +805,7 @@
+ }
+ if ( bitno != 8 )
+ fprintf (outfil, "%s", maskbuf);
+-fprintf (outfil, canned1a);
++fprintf (outfil, "%s", canned1a);
+
+ /*
+ * close the output file
+@@ -878,8 +878,8 @@
+ printf ("\nCouldn't open UilSymReas.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned_warn);
++fprintf (outfil, "%s", canned1);
+
+ /*
+ * Generate the bit vectors for each class. Outer loop on the reason code,
+@@ -925,13 +925,13 @@
+ /*
+ * Write the vector of vectors.
+ */
+-fprintf (outfil, canned2);
++fprintf (outfil, "%s", canned2);
+ for ( resndx=0 ; resndx<wml_obj_reason_ptr->cnt ; resndx++ )
+ {
+ resobj = (WmlResourceDefPtr) wml_obj_reason_ptr->hvec[resndx].objptr;
+ fprintf (outfil, " reason_class_vec%d,\n", resobj->sym_code);
+ }
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+
+ /*
+ * close the output file
+@@ -1004,8 +1004,8 @@
+ printf ("\nCouldn't open UilSymArTa.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned_warn);
++fprintf (outfil, "%s", canned1);
+
+ /*
+ * Generate the bit vectors for each class. Outer loop on the argument code,
+@@ -1051,13 +1051,13 @@
+ /*
+ * Write the vector of vectors.
+ */
+-fprintf (outfil, canned2);
++fprintf (outfil, "%s", canned2);
+ for ( resndx=0 ; resndx<wml_obj_arg_ptr->cnt ; resndx++ )
+ {
+ resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[resndx].objptr;
+ fprintf (outfil, " arg_class_vec%d,\n", resobj->sym_code);
+ }
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+
+ /*
+ * close the output file
+@@ -1129,8 +1129,8 @@
+ printf ("\nCouldn't open UilSymChTa.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned_warn);
++fprintf (outfil, "%s", canned1);
+
+ /*
+ * Generate the bit vectors for each class. Outer loop on the child code,
+@@ -1174,13 +1174,13 @@
+ /*
+ * Write the vector of vectors.
+ */
+-fprintf (outfil, canned2);
++fprintf (outfil, "%s", canned2);
+ for ( childndx=0 ; childndx<wml_obj_child_ptr->cnt ; childndx++ )
+ {
+ childobj = (WmlChildDefPtr) wml_obj_child_ptr->hvec[childndx].objptr;
+ fprintf (outfil, " child_class_vec%d,\n", childobj->sym_code);
+ }
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+
+ /*
+ * close the output file
+@@ -1251,8 +1251,8 @@
+ printf ("\nCouldn't open UilSymCtl.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned_warn);
++fprintf (outfil, "%s", canned1);
+
+ /*
+ * Generate the bit vectors for each class. Outer loop on the class code,
+@@ -1296,13 +1296,13 @@
+ /*
+ * Write the vector of vectors.
+ */
+-fprintf (outfil, canned2);
++fprintf (outfil, "%s", canned2);
+ for ( ctlndx=0 ; ctlndx<wml_obj_class_ptr->cnt ; ctlndx++ )
+ {
+ clsobj = (WmlClassDefPtr) wml_obj_class_ptr->hvec[ctlndx].objptr;
+ fprintf (outfil, " object_class_vec%d,\n", clsobj->sym_code);
+ }
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+
+ /*
+ * close the output file
+@@ -1438,7 +1438,7 @@
+ printf ("\nCouldn't open UilSymNam.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Write entries for widgets
+@@ -1517,7 +1517,7 @@
+ fprintf (outfil, " \"%s\",\n",
+ synch->name);
+ }
+-fprintf (outfil, canned7);
++fprintf (outfil, "%s", canned7);
+
+ /*
+ * close the output file
+@@ -1621,12 +1621,12 @@
+ printf ("\nCouldn't open UilSymEnum.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Generate the enumeration value vectors for each enumeration set.
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ for ( ndx=0 ; ndx<wml_obj_enumset_ptr->cnt ; ndx++ )
+ {
+ enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr;
+@@ -1643,7 +1643,7 @@
+ /*
+ * Generate the enumeration set tables
+ */
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+ for ( ndx=0 ; ndx<wml_obj_enumset_ptr->cnt ; ndx++ )
+ {
+ enumsetobj = (WmlEnumSetDefPtr) wml_obj_enumset_ptr->hvec[ndx].objptr;
+@@ -1655,7 +1655,7 @@
+ /*
+ * Create enumset table entries for arguments, similar to writing sym_k...
+ */
+-fprintf (outfil, canned4);
++fprintf (outfil, "%s", canned4);
+ for ( ndx=0 ; ndx<wml_obj_arg_ptr->cnt ; ndx++ )
+ {
+ resobj = (WmlResourceDefPtr) wml_obj_arg_ptr->hvec[ndx].objptr;
+@@ -1669,13 +1669,13 @@
+ /*
+ * Create the enumval values table.
+ */
+-fprintf (outfil, canned5);
++fprintf (outfil, "%s", canned5);
+ for ( ndx=0 ; ndx<wml_obj_enumval_ptr->cnt ; ndx++ )
+ {
+ evobj = (WmlEnumValueDefPtr) wml_obj_enumval_ptr->hvec[ndx].objptr;
+ fprintf (outfil, " %s,\n", evobj->syndef->enumlit);
+ }
+-fprintf (outfil, canned5a);
++fprintf (outfil, "%s", canned5a);
+
+ /*
+ * close the output file
+@@ -1813,12 +1813,12 @@
+ printf ("\nCouldn't open UilSymCSet.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Generate the standards name table
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
+ {
+ csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
+@@ -1836,7 +1836,7 @@
+ /*
+ * Generate the writing direction table
+ */
+-fprintf (outfil, canned2);
++fprintf (outfil, "%s", canned2);
+ for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
+ {
+ csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
+@@ -1858,7 +1858,7 @@
+ /*
+ * Generate the parsing direction table
+ */
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+ for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
+ {
+ csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
+@@ -1880,7 +1880,7 @@
+ /*
+ * Generate the character size table
+ */
+-fprintf (outfil, canned4);
++fprintf (outfil, "%s", canned4);
+ for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
+ {
+ csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
+@@ -1906,7 +1906,7 @@
+ /*
+ * Generate the $LANG name recognition table
+ */
+-fprintf (outfil, canned5);
++fprintf (outfil, "%s", canned5);
+ lang_max = 0;
+ for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
+ {
+@@ -1936,7 +1936,7 @@
+ /*
+ * Generate the $LANG code lookup table, in upper case
+ */
+-fprintf (outfil, canned6);
++fprintf (outfil, "%s", canned6);
+ for ( ndx=0 ; ndx<wml_obj_charset_ptr->cnt ; ndx++ )
+ {
+ csobj = (WmlCharSetDefPtr) wml_obj_charset_ptr->hvec[ndx].objptr;
+--- a/tools/wml/wmloutkey.c
++++ b/tools/wml/wmloutkey.c
+@@ -574,16 +574,16 @@
+ printf ("\nCouldn't open UilKeyTab.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
++fprintf (outfil, "%s", canned_warn);
+
+ /*
+ * Print the case sensitive and insensitive tables
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ wmlOutputUilKeyTabBody (outfil, wml_tok_sens_ptr, &maxlen, &maxkey);
+ fprintf (outfil, canned2, maxlen, maxkey);
+ wmlOutputUilKeyTabBody (outfil, wml_tok_insens_ptr, &maxlen, &maxkey);
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+
+ /*
+ * close the output file
+@@ -812,8 +812,8 @@
+ printf ("\nCouldn't open UilTokName.h");
+ return;
+ }
+-fprintf (outfil, canned_warn);
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned_warn);
++fprintf (outfil, "%s", canned1);
+
+ /*
+ * Print the token name entries
+--- a/tools/wml/wmloutmm.c
++++ b/tools/wml/wmloutmm.c
+@@ -209,9 +209,9 @@
+ /*
+ * Write out header information
+ */
+-fprintf (outfil, canned1);
++fprintf (outfil, "%s", canned1);
+ fprintf (outfil, "%s\n", name);
+-fprintf (outfil, canned2);
++fprintf (outfil, "%s", canned2);
+
+ /*
+ * Alphabetize the controls, reason, and argument lists
+@@ -287,7 +287,7 @@
+ else
+ fprintf (outfil, "\n");
+ }
+-fprintf (outfil, canned3);
++fprintf (outfil, "%s", canned3);
+
+ /*
+ * Write out the argument table
+@@ -323,7 +323,7 @@
+ }
+ argndx += 1;
+ }
+-fprintf (outfil, canned4);
++fprintf (outfil, "%s", canned4);
+
+ }
+
diff --git a/repo/x11/motif/03-no-demos.patch b/repo/x11/motif/03-no-demos.patch
new file mode 100644
index 0000000..03953c4
--- /dev/null
+++ b/repo/x11/motif/03-no-demos.patch
@@ -0,0 +1,53 @@
+Description: Add option to disable building of demos
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1575
+Author: Graham Inggs <graham@nerve.org.za>
+Last-Update: 2013-01-09
+--- a/configure.ac
++++ b/configure.ac
+@@ -311,7 +311,20 @@
+ doc/man/man5/Makefile \
+ tools/Makefile \
+ tools/wml/Makefile \
+-demos/Makefile \
++lib/Xm/xmstring.list \
++])
++
++AC_ARG_ENABLE(demos, [ --disable-demos
++ Disable building demos])
++
++if test x$enable_demos = x
++then
++ enable_demos="yes"
++fi
++
++if test "$enable_demos" = "yes"
++then
++ AC_CONFIG_FILES([demos/Makefile
+ demos/lib/Makefile \
+ demos/lib/Xmd/Makefile \
+ demos/lib/Wsm/Makefile \
+@@ -395,6 +408,11 @@
+ demos/doc/programGuide/ch17/Makefile \
+ demos/doc/programGuide/ch17/simple_drop/Makefile \
+ demos/doc/programGuide/ch17/simple_drag/Makefile \
+-lib/Xm/xmstring.list \
+-])
++ ])
++ MAYBE_DEMOS=demos
++else
++ MAYBE_DEMOS=
++fi
++AC_SUBST(MAYBE_DEMOS)
++
+ AC_OUTPUT
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -29,6 +29,7 @@
+ tools \
+ clients \
+ doc \
+- demos
++ $(MAYBE_DEMOS)
++
+ AUTOMAKE_OPTIONS = 1.4
+ ACLOCAL_AMFLAGS = -I .
diff --git a/repo/x11/motif/06-cast-size_t-to-int.patch b/repo/x11/motif/06-cast-size_t-to-int.patch
new file mode 100644
index 0000000..b5ce9c6
--- /dev/null
+++ b/repo/x11/motif/06-cast-size_t-to-int.patch
@@ -0,0 +1,17 @@
+Description: To prevent build failure during building with Hardening options
+ enabled due to "format '%d' expects argument of type 'int', but argument 5 has
+ type 'size_t'", the fifth argument is cast to integer on the input.
+Author: Paul Gevers <elbrus@debian.org>
+Updated: 13-01-2013
+
+--- a/tools/wml/wmloutkey.c
++++ b/tools/wml/wmloutkey.c
+@@ -627,7 +627,7 @@
+ fprintf (outfil, " {%s, %s, %d, %s, \"%s\"},\n",
+ tkclass,
+ tksym,
+- strlen(tokstg),
++ (int)strlen(tokstg),
+ tktoken,
+ tokstg);
+ if ( (int)strlen(tokstg) > *maxlen )
diff --git a/repo/x11/motif/07-fix_lintian_reported_manpage_typos.patch b/repo/x11/motif/07-fix_lintian_reported_manpage_typos.patch
new file mode 100644
index 0000000..5ddfd76
--- /dev/null
+++ b/repo/x11/motif/07-fix_lintian_reported_manpage_typos.patch
@@ -0,0 +1,118 @@
+Description: lintian reports several typos in manpages. This patch fixes those
+ reported
+Author: Paul Gevers <elbrus@debian.org>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1587
+Last-reviewed: 14 Jan 2013
+
+--- a/doc/man/man1/mwm.1
++++ b/doc/man/man1/mwm.1
+@@ -359,7 +359,7 @@
+ (and other associated messages) by saving the geometries of its clients to a state file\&.
+ \fBmwm\fP can then be restarted by the XSMP session manager\&.
+ The default location for the state file is \fB$HOME/\&.mwmclientdb\fP\&.
+-This location can be overriden with the resource \fBsessionClientDB\fP\&.
++This location can be overridden with the resource \fBsessionClientDB\fP\&.
+ .SS "X Resources"
+ .PP
+ The \fBmwm\fP command is configured from its resource
+--- a/doc/man/man3/VendorShell.3
++++ b/doc/man/man3/VendorShell.3
+@@ -76,7 +76,7 @@
+ to the VendorShell resources for controlling toolTips. VendorShell displays
+ the XmNtooTipString in an XmLabel that is a child of a transientShell. The name
+ of the transientShell is TipShell, and the name of the XmLabel is TipLabel.
+-The appearance of the tip can be controlled by specifing resources on these
++The appearance of the tip can be controlled by specifying resources on these
+ widgets.
+ .PP
+ If an application uses the \fBXmNmwmDecorations\fP,
+--- a/doc/man/man3/XmComboBox.3
++++ b/doc/man/man3/XmComboBox.3
+@@ -581,7 +581,7 @@
+ ComboBox \fBXmNcomboBoxType\fP is
+ \fBXmDROP_DOWN_LIST\fP,
+ \fB<osfActivate>\fP, \fB<osfCancel>\fP, and
+-\fBReturn\fP are overriden by ComboBox actions\&.
++\fBReturn\fP are overridden by ComboBox actions\&.
+ .IP "\fB:c\fP <Key>\fB<osfDown>\fP:" 10
+ CBDropDownList()
+ .IP "\fB:c\fP <Key>\fB<osfUp>\fP:" 10
+--- a/doc/man/man3/XmGetPixmap.3
++++ b/doc/man/man3/XmGetPixmap.3
+@@ -109,7 +109,7 @@
+ In addition to X bitmap files (XBM), Motif also supports XPM (X
+ Pixmap) file formats and, from version 2.3, JPEG and PNG image formats\&.
+ (Note that support of JPEG and PNG image format is an optional feature
+-of Motif, in order to check if current version supports PNG ang JPEG
++of Motif, in order to check if current version supports PNG and JPEG
+ image formats the PNG_SUPPORT and JPEG_SUPPORT macros should be checked
+ correspondingly.)
+ The \fBXBMLANGPATH\fP specifies the path for
+--- a/doc/man/man3/XmGetPixmapByDepth.3
++++ b/doc/man/man3/XmGetPixmapByDepth.3
+@@ -111,7 +111,7 @@
+ In addition to X bitmap files (XBM), Motif also supports XPM (X
+ Pixmap) file formats, and, from version 2.3, JPEG and PNG image formats\&.
+ (Note that support of JPEG and PNG image format is an optional feature
+-of Motif, in order to check if current version supports PNG ang JPEG
++of Motif, in order to check if current version supports PNG and JPEG
+ image formats the PNG_SUPPORT and JPEG_SUPPORT macros should be checked
+ correspondingly.)
+ The \fBXBMLANGPATH\fP specifies the path for
+--- a/doc/man/man3/XmHierarchyGetChildNodes.3
++++ b/doc/man/man3/XmHierarchyGetChildNodes.3
+@@ -69,8 +69,8 @@
+ \fBXmHierarchy\fP(3)\&.
+ .SH "RETURN"
+ .PP
+-Returns WidgetList with child nodes of the hierachy, or NULL
+-if the hierachy contains no children\&.
++Returns WidgetList with child nodes of the hierarchy, or NULL
++if the hierarchy contains no children\&.
+ .SH "RELATED"
+ .PP
+ \fBXmHierarchy\fP(3)\&.
+--- a/doc/man/man3/XmManager.3
++++ b/doc/man/man3/XmManager.3
+@@ -502,7 +502,7 @@
+ Indicates whether the posting process should continue\&. The
+ application may modify this field\&.
+ .IP "\fItarget\fP" 10
+-Specifies the most specific widget or gadget that the menu sytem found
++Specifies the most specific widget or gadget that the menu system found
+ from the event that matches the event\&.
+ .SS "Translations"
+ .PP
+--- a/doc/man/man3/XmPrimitive.3
++++ b/doc/man/man3/XmPrimitive.3
+@@ -609,7 +609,7 @@
+ Indicates whether the posting process should continue\&. The
+ application may modify this field\&.
+ .IP "\fItarget\fP" 10
+-Specifies the most specific widget or gadget that the menu sytem found
++Specifies the most specific widget or gadget that the menu system found
+ from the event that matches the event\&.
+ .SS "Translations"
+ .PP
+--- a/doc/man/man3/XmRendition.3
++++ b/doc/man/man3/XmRendition.3
+@@ -71,7 +71,7 @@
+ If a resource in a rendition is unspecified, usually by setting it to
+ \fBXmAS_IS\fP or \fBXmUNSPECIFIED_PIXEL\fP,
+ then the value to be used for that resource is the value of the
+-immediately preceeding rendition in \fBXmString\fR\&. If that value
++immediately preceding rendition in \fBXmString\fR\&. If that value
+ is unspecified, then the preceding value is used, and so on\&. If
+ no renditions specify a value for a resource, then a default value
+ will be used\&.
+--- a/doc/man/man3/XmStringGetNextComponent.3
++++ b/doc/man/man3/XmStringGetNextComponent.3
+@@ -111,7 +111,7 @@
+ \fBXmSTRING_COMPONENT_UNKNOWN\fP\&. The data returned by these
+ components is returned in the \fIunknown_tag\fP, \fIunknown_length\fP,
+ and \fIunknown_value\fP fields\&. This apparent inconsistency is
+-designed to accomodate older applications that may not be equipped to
++designed to accommodate older applications that may not be equipped to
+ handle the newer component types of Motif version 2\&.0 and beyond\&.
+ Consequently, the use of this procedure is not recommended\&. Instead,
+ use the \fBXmStringGetNextTriple\fP procedure, which provides all the
diff --git a/repo/x11/motif/08-fix_hyphen_in_man_pages.patch b/repo/x11/motif/08-fix_hyphen_in_man_pages.patch
new file mode 100644
index 0000000..bc1beb0
--- /dev/null
+++ b/repo/x11/motif/08-fix_hyphen_in_man_pages.patch
@@ -0,0 +1,156 @@
+Description: lintian reports hyphen misuse in manpages. This patch fixes those
+ reported.
+Author: Paul Gevers <elbrus@debian.org>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1588
+Last-reviewed: 06 Feb 2013
+
+--- a/doc/man/man1/mwm.1
++++ b/doc/man/man1/mwm.1
+@@ -904,7 +904,7 @@
+ resizeCursorsResizeCursorsT/FT
+ transientDecorationTransientDecorationstringmenu title
+ transientFunctionsTransientFunctionsstringT{
+--minimize-maximize
++\-minimize-maximize
+ T}
+ useIconBoxUseIconBoxT/FF
+ .TE
+@@ -941,7 +941,7 @@
+ screen size of the icon box window depends on the iconImageMaximum (size)
+ and \fIiconDecoration\fP resources\&. The default value for size
+ is (6 * iconWidth + padding) wide by (1 * iconHeight + padding) high\&. The
+-default value of the location is +0 -0\&.
++default value of the location is +0 \-0\&.
+ .IP "\fIiconBoxName\fP\ (class\ \fIIconBoxName\fP)" 10
+ This resource specifies the name that is used to look up icon box resources\&.
+ The default name is iconbox\&.
+@@ -1059,7 +1059,7 @@
+ This resource is used to indicate which window management functions
+ are applicable (or not applicable) to transient windows\&. The function specification
+ is exactly the same as for the \fIclientFunctions\fP (client
+-specific) resource\&. The default value for this resource is -minimize -maximize\&.
++specific) resource\&. The default value for this resource is \-minimize \-maximize\&.
+ .IP "" 10
+ An application can also specify which functions \fBmwm\fP
+ should apply to its windows\&. If it does so, \fBmwm\fP applies
+@@ -1176,7 +1176,7 @@
+ titleTitle bar (includes border)\&.
+ .TE
+ .PP
+-Examples: \fIMwm*XClock\&.clientDecoration: -resizeh -maximize\fP This removes the resize handles and maximize button from XClock
++Examples: \fIMwm*XClock\&.clientDecoration: \-resizeh \-maximize\fP This removes the resize handles and maximize button from XClock
+ windows\&. \fIMwm*XClock\&.clientDecoration: menu minimize border\fP This does the same thing as above\&. Note that either \fImenu\fP or \fIminimize\fP implies
+ \fItitle\fP\&.
+ .IP "\fIclientFunctions\fP\ (class\ \fIClientFunctions\fP)" 10
+--- a/doc/man/man4/mwmrc.4
++++ b/doc/man/man4/mwmrc.4
+@@ -84,7 +84,7 @@
+ be specified from the command line:
+ .PP
+ .nf
+-\f(CW/usr/X11R6/bin/X11/mwm -xrm "mwm*configFile: mymwmrc"\fR
++\f(CW/usr/X11R6/bin/X11/mwm \-xrm "mwm*configFile: mymwmrc"\fR
+ .fi
+ .PP
+ .SS "Resource Types"
+--- a/doc/man/man3/XmFontList.3
++++ b/doc/man/man3/XmFontList.3
+@@ -119,7 +119,7 @@
+ without a font list entry tag;
+ .PP
+ .nf
+-\f(CW*fontList: -Adobe-Times-Medium-I-Normal--10*\fR
++\f(CW*fontList: \-Adobe\-Times\-Medium\-I\-Normal\-\-10*\fR
+ .fi
+ .PP
+ .PP
+@@ -138,9 +138,9 @@
+ and an explicit font list entry tag\&.
+ .PP
+ .nf
+-\f(CW*fontList: -Adobe-Courier-Bold-R-Normal--25-180-100-100-M-150;\
+--JIS-Fixed-Medium-R-Normal--26-180-100-100-C-240;\
+--JIS-Fixed-Medium-R-Normal--26-180-100-100-C-120:MY_TAG\fR
++\f(CW*fontList: \-Adobe\-Courier\-Bold\-R\-Normal\-\-25\-180\-100\-100\-M\-150;\
++\-JIS\-Fixed\-Medium\-R\-Normal\-\-26\-180\-100\-100\-C\-240;\
++\-JIS\-Fixed\-Medium\-R\-Normal\-\-26\-180\-100\-100\-C\-120:MY_TAG\fR
+ .fi
+ .PP
+ .PP
+--- a/doc/man/man3/XmGetPixmapByDepth.3
++++ b/doc/man/man3/XmGetPixmapByDepth.3
+@@ -245,8 +245,8 @@
+ \f(CW/* XBM file */
+ #define plaid_width 22
+ #define plaid_height 22
+-#define plaid_x_hot -1
+-#define plaid_y_hot -1
++#define plaid_x_hot \-1
++#define plaid_y_hot \-1
+ static char plaid_bits[] = {
+ 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
+ 0x75, 0xfd, 0x3f, 0xff, 0x57, 0x15, 0x75, 0xfd, 0x3f, 0xaa, 0xfa, 0x3e,
+--- a/doc/man/man3/XmList.3
++++ b/doc/man/man3/XmList.3
+@@ -182,7 +182,7 @@
+ A value of 1 transfers the first item in the List; a value of 2
+ transfers the second item; and so on\&.
+ If the entire contents of the List are being transferred, the value is
+--1\&.
++\-1\&.
+ .PP
+ As a source of data, List supports the following targets and associated
+ conversions of data to these targets:
+--- a/doc/man/man3/XmScreen.3
++++ b/doc/man/man3/XmScreen.3
+@@ -300,7 +300,7 @@
+ startup time, either by placing it within a defaults file or by using the
+ \fB-xrm\fP command line argument\&. For example:
+ .IP "" 10
+-\fBmyProg -xrm "*menuCursor: arrow"\fP
++\fBmyProg \-xrm "*menuCursor: arrow"\fP
+ .IP "" 10
+ The menu cursor can also be selected in the program through
+ the function \fBXmSetMenuCursor\fP\&.
+--- a/doc/man/man3/XmTabListCopy.3
++++ b/doc/man/man3/XmTabListCopy.3
+@@ -71,7 +71,7 @@
+ Specifies where to start copying\&. A value of 0 (zero) indicates begin
+ at the beginning, a value of 1 indicates to skip the first tab, and so
+ on\&. A negative indicates to begin counting backwards from the end\&.
+-A value of -1 indicates to start copying from the last tab\&.
++A value of \-1 indicates to start copying from the last tab\&.
+ .IP "\fIcount\fP" 10
+ Specifies the number of tabs to copy\&. A value of 0 (zero) indicates
+ to copy all elements from the starting point to the end (beginning if
+--- a/doc/man/man3/XmTabListInsertTabs.3
++++ b/doc/man/man3/XmTabListInsertTabs.3
+@@ -83,7 +83,7 @@
+ value of 1 makes it the second tab, and so on\&. If \fIposition\fP is
+ greater than the number of tabs in \fIoldlist\fP, then the tabs will
+ be inserted at the end\&. If \fIposition\fP is negative, the count will
+-be backwards from the end\&. A value of -1 makes the first new tab
++be backwards from the end\&. A value of \-1 makes the first new tab
+ the last tab, and so on\&.
+ .SH "RETURN"
+ .PP
+--- a/doc/man/man5/UIL.5
++++ b/doc/man/man5/UIL.5
+@@ -1211,7 +1211,7 @@
+ 3\&.1415E-2 (equals \&.031415)
+ T}2\&.87 e6 (embedded blanks)
+ T{
+--6\&.29e7 (equals -62900000)
++\-6\&.29e7 (equals \-62900000)
+ T}2\&.0e100 (out of range)
+ .TE
+ .PP
+@@ -1322,7 +1322,7 @@
+ You can use parentheses to override the normal precedence of operators\&.
+ In a sequence of unary operators, the operations are performed in
+ right-to-left
+-order\&. For example, \fB- + -A\fP is equivalent to \fB-(+(-A))\fP\&.
++order\&. For example, \fB- + \-A\fP is equivalent to \fB\-(+(\-A))\fP\&.
+ In a sequence of binary operators of the same precedence, the operations
+ are performed in left-to-right order\&. For example, \fBA*B/C*D\fP is
+ equivalent to \fB((A*B)/C)*D\fP\&.
diff --git a/repo/x11/motif/09-fix_typo_in_libxm.patch b/repo/x11/motif/09-fix_typo_in_libxm.patch
new file mode 100644
index 0000000..90d39a3
--- /dev/null
+++ b/repo/x11/motif/09-fix_typo_in_libxm.patch
@@ -0,0 +1,25 @@
+Description: lintian reports a typo in libXm. This patch fixes it.
+Author: Paul Gevers <elbrus@debian.org>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1589
+Last-reviewed: 06 Feb 2013
+
+--- a/lib/Xm/FontS.c
++++ b/lib/Xm/FontS.c
+@@ -1225,7 +1225,7 @@
+
+ if ((fontdata = XLoadQueryFont(XtDisplay((Widget) fsw), font)) == NULL)
+ {
+- sprintf(buf, "Font '%s'\nis not availiable on this machine", font);
++ sprintf(buf, "Font '%s'\nis not available on this machine", font);
+ DisplayUserError(fsw, buf);
+ err = True;
+ }
+@@ -1275,7 +1275,7 @@
+ fbuf)) == NULL)
+ {
+ sprintf(buf,
+- "Font '%s'\nis not availiable on this machine",
++ "Font '%s'\nis not available on this machine",
+ font);
+ DisplayUserError(fsw, buf);
+ err = True;
diff --git a/repo/x11/motif/10-fix_manpage-has-bad-whatis-entry.patch b/repo/x11/motif/10-fix_manpage-has-bad-whatis-entry.patch
new file mode 100644
index 0000000..cf51d1f
--- /dev/null
+++ b/repo/x11/motif/10-fix_manpage-has-bad-whatis-entry.patch
@@ -0,0 +1,49 @@
+Description: lintian reports bad whatis entries in manpages. Fixing here
+Author: Paul Gevers <elbrus@debian.org>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1590
+Last-reviewed: 17 Feb 2013
+
+--- a/doc/man/man3/XmColorSelector.3
++++ b/doc/man/man3/XmColorSelector.3
+@@ -1,7 +1,7 @@
+ .DT
+ .TH XmColorSelector 3X ""
+ .SH NAME
+-The Color Selector widget
++XmColorSelector \- The Color Selector widget
+ .SH SYNOPSIS
+ #include <Xm/ColorS.h>
+ .SH DESCRIPTION
+--- a/doc/man/man3/XmExt18List.3
++++ b/doc/man/man3/XmExt18List.3
+@@ -1,7 +1,7 @@
+ .DT
+ .TH XxExt18LIst 3x ""
+ .SH NAME
+-The Internationalized Extended List widget
++XmExt18List \- The Internationalized Extended List widget
+ .SH SYNOPSIS
+ #include <Xm/Ext18List.h>
+ .SH DESCRIPTION
+--- a/doc/man/man3/XmFontSelector.3
++++ b/doc/man/man3/XmFontSelector.3
+@@ -1,7 +1,7 @@
+ .DT
+ .TH XmFontSelector 3X ""
+ .SH NAME
+-The Font Selector widget
++XmFontSelector \- The Font Selector widget
+ .SH SYNOPSIS
+ #include <Xm/FontS.h>
+ .SH DESCRIPTION
+--- a/doc/man/man3/XmIconButton.3
++++ b/doc/man/man3/XmIconButton.3
+@@ -1,7 +1,7 @@
+ .DT
+ .TH XmIconButton 3X "15 July 1992"
+ .SH NAME
+-The Icon Button widget
++XmIconButton \- The Icon Button widget
+ .SH SYNOPSIS
+ Documents the XmIconButton widget
+ .SH DESCRIPTION
diff --git a/repo/x11/motif/11-fix_underlinking.patch b/repo/x11/motif/11-fix_underlinking.patch
new file mode 100644
index 0000000..601b091
--- /dev/null
+++ b/repo/x11/motif/11-fix_underlinking.patch
@@ -0,0 +1,564 @@
+Description: Fix underlinking of libXt, libXext and libX11
+ Recent changes to default linker behaviour prevent shared libraries from being
+ indirectly linked, resulting in FTBFS in Ubuntu Raring.
+ .
+ This patch fixes this by explicitly linking libXt, libXext and libX11 wherever
+ necessary. Demos are patched even though they are not built for distribution.
+Author: Graham Inggs <graham@nerve.org.za>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1583
+Last-Update: 2013-02-26
+--- a/clients/mwm/Makefile.am
++++ b/clients/mwm/Makefile.am
+@@ -9,7 +9,7 @@
+ rc_DATA = system.mwmrc
+
+ bin_PROGRAMS = mwm
+-mwm_LDADD = ./WmWsmLib/libWsm.a ../../lib/Xm/libXm.la
++mwm_LDADD = ./WmWsmLib/libWsm.a ../../lib/Xm/libXm.la -lXt -lXext -lX11
+
+ INCLUDES = -DLARGECURSORS -DR2_COMPAT -DUNMAP_ON_RESTART \
+ -DCDE_INSTALLATION_TOP=\"@CDE_INSTALLATION_TOP@\" \
+--- a/clients/uil/Makefile.am
++++ b/clients/uil/Makefile.am
+@@ -11,9 +11,9 @@
+ UilParser.lo: UilParser.c
+ $(LTCOMPILE) -DCALLABLE -c UilParser.c
+
+-libUil_la_LIBADD = UilParser.lo ../../lib/Mrm/libMrm.la ../../lib/Xm/libXm.la
++libUil_la_LIBADD = UilParser.lo ../../lib/Mrm/libMrm.la ../../lib/Xm/libXm.la -lXt
+
+-uil_LDADD = ../../lib/Mrm/libMrm.la ../../lib/Xm/libXm.la
++uil_LDADD = ../../lib/Mrm/libMrm.la ../../lib/Xm/libXm.la -lXt
+
+ INCLUDES = -DINCDIR=\"@INCDIR@\" \
+ -DLIBDIR=\"@LIBDIR@\" \
+--- a/clients/xmbind/Makefile.am
++++ b/clients/xmbind/Makefile.am
+@@ -2,6 +2,6 @@
+
+ bin_PROGRAMS = xmbind
+
+-LDADD = ../../lib/Xm/libXm.la
++LDADD = ../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/doc/programGuide/ch05/Scale/Makefile.am
++++ b/demos/doc/programGuide/ch05/Scale/Makefile.am
+@@ -8,4 +8,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/doc/programGuide/ch06/combo_box/Makefile.am
++++ b/demos/doc/programGuide/ch06/combo_box/Makefile.am
+@@ -9,4 +9,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/doc/programGuide/ch06/spin_box/Makefile.am
++++ b/demos/doc/programGuide/ch06/spin_box/Makefile.am
+@@ -9,4 +9,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/doc/programGuide/ch08/Container/Makefile.am
++++ b/demos/doc/programGuide/ch08/Container/Makefile.am
+@@ -8,4 +8,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/doc/programGuide/ch08/Notebook/Makefile.am
++++ b/demos/doc/programGuide/ch08/Notebook/Makefile.am
+@@ -8,4 +8,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/doc/programGuide/ch16/Makefile.am
++++ b/demos/doc/programGuide/ch16/Makefile.am
+@@ -9,4 +9,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/doc/programGuide/ch17/simple_drag/Makefile.am
++++ b/demos/doc/programGuide/ch17/simple_drag/Makefile.am
+@@ -9,4 +9,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/doc/programGuide/ch17/simple_drop/Makefile.am
++++ b/demos/doc/programGuide/ch17/simple_drop/Makefile.am
+@@ -9,4 +9,4 @@
+
+ INCLUDES = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_srcdir)/demos/lib $(X_CFLAGS)
+
+-LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la
++LDADD = -L$(top_builddir)/demos/lib/Xmd -lXmd $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+--- a/demos/lib/Exm/wml/Makefile.am
++++ b/demos/lib/Exm/wml/Makefile.am
+@@ -18,7 +18,7 @@
+ -I$(top_builddir)/clients/uil \
+ ${X_CFLAGS}
+
+-LDADD = $(top_builddir)/lib/Xm/libXm.la
++LDADD = $(top_builddir)/lib/Xm/libXm.la -lXt
+
+ DISTCLEANFILES = motif.wmd
+
+--- a/demos/lib/Xmd/Makefile.am
++++ b/demos/lib/Xmd/Makefile.am
+@@ -12,7 +12,7 @@
+ Print.h PrintP.h \
+ RegEdit.h RegEditI.h
+
+-LDADD = libXmd.a ../../../lib/Xm/libXm.la
++LDADD = libXmd.a ../../../lib/Xm/libXm.la -lXt
+
+ INCLUDES = -I$(top_builddir)/lib -I$(srcdir)/../../../lib ${X_CFLAGS}
+
+--- a/demos/programs/ButtonBox/Makefile.am
++++ b/demos/programs/ButtonBox/Makefile.am
+@@ -8,6 +8,6 @@
+ bboxdemo_SOURCES = bboxdemo.c
+ data_DATA = $(EXTRA_DIST) $(bboxdemo_SOURCES)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt
+
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/ColorSel/Makefile.am
++++ b/demos/programs/ColorSel/Makefile.am
+@@ -7,6 +7,6 @@
+ colordemo_SOURCES = util-c.c colordemo.c
+ EXTRA_DIST = Imakefile
+ data_DATA = $(colordemo_SOURCES) $(EXTRA_DIST)
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt -lX11
+ TOPDIR = ../../..
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/Column/Makefile.am
++++ b/demos/programs/Column/Makefile.am
+@@ -8,5 +8,5 @@
+ EXTRA_DIST = Imakefile Column.ad
+ data_DATA = $(EXTRA_DIST) $(column_SOURCES)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt -lX11
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/Combo2/Makefile.am
++++ b/demos/programs/Combo2/Makefile.am
+@@ -8,5 +8,5 @@
+ combo_SOURCES = combo.c
+ data_DATA = $(EXTRA_DIST) $(combo_SOURCES)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/Exm/app_in_c/Makefile.am
++++ b/demos/programs/Exm/app_in_c/Makefile.am
+@@ -14,4 +14,4 @@
+ -I$(top_builddir)/lib \
+ ${X_CFLAGS}
+ LDADD = ../../../lib/Exm/libExm.a \
+- ../../../../lib/Xm/libXm.la
++ ../../../../lib/Xm/libXm.la -lXt -lXext -lX11
+--- a/demos/programs/Exm/simple_app/Makefile.am
++++ b/demos/programs/Exm/simple_app/Makefile.am
+@@ -14,5 +14,6 @@
+ -I$(srcdir)/../../../lib \
+ -I$(top_builddir)/lib \
+ ${X_CFLAGS}
+-LDADD = ../../../../lib/Xm/libXm.la \
+- ../../../lib/Exm/libExm.a
++LDADD = ../../../lib/Exm/libExm.a \
++ ../../../../lib/Xm/libXm.la -lXt -lX11
++
+--- a/demos/programs/Ext18List/Makefile.am
++++ b/demos/programs/Ext18List/Makefile.am
+@@ -10,6 +10,6 @@
+ EXTRA_DIST = Imakefile
+ data_DATA = $(EXTRA_DIST) $(ext18list_SOURCES)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(TOPDIR)/lib -I.. -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/FontSel/Makefile.am
++++ b/demos/programs/FontSel/Makefile.am
+@@ -7,6 +7,6 @@
+ fontsel_SOURCES = callbacks-c.c creation-c.c fontsel.c fontsel.h
+ EXTRA_DIST = Imakefile
+ data_DATA = $(EXTRA_DIST) $(fontsel_SOURCES)
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt
+ TOPDIR = ../../..
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/IconB/Makefile.am
++++ b/demos/programs/IconB/Makefile.am
+@@ -8,7 +8,7 @@
+ iconbuttondemo_SOURCES = misc.c iconbuttondemo.c
+ data_DATA = $(iconbuttondemo_SOURCES) $(EXTRA_DIST)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/.. \
+ -I$(srcdir)/$(TOPDIR)/lib \
+--- a/demos/programs/Outline/Makefile.am
++++ b/demos/programs/Outline/Makefile.am
+@@ -7,6 +7,6 @@
+ bin_PROGRAMS = outline
+ outline_SOURCES = outline.c
+ data_DATA = $(outline_SOURCES) $(EXTRA_DIST)
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt
+ TOPDIR = ../../..
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/Paned/Makefile.am
++++ b/demos/programs/Paned/Makefile.am
+@@ -8,6 +8,6 @@
+ paned_SOURCES = creation-c.c paned.c
+ data_DATA = $(EXTRA_DIST) $(paned_SOURCES)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt
+
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/TabStack/Makefile.am
++++ b/demos/programs/TabStack/Makefile.am
+@@ -8,6 +8,6 @@
+ EXTRA_DIST = Imakefile
+ data_DATA = $(tabstack_SOURCES) $(EXTRA_DIST)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/Tree/Makefile.am
++++ b/demos/programs/Tree/Makefile.am
+@@ -8,6 +8,6 @@
+ tree_SOURCES = bxutil-c.c tree.c
+ data_DATA = $(EXTRA_DIST) $(tree_SOURCES)
+ TOPDIR = ../../..
+-LDADD = $(TOPDIR)/lib/Xm/libXm.la
++LDADD = $(TOPDIR)/lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(TOPDIR)/lib -I$(srcdir)/.. -I$(srcdir)/$(TOPDIR)/lib ${X_CFLAGS}
+--- a/demos/programs/airport/Makefile.am
++++ b/demos/programs/airport/Makefile.am
+@@ -8,5 +8,5 @@
+ dragsource.h dropsite.h main.h
+ EXTRA_DIST = Imakefile XmdAirport.ad README
+ data_DATA = $(airport_SOURCES) $(EXTRA_DIST)
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/animate/Makefile.am
++++ b/demos/programs/animate/Makefile.am
+@@ -17,7 +17,7 @@
+
+ bin_PROGRAMS = xmanimate
+
+-LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Mrm/libMrm.la ../../../lib/Xm/libXm.la
++LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Mrm/libMrm.la ../../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib \
+ -I$(srcdir)/../../lib \
+--- a/demos/programs/drag_and_drop/Makefile.am
++++ b/demos/programs/drag_and_drop/Makefile.am
+@@ -10,6 +10,6 @@
+ simpledrop_SOURCES = simpledrop.c
+ data_DATA = $(EXTRA_DIST) $(DNDDemo_SOURCES) $(simpledrop_SOURCES)
+ noinst_HEADERS = DNDDemo.h
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/draw/Makefile.am
++++ b/demos/programs/draw/Makefile.am
+@@ -7,5 +7,5 @@
+ draw_SOURCES = draw.c
+ EXTRA_DIST = Imakefile XmdDraw.ad README draw.help draw.man
+ data_DATA = $(EXTRA_DIST) $(draw_SOURCES)
+-LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la
++LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la -lXt -lX11
+ INCLUDES = -I$(srcdir)/../../lib -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/earth/Makefile.am
++++ b/demos/programs/earth/Makefile.am
+@@ -7,5 +7,5 @@
+ earth_SOURCES = earth.c
+ EXTRA_DIST = terre.xbm earth.man Imakefile README
+ data_DATA = $(EXTRA_DIST) $(earth_SOURCES)
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lXext -lX11
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/filemanager/Makefile.am
++++ b/demos/programs/filemanager/Makefile.am
+@@ -11,7 +11,7 @@
+ obj.xpm pix.xpm s_dir.xpm s_exec.xpm s_file.xpm \
+ s_none.xpm s_pix.xpm
+ data_DATA = $(EXTRA_DIST) $(filemanager_SOURCES)
+-LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la
++LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la -lXt -lX11
+ INCLUDES = -I$(srcdir)/../../lib -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+
+
+--- a/demos/programs/fileview/Makefile.am
++++ b/demos/programs/fileview/Makefile.am
+@@ -11,7 +11,7 @@
+
+ UILS= French.uil German.uil English.uil
+
+-LDADD = ../../../lib/Xm/libXm.la ../../../lib/Mrm/libMrm.la
++LDADD = ../../../lib/Xm/libXm.la ../../../lib/Mrm/libMrm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+
+--- a/demos/programs/getsubres/Makefile.am
++++ b/demos/programs/getsubres/Makefile.am
+@@ -7,5 +7,5 @@
+ EXTRA_DIST = getsubres.help getsubres.man README Imakefile
+ getsubres_SOURCES = getsubres.c
+ data_DATA = $(EXTRA_DIST) $(getsubres_SOURCES)
+-LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la
++LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la -lXt -lX11
+ INCLUDES = -I$(srcdir)/../../lib -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/hellomotif/Makefile.am
++++ b/demos/programs/hellomotif/Makefile.am
+@@ -7,7 +7,7 @@
+ EXTRA_DIST = hellomotif.uil Imakefile README
+ hellomotif_SOURCES = hellomotif.c
+ data_DATA = $(EXTRA_DIST) $(hellomotif_SOURCES) hellomotif.uid
+-LDADD = ../../../lib/Xm/libXm.la ../../../lib/Mrm/libMrm.la
++LDADD = ../../../lib/Xm/libXm.la ../../../lib/Mrm/libMrm.la -lXt
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+
+ all: hellomotif.uid
+--- a/demos/programs/hellomotifi18n/Makefile.am
++++ b/demos/programs/hellomotifi18n/Makefile.am
+@@ -12,7 +12,7 @@
+ helloint_DEPENDENCIES = helloint.uid C/uid/l_strings.uid english/uid/l_strings.uid french/uid/l_strings.uid hebrew/uid/l_strings.uid japan/uid/l_strings.uid japanese/uid/l_strings.uid swedish/uid/l_strings.uid
+
+ INCLUDES = -I$(top_srcdir)/lib -I$(top_builddir)/lib ${X_CFLAGS}
+-LDADD = $(top_builddir)/lib/Mrm/libMrm.la $(top_builddir)/lib/Xm/libXm.la
++LDADD = $(top_builddir)/lib/Mrm/libMrm.la $(top_builddir)/lib/Xm/libXm.la -lXt
+
+ SUFFIXES = .uil .uid
+
+--- a/demos/programs/i18ninput/Makefile.am
++++ b/demos/programs/i18ninput/Makefile.am
+@@ -8,6 +8,6 @@
+ EXTRA_DIST = XmdI18nInput.ad README i18ninput.man i18ninput.help \
+ Imakefile
+ data_DATA = $(EXTRA_DIST) $(i18ninput_SOURCES)
+-LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la
++LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../lib -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/panner/Makefile.am
++++ b/demos/programs/panner/Makefile.am
+@@ -7,5 +7,5 @@
+ panner_SOURCES = panner.c
+ EXTRA_DIST = README panner.man Imakefile
+ data_DATA = $(EXTRA_DIST) $(panner_SOURCES)
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/periodic/Makefile.am
++++ b/demos/programs/periodic/Makefile.am
+@@ -7,7 +7,7 @@
+ EXTRA_DIST = periodic.uil periodic_l.uil XmdPeriodic.ad Imakefile README
+ periodic_SOURCES = periodic.c
+ data_DATA = $(EXTRA_DIST) $(periodic_SOURCES) periodic.uid
+-LDADD = ../../../lib/Xm/libXm.la ../../../lib/Mrm/libMrm.la
++LDADD = ../../../lib/Xm/libXm.la ../../../lib/Mrm/libMrm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+
+--- a/demos/programs/piano/Makefile.am
++++ b/demos/programs/piano/Makefile.am
+@@ -8,6 +8,6 @@
+ EXTRA_DIST = piano.images README Inv8_part1.piano Inv8_part2.piano \
+ piano.man Imakefile
+ data_DATA = $(EXTRA_DIST) $(piano_SOURCES)
+-LDADD = ../../../lib/Xm/libXm.la -lm
++LDADD = ../../../lib/Xm/libXm.la -lm -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/popups/Makefile.am
++++ b/demos/programs/popups/Makefile.am
+@@ -7,6 +7,6 @@
+ autopopups_SOURCES = autopopups.c
+ EXTRA_DIST = README autopopups.man Imakefile
+ data_DATA = $(EXTRA_DIST) $(autopopups_SOURCES)
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/sampler2_0/Makefile.am
++++ b/demos/programs/sampler2_0/Makefile.am
+@@ -10,6 +10,6 @@
+ bin_PROGRAMS = sampler2_0
+ sampler2_0_SOURCES = sampler2_0.c
+ data_DATA = $(sampler2_0_SOURCES) $(EXTRA_DIST)
+-LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la
++LDADD = ../../lib/Xmd/libXmd.a ../../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../lib -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/setdate/Makefile.am
++++ b/demos/programs/setdate/Makefile.am
+@@ -7,6 +7,6 @@
+ EXTRA_DIST = XmdSetDate.ad README setDate.man Imakefile
+ setDate_SOURCES = setDate.c
+ data_DATA = $(EXTRA_DIST) $(setDate_SOURCES)
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/todo/Makefile.am
++++ b/demos/programs/todo/Makefile.am
+@@ -9,4 +9,4 @@
+ data_DATA = $(EXTRA_DIST) $(todo_SOURCES)
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(srcdir)/../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+-LDADD = -L../../lib/Xmd -lXmd -L../../lib/Exm -lExm ../../../lib/Xm/libXm.la
++LDADD = -L../../lib/Xmd -lXmd -L../../lib/Exm -lExm ../../../lib/Xm/libXm.la -lXt -lXext -lX11
+--- a/demos/programs/tooltips/Makefile.am
++++ b/demos/programs/tooltips/Makefile.am
+@@ -7,6 +7,6 @@
+ bin_PROGRAMS = tooltips
+ tooltips_SOURCES = tooltips.c
+ data_DATA = $(tooltips_SOURCES) $(EXTRA_DIST)
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/demos/programs/workspace/Makefile.am
++++ b/demos/programs/workspace/Makefile.am
+@@ -11,4 +11,4 @@
+ wsm.h wsmSend.h wsmStruct.h wsm_ui.h xrmLib.h
+ data_DATA = $(wsm_SOURCES) $(EXTRA_DIST)
+ INCLUDES = -I$(srcdir)/../../../lib -I$(srcdir)/../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+-LDADD = ../../../lib/Xm/libXm.la -L../../lib/Wsm -lWsm
++LDADD = ../../../lib/Xm/libXm.la -L../../lib/Wsm -lWsm -lXt -lX11
+--- a/demos/unsupported/aicon/Makefile.am
++++ b/demos/unsupported/aicon/Makefile.am
+@@ -2,7 +2,7 @@
+
+ noinst_PROGRAMS = aicon
+
+-LDADD = -L../../lib/Xmd -lXmd ../../../lib/Xm/libXm.la
++LDADD = -L../../lib/Xmd -lXmd ../../../lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(srcdir)/../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+
+--- a/demos/unsupported/dainput/Makefile.am
++++ b/demos/unsupported/dainput/Makefile.am
+@@ -4,7 +4,7 @@
+
+ dainput_SOURCES = dainput.c dainput_dlg.c dainput_ui.c
+
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+
+ EXTRA_DIST = Imakefile
+
+--- a/demos/unsupported/dogs/Makefile.am
++++ b/demos/unsupported/dogs/Makefile.am
+@@ -16,7 +16,7 @@
+
+ dogs_DEPENDENCIES = dogs.uid
+
+-LDADD = $(top_builddir)/lib/Mrm/libMrm.la $(top_builddir)/lib/Xm/libXm.la
++LDADD = $(top_builddir)/lib/Mrm/libMrm.la $(top_builddir)/lib/Xm/libXm.la -lXt -lX11
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+
+--- a/demos/unsupported/hellomotif/Makefile.am
++++ b/demos/unsupported/hellomotif/Makefile.am
+@@ -4,7 +4,7 @@
+
+ SOURCES = hellomotif.c
+
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt
+
+ EXTRA_DIST = Imakefile
+
+--- a/demos/unsupported/motifshell/Makefile.am
++++ b/demos/unsupported/motifshell/Makefile.am
+@@ -4,7 +4,7 @@
+
+ SOURCES = motifshell.c
+
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+
+ EXTRA_DIST = Imakefile
+
+--- a/demos/unsupported/xmapdef/Makefile.am
++++ b/demos/unsupported/xmapdef/Makefile.am
+@@ -4,7 +4,7 @@
+
+ SOURCES = xmapdef.c
+
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+
+ EXTRA_DIST = Imakefile
+
+--- a/demos/unsupported/xmfonts/Makefile.am
++++ b/demos/unsupported/xmfonts/Makefile.am
+@@ -4,7 +4,7 @@
+
+ SOURCES = xmfonts.c
+
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt -lX11
+
+ EXTRA_DIST = Imakefile
+
+--- a/demos/unsupported/xmforc/Makefile.am
++++ b/demos/unsupported/xmforc/Makefile.am
+@@ -4,7 +4,7 @@
+
+ SOURCES = xmforc.c
+
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt
+
+ EXTRA_DIST = Imakefile
+
+--- a/demos/unsupported/xmform/Makefile.am
++++ b/demos/unsupported/xmform/Makefile.am
+@@ -6,6 +6,6 @@
+
+ EXTRA_DIST = Imakefile
+
+-LDADD = ../../../lib/Xm/libXm.la
++LDADD = ../../../lib/Xm/libXm.la -lXt
+
+ INCLUDES = -I$(srcdir)/../../../lib -I$(top_builddir)/lib ${X_CFLAGS}
+--- a/tools/wml/Makefile.am
++++ b/tools/wml/Makefile.am
+@@ -30,7 +30,7 @@
+ wml_LDADD = -L. -lwml
+ wml_DEPENDENCIES = libwml.a
+
+-wmldbcreate_LDADD = ../../lib/Xm/libXm.la
++wmldbcreate_LDADD = ../../lib/Xm/libXm.la -lXt
+
+ INCLUDES = -I../../lib -I$(srcdir)/../../lib -I$(srcdir)/../../include ${X_CFLAGS}
+
diff --git a/repo/x11/motif/13-fix_hardcoded_x11rgb_path.patch b/repo/x11/motif/13-fix_hardcoded_x11rgb_path.patch
new file mode 100644
index 0000000..6d53285
--- /dev/null
+++ b/repo/x11/motif/13-fix_hardcoded_x11rgb_path.patch
@@ -0,0 +1,54 @@
+Description: Fix hardcoded path to /usr/lib/X11/rgb.txt in lib/Xm/ColorS.c
+ LibXm is hardcoded to read rgb.txt from /usr/lib/X11 but this file, provided
+ by x11-common in Debian, is located in /etc/X11 and /usr/share/X11 via symlink.
+ .
+ This patch fixes this by allowing the directory in which rgb.txt resides to be
+ customized by the --with-x11rgbdir=DIR configure option.
+Author: Graham Inggs <graham@nerve.org.za>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1585
+Last-Update: 2013-03-12
+--- a/configure.ac
++++ b/configure.ac
+@@ -189,6 +189,10 @@
+ XMBINDDIR_FALLBACK="$xmbinddir"
+ AC_SUBST(XMBINDDIR_FALLBACK)
+
++AC_ARG_WITH(x11rgbdir, [ --with-x11rgbdir=DIR rgb.txt is located in DIR], x11rgbdir=$withval, x11rgbdir="/usr/lib/X11")
++X11RGBPATH="$x11rgbdir/rgb.txt"
++AC_SUBST(X11RGBPATH)
++
+ RM="rm -f"
+ AC_SUBST(RM)
+
+--- a/lib/Xm/ColorS.c
++++ b/lib/Xm/ColorS.c
+@@ -123,6 +123,10 @@
+ * STATIC DECLARATIONS
+ ************************************************************/
+
++#ifndef X11RGBPATH
++#define X11RGBPATH "/usr/lib/X11/rgb.txt"
++#endif
++
+ static XtResource resources[] =
+ {
+ {
+@@ -146,7 +150,7 @@
+ {
+ XmNrgbFile, XmCString, XmRString,
+ sizeof(String), XtOffsetOf(XmColorSelectorRec, cs.rgb_file),
+- XmRString, (XtPointer) "/usr/lib/X11/rgb.txt"
++ XmRString, (XtPointer) X11RGBPATH
+ },
+ #endif
+ {
+--- a/lib/Xm/Makefile.am
++++ b/lib/Xm/Makefile.am
+@@ -8,6 +8,7 @@
+ INCLUDES = -I.. -I$(srcdir)/.. -DXMBINDDIR_FALLBACK=\"@XMBINDDIR_FALLBACK@\" \
+ -DINCDIR=\"@INCDIR@\" \
+ -DLIBDIR=\"@LIBDIR@\" \
++ -DX11RGBPATH=\"@X11RGBPATH@\" \
+ ${X_CFLAGS}
+ xmdir = $(includedir)/Xm
+
diff --git a/repo/x11/motif/15-link_uil_against_libuil.patch b/repo/x11/motif/15-link_uil_against_libuil.patch
new file mode 100644
index 0000000..11792a7
--- /dev/null
+++ b/repo/x11/motif/15-link_uil_against_libuil.patch
@@ -0,0 +1,29 @@
+Description: Link the uil executable against libUil
+ Linking the uil executable againt libUil instead of compiling with the libUil
+ code results in a reduction in size of the uil executable from about 348KB
+ to about 16KB.
+ .
+ This patch originates from Red Hat.
+Author: Graham Inggs <graham@nerve.org.za>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1586
+Last-Update: 2013-03-12
+--- a/clients/uil/Makefile.am
++++ b/clients/uil/Makefile.am
+@@ -13,7 +13,7 @@
+
+ libUil_la_LIBADD = UilParser.lo ../../lib/Mrm/libMrm.la ../../lib/Xm/libXm.la -lXt
+
+-uil_LDADD = ../../lib/Mrm/libMrm.la ../../lib/Xm/libXm.la -lXt
++uil_LDADD = libUil.la ../../lib/Mrm/libMrm.la ../../lib/Xm/libXm.la -lXt
+
+ INCLUDES = -DINCDIR=\"@INCDIR@\" \
+ -DLIBDIR=\"@LIBDIR@\" \
+@@ -42,7 +42,7 @@
+ UilLstMac.c UilSemVal.c UilSemCSet.c UilDB.c
+
+ SRCS = $(COMMON_SRC)
+-SRCS2 = $(COMMON_SRC) UilMain.c
++SRCS2 = UilMain.c
+
+ HEADERS_1 = Uil.h UilSymGl.h UilSymDef.h \
+ UilDef.h XmAppl.uil
diff --git a/repo/x11/motif/16-fix-undefined-use-of-sprintf.patch b/repo/x11/motif/16-fix-undefined-use-of-sprintf.patch
new file mode 100644
index 0000000..95a753e
--- /dev/null
+++ b/repo/x11/motif/16-fix-undefined-use-of-sprintf.patch
@@ -0,0 +1,17 @@
+Description: Fix undefined use of sprintf
+ This patch fixes the undefined use of sprintf when the
+ source and destination buffers overlap.
+Author: Graham Inggs <graham@nerve.org.za>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1628
+Last-Update: 2013-09-24
+--- a/lib/Xm/XmRenderT.c
++++ b/lib/Xm/XmRenderT.c
+@@ -2703,7 +2703,7 @@
+ number = tlist -> count;
+ tab = (_XmTab) tlist -> start;
+ while(number > 0) {
+- sprintf(temp, "%s %f %d %d %d, ", temp, tab -> value,
++ sprintf(temp + strlen(temp), " %f %d %d %d, ", tab -> value,
+ tab -> units, tab -> alignment, tab -> offsetModel);
+ tab = (_XmTab) tab -> next;
+ number--;
diff --git a/repo/x11/motif/17-switch-to-system-iswspace.patch b/repo/x11/motif/17-switch-to-system-iswspace.patch
new file mode 100644
index 0000000..a77b879
--- /dev/null
+++ b/repo/x11/motif/17-switch-to-system-iswspace.patch
@@ -0,0 +1,384 @@
+Description: Switch to system iswspace() function
+ This patch replaces calls to _XmDataFieldIsWSpace() in lib/Xm/DataF.c
+ and _XmTextFieldIsWSpace() in lib/Xm/TextF.c with calls to the system
+ iswspace() function.
+ .
+ It fixes an array bounds error in lib/Xm/DataF.c where
+ _XmDataFieldIsWSpace() is called with num_entries = 3.
+Author: Graham Inggs <graham@nerve.org.za>
+Forwarded: http://bugs.motifzone.net/show_bug.cgi?id=1629
+Last-Update: 2013-11-18
+--- a/lib/Xm/DataF.c
++++ b/lib/Xm/DataF.c
+@@ -208,7 +208,6 @@
+ static Boolean df_VerifyLeave() ;
+ static Boolean _XmDataFieldIsWordBoundary() ;
+ static int _XmGetImage(Screen *, char *, XImage **);
+-static Boolean _XmDataFieldIsWSpace() ;
+ static void df_FindWord() ;
+ static void df_FindPrevWord() ;
+ static void df_FindNextWord() ;
+@@ -549,10 +548,6 @@
+ XmDataFieldWidget tf,
+ XmTextPosition pos1,
+ XmTextPosition pos2) ;
+-static Boolean _XmDataFieldIsWSpace(
+- wchar_t wide_char,
+- wchar_t *white_space,
+- int num_entries) ;
+ static void df_FindWord(
+ XmDataFieldWidget tf,
+ XmTextPosition begin,
+@@ -4549,40 +4544,6 @@
+ return False;
+ }
+
+-/* This routine accepts an array of wchar_t's containing wchar encodings
+- * of whitespace characters (and the number of array elements), comparing
+- * the wide character passed to each element of the array. If a match
+- * is found, we got a white space. This routine exists only because
+- * iswspace(3c) is not yet standard. If a system has isw* available,
+- * calls to this routine should be changed to iswspace(3c) (and callers
+- * should delete initialization of the array), and this routine should
+- * be deleted. Its a stop gap measure to avoid allocating an instance
+- * variable for the white_space array and/or declaring a widget wide
+- * global for the data and using a macro. Its ugly, but it works and
+- * in the long run will be replaced by standard functionality. */
+-
+-/* ARGSUSED */
+-static Boolean
+-#ifdef _NO_PROTO
+-_XmDataFieldIsWSpace( wide_char, white_space, num_entries )
+- wchar_t wide_char ;
+- wchar_t * white_space ;
+- int num_entries ;
+-#else
+-_XmDataFieldIsWSpace(
+- wchar_t wide_char,
+- wchar_t * white_space ,
+- int num_entries )
+-#endif /* _NO_PROTO */
+-{
+- int i;
+-
+- for (i=num_entries; i > 0; i--){
+- if (wide_char == white_space[i]) return True;
+- }
+- return False;
+-}
+-
+ static void
+ #ifdef _NO_PROTO
+ df_FindWord( tf, begin, left, right )
+@@ -4599,7 +4560,6 @@
+ #endif /* _NO_PROTO */
+ {
+ XmTextPosition start, end;
+- wchar_t white_space[3];
+
+ if (XmTextF_max_char_size(tf) == 1) {
+ for (start = begin; start > 0; start--) {
+@@ -4617,11 +4577,8 @@
+ }
+ *right = end - 1;
+ } else { /* check for iswspace and iswordboundary in each direction */
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+ for (start = begin; start > 0; start --) {
+- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start-1],white_space, 3)
++ if (iswspace(XmTextF_wc_value(tf)[start-1])
+ || _XmDataFieldIsWordBoundary(tf, (XmTextPosition) start - 1,
+ start)) {
+ break;
+@@ -4630,7 +4587,7 @@
+ *left = start;
+
+ for (end = begin; end <= XmTextF_string_length(tf); end++) {
+- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)){
++ if (iswspace(XmTextF_wc_value(tf)[end])){
+ end++;
+ break;
+ } else if (end < XmTextF_string_length(tf)) {
+@@ -4659,14 +4616,6 @@
+ {
+
+ XmTextPosition start = XmTextF_cursor_position(tf);
+- wchar_t white_space[3];
+-
+- if (XmTextF_max_char_size(tf) != 1) {
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+- }
+-
+
+ if (XmTextF_max_char_size(tf) == 1) {
+ if ((start > 0) &&
+@@ -4680,11 +4629,9 @@
+ }
+ df_FindWord(tf, start, left, right);
+ } else {
+- if ((start > 0) && (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start - 1],
+- white_space, 3))) {
++ if ((start > 0) && (iswspace(XmTextF_wc_value(tf)[start - 1]))) {
+ for (; start > 0; start--) {
+- if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[start -1],
+- white_space, 3)){
++ if (!iswspace(XmTextF_wc_value(tf)[start -1])){
+ start--;
+ break;
+ }
+@@ -4713,14 +4660,6 @@
+ {
+
+ XmTextPosition end = XmTextF_cursor_position(tf);
+- wchar_t white_space[3];
+-
+- if (XmTextF_max_char_size(tf) != 1) {
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+- }
+-
+
+ if(XmTextF_max_char_size(tf) == 1) {
+ if (isspace((int)(unsigned char)XmTextF_value(tf)[end])) {
+@@ -4742,9 +4681,9 @@
+ if (*right < XmTextF_string_length(tf))
+ *right = *right - 1;
+ } else {
+- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)) {
++ if (iswspace(XmTextF_wc_value(tf)[end])) {
+ for ( ; end < XmTextF_string_length(tf); end ++) {
+- if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[end], white_space, 3)) {
++ if (!iswspace(XmTextF_wc_value(tf)[end])) {
+ break;
+ }
+ }
+@@ -4758,10 +4697,9 @@
+ * If word boundary caused by whitespace, set right to the last
+ * whitespace following the end of the current word.
+ */
+- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[(int)*right], white_space, 3)) {
++ if (iswspace(XmTextF_wc_value(tf)[(int)*right])) {
+ while (*right < XmTextF_string_length(tf) &&
+- _XmDataFieldIsWSpace(XmTextF_wc_value(tf)[(int)*right],
+- white_space, 3)) {
++ iswspace(XmTextF_wc_value(tf)[(int)*right])) {
+ *right = *right + 1;
+ }
+ if (*right < XmTextF_string_length(tf))
+@@ -5872,13 +5810,6 @@
+ {
+ XmDataFieldWidget tf = (XmDataFieldWidget) w;
+ XmTextPosition cursorPos, position, dummy;
+- wchar_t white_space[3];
+-
+- if (XmTextF_max_char_size(tf) != 1) {
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+- }
+
+ cursorPos = XmTextF_cursor_position(tf);
+
+@@ -5896,16 +5827,13 @@
+ }
+ }
+ } else {
+- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[cursorPos],
+- white_space, 3))
++ if (iswspace(XmTextF_wc_value(tf)[cursorPos]))
+ df_FindWord(tf, cursorPos, &dummy, &position);
+ else
+ df_FindNextWord(tf, &dummy, &position);
+- if (_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[position],
+- white_space, 3)){
++ if (iswspace(XmTextF_wc_value(tf)[position])){
+ for (; position < XmTextF_string_length(tf); position++) {
+- if (!_XmDataFieldIsWSpace(XmTextF_wc_value(tf)[position],
+- white_space, 3))
++ if (!iswspace(XmTextF_wc_value(tf)[position]))
+ break;
+ }
+ }
+--- a/lib/Xm/TextF.c
++++ b/lib/Xm/TextF.c
+@@ -360,10 +360,6 @@
+ XmTextPosition pos1,
+ XmTextPosition pos2);
+
+-static Boolean _XmTextFieldIsWSpace(wchar_t wide_char,
+- wchar_t *white_space,
+- int num_entries);
+-
+ static void FindWord(XmTextFieldWidget tf,
+ XmTextPosition begin,
+ XmTextPosition *left,
+@@ -3514,32 +3510,6 @@
+ return False;
+ }
+
+-/* This routine accepts an array of wchar_t's containing wchar encodings
+- * of whitespace characters (and the number of array elements), comparing
+- * the wide character passed to each element of the array. If a match
+- * is found, we got a white space. This routine exists only because
+- * iswspace(3c) is not yet standard. If a system has isw* available,
+- * calls to this routine should be changed to iswspace(3c) (and callers
+- * should delete initialization of the array), and this routine should
+- * be deleted. Its a stop gap measure to avoid allocating an instance
+- * variable for the white_space array and/or declaring a widget wide
+- * global for the data and using a macro. Its ugly, but it works and
+- * in the long run will be replaced by standard functionality. */
+-
+-/* ARGSUSED */
+-static Boolean
+-_XmTextFieldIsWSpace(wchar_t wide_char,
+- wchar_t * white_space ,
+- int num_entries)
+-{
+- int i;
+-
+- for (i=0; i < num_entries; i++) {
+- if (wide_char == white_space[i]) return True;
+- }
+- return False;
+-}
+-
+ static void
+ FindWord(XmTextFieldWidget tf,
+ XmTextPosition begin,
+@@ -3547,7 +3517,6 @@
+ XmTextPosition *right)
+ {
+ XmTextPosition start, end;
+- wchar_t white_space[3];
+
+ if (tf->text.max_char_size == 1) {
+ for (start = begin; start > 0; start--) {
+@@ -3565,11 +3534,8 @@
+ }
+ *right = end - 1;
+ } else { /* check for iswspace and iswordboundary in each direction */
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+ for (start = begin; start > 0; start --) {
+- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[start-1],white_space, 3)
++ if (iswspace(TextF_WcValue(tf)[start-1])
+ || _XmTextFieldIsWordBoundary(tf, (XmTextPosition) start - 1,
+ start)) {
+ break;
+@@ -3578,7 +3544,7 @@
+ *left = start;
+
+ for (end = begin; end <= tf->text.string_length; end++) {
+- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[end], white_space, 3)) {
++ if (iswspace(TextF_WcValue(tf)[end])) {
+ end++;
+ break;
+ } else if (end < tf->text.string_length) {
+@@ -3599,14 +3565,6 @@
+ {
+
+ XmTextPosition start = TextF_CursorPosition(tf);
+- wchar_t white_space[3];
+-
+- if (tf->text.max_char_size != 1) {
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+- }
+-
+
+ if (tf->text.max_char_size == 1) {
+ if ((start > 0) &&
+@@ -3620,11 +3578,9 @@
+ }
+ FindWord(tf, start, left, right);
+ } else {
+- if ((start > 0) && (_XmTextFieldIsWSpace(TextF_WcValue(tf)[start - 1],
+- white_space, 3))) {
++ if ((start > 0) && (iswspace(TextF_WcValue(tf)[start - 1]))) {
+ for (; start > 0; start--) {
+- if (!_XmTextFieldIsWSpace(TextF_WcValue(tf)[start -1],
+- white_space, 3)) {
++ if (!iswspace(TextF_WcValue(tf)[start -1])) {
+ start--;
+ break;
+ }
+@@ -3645,14 +3601,6 @@
+ {
+
+ XmTextPosition end = TextF_CursorPosition(tf);
+- wchar_t white_space[3];
+-
+- if (tf->text.max_char_size != 1) {
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+- }
+-
+
+ if(tf->text.max_char_size == 1) {
+ if (isspace((unsigned char)TextF_Value(tf)[end])) {
+@@ -3674,9 +3622,9 @@
+ if (*right < tf->text.string_length)
+ *right = *right - 1;
+ } else {
+- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[end], white_space, 3)) {
++ if (iswspace(TextF_WcValue(tf)[end])) {
+ for (; end < tf->text.string_length; end ++) {
+- if (!_XmTextFieldIsWSpace(TextF_WcValue(tf)[end], white_space, 3)) {
++ if (!iswspace(TextF_WcValue(tf)[end])) {
+ break;
+ }
+ }
+@@ -3690,10 +3638,9 @@
+ * If word boundary caused by whitespace, set right to the last
+ * whitespace following the end of the current word.
+ */
+- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[(int)*right], white_space, 3)) {
++ if (iswspace(TextF_WcValue(tf)[(int)*right])) {
+ while (*right < tf->text.string_length &&
+- _XmTextFieldIsWSpace(TextF_WcValue(tf)[(int)*right],
+- white_space, 3)) {
++ iswspace(TextF_WcValue(tf)[(int)*right])) {
+ *right = *right + 1;
+ }
+ if (*right < tf->text.string_length)
+@@ -4546,13 +4493,6 @@
+ {
+ XmTextFieldWidget tf = (XmTextFieldWidget) w;
+ XmTextPosition cursorPos, position, dummy;
+- wchar_t white_space[3];
+-
+- if (tf->text.max_char_size != 1) {
+- (void)mbtowc(&white_space[0], " ", 1);
+- (void)mbtowc(&white_space[1], "\n", 1);
+- (void)mbtowc(&white_space[2], "\t", 1);
+- }
+
+ cursorPos = TextF_CursorPosition(tf);
+
+@@ -4570,16 +4510,13 @@
+ }
+ }
+ } else {
+- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[cursorPos],
+- white_space, 3))
++ if (iswspace(TextF_WcValue(tf)[cursorPos]))
+ FindWord(tf, cursorPos, &dummy, &position);
+ else
+ FindNextWord(tf, &dummy, &position);
+- if (_XmTextFieldIsWSpace(TextF_WcValue(tf)[position],
+- white_space, 3)) {
++ if (iswspace(TextF_WcValue(tf)[position])) {
+ for (; position < tf->text.string_length; position++) {
+- if (!_XmTextFieldIsWSpace(TextF_WcValue(tf)[position],
+- white_space, 3))
++ if (!iswspace(TextF_WcValue(tf)[position]))
+ break;
+ }
+ }
diff --git a/repo/x11/motif/18-option-main.patch b/repo/x11/motif/18-option-main.patch
new file mode 100644
index 0000000..3ad059c
--- /dev/null
+++ b/repo/x11/motif/18-option-main.patch
@@ -0,0 +1,9 @@
+diff -urN motif-2.3.8.orig/tools/wml/wmluiltok.l motif-2.3.8/tools/wml/wmluiltok.l
+--- motif-2.3.8.orig/tools/wml/wmluiltok.l 2021-05-25 13:51:53.464073407 -0600
++++ motif-2.3.8/tools/wml/wmluiltok.l 2021-05-25 13:52:25.354192799 -0600
+@@ -1,3 +1,5 @@
++%option main
++
+ %{
+ /*
+ * Motif
diff --git a/repo/x11/motif.xibuild b/repo/x11/motif/motif.xibuild
index a283ca0..a283ca0 100644
--- a/repo/x11/motif.xibuild
+++ b/repo/x11/motif/motif.xibuild
diff --git a/repo/x11/pango/disable-broken-test.patch b/repo/x11/pango/disable-broken-test.patch
new file mode 100644
index 0000000..db3d6c3
--- /dev/null
+++ b/repo/x11/pango/disable-broken-test.patch
@@ -0,0 +1,15 @@
+--- a/tests/meson.build
++++ b/tests/meson.build
+@@ -58,12 +58,6 @@
+ [ 'testmisc', [ 'testmisc.c' ], [ libpangocairo_dep, libpangoft2_dep, glib_dep, harfbuzz_dep ] ],
+ [ 'testserialize', [ 'testserialize.c' ], [ libpangocairo_dep, libpangoft2_dep ] ],
+ ]
+-
+- if host_system != 'darwin'
+- tests += [
+- [ 'test-layout', [ 'test-layout.c', 'test-common.c' ], [ libpangocairo_dep, libpangoft2_dep ] ],
+- ]
+- endif
+ endif
+
+ if host_system != 'darwin'
diff --git a/repo/x11/pango.xibuild b/repo/x11/pango/pango.xibuild
index 8b507dc..8b507dc 100644
--- a/repo/x11/pango.xibuild
+++ b/repo/x11/pango/pango.xibuild
diff --git a/repo/x11/picom.xibuild b/repo/x11/picom/picom.xibuild
index 2c3eb28..2c3eb28 100644
--- a/repo/x11/picom.xibuild
+++ b/repo/x11/picom/picom.xibuild
diff --git a/repo/x11/pixman.xibuild b/repo/x11/pixman/pixman.xibuild
index c502b84..c502b84 100644
--- a/repo/x11/pixman.xibuild
+++ b/repo/x11/pixman/pixman.xibuild
diff --git a/repo/x11/rofi/rofi-sensible-terminal-use-sh.patch b/repo/x11/rofi/rofi-sensible-terminal-use-sh.patch
new file mode 100644
index 0000000..926aa7a
--- /dev/null
+++ b/repo/x11/rofi/rofi-sensible-terminal-use-sh.patch
@@ -0,0 +1,23 @@
+From 34d5779d41a902be21cef3fc3e70d8f6881ca05c Mon Sep 17 00:00:00 2001
+From: Jakub Jirutka <jakub@jirutka.cz>
+Date: Mon, 27 Sep 2021 01:00:43 +0200
+Subject: [PATCH] [rofi-sensible-terminal] Use /bin/sh instead of /usr/bin/env bash
+Patch-Source: https://github.com/davatorium/rofi/pull/1478
+
+This script is fully POSIX-sh compatible, i.e. it's portable and can be
+run in any shell, not just bash. It's incorrect to assume that bash is
+available on every *nix system (it's not), but /bin/sh is.
+---
+ script/rofi-sensible-terminal | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/script/rofi-sensible-terminal b/script/rofi-sensible-terminal
+index 112e1d14e..e2b6cc4b9 100755
+--- a/script/rofi-sensible-terminal
++++ b/script/rofi-sensible-terminal
+@@ -1,4 +1,4 @@
+-#!/usr/bin/env bash
++#!/bin/sh
+ #
+ # This code is released in public domain by Han Boetes <han@mijncomputer.nl>
+ # Updated by Dave Davenport <qball@gmpclient.org>
diff --git a/repo/x11/rofi.xibuild b/repo/x11/rofi/rofi.xibuild
index e377909..e377909 100644
--- a/repo/x11/rofi.xibuild
+++ b/repo/x11/rofi/rofi.xibuild
diff --git a/repo/x11/rofi/scrollbar-test.patch b/repo/x11/rofi/scrollbar-test.patch
new file mode 100644
index 0000000..40f9dec
--- /dev/null
+++ b/repo/x11/rofi/scrollbar-test.patch
@@ -0,0 +1,31 @@
+Subject: the test fails on x86
+
+diff --git a/meson.build b/meson.build
+index 6e1105a..f707cd9 100644
+--- a/meson.build
++++ b/meson.build
+@@ -345,24 +345,6 @@ test('box test', executable('box.test', [
+ dependencies: deps,
+ ))
+
+-test('scrollbar test', executable('scrollbar.test', [
+- 'test/scrollbar-test.c',
+- theme_parser,
+- theme_lexer,
+- default_theme,
+- ],
+- objects: rofi.extract_objects([
+- 'source/widgets/widget.c',
+- 'source/widgets/scrollbar.c',
+- 'source/theme.c',
+- 'source/css-colors.c',
+- 'source/rofi-types.c',
+- 'source/css-colors.c',
+- 'config/config.c',
+- ]),
+- dependencies: deps,
+-))
+-
+ test('textbox test', executable('textbox.test', [
+ 'test/textbox-test.c',
+ theme_parser,
diff --git a/repo/x11/sdl2/directfb-cflags.patch b/repo/x11/sdl2/directfb-cflags.patch
new file mode 100644
index 0000000..037667d
--- /dev/null
+++ b/repo/x11/sdl2/directfb-cflags.patch
@@ -0,0 +1,10 @@
+--- a/cmake/sdlchecks.cmake
++++ b/cmake/sdlchecks.cmake
+@@ -745,6 +745,7 @@
+ set(SDL_VIDEO_DRIVER_DIRECTFB 1)
+ set(SDL_VIDEO_RENDER_DIRECTFB 1)
+ list(APPEND EXTRA_CFLAGS ${PKG_DIRECTFB_CFLAGS})
++ list(JOIN PKG_DIRECTFB_CFLAGS " " SDL_CFLAGS)
+ if(SDL_DIRECTFB_SHARED AND NOT HAVE_SDL_LOADSO)
+ message_warn("You must have SDL_LoadObject() support for dynamic DirectFB loading")
+ endif()
diff --git a/repo/x11/sdl2.xibuild b/repo/x11/sdl2/sdl2.xibuild
index 0f0778f..0f0778f 100644
--- a/repo/x11/sdl2.xibuild
+++ b/repo/x11/sdl2/sdl2.xibuild
diff --git a/repo/x11/sessreg.xibuild b/repo/x11/sessreg/sessreg.xibuild
index 08d3e4e..08d3e4e 100644
--- a/repo/x11/sessreg.xibuild
+++ b/repo/x11/sessreg/sessreg.xibuild
diff --git a/repo/x11/setxkbmap.xibuild b/repo/x11/setxkbmap/setxkbmap.xibuild
index 42c0200..42c0200 100644
--- a/repo/x11/setxkbmap.xibuild
+++ b/repo/x11/setxkbmap/setxkbmap.xibuild
diff --git a/repo/x11/slock.xibuild b/repo/x11/slock/slock.xibuild
index 596cdcf..596cdcf 100644
--- a/repo/x11/slock.xibuild
+++ b/repo/x11/slock/slock.xibuild
diff --git a/repo/x11/slop.xibuild b/repo/x11/slop/slop.xibuild
index 263118b..263118b 100644
--- a/repo/x11/slop.xibuild
+++ b/repo/x11/slop/slop.xibuild
diff --git a/repo/x11/smproxy.xibuild b/repo/x11/smproxy/smproxy.xibuild
index 8d1867e..8d1867e 100644
--- a/repo/x11/smproxy.xibuild
+++ b/repo/x11/smproxy/smproxy.xibuild
diff --git a/repo/x11/spice-protocol.xibuild b/repo/x11/spice-protocol/spice-protocol.xibuild
index 8656080..8656080 100644
--- a/repo/x11/spice-protocol.xibuild
+++ b/repo/x11/spice-protocol/spice-protocol.xibuild
diff --git a/repo/x11/sxhkd.xibuild b/repo/x11/sxhkd/sxhkd.xibuild
index a18247a..a18247a 100644
--- a/repo/x11/sxhkd.xibuild
+++ b/repo/x11/sxhkd/sxhkd.xibuild
diff --git a/repo/x11/wayland-protocols.xibuild b/repo/x11/wayland-protocols/wayland-protocols.xibuild
index 764fa29..764fa29 100644
--- a/repo/x11/wayland-protocols.xibuild
+++ b/repo/x11/wayland-protocols/wayland-protocols.xibuild
diff --git a/repo/x11/wayland.xibuild b/repo/x11/wayland/wayland.xibuild
index c26f903..c26f903 100644
--- a/repo/x11/wayland.xibuild
+++ b/repo/x11/wayland/wayland.xibuild
diff --git a/repo/x11/x11perf.xibuild b/repo/x11/x11perf/x11perf.xibuild
index ebb5ede..ebb5ede 100644
--- a/repo/x11/x11perf.xibuild
+++ b/repo/x11/x11perf/x11perf.xibuild
diff --git a/repo/x11/xauth.xibuild b/repo/x11/xauth/xauth.xibuild
index a9c14d7..a9c14d7 100644
--- a/repo/x11/xauth.xibuild
+++ b/repo/x11/xauth/xauth.xibuild
diff --git a/repo/x11/xautolock/processwait.patch b/repo/x11/xautolock/processwait.patch
new file mode 100644
index 0000000..a288d9a
--- /dev/null
+++ b/repo/x11/xautolock/processwait.patch
@@ -0,0 +1,33 @@
+--- a/src/engine.c.orig 2014-08-28 12:50:56.086307943 +0000
++++ b/src/engine.c 2014-08-28 12:50:59.496333650 +0000
+@@ -209,24 +209,24 @@ evaluateTriggers (Display* d)
+ {
+ #else /* VMS */
+ if (lockerPid)
+ {
+-#if !defined (UTEKV) && !defined (SYSV) && !defined (SVR4)
++#if (!defined (UTEKV) && !defined (SYSV) && !defined (SVR4)) && defined (__GLIBC__)
+ union wait status; /* childs process status */
+-#else /* !UTEKV && !SYSV && !SVR4 */
++#else /* (!UTEKV && !SYSV && !SVR4) && __GLIBC__ */
+ int status = 0; /* childs process status */
+-#endif /* !UTEKV && !SYSV && !SVR4 */
++#endif /* (!UTEKV && !SYSV && !SVR4) && __GLIBC__ */
+
+ if (unlockNow && !disabled)
+ {
+ (void) kill (lockerPid, SIGTERM);
+ }
+
+-#if !defined (UTEKV) && !defined (SYSV) && !defined (SVR4)
++#if (!defined (UTEKV) && !defined (SYSV) && !defined (SVR4)) && defined (__GLIBC__)
+ if (wait3 (&status, WNOHANG, 0))
+-#else /* !UTEKV && !SYSV && !SVR4 */
++#else /* (!UTEKV && !SYSV && !SVR4) && __GLIBC__ */
+ if (waitpid (-1, &status, WNOHANG))
+-#endif /* !UTEKV && !SYSV && !SVR4 */
++#endif /* (!UTEKV && !SYSV && !SVR4) && __GLIBC__ */
+ {
+ /*
+ * If the locker exited normally, we disable any pending kill
+ * trigger. Otherwise, we assume that it either has crashed or
diff --git a/repo/x11/xautolock.xibuild b/repo/x11/xautolock/xautolock.xibuild
index 75476d6..75476d6 100644
--- a/repo/x11/xautolock.xibuild
+++ b/repo/x11/xautolock/xautolock.xibuild
diff --git a/repo/x11/xbacklight.xibuild b/repo/x11/xbacklight/xbacklight.xibuild
index 7f79bc0..7f79bc0 100644
--- a/repo/x11/xbacklight.xibuild
+++ b/repo/x11/xbacklight/xbacklight.xibuild
diff --git a/repo/x11/xbitmaps.xibuild b/repo/x11/xbitmaps/xbitmaps.xibuild
index 591adc8..591adc8 100644
--- a/repo/x11/xbitmaps.xibuild
+++ b/repo/x11/xbitmaps/xbitmaps.xibuild
diff --git a/repo/x11/xcb-proto.xibuild b/repo/x11/xcb-proto/xcb-proto.xibuild
index 01ece2a..01ece2a 100644
--- a/repo/x11/xcb-proto.xibuild
+++ b/repo/x11/xcb-proto/xcb-proto.xibuild
diff --git a/repo/x11/xcb-util-cursor.xibuild b/repo/x11/xcb-util-cursor/xcb-util-cursor.xibuild
index cae954b..cae954b 100644
--- a/repo/x11/xcb-util-cursor.xibuild
+++ b/repo/x11/xcb-util-cursor/xcb-util-cursor.xibuild
diff --git a/repo/x11/xcb-util-image.xibuild b/repo/x11/xcb-util-image/xcb-util-image.xibuild
index e11280a..e11280a 100644
--- a/repo/x11/xcb-util-image.xibuild
+++ b/repo/x11/xcb-util-image/xcb-util-image.xibuild
diff --git a/repo/x11/xcb-util-keysyms.xibuild b/repo/x11/xcb-util-keysyms/xcb-util-keysyms.xibuild
index 31bc072..31bc072 100644
--- a/repo/x11/xcb-util-keysyms.xibuild
+++ b/repo/x11/xcb-util-keysyms/xcb-util-keysyms.xibuild
diff --git a/repo/x11/xcb-util-renderutil.xibuild b/repo/x11/xcb-util-renderutil/xcb-util-renderutil.xibuild
index 293f41d..293f41d 100644
--- a/repo/x11/xcb-util-renderutil.xibuild
+++ b/repo/x11/xcb-util-renderutil/xcb-util-renderutil.xibuild
diff --git a/repo/x11/xcb-util-wm.xibuild b/repo/x11/xcb-util-wm/xcb-util-wm.xibuild
index 7180dec..7180dec 100644
--- a/repo/x11/xcb-util-wm.xibuild
+++ b/repo/x11/xcb-util-wm/xcb-util-wm.xibuild
diff --git a/repo/x11/xcb-util.xibuild b/repo/x11/xcb-util/xcb-util.xibuild
index 04321d1..04321d1 100644
--- a/repo/x11/xcb-util.xibuild
+++ b/repo/x11/xcb-util/xcb-util.xibuild
diff --git a/repo/x11/xclip.xibuild b/repo/x11/xclip/xclip.xibuild
index 28de291..28de291 100644
--- a/repo/x11/xclip.xibuild
+++ b/repo/x11/xclip/xclip.xibuild
diff --git a/repo/x11/xclock.xibuild b/repo/x11/xclock/xclock.xibuild
index 14e1307..14e1307 100644
--- a/repo/x11/xclock.xibuild
+++ b/repo/x11/xclock/xclock.xibuild
diff --git a/repo/x11/xcmsdb.xibuild b/repo/x11/xcmsdb/xcmsdb.xibuild
index ddaadef..ddaadef 100644
--- a/repo/x11/xcmsdb.xibuild
+++ b/repo/x11/xcmsdb/xcmsdb.xibuild
diff --git a/repo/x11/xcursor-themes.xibuild b/repo/x11/xcursor-themes/xcursor-themes.xibuild
index f3ecb0b..f3ecb0b 100644
--- a/repo/x11/xcursor-themes.xibuild
+++ b/repo/x11/xcursor-themes/xcursor-themes.xibuild
diff --git a/repo/x11/xcursorgen.xibuild b/repo/x11/xcursorgen/xcursorgen.xibuild
index 13c14a0..13c14a0 100644
--- a/repo/x11/xcursorgen.xibuild
+++ b/repo/x11/xcursorgen/xcursorgen.xibuild
diff --git a/repo/x11/xdg-utils/xdg-screensaver-mv-T.patch b/repo/x11/xdg-utils/xdg-screensaver-mv-T.patch
new file mode 100644
index 0000000..9e209f7
--- /dev/null
+++ b/repo/x11/xdg-utils/xdg-screensaver-mv-T.patch
@@ -0,0 +1,25 @@
+--- ./scripts/xdg-screensaver.in.orig
++++ ./scripts/xdg-screensaver.in
+@@ -26,18 +26,10 @@
+
+ #@xdg-utils-common@
+
+-# Check if we can use "mv -T"
+-if mv -T ... ... 2>&1 | grep '\.\.\.' > /dev/null ; then
+- # We can securely move files in /tmp with mv -T
+- DEBUG 1 "mv -T available"
+- MV="mv -T"
+- screensaver_file="/tmp/xdg-screensaver-$USER-"`echo $DISPLAY | sed 's/:/-/g'`
+-else
+- # No secure moves available, use home dir
+- DEBUG 1 "mv -T not available"
+- MV="mv"
+- screensaver_file="$HOME/.xdg-screensaver-"`echo $(hostname)-$DISPLAY | sed 's/:/-/g'`
+-fi
++# No secure moves available, use home dir
++DEBUG 1 "mv -T not available"
++MV="mv"
++screensaver_file="$HOME/.xdg-screensaver-"`echo $(hostname)-$DISPLAY | sed 's/:/-/g'`
+ lockfile_command=`which lockfile 2> /dev/null`
+
+ lockfile()
diff --git a/repo/x11/xdg-utils.xibuild b/repo/x11/xdg-utils/xdg-utils.xibuild
index ad51ab4..ad51ab4 100644
--- a/repo/x11/xdg-utils.xibuild
+++ b/repo/x11/xdg-utils/xdg-utils.xibuild
diff --git a/repo/x11/xdpyinfo.xibuild b/repo/x11/xdpyinfo/xdpyinfo.xibuild
index 3784477..3784477 100644
--- a/repo/x11/xdpyinfo.xibuild
+++ b/repo/x11/xdpyinfo/xdpyinfo.xibuild
diff --git a/repo/x11/xdriinfo.xibuild b/repo/x11/xdriinfo/xdriinfo.xibuild
index f32f3c0..f32f3c0 100644
--- a/repo/x11/xdriinfo.xibuild
+++ b/repo/x11/xdriinfo/xdriinfo.xibuild
diff --git a/repo/x11/xev.xibuild b/repo/x11/xev/xev.xibuild
index 5f8e8d9..5f8e8d9 100644
--- a/repo/x11/xev.xibuild
+++ b/repo/x11/xev/xev.xibuild
diff --git a/repo/x11/xeyes.xibuild b/repo/x11/xeyes/xeyes.xibuild
index 39a175e..39a175e 100644
--- a/repo/x11/xeyes.xibuild
+++ b/repo/x11/xeyes/xeyes.xibuild
diff --git a/repo/x11/xf86-input-evdev.xibuild b/repo/x11/xf86-input-evdev/xf86-input-evdev.xibuild
index de4aeed..de4aeed 100644
--- a/repo/x11/xf86-input-evdev.xibuild
+++ b/repo/x11/xf86-input-evdev/xf86-input-evdev.xibuild
diff --git a/repo/x11/xf86-input-libinput.xibuild b/repo/x11/xf86-input-libinput/xf86-input-libinput.xibuild
index 9385bc0..9385bc0 100644
--- a/repo/x11/xf86-input-libinput.xibuild
+++ b/repo/x11/xf86-input-libinput/xf86-input-libinput.xibuild
diff --git a/repo/x11/xf86-input-synaptics.xibuild b/repo/x11/xf86-input-synaptics/xf86-input-synaptics.xibuild
index 27ed0ec..27ed0ec 100644
--- a/repo/x11/xf86-input-synaptics.xibuild
+++ b/repo/x11/xf86-input-synaptics/xf86-input-synaptics.xibuild
diff --git a/repo/x11/xf86-input-wacom.xibuild b/repo/x11/xf86-input-wacom/xf86-input-wacom.xibuild
index 77e3f55..77e3f55 100644
--- a/repo/x11/xf86-input-wacom.xibuild
+++ b/repo/x11/xf86-input-wacom/xf86-input-wacom.xibuild
diff --git a/repo/x11/xf86-video-amdgpu.xibuild b/repo/x11/xf86-video-amdgpu/xf86-video-amdgpu.xibuild
index 89b8e80..89b8e80 100644
--- a/repo/x11/xf86-video-amdgpu.xibuild
+++ b/repo/x11/xf86-video-amdgpu/xf86-video-amdgpu.xibuild
diff --git a/repo/x11/xf86-video-ati.xibuild b/repo/x11/xf86-video-ati/xf86-video-ati.xibuild
index 421bf3e..421bf3e 100644
--- a/repo/x11/xf86-video-ati.xibuild
+++ b/repo/x11/xf86-video-ati/xf86-video-ati.xibuild
diff --git a/repo/x11/xf86-video-fbdev.xibuild b/repo/x11/xf86-video-fbdev/xf86-video-fbdev.xibuild
index 050aa76..050aa76 100644
--- a/repo/x11/xf86-video-fbdev.xibuild
+++ b/repo/x11/xf86-video-fbdev/xf86-video-fbdev.xibuild
diff --git a/repo/x11/xf86-video-intel.xibuild b/repo/x11/xf86-video-intel/xf86-video-intel.xibuild
index ac5fce2..ac5fce2 100644
--- a/repo/x11/xf86-video-intel.xibuild
+++ b/repo/x11/xf86-video-intel/xf86-video-intel.xibuild
diff --git a/repo/x11/xf86-video-nouveau.xibuild b/repo/x11/xf86-video-nouveau/xf86-video-nouveau.xibuild
index e2f593c..e2f593c 100644
--- a/repo/x11/xf86-video-nouveau.xibuild
+++ b/repo/x11/xf86-video-nouveau/xf86-video-nouveau.xibuild
diff --git a/repo/x11/xf86-video-nouveau/xorg-server-21.1.patch b/repo/x11/xf86-video-nouveau/xorg-server-21.1.patch
new file mode 100644
index 0000000..03d0b80
--- /dev/null
+++ b/repo/x11/xf86-video-nouveau/xorg-server-21.1.patch
@@ -0,0 +1,50 @@
+diff --git a/src/compat-api.h b/src/compat-api.h
+index fde2f4b1cfde75875c07bfe13524dc6ba2661382..8a1fcf9be1c5d1ceb48a50f2ed533d93ec7ff4c7 100644
+--- a/src/compat-api.h
++++ b/src/compat-api.h
+@@ -102,4 +102,8 @@
+
+ #endif
+
++#if ABI_VIDEODRV_VERSION < SET_ABI_VERSION(25, 2)
++#define secondary_dst slave_dst
++#endif
++
+ #endif
+diff --git a/src/nouveau_exa.c b/src/nouveau_exa.c
+index 55df6f8f11c9e14b1891e5c841faef10c17f0a35..db3b112a2db70f8e902e54aa3af99e51e7d0c6f7 100644
+--- a/src/nouveau_exa.c
++++ b/src/nouveau_exa.c
+@@ -157,7 +157,7 @@ nouveau_exa_destroy_pixmap(ScreenPtr pScreen, void *priv)
+
+ #ifdef NOUVEAU_PIXMAP_SHARING
+ static Bool
+-nouveau_exa_share_pixmap_backing(PixmapPtr ppix, ScreenPtr slave, void **handle_p)
++nouveau_exa_share_pixmap_backing(PixmapPtr ppix, ScreenPtr secondary, void **handle_p)
+ {
+ struct nouveau_bo *bo = nouveau_pixmap_bo(ppix);
+ struct nouveau_pixmap *nvpix = nouveau_pixmap(ppix);
+diff --git a/src/nv_driver.c b/src/nv_driver.c
+index e72a6b65a81119f12f3608295a4547762a866ad7..f9ab4af19361d99d74f580d1ff3f28d49843e8b0 100644
+--- a/src/nv_driver.c
++++ b/src/nv_driver.c
+@@ -559,16 +559,16 @@ redisplay_dirty(ScreenPtr screen, PixmapDirtyUpdatePtr dirty)
+ {
+ RegionRec pixregion;
+
+- PixmapRegionInit(&pixregion, dirty->slave_dst);
++ PixmapRegionInit(&pixregion, dirty->secondary_dst);
+
+- DamageRegionAppend(&dirty->slave_dst->drawable, &pixregion);
++ DamageRegionAppend(&dirty->secondary_dst->drawable, &pixregion);
+ #ifdef HAS_DIRTYTRACKING_ROTATION
+ PixmapSyncDirtyHelper(dirty);
+ #else
+ PixmapSyncDirtyHelper(dirty, &pixregion);
+ #endif
+
+- DamageRegionProcessPending(&dirty->slave_dst->drawable);
++ DamageRegionProcessPending(&dirty->secondary_dst->drawable);
+ RegionUninit(&pixregion);
+ }
+
diff --git a/repo/x11/xf86-video-qxl/buildfix.patch b/repo/x11/xf86-video-qxl/buildfix.patch
new file mode 100644
index 0000000..d1a8d7e
--- /dev/null
+++ b/repo/x11/xf86-video-qxl/buildfix.patch
@@ -0,0 +1,101 @@
+From 4b083ede3c4a827a84295ff223e34ee3c2e581b2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Zolt=C3=A1n=20B=C3=B6sz=C3=B6rm=C3=A9nyi?=
+ <zboszor@gmail.com>
+Date: Sat, 28 Aug 2021 15:38:40 +0200
+Subject: [PATCH] Fix a build error with Xorg master
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Use xf86ReturnOptValBool() in get_bool_option() instead of
+options[option_index].value.bool to fix a compiler error with
+current Xorg xserver master branch.
+
+Also use xf86GetOptValInteger() in get_int_option() and
+xf86GetOptValString() in get_str_option() for consistency.
+
+The change causes a slight performance drop during option parsing
+because the passed-in index_value is no longer used as an index
+into the options array.
+
+Instead, it's used as a token now for the standard option getter
+functions which works since the index_value to the get_*_option()
+functions are identical to the value of options[n].token in the
+passed-in OptionInfoRec array.
+
+Also rename "int option_index" to "int token" for clarity in all
+three functions.
+
+Signed-off-by: Zoltán Böszörményi <zboszor@gmail.com>
+---
+ src/qxl_option_helpers.c | 13 +++++++------
+ src/qxl_option_helpers.h | 6 +++---
+ 2 files changed, 10 insertions(+), 9 deletions(-)
+
+diff --git a/src/qxl_option_helpers.c b/src/qxl_option_helpers.c
+index 2aba677..7707b7c 100644
+--- a/src/qxl_option_helpers.c
++++ b/src/qxl_option_helpers.c
+@@ -10,31 +10,32 @@
+
+ #include "qxl_option_helpers.h"
+
+-int get_int_option(OptionInfoPtr options, int option_index,
++int get_int_option(OptionInfoPtr options, int token,
+ const char *env_name)
+ {
++ int value;
+ if (env_name && getenv(env_name)) {
+ return atoi(getenv(env_name));
+ }
+- return options[option_index].value.num;
++ return xf86GetOptValInteger(options, token, &value) ? value : 0;
+ }
+
+-const char *get_str_option(OptionInfoPtr options, int option_index,
++const char *get_str_option(OptionInfoPtr options, int token,
+ const char *env_name)
+ {
+ if (getenv(env_name)) {
+ return getenv(env_name);
+ }
+- return options[option_index].value.str;
++ return xf86GetOptValString(options, token);
+ }
+
+-int get_bool_option(OptionInfoPtr options, int option_index,
++int get_bool_option(OptionInfoPtr options, int token,
+ const char *env_name)
+ {
+ const char* value = getenv(env_name);
+
+ if (!value) {
+- return options[option_index].value.bool;
++ return xf86ReturnOptValBool(options, token, FALSE);
+ }
+ if (strcmp(value, "0") == 0 ||
+ strcasecmp(value, "off") == 0 ||
+diff --git a/src/qxl_option_helpers.h b/src/qxl_option_helpers.h
+index 7c54c72..66d0a17 100644
+--- a/src/qxl_option_helpers.h
++++ b/src/qxl_option_helpers.h
+@@ -4,13 +4,13 @@
+ #include <xf86Crtc.h>
+ #include <xf86Opt.h>
+
+-int get_int_option(OptionInfoPtr options, int option_index,
++int get_int_option(OptionInfoPtr options, int token,
+ const char *env_name);
+
+-const char *get_str_option(OptionInfoPtr options, int option_index,
++const char *get_str_option(OptionInfoPtr options, int token,
+ const char *env_name);
+
+-int get_bool_option(OptionInfoPtr options, int option_index,
++int get_bool_option(OptionInfoPtr options, int token,
+ const char *env_name);
+
+ #endif // OPTION_HELPERS_H
+--
+GitLab
+
diff --git a/repo/x11/xf86-video-qxl/convert-xspice-python3.patch b/repo/x11/xf86-video-qxl/convert-xspice-python3.patch
new file mode 100644
index 0000000..145d3e3
--- /dev/null
+++ b/repo/x11/xf86-video-qxl/convert-xspice-python3.patch
@@ -0,0 +1,154 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Christophe Fergeau <cfergeau@redhat.com>
+Date: Wed, 8 Feb 2017 15:23:56 +0100
+Subject: [PATCH] Xspice: Use print("") instead of print ""
+
+This allows Xspice to run when using python3 instead of python2
+---
+ scripts/Xspice | 16 ++++++++--------
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/scripts/Xspice b/scripts/Xspice
+index ada99d1..30d10fa 100755
+--- a/scripts/Xspice
++++ b/scripts/Xspice
+@@ -34,7 +34,7 @@ def which(x):
+ candidate = os.path.join(p, x)
+ if os.path.exists(candidate):
+ return candidate
+- print 'Warning: failed to find executable %s' % x
++ print('Warning: failed to find executable %s' % x)
+ return None
+
+ if 'XSPICE_ENABLE_GDB' in os.environ:
+@@ -128,10 +128,10 @@ args, xorg_args = parser.parse_known_args(sys.argv[1:])
+ def agents_new_enough(args):
+ for f in [args.vdagent_exec, args.vdagentd_exec]:
+ if not f:
+- print 'please specify path to vdagent/vdagentd executables'
++ print('please specify path to vdagent/vdagentd executables')
+ return False
+ if not os.path.exists(f):
+- print 'error: file not found ', f
++ print('error: file not found ', f)
+ return False
+
+ for f in [args.vdagent_exec, args.vdagentd_exec]:
+@@ -169,11 +169,11 @@ def tls_files(args):
+ # and it isn't supplied spice will still abort, and Xorg with it.
+ for key, filename in tls_files(args).items():
+ if not os.path.exists(filename):
+- print "missing %s - %s does not exist" % (key, filename)
++ print("missing %s - %s does not exist" % (key, filename))
+ sys.exit(1)
+
+ def error(msg, exit_code=1):
+- print "Xspice: %s" % msg
++ print("Xspice: %s" % msg)
+ sys.exit(exit_code)
+
+ if not args.xorg:
+@@ -319,7 +319,7 @@ for arg in xorg_args:
+ if arg.startswith(":"):
+ display = arg
+ if not display:
+- print "Error: missing display on line (i.e. :3)"
++ print("Error: missing display on line (i.e. :3)")
+ raise SystemExit
+ os.environ ['DISPLAY'] = display
+
+@@ -343,7 +343,7 @@ time.sleep(2)
+
+ retpid,rc = os.waitpid(xorg.pid, os.WNOHANG)
+ if retpid != 0:
+- print "Error: X server is not running"
++ print("Error: X server is not running")
+ else:
+ if args.vdagent_enabled and args.vdagent_launch:
+ # XXX use systemd --user for this?
+@@ -361,4 +361,4 @@ else:
+ xorg.wait()
+ except KeyboardInterrupt:
+ # Catch Ctrl-C as that is the common way of ending this script
+- print "Keyboard Interrupt"
++ print("Keyboard Interrupt")
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Christophe Fergeau <cfergeau@redhat.com>
+Date: Wed, 8 Feb 2017 17:07:39 +0100
+Subject: [PATCH] Xspice: Remove extra space before assignment
+
+---
+ scripts/Xspice | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/scripts/Xspice b/scripts/Xspice
+index 30d10fa..41fd80c 100755
+--- a/scripts/Xspice
++++ b/scripts/Xspice
+@@ -211,7 +211,7 @@ signal.signal(signal.SIGTERM, cleanup)
+ atexit.register(cleanup)
+
+ if args.auto:
+- temp_dir = tempfile.mkdtemp(prefix="Xspice-")
++ temp_dir = tempfile.mkdtemp(prefix="Xspice-")
+ cleanup_dirs.append(temp_dir)
+
+ args.config = temp_dir + "/xorg.conf"
+@@ -275,7 +275,7 @@ if args.vdagent_enabled:
+ os.unlink(f)
+
+ if not temp_dir:
+- temp_dir = tempfile.mkdtemp(prefix="Xspice-")
++ temp_dir = tempfile.mkdtemp(prefix="Xspice-")
+ cleanup_dirs.append(temp_dir)
+
+ # Auto generate temporary files for vdagent
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Christophe Fergeau <cfergeau@redhat.com>
+Date: Wed, 8 Feb 2017 17:07:56 +0100
+Subject: [PATCH] Xspice: Fix Python3 str() vs bytes() confusion
+
+With python3, without universal_newlines=True, Popen().stdout.read()
+will return a byte array, while find(str) expects to operate on a
+string.
+I've checked that this still works with python2 as well.
+---
+ scripts/Xspice | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/scripts/Xspice b/scripts/Xspice
+index 41fd80c..927dcb1 100755
+--- a/scripts/Xspice
++++ b/scripts/Xspice
+@@ -135,7 +135,7 @@ def agents_new_enough(args):
+ return False
+
+ for f in [args.vdagent_exec, args.vdagentd_exec]:
+- if Popen(args=[f, '-h'], stdout=PIPE).stdout.read().find('-S') == -1:
++ if Popen(args=[f, '-h'], stdout=PIPE, universal_newlines=True).stdout.read().find('-S') == -1:
+ return False
+ return True
+
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Christophe Fergeau <cfergeau@redhat.com>
+Date: Thu, 17 May 2018 15:31:05 +0200
+Subject: [PATCH] Xspice: Adjust shebang to explicitly mention python3
+
+---
+ scripts/Xspice | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/scripts/Xspice b/scripts/Xspice
+index 927dcb1..78d0794 100755
+--- a/scripts/Xspice
++++ b/scripts/Xspice
+@@ -1,4 +1,4 @@
+-#!/usr/bin/python
++#!/usr/bin/python3
+
+ """
+ Xspice
+
+
diff --git a/repo/x11/xf86-video-qxl.xibuild b/repo/x11/xf86-video-qxl/xf86-video-qxl.xibuild
index f7fd090..f7fd090 100644
--- a/repo/x11/xf86-video-qxl.xibuild
+++ b/repo/x11/xf86-video-qxl/xf86-video-qxl.xibuild
diff --git a/repo/x11/xf86-video-vmware.xibuild b/repo/x11/xf86-video-vmware/xf86-video-vmware.xibuild
index 569ab92..569ab92 100644
--- a/repo/x11/xf86-video-vmware.xibuild
+++ b/repo/x11/xf86-video-vmware/xf86-video-vmware.xibuild
diff --git a/repo/x11/xgamma.xibuild b/repo/x11/xgamma/xgamma.xibuild
index 0f987b1..0f987b1 100644
--- a/repo/x11/xgamma.xibuild
+++ b/repo/x11/xgamma/xgamma.xibuild
diff --git a/repo/x11/xhost.xibuild b/repo/x11/xhost/xhost.xibuild
index 5d1509d..5d1509d 100644
--- a/repo/x11/xhost.xibuild
+++ b/repo/x11/xhost/xhost.xibuild
diff --git a/repo/x11/xinput.xibuild b/repo/x11/xinput/xinput.xibuild
index d52f202..d52f202 100644
--- a/repo/x11/xinput.xibuild
+++ b/repo/x11/xinput/xinput.xibuild
diff --git a/repo/x11/xkbcomp.xibuild b/repo/x11/xkbcomp/xkbcomp.xibuild
index 35debf3..35debf3 100644
--- a/repo/x11/xkbcomp.xibuild
+++ b/repo/x11/xkbcomp/xkbcomp.xibuild
diff --git a/repo/x11/xkbevd.xibuild b/repo/x11/xkbevd/xkbevd.xibuild
index 62452f5..62452f5 100644
--- a/repo/x11/xkbevd.xibuild
+++ b/repo/x11/xkbevd/xkbevd.xibuild
diff --git a/repo/x11/xkbutils.xibuild b/repo/x11/xkbutils/xkbutils.xibuild
index 637bcf8..637bcf8 100644
--- a/repo/x11/xkbutils.xibuild
+++ b/repo/x11/xkbutils/xkbutils.xibuild
diff --git a/repo/x11/xkeyboardconfig.xibuild b/repo/x11/xkeyboardconfig/xkeyboardconfig.xibuild
index 74f48e7..74f48e7 100644
--- a/repo/x11/xkeyboardconfig.xibuild
+++ b/repo/x11/xkeyboardconfig/xkeyboardconfig.xibuild
diff --git a/repo/x11/xkill.xibuild b/repo/x11/xkill/xkill.xibuild
index 591ccb6..591ccb6 100644
--- a/repo/x11/xkill.xibuild
+++ b/repo/x11/xkill/xkill.xibuild
diff --git a/repo/x11/xlsatoms.xibuild b/repo/x11/xlsatoms/xlsatoms.xibuild
index e9e20c2..e9e20c2 100644
--- a/repo/x11/xlsatoms.xibuild
+++ b/repo/x11/xlsatoms/xlsatoms.xibuild
diff --git a/repo/x11/xlsclients.xibuild b/repo/x11/xlsclients/xlsclients.xibuild
index 9400313..9400313 100644
--- a/repo/x11/xlsclients.xibuild
+++ b/repo/x11/xlsclients/xlsclients.xibuild
diff --git a/repo/x11/xmessage.xibuild b/repo/x11/xmessage/xmessage.xibuild
index 4cb6ab4..4cb6ab4 100644
--- a/repo/x11/xmessage.xibuild
+++ b/repo/x11/xmessage/xmessage.xibuild
diff --git a/repo/x11/xmodmap.xibuild b/repo/x11/xmodmap/xmodmap.xibuild
index b940a85..b940a85 100644
--- a/repo/x11/xmodmap.xibuild
+++ b/repo/x11/xmodmap/xmodmap.xibuild
diff --git a/repo/x11/xorg-libs.xibuild b/repo/x11/xorg-libs/xorg-libs.xibuild
index c97f3d9..c97f3d9 100644
--- a/repo/x11/xorg-libs.xibuild
+++ b/repo/x11/xorg-libs/xorg-libs.xibuild
diff --git a/repo/x11/xorg-server.xibuild b/repo/x11/xorg-server/xorg-server.xibuild
index 11553aa..11553aa 100644
--- a/repo/x11/xorg-server.xibuild
+++ b/repo/x11/xorg-server/xorg-server.xibuild
diff --git a/repo/x11/xorg-util-macros.xibuild b/repo/x11/xorg-util-macros/xorg-util-macros.xibuild
index b945b41..b945b41 100644
--- a/repo/x11/xorg-util-macros.xibuild
+++ b/repo/x11/xorg-util-macros/xorg-util-macros.xibuild
diff --git a/repo/x11/xorg-xinit.xibuild b/repo/x11/xorg-xinit/xorg-xinit.xibuild
index ccd76a8..ccd76a8 100644
--- a/repo/x11/xorg-xinit.xibuild
+++ b/repo/x11/xorg-xinit/xorg-xinit.xibuild
diff --git a/repo/x11/xorgproto.xibuild b/repo/x11/xorgproto/xorgproto.xibuild
index f49cf52..f49cf52 100644
--- a/repo/x11/xorgproto.xibuild
+++ b/repo/x11/xorgproto/xorgproto.xibuild
diff --git a/repo/x11/xpr.xibuild b/repo/x11/xpr/xpr.xibuild
index 70d557e..70d557e 100644
--- a/repo/x11/xpr.xibuild
+++ b/repo/x11/xpr/xpr.xibuild
diff --git a/repo/x11/xprop.xibuild b/repo/x11/xprop/xprop.xibuild
index d3133ac..d3133ac 100644
--- a/repo/x11/xprop.xibuild
+++ b/repo/x11/xprop/xprop.xibuild
diff --git a/repo/x11/xrandr.xibuild b/repo/x11/xrandr/xrandr.xibuild
index 49f8a8d..49f8a8d 100644
--- a/repo/x11/xrandr.xibuild
+++ b/repo/x11/xrandr/xrandr.xibuild
diff --git a/repo/x11/xrdb.xibuild b/repo/x11/xrdb/xrdb.xibuild
index b8a55ef..b8a55ef 100644
--- a/repo/x11/xrdb.xibuild
+++ b/repo/x11/xrdb/xrdb.xibuild
diff --git a/repo/x11/xrefresh.xibuild b/repo/x11/xrefresh/xrefresh.xibuild
index cb6c224..cb6c224 100644
--- a/repo/x11/xrefresh.xibuild
+++ b/repo/x11/xrefresh/xrefresh.xibuild
diff --git a/repo/x11/xsel.xibuild b/repo/x11/xsel/xsel.xibuild
index ee59b5b..ee59b5b 100644
--- a/repo/x11/xsel.xibuild
+++ b/repo/x11/xsel/xsel.xibuild
diff --git a/repo/x11/xset.xibuild b/repo/x11/xset/xset.xibuild
index 403fcc9..403fcc9 100644
--- a/repo/x11/xset.xibuild
+++ b/repo/x11/xset/xset.xibuild
diff --git a/repo/x11/xsetroot.xibuild b/repo/x11/xsetroot/xsetroot.xibuild
index 3fda50e..3fda50e 100644
--- a/repo/x11/xsetroot.xibuild
+++ b/repo/x11/xsetroot/xsetroot.xibuild
diff --git a/repo/x11/xtrans.xibuild b/repo/x11/xtrans/xtrans.xibuild
index 52a0c9f..52a0c9f 100644
--- a/repo/x11/xtrans.xibuild
+++ b/repo/x11/xtrans/xtrans.xibuild
diff --git a/repo/x11/xvinfo.xibuild b/repo/x11/xvinfo/xvinfo.xibuild
index 91269f9..91269f9 100644
--- a/repo/x11/xvinfo.xibuild
+++ b/repo/x11/xvinfo/xvinfo.xibuild
diff --git a/repo/x11/xwd.xibuild b/repo/x11/xwd/xwd.xibuild
index 8b28ccf..8b28ccf 100644
--- a/repo/x11/xwd.xibuild
+++ b/repo/x11/xwd/xwd.xibuild
diff --git a/repo/x11/xwininfo.xibuild b/repo/x11/xwininfo/xwininfo.xibuild
index 496ea6b..496ea6b 100644
--- a/repo/x11/xwininfo.xibuild
+++ b/repo/x11/xwininfo/xwininfo.xibuild
diff --git a/repo/x11/xwud.xibuild b/repo/x11/xwud/xwud.xibuild
index f02ede7..f02ede7 100644
--- a/repo/x11/xwud.xibuild
+++ b/repo/x11/xwud/xwud.xibuild