pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

MesaLib: add version 21.1.5 to pkgsrc-wip



Module Name:	pkgsrc-wip
Committed By:	Tobias Nygren <tnn%NetBSD.org@localhost>
Pushed By:	tnn
Date:		Tue Jul 20 13:39:41 2021 +0200
Changeset:	34ccaffebecb07ca634ace0e1b1019c5781c107d

Modified Files:
	Makefile
Added Files:
	MesaLib/DESCR
	MesaLib/Makefile
	MesaLib/PLIST
	MesaLib/buildlink3.mk
	MesaLib/builtin.mk
	MesaLib/distinfo
	MesaLib/features.mk
	MesaLib/options.mk
	MesaLib/patches/patch-include_c11_threads__posix.h
	MesaLib/patches/patch-src_compiler_builtin__type__macros.h
	MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c
	MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c
	MesaLib/patches/patch-src_egl_main_eglglobals.c
	MesaLib/patches/patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.c
	MesaLib/patches/patch-src_gallium_auxiliary_rbug_rbug__texture.c
	MesaLib/patches/patch-src_gallium_drivers_llvmpipe_lp__memory.c
	MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c
	MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c
	MesaLib/patches/patch-src_gallium_drivers_vc4_vc4__bufmgr.c
	MesaLib/patches/patch-src_gallium_frontends_clover_llvm_invocation.cpp
	MesaLib/patches/patch-src_gallium_frontends_clover_util_range.hpp
	MesaLib/patches/patch-src_glx_dri__common.c
	MesaLib/patches/patch-src_glx_dri__common.h
	MesaLib/patches/patch-src_glx_glxclient.h
	MesaLib/patches/patch-src_glx_glxcurrent.c
	MesaLib/patches/patch-src_glx_glxext.c
	MesaLib/patches/patch-src_intel_compiler_brw__fs__bank__conflicts.cpp
	MesaLib/patches/patch-src_intel_tools_aubinator__error__decode.c
	MesaLib/patches/patch-src_mapi_entry__x86-64__tls.h
	MesaLib/patches/patch-src_mapi_entry__x86__tls.h
	MesaLib/patches/patch-src_mapi_u__current.c
	MesaLib/patches/patch-src_mesa_main_extensions.c
	MesaLib/patches/patch-src_mesa_main_shader__query.cpp
	MesaLib/patches/patch-src_mesa_x86_common__x86.c
	MesaLib/patches/patch-src_util_build__id.c
	MesaLib/patches/patch-src_util_strndup.h
	MesaLib/patches/patch-src_util_u__atomic.h
	MesaLib/patches/patch-src_util_u__queue.c
	MesaLib/patches/patch-src_util_u__thread.h
	MesaLib/version.mk

Log Message:
MesaLib: add version 21.1.5 to pkgsrc-wip

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=34ccaffebecb07ca634ace0e1b1019c5781c107d

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 Makefile                                           |   1 +
 MesaLib/DESCR                                      |  10 ++
 MesaLib/Makefile                                   | 181 +++++++++++++++++++++
 MesaLib/PLIST                                      | 115 +++++++++++++
 MesaLib/buildlink3.mk                              |  43 +++++
 MesaLib/builtin.mk                                 |  89 ++++++++++
 MesaLib/distinfo                                   |  37 +++++
 MesaLib/features.mk                                |  36 ++++
 MesaLib/options.mk                                 | 132 +++++++++++++++
 MesaLib/patches/patch-include_c11_threads__posix.h |  17 ++
 .../patch-src_compiler_builtin__type__macros.h     |  25 +++
 .../patch-src_egl_drivers_dri2_platform__drm.c     |  23 +++
 .../patch-src_egl_drivers_dri2_platform__x11.c     |  63 +++++++
 MesaLib/patches/patch-src_egl_main_eglglobals.c    |  53 ++++++
 ...llium_auxiliary_pipe-loader_pipe__loader__drm.c | 127 +++++++++++++++
 ...atch-src_gallium_auxiliary_rbug_rbug__texture.c |  14 ++
 ...patch-src_gallium_drivers_llvmpipe_lp__memory.c |  23 +++
 ...c_gallium_drivers_nouveau_nouveau__vp3__video.c |  18 ++
 ...-src_gallium_drivers_nouveau_nv50_nv84__video.c |  18 ++
 .../patch-src_gallium_drivers_vc4_vc4__bufmgr.c    |  18 ++
 ...rc_gallium_frontends_clover_llvm_invocation.cpp |  41 +++++
 ...tch-src_gallium_frontends_clover_util_range.hpp |  40 +++++
 MesaLib/patches/patch-src_glx_dri__common.c        |  41 +++++
 MesaLib/patches/patch-src_glx_dri__common.h        |  17 ++
 MesaLib/patches/patch-src_glx_glxclient.h          |  19 +++
 MesaLib/patches/patch-src_glx_glxcurrent.c         |  42 +++++
 MesaLib/patches/patch-src_glx_glxext.c             |  39 +++++
 ...src_intel_compiler_brw__fs__bank__conflicts.cpp |  23 +++
 ...atch-src_intel_tools_aubinator__error__decode.c |  19 +++
 .../patches/patch-src_mapi_entry__x86-64__tls.h    |  56 +++++++
 MesaLib/patches/patch-src_mapi_entry__x86__tls.h   |  53 ++++++
 MesaLib/patches/patch-src_mapi_u__current.c        |  31 ++++
 MesaLib/patches/patch-src_mesa_main_extensions.c   |  31 ++++
 .../patches/patch-src_mesa_main_shader__query.cpp  |  58 +++++++
 MesaLib/patches/patch-src_mesa_x86_common__x86.c   |  24 +++
 MesaLib/patches/patch-src_util_build__id.c         |  25 +++
 MesaLib/patches/patch-src_util_strndup.h           |  15 ++
 MesaLib/patches/patch-src_util_u__atomic.h         |  15 ++
 MesaLib/patches/patch-src_util_u__queue.c          |  44 +++++
 MesaLib/patches/patch-src_util_u__thread.h         |  71 ++++++++
 MesaLib/version.mk                                 |  30 ++++
 41 files changed, 1777 insertions(+)

diffs:
diff --git a/Makefile b/Makefile
index 091c06679c..56a7c29c7d 100644
--- a/Makefile
+++ b/Makefile
@@ -21,6 +21,7 @@ SUBDIR+=	Geomyidae-git
 SUBDIR+=	GoogleEarth
 SUBDIR+=	I2util
 SUBDIR+=	LuaJIT21
+SUBDIR+=	MesaLib
 SUBDIR+=	MesaLib-dfbsd
 SUBDIR+=	MesaLib-dfbsd-meson
 SUBDIR+=	MoleInvasion
diff --git a/MesaLib/DESCR b/MesaLib/DESCR
new file mode 100644
index 0000000000..8ae75a59fc
--- /dev/null
+++ b/MesaLib/DESCR
@@ -0,0 +1,10 @@
+The Mesa project began as an open-source implementation of the OpenGL
+specification - a system for rendering interactive 3D graphics.
+
+Over the years the project has grown to implement more graphics APIs,
+including OpenGL ES (versions 1, 2, 3), OpenCL, OpenMAX, VDPAU, VA API,
+XvMC and Vulkan.
+
+A variety of device drivers allows the Mesa libraries to be used in many
+different environments ranging from software emulation to complete hardware
+acceleration for modern GPUs.
diff --git a/MesaLib/Makefile b/MesaLib/Makefile
new file mode 100644
index 0000000000..9a7f95235c
--- /dev/null
+++ b/MesaLib/Makefile
@@ -0,0 +1,181 @@
+# $NetBSD: Makefile,v 1.197 2021/04/25 07:51:26 mrg Exp $
+
+DISTNAME=	mesa-21.1.5
+PKGNAME=	${DISTNAME:S/mesa/MesaLib/}
+CATEGORIES=	graphics
+MASTER_SITES=	https://mesa.freedesktop.org/archive/
+EXTRACT_SUFX=	.tar.xz
+
+MAINTAINER=	nia%NetBSD.org@localhost
+HOMEPAGE=	https://www.mesa3d.org/
+COMMENT=	Open source OpenGL implementation
+LICENSE=	mit
+
+USE_TOOLS+=	bison flex pkg-config xgettext
+USE_LANGUAGES=	c99 c++14
+
+# ERROR: C++ Compiler does not support -std=c++14
+GCC_REQD+=	5
+
+USE_FEATURES+=	strnlen
+
+CFLAGS.SunOS+=		-D_POSIX_PTHREAD_SEMANTICS
+CXXFLAGS.SunOS+=	-Drestrict=__restrict__
+LDFLAGS.SunOS+=		-lsocket -lnsl
+
+# Some of these get appended in options.mk.
+DRI_DRIVERS=		#
+GALLIUM_DRIVERS=	swrast
+VULKAN_DRIVERS=		#
+MESA_PLATFORMS=		#
+
+.include "../../mk/compiler.mk"
+.include "features.mk"
+.include "options.mk"
+
+PLIST_SUBST+=	GLVER="1.2.0"
+
+# classic DRI drivers
+PLIST_VARS+=		i915 i965 r100 r200 nouveau_dri arm
+
+# Gallium drivers
+PLIST_VARS+=		r300 svga nouveau
+
+# other features
+PLIST_VARS+=		kms vaapi
+
+.if ${MESALIB_SUPPORTS_DRI} == "yes"
+BUILDLINK_API_DEPENDS.libdrm+=  libdrm>=2.4.100
+.include "../../wip/libdrm/buildlink3.mk"
+.  if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
+.    include "../../sysutils/libpciaccess/buildlink3.mk"
+.  endif
+MESON_ARGS+=		-Degl=true
+MESON_ARGS+=		-Dgbm=true
+MESON_ARGS+=		-Dgallium-xa=true
+.  if ${X11_TYPE} == "native" && !exists(${X11BASE}/include/xcb/dri3.h)
+MESON_ARGS+=		-Ddri3=false
+.  endif
+PLIST.kms=		yes
+.  if !empty(MACHINE_ARCH:M*arm*) || \
+      ${MACHINE_CPU} == "aarch64"
+# not yet
+GALLIUM_DRIVERS+=	freedreno vc4 etnaviv tegra panfrost lima
+PLIST.arm=		yes
+.  endif
+.  if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
+GALLIUM_DRIVERS+=	svga
+DRI_DRIVERS+=		i915 i965
+PLIST.svga=		yes
+PLIST.i915=		yes
+PLIST.i965=		yes
+.  endif
+# FreeBSD lacks nouveau support (there are official binaries from Nvidia)
+.  if ${OPSYS} != "FreeBSD"
+PLIST.nouveau=		yes
+PLIST.nouveau_dri=	yes
+GALLIUM_DRIVERS+=	nouveau
+DRI_DRIVERS+=		nouveau
+.  endif
+.  if !empty(MACHINE_PLATFORM:MLinux-*-x86_64)
+# qemu Linux guest driver
+# XXX test this
+#GALLIUM_DRIVERS+=	virgl
+#PLIST.virgl=		yes
+.  endif
+# theoretically cross platform PCI drivers
+.  if empty(MACHINE_PLATFORM:MNetBSD-*-*arm*) && \
+      empty(MACHINE_PLATFORM:MNetBSD-*-mipsel)
+DRI_DRIVERS+=		r100 r200
+GALLIUM_DRIVERS+=	r300
+PLIST.r100=		yes
+PLIST.r200=		yes
+PLIST.r300=		yes
+.  endif
+.  include "../../multimedia/libva/available.mk"
+.  if ${VAAPI_AVAILABLE} == "yes" && \
+      !(empty(GALLIUM_DRIVERS:Mr600) && empty(GALLIUM_DRIVERS:Mradeonsi) && \
+        empty(GALLIUM_DRIVERS:Mnouveau))
+MESON_ARGS+=		-Dgallium-va=true
+PLIST.vaapi=		yes
+.    include "../../multimedia/libva/buildlink3.mk"
+.  else
+MESON_ARGS+=		-Dgallium-va=false
+.  endif
+.else
+MESON_ARGS+=		-Degl=false
+MESON_ARGS+=		-Dgbm=false
+.endif # ${MESALIB_SUPPORTS_DRI} == "yes"
+
+MESON_ARGS+=	-Dgallium-drivers=${GALLIUM_DRIVERS:ts,}
+MESON_ARGS+=	-Ddri-drivers=${DRI_DRIVERS:ts,}
+MESON_ARGS+=	-Dvulkan-drivers=${VULKAN_DRIVERS:ts,}
+MESON_ARGS+=	-Dplatforms=${MESA_PLATFORMS:ts,}
+
+.if ${MACHINE_ARCH} == "i386"
+MESON_ARGS+=	-Dglx-read-only-text=true
+CFLAGS+=	-march=i586
+CXXFLAGS+=	-march=i586
+.endif
+
+MESON_ARGS+=	-Dgles1=true
+MESON_ARGS+=	-Dgles2=true
+MESON_ARGS+=	-Dosmesa=true
+MESON_ARGS+=	-Dshared-glapi=true
+MESON_ARGS+=	-Dgallium-xvmc=false
+
+CPPFLAGS+=	-DHAVE_NOATEXIT
+CPPFLAGS+=	-DSYSCONFDIR=${PKG_SYSCONFDIR}
+
+TOOL_DEPENDS+=	${PYPKGPREFIX}-mako-[0-9]*:../../devel/py-mako
+
+# needed to build vulkan support
+TOOL_DEPENDS+=	${PYPKGPREFIX}-cElementTree-[0-9]*:../../textproc/py-cElementTree
+
+BUILDLINK_TRANSFORM+=		rm:-Werror=incompatible-pointer-types
+
+# https://gitlab.freedesktop.org/mesa/mesa/merge_requests/1854
+BUILDLINK_TRANSFORM+=		rm:-Werror=return-type
+
+# ../src/intel/perf/gen_perf.c:426:7: error: %m is only allowed in syslog(3) like functions
+BUILDLINK_TRANSFORM+=		rm:-Werror=format
+BUILDLINK_TRANSFORM+=		rm:-Wformat-security
+
+# https://gitlab.freedesktop.org/mesa/mesa/merge_requests/1853
+BUILDLINK_TRANSFORM.SunOS+=	rm:-Wl,--build-id=sha1
+
+# Work around Xorg segfaulting in radeon driver due to wrong alloca being used
+CFLAGS.NetBSD+=		-Dalloca=__builtin_alloca
+CXXFLAGS.NetBSD+=	-Dalloca=__builtin_alloca
+
+EGDIR=		${PREFIX}/share/examples/mesa
+
+CONF_FILES+=	${EGDIR}/00-mesa-defaults.conf ${PKG_SYSCONFDIR}/drirc
+
+INSTALLATION_DIRS+=	${EGDIR}
+
+PYTHON_FOR_BUILD_ONLY=		tool
+PYTHON_VERSIONS_INCOMPATIBLE=	27
+
+PKGCONFIG_OVERRIDE_STAGE=	pre-install
+PKGCONFIG_OVERRIDE+=		output/meson-private/glesv1_cm.pc
+PKGCONFIG_OVERRIDE+=		output/meson-private/glesv2.pc
+PKGCONFIG_OVERRIDE+=		output/meson-private/dri.pc
+PKGCONFIG_OVERRIDE+=		output/meson-private/gbm.pc
+PKGCONFIG_OVERRIDE+=		output/meson-private/egl.pc
+PKGCONFIG_OVERRIDE+=		output/meson-private/osmesa.pc
+PKGCONFIG_OVERRIDE+=		output/meson-private/xatracker.pc
+PKGCONFIG_OVERRIDE+=		output/meson-private/gl.pc
+
+post-install:
+	${MV} ${DESTDIR}${PREFIX}/share/drirc.d/00-mesa-defaults.conf ${DESTDIR}${EGDIR}
+.if ${OPSYS} == "Darwin"
+	install_name_tool -id ${PREFIX}/lib/dri/swrast_dri.so \
+	    ${DESTDIR}${PREFIX}/lib/dri/swrast_dri.so
+.endif
+
+.include "../../devel/meson/build.mk"
+.include "../../devel/zlib/buildlink3.mk"
+.include "../../lang/python/tool.mk"
+.include "../../textproc/expat/buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/MesaLib/PLIST b/MesaLib/PLIST
new file mode 100644
index 0000000000..5f065a7bb5
--- /dev/null
+++ b/MesaLib/PLIST
@@ -0,0 +1,115 @@
+@comment $NetBSD: PLIST,v 1.46 2019/11/30 11:02:39 nia Exp $
+${PLIST.kms}include/EGL/egl.h
+${PLIST.kms}include/EGL/eglext.h
+${PLIST.kms}include/EGL/eglextchromium.h
+${PLIST.kms}include/EGL/eglmesaext.h
+${PLIST.kms}include/EGL/eglplatform.h
+include/GL/gl.h
+include/GL/glcorearb.h
+include/GL/glext.h
+${PLIST.glx}include/GL/glx.h
+${PLIST.glx}include/GL/glxext.h
+include/GL/internal/dri_interface.h
+include/GL/osmesa.h
+include/GLES/egl.h
+include/GLES/gl.h
+include/GLES/glext.h
+include/GLES/glplatform.h
+include/GLES2/gl2.h
+include/GLES2/gl2ext.h
+include/GLES2/gl2platform.h
+include/GLES3/gl3.h
+include/GLES3/gl31.h
+include/GLES3/gl32.h
+include/GLES3/gl3ext.h
+include/GLES3/gl3platform.h
+include/KHR/khrplatform.h
+${PLIST.kms}include/gbm.h
+${PLIST.kms}include/xa_composite.h
+${PLIST.kms}include/xa_context.h
+${PLIST.kms}include/xa_tracker.h
+${PLIST.arm}lib/dri/armada-drm_dri.so
+${PLIST.arm}lib/dri/exynos_dri.so
+${PLIST.arm}lib/dri/hx8357d_dri.so
+${PLIST.i915}lib/dri/i915_dri.so
+${PLIST.i965}lib/dri/i965_dri.so
+${PLIST.arm}lib/dri/ili9225_dri.so
+${PLIST.arm}lib/dri/ili9341_dri.so
+${PLIST.arm}lib/dri/imx-dcss_dri.so
+${PLIST.arm}lib/dri/imx-drm_dri.so
+${PLIST.arm}lib/dri/ingenic-drm_dri.so
+${PLIST.kms}lib/dri/kms_swrast_dri.so
+${PLIST.arm}lib/dri/mcde_dri.so
+${PLIST.arm}lib/dri/mediatek_dri.so
+${PLIST.arm}lib/dri/meson_dri.so
+${PLIST.arm}lib/dri/mi0283qt_dri.so
+${PLIST.arm}lib/dri/mxsfb-drm_dri.so
+${PLIST.nouveau}lib/dri/nouveau_dri.so
+${PLIST.nouveau}${PLIST.vaapi}lib/dri/nouveau_drv_video.so
+${PLIST.nouveau_dri}lib/dri/nouveau_vieux_dri.so
+${PLIST.arm}lib/dri/pl111_dri.so
+${PLIST.r200}lib/dri/r200_dri.so
+${PLIST.r300}lib/dri/r300_dri.so
+${PLIST.r600}lib/dri/r600_dri.so
+${PLIST.r600}${PLIST.vaapi}lib/dri/r600_drv_video.so
+${PLIST.r100}lib/dri/radeon_dri.so
+${PLIST.radeonsi}lib/dri/radeonsi_dri.so
+${PLIST.r600}${PLIST.vaapi}lib/dri/radeonsi_drv_video.so
+${PLIST.arm}lib/dri/repaper_dri.so
+${PLIST.arm}lib/dri/rockchip_dri.so
+${PLIST.arm}lib/dri/st7586_dri.so
+${PLIST.arm}lib/dri/st7735r_dri.so
+${PLIST.arm}lib/dri/stm_dri.so
+${PLIST.arm}lib/dri/sun4i-drm_dri.so
+lib/dri/swrast_dri.so
+${PLIST.arm}lib/dri/vc4_dri.so
+${PLIST.svga}lib/dri/vmwgfx_dri.so
+${PLIST.kms}lib/libEGL.so
+${PLIST.kms}lib/libEGL.so.1
+${PLIST.kms}lib/libEGL.so.1.0.0
+${PLIST.glx}lib/libGL.so
+${PLIST.glx}lib/libGL.so.1
+${PLIST.glx}lib/libGL.so.${GLVER}
+lib/libGLESv1_CM.so
+lib/libGLESv1_CM.so.1
+lib/libGLESv1_CM.so.1.1.0
+lib/libGLESv2.so
+lib/libGLESv2.so.2
+lib/libGLESv2.so.2.0.0
+lib/libOSMesa.so
+lib/libOSMesa.so.8
+lib/libOSMesa.so.8.0.0
+${PLIST.kms}lib/libgbm.so
+${PLIST.kms}lib/libgbm.so.1
+${PLIST.kms}lib/libgbm.so.1.0.0
+lib/libglapi.so
+lib/libglapi.so.0
+lib/libglapi.so.0.0.0
+${PLIST.kms}lib/libxatracker.so
+${PLIST.kms}lib/libxatracker.so.2
+${PLIST.kms}lib/libxatracker.so.2.5.0
+lib/pkgconfig/dri.pc
+${PLIST.kms}lib/pkgconfig/egl.pc
+${PLIST.kms}lib/pkgconfig/gbm.pc
+${PLIST.glx}lib/pkgconfig/gl.pc
+lib/pkgconfig/glesv1_cm.pc
+lib/pkgconfig/glesv2.pc
+lib/pkgconfig/osmesa.pc
+${PLIST.kms}lib/pkgconfig/xatracker.pc
+${PLIST.nouveau}${PLIST.vdpau}lib/vdpau/libvdpau_nouveau.so
+${PLIST.nouveau}${PLIST.vdpau}lib/vdpau/libvdpau_nouveau.so.1
+${PLIST.nouveau}${PLIST.vdpau}lib/vdpau/libvdpau_nouveau.so.1.0
+${PLIST.nouveau}${PLIST.vdpau}lib/vdpau/libvdpau_nouveau.so.1.0.0
+${PLIST.r300}${PLIST.vdpau}lib/vdpau/libvdpau_r300.so
+${PLIST.r300}${PLIST.vdpau}lib/vdpau/libvdpau_r300.so.1
+${PLIST.r300}${PLIST.vdpau}lib/vdpau/libvdpau_r300.so.1.0
+${PLIST.r300}${PLIST.vdpau}lib/vdpau/libvdpau_r300.so.1.0.0
+${PLIST.r600}${PLIST.vdpau}lib/vdpau/libvdpau_r600.so
+${PLIST.r600}${PLIST.vdpau}lib/vdpau/libvdpau_r600.so.1
+${PLIST.r600}${PLIST.vdpau}lib/vdpau/libvdpau_r600.so.1.0
+${PLIST.r600}${PLIST.vdpau}lib/vdpau/libvdpau_r600.so.1.0.0
+${PLIST.radeonsi}${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so
+${PLIST.radeonsi}${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so.1
+${PLIST.radeonsi}${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so.1.0
+${PLIST.radeonsi}${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so.1.0.0
+share/examples/mesa/00-mesa-defaults.conf
diff --git a/MesaLib/buildlink3.mk b/MesaLib/buildlink3.mk
new file mode 100644
index 0000000000..b8d49ddbb7
--- /dev/null
+++ b/MesaLib/buildlink3.mk
@@ -0,0 +1,43 @@
+# $NetBSD: buildlink3.mk,v 1.67 2020/03/08 16:49:52 wiz Exp $
+
+BUILDLINK_TREE+=	MesaLib
+
+.if !defined(MESALIB_BUILDLINK3_MK)
+MESALIB_BUILDLINK3_MK:=
+
+BUILDLINK_API_DEPENDS.MesaLib+=	MesaLib>=3.4.2
+BUILDLINK_ABI_DEPENDS.MesaLib+=	MesaLib>=20.0.1nb1
+BUILDLINK_PKGSRCDIR.MesaLib?=	../../graphics/MesaLib
+
+.include "../../graphics/MesaLib/features.mk"
+
+# See <http://developer.apple.com/qa/qa2007/qa1567.html>.
+.if ${X11_TYPE} == "native" && !empty(MACHINE_PLATFORM:MDarwin-[9].*-*)
+BUILDLINK_LDFLAGS.MesaLib+=	-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib
+.endif
+
+pkgbase:= MesaLib
+
+.include "../../mk/pkg-build-options.mk"
+
+.if !empty(PKG_BUILD_OPTIONS.MesaLib:Mx11)
+.  include "../../x11/libX11/buildlink3.mk"
+.  include "../../x11/libXdamage/buildlink3.mk"
+.  include "../../x11/libXext/buildlink3.mk"
+.  include "../../x11/libXfixes/buildlink3.mk"
+.  include "../../x11/libXrandr/buildlink3.mk"
+.  include "../../x11/libXxf86vm/buildlink3.mk"
+.  include "../../x11/libxcb/buildlink3.mk"
+.  include "../../x11/libxshmfence/buildlink3.mk"
+.  include "../../x11/xcb-proto/buildlink3.mk"
+.  include "../../x11/xorgproto/buildlink3.mk"
+.endif
+
+.if ${MESALIB_SUPPORTS_DRI} == "yes"
+.  include "../../wip/libdrm/buildlink3.mk"
+.endif
+
+.include "../../mk/pthread.buildlink3.mk"
+.endif # MESALIB_BUILDLINK3_MK
+
+BUILDLINK_TREE+=	-MesaLib
diff --git a/MesaLib/builtin.mk b/MesaLib/builtin.mk
new file mode 100644
index 0000000000..b2c566d8e0
--- /dev/null
+++ b/MesaLib/builtin.mk
@@ -0,0 +1,89 @@
+# $NetBSD: builtin.mk,v 1.23 2019/08/30 19:06:34 nia Exp $
+
+BUILTIN_PKG:=	MesaLib
+
+BUILTIN_FIND_FILES_VAR:=	H_MESALIB PC_GL
+BUILTIN_FIND_FILES.H_MESALIB=	${X11BASE}/include/GL/glx.h
+BUILTIN_FIND_FILES.PC_GL=	${X11BASE}/lib/pkgconfig/gl.pc
+BUILTIN_FIND_FILES.PC_GL+=	${X11BASE}/lib${LIBABISUFFIX}/pkgconfig/gl.pc
+
+.include "../../mk/buildlink3/bsd.builtin.mk"
+
+###
+### Determine if there is a built-in implementation of the package and
+### set IS_BUILTIN.<pkg> appropriately ("yes" or "no").
+###
+.if !defined(IS_BUILTIN.MesaLib)
+.  if empty(PC_GL:M__nonexistent__)
+IS_BUILTIN.MesaLib=	yes
+.  elif empty(H_MESALIB:M__nonexistent__)
+IS_BUILTIN.MesaLib=	yes
+.  else
+IS_BUILTIN.MesaLib=	no
+.  endif
+.endif
+
+MAKEVARS+=	IS_BUILTIN.MesaLib
+
+###
+### If there is a built-in implementation, then set BUILTIN_PKG.<pkg> to
+### a package name to represent the built-in package.
+###
+.if !defined(BUILTIN_PKG.MesaLib) && \
+    !empty(IS_BUILTIN.MesaLib:M[yY][eE][sS])
+.  if empty(PC_GL:M__nonexistent__)
+BUILTIN_VERSION.Mesa!= ${SED} -n -e 's/Version: //p' ${PC_GL}
+.  elif empty(H_MESALIB:M__nonexistent__)
+.    include "version.mk"
+.  else # ?
+BUILTIN_VERSION.Mesa:= 0.something-weird-happened
+.  endif
+BUILTIN_PKG.MesaLib=	MesaLib-${BUILTIN_VERSION.Mesa}
+MAKEVARS+=	BUILTIN_VERSION.Mesa
+.endif
+MAKEVARS+=	BUILTIN_PKG.MesaLib
+
+###
+### Determine whether we should use the built-in implementation if it
+### exists, and set USE_BUILTIN.<pkg> appropriate ("yes" or "no").
+###
+.if !defined(USE_BUILTIN.MesaLib)
+.  if ${PREFER.MesaLib} == "pkgsrc"
+USE_BUILTIN.MesaLib=	no
+.  else
+USE_BUILTIN.MesaLib=	${IS_BUILTIN.MesaLib}
+.    if defined(BUILTIN_PKG.MesaLib) && \
+        !empty(IS_BUILTIN.MesaLib:M[yY][eE][sS])
+USE_BUILTIN.MesaLib=	yes
+.      for dep in ${BUILDLINK_API_DEPENDS.MesaLib}
+.        if !empty(USE_BUILTIN.MesaLib:M[yY][eE][sS])
+USE_BUILTIN.MesaLib!=							\
+	if ${PKG_ADMIN} pmatch ${dep:Q} ${BUILTIN_PKG.MesaLib}; then \
+		${ECHO} yes;						\
+	else								\
+		${ECHO} no;						\
+	fi
+.        endif
+.      endfor
+.    endif
+.  endif  # PREFER.MesaLib
+.endif
+
+MAKEVARS+=	USE_BUILTIN.MesaLib
+
+###
+### The section below only applies if we are not including this file
+### solely to determine whether a built-in implementation exists.
+###
+CHECK_BUILTIN.MesaLib?=	no
+.if !empty(CHECK_BUILTIN.MesaLib:M[nN][oO])
+
+.  if !empty(USE_BUILTIN.MesaLib:M[nN][oO])
+.    include "../../mk/pthread.buildlink3.mk"
+.    include "../../mk/pthread.builtin.mk"
+BUILTIN_PKG:=	MesaLib
+.  endif
+
+.  include "../../mk/x11.builtin.mk"
+
+.endif	# CHECK_BUILTIN.MesaLib
diff --git a/MesaLib/distinfo b/MesaLib/distinfo
new file mode 100644
index 0000000000..15fee942c4
--- /dev/null
+++ b/MesaLib/distinfo
@@ -0,0 +1,37 @@
+$NetBSD: distinfo,v 1.157 2021/07/15 14:06:56 schmonz Exp $
+
+SHA1 (mesa-21.1.5.tar.xz) = ceefadf8e0f0b0fee643bec98535684a8db12527
+RMD160 (mesa-21.1.5.tar.xz) = 5b189c9fc2c8843bbe0ada928a54c1a0b24ef28e
+SHA512 (mesa-21.1.5.tar.xz) = d9e0e1b6a1d717febee2aa67b06620c9a21e061ea7e594be5b4c382db1ed6f5acf5d13a75a9f2bba9c32621466ebc816708606e16e8b34700d987158fd8f0b7b
+Size (mesa-21.1.5.tar.xz) = 15286704 bytes
+SHA1 (patch-include_c11_threads__posix.h) = e1dca04b5c514d20123ef99338c6dabedbc14c5f
+SHA1 (patch-src_compiler_builtin__type__macros.h) = e4868011711fb89a293580a12eb603b8e7162336
+SHA1 (patch-src_egl_drivers_dri2_platform__drm.c) = 9230fbae2c04246ebca8437ecad694bbae857fbe
+SHA1 (patch-src_egl_drivers_dri2_platform__x11.c) = ccf7c3ba7bdac39f9924102868f30afd7f4f05a2
+SHA1 (patch-src_egl_main_eglglobals.c) = 0d52014f52e62fc5fa6650336ddb0011ecf331e6
+SHA1 (patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.c) = f913b779404e6bd8ae707a4fd66eb7c1dca9b311
+SHA1 (patch-src_gallium_auxiliary_rbug_rbug__texture.c) = 57d831b1001419191a27c05d9cb7734481372d27
+SHA1 (patch-src_gallium_drivers_llvmpipe_lp__memory.c) = ca3c1b317c41f6ae56a08272ffabdecb38fea2ec
+SHA1 (patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c) = 04f95784c3270c9bb7e95377982e217962481525
+SHA1 (patch-src_gallium_drivers_nouveau_nv50_nv84__video.c) = 1b4239fe053523835ecac006894bdb0cde0ee626
+SHA1 (patch-src_gallium_drivers_vc4_vc4__bufmgr.c) = 1d591d346486fdf58893f69ab92a272e6a31a987
+SHA1 (patch-src_gallium_frontends_clover_llvm_invocation.cpp) = c59ab60843717369be20a83f658960e91ce68bf4
+SHA1 (patch-src_gallium_frontends_clover_util_range.hpp) = c1bd73721482642e62378c70cbe245c304c36d4f
+SHA1 (patch-src_glx_dri__common.c) = 7fa80f8da89ba90649db170e45c8e842cf69c1eb
+SHA1 (patch-src_glx_dri__common.h) = 0274877f8c65a4bb729536a897df4704897a4c6e
+SHA1 (patch-src_glx_glxclient.h) = f0358179ae397bc8677597b0ccb9a471f40f15de
+SHA1 (patch-src_glx_glxcurrent.c) = a872950c2cb08f60c1d018d0490c610a764ab468
+SHA1 (patch-src_glx_glxext.c) = 1eacf9062b5926ea6c756e769bf6eebc7671ccba
+SHA1 (patch-src_intel_compiler_brw__fs__bank__conflicts.cpp) = 6276d2c6846bb4dd08699921bec4e20202a17478
+SHA1 (patch-src_intel_tools_aubinator__error__decode.c) = d8f636e3c3e76763a505a1dce23de0b198ad62fa
+SHA1 (patch-src_mapi_entry__x86-64__tls.h) = f3e93565a2247b47495489f2dbecdc354d4a21a0
+SHA1 (patch-src_mapi_entry__x86__tls.h) = 1ca12843b7214831c25c5cdd7860dad94312c118
+SHA1 (patch-src_mapi_u__current.c) = 996a1839a8dcf60468a84302750befa18e166f44
+SHA1 (patch-src_mesa_main_extensions.c) = 8a6094690864289393315bd0ccc4ebd1e0c59ca5
+SHA1 (patch-src_mesa_main_shader__query.cpp) = 3f9c31645d87855759def11344dee16af23c7be3
+SHA1 (patch-src_mesa_x86_common__x86.c) = f8c4b93443ef66d017f6aa114b877565b30f2598
+SHA1 (patch-src_util_build__id.c) = 7a9547bbda9d2fb9f0018ccf27b70b59e497aa2c
+SHA1 (patch-src_util_strndup.h) = 73f49694ca48ad6b9a9d8346c5b84fddec2463bd
+SHA1 (patch-src_util_u__atomic.h) = 31d4514538ef5ee53012695eb5c66134aaec981e
+SHA1 (patch-src_util_u__queue.c) = e8d6b00473a16b6a32dcacd5ae092326fb2adb84
+SHA1 (patch-src_util_u__thread.h) = b273472a779edcc44c34174b96a43469c366e702
diff --git a/MesaLib/features.mk b/MesaLib/features.mk
new file mode 100644
index 0000000000..a033bc6eea
--- /dev/null
+++ b/MesaLib/features.mk
@@ -0,0 +1,36 @@
+# $NetBSD: features.mk,v 1.1 2019/10/21 20:47:55 nia Exp $
+
+.include "../../mk/bsd.fast.prefs.mk"
+
+.if !defined(MESALIB_SUPPORTS_DRI)
+.  for dri_os in DragonFly FreeBSD NetBSD OpenBSD Linux SunOS
+.    if !empty(OPSYS:M${dri_os})
+MESALIB_SUPPORTS_DRI?=		yes
+.    endif
+.  endfor
+.endif
+
+MESALIB_SUPPORTS_DRI?=		no
+
+.if ${X11_TYPE} == "modular"
+MESALIB_SUPPORTS_OSMESA?=	yes
+MESALIB_SUPPORTS_GLESv2?=	yes
+.  if ${MESALIB_SUPPORTS_DRI} == "yes"
+MESALIB_SUPPORTS_EGL?=		yes
+.  else
+.  endif
+.else
+.  if exists(${X11BASE}/include/EGL/egl.h)
+MESALIB_SUPPORTS_EGL?=		yes
+.  endif
+.  if exists(${X11BASE}/lib/libOSMesa.so)
+MESALIB_SUPPORTS_OSMESA?=	yes
+.  endif
+.  if exists(${X11BASE}/include/GLES2/gl2.h)
+MESALIB_SUPPORTS_GLESv2?=	yes
+.  endif
+.endif
+
+MESALIB_SUPPORTS_EGL?=		no
+MESALIB_SUPPORTS_GLESv2?=	no
+MESALIB_SUPPORTS_OSMESA?=	no
diff --git a/MesaLib/options.mk b/MesaLib/options.mk
new file mode 100644
index 0000000000..919ca56644
--- /dev/null
+++ b/MesaLib/options.mk
@@ -0,0 +1,132 @@
+# $NetBSD: options.mk,v 1.81 2020/04/09 16:54:22 nia Exp $
+
+PKG_OPTIONS_VAR=		PKG_OPTIONS.MesaLib
+
+.include "features.mk"
+
+PKG_SUPPORTED_OPTIONS+=		elf-tls llvm vulkan x11
+
+.if ${MESALIB_SUPPORTS_DRI} == "yes"
+PKG_SUPPORTED_OPTIONS+=		wayland
+.  include "../../devel/wayland/platform.mk"
+.  if ${PLATFORM_SUPPORTS_WAYLAND} == "yes"
+PKG_SUGGESTED_OPTIONS+=		wayland
+.  endif
+.endif
+
+PKG_SUGGESTED_OPTIONS+=		x11
+
+.include "../../mk/bsd.fast.prefs.mk"
+
+# The LLVM option enables JIT accelerated software rendering and is also
+# required to support the latest RADEON GPUs.
+#
+# Enable it by default on platforms where such GPUs might be encountered or
+# LLVM-accelerated software rendering might be useful.
+.if ${MESALIB_SUPPORTS_DRI} == "yes" && \
+    ${OPSYS} != "SunOS" && \
+      (${MACHINE_ARCH} == "i386" || \
+       ${MACHINE_ARCH} == "x86_64" || \
+       ${MACHINE_ARCH} == "aarch64")
+PKG_SUGGESTED_OPTIONS+=		llvm
+.endif
+
+# ELF TLS is broken in at least the following cases:
+# - NetBSD with SDL2 without X11
+# - FreeBSD - https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3559
+# - Linux with musl libc
+#
+# https://gitlab.freedesktop.org/mesa/mesa/issues/966
+.if ${OPSYS} == "Linux" && !empty(GLIBC_VERSION)
+PKG_SUGGESTED_OPTIONS+=		elf-tls
+.endif
+
+.include "../../mk/bsd.options.mk"
+
+# Gallium drivers requiring LLVM
+PLIST_VARS+=	r600 radeonsi
+
+# Windowing systems
+PLIST_VARS+=	wayland glx
+
+# Misc. features
+PLIST_VARS+=	vdpau
+
+#
+# ELF TLS support
+#
+.if empty(PKG_OPTIONS:Melf-tls)
+BUILDLINK_TRANSFORM+=	rm:-DUSE_ELF_TLS
+.endif
+
+#
+# LLVM support
+#
+.if !empty(PKG_OPTIONS:Mllvm)
+MESON_ARGS+=		-Dllvm=enabled
+.  include "../../devel/libelf/buildlink3.mk"
+.  include "../../wip/libLLVM/buildlink3.mk"
+
+.  if ${OPSYS} != "Darwin" && ${OPSYS} != "Cygwin"
+# This is the latest libdrm requirement for amdgpu.
+BUILDLINK_API_DEPENDS.libdrm+=	libdrm>=2.4.107
+
+PLIST.r600=		yes
+GALLIUM_DRIVERS+=	r600
+PLIST.radeonsi=		yes
+GALLIUM_DRIVERS+=	radeonsi
+.  endif
+.else
+MESON_ARGS+=		-Dllvm=disabled
+.endif
+
+#
+# Vulkan support - experimental
+#
+.if !empty(PKG_OPTIONS:Mvulkan)
+MESON_ARGS+=		-Dvulkan-drivers="auto"
+.else
+MESON_ARGS+=		-Dvulkan-drivers=""
+.endif
+
+#
+# X11 support
+#
+.if !empty(PKG_OPTIONS:Mx11)
+MESA_PLATFORMS+=	x11
+PLIST.glx=		yes
+.  if ${MESALIB_SUPPORTS_DRI} == "yes"
+MESON_ARGS+=		-Dglx=dri
+.    include "../../multimedia/libvdpau/available.mk"
+.    if ${VDPAU_AVAILABLE} == "yes"
+MESON_ARGS+=		-Dgallium-vdpau=true
+PLIST.vdpau=		yes
+.      include "../../multimedia/libvdpau/buildlink3.mk"
+.    else
+MESON_ARGS+=		-Dgallium-vdpau=false
+.    endif
+.  endif
+.  include "../../x11/libX11/buildlink3.mk"
+.  include "../../x11/libXdamage/buildlink3.mk"
+.  include "../../x11/libXext/buildlink3.mk"
+.  include "../../x11/libXfixes/buildlink3.mk"
+.  include "../../x11/libXrandr/buildlink3.mk"
+.  include "../../x11/libXxf86vm/buildlink3.mk"
+.  include "../../x11/libxcb/buildlink3.mk"
+.  include "../../x11/libxshmfence/buildlink3.mk"
+.  include "../../x11/xcb-proto/buildlink3.mk"
+.  include "../../x11/xorgproto/buildlink3.mk"
+.else
+MESON_ARGS+=		-Dglx=disabled
+MESON_ARGS+=		-Dgallium-vdpau=false
+.endif
+
+#
+# Wayland support
+#
+.if !empty(PKG_OPTIONS:Mwayland)
+MESA_PLATFORMS+=	wayland
+PLIST.wayland=		yes
+.  include "../../devel/wayland/buildlink3.mk"
+.  include "../../devel/wayland-protocols/buildlink3.mk"
+.endif
diff --git a/MesaLib/patches/patch-include_c11_threads__posix.h b/MesaLib/patches/patch-include_c11_threads__posix.h
new file mode 100644
index 0000000000..9b61b6ce05
--- /dev/null
+++ b/MesaLib/patches/patch-include_c11_threads__posix.h
@@ -0,0 +1,17 @@
+$NetBSD: patch-include_c11_threads__posix.h,v 1.1 2019/11/29 10:34:13 jperkin Exp $
+
+Use compat version of timespec_get regardless on Darwin.  The
+meson configure test completes successfully even with clearly
+bogus values.
+
+--- include/c11/threads_posix.h.orig	2019-11-22 00:06:57.000000000 +0000
++++ include/c11/threads_posix.h
+@@ -382,7 +382,7 @@ tss_set(tss_t key, void *val)
+ 
+ /*-------------------- 7.25.7 Time functions --------------------*/
+ // 7.25.6.1
+-#ifndef HAVE_TIMESPEC_GET
++#if !defined(HAVE_TIMESPEC_GET) || defined(__APPLE__)
+ static inline int
+ timespec_get(struct timespec *ts, int base)
+ {
diff --git a/MesaLib/patches/patch-src_compiler_builtin__type__macros.h b/MesaLib/patches/patch-src_compiler_builtin__type__macros.h
new file mode 100644
index 0000000000..b040332f3a
--- /dev/null
+++ b/MesaLib/patches/patch-src_compiler_builtin__type__macros.h
@@ -0,0 +1,25 @@
+$NetBSD: patch-src_compiler_builtin__type__macros.h,v 1.2 2019/08/31 17:56:09 nia Exp $
+
+Workaround netbsd 8 headers.
+
+--- src/compiler/builtin_type_macros.h.orig	2018-09-07 21:18:07.000000000 +0000
++++ src/compiler/builtin_type_macros.h
+@@ -28,6 +28,18 @@
+  * language version or extension might provide them.
+  */
+ 
++#ifdef __NetBSD__ /* XXX https://mail-index.netbsd.org/tech-userlevel/2018/09/08/msg011381.html */
++#undef uint8_t
++#undef uint16_t
++#undef uint32_t
++#undef uint64_t
++#undef int8_t
++#undef int16_t
++#undef int32_t
++#undef int64_t
++#endif
++
++
+ DECL_TYPE(error,  GL_INVALID_ENUM, GLSL_TYPE_ERROR, 0, 0)
+ DECL_TYPE(void,   GL_INVALID_ENUM, GLSL_TYPE_VOID,  0, 0)
+ 
diff --git a/MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c
new file mode 100644
index 0000000000..d1a4cb405e
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c
@@ -0,0 +1,23 @@
+$NetBSD: patch-src_egl_drivers_dri2_platform__drm.c,v 1.5 2020/01/21 14:41:26 nia Exp $
+
+Revert: https://cgit.freedesktop.org/mesa/mesa/commit/?id=621b0fa8922ade0a8122b868177308e65e6d3595
+
+This causes symbol referencing errors:
+"ld: /usr/pkg/lib/libEGL.so.1: undefined reference to `gbm_format_get_name'"
+
+TODO: Talk to upstream and investigate why.
+
+--- src/egl/drivers/dri2/platform_drm.c.orig	2019-12-04 22:10:12.000000000 +0000
++++ src/egl/drivers/dri2/platform_drm.c
+@@ -649,9 +649,8 @@ drm_add_configs_for_visuals(_EGLDriver *
+ 
+    for (unsigned i = 0; i < ARRAY_SIZE(format_count); i++) {
+       if (!format_count[i]) {
+-         struct gbm_format_name_desc desc;
+-         _eglLog(_EGL_DEBUG, "No DRI config supports native format %s",
+-                 gbm_format_get_name(visuals[i].gbm_format, &desc));
++         _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x",
++                 visuals[i].gbm_format);
+       }
+    }
+ 
diff --git a/MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c
new file mode 100644
index 0000000000..741826af67
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c
@@ -0,0 +1,63 @@
+$NetBSD$
+
+Provide compat strndup for older Darwin.
+
+* From FreeBSD ports 18.0.0:
+work-around for https://bugs.freedesktop.org/show_bug.cgi?id=100627
+
+Mon Apr 10 19:14:48 2017 UTC
+DRI3 remains enabled at compile time, but it is now disabled at
+runtime for stock FreeBSD.  Set LIBGL_DRI3_ENABLE in the
+environment to enable DRI3.
+This change was made to work around a problem in libEGL,
+which fails to fall back to using DRI2 when run on a system
+without DRI3 support.
+
+* Added logging statement to note dri3 initialization being invoked.
+
+--- src/egl/drivers/dri2/platform_x11.c.orig	2021-07-14 20:04:46.732922600 +0000
++++ src/egl/drivers/dri2/platform_x11.c
+@@ -628,6 +628,23 @@ dri2_x11_local_authenticate(struct dri2_
+    return EGL_TRUE;
+ }
+ 
++#if (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
++static char *
++strndup(const char *s, int length)
++{
++   char *d;
++
++   d = malloc(length + 1);
++   if (d == NULL)
++      return NULL;
++
++   memcpy(d, s, length);
++   d[length] = '\0';
++
++   return d;
++}
++#endif
++
+ static EGLBoolean
+ dri2_x11_connect(struct dri2_egl_display *dri2_dpy)
+ {
+@@ -1539,9 +1556,17 @@ dri2_initialize_x11(_EGLDisplay *disp)
+       return dri2_initialize_x11_swrast(disp);
+ 
+ #ifdef HAVE_DRI3
+-   if (!env_var_as_boolean("LIBGL_DRI3_DISABLE", false))
+-      if (dri2_initialize_x11_dri3(disp))
++
++#if ((defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !defined(__DRM_NEXT__)) || defined(__DragonFly__) || defined(__NetBSD__)
++   if (env_var_as_boolean("LIBGL_DRI3_ENABLE", false))
++#endif
++   if (!env_var_as_boolean("LIBGL_DRI3_DISABLE", false)) {
++      _eglLog(_EGL_INFO, "platform_x11.c: calling dri2_initialize_x11_dri3\n");
++      if (dri2_initialize_x11_dri3(disp)) {
++         _eglLog(_EGL_INFO, "platform_x11.c: initialized by dri2_initialize_x11_dri3\n");
+          return EGL_TRUE;
++      }
++   }
+ #endif
+ 
+    if (!env_var_as_boolean("LIBGL_DRI2_DISABLE", false))
diff --git a/MesaLib/patches/patch-src_egl_main_eglglobals.c b/MesaLib/patches/patch-src_egl_main_eglglobals.c
new file mode 100644
index 0000000000..94c40c0877
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_main_eglglobals.c
@@ -0,0 +1,53 @@
+$NetBSD: patch-src_egl_main_eglglobals.c,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+atexit() is not a good idea in shared libraries.
+
+FreeBSD reported atexit bug for 10.6:
+https://bugs.freedesktop.org/show_bug.cgi?id=91869
+
+--- src/egl/main/eglglobals.c.orig	2018-01-18 21:30:28.000000000 +0000
++++ src/egl/main/eglglobals.c
+@@ -85,11 +85,22 @@ struct _egl_global _eglGlobal =
+    .debugTypesEnabled = _EGL_DEBUG_BIT_CRITICAL | _EGL_DEBUG_BIT_ERROR,
+ };
+ 
++#if defined(HAVE_NOATEXIT)
++static EGLBoolean registered = EGL_FALSE;
+ 
++static void __attribute__((__destructor__))
++#else
+ static void
++#endif
+ _eglAtExit(void)
+ {
+    EGLint i;
++
++#if defined(HAVE_NOATEXIT)
++   if (!registered)
++      return;
++#endif
++
+    for (i = _eglGlobal.NumAtExitCalls - 1; i >= 0; i--)
+       _eglGlobal.AtExitCalls[i]();
+ }
+@@ -99,14 +110,20 @@ void
+ _eglAddAtExitCall(void (*func)(void))
+ {
+    if (func) {
++#if !defined(HAVE_NOATEXIT)
+       static EGLBoolean registered = EGL_FALSE;
++#endif
+ 
+       mtx_lock(_eglGlobal.Mutex);
+ 
++#if defined(HAVE_NOATEXIT)
++      registered = EGL_TRUE;
++#else
+       if (!registered) {
+          atexit(_eglAtExit);
+          registered = EGL_TRUE;
+       }
++#endif
+ 
+       assert(_eglGlobal.NumAtExitCalls < ARRAY_SIZE(_eglGlobal.AtExitCalls));
+       _eglGlobal.AtExitCalls[_eglGlobal.NumAtExitCalls++] = func;
diff --git a/MesaLib/patches/patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.c b/MesaLib/patches/patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.c
new file mode 100644
index 0000000000..7aba3f6a5c
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.c
@@ -0,0 +1,127 @@
+$NetBSD: patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+* From FreeBSD ports / DragonFly dports graphics/mesa-dri
+
+Revert the following commit.
+
+FreeBSD and DragonFly don't have the required render nodes.
+
+-------
+
+From 69a1b9959e59653da262185c4e2cf57d24939b19 Mon Sep 17 00:00:00 2001
+Date: Mon, 29 Jun 2015 12:36:45 +0100
+Subject: pipe-loader: drop support for non-render node devices
+
+Render nodes have been around for quite some time. Removing support via
+the master/primary node allows us to clean up the conditional
+compilation and simplify the build greatly.
+
+For example currently we the pipe-loader, which explicitly links against
+xcb and friends (for X auth) if found at compile-time. That
+would cause problems as one will be forced to use X/xcb, even if it's a
+headless system that is used for opencl.
+
+v2: Clarify the linking topic in the commit message.
+
+* Extended for NetBSD.
+
+--- src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c.orig	2018-12-11 21:13:57.000000000 +0000
++++ src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+@@ -229,6 +229,16 @@ pipe_loader_drm_probe_fd(struct pipe_loa
+    return ret;
+ }
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
++static int
++open_drm_minor(int minor)
++{
++   char path[PATH_MAX];
++   snprintf(path, sizeof(path), DRM_DEV_NAME, DRM_DIR_NAME, minor);
++   return open(path, O_RDWR, 0);
++}
++#endif
++
+ static int
+ open_drm_render_node_minor(int minor)
+ {
+@@ -241,7 +251,19 @@ open_drm_render_node_minor(int minor)
+ int
+ pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev)
+ {
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
++   int i, k, fd, num_render_node_devs;
++   int j = 0;
++
++   struct {
++      unsigned vendor_id;
++      unsigned chip_id;
++   } render_node_devs[DRM_RENDER_NODE_MAX_NODES];
++
++   /* Look for render nodes first */
++#else
+    int i, j, fd;
++#endif
+ 
+    for (i = DRM_RENDER_NODE_MIN_MINOR, j = 0;
+         i <= DRM_RENDER_NODE_MAX_MINOR; i++) {
+@@ -256,6 +278,11 @@ pipe_loader_drm_probe(struct pipe_loader
+          continue;
+       }
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
++      render_node_devs[j].vendor_id = dev->u.pci.vendor_id;
++      render_node_devs[j].chip_id = dev->u.pci.chip_id;
++
++#endif
+       if (j < ndev) {
+          devs[j] = dev;
+       } else {
+@@ -265,6 +292,48 @@ pipe_loader_drm_probe(struct pipe_loader
+       j++;
+    }
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__NetBSD__)
++   num_render_node_devs = j;
++
++   /* Next look for drm devices. */
++   for (i = 0; i < DRM_MAX_MINOR; i++) {
++      struct pipe_loader_device *dev;
++      boolean duplicate = FALSE;
++      fd = open_drm_minor(i);
++      if (fd < 0)
++         continue;
++
++      if (!pipe_loader_drm_probe_fd(&dev, fd)) {
++         close(fd);
++         continue;
++      }
++
++      /* Check to make sure we aren't already accessing this device via
++       * render nodes.
++       */
++      for (k = 0; k < num_render_node_devs; k++) {
++         if (dev->u.pci.vendor_id == render_node_devs[k].vendor_id &&
++             dev->u.pci.chip_id == render_node_devs[k].chip_id) {
++            close(fd);
++            dev->ops->release(&dev);
++            duplicate = TRUE;
++            break;
++         }
++      }
++
++      if (duplicate)
++         continue;
++
++      if (j < ndev) {
++         devs[j] = dev;
++      } else {
++         dev->ops->release(&dev);
++      }
++
++      j++;
++   }
++
++#endif
+    return j;
+ }
+ 
diff --git a/MesaLib/patches/patch-src_gallium_auxiliary_rbug_rbug__texture.c b/MesaLib/patches/patch-src_gallium_auxiliary_rbug_rbug__texture.c
new file mode 100644
index 0000000000..09dbd3bf8d
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_auxiliary_rbug_rbug__texture.c
@@ -0,0 +1,14 @@
+$NetBSD: patch-src_gallium_auxiliary_rbug_rbug__texture.c,v 1.1 2019/10/29 20:20:04 nia Exp $
+
+Needs alloca definition.
+
+--- src/gallium/auxiliary/rbug/rbug_texture.c.orig	2019-10-24 16:13:03.000000000 +0000
++++ src/gallium/auxiliary/rbug/rbug_texture.c
+@@ -36,6 +36,7 @@
+ 
+ #include "rbug_internal.h"
+ #include "rbug_texture.h"
++#include "c99_alloca.h"
+ 
+ int rbug_send_texture_list(struct rbug_connection *__con,
+                            uint32_t *__serial)
diff --git a/MesaLib/patches/patch-src_gallium_drivers_llvmpipe_lp__memory.c b/MesaLib/patches/patch-src_gallium_drivers_llvmpipe_lp__memory.c
new file mode 100644
index 0000000000..9a38fd348c
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_llvmpipe_lp__memory.c
@@ -0,0 +1,23 @@
+$NetBSD: patch-src_gallium_drivers_llvmpipe_lp__memory.c,v 1.1 2020/03/08 10:35:03 tnn Exp $
+
+Force the symbol into data rather than bss to work around linking
+problem on OS X.
+
+Undefined symbols for architecture x86_64:
+  "_lp_dummy_tile", referenced from:
+      _lp_rast_create in libllvmpipe.a(lp_rast.c.o)
+      _llvmpipe_launch_grid in libllvmpipe.a(lp_state_cs.c.o)
+      _lp_setup_set_fragment_sampler_views in libllvmpipe.a(lp_setup.c.o)
+
+--- src/gallium/drivers/llvmpipe/lp_memory.c.orig	2020-03-05 21:34:31.000000000 +0000
++++ src/gallium/drivers/llvmpipe/lp_memory.c
+@@ -32,5 +32,9 @@
+ /* A single dummy tile used in a couple of out-of-memory situations. 
+  */
+ PIPE_ALIGN_VAR(LP_MIN_VECTOR_ALIGN)
++#ifdef __APPLE__
++uint8_t lp_dummy_tile[TILE_SIZE * TILE_SIZE * 4] = { 0 };
++#else
+ uint8_t lp_dummy_tile[TILE_SIZE * TILE_SIZE * 4];
++#endif
+ 
diff --git a/MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c
new file mode 100644
index 0000000000..7b310b3922
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_gallium_drivers_nouveau_nouveau__vp3__video.c,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+Fix build on platforms without close-on-exec.
+
+--- src/gallium/drivers/nouveau/nouveau_vp3_video.c.orig	2017-02-13 11:55:49.000000000 +0000
++++ src/gallium/drivers/nouveau/nouveau_vp3_video.c
+@@ -294,7 +294,11 @@ nouveau_vp3_load_firmware(struct nouveau
+    if (nouveau_bo_map(dec->fw_bo, NOUVEAU_BO_WR, dec->client))
+       return 1;
+ 
++#ifdef O_CLOEXEC
+    fd = open(path, O_RDONLY | O_CLOEXEC);
++#else
++   fd = open(path, O_RDONLY);
++#endif
+    if (fd < 0) {
+       fprintf(stderr, "opening firmware file %s failed: %m\n", path);
+       return 1;
diff --git a/MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c
new file mode 100644
index 0000000000..ae714d1470
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_nouveau_nv50_nv84__video.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_gallium_drivers_nouveau_nv50_nv84__video.c,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+Fix build on platforms without close-on-exec.
+
+--- src/gallium/drivers/nouveau/nv50/nv84_video.c.orig	2015-03-21 00:51:18.000000000 +0000
++++ src/gallium/drivers/nouveau/nv50/nv84_video.c
+@@ -34,7 +34,11 @@
+ static int
+ nv84_copy_firmware(const char *path, void *dest, ssize_t len)
+ {
++#ifdef O_CLOEXEC
+    int fd = open(path, O_RDONLY | O_CLOEXEC);
++#else
++   int fd = open(path, O_RDONLY);
++#endif
+    ssize_t r;
+    if (fd < 0) {
+       fprintf(stderr, "opening firmware file %s failed: %m\n", path);
diff --git a/MesaLib/patches/patch-src_gallium_drivers_vc4_vc4__bufmgr.c b/MesaLib/patches/patch-src_gallium_drivers_vc4_vc4__bufmgr.c
new file mode 100644
index 0000000000..60fd41f962
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_vc4_vc4__bufmgr.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_gallium_drivers_vc4_vc4__bufmgr.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+Patch from FreeBSD ports graphics/mesa-dri 17.1.0
+
+# define ETIME as ETIMEOUT same as in intel driver
+
+--- src/gallium/drivers/vc4/vc4_bufmgr.c.orig	2017-05-25 07:13:13.000000000 +0000
++++ src/gallium/drivers/vc4/vc4_bufmgr.c
+@@ -27,6 +27,9 @@
+ #include <fcntl.h>
+ #include <xf86drm.h>
+ #include <xf86drmMode.h>
++#ifndef ETIME
++#define ETIME ETIMEDOUT
++#endif
+ 
+ #include "util/u_hash_table.h"
+ #include "util/u_memory.h"
diff --git a/MesaLib/patches/patch-src_gallium_frontends_clover_llvm_invocation.cpp b/MesaLib/patches/patch-src_gallium_frontends_clover_llvm_invocation.cpp
new file mode 100644
index 0000000000..09136b9014
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_frontends_clover_llvm_invocation.cpp
@@ -0,0 +1,41 @@
+$NetBSD$
+
+Patch from FreeBSD ports graphics/mesa-dri 17.1.0
+
+# fix errors like the following
+#
+# llvm/invocation.cpp:(.text+0x1275): undefined reference to `std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::c_str()
+ const'
+# /usr/bin/ld: ../../../../src/gallium/state_trackers/clover/.libs/libclover.a(libclllvm_la-invocation.o): relocation R_X86_64_PC32 against `_ZNKSt3__112bas
+ic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5c_strEv' can not be used when making a shared object; recompile with -fPIC
+# /usr/bin/ld: final link failed: Bad value
+#
+
+--- src/gallium/frontends/clover/llvm/invocation.cpp.orig	2021-07-14 20:04:53.702990300 +0000
++++ src/gallium/frontends/clover/llvm/invocation.cpp
+@@ -212,6 +212,10 @@ namespace {
+       return get_lang_standard_from_version(device_version);
+    }
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++   const char* cstr(const std::string& str) { return str.c_str(); }
++#endif
++
+    std::unique_ptr<clang::CompilerInstance>
+    create_compiler_instance(const device &dev, const std::string& ir_target,
+                             const std::vector<std::string> &opts,
+@@ -224,9 +228,13 @@ namespace {
+       // Parse the compiler options.  A file name should be present at the end
+       // and must have the .cl extension in order for the CompilerInvocation
+       // class to recognize it as an OpenCL source file.
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++      std::vector<const char *> copts(opts.size());
++      std::transform(opts.begin(), opts.end(), copts.begin(), cstr);
++#else
+       const std::vector<const char *> copts =
+          map(std::mem_fn(&std::string::c_str), opts);
+-
++#endif
+       const target &target = ir_target;
+       const cl_version device_clc_version = dev.device_clc_version();
+ 
diff --git a/MesaLib/patches/patch-src_gallium_frontends_clover_util_range.hpp b/MesaLib/patches/patch-src_gallium_frontends_clover_util_range.hpp
new file mode 100644
index 0000000000..57522e575a
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_frontends_clover_util_range.hpp
@@ -0,0 +1,40 @@
+$NetBSD$
+
+From FreeBSD ports for mesa 17.1.10:
+
+From b95533b981af9a6687b41418e7cc2a5652fc2bdb Mon Sep 17 00:00:00 2001
+Date: Fri, 7 Mar 2014 15:16:08 +0100
+Subject: [PATCH 3/3] Work around for clang 3.4 which fails to build Clover
+
+See:
+  https://bugs.freedesktop.org/show_bug.cgi?id=74098#c3
+
+--- src/gallium/frontends/clover/util/range.hpp.orig	2021-07-14 20:04:53.703990500 +0000
++++ src/gallium/frontends/clover/util/range.hpp
+@@ -362,6 +362,14 @@ namespace clover {
+       return { i, i + n };
+    }
+ 
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++   namespace detail {
++      template<typename T>
++      using fixup_function_type =
++         typename std::conditional<std::is_function<T>::value, T &, T>::type;
++   }
++#endif
++
+    ///
+    /// Create a range by transforming the contents of a number of
+    /// source ranges \a rs element-wise using a provided functor \a f.
+@@ -369,7 +377,11 @@ namespace clover {
+    /// \sa adaptor_range.
+    ///
+    template<typename F, typename... Rs>
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++   adaptor_range<detail::fixup_function_type<F>, Rs...>
++#else
+    adaptor_range<F, Rs...>
++#endif
+    map(F &&f, Rs &&... rs) {
+       return { std::forward<F>(f), std::forward<Rs>(rs)... };
+    }
diff --git a/MesaLib/patches/patch-src_glx_dri__common.c b/MesaLib/patches/patch-src_glx_dri__common.c
new file mode 100644
index 0000000000..70264bd596
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_dri__common.c
@@ -0,0 +1,41 @@
+$NetBSD$
+
+atexit() is not a good idea in shared libraries.
+
+FreeBSD reported atexit bug for 10.6:
+https://bugs.freedesktop.org/show_bug.cgi?id=91869
+
+--- src/glx/dri_common.c.orig	2021-07-14 20:04:55.743010300 +0000
++++ src/glx/dri_common.c
+@@ -690,9 +690,19 @@ static struct driver_config_entry *drive
+ /* Called as an atexit function. Otherwise, this would have to be called with
+  * driver_config_mutex locked.
+  */
++#if defined(HAVE_NOATEXIT)
++static Bool e_next_ever_null = False;
++
++static void __attribute__((__destructor__))
++#else
+ static void
++#endif
+ clear_driver_config_cache()
+ {
++#if defined(HAVE_NOATEXIT)
++   if (!e_next_ever_null)
++      return;
++#endif
+    while (driver_config_cache) {
+       struct driver_config_entry *e = driver_config_cache;
+       driver_config_cache = e->next;
+@@ -777,7 +787,11 @@ glXGetDriverConfig(const char *driverNam
+    driver_config_cache = e;
+ 
+    if (!e->next)
++#if defined(HAVE_NOATEXIT)
++      e_next_ever_null = True;
++#else
+       atexit(clear_driver_config_cache);
++#endif
+ 
+ out:
+    pthread_mutex_unlock(&driver_config_mutex);
diff --git a/MesaLib/patches/patch-src_glx_dri__common.h b/MesaLib/patches/patch-src_glx_dri__common.h
new file mode 100644
index 0000000000..6cb9109827
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_dri__common.h
@@ -0,0 +1,17 @@
+$NetBSD: patch-src_glx_dri__common.h,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+Fix error on OSX.
+
+--- src/glx/dri_common.h.orig	2019-01-17 11:26:23.000000000 +0000
++++ src/glx/dri_common.h
+@@ -55,8 +55,10 @@ extern struct glx_config *driConvertConf
+ 
+ extern void driDestroyConfigs(const __DRIconfig **configs);
+ 
++#if !defined(GLX_USE_APPLEGL)
+ extern __GLXDRIdrawable *
+ driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable);
++#endif
+ 
+ extern void
+ driReleaseDrawables(struct glx_context *gc);
diff --git a/MesaLib/patches/patch-src_glx_glxclient.h b/MesaLib/patches/patch-src_glx_glxclient.h
new file mode 100644
index 0000000000..a7b3b90804
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_glxclient.h
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_glx_glxclient.h,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/glx/glxclient.h.orig	2017-02-13 11:55:49.000000000 +0000
++++ src/glx/glxclient.h
+@@ -661,7 +661,11 @@ extern void __glXSetCurrentContext(struc
+ extern __thread void *__glX_tls_Context
+    __attribute__ ((tls_model("initial-exec")));
+ 
++#if defined(__NetBSD__)
++#  define __glXGetCurrentContext() (likely(__glX_tls_Context) ? __glX_tls_Context : (void*)&dummyContext)
++#else
+ #  define __glXGetCurrentContext() __glX_tls_Context
++#endif
+ 
+ # else
+ 
diff --git a/MesaLib/patches/patch-src_glx_glxcurrent.c b/MesaLib/patches/patch-src_glx_glxcurrent.c
new file mode 100644
index 0000000000..294b35ae2b
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_glxcurrent.c
@@ -0,0 +1,42 @@
+$NetBSD: patch-src_glx_glxcurrent.c,v 1.4 2020/02/19 21:03:41 tnn Exp $
+
+Interim fix for toolchain/50277.
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/glx/glxcurrent.c.orig	2019-12-04 22:10:12.000000000 +0000
++++ src/glx/glxcurrent.c
+@@ -40,6 +40,20 @@
+ #include "glx_error.h"
+ 
+ /*
++ * MASSIVE KLUDGE!
++ * We need these to not be extern in libGL.so because of
++ * PR toolchain/50277
++ */
++#if defined(USE_ELF_TLS) && defined(__NetBSD__)
++#define u_current_table _glapi_tls_Dispatch
++#define u_current_context _glapi_tls_Context
++_X_EXPORT __thread struct _glapi_table *u_current_table
++    __attribute__((tls_model("initial-exec"))) = NULL;
++_X_EXPORT __thread void * u_current_context
++    __attribute__((tls_model("initial-exec")));
++#endif
++
++/*
+ ** We setup some dummy structures here so that the API can be used
+ ** even if no context is current.
+ */
+@@ -77,7 +91,11 @@ _X_HIDDEN pthread_mutex_t __glXmutex = P
+  * \c __glXGetCurrentContext can be implemented as trivial macro.
+  */
+ __thread void *__glX_tls_Context __attribute__ ((tls_model("initial-exec")))
++#if defined(__NetBSD__)
++   = NULL; /* non-zero initializers not supported with dlopen */
++#else
+    = &dummyContext;
++#endif
+ 
+ _X_HIDDEN void
+ __glXSetCurrentContext(struct glx_context * c)
diff --git a/MesaLib/patches/patch-src_glx_glxext.c b/MesaLib/patches/patch-src_glx_glxext.c
new file mode 100644
index 0000000000..59990a9340
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_glxext.c
@@ -0,0 +1,39 @@
+$NetBSD$
+
+* Patch from FreeBSD ports graphics/mesa-dri 18.0.0
+
+# work-around for https://bugs.freedesktop.org/show_bug.cgi?id=100627
+
+* Extended to DragonFly and NetBSD.  Other OSes might need this as well.
+
+* Added logging statements to note dri3 initialization being invoked.
+
+--- src/glx/glxext.c.orig	2021-07-14 20:04:55.750010300 +0000
++++ src/glx/glxext.c
+@@ -819,7 +819,11 @@ AllocAndFetchScreenConfigs(Display * dpy
+ #if defined(GLX_USE_DRM)
+ #if defined(HAVE_DRI3)
+       if (priv->dri3Display)
++         InfoMessageF("glxext.c: AllocAndFetchScreenConfigs: priv->dri3Display\n");
++      if (priv->dri3Display)
+          psc = (*priv->dri3Display->createScreen) (i, priv);
++      if (psc != NULL && priv->dri3Display)
++         InfoMessageF("glxext.c: AllocAndFetchScreenConfigs: psc set by priv->dri3Display\n");
+ #endif /* HAVE_DRI3 */
+       if (psc == NULL && priv->dri2Display)
+ 	 psc = (*priv->dri2Display->createScreen) (i, priv);
+@@ -925,8 +929,13 @@ __glXInitialize(Display * dpy)
+ #if defined(GLX_USE_DRM)
+    if (glx_direct && glx_accel) {
+ #if defined(HAVE_DRI3)
+-      if (!env_var_as_boolean("LIBGL_DRI3_DISABLE", false))
++#if ((defined(__FreeBSD__) || defined(__FreeBSD_kernel__)) && !defined(__DRM_NEXT__)) || defined(__DragonFly__) || defined(__NetBSD__)
++      if (env_var_as_boolean("LIBGL_DRI3_ENABLE", false))
++#endif
++      if (!env_var_as_boolean("LIBGL_DRI3_DISABLE", false)) {
++         InfoMessageF("glxext.c: __glxInitialize: dpyPriv->dri3Display = dri3_create_display\n");
+          dpyPriv->dri3Display = dri3_create_display(dpy);
++      }
+ #endif /* HAVE_DRI3 */
+       if (!env_var_as_boolean("LIBGL_DRI2_DISABLE", false))
+          dpyPriv->dri2Display = dri2CreateDisplay(dpy);
diff --git a/MesaLib/patches/patch-src_intel_compiler_brw__fs__bank__conflicts.cpp b/MesaLib/patches/patch-src_intel_compiler_brw__fs__bank__conflicts.cpp
new file mode 100644
index 0000000000..e51fe2a1f3
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_compiler_brw__fs__bank__conflicts.cpp
@@ -0,0 +1,23 @@
+$NetBSD: patch-src_intel_compiler_brw__fs__bank__conflicts.cpp,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225415
+FreeBSD Bugzilla: Bug 225415 graphics/mesa-dri: update to 18.0.0
+
+compiler/brw_fs_bank_conflicts.cpp:719:25: error: scalar initializer cannot be empty
+      vector_type s_p = {}, s_n = {};
+                        ^~
+compiler/brw_fs_bank_conflicts.cpp:719:35: error: scalar initializer cannot be empty
+      vector_type s_p = {}, s_n = {};
+                                  ^~
+
+--- src/intel/compiler/brw_fs_bank_conflicts.cpp.orig	2018-02-09 02:17:59.000000000 +0000
++++ src/intel/compiler/brw_fs_bank_conflicts.cpp
+@@ -716,7 +716,7 @@ namespace {
+                    const weight_vector_type &conflicts)
+    {
+       const unsigned m = DIV_ROUND_UP(conflicts.size, vector_width);
+-      vector_type s_p = {}, s_n = {};
++      vector_type s_p = {0}, s_n = {0};
+ 
+       for (unsigned r = 0; r < m; r++) {
+          s_p = adds(s_p, mask(bank_mask_p.v[r], conflicts.v[r]));
diff --git a/MesaLib/patches/patch-src_intel_tools_aubinator__error__decode.c b/MesaLib/patches/patch-src_intel_tools_aubinator__error__decode.c
new file mode 100644
index 0000000000..488212746b
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_tools_aubinator__error__decode.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_intel_tools_aubinator__error__decode.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+Patch from FreeBSD ports graphics/mesa-dri 17.1.0
+
+# expose getline in FreeBSD's stdio.h
+#
+
+--- src/intel/tools/aubinator_error_decode.c.orig	2017-05-25 07:13:13.000000000 +0000
++++ src/intel/tools/aubinator_error_decode.c
+@@ -22,6 +22,9 @@
+  *
+  */
+ 
++#ifdef __FreeBSD__
++#define _WITH_GETLINE
++#endif
+ #include <stdbool.h>
+ #include <stdio.h>
+ #include <stdlib.h>
diff --git a/MesaLib/patches/patch-src_mapi_entry__x86-64__tls.h b/MesaLib/patches/patch-src_mapi_entry__x86-64__tls.h
new file mode 100644
index 0000000000..6302e9972c
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_entry__x86-64__tls.h
@@ -0,0 +1,56 @@
+$NetBSD$
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+table_noop_array is only defined for shared-glapi.
+es1api and es2api are not going to be patched for NetBSD.
+
+--- src/mapi/entry_x86-64_tls.h.orig	2021-07-14 20:04:57.805030000 +0000
++++ src/mapi/entry_x86-64_tls.h
+@@ -38,22 +38,34 @@
+ #endif
+ 
+ __asm__(".text\n"
+-        ".balign 32\n"
++        ".balign 64\n"
+         "x86_64_entry_start:");
+ 
+ #define STUB_ASM_ENTRY(func)                             \
+    ".globl " func "\n"                                   \
+    ".type " func ", @function\n"                         \
+-   ".balign 32\n"                                        \
++   ".balign 64\n"                                        \
+    func ":"
+ 
+ #ifndef __ILP32__
+ 
++#if defined(__NetBSD__)
++#define STUB_ASM_CODE(slot)                              \
++   "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t"  \
++   "movq %fs:(%rax), %r11\n\t"                           \
++   "testq %r11, %r11\n\t"                                \
++   "je 1f\n\t"                                           \
++   "jmp *(8 * " slot ")(%r11)\n\t"                       \
++   "1:\n\t"                                              \
++   "callq " ENTRY_CURRENT_TABLE_GET "@PLT\n\t"           \
++   "jmp *(8 * " slot ")(%rax)"
++#else
+ #define STUB_ASM_CODE(slot)                              \
+    ENDBR                                                 \
+    "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t"  \
+    "movq %fs:(%rax), %r11\n\t"                           \
+    "jmp *(8 * " slot ")(%r11)"
++#endif
+ 
+ #else
+ 
+@@ -85,7 +97,7 @@ x86_64_entry_start[] HIDDEN;
+ mapi_func
+ entry_get_public(int slot)
+ {
+-   return (mapi_func) (x86_64_entry_start + slot * 32);
++   return (mapi_func) (x86_64_entry_start + slot * 64);
+ }
+ 
+ void
diff --git a/MesaLib/patches/patch-src_mapi_entry__x86__tls.h b/MesaLib/patches/patch-src_mapi_entry__x86__tls.h
new file mode 100644
index 0000000000..c1aa21045c
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_entry__x86__tls.h
@@ -0,0 +1,53 @@
+$NetBSD$
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/mapi/entry_x86_tls.h.orig	2021-07-14 20:04:57.805030000 +0000
++++ src/mapi/entry_x86_tls.h
+@@ -51,6 +51,25 @@ __asm__("x86_current_tls:\n\t"
+ 	"movl " ENTRY_CURRENT_TABLE "@GOTNTPOFF(%eax), %eax\n\t"
+ 	"ret");
+ 
++#if defined(__NetBSD__)
++__asm__("x86_current_table_helper:\n\t"
++	"call 1f\n\t"
++	"1:\n\t"
++	"popl %eax\n\t"
++	"addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t"
++	"movl " ENTRY_CURRENT_TABLE "@GOTNTPOFF(%eax), %eax\n\t"
++	"movl %gs:(%eax), %eax\n\t"
++	"testl %eax, %eax\n\t"
++	"je 2f\n\t"
++	"ret\n\t"
++	"2:\n\t"
++	"call 3f\n\t"
++	"3:\n\t"
++	"popl %eax\n\t"
++	"addl $_GLOBAL_OFFSET_TABLE_+[.-3b], %eax\n\t"
++	"jmp *" ENTRY_CURRENT_TABLE_GET "@GOT(%eax)");
++#endif
++
+ #ifndef GLX_X86_READONLY_TEXT
+ __asm__(".section wtext, \"awx\", @progbits");
+ #endif /* GLX_X86_READONLY_TEXT */
+@@ -64,6 +83,11 @@ __asm__(".balign 16\n"
+    ".balign 16\n"                \
+    func ":"
+ 
++#if defined(__NetBSD__)
++#define STUB_ASM_CODE(slot)                                 \
++   "call x86_current_table_helper\n\t"                      \
++   "jmp *(4 * " slot ")(%eax)"
++#else
+ #define STUB_ASM_CODE(slot)                                 \
+    ENDBR                                                    \
+    "call 1f\n"                                              \
+@@ -73,6 +97,7 @@ __asm__(".balign 16\n"
+    "movl " ENTRY_CURRENT_TABLE "@GOTNTPOFF(%eax), %eax\n\t" \
+    "movl %gs:(%eax), %eax\n\t"                              \
+    "jmp *(4 * " slot ")(%eax)"
++#endif
+ 
+ #define MAPI_TMP_STUB_ASM_GCC
+ #include "mapi_tmp.h"
diff --git a/MesaLib/patches/patch-src_mapi_u__current.c b/MesaLib/patches/patch-src_mapi_u__current.c
new file mode 100644
index 0000000000..56999822fb
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_u__current.c
@@ -0,0 +1,31 @@
+$NetBSD$
+
+NetBSD only supports zero-initialized initial-exec tls variables in conjuction
+with dlopen(3) at the moment.
+
+--- src/mapi/u_current.c.orig	2021-07-14 20:04:57.831030400 +0000
++++ src/mapi/u_current.c
+@@ -107,7 +107,11 @@ __declspec(thread) void *u_current_conte
+ #else
+ __thread struct _glapi_table *u_current_table
+     __attribute__((tls_model("initial-exec")))
++#if defined(__NetBSD__)
++    = NULL; /* non-zero initializers not supported with dlopen */
++#else
+     = (struct _glapi_table *) table_noop_array;
++#endif
+ 
+ __thread void *u_current_context
+     __attribute__((tls_model("initial-exec")));
+@@ -259,7 +263,11 @@ struct _glapi_table *
+ u_current_get_table_internal(void)
+ {
+ #if defined(USE_ELF_TLS)
++#  if defined(__NetBSD__)
++    return (likely(u_current_table) ? u_current_table : (struct _glapi_table *) table_noop_array);
++#  else
+    return u_current_table;
++#  endif
+ #else
+    if (ThreadSafe)
+       return (struct _glapi_table *) tss_get(u_current_table_tsd);
diff --git a/MesaLib/patches/patch-src_mesa_main_extensions.c b/MesaLib/patches/patch-src_mesa_main_extensions.c
new file mode 100644
index 0000000000..8d37e38e72
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_extensions.c
@@ -0,0 +1,31 @@
+$NetBSD$
+
+atexit() is not a good idea in shared libraries.
+
+FreeBSD reported atexit bug for 10.6:
+https://bugs.freedesktop.org/show_bug.cgi?id=91869
+
+--- src/mesa/main/extensions.c.orig	2021-07-14 20:04:58.316035000 +0000
++++ src/mesa/main/extensions.c
+@@ -213,7 +213,11 @@ set_extension(struct gl_extensions *ext,
+  * This string is allocated early during the first context creation by
+  * _mesa_one_time_init_extension_overrides.
+  */
++#if defined(HAVE_NOATEXIT)
++static void __attribute__((__destructor__))
++#else
+ static void
++#endif
+ free_unknown_extensions_strings(void)
+ {
+    free(unrecognized_extensions.env);
+@@ -304,7 +308,9 @@ _mesa_one_time_init_extension_overrides(
+       free(env);
+    } else {
+       unrecognized_extensions.env = env;
++#if !defined(HAVE_NOATEXIT)
+       atexit(free_unknown_extensions_strings);
++#endif
+    }
+ }
+ 
diff --git a/MesaLib/patches/patch-src_mesa_main_shader__query.cpp b/MesaLib/patches/patch-src_mesa_main_shader__query.cpp
new file mode 100644
index 0000000000..081728ec92
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_shader__query.cpp
@@ -0,0 +1,58 @@
+$NetBSD: patch-src_mesa_main_shader__query.cpp,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+https://bugs.freedesktop.org/show_bug.cgi?id=66346
+
+From c4a1fec68d2508ff0c4fc2831465aca8c4ca783a Mon Sep 17 00:00:00 2001
+From: Julien Isorce <j.isorce%samsung.com@localhost>
+Date: Wed, 22 Apr 2015 23:04:42 +0100
+Subject: [PATCH 1/2] shader_query: convert GLhandleARB to uintptr_t before
+ troncating to GLuint
+
+Fixes compiler error on OSX as GLhandleARB is defined as void* if __APPLE__.
+
+https://bugs.freedesktop.org/show_bug.cgi?id=66346
+---
+ src/mesa/main/shader_query.cpp | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+--- src/mesa/main/shader_query.cpp.orig	2016-11-10 22:05:17.000000000 +0000
++++ src/mesa/main/shader_query.cpp
+@@ -70,7 +70,12 @@ _mesa_BindAttribLocation(GLuint program,
+    GET_CURRENT_CONTEXT(ctx);
+ 
+    struct gl_shader_program *const shProg =
++#if defined(__APPLE__)
++      _mesa_lookup_shader_program_err(ctx, (GLuint)(uintptr_t)program, "glBindAttribLocation");
++#else
+       _mesa_lookup_shader_program_err(ctx, program, "glBindAttribLocation");
++#endif
++
+    if (!shProg)
+       return;
+ 
+@@ -114,7 +119,12 @@ _mesa_GetActiveAttrib(GLuint program, GL
+       return;
+    }
+ 
++#if defined(__APPLE__)
++   shProg = _mesa_lookup_shader_program_err(ctx, (GLuint)(uintptr_t)program, "glGetActiveAttrib");
++#else
+    shProg = _mesa_lookup_shader_program_err(ctx, program, "glGetActiveAttrib");
++#endif
++
+    if (!shProg)
+       return;
+ 
+@@ -159,7 +169,12 @@ _mesa_GetAttribLocation(GLuint program,
+ {
+    GET_CURRENT_CONTEXT(ctx);
+    struct gl_shader_program *const shProg =
++
++#if defined(__APPLE__)
++      _mesa_lookup_shader_program_err(ctx, (GLuint)(uintptr_t)program, "glGetAttribLocation");
++#else
+       _mesa_lookup_shader_program_err(ctx, program, "glGetAttribLocation");
++#endif
+ 
+    if (!shProg) {
+       return -1;
diff --git a/MesaLib/patches/patch-src_mesa_x86_common__x86.c b/MesaLib/patches/patch-src_mesa_x86_common__x86.c
new file mode 100644
index 0000000000..8858cac199
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_x86_common__x86.c
@@ -0,0 +1,24 @@
+$NetBSD: patch-src_mesa_x86_common__x86.c,v 1.3 2019/08/21 13:35:28 nia Exp $
+
+DragonFly support.
+
+--- src/mesa/x86/common_x86.c.orig	2017-05-10 14:13:58.000000000 +0000
++++ src/mesa/x86/common_x86.c
+@@ -35,7 +35,7 @@
+  */
+ 
+ /* XXX these includes should probably go into imports.h or glheader.h */
+-#if defined(USE_SSE_ASM) && defined(__FreeBSD__)
++#if defined(USE_SSE_ASM) && (defined(__FreeBSD__) || defined(__DragonFly__))
+ #include <sys/types.h>
+ #include <sys/sysctl.h>
+ #endif
+@@ -125,7 +125,7 @@ static LONG WINAPI ExceptionFilter(LPEXC
+  */
+ void _mesa_check_os_sse_support( void )
+ {
+-#if defined(__FreeBSD__)
++#if defined(__FreeBSD__) || defined(__DragonFly__)
+    {
+       int ret, enabled;
+       unsigned int len;
diff --git a/MesaLib/patches/patch-src_util_build__id.c b/MesaLib/patches/patch-src_util_build__id.c
new file mode 100644
index 0000000000..647e40d719
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_build__id.c
@@ -0,0 +1,25 @@
+$NetBSD: patch-src_util_build__id.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+Patch taken from FreeBSD ports graphics/mesa-dri mesa 17.1.0.
+
+# Elf_ doesn't exist, use Elf32_ or Elf64_.
+
+--- src/util/build_id.c.orig	2018-09-07 21:18:07.000000000 +0000
++++ src/util/build_id.c
+@@ -35,7 +35,15 @@
+ #endif
+ 
+ #ifndef ElfW
+-#define ElfW(type) Elf_##type
++# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++#  ifdef __LP64__
++#    define ElfW(type) Elf64_##type
++#  else
++#    define ElfW(type) Elf32_##type
++#  endif /* __LP64__ */
++#  else
++#    define ElfW(type) Elf_##type
++#  endif
+ #endif
+ 
+ struct build_id_note {
diff --git a/MesaLib/patches/patch-src_util_strndup.h b/MesaLib/patches/patch-src_util_strndup.h
new file mode 100644
index 0000000000..0151a3596f
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_strndup.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_util_strndup.h,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+Provide compat strndup for older Darwin.
+
+--- src/util/strndup.h.orig	2017-05-10 14:13:58.000000000 +0000
++++ src/util/strndup.h
+@@ -24,7 +24,7 @@
+ #ifndef STRNDUP_H
+ #define STRNDUP_H
+ 
+-#if defined(_WIN32)
++#if defined(_WIN32) || (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
+ 
+ #include <stdlib.h> // size_t
+ #include <string.h>
diff --git a/MesaLib/patches/patch-src_util_u__atomic.h b/MesaLib/patches/patch-src_util_u__atomic.h
new file mode 100644
index 0000000000..58a6aef473
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_u__atomic.h
@@ -0,0 +1,15 @@
+$NetBSD: patch-src_util_u__atomic.h,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+Fix SunOS atomic macros.
+
+--- src/util/u_atomic.h.orig	2018-09-07 21:18:07.000000000 +0000
++++ src/util/u_atomic.h
+@@ -20,7 +20,7 @@
+  * locally coded assembly, compiler intrinsic or ultimately a
+  * mutex-based implementation.
+  */
+-#if defined(__sun)
++#if defined(__sun) && !defined(__GNUC__)
+ #define PIPE_ATOMIC_OS_SOLARIS
+ #elif defined(_MSC_VER)
+ #define PIPE_ATOMIC_MSVC_INTRINSIC
diff --git a/MesaLib/patches/patch-src_util_u__queue.c b/MesaLib/patches/patch-src_util_u__queue.c
new file mode 100644
index 0000000000..7170bc2e71
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_u__queue.c
@@ -0,0 +1,44 @@
+$NetBSD$
+
+atexit() is not a good idea in shared libraries.
+
+FreeBSD reported atexit bug for 10.6:
+https://bugs.freedesktop.org/show_bug.cgi?id=91869
+
+--- src/util/u_queue.c.orig	2021-07-14 20:04:59.260044300 +0000
++++ src/util/u_queue.c
+@@ -58,11 +58,22 @@ static once_flag atexit_once_flag = ONCE
+ static struct list_head queue_list;
+ static mtx_t exit_mutex = _MTX_INITIALIZER_NP;
+ 
++#if defined(HAVE_NOATEXIT)
++static int global_init_called = 0;
++
++static void __attribute__((__destructor__))
++#else
+ static void
++#endif
+ atexit_handler(void)
+ {
+    struct util_queue *iter;
+ 
++#if defined(HAVE_NOATEXIT)
++   if (!global_init_called)
++      return;
++#endif
++
+    mtx_lock(&exit_mutex);
+    /* Wait for all queues to assert idle. */
+    LIST_FOR_EACH_ENTRY(iter, &queue_list, head) {
+@@ -75,7 +86,11 @@ static void
+ global_init(void)
+ {
+    list_inithead(&queue_list);
++#if defined(HAVE_NOATEXIT)
++   global_init_called = 1;
++#else
+    atexit(atexit_handler);
++#endif
+ }
+ 
+ static void
diff --git a/MesaLib/patches/patch-src_util_u__thread.h b/MesaLib/patches/patch-src_util_u__thread.h
new file mode 100644
index 0000000000..208aa02ba2
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_u__thread.h
@@ -0,0 +1,71 @@
+$NetBSD$
+
+Oracle Solaris has pthread_setname_np. illumos does not.
+
+Don't hard error when there's no pthread_setname_np.
+
+handle NetBSD-style pthread_setaffinity_np(3)
+
+--- src/util/u_thread.h.orig	2021-07-14 20:04:59.275044400 +0000
++++ src/util/u_thread.h
+@@ -103,7 +103,7 @@ static inline thrd_t u_thread_create(int
+ static inline void u_thread_setname( const char *name )
+ {
+ #if defined(HAVE_PTHREAD)
+-#if DETECT_OS_LINUX || DETECT_OS_CYGWIN || DETECT_OS_SOLARIS
++#if DETECT_OS_LINUX || DETECT_OS_CYGWIN
+    pthread_setname_np(pthread_self(), name);
+ #elif DETECT_OS_FREEBSD || DETECT_OS_OPENBSD
+    pthread_set_name_np(pthread_self(), name);
+@@ -136,8 +136,32 @@ util_set_thread_affinity(thrd_t thread,
+                          unsigned num_mask_bits)
+ {
+ #if defined(HAVE_PTHREAD_SETAFFINITY)
+-   cpu_set_t cpuset;
++# if defined(__NetBSD__)
++   cpu_set_t *cpuset;
++   cpuset = cpuset_create();
++   if (cpuset == NULL)
++      return;
++   if (old_mask) {
++      if (pthread_getaffinity_np(thread, cpuset_size(cpuset), cpuset) != 0)
++         return false;
+ 
++      memset(old_mask, 0, num_mask_bits / 8);
++      for (unsigned i = 0; i < num_mask_bits && i < CPU_SETSIZE; i++) {
++         if (cpuset_isset(i, cpuset))
++            old_mask[i / 32] |= 1u << (i % 32);
++      }
++   }
++
++   cpuset_zero(cpuset);
++   for (unsigned i = 0; i < num_mask_bits && i < CPU_SETSIZE; i++) {
++      if (mask[i / 32] & (1u << (i % 32)))
++         cpuset_set(i, cpuset);
++   }
++   int err = pthread_setaffinity_np(thread, cpuset_size(cpuset), cpuset);
++   cpuset_destroy(cpuset);
++   return err == 0;
++# else
++   cpu_set_t cpuset;
+    if (old_mask) {
+       if (pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset) != 0)
+          return false;
+@@ -155,7 +179,7 @@ util_set_thread_affinity(thrd_t thread,
+          CPU_SET(i, &cpuset);
+    }
+    return pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset) == 0;
+-
++# endif
+ #elif defined(_WIN32) && !defined(__CYGWIN__)
+    DWORD_PTR m = mask[0];
+ 
+@@ -209,7 +233,7 @@ util_set_current_thread_affinity(const u
+ static inline int64_t
+ util_thread_get_time_nano(thrd_t thread)
+ {
+-#if defined(HAVE_PTHREAD) && !defined(__APPLE__) && !defined(__HAIKU__)
++#if defined(HAVE_PTHREAD) && !defined(__APPLE__) && !defined(__HAIKU__) && !defined(__sun)
+    struct timespec ts;
+    clockid_t cid;
+ 
diff --git a/MesaLib/version.mk b/MesaLib/version.mk
new file mode 100644
index 0000000000..7f8b9ab5dd
--- /dev/null
+++ b/MesaLib/version.mk
@@ -0,0 +1,30 @@
+# $NetBSD: version.mk,v 1.1 2019/08/30 19:06:34 nia Exp $
+#
+# This file computes the version number of the Mesa distributed with
+# XFree86 and stores it in ${BUILTIN_VERSION.Mesa}.
+#
+# NOTE: This file should only be used by the Mesa-related builtin.mk files.
+#
+
+BUILTIN_FIND_FILES_VAR:=	H_MESA
+BUILTIN_FIND_FILES.H_MESA=	${X11BASE}/include/GL/gl.h
+.include "../../mk/buildlink3/find-files.mk"
+.include "../../mk/bsd.fast.prefs.mk"
+.if !defined(BUILTIN_VERSION.Mesa) && exists(${H_MESA})
+#
+# According to the Mesa documentation, for stable releases:
+#
+#	Mesa-6.0 implements OpenGL 1.5,
+#	Mesa-5.0 implements OpenGL 1.4,
+#	Mesa-4.0.4 implements OpenGL 1.3,
+#	Mesa-3.4.2 implements OpenGL 1.2.
+#
+BUILTIN_VERSION.Mesa!=							\
+	${AWK} '/\#define[ 	]*GL_VERSION_1_2/ { v = "3.4.2" }	\
+		/\#define[ 	]*GL_VERSION_1_3/ { v = "4.0.4" }	\
+		/\#define[ 	]*GL_VERSION_1_4/ { v = "5.0" }		\
+		/\#define[ 	]*GL_VERSION_1_5/ { v = "6.0" }		\
+		END { printf "%s\n", v }'				\
+		${H_MESA}
+.endif
+MAKEVARS+=	BUILTIN_VERSION.Mesa


Home | Main Index | Thread Index | Old Index