pkgsrc-WIP-changes archive

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

Add MesaLib19.



Module Name:	pkgsrc-wip
Committed By:	nia <nia%netbsd.org@localhost>
Pushed By:	nee
Date:		Thu Aug 22 14:38:54 2019 +0100
Changeset:	3e8f60cdbf98344b59b956fcd2fd381ae0e847a2

Modified Files:
	Makefile
Added Files:
	MesaLib/DESCR
	MesaLib/Makefile
	MesaLib/PLIST
	MesaLib/buildlink3.mk
	MesaLib/builtin.mk
	MesaLib/distinfo
	MesaLib/dri.mk
	MesaLib/options.mk
	MesaLib/patches/patch-common.py
	MesaLib/patches/patch-meson.build
	MesaLib/patches/patch-src_amd_common_ac__debug.c
	MesaLib/patches/patch-src_amd_vulkan_winsys_amdgpu_radv__amdgpu__cs.c
	MesaLib/patches/patch-src_compiler_builtin__type__macros.h
	MesaLib/patches/patch-src_compiler_glsl_glsl__parser__extras.cpp
	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_drivers_trace_tr__dump.c
	MesaLib/patches/patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.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_radeonsi_si__state__shaders.c
	MesaLib/patches/patch-src_gallium_drivers_vc4_vc4__bufmgr.c
	MesaLib/patches/patch-src_gallium_include_pipe_p__config.h
	MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_invocation.cpp
	MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_metadata.hpp
	MesaLib/patches/patch-src_gallium_state__trackers_clover_util_range.hpp
	MesaLib/patches/patch-src_glx_apple_apple__glapi.c
	MesaLib/patches/patch-src_glx_dri__common.h
	MesaLib/patches/patch-src_glx_dri__glx.c
	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_isl_isl__tiled__memcpy.c
	MesaLib/patches/patch-src_intel_perf_gen__perf.h
	MesaLib/patches/patch-src_intel_tools_aub__mem.c
	MesaLib/patches/patch-src_intel_tools_aubinator__error__decode.c
	MesaLib/patches/patch-src_intel_vulkan_anv__allocator.c
	MesaLib/patches/patch-src_intel_vulkan_anv__gem.c
	MesaLib/patches/patch-src_intel_vulkan_anv__gem__stubs.c
	MesaLib/patches/patch-src_intel_vulkan_anv__queue.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_mapi_u__current.h
	MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c
	MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c
	MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c
	MesaLib/patches/patch-src_mesa_main_extensions.c
	MesaLib/patches/patch-src_mesa_main_macros.h
	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_disk__cache.c
	MesaLib/patches/patch-src_util_ralloc.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

Log Message:
Add MesaLib19.

They have switched to meson.

Builds and seems to work on NetBSD.

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

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                                   |  89 +++++++
 MesaLib/PLIST                                      | 117 +++++++++
 MesaLib/buildlink3.mk                              |  49 ++++
 MesaLib/builtin.mk                                 |  89 +++++++
 MesaLib/distinfo                                   |  58 +++++
 MesaLib/dri.mk                                     |  31 +++
 MesaLib/options.mk                                 | 265 +++++++++++++++++++++
 MesaLib/patches/patch-common.py                    |  15 ++
 MesaLib/patches/patch-meson.build                  |  24 ++
 MesaLib/patches/patch-src_amd_common_ac__debug.c   |  19 ++
 ...src_amd_vulkan_winsys_amdgpu_radv__amdgpu__cs.c |  19 ++
 .../patch-src_compiler_builtin__type__macros.h     |  25 ++
 ...atch-src_compiler_glsl_glsl__parser__extras.cpp |  18 ++
 .../patch-src_egl_drivers_dri2_platform__drm.c     |  18 ++
 .../patch-src_egl_drivers_dri2_platform__x11.c     |  60 +++++
 MesaLib/patches/patch-src_egl_main_eglglobals.c    |  53 +++++
 ...-src_gallium_auxiliary_drivers_trace_tr__dump.c |  50 ++++
 ...llium_auxiliary_pipe-loader_pipe__loader__drm.c | 127 ++++++++++
 ...c_gallium_drivers_nouveau_nouveau__vp3__video.c |  18 ++
 ...-src_gallium_drivers_nouveau_nv50_nv84__video.c |  18 ++
 ...c_gallium_drivers_radeonsi_si__state__shaders.c |  21 ++
 .../patch-src_gallium_drivers_vc4_vc4__bufmgr.c    |  18 ++
 .../patch-src_gallium_include_pipe_p__config.h     |  31 +++
 ...lium_state__trackers_clover_llvm_invocation.cpp |  40 ++++
 ...allium_state__trackers_clover_llvm_metadata.hpp |  21 ++
 ...c_gallium_state__trackers_clover_util_range.hpp |  40 ++++
 MesaLib/patches/patch-src_glx_apple_apple__glapi.c |  24 ++
 MesaLib/patches/patch-src_glx_dri__common.h        |  17 ++
 MesaLib/patches/patch-src_glx_dri__glx.c           |  43 ++++
 MesaLib/patches/patch-src_glx_glxclient.h          |  19 ++
 MesaLib/patches/patch-src_glx_glxcurrent.c         |  40 ++++
 MesaLib/patches/patch-src_glx_glxext.c             |  47 ++++
 ...src_intel_compiler_brw__fs__bank__conflicts.cpp |  23 ++
 .../patch-src_intel_isl_isl__tiled__memcpy.c       |  22 ++
 MesaLib/patches/patch-src_intel_perf_gen__perf.h   |  16 ++
 MesaLib/patches/patch-src_intel_tools_aub__mem.c   |  36 +++
 ...atch-src_intel_tools_aubinator__error__decode.c |  19 ++
 .../patch-src_intel_vulkan_anv__allocator.c        |  62 +++++
 MesaLib/patches/patch-src_intel_vulkan_anv__gem.c  |  19 ++
 .../patch-src_intel_vulkan_anv__gem__stubs.c       |  36 +++
 .../patches/patch-src_intel_vulkan_anv__queue.c    |  25 ++
 .../patches/patch-src_mapi_entry__x86-64__tls.h    |  32 +++
 MesaLib/patches/patch-src_mapi_entry__x86__tls.h   |  40 ++++
 MesaLib/patches/patch-src_mapi_u__current.c        |  31 +++
 MesaLib/patches/patch-src_mapi_u__current.h        |  16 ++
 ...patch-src_mesa_drivers_dri_i915_intel__screen.c |  44 ++++
 ...patch-src_mesa_drivers_dri_i965_intel__screen.c |  44 ++++
 .../patch-src_mesa_drivers_dri_swrast_swrast.c     |  19 ++
 MesaLib/patches/patch-src_mesa_main_extensions.c   |  31 +++
 MesaLib/patches/patch-src_mesa_main_macros.h       |  18 ++
 .../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_disk__cache.c       |  29 +++
 MesaLib/patches/patch-src_util_ralloc.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          |  70 ++++++
 MesaLib/patches/patch-src_util_u__thread.h         |  76 ++++++
 61 files changed, 2404 insertions(+)

diffs:
diff --git a/Makefile b/Makefile
index 8bce1b7942..12741b1813 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,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..87f5f60832
--- /dev/null
+++ b/MesaLib/Makefile
@@ -0,0 +1,89 @@
+# $NetBSD: Makefile,v 1.151 2019/08/22 09:59:47 nia Exp $
+
+DISTNAME=	mesa-19.1.4
+PKGNAME=	${DISTNAME:S/mesa/MesaLib/}
+CATEGORIES=	graphics x11
+MASTER_SITES=	https://mesa.freedesktop.org/archive/
+EXTRACT_SUFX=	.tar.xz
+
+MAINTAINER=	pkgsrc-users%NetBSD.org@localhost
+HOMEPAGE=	https://www.mesa3d.org/
+COMMENT=	Open source OpenGL implementation
+LICENSE=	mit
+
+USE_TOOLS+=	pkg-config
+USE_LANGUAGES=	c99 c++
+USE_LIBTOOL=	yes
+
+PKGCONFIG_OVERRIDE+=	src/egl/main/egl.pc.in
+PKGCONFIG_OVERRIDE+=	src/gallium/targets/d3dadapter9/d3d.pc.in
+PKGCONFIG_OVERRIDE+=	src/gallium/targets/osmesa/osmesa.pc.in
+PKGCONFIG_OVERRIDE+=	src/gallium/targets/xa/xatracker.pc.in
+PKGCONFIG_OVERRIDE+=	src/gbm/main/gbm.pc.in
+PKGCONFIG_OVERRIDE+=	src/glx/windows/windowsdriproto.pc.in
+PKGCONFIG_OVERRIDE+=	src/mapi/es1api/glesv1_cm.pc.in
+PKGCONFIG_OVERRIDE+=	src/mapi/es2api/glesv2.pc.in
+PKGCONFIG_OVERRIDE+=	src/mesa/drivers/dri/dri.pc.in
+PKGCONFIG_OVERRIDE+=	src/mesa/drivers/osmesa/osmesa.pc.in
+PKGCONFIG_OVERRIDE+=	src/mesa/gl.pc.in
+
+# Replace /etc/drirc.d with ${PREFIX}/etc/drirc.d
+SUBST_CLASSES+=		drirc
+SUBST_STAGE.drirc=	pre-configure
+SUBST_MESSAGE.drirc=	Fixing hardcoded /etc/drirc.d references
+SUBST_FILES.drirc+=	src/util/xmlconfig.c
+SUBST_SED.drirc+=	-e 's|/etc|${PREFIX}/etc|g'
+
+SUBST_CLASSES+=		py
+SUBST_STAGE.py=		pre-configure
+SUBST_MESSAGE.py=	Fixing Python binary name
+SUBST_FILES.py+=	meson.build
+SUBST_VARS.py+=		PYTHONBIN
+
+CFLAGS.SunOS+=		-D__EXTENSIONS__ -D_POSIX_PTHREAD_SEMANTICS
+CXXFLAGS.SunOS+=	-Drestrict=__restrict__
+LDFLAGS.SunOS+=		-lsocket -lnsl
+
+.include "../../mk/bsd.prefs.mk"
+.include "../../mk/compiler.mk"
+.include "options.mk"
+
+.if ${MACHINE_ARCH} == "i386"
+MESON_ARGS+=	-Dglx-read-only-text=true
+.endif
+
+MESON_ARGS+=	-Dshared-glapi=true
+
+CPPFLAGS+=	-DHAVE_NOATEXIT
+
+# Work around Xorg segfaulting in radeon driver due to wrong alloca being used
+CFLAGS.NetBSD+=		-Dalloca=__builtin_alloca
+CXXFLAGS.NetBSD+=	-Dalloca=__builtin_alloca
+
+PYTHON_FOR_BUILD_ONLY=	yes
+BUILD_DEPENDS+=		${PYPKGPREFIX}-mako-[0-9]*:../../devel/py-mako
+# needed to build vulkan support
+BUILD_DEPENDS+=		${PYPKGPREFIX}-cElementTree-[0-9]*:../../textproc/py-cElementTree
+
+pre-configure:
+	touch ${WRKSRC}/src/glx/apple_dummy.cpp
+
+DRIRC_DIR=		${PKG_SYSCONFDIR}/drirc.d
+EGDIR=			${PREFIX}/share/examples/mesa
+OWN_DIRS+=		${DRIRC_DIR}
+INSTALLATION_DIRS+=	${EGDIR}
+CONF_FILES+=		${EGDIR}/00-mesa-defaults.conf \
+			${DRIRC_DIR}/00-mesa-defaults.conf
+
+post-install:
+	${INSTALL_DATA} ${WRKSRC}/src/util/00-mesa-defaults.conf ${DESTDIR}${EGDIR}
+
+.include "../../devel/py-meson/build.mk"
+.include "../../devel/zlib/buildlink3.mk"
+.include "../../textproc/expat/buildlink3.mk"
+.include "../../x11/libXrandr/buildlink3.mk"
+.include "../../x11/libX11/buildlink3.mk"
+.include "../../x11/libXext/buildlink3.mk"
+.include "../../x11/libxcb/buildlink3.mk"
+.include "../../x11/libxshmfence/buildlink3.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/MesaLib/PLIST b/MesaLib/PLIST
new file mode 100644
index 0000000000..ae21c4691f
--- /dev/null
+++ b/MesaLib/PLIST
@@ -0,0 +1,117 @@
+@comment $NetBSD: PLIST,v 1.39 2019/08/21 13:35:28 nia Exp $
+${PLIST.egl}include/EGL/egl.h
+${PLIST.egl}include/EGL/eglext.h
+${PLIST.egl}include/EGL/eglextchromium.h
+${PLIST.egl}include/EGL/eglmesaext.h
+${PLIST.egl}include/EGL/eglplatform.h
+include/GL/gl.h
+include/GL/gl_mangle.h
+include/GL/glcorearb.h
+include/GL/glext.h
+include/GL/glx.h
+include/GL/glx_mangle.h
+include/GL/glxext.h
+${PLIST.dri}include/GL/internal/dri_interface.h
+${PLIST.osmesa}include/GL/osmesa.h
+${PLIST.glesv1}include/GLES/egl.h
+${PLIST.glesv1}include/GLES/gl.h
+${PLIST.glesv1}include/GLES/glext.h
+${PLIST.glesv1}include/GLES/glplatform.h
+${PLIST.glesv2}include/GLES2/gl2.h
+${PLIST.glesv2}include/GLES2/gl2ext.h
+${PLIST.glesv2}include/GLES2/gl2platform.h
+${PLIST.glesv2}include/GLES3/gl3.h
+${PLIST.glesv2}include/GLES3/gl31.h
+${PLIST.glesv2}include/GLES3/gl32.h
+${PLIST.glesv2}include/GLES3/gl3ext.h
+${PLIST.glesv2}include/GLES3/gl3platform.h
+include/KHR/khrplatform.h
+${PLIST.gbm}include/gbm.h
+${PLIST.vulkan}include/vulkan/vulkan_intel.h
+${PLIST.xatracker}include/xa_composite.h
+${PLIST.xatracker}include/xa_context.h
+${PLIST.xatracker}include/xa_tracker.h
+@comment ${PLIST.vaapi}lib/dri/gallium_drv_video.la
+@comment ${PLIST.vaapi}lib/dri/gallium_drv_video.so
+${PLIST.i915}lib/dri/i915_dri.so
+${PLIST.i965}lib/dri/i965_dri.so
+@comment ${PLIST.ilo}lib/dri/ilo_dri.so
+${PLIST.freedreno}lib/dri/kgsl_dri.so
+${PLIST.swrast}lib/dri/kms_swrast_dri.so
+${PLIST.freedreno}lib/dri/msm_dri.so
+${PLIST.nouveau}lib/dri/nouveau_dri.so
+@comment ${PLIST.vdpau}lib/dri/nouveau_drv_video.la
+${PLIST.nouveau}${PLIST.vaapi}lib/dri/nouveau_drv_video.so
+${PLIST.nouveau_dri}lib/dri/nouveau_vieux_dri.so
+@comment ${PLIST.vdpau}lib/dri/radeonsi_drv_video.la
+${PLIST.r200}lib/dri/r200_dri.so
+${PLIST.r300}lib/dri/r300_dri.so
+${PLIST.r600}lib/dri/r600_dri.so
+@comment ${PLIST.vdpau}lib/dri/r600_drv_video.la
+${PLIST.vaapi}lib/dri/r600_drv_video.so
+${PLIST.r100}lib/dri/radeon_dri.so
+${PLIST.radeonsi}lib/dri/radeonsi_dri.so
+${PLIST.vaapi}lib/dri/radeonsi_drv_video.so
+${PLIST.swrast_dri}lib/dri/swrast_dri.so
+${PLIST.vc4}lib/dri/vc4_dri.so
+${PLIST.svga}lib/dri/vmwgfx_dri.so
+${PLIST.egl}lib/libEGL.so
+${PLIST.egl}lib/libEGL.so.1
+${PLIST.egl}lib/libEGL.so.1.0.0
+lib/libGL.so
+lib/libGL.so.1
+lib/libGL.so.1.2.0
+${PLIST.glesv1}lib/libGLESv1_CM.so
+${PLIST.glesv1}lib/libGLESv1_CM.so.1
+${PLIST.glesv1}lib/libGLESv1_CM.so.1.1.0
+${PLIST.glesv2}lib/libGLESv2.so
+${PLIST.glesv2}lib/libGLESv2.so.2
+${PLIST.glesv2}lib/libGLESv2.so.2.0.0
+${PLIST.osmesa}lib/libOSMesa.so
+${PLIST.osmesa}lib/libOSMesa.so.8
+${PLIST.osmesa}lib/libOSMesa.so.8.0.0
+${PLIST.xvmc}${PLIST.nouveau}lib/libXvMCnouveau.so
+${PLIST.xvmc}${PLIST.nouveau}lib/libXvMCnouveau.so.1
+${PLIST.xvmc}${PLIST.nouveau}lib/libXvMCnouveau.so.1.0
+${PLIST.xvmc}${PLIST.nouveau}lib/libXvMCnouveau.so.1.0.0
+${PLIST.xvmc}${PLIST.r600}lib/libXvMCr600.so
+${PLIST.xvmc}${PLIST.r600}lib/libXvMCr600.so.1
+${PLIST.xvmc}${PLIST.r600}lib/libXvMCr600.so.1.0
+${PLIST.xvmc}${PLIST.r600}lib/libXvMCr600.so.1.0.0
+${PLIST.gbm}lib/libgbm.so
+${PLIST.gbm}lib/libgbm.so.1
+${PLIST.gbm}lib/libgbm.so.1.0.0
+lib/libglapi.so
+lib/libglapi.so.0
+lib/libglapi.so.0.0.0
+${PLIST.xatracker}lib/libxatracker.so
+${PLIST.xatracker}lib/libxatracker.so.2
+${PLIST.xatracker}lib/libxatracker.so.2.5.0
+${PLIST.dri}lib/pkgconfig/dri.pc
+${PLIST.egl}lib/pkgconfig/egl.pc
+${PLIST.gbm}lib/pkgconfig/gbm.pc
+lib/pkgconfig/gl.pc
+${PLIST.glesv1}lib/pkgconfig/glesv1_cm.pc
+${PLIST.glesv2}lib/pkgconfig/glesv2.pc
+${PLIST.osmesa}lib/pkgconfig/osmesa.pc
+${PLIST.xatracker}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.vdpau}lib/vdpau/libvdpau_r300.so
+${PLIST.vdpau}lib/vdpau/libvdpau_r300.so.1
+${PLIST.vdpau}lib/vdpau/libvdpau_r300.so.1.0
+${PLIST.vdpau}lib/vdpau/libvdpau_r300.so.1.0.0
+${PLIST.vdpau}lib/vdpau/libvdpau_r600.so
+${PLIST.vdpau}lib/vdpau/libvdpau_r600.so.1
+${PLIST.vdpau}lib/vdpau/libvdpau_r600.so.1.0
+${PLIST.vdpau}lib/vdpau/libvdpau_r600.so.1.0.0
+${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so
+${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so.1
+${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so.1.0
+${PLIST.vdpau}lib/vdpau/libvdpau_radeonsi.so.1.0.0
+${PLIST.vulkan}share/vulkan/icd.d/intel_icd.${MACHINE_ARCH}.json
+${PLIST.vulkan}share/vulkan/icd.d/radeon_icd.${MACHINE_ARCH}.json
+share/drirc.d/00-mesa-defaults.conf
+share/examples/mesa/00-mesa-defaults.conf
diff --git a/MesaLib/buildlink3.mk b/MesaLib/buildlink3.mk
new file mode 100644
index 0000000000..dc9bb54da1
--- /dev/null
+++ b/MesaLib/buildlink3.mk
@@ -0,0 +1,49 @@
+# $NetBSD: buildlink3.mk,v 1.58 2019/08/21 13:35:28 nia 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>=7.11.2
+BUILDLINK_PKGSRCDIR.MesaLib?=	../../graphics/MesaLib
+
+.include "../../mk/bsd.fast.prefs.mk"
+
+.if ${X11_TYPE} == "modular"
+BUILDLINK_ABI_DEPENDS.MesaLib+=	MesaLib>=10.5.3
+.  if defined(USE_LANGUAGES) && !empty(USE_LANGUAGES:Mc++)
+# This is needed to avoid linking conflicting libstdc++ versions
+GCC_REQD+=			4.2
+.  endif
+.endif
+
+# 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 ${X11_TYPE} == "native" && ${OPSYS} != "Cygwin" && exists(${X11BASE}/lib/pkgconfig/dri.pc)
+PKG_BUILD_OPTIONS.MesaLib+=	dri
+.endif
+
+.if !empty(PKG_BUILD_OPTIONS.MesaLib:Mdri)
+.  include "../../graphics/MesaLib/dri.mk"
+.endif
+
+.if	${X11_TYPE} == "modular" && !empty(PKG_BUILD_OPTIONS.MesaLib:Mdri) ||	\
+	${X11_TYPE} == "native"  && exists(${X11BASE}/include/EGL/egl.h)
+MESALIB_SUPPORTS_EGL=	yes
+.else
+MESALIB_SUPPORTS_EGL=	no
+.endif
+
+.include "../../x11/libXext/buildlink3.mk"
+.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..350aee3698
--- /dev/null
+++ b/MesaLib/builtin.mk
@@ -0,0 +1,89 @@
+# $NetBSD: builtin.mk,v 1.22 2019/08/21 13:35:28 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 "../../graphics/Mesa/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..6866542d0d
--- /dev/null
+++ b/MesaLib/distinfo
@@ -0,0 +1,58 @@
+$NetBSD: distinfo,v 1.124 2019/08/21 13:35:28 nia Exp $
+
+SHA1 (mesa-19.1.4.tar.xz) = 393053bfa41b7fc65add756713004f034c39c3ce
+RMD160 (mesa-19.1.4.tar.xz) = 1d813c4a212710bb6fa8db184b4618788851cd15
+SHA512 (mesa-19.1.4.tar.xz) = 234032d917c9b378c3f6ceb921677b64e549344c3957331810b50fd73e0dccd2f4f62e2bd39e619590f389bc58fdab10fab4b88f7c117557cbeb1dda049b9fc5
+Size (mesa-19.1.4.tar.xz) = 10938008 bytes
+SHA1 (patch-common.py) = 3ebf2f475332df7eb6bce162ae7d65e7d75a8132
+SHA1 (patch-meson.build) = a9fdcaa59aed9b56ff95d4153dd73064e2261c45
+SHA1 (patch-src_amd_common_ac__debug.c) = 8233367c3b5bc344442ea8d19488fdd1e3791ae9
+SHA1 (patch-src_amd_vulkan_winsys_amdgpu_radv__amdgpu__cs.c) = 1fe81a7b16e36dc9125400c20543271216a33a45
+SHA1 (patch-src_compiler_builtin__type__macros.h) = 857bca0c0f55ec8d7a20b3807c7a5d7bd06bdfbf
+SHA1 (patch-src_compiler_glsl_glsl__parser__extras.cpp) = ef114d6e288e6d212fce9d1c0606f7d454a171c4
+SHA1 (patch-src_egl_drivers_dri2_platform__drm.c) = e18e7b1ffbc74b8acf3d9095a92c750f9d005479
+SHA1 (patch-src_egl_drivers_dri2_platform__x11.c) = 49e48c31eacb79d1da357fe70eaffd2926b5280e
+SHA1 (patch-src_egl_main_eglglobals.c) = 0d52014f52e62fc5fa6650336ddb0011ecf331e6
+SHA1 (patch-src_gallium_auxiliary_drivers_trace_tr__dump.c) = 360e1608508a7bbb41acecd58930781038e2309e
+SHA1 (patch-src_gallium_auxiliary_pipe-loader_pipe__loader__drm.c) = f913b779404e6bd8ae707a4fd66eb7c1dca9b311
+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_radeonsi_si__state__shaders.c) = ed51a57765f2349bc91fd509dc03e709241bd899
+SHA1 (patch-src_gallium_drivers_vc4_vc4__bufmgr.c) = 1d591d346486fdf58893f69ab92a272e6a31a987
+SHA1 (patch-src_gallium_include_pipe_p__config.h) = f4e38eac66167b619c30076bb0144dd716310967
+SHA1 (patch-src_gallium_state__trackers_clover_llvm_invocation.cpp) = 3053db09fbfffffd82e232b60b244a0a80c8f181
+SHA1 (patch-src_gallium_state__trackers_clover_llvm_metadata.hpp) = c97d38098ea03658bc193a50e445b87f1c020839
+SHA1 (patch-src_gallium_state__trackers_clover_util_range.hpp) = cdc78067986c1b92818472c4201c58ef1b42c4f4
+SHA1 (patch-src_glx_apple_apple__glapi.c) = c4eea8dabf74eb03d22da4eb834b18ae3384c63b
+SHA1 (patch-src_glx_dri__common.h) = 0274877f8c65a4bb729536a897df4704897a4c6e
+SHA1 (patch-src_glx_dri__glx.c) = 8fd48776e9953b18bd17ba130d90ae2935e67242
+SHA1 (patch-src_glx_glxclient.h) = f0358179ae397bc8677597b0ccb9a471f40f15de
+SHA1 (patch-src_glx_glxcurrent.c) = 8b8e949eded13491c5865601253c6e7d4b06e228
+SHA1 (patch-src_glx_glxext.c) = 15c2c5e0c6b5095ce849fb86ad148aa05d7d907a
+SHA1 (patch-src_intel_compiler_brw__fs__bank__conflicts.cpp) = 6276d2c6846bb4dd08699921bec4e20202a17478
+SHA1 (patch-src_intel_isl_isl__tiled__memcpy.c) = 9b79991648ab4c39ae14df219135cd2b01c1b3c0
+SHA1 (patch-src_intel_perf_gen__perf.h) = 61198d4031df8c2ff5f856b5680f3330aedaada8
+SHA1 (patch-src_intel_tools_aub__mem.c) = 6a21ecb4cfbdf216474b3be16bda441bb1390350
+SHA1 (patch-src_intel_tools_aubinator__error__decode.c) = d8f636e3c3e76763a505a1dce23de0b198ad62fa
+SHA1 (patch-src_intel_vulkan_anv__allocator.c) = da5a11c95d17d6476e7141572264a215807b8cd7
+SHA1 (patch-src_intel_vulkan_anv__gem.c) = b8eb487fa704151e7c3c3b1d23973b2b0aa5922e
+SHA1 (patch-src_intel_vulkan_anv__gem__stubs.c) = ad5a4bd9fe521cf73faf2f0cf0f493a0b40f4c20
+SHA1 (patch-src_intel_vulkan_anv__queue.c) = 2dbf7dfd0c77f74f510032bf8d12109f58c50a30
+SHA1 (patch-src_mapi_entry__x86-64__tls.h) = 11b7ef1da435fa17fc7025a46a123d447d6a7d07
+SHA1 (patch-src_mapi_entry__x86__tls.h) = 11c0f5302d305a77f3a1780d44a2c61f48a66273
+SHA1 (patch-src_mapi_u__current.c) = 38d324fcd1c28d155106ccd248edb5eb1aa9ffac
+SHA1 (patch-src_mapi_u__current.h) = 465a992bd34057e9521f0a33e6f2e25cefc145ca
+SHA1 (patch-src_mesa_drivers_dri_i915_intel__screen.c) = e33f51b3502e8c52ff7283aeb807996717f79f4f
+SHA1 (patch-src_mesa_drivers_dri_i965_intel__screen.c) = 795b17970e95347222514bacc0701aa86fa1ff02
+SHA1 (patch-src_mesa_drivers_dri_swrast_swrast.c) = 3106f350e590f62c8bd29cd85f24f977639dccdb
+SHA1 (patch-src_mesa_main_extensions.c) = 2f48bdb1176c2878bb33bcfab7556172b50a987e
+SHA1 (patch-src_mesa_main_macros.h) = c5dceaa8dc02a58e5b2273d82e3fe1cc12e327d3
+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_disk__cache.c) = cc0b29780dba5d5b5e43c0798336f16a1f0008de
+SHA1 (patch-src_util_ralloc.c) = d311bfd9ed7e673d72e050668d351c1e6552cdc8
+SHA1 (patch-src_util_strndup.h) = 73f49694ca48ad6b9a9d8346c5b84fddec2463bd
+SHA1 (patch-src_util_u__atomic.h) = 31d4514538ef5ee53012695eb5c66134aaec981e
+SHA1 (patch-src_util_u__queue.c) = ed1ea3f6fc37e9a64894a3e865c48691b6e01b2c
+SHA1 (patch-src_util_u__thread.h) = f0453485bb62d0b7c00a1b840cfce2726ebcbfd2
diff --git a/MesaLib/dri.mk b/MesaLib/dri.mk
new file mode 100644
index 0000000000..fcfc8c030c
--- /dev/null
+++ b/MesaLib/dri.mk
@@ -0,0 +1,31 @@
+# $NetBSD: dri.mk,v 1.18 2019/08/21 13:35:28 nia Exp $
+#
+# Currently, this is for convenience only.
+#
+.if !defined(DRI_MK)
+DRI_MK=		# defined
+
+.if !defined(USE_BUILTIN.MesaLib)
+CHECK_BUILTIN.MesaLib:=	yes
+.  include "../../graphics/MesaLib/builtin.mk"
+CHECK_BUILTIN.MesaLib:=	no
+.endif
+
+.if !empty(USE_BUILTIN.MesaLib:M[Nn][Oo])
+.  if ${OPSYS} != "Darwin"
+BUILDLINK_API_DEPENDS.libdrm+=		libdrm>=2.4.60
+.  endif
+.  if ${OPSYS} == "Linux"
+BUILDLINK_API_DEPENDS.libxcb+=	libxcb>=1.9.3
+.  endif
+.endif
+.include "../../x11/xorgproto/buildlink3.mk"
+# XXX these do not have builtin.mk
+.include "../../x11/libxshmfence/buildlink3.mk"
+.include "../../x11/libXdamage/buildlink3.mk"
+.include "../../x11/libXfixes/buildlink3.mk"
+.include "../../x11/libXxf86vm/buildlink3.mk"
+.if ${OPSYS} != "Darwin"
+.  include "../../x11/libdrm/buildlink3.mk"
+.endif
+.endif
diff --git a/MesaLib/options.mk b/MesaLib/options.mk
new file mode 100644
index 0000000000..2136332cfb
--- /dev/null
+++ b/MesaLib/options.mk
@@ -0,0 +1,265 @@
+# $NetBSD: options.mk,v 1.65 2019/08/21 13:35:28 nia Exp $
+
+PKG_OPTIONS_VAR=		PKG_OPTIONS.MesaLib
+PKG_SUPPORTED_OPTIONS=		llvm dri wayland
+PKG_SUGGESTED_OPTIONS=
+
+PKG_SUPPORTED_OPTIONS+=		vdpau vaapi
+PKG_SUPPORTED_OPTIONS+=		osmesa
+PKG_SUPPORTED_OPTIONS+=		glesv1 glesv2
+PKG_SUPPORTED_OPTIONS+=		gallium-xa
+PKG_SUPPORTED_OPTIONS+=		gallium-xvmc
+PKG_SUPPORTED_OPTIONS+=		vulkan
+
+PKG_SUGGESTED_OPTIONS+=		vdpau vaapi
+PKG_SUGGESTED_OPTIONS+=		glesv1 glesv2
+
+PKG_SUGGESTED_OPTIONS+=		gallium-xa
+#PKG_SUGGESTED_OPTIONS+=	gallium-xvmc
+PKG_SUGGESTED_OPTIONS+=		osmesa
+
+PKG_OPTIONS_LEGACY_OPTS+=	xa:gallium-xa
+PKG_OPTIONS_LEGACY_OPTS+=	xvmc:gallium-xvmc
+
+# The LLVM option enables JIT accelerated software rendering and
+# is also required to support the latest RADEON GPUs, so enable it
+# by default on platforms where such GPUs might be encountered.
+.if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64") && \
+	${OPSYS} != "SunOS" && ${OPSYS} != "Darwin"
+PKG_SUGGESTED_OPTIONS+=		llvm
+.endif
+
+.if ${OPSYS} == "FreeBSD" || ${OPSYS} == "OpenBSD" ||		\
+	${OPSYS} == "DragonFly" || ${OPSYS} == "Linux" ||	\
+	${OPSYS} == "SunOS" || ${OPSYS} == "NetBSD" ||		\
+	${OPSYS} == "Darwin"
+PKG_SUGGESTED_OPTIONS+=		dri
+.endif
+
+.include "../../mk/bsd.options.mk"
+
+# gallium
+PLIST_VARS+=	freedreno i915 i965 nouveau r300 r600 radeonsi	\
+		swrast svga vc4 virgl vulkan
+# classic DRI
+PLIST_VARS+=	dri swrast_dri nouveau_dri r100 r200
+# other features
+PLIST_VARS+=	egl gbm vaapi vdpau wayland xatracker
+PLIST_VARS+=	osmesa xvmc
+PLIST_VARS+=	glesv1 glesv2
+
+EGL_PLATFORMS+=		x11
+
+.if ${OPSYS} != "Darwin"
+EGL_PLATFORMS+=		drm
+.endif
+
+.if !empty(PKG_OPTIONS:Mwayland)
+EGL_PLATFORMS+=		wayland
+PLIST.wayland=		yes
+.include "../../devel/wayland/buildlink3.mk"
+.include "../../devel/wayland-protocols/buildlink3.mk"
+.endif
+
+.if !empty(PKG_OPTIONS:Mdri)
+# Having DRI3 and egl compiled in by default doesn't hurt, the X server
+# will only use it if it is supported at run time.
+MESON_ARGS+=		-Ddri3=true
+.  if ${OPSYS} != "Darwin"
+MESON_ARGS+=		-Degl=true
+MESON_ARGS+=		-Dgbm=true
+PLIST.egl=		yes
+PLIST.gbm=		yes
+.  else
+MESON_ARGS+=		-Degl=false
+MESON_ARGS+=		-Dgbm=false
+.  endif
+
+.  if !empty(PKG_OPTIONS:Mosmesa)
+MESON_ARGS+=		-Dosmesa=classic
+PLIST.osmesa=		yes
+.  else
+MESON_ARGS+=		-Dosmesa=none
+.  endif
+
+.  if !empty(PKG_OPTIONS:Mglesv1)
+MESON_ARGS+=		-Dgles1=true
+PLIST.glesv1=		yes
+.  else
+MESON_ARGS+=		-Dgles1=false
+.  endif
+
+.  if !empty(PKG_OPTIONS:Mglesv2)
+MESON_ARGS+=		-Dgles2=true
+PLIST.glesv2=		yes
+.  else
+MESON_ARGS+=		-Dgles2=false
+.  endif
+
+PLIST.dri=	yes
+
+.  if ${OPSYS} != "Darwin"
+BUILDLINK_DEPMETHOD.libpciaccess=	full
+.    include "../../sysutils/libpciaccess/buildlink3.mk"
+.  endif
+.  include "../../graphics/MesaLib/dri.mk"
+
+DRI_DRIVERS=		#
+GALLIUM_DRIVERS=	#
+VULKAN_DRIVERS=		#
+
+# Software rasterizer
+PLIST.swrast_dri=	yes
+DRI_DRIVERS+=		swrast
+
+# x86 only drivers
+.  if (${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64") && ${OPSYS} != "Darwin"
+# svga / VMWare driver
+PLIST.svga=		yes
+GALLIUM_DRIVERS+=	svga
+
+# Intel chipsets, x86 only
+PLIST.i915=		yes
+DRI_DRIVERS+=		i915
+
+PLIST.i965=		yes
+DRI_DRIVERS+=		i965
+
+.  endif
+
+# Vulkan support
+.  if !empty(PKG_OPTIONS:Mvulkan)
+VULKAN_DRIVERS+=	intel
+VULKAN_DRIVERS+=	radeon
+PLIST.vulkan=		yes
+.  endif
+
+# ARM drivers
+.  if !empty(MACHINE_PLATFORM:MNetBSD-*-*arm*)
+# Qualcomm SnapDragon, libdrm_freedreno.pc
+#GALLIUM_DRIVERS+=	freedreno
+#PLIST.freedreno=	yes
+
+# Broadcom VideoCore 4
+GALLIUM_DRIVERS+=	vc4
+PLIST.vc4=		yes
+.  endif
+
+# qemu Linux guest driver
+.  if !empty(MACHINE_PLATFORM:MLinux-*-x86_64)
+# XXX test this
+#GALLIUM_DRIVERS+=	virgl
+#PLIST.virgl=		yes
+.  endif
+
+# theoretically cross platform PCI drivers
+.  if ${OPSYS} != "Darwin" && empty(MACHINE_PLATFORM:MNetBSD-*-*arm*) && \
+	empty(MACHINE_PLATFORM:MNetBSD-*-mipsel)
+
+# AMD Radeon r600
+PLIST.r600=		yes
+GALLIUM_DRIVERS+=	r600
+
+# FULL_OS_VERSION_CMD=	${UNAME} -r
+# FULL_OS_VERSION=	${FULL_OS_VERSION_CMD:sh}
+
+# FreeBSD lacks nouveau support (there are official binaries from Nvidia)
+.    if ${OPSYS} != "FreeBSD"
+# nVidia
+PLIST.nouveau=		yes
+GALLIUM_DRIVERS+=	nouveau
+.    endif
+
+# classic DRI r100
+PLIST.r100=		yes
+DRI_DRIVERS+=		r100
+
+# classic DRI r200
+PLIST.r200=		yes
+DRI_DRIVERS+=		r200
+
+# FreeBSD lacks nouveau support (there are official binaries from Nvidia)
+.    if ${OPSYS} != "FreeBSD"
+# classic DRI nouveau
+PLIST.nouveau_dri=	yes
+DRI_DRIVERS+=		nouveau
+.    endif
+.  endif
+# end cross platform PCI drivers
+
+.  if !empty(PKG_OPTIONS:Mllvm)
+# VA-API and VDPAU
+.    if !empty(PKG_OPTIONS:Mvaapi)
+.      include "../../multimedia/libva/available.mk"
+.      if ${VAAPI_AVAILABLE} == "yes"
+PLIST.vaapi=	yes
+.        include "../../multimedia/libva/buildlink3.mk"
+.      endif
+.    endif # vaapi
+.    if !empty(PKG_OPTIONS:Mvdpau)
+.      include "../../multimedia/libvdpau/available.mk"
+.      if ${VDPAU_AVAILABLE} == "yes"
+PLIST.vdpau=	yes
+.        include "../../multimedia/libvdpau/buildlink3.mk"
+.      endif
+.    endif # vdpau
+
+# XA is useful for accelerating xf86-video-vmware
+.    if !empty(PKG_OPTIONS:Mgallium-xa)
+MESON_ARGS+=		-Dgallium-xa=true
+PLIST.xatracker=	yes
+.    else
+MESON_ARGS+=		-Dgallium-xa=false
+.    endif
+
+# AMD Radeon r300
+PLIST.r300=		yes
+GALLIUM_DRIVERS+=	r300
+# AMD Canary Islands GPUs
+PLIST.radeonsi=		yes
+GALLIUM_DRIVERS+=	radeonsi
+MESON_ARGS+=		-Dllvm=true
+
+BUILDLINK_API_DEPENDS.libLLVM+= libLLVM>=7.0
+.    include "../../devel/libelf/buildlink3.mk"
+.    include "../../lang/libunwind/buildlink3.mk"
+.    include "../../lang/llvm/buildlink3.mk"
+
+SUBST_CLASSES+=		llvm
+SUBST_STAGE.llvm=	pre-configure
+SUBST_MESSAGE.llvm=	Fixing llvm-config path
+SUBST_FILES.llvm+=	common.py
+SUBST_VARS.llvm+=	LLVM_CONFIG_PATH
+
+.  else # !llvm
+MESON_ARGS+=		-Dgallium-xa=false
+MESON_ARGS+=		-Dllvm=false
+MESON_ARGS+=		-Dllvm-shared=false
+.  endif # llvm
+MESON_ARGS+=		-Dgallium-drivers=${GALLIUM_DRIVERS:ts,}
+MESON_ARGS+=		-Ddri-drivers=${DRI_DRIVERS:ts,}
+MESON_ARGS+=		-Dvulkan-drivers=${VULKAN_DRIVERS:ts,}
+MESON_ARGS+=		-Dplatforms=${EGL_PLATFORMS:ts,}
+.else # !dri
+MESON_ARGS+=		-Dgallium-drivers=
+MESON_ARGS+=		-Ddri-drivers=
+MESON_ARGS+=		-Dvulkan-drivers=
+MESON_ARGS+=		-Ddri3=false
+MESON_ARGS+=		-Degl=false
+MESON_ARGS+=		-Dgbm=false
+MESON_ARGS+=		-Dgles1=false
+MESON_ARGS+=		-Dgles2=false
+MESON_ARGS+=		-Dglx=xlib
+MESON_ARGS+=		-Dplatforms=x11
+.  if !empty(PKG_OPTIONS:Mllvm)
+PKG_FAIL_REASON+=	"The llvm PKG_OPTION must also be disabled when dri is disabled"
+.  endif
+.endif # dri
+
+.if !empty(PKG_OPTIONS:Mgallium-xvmc)
+MESON_ARGS+=		-Dgallium-xvmc=true
+.include "../../x11/libXvMC/buildlink3.mk"
+PLIST.xvmc=		yes
+.else
+MESON_ARGS+=		-Dgallium-xvmc=false
+.endif
diff --git a/MesaLib/patches/patch-common.py b/MesaLib/patches/patch-common.py
new file mode 100644
index 0000000000..cc7366ff49
--- /dev/null
+++ b/MesaLib/patches/patch-common.py
@@ -0,0 +1,15 @@
+$NetBSD$
+
+Fix path to llvm-config executable.
+
+--- common.py.orig	2019-08-07 16:39:16.000000000 +0000
++++ common.py
+@@ -65,7 +65,7 @@ else:
+     default_llvm = 'no'
+     try:
+         if target_platform != 'windows' and \
+-           subprocess.call(['llvm-config', '--version'],
++           subprocess.call(['@LLVM_CONFIG_PATH@', '--version'],
+                            stdout=subprocess.PIPE) == 0:
+             default_llvm = 'yes'
+     except:
diff --git a/MesaLib/patches/patch-meson.build b/MesaLib/patches/patch-meson.build
new file mode 100644
index 0000000000..393cc81e3b
--- /dev/null
+++ b/MesaLib/patches/patch-meson.build
@@ -0,0 +1,24 @@
+$NetBSD$
+
+Fix python binary name.
+
+--- meson.build.orig	2019-08-07 16:39:16.000000000 +0000
++++ meson.build
+@@ -22,7 +22,7 @@ project(
+   'mesa',
+   ['c', 'cpp'],
+   version : run_command(
+-    [find_program('python', 'python2', 'python3'), 'bin/meson_get_version.py']
++    [find_program('@PYTHONBIN@', 'python', 'python2', 'python3'), 'bin/meson_get_version.py']
+   ).stdout(),
+   license : 'MIT',
+   meson_version : '>= 0.45',
+@@ -760,7 +760,7 @@ if with_platform_haiku
+ endif
+ 
+ if meson.version().version_compare('>=0.50')
+-  prog_python = import('python').find_installation('python3')
++  prog_python = import('python').find_installation('@PYTHONBIN@')
+ else
+   prog_python = import('python3').find_python()
+ endif
diff --git a/MesaLib/patches/patch-src_amd_common_ac__debug.c b/MesaLib/patches/patch-src_amd_common_ac__debug.c
new file mode 100644
index 0000000000..d74b5eeb3b
--- /dev/null
+++ b/MesaLib/patches/patch-src_amd_common_ac__debug.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_amd_common_ac__debug.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+#if'out some debug code on SunOS. There is no open_memstream(3)
+
+--- src/amd/common/ac_debug.c.orig	2019-01-17 11:26:22.000000000 +0000
++++ src/amd/common/ac_debug.c
+@@ -571,10 +571,12 @@ void ac_parse_ib_chunk(FILE *f, uint32_t
+ 
+ 	char *out;
+ 	size_t outsize;
++#if defined(HAVE_OPEN_MEMSTREAM)
+ 	FILE *memf = open_memstream(&out, &outsize);
+ 	ib.f = memf;
+ 	ac_do_parse_ib(memf, &ib);
+ 	fclose(memf);
++#endif
+ 
+ 	if (out) {
+ 		format_ib_output(f, out);
diff --git a/MesaLib/patches/patch-src_amd_vulkan_winsys_amdgpu_radv__amdgpu__cs.c b/MesaLib/patches/patch-src_amd_vulkan_winsys_amdgpu_radv__amdgpu__cs.c
new file mode 100644
index 0000000000..0de4957c4a
--- /dev/null
+++ b/MesaLib/patches/patch-src_amd_vulkan_winsys_amdgpu_radv__amdgpu__cs.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_amd_vulkan_winsys_amdgpu_radv__amdgpu__cs.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+Define ETIME if missing
+
+https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225415
+FreeBSD Bugzilla: Bug 225415 graphics/mesa-dri: update to 18.0.0 
+
+--- src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c.orig	2018-02-09 02:17:57.000000000 +0000
++++ src/amd/vulkan/winsys/amdgpu/radv_amdgpu_cs.c
+@@ -33,6 +33,9 @@
+ #include "radv_amdgpu_bo.h"
+ #include "sid.h"
+ 
++#ifndef ETIME
++#define ETIME ETIMEDOUT
++#endif
+ 
+ enum {
+ 	VIRTUAL_BUFFER_HASH_TABLE_SIZE = 1024
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..68dc8e41fc
--- /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.1 2019/08/21 13:35:28 nia Exp $
+
+Workaround netbsd 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_compiler_glsl_glsl__parser__extras.cpp b/MesaLib/patches/patch-src_compiler_glsl_glsl__parser__extras.cpp
new file mode 100644
index 0000000000..601a309ed8
--- /dev/null
+++ b/MesaLib/patches/patch-src_compiler_glsl_glsl__parser__extras.cpp
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_compiler_glsl_glsl__parser__extras.cpp,v 1.3 2019/08/21 13:35:28 nia Exp $
+
+atexit() is not a good idea in a library; use destructor attribute.
+
+--- src/compiler/glsl/glsl_parser_extras.cpp.orig	2017-09-25 16:56:18.000000000 +0000
++++ src/compiler/glsl/glsl_parser_extras.cpp
+@@ -2224,7 +2224,11 @@ extern "C" {
+  * programs would be invalid.  So this should happen at approximately
+  * program exit.
+  */
++#if defined(HAVE_NOATEXIT)
++void __attribute__((__destructor__))
++#else
+ void
++#endif
+ _mesa_destroy_shader_compiler(void)
+ {
+    _mesa_destroy_shader_compiler_caches();
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..f7f637a1e3
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__drm.c
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_egl_drivers_dri2_platform__drm.c,v 1.3 2019/08/21 13:35:28 nia Exp $
+
+netbsd-5 build fix
+
+--- src/egl/drivers/dri2/platform_drm.c.orig	2019-01-17 11:26:22.000000000 +0000
++++ src/egl/drivers/dri2/platform_drm.c
+@@ -725,7 +725,11 @@ dri2_initialize_drm(_EGLDriver *drv, _EG
+       }
+       dri2_dpy->own_device = true;
+    } else {
++#ifdef F_DUPFD_CLOEXEC
+       dri2_dpy->fd = fcntl(gbm_device_get_fd(gbm), F_DUPFD_CLOEXEC, 3);
++#else
++      dri2_dpy->fd = -1;
++#endif
+       if (dri2_dpy->fd < 0) {
+          err = "DRI2: failed to fcntl() existing gbm device";
+          goto cleanup;
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..89028fbb19
--- /dev/null
+++ b/MesaLib/patches/patch-src_egl_drivers_dri2_platform__x11.c
@@ -0,0 +1,60 @@
+$NetBSD: patch-src_egl_drivers_dri2_platform__x11.c,v 1.3 2019/08/21 13:35:28 nia Exp $
+
+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	2018-02-09 02:17:57.000000000 +0000
++++ src/egl/drivers/dri2/platform_x11.c
+@@ -608,6 +608,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)
+ {
+@@ -1466,8 +1483,15 @@ dri2_initialize_x11(_EGLDriver *drv, _EG
+ 
+    if (!disp->Options.ForceSoftware) {
+ #ifdef 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)) {
++         _eglLog(_EGL_INFO, "platform_x11.c: calling dri2_initialize_x11_dri3\n");
+          initialized = dri2_initialize_x11_dri3(drv, disp);
++         if (initialized)
++            _eglLog(_EGL_INFO, "platform_x11.c: initialized by dri2_initialize_x11_dri3\n");
++      }
+ #endif
+ 
+       if (!initialized)
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_drivers_trace_tr__dump.c b/MesaLib/patches/patch-src_gallium_auxiliary_drivers_trace_tr__dump.c
new file mode 100644
index 0000000000..7ee5c7f701
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_auxiliary_drivers_trace_tr__dump.c
@@ -0,0 +1,50 @@
+$NetBSD: patch-src_gallium_auxiliary_drivers_trace_tr__dump.c,v 1.1 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/gallium/auxiliary/driver_trace/tr_dump.c.orig	2018-09-07 21:18:07.000000000 +0000
++++ src/gallium/auxiliary/driver_trace/tr_dump.c
+@@ -63,7 +63,6 @@ static mtx_t call_mutex = _MTX_INITIALIZ
+ static long unsigned call_no = 0;
+ static boolean dumping = FALSE;
+ 
+-
+ static inline void
+ trace_dump_write(const char *buf, size_t size)
+ {
+@@ -171,9 +170,20 @@ trace_dump_trace_flush(void)
+    }
+ }
+ 
++#if defined(HAVE_NOATEXIT)
++static boolean trace_dump_has_begun = FALSE;
++
++static void __attribute__((__destructor__))
++#else
+ static void
++#endif
+ trace_dump_trace_close(void)
+ {
++#if defined(HAVE_NOATEXIT)
++   if (!trace_dump_has_begun)
++      return;
++#endif
++
+    if (stream) {
+       trace_dump_writes("</trace>\n");
+       if (close_stream) {
+@@ -233,7 +243,11 @@ trace_dump_trace_begin(void)
+        * screen multiple times, so we only write </trace> tag and close at exit
+        * time.
+        */
++#if defined(HAVE_NOATEXIT)
++      trace_dump_has_begun = TRUE;
++#else
+       atexit(trace_dump_trace_close);
++#endif
+    }
+ 
+    return TRUE;
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_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_radeonsi_si__state__shaders.c b/MesaLib/patches/patch-src_gallium_drivers_radeonsi_si__state__shaders.c
new file mode 100644
index 0000000000..367a9d7a3b
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_drivers_radeonsi_si__state__shaders.c
@@ -0,0 +1,21 @@
+$NetBSD: patch-src_gallium_drivers_radeonsi_si__state__shaders.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+#if'out some debug code on SunOS. There is no open_memstream(3)
+
+--- src/gallium/drivers/radeonsi/si_state_shaders.c.orig	2019-01-17 11:26:22.000000000 +0000
++++ src/gallium/drivers/radeonsi/si_state_shaders.c
+@@ -1721,12 +1721,14 @@ static void si_build_shader_variant(stru
+ 	}
+ 
+ 	if (shader->compiler_ctx_state.is_debug_context) {
++#if defined(HAVE_OPEN_MEMSTREAM)
+ 		FILE *f = open_memstream(&shader->shader_log,
+ 					 &shader->shader_log_size);
+ 		if (f) {
+ 			si_shader_dump(sscreen, shader, NULL, sel->type, f, false);
+ 			fclose(f);
+ 		}
++#endif
+ 	}
+ 
+ 	si_shader_init_pm4_state(sscreen, shader);
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_include_pipe_p__config.h b/MesaLib/patches/patch-src_gallium_include_pipe_p__config.h
new file mode 100644
index 0000000000..bf1f0ff5a9
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_include_pipe_p__config.h
@@ -0,0 +1,31 @@
+$NetBSD: patch-src_gallium_include_pipe_p__config.h,v 1.7 2019/08/21 13:35:28 nia Exp $
+
+* Patches for Sparc from FreeBSD ports for mesa-dri 17.2.3.
+
+* Definitions for DragonFly already in upstream source.
+
+--- src/gallium/include/pipe/p_config.h.orig	2017-10-19 12:23:53.000000000 +0000
++++ src/gallium/include/pipe/p_config.h
+@@ -77,6 +77,12 @@
+ #define PIPE_CC_ICL
+ #endif
+ 
++#if defined(__sparc__) || defined(__sparc64__)
++#define PIPE_ARCH_SPARC
++#if defined(__sparc64__)
++#define PIPE_ARCH_SPARC_64
++#endif
++#endif
+ 
+ /*
+  * Processor architecture
+@@ -131,7 +137,8 @@
+ 
+ #if defined(PIPE_ARCH_X86) || defined(PIPE_ARCH_X86_64) || defined(PIPE_ARCH_ARM) || defined(PIPE_ARCH_AARCH64)
+ #define PIPE_ARCH_LITTLE_ENDIAN
+-#elif defined(PIPE_ARCH_PPC) || defined(PIPE_ARCH_PPC_64) || defined(PIPE_ARCH_S390)
++#elif defined(PIPE_ARCH_PPC) || defined(PIPE_ARCH_PPC_64) || defined(PIPE_ARCH_S390) || defined(PIPE_ARCH_SPARC) || defined(PIPE_ARCH_SPARC_64)
++
+ #define PIPE_ARCH_BIG_ENDIAN
+ #endif
+ 
diff --git a/MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_invocation.cpp b/MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_invocation.cpp
new file mode 100644
index 0000000000..c7fd1cbf56
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_invocation.cpp
@@ -0,0 +1,40 @@
+$NetBSD: patch-src_gallium_state__trackers_clover_llvm_invocation.cpp,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+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/state_trackers/clover/llvm/invocation.cpp.orig	2018-09-07 21:18:07.000000000 +0000
++++ src/gallium/state_trackers/clover/llvm/invocation.cpp
+@@ -181,6 +181,10 @@ namespace {
+       return get_lang_standard_from_version_str(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::vector<std::string> &opts,
+@@ -193,8 +197,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 = dev.ir_target();
+       const std::string &device_clc_version = dev.device_clc_version();
diff --git a/MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_metadata.hpp b/MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_metadata.hpp
new file mode 100644
index 0000000000..299100b9e2
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_state__trackers_clover_llvm_metadata.hpp
@@ -0,0 +1,21 @@
+$NetBSD: patch-src_gallium_state__trackers_clover_llvm_metadata.hpp,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+From FreeBSD ports graphics/libGL mesa 13.0.5
+
+# Fix error: no matching constructor for initialization of 'std::vector<const ::llvm::MDNode *>' 
+#
+
+--- src/gallium/state_trackers/clover/llvm/metadata.hpp.orig	2017-02-13 11:55:49.000000000 +0000
++++ src/gallium/state_trackers/clover/llvm/metadata.hpp
+@@ -42,7 +42,11 @@ namespace clover {
+          get_kernel_nodes(const ::llvm::Module &mod) {
+             if (const ::llvm::NamedMDNode *n =
+                    mod.getNamedMetadata("opencl.kernels"))
++#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
++               return { n->getOperand(0), n->getOperand(n->getNumOperands()) };
++#else
+                return { n->op_begin(), n->op_end() };
++#endif
+             else
+                return {};
+          }
diff --git a/MesaLib/patches/patch-src_gallium_state__trackers_clover_util_range.hpp b/MesaLib/patches/patch-src_gallium_state__trackers_clover_util_range.hpp
new file mode 100644
index 0000000000..ab7f36bc66
--- /dev/null
+++ b/MesaLib/patches/patch-src_gallium_state__trackers_clover_util_range.hpp
@@ -0,0 +1,40 @@
+$NetBSD: patch-src_gallium_state__trackers_clover_util_range.hpp,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+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/state_trackers/clover/util/range.hpp.orig	2017-09-25 16:56:19.000000000 +0000
++++ src/gallium/state_trackers/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_apple_apple__glapi.c b/MesaLib/patches/patch-src_glx_apple_apple__glapi.c
new file mode 100644
index 0000000000..da2a9eec84
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_apple_apple__glapi.c
@@ -0,0 +1,24 @@
+$NetBSD: patch-src_glx_apple_apple__glapi.c,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+https://bugs.freedesktop.org/show_bug.cgi?id=90311
+See also hacks.mk.
+
+--- src/glx/apple/apple_glapi.c.orig	2018-02-09 02:17:59.000000000 +0000
++++ src/glx/apple/apple_glapi.c
+@@ -39,6 +39,7 @@
+ #include <GL/gl.h>
+ 
+ #include "main/glheader.h"
++#include "main/remap.h"
+ #include "glapi.h"
+ #include "glapitable.h"
+ 
+@@ -53,6 +54,8 @@ static void _apple_glapi_create_table(vo
+     if (__applegl_api)
+         return;
+ 
++    _mesa_init_remap_table(); 
++
+     __ogl_framework_api = _glapi_create_table_from_handle(apple_cgl_get_dl_handle(), "gl");
+     assert(__ogl_framework_api);
+ 
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_dri__glx.c b/MesaLib/patches/patch-src_glx_dri__glx.c
new file mode 100644
index 0000000000..64c785ec28
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_dri__glx.c
@@ -0,0 +1,43 @@
+$NetBSD: patch-src_glx_dri__glx.c,v 1.1 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/glx/dri_glx.c.orig	2018-01-18 21:30:28.000000000 +0000
++++ src/glx/dri_glx.c
+@@ -183,9 +183,21 @@ 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;
+@@ -276,7 +288,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_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..64ab042939
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_glxcurrent.c
@@ -0,0 +1,40 @@
+$NetBSD: patch-src_glx_glxcurrent.c,v 1.3 2019/08/21 13:35:28 nia 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	2018-02-09 02:17:59.000000000 +0000
++++ src/glx/glxcurrent.c
+@@ -40,6 +40,18 @@
+ #include "glx_error.h"
+ 
+ /*
++ * MASSIVE KLUDGE!
++ * We need these to not be extern in libGL.so because of
++ * PR toolchain/50277
++ */
++#if defined(GLX_USE_TLS) && defined(__NetBSD__)
++_X_EXPORT __thread struct _glapi_table * _glapi_tls_Dispatch
++    __attribute__((tls_model("initial-exec"))) = NULL;
++_X_EXPORT __thread void * _glapi_tls_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 +89,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..de73a6d69f
--- /dev/null
+++ b/MesaLib/patches/patch-src_glx_glxext.c
@@ -0,0 +1,47 @@
+$NetBSD: patch-src_glx_glxext.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+* 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	2017-12-08 13:49:11.000000000 +0000
++++ src/glx/glxext.c
+@@ -55,6 +55,7 @@
+ #include <xcb/xcb.h>
+ #include <xcb/glx.h>
+ 
++#include "dri_common.h"
+ 
+ #ifdef DEBUG
+ void __glXDumpDrawBuffer(struct glx_context * ctx);
+@@ -817,7 +818,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);
+@@ -920,8 +925,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 */
+       dpyPriv->dri2Display = dri2CreateDisplay(dpy);
+       dpyPriv->driDisplay = driCreateDisplay(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_isl_isl__tiled__memcpy.c b/MesaLib/patches/patch-src_intel_isl_isl__tiled__memcpy.c
new file mode 100644
index 0000000000..9935217aa4
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_isl_isl__tiled__memcpy.c
@@ -0,0 +1,22 @@
+$NetBSD$
+
+NetBSD has bswap32 in libc.
+
+--- src/intel/isl/isl_tiled_memcpy.c.orig	2019-08-07 16:39:17.000000000 +0000
++++ src/intel/isl/isl_tiled_memcpy.c
+@@ -64,6 +64,7 @@ ror(uint32_t n, uint32_t d)
+    return (n >> d) | (n << (32 - d));
+ }
+ 
++#ifndef __NetBSD__
+ static inline uint32_t
+ bswap32(uint32_t n)
+ {
+@@ -76,6 +77,7 @@ bswap32(uint32_t n)
+           (n << 24);
+ #endif
+ }
++#endif
+ 
+ /**
+  * Copy RGBA to BGRA - swap R and B.
diff --git a/MesaLib/patches/patch-src_intel_perf_gen__perf.h b/MesaLib/patches/patch-src_intel_perf_gen__perf.h
new file mode 100644
index 0000000000..8d7fd775d3
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_perf_gen__perf.h
@@ -0,0 +1,16 @@
+$NetBSD$
+
+for major() - sysmacros.h is non-portable
+
+--- src/intel/perf/gen_perf.h.orig	2019-08-07 16:39:17.000000000 +0000
++++ src/intel/perf/gen_perf.h
+@@ -28,7 +28,9 @@
+ #include <stdint.h>
+ #include <string.h>
+ 
++#ifdef __linux
+ #include <sys/sysmacros.h>
++#endif
+ 
+ #include "util/hash_table.h"
+ #include "util/ralloc.h"
diff --git a/MesaLib/patches/patch-src_intel_tools_aub__mem.c b/MesaLib/patches/patch-src_intel_tools_aub__mem.c
new file mode 100644
index 0000000000..2b60b68402
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_tools_aub__mem.c
@@ -0,0 +1,36 @@
+$NetBSD: patch-src_intel_tools_aub__mem.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+* Partially implement memfd_create() via mkostemp()
+
+--- src/intel/tools/aub_mem.c.orig	2018-12-11 21:13:57.000000000 +0000
++++ src/intel/tools/aub_mem.c
+@@ -34,7 +34,29 @@
+ static inline int
+ memfd_create(const char *name, unsigned int flags)
+ {
++#if defined(SYS_memfd_create)
+    return syscall(SYS_memfd_create, name, flags);
++#elif defined(__FreeBSD__)
++   return shm_open(SHM_ANON, flags | O_RDWR | O_CREAT, 0600);
++#else /* DragonFly, NetBSD, OpenBSD, Solaris */
++   char template[] = "/tmp/shmfd-XXXXXX";
++#ifdef HAVE_MKOSTEMP
++   int fd = mkostemp(template, flags);
++#else
++   int fd = mkstemp(template);
++   if (flags & O_CLOEXEC) {
++      int flags = fcntl(fd, F_GETFD);
++      if (flags != -1) {
++         flags |= FD_CLOEXEC;
++         (void) fcntl(fd, F_SETFD, &flags);
++      }
++   }
++#endif /* HAVE_MKOSTEMP */
++   if (fd >= 0)
++      unlink(template);
++
++   return fd;
++#endif /* __linux__ */
+ }
+ #endif
+ 
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_intel_vulkan_anv__allocator.c b/MesaLib/patches/patch-src_intel_vulkan_anv__allocator.c
new file mode 100644
index 0000000000..cfa79dcfd3
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_vulkan_anv__allocator.c
@@ -0,0 +1,62 @@
+$NetBSD: patch-src_intel_vulkan_anv__allocator.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+* Partially implement memfd_create() via mkostemp()
+* Ignore MAP_POPULATE if unsupported
+
+FreeBSD Bugzilla - Bug 225415: graphics/mesa-dri: update to 18.0.0
+https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225415
+
+--- src/intel/vulkan/anv_allocator.c.orig	2018-02-09 02:17:59.000000000 +0000
++++ src/intel/vulkan/anv_allocator.c
+@@ -25,9 +25,21 @@
+ #include <unistd.h>
+ #include <limits.h>
+ #include <assert.h>
++#ifdef __linux__
+ #include <linux/memfd.h>
++#else
++#include <fcntl.h>
++#endif
+ #include <sys/mman.h>
+ 
++#ifndef MAP_POPULATE
++#define MAP_POPULATE 0
++#endif
++
++#ifndef MFD_CLOEXEC
++#define MFD_CLOEXEC O_CLOEXEC
++#endif
++
+ #include "anv_private.h"
+ 
+ #include "util/hash_table.h"
+@@ -113,7 +125,29 @@ struct anv_mmap_cleanup {
+ static inline int
+ memfd_create(const char *name, unsigned int flags)
+ {
++#if defined(SYS_memfd_create)
+    return syscall(SYS_memfd_create, name, flags);
++#elif defined(__FreeBSD__)
++   return shm_open(SHM_ANON, flags | O_RDWR | O_CREAT, 0600);
++#else /* DragonFly, NetBSD, OpenBSD, Solaris */
++   char template[] = "/tmp/shmfd-XXXXXX";
++#ifdef HAVE_MKOSTEMP
++   int fd = mkostemp(template, flags);
++#else
++   int fd = mkstemp(template);
++   if (flags & O_CLOEXEC) {
++      int flags = fcntl(fd, F_GETFD);
++      if (flags != -1) {
++         flags |= FD_CLOEXEC;
++         (void) fcntl(fd, F_SETFD, &flags);
++      }
++   }
++#endif /* HAVE_MKOSTEMP */
++   if (fd >= 0)
++      unlink(template);
++
++   return fd;
++#endif /* __linux__ */
+ }
+ #endif
+ 
diff --git a/MesaLib/patches/patch-src_intel_vulkan_anv__gem.c b/MesaLib/patches/patch-src_intel_vulkan_anv__gem.c
new file mode 100644
index 0000000000..ce1d1cc380
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_vulkan_anv__gem.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_intel_vulkan_anv__gem.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+* Define ETIME if missing
+
+FreeBSD Bugzilla - Bug 225415: graphics/mesa-dri: update to 18.0.0
+https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225415
+
+--- src/intel/vulkan/anv_gem.c.orig	2018-02-09 02:17:59.000000000 +0000
++++ src/intel/vulkan/anv_gem.c
+@@ -26,6 +26,9 @@
+ #include <sys/mman.h>
+ #include <string.h>
+ #include <errno.h>
++#ifndef ETIME
++#define ETIME ETIMEDOUT
++#endif
+ #include <unistd.h>
+ #include <fcntl.h>
+ 
diff --git a/MesaLib/patches/patch-src_intel_vulkan_anv__gem__stubs.c b/MesaLib/patches/patch-src_intel_vulkan_anv__gem__stubs.c
new file mode 100644
index 0000000000..2830b96bbb
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_vulkan_anv__gem__stubs.c
@@ -0,0 +1,36 @@
+$NetBSD: patch-src_intel_vulkan_anv__gem__stubs.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+* Partially implement memfd_create() via mkostemp()
+
+--- src/intel/vulkan/anv_gem_stubs.c.orig	2018-12-11 21:13:57.000000000 +0000
++++ src/intel/vulkan/anv_gem_stubs.c
+@@ -31,7 +31,29 @@
+ static inline int
+ memfd_create(const char *name, unsigned int flags)
+ {
++#if defined(SYS_memfd_create)
+    return syscall(SYS_memfd_create, name, flags);
++#elif defined(__FreeBSD__)
++   return shm_open(SHM_ANON, flags | O_RDWR | O_CREAT, 0600);
++#else /* DragonFly, NetBSD, OpenBSD, Solaris */
++   char template[] = "/tmp/shmfd-XXXXXX";
++#ifdef HAVE_MKOSTEMP
++   int fd = mkostemp(template, flags);
++#else
++   int fd = mkstemp(template);
++   if (flags & O_CLOEXEC) {
++      int flags = fcntl(fd, F_GETFD);
++      if (flags != -1) {
++         flags |= FD_CLOEXEC;
++         (void) fcntl(fd, F_SETFD, &flags);
++      }
++   }
++#endif /* HAVE_MKOSTEMP */
++   if (fd >= 0)
++      unlink(template);
++
++   return fd;
++#endif /* __linux__ */
+ }
+ #endif
+ 
diff --git a/MesaLib/patches/patch-src_intel_vulkan_anv__queue.c b/MesaLib/patches/patch-src_intel_vulkan_anv__queue.c
new file mode 100644
index 0000000000..08ec063ab9
--- /dev/null
+++ b/MesaLib/patches/patch-src_intel_vulkan_anv__queue.c
@@ -0,0 +1,25 @@
+$NetBSD: patch-src_intel_vulkan_anv__queue.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+* Define ETIME if missing
+* Drop header that was never used (modified for Linux inclusion)
+
+FreeBSD Bugzilla - Bug 225415: graphics/mesa-dri: update to 18.0.0
+https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=225415
+
+--- src/intel/vulkan/anv_queue.c.orig	2018-02-09 02:17:59.000000000 +0000
++++ src/intel/vulkan/anv_queue.c
+@@ -26,8 +26,14 @@
+  */
+ 
+ #include <fcntl.h>
++#include <errno.h>
++#ifndef ETIME
++#define ETIME ETIMEDOUT
++#endif
+ #include <unistd.h>
++#if defined(__linux__)
+ #include <sys/eventfd.h>
++#endif
+ 
+ #include "anv_private.h"
+ #include "vk_util.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..4e518294f0
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_entry__x86-64__tls.h
@@ -0,0 +1,32 @@
+$NetBSD: patch-src_mapi_entry__x86-64__tls.h,v 1.3 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.
+
+Fix --enable-glx-tls with clang. From FreeBSD.
+
+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	2017-11-20 14:25:47.000000000 +0000
++++ src/mapi/entry_x86-64_tls.h
+@@ -43,10 +43,19 @@ __asm__(".text\n"
+ 
+ #ifndef __ILP32__
+ 
++#if defined(__NetBSD__) && defined(MAPI_MODE_GLAPI)
+ #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"                                \
++   "cmoveq table_noop_array@GOTPCREL(%rip), %r11\n\t"    \
+    "jmp *(8 * " slot ")(%r11)"
++#else
++#define STUB_ASM_CODE(slot)                              \
++   "movq " ENTRY_CURRENT_TABLE "@GOTTPOFF(%rip), %rax\n\t"  \
++   "movq %fs:(%rax), %r11\n\t"                           \
++   "jmp *(8 * " slot ")(%r11)"
++#endif
+ 
+ #else
+ 
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..5017607762
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_entry__x86__tls.h
@@ -0,0 +1,40 @@
+$NetBSD: patch-src_mapi_entry__x86__tls.h,v 1.3 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.
+
+Fix --enable-glx-tls with clang. From FreeBSD.
+
+table_noop_array is only defined for shared-glapi.
+es1api and es2api are not going to be patched for NetBSD.
+
+--- src/mapi/entry_x86_tls.h.orig	2018-01-18 21:30:29.000000000 +0000
++++ src/mapi/entry_x86_tls.h
+@@ -56,10 +56,27 @@ __asm__(".balign 16\n"
+    ".balign 16\n"                \
+    func ":"
+ 
++#if defined(__NetBSD__) && defined(MAPI_MODE_GLAPI)
++extern const mapi_func table_noop_array[];
+ #define STUB_ASM_CODE(slot)      \
+    "call x86_current_tls\n\t"    \
+    "movl %gs:(%eax), %eax\n\t"   \
++   "testl %eax, %eax\n\t"        \
++   "je 1f\n\t"                   \
++   "jmp *(4 * " slot ")(%eax)\n\t" \
++   "1:\n\t"                      \
++   "call 2f\n"                   \
++   "2:\n\t"                      \
++   "popl %eax\n\t"               \
++   "addl $_GLOBAL_OFFSET_TABLE_+[.-1b], %eax\n\t" \
++   "movl table_noop_array@GOT(%eax), %eax\n\t" \
+    "jmp *(4 * " slot ")(%eax)"
++#else
++#define STUB_ASM_CODE(slot)      \
++   "call x86_current_tls\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..35e726a55b
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_u__current.c
@@ -0,0 +1,31 @@
+$NetBSD: patch-src_mapi_u__current.c,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/mapi/u_current.c.orig	2015-09-02 17:06:23.000000000 +0000
++++ src/mapi/u_current.c
+@@ -101,7 +101,11 @@ extern void (*__glapi_noop_table[])(void
+ 
+ __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")));
+@@ -283,7 +287,11 @@ struct _glapi_table *
+ u_current_get_table_internal(void)
+ {
+ #if defined(GLX_USE_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_mapi_u__current.h b/MesaLib/patches/patch-src_mapi_u__current.h
new file mode 100644
index 0000000000..7e1f7aed16
--- /dev/null
+++ b/MesaLib/patches/patch-src_mapi_u__current.h
@@ -0,0 +1,16 @@
+$NetBSD: patch-src_mapi_u__current.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/mapi/u_current.h.orig	2015-09-02 17:06:23.000000000 +0000
++++ src/mapi/u_current.h
+@@ -68,7 +68,7 @@ u_current_get_context_internal(void);
+ static inline const struct _glapi_table *
+ u_current_get_table(void)
+ {
+-#ifdef GLX_USE_TLS
++#if defined(GLX_USE_TLS) && !defined(__NetBSD__)
+    return u_current_table;
+ #else
+    return (likely(u_current_table) ?
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c b/MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c
new file mode 100644
index 0000000000..c94f15b34e
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_i915_intel__screen.c
@@ -0,0 +1,44 @@
+$NetBSD: patch-src_mesa_drivers_dri_i915_intel__screen.c,v 1.3 2019/08/21 13:35:28 nia Exp $
+
+Move sys/sysctl.h include because on NetBSD, sysctl.h includes sys/param.h,
+and sys/param.h defines a one argument ALIGN.  Allows mesa to redefine
+to a two argument ALIGN.
+
+Fix build on older NetBSD w/o _SC_PHYS_PAGES.
+
+--- src/mesa/drivers/dri/i915/intel_screen.c.orig	2017-11-10 23:18:56.000000000 +0000
++++ src/mesa/drivers/dri/i915/intel_screen.c
+@@ -28,6 +28,11 @@
+ #include <errno.h>
+ #include <time.h>
+ #include <unistd.h>
++
++#if defined(HAVE_SYS_SYSCTL_H) && defined(__NetBSD__)
++# include <sys/sysctl.h>
++#endif
++
+ #include "main/glheader.h"
+ #include "main/context.h"
+ #include "main/framebuffer.h"
+@@ -739,6 +744,13 @@ i915_query_renderer_integer(__DRIscreen
+       const unsigned gpu_mappable_megabytes =
+          (aper_size / (1024 * 1024)) * 3 / 4;
+ 
++#if defined(HW_PHYSMEM64) && defined(__NetBSD__)
++      int mib[2] = { CTL_HW, HW_PHYSMEM64 };
++      uint64_t system_memory_bytes;
++      size_t len = sizeof(system_memory_bytes);
++      if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
++         return -1;
++#else
+       const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
+       const long system_page_size = sysconf(_SC_PAGE_SIZE);
+ 
+@@ -747,6 +759,7 @@ i915_query_renderer_integer(__DRIscreen
+ 
+       const uint64_t system_memory_bytes = (uint64_t) system_memory_pages
+          * (uint64_t) system_page_size;
++#endif
+ 
+       const unsigned system_memory_megabytes =
+          (unsigned) (system_memory_bytes / (1024 * 1024));
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c b/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c
new file mode 100644
index 0000000000..623c118848
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_i965_intel__screen.c
@@ -0,0 +1,44 @@
+$NetBSD: patch-src_mesa_drivers_dri_i965_intel__screen.c,v 1.3 2019/08/21 13:35:28 nia Exp $
+
+Move sys/sysctl.h include because on NetBSD, sysctl.h includes sys/param.h,
+and sys/param.h defines a one argument ALIGN.  Allows mesa to redefine
+to a two argument ALIGN.
+
+Fix build on older NetBSD w/o _SC_PHYS_PAGES.
+
+--- src/mesa/drivers/dri/i965/intel_screen.c.orig	2017-11-10 23:18:56.000000000 +0000
++++ src/mesa/drivers/dri/i965/intel_screen.c
+@@ -27,6 +27,11 @@
+ #include <errno.h>
+ #include <time.h>
+ #include <unistd.h>
++
++#if defined(HAVE_SYS_SYSCTL_H) && defined(__NetBSD__)
++# include <sys/sysctl.h>
++#endif
++
+ #include "main/context.h"
+ #include "main/framebuffer.h"
+ #include "main/renderbuffer.h"
+@@ -1220,6 +1225,13 @@ brw_query_renderer_integer(__DRIscreen *
+       const unsigned gpu_mappable_megabytes =
+          screen->aperture_threshold / (1024 * 1024);
+ 
++#if defined(HW_PHYSMEM64) && defined(__NetBSD__)
++      int mib[2] = { CTL_HW, HW_PHYSMEM64 };
++      const uint64_t system_memory_bytes;
++      size_t len = sizeof(system_memory_bytes);
++      if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
++         return -1;
++#else
+       const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
+       const long system_page_size = sysconf(_SC_PAGE_SIZE);
+ 
+@@ -1228,6 +1240,7 @@ brw_query_renderer_integer(__DRIscreen *
+ 
+       const uint64_t system_memory_bytes = (uint64_t) system_memory_pages
+          * (uint64_t) system_page_size;
++#endif
+ 
+       const unsigned system_memory_megabytes =
+          (unsigned) (system_memory_bytes / (1024 * 1024));
diff --git a/MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c b/MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c
new file mode 100644
index 0000000000..640e775262
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_drivers_dri_swrast_swrast.c
@@ -0,0 +1,19 @@
+$NetBSD: patch-src_mesa_drivers_dri_swrast_swrast.c,v 1.3 2019/08/21 13:35:28 nia Exp $
+
+Fix build on older NetBSD w/o _SC_PHYS_PAGES.
+
+--- src/mesa/drivers/dri/swrast/swrast.c.orig	2017-10-19 12:23:53.000000000 +0000
++++ src/mesa/drivers/dri/swrast/swrast.c
+@@ -151,6 +151,12 @@ swrast_query_renderer_integer(__DRIscree
+         size_t len = sizeof(system_memory_bytes);
+         if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
+             return -1;
++#elif defined(HW_PHYSMEM64) && defined(__NetBSD__)
++        int mib[2] = { CTL_HW, HW_PHYSMEM64 };
++        uint64_t system_memory_bytes;
++        size_t len = sizeof(system_memory_bytes);
++        if (sysctl(mib, 2, &system_memory_bytes, &len, NULL, 0) != 0)
++            return -1;
+ #elif defined(_SC_PHYS_PAGES) && defined(_SC_PAGE_SIZE)
+       /* XXX: Do we want to return the full amount of system memory ? */
+       const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
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..c1983bdc91
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_extensions.c
@@ -0,0 +1,31 @@
+$NetBSD: patch-src_mesa_main_extensions.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/mesa/main/extensions.c.orig	2018-02-09 02:17:59.000000000 +0000
++++ src/mesa/main/extensions.c
+@@ -203,7 +203,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);
+@@ -293,7 +297,9 @@ _mesa_one_time_init_extension_overrides(
+       free(env);
+    } else {
+       unrecognized_extensions = env;
++#if !defined(HAVE_NOATEXIT)
+       atexit(free_unknown_extensions_strings);
++#endif
+    }
+ }
+ 
diff --git a/MesaLib/patches/patch-src_mesa_main_macros.h b/MesaLib/patches/patch-src_mesa_main_macros.h
new file mode 100644
index 0000000000..fdda0491be
--- /dev/null
+++ b/MesaLib/patches/patch-src_mesa_main_macros.h
@@ -0,0 +1,18 @@
+$NetBSD: patch-src_mesa_main_macros.h,v 1.2 2019/08/21 13:35:28 nia Exp $
+
+ALIGN is also defined in sys/param.h on NetBSD.
+
+Extend undefining ALIGN to all other OSes.
+
+--- src/mesa/main/macros.h.orig	2017-11-10 23:18:56.000000000 +0000
++++ src/mesa/main/macros.h
+@@ -677,6 +677,9 @@ minify(unsigned value, unsigned levels)
+  *
+  * \sa ROUND_DOWN_TO()
+  */
++#ifdef ALIGN
++#undef ALIGN
++#endif
+ static inline uintptr_t
+ ALIGN(uintptr_t value, int32_t alignment)
+ {
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_disk__cache.c b/MesaLib/patches/patch-src_util_disk__cache.c
new file mode 100644
index 0000000000..61bb4fcb7c
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_disk__cache.c
@@ -0,0 +1,29 @@
+$NetBSD: patch-src_util_disk__cache.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+Use fcntl() on SunOS.
+
+--- src/util/disk_cache.c.orig	2018-09-07 21:18:07.000000000 +0000
++++ src/util/disk_cache.c
+@@ -857,6 +857,9 @@ cache_put(void *job, int thread_index)
+    unsigned i = 0;
+    char *filename = NULL, *filename_tmp = NULL;
+    struct disk_cache_put_job *dc_job = (struct disk_cache_put_job *) job;
++#ifdef __sun
++   struct flock lock = {0};
++#endif
+ 
+    filename = get_cache_file(dc_job->cache, dc_job->key);
+    if (filename == NULL)
+@@ -895,7 +898,12 @@ cache_put(void *job, int thread_index)
+     * open with the flock held. So just let that file be responsible
+     * for writing the file.
+     */
++#ifdef __sun
++   lock.l_type = F_WRLCK;
++   err = fcntl(fd, F_SETLK, &lock);
++#else
+    err = flock(fd, LOCK_EX | LOCK_NB);
++#endif
+    if (err == -1)
+       goto done;
+ 
diff --git a/MesaLib/patches/patch-src_util_ralloc.c b/MesaLib/patches/patch-src_util_ralloc.c
new file mode 100644
index 0000000000..7cb2344d99
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_ralloc.c
@@ -0,0 +1,25 @@
+$NetBSD: patch-src_util_ralloc.c,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+FreeBSD reported atexit bug for 10.6:
+https://bugs.freedesktop.org/show_bug.cgi?id=91869
+
+* Fix exit time segfault of qt5 application with modular xorg
+* Provide compat strnlen for older Darwin.
+
+--- src/util/ralloc.c.orig	2017-05-10 14:13:58.000000000 +0000
++++ src/util/ralloc.c
+@@ -368,7 +368,14 @@ ralloc_strndup(const void *ctx, const ch
+    if (unlikely(str == NULL))
+       return NULL;
+ 
++#if (defined(__APPLE__) && __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 < 1070)
++   for (n = 0; n < max; n++, str++) {
++     if (!*str)
++       break;
++   }
++#else
+    n = strnlen(str, max);
++#endif
+    ptr = ralloc_array(ctx, char, n + 1);
+    memcpy(ptr, str, n);
+    ptr[n] = '\0';
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..f5b7c0b57f
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_u__queue.c
@@ -0,0 +1,70 @@
+$NetBSD: patch-src_util_u__queue.c,v 1.1 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/util/u_queue.c.orig	2018-12-11 21:13:57.000000000 +0000
++++ src/util/u_queue.c
+@@ -46,11 +46,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) {
+@@ -63,7 +74,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
+@@ -244,12 +259,25 @@ util_queue_thread_func(void *input)
+       /* Don't inherit the thread affinity from the parent thread.
+        * Set the full mask.
+        */
++#if defined(__NetBSD__)
++      cpuset_t *cpuset;
++      cpuset = cpuset_create();
++      if (cpuset != NULL) {
++         cpuset_zero(cpuset);
++         for (unsigned i = 0; i < cpuset_size(cpuset); i++)
++            cpuset_set(i, cpuset);
++
++         pthread_setaffinity_np(pthread_self(), cpuset_size(cpuset), cpuset);
++         cpuset_destroy(cpuset);
++      }
++#else
+       cpu_set_t cpuset;
+       CPU_ZERO(&cpuset);
+       for (unsigned i = 0; i < CPU_SETSIZE; i++)
+          CPU_SET(i, &cpuset);
+ 
+       pthread_setaffinity_np(pthread_self(), sizeof(cpuset), &cpuset);
++#endif
+    }
+ #endif
+ 
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..d53cde5bc8
--- /dev/null
+++ b/MesaLib/patches/patch-src_util_u__thread.h
@@ -0,0 +1,76 @@
+$NetBSD: patch-src_util_u__thread.h,v 1.1 2019/08/21 13:35:28 nia Exp $
+
+handle NetBSD-style pthread_setaffinity_np(3)
+
+--- src/util/u_thread.h.orig	2018-12-11 21:13:57.000000000 +0000
++++ src/util/u_thread.h
+@@ -83,6 +83,17 @@ static inline void
+ util_pin_thread_to_L3(thrd_t thread, unsigned L3_index, unsigned cores_per_L3)
+ {
+ #if defined(HAVE_PTHREAD_SETAFFINITY)
++#if defined(__NetBSD__)
++   cpuset_t *cpuset;
++   cpuset = cpuset_create();
++   if (cpuset == NULL)
++      return;
++   cpuset_zero(cpuset);
++   for (unsigned i = 0; i < cores_per_L3; i++)
++      cpuset_set(L3_index * cores_per_L3 + i, cpuset);
++   pthread_setaffinity_np(thread, cpuset_size(cpuset), cpuset);
++   cpuset_destroy(cpuset);
++#else
+    cpu_set_t cpuset;
+ 
+    CPU_ZERO(&cpuset);
+@@ -90,6 +101,7 @@ util_pin_thread_to_L3(thrd_t thread, uns
+       CPU_SET(L3_index * cores_per_L3 + i, &cpuset);
+    pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
+ #endif
++#endif
+ }
+ 
+ /**
+@@ -103,6 +115,35 @@ static inline int
+ util_get_L3_for_pinned_thread(thrd_t thread, unsigned cores_per_L3)
+ {
+ #if defined(HAVE_PTHREAD_SETAFFINITY)
++#if defined(__NetBSD__)
++   cpuset_t *cpuset;
++
++   cpuset = cpuset_create();
++   if (cpuset == NULL)
++      return -1;
++
++   if (pthread_getaffinity_np(thread, cpuset_size(cpuset), cpuset) == 0) {
++      int L3_index = -1;
++
++      for (unsigned i = 0; i < cpuset_size(cpuset); i++) {
++         if (cpuset_isset(i, cpuset)) {
++            int x = i / cores_per_L3;
++
++            if (L3_index != x) {
++               if (L3_index == -1)
++                  L3_index = x;
++               else {
++                  cpuset_destroy(cpuset);
++                  return -1; /* multiple L3s are set */
++               }
++            }
++         }
++      }
++      cpuset_destroy(cpuset);
++      return L3_index;
++   }
++   cpuset_destroy(cpuset);
++#else
+    cpu_set_t cpuset;
+ 
+    if (pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset) == 0) {
+@@ -123,6 +164,7 @@ util_get_L3_for_pinned_thread(thrd_t thr
+       return L3_index;
+    }
+ #endif
++#endif
+    return -1;
+ }
+ 


Home | Main Index | Thread Index | Old Index