[2/2] meson: make "auto" only choose buildable drivers

Submitted by Alyssa Ross on July 18, 2019, 2:15 p.m.

Details

Message ID 20190718141530.9174-3-hi@alyssa.is
State New
Headers show
Series "meson: improve configuration experience" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Alyssa Ross July 18, 2019, 2:15 p.m.
"auto" pays attention to the OS and architecture of the target system,
but not the available libraries. If, say, libdrm isn't available, "auto"
won't work, and a manual list of drivers will be required anyway. It
would also try building the virgl and svga gallium drivers, even when
unsupported due to building with EGL and no compatible platform.

This wasn't a lot of code to implement, but it required moving around
various parts of meson.build so that the necessary information was
available in the right place.
---
 meson.build | 183 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 113 insertions(+), 70 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meson.build b/meson.build
index 52dd5be25e7..f25bbc92bfa 100644
--- a/meson.build
+++ b/meson.build
@@ -108,12 +108,30 @@  with_shared_glapi = get_option('shared-glapi') and with_any_opengl
 
 system_has_kms_drm = ['openbsd', 'netbsd', 'freebsd', 'gnu/kfreebsd', 'dragonfly', 'linux'].contains(host_machine.system())
 
+_drm_amdgpu_ver = '2.4.97'
+_drm_radeon_ver = '2.4.71'
+_drm_nouveau_ver = '2.4.66'
+_drm_intel_ver = '2.4.75'
+_drm_ver = '2.4.75'
+
 dri_drivers = get_option('dri-drivers')
 if dri_drivers.contains('auto')
   if system_has_kms_drm
     # TODO: PPC, Sparc
     if ['x86', 'x86_64'].contains(host_machine.cpu_family())
-      dri_drivers = ['i915', 'i965', 'r100', 'r200', 'nouveau']
+      dri_drivers = []
+      if dependency('libdrm_intel', version : '>=' + _drm_intel_ver, required : false).found()
+        dri_drivers += 'i915'
+      endif
+      if dependency('libdrm', version : '>=' + _drm_ver, required : false).found()
+        dri_drivers += 'i965'
+      endif
+      if dependency('libdrm_radeon', version : '>=' + _drm_radeon_ver, required : false).found()
+        dri_drivers += ['r100', 'r200']
+      endif
+      if dependency('libdrm_nouveau', version : '>=' + _drm_nouveau_ver, required : false).found()
+        dri_drivers += 'nouveau'
+      endif
     elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
       dri_drivers = []
     else
@@ -139,55 +157,6 @@  with_dri_swrast = dri_drivers.contains('swrast')
 with_dri = dri_drivers.length() != 0 and dri_drivers != ['']
 
 gallium_drivers = get_option('gallium-drivers')
-if gallium_drivers.contains('auto')
-  if system_has_kms_drm
-    # TODO: PPC, Sparc
-    if ['x86', 'x86_64'].contains(host_machine.cpu_family())
-      gallium_drivers = [
-        'r300', 'r600', 'radeonsi', 'nouveau', 'virgl', 'svga', 'swrast'
-      ]
-    elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
-      gallium_drivers = [
-        'kmsro', 'v3d', 'vc4', 'freedreno', 'etnaviv', 'nouveau',
-        'tegra', 'virgl', 'lima', 'swrast'
-      ]
-    else
-      error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
-            host_machine.cpu_family()))
-    endif
-  elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
-    gallium_drivers = ['swrast']
-  else
-    error('Unknown OS @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
-          host_machine.system()))
-  endif
-endif
-with_gallium_kmsro = gallium_drivers.contains('kmsro')
-with_gallium_radeonsi = gallium_drivers.contains('radeonsi')
-with_gallium_r300 = gallium_drivers.contains('r300')
-with_gallium_r600 = gallium_drivers.contains('r600')
-with_gallium_nouveau = gallium_drivers.contains('nouveau')
-with_gallium_freedreno = gallium_drivers.contains('freedreno')
-with_gallium_softpipe = gallium_drivers.contains('swrast')
-with_gallium_vc4 = gallium_drivers.contains('vc4')
-with_gallium_v3d = gallium_drivers.contains('v3d')
-with_gallium_panfrost = gallium_drivers.contains('panfrost')
-with_gallium_etnaviv = gallium_drivers.contains('etnaviv')
-with_gallium_tegra = gallium_drivers.contains('tegra')
-with_gallium_iris = gallium_drivers.contains('iris')
-with_gallium_i915 = gallium_drivers.contains('i915')
-with_gallium_svga = gallium_drivers.contains('svga')
-with_gallium_virgl = gallium_drivers.contains('virgl')
-with_gallium_swr = gallium_drivers.contains('swr')
-with_gallium_lima = gallium_drivers.contains('lima')
-
-if cc.get_id() == 'intel'
-  if meson.version().version_compare('< 0.49.0')
-    error('Meson does not have sufficient support of ICC before 0.49.0 to compile mesa')
-  elif with_gallium_swr and meson.version().version_compare('== 0.49.0')
-    warning('Meson as of 0.49.0 is sufficient for compiling mesa with ICC, but there are some caveats with SWR. 0.49.1 should resolve all of these')
-  endif
-endif
 
 with_gallium = gallium_drivers.length() != 0 and gallium_drivers != ['']
 
@@ -203,7 +172,13 @@  _vulkan_drivers = get_option('vulkan-drivers')
 if _vulkan_drivers.contains('auto')
   if system_has_kms_drm
     if host_machine.cpu_family().startswith('x86')
-      _vulkan_drivers = ['amd', 'intel']
+      _vulkan_drivers = []
+      if dependency('libdrm_amdgpu', version : '>=' + _drm_amdgpu_ver, required : false).found()
+        _vulkan_drivers += 'amd'
+      endif
+      if dependency('libdrm', version : '>=' + _drm_ver, required : false).found()
+        _vulkan_drivers += 'intel'
+      endif
     elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
       _vulkan_drivers = []
     else
@@ -228,19 +203,6 @@  if with_freedreno_vk and get_option('I-love-half-baked-turnips') != true
   error('Cannot enable freedreno vulkan driver')
 endif
 
-if with_dri_swrast and (with_gallium_softpipe or with_gallium_swr)
-  error('Only one swrast provider can be built')
-endif
-if with_dri_i915 and with_gallium_i915
-  error('Only one i915 provider can be built')
-endif
-if with_gallium_kmsro and not (with_gallium_v3d or with_gallium_vc4 or with_gallium_etnaviv or with_gallium_freedreno or with_gallium_panfrost or with_gallium_lima)
-  error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, freedreno, panfrost, lima)')
-endif
-if with_gallium_tegra and not with_gallium_nouveau
-  error('tegra driver requires nouveau driver')
-endif
-
 if host_machine.system() == 'darwin'
   with_dri_platform = 'apple'
 elif ['windows', 'cygwin'].contains(host_machine.system())
@@ -356,6 +318,93 @@  else
   with_egl = false
 endif
 
+if gallium_drivers.contains('auto')
+  if system_has_kms_drm
+    # TODO: PPC, Sparc
+    if ['x86', 'x86_64'].contains(host_machine.cpu_family())
+      gallium_drivers = ['swrast']
+      if dependency('libdrm', version : '>=' + _drm_ver, required : false).found()
+        gallium_drivers += 'svga'
+        if not with_egl or with_platform_drm or with_platform_surfaceless or with_platform_android
+          gallium_drivers += 'virgl'
+        endif
+      endif
+      if dependency('libdrm_nouveau', version : '>=' + _drm_nouveau_ver, required : false).found()
+        gallium_drivers += 'nouveau'
+      endif
+      if dependency('libdrm_amdgpu', version : '>=' + _drm_amdgpu_ver, required : false).found()
+        if not with_egl or with_platform_drm or with_platform_surfaceless or with_platform_android
+          gallium_drivers += 'radeonsi'
+        endif
+      endif
+      if dependency('libdrm_radeon', version : '>=' + _drm_radeon_ver, required : false).found()
+        gallium_drivers += ['r300', 'r600']
+      endif
+    elif ['arm', 'aarch64'].contains(host_machine.cpu_family())
+      gallium_drivers = ['swrast']
+      if dependency('libdrm', version : '>= 2.4.89', required : false).found()
+        gallium_drivers += ['vc4', 'etnaviv']
+      endif
+      if dependency('libdrm_nouveau', version : '>=' + _drm_nouveau_ver, required : false).found()
+        gallium_drivers += ['nouveau', 'tegra']
+      endif
+      if dependency('libdrm', version : '>=' + _drm_ver, required : false).found()
+        gallium_drivers += ['kmsro', 'lima', 'freedreno', 'v3d']
+        if not with_egl or with_platform_drm or with_platform_surfaceless or with_platform_android
+          gallium_drivers += 'virgl'
+        endif
+      endif
+    else
+      error('Unknown architecture @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
+            host_machine.cpu_family()))
+    endif
+  elif ['darwin', 'windows', 'cygwin', 'haiku'].contains(host_machine.system())
+    gallium_drivers = ['swrast']
+  else
+    error('Unknown OS @0@. Please pass -Dgallium-drivers to set driver options. Patches gladly accepted to fix this.'.format(
+          host_machine.system()))
+  endif
+endif
+with_gallium_kmsro = gallium_drivers.contains('kmsro')
+with_gallium_radeonsi = gallium_drivers.contains('radeonsi')
+with_gallium_r300 = gallium_drivers.contains('r300')
+with_gallium_r600 = gallium_drivers.contains('r600')
+with_gallium_nouveau = gallium_drivers.contains('nouveau')
+with_gallium_freedreno = gallium_drivers.contains('freedreno')
+with_gallium_softpipe = gallium_drivers.contains('swrast')
+with_gallium_vc4 = gallium_drivers.contains('vc4')
+with_gallium_v3d = gallium_drivers.contains('v3d')
+with_gallium_panfrost = gallium_drivers.contains('panfrost')
+with_gallium_etnaviv = gallium_drivers.contains('etnaviv')
+with_gallium_tegra = gallium_drivers.contains('tegra')
+with_gallium_iris = gallium_drivers.contains('iris')
+with_gallium_i915 = gallium_drivers.contains('i915')
+with_gallium_svga = gallium_drivers.contains('svga')
+with_gallium_virgl = gallium_drivers.contains('virgl')
+with_gallium_swr = gallium_drivers.contains('swr')
+with_gallium_lima = gallium_drivers.contains('lima')
+
+if cc.get_id() == 'intel'
+  if meson.version().version_compare('< 0.49.0')
+    error('Meson does not have sufficient support of ICC before 0.49.0 to compile mesa')
+  elif with_gallium_swr and meson.version().version_compare('== 0.49.0')
+    warning('Meson as of 0.49.0 is sufficient for compiling mesa with ICC, but there are some caveats with SWR. 0.49.1 should resolve all of these')
+  endif
+endif
+
+if with_dri_swrast and (with_gallium_softpipe or with_gallium_swr)
+  error('Only one swrast provider can be built')
+endif
+if with_dri_i915 and with_gallium_i915
+  error('Only one i915 provider can be built')
+endif
+if with_gallium_kmsro and not (with_gallium_v3d or with_gallium_vc4 or with_gallium_etnaviv or with_gallium_freedreno or with_gallium_panfrost or with_gallium_lima)
+  error('kmsro driver requires one or more renderonly drivers (vc4, etnaviv, freedreno, panfrost, lima)')
+endif
+if with_gallium_tegra and not with_gallium_nouveau
+  error('tegra driver requires nouveau driver')
+endif
+
 if with_egl and not (with_platform_drm or with_platform_surfaceless or with_platform_android)
   if with_gallium_radeonsi
     error('RadeonSI requires the drm, surfaceless or android platform when using EGL')
@@ -1133,12 +1182,6 @@  dep_libdrm_radeon = null_dep
 dep_libdrm_nouveau = null_dep
 dep_libdrm_intel = null_dep
 
-_drm_amdgpu_ver = '2.4.99'
-_drm_radeon_ver = '2.4.71'
-_drm_nouveau_ver = '2.4.66'
-_drm_intel_ver = '2.4.75'
-_drm_ver = '2.4.81'
-
 _libdrm_checks = [
   ['intel', with_dri_i915 or with_gallium_i915],
   ['amdgpu', with_amd_vk or with_gallium_radeonsi],

Comments




On Thu, Jul 18, 2019 at 7:19 AM Alyssa Ross <hi@alyssa.is> wrote:
>
> "auto" pays attention to the OS and architecture of the target system,
> but not the available libraries. If, say, libdrm isn't available, "auto"
> won't work, and a manual list of drivers will be required anyway. It
> would also try building the virgl and svga gallium drivers, even when
> unsupported due to building with EGL and no compatible platform.

Today with "auto" you'll get some error message if a driver cannot be
built because of a missing library, right?

What happens after your patch? Is the user informed that some driver
included in the "auto" set is not going to be built because of a
missing library? It doesn't seem like it, unless I'm missing
something, and that seems potentially worse than giving an error.

I think automatic selection of build targets really breaks down when
you have as many options and dependencies as we have.