[Mesa-dev] [PATCH 2/2] meson: make "auto" only choose buildable drivers

Dylan Baker dylan at pnwbakers.com
Thu Jul 18 16:13:39 UTC 2019


Quoting Alyssa Ross (2019-07-18 07:15:14)
> "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(-)
> 
> 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())

Newer versions of meson cache calls to dependency(), but older ones (which we
still support) don't, and I'm afraid that calling dependency() several times for
each libdrm library is going to stink for performance.

Would it work to just move the libdrm check before the drivers check, and
instead of erroring if libdrm_foo isn't found do that in the acutal drivers
checks, something like (pusdocode):

foreach d : ['intel', 'amdgpu', ...]
  dep_libdrm_$d = dependency(..., required : false)
endforeach

if dri_drivers.contains('auto')
  if system_has_kms_drm
    dri_drivers = []
    if ['x86', 'x86_64'].contains(host_machine.cpu_family())
      if dep_libdrm_intel.found()
        dri_drivers += 'i915'
      endif
      ...
    endif
  ...
  endif
else
  _checks = [['i915', dep_libdrm_intel], ...]
  foreach c : _checks
    if dri_drivers.contains(c[0]) and not c[1].found()
      error(...)
    endif
  endforeach
endif

if gallim_drivers.contains('auto')
  ...
else
  ...
endif

For virgl/svga: I'd be inclined not to build them automatically. They're not
useful outside of a VM, so most developers either will be exclusively building
one (not both) of those, or not be interested in them at all. And Distros don't
use auto options so we don't need to worry about them.
        
Dylan

>        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 at . 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 at . 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 at . 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 at . 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],
> -- 
> 2.22.0
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 228 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20190718/59542168/attachment.sig>


More information about the mesa-dev mailing list