[Mesa-dev] [PATCH v3 3/4] meson: Add build Intel "anv" vulkan driver

Dylan Baker dylan at pnwbakers.com
Tue Sep 26 19:59:03 UTC 2017


Quoting Eric Anholt (2017-09-26 11:46:50)
> Dylan Baker <dylan at pnwbakers.com> writes:
> 
> > This allows building and installing the Intel "anv" Vulkan driver using
> > meson and ninja, the driver has been tested against the CTS and has
> > seems to pass the same series of tests (they both segfault when the CTS
> > tries to run wayland wsi tests).
> >
> > There are still a mess of TODO, XXX, and FIXME comments in here. Those
> > are mostly for meson bugs I'm trying to fix, or for additional things to
> > implement for other drivers/features.
> >
> > I have configured all intermediate libraries and optional tools to not
> > build by default, meaning they will only be built if they're pulled in
> > as a dependency of a target that will actually be installed) this allows
> > us to avoid massive if chains, while ensuring that only the bits that
> > need to be built are.
> 
> I am really looking forward to converting my vc5-vulkan work over to the
> meson build.  Given the rate I have to rebase that branch, it would be
> worth my time to convert over it in the next day of actual code
> development I get to do.
> 
> So, I'll offer a few bits of feedback on meson usage, after which you
> can have my
> 
> Reviewed-by: Eric Anholt <eric at anholt.net>
> 
> so that we can start working in the tree together.
> 
> > diff --git a/meson.build b/meson.build
> > new file mode 100644
> > index 00000000000..09e53957fe9
> > --- /dev/null
> > +++ b/meson.build
> > @@ -0,0 +1,423 @@
> > +# Copyright © 2017 Intel Corporation
> > +
> > +# Permission is hereby granted, free of charge, to any person obtaining a copy
> > +# of this software and associated documentation files (the "Software"), to deal
> > +# in the Software without restriction, including without limitation the rights
> > +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> > +# copies of the Software, and to permit persons to whom the Software is
> > +# furnished to do so, subject to the following conditions:
> > +
> > +# The above copyright notice and this permission notice shall be included in
> > +# all copies or substantial portions of the Software.
> > +
> > +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> > +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> > +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> > +# SOFTWARE.
> > +
> > +project('mesa', ['c', 'cpp'], version : '17.3.0-devel', license : 'MIT',
> > +        default_options : ['c_std=c99'])
> > +
> > +with_dri3 = true  # XXX: need a switch for this
> > +with_vulkan_icd_dir = get_option('vulkan_icd_dir')
> > +with_tests = get_option('build-tests')
> > +with_valgrind = get_option('valgrind')
> > +
> > +# TODO: there are more platforms required for non-vulkan drivers
> > +with_platform_wayland = false
> > +with_platform_x11 = false
> > +_platforms = get_option('platforms')
> > +if _platforms != ''
> > +  _split = _platforms.split(',')
> > +  with_platform_x11 = _split.contains('x11')
> > +  with_platform_wayland = _split.contains('wayland')
> > +endif
> > +
> > +if with_vulkan_icd_dir == ''
> > +  with_vulkan_icd_dir = join_paths(get_option('datadir'), 'vulkan/icd.d')
> > +endif
> > +
> > +with_intel_vk = false
> > +with_amd_vk = false
> > +_vulkan_drivers = get_option('vulkan-drivers')
> > +if _vulkan_drivers != ''
> > +  _split = _vulkan_drivers.split(',')
> > +  with_intel_vk = _split.contains('intel')
> > +  with_amd_vk = _split.contains('amd')
> > +  if not (with_platform_x11 or with_platform_wayland)
> > +    error('Vulkan requires at least one platform (x11, wayland)')
> > +  endif
> > +endif
> > +
> > +prog_python2 = find_program('python2')
> > +
> > +cc = meson.get_compiler('c')
> > +if cc.get_id() == 'gcc' and cc.version().version_compare('< 4.4.6')
> > +  error('When using GCC version 4.2.0 or later required.')
> > +endif
> > +
> > +# Arguments for the preprocessor. These need to be added to both the C and the
> > +# C++ (cpp in meson terminology) arguments, so the they're calculated
> 
> "so that they're"
> 

I think that "the" is just useless here, I'm trying to say "put preprocessor
args in a separate array since they need to be added to the default arguments
for C and C++"

> > +# separately
> > +pre_args = ['-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS',
> > +            '-D__STDC_LIMIT_MACROS',
> > +            '-DVERSION="@0@"'.format(meson.project_version())]
> > +
> > +# Define debug for debug and debugoptimized builds
> 
>             DEBUG
> 
> > +if get_option('buildtype').startswith('debug')
> > +  pre_args += '-DDEBUG'
> > +endif
> > +
> 
> 
> > +# check for dl support
> > +if cc.has_function('dlopen')
> > +  pre_args += '-DHAVE_DLOPEN'
> > +  dep_dl = []
> > +else
> > +  dep_dl = cc.find_library('dl')
> 
> Note: The configure.ac path sets HAVE_DLOPEN if libdl is found.  Needed
> for core mesa.
> 
> > +endif
> > +
> > +if not cc.has_function('dladdr', dependencies : dep_dl)
> > +  error('dl library doesn\'t have dladdr')
> > +endif
> > +
> > +if cc.has_function('dl_iterate_phdr')
> > +  pre_args += '-DHAVE_DL_ITERATE_PHDR'
> > +else
> > +  # TODO: this is required for vulkan
> > +endif
> > +
> > +# Determine whether or not the rt library is needed for time functions
> > +if cc.has_function('clock_gettime')
> > +  dep_clock = []
> > +else
> > +  dep_clock = cc.find_library('rt')
> > +endif
> > +
> > +# Check for posix_memalign
> > +if cc.has_function('posix_memalign')
> > +  pre_args += '-DHAVE_POSIX_MEMALIGN'
> > +endif
> 
> Possible improvement, move posix_memalign up with mkostemp and do it as
> an array loop.
> 
> > diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py
> > index b19d6de9f2f..47c4bf7c22e 100644
> > --- a/src/vulkan/util/gen_enum_to_str.py
> > +++ b/src/vulkan/util/gen_enum_to_str.py
> > @@ -219,8 +219,8 @@ def main():
> >      enums = sorted(enum_factory.registry.values(), key=lambda e: e.name)
> >      extensions = sorted(ext_factory.registry.values(), key=lambda e: e.name)
> >  
> > -    for template, file_ in [(C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c')),
> > -                            (H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h'))]:
> > +    for template, file_ in [(H_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.h')),
> > +                            (C_TEMPLATE, os.path.join(args.outdir, 'vk_enum_to_str.c'))]:
> >          with open(file_, 'wb') as f:
> >              f.write(template.render(
> >                  file=os.path.basename(__file__),
> 
> What's this hunk about?

Originally I was doing something very hacky to get a split in the header/code
here. I moved to a target workaround and now have a merge request #2376 to allow
indexing CustomTarget's instead. I'll remove this.

> 
> > diff --git a/src/vulkan/util/meson.build b/src/vulkan/util/meson.build
> > new file mode 100644
> > index 00000000000..e9a2906dbc6
> > --- /dev/null
> > +++ b/src/vulkan/util/meson.build
> > @@ -0,0 +1,47 @@
> > +# Copyright © 2017 Intel Corporation
> > +
> > +# Permission is hereby granted, free of charge, to any person obtaining a copy
> > +# of this software and associated documentation files (the "Software"), to deal
> > +# in the Software without restriction, including without limitation the rights
> > +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> > +# copies of the Software, and to permit persons to whom the Software is
> > +# furnished to do so, subject to the following conditions:
> > +
> > +# The above copyright notice and this permission notice shall be included in
> > +# all copies or substantial portions of the Software.
> > +
> > +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> > +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> > +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> > +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> > +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> > +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> > +# SOFTWARE.
> > +
> > +files_vulkan_util = files(
> > +  'vk_alloc.h',
> > +  'vk_util.c',
> > +  'vk_util.h',
> > +)
> > +
> > +vk_enum_to_str = custom_target(
> > +  'vk_enum_to_str',
> > +  input : ['gen_enum_to_str.py', vk_api_xml[0]],
> > +  output : ['vk_enum_to_str.c', 'vk_enum_to_str.h'],
> > +  command : [prog_python2, '@INPUT0@', '--xml', '@INPUT1@',
> > +             '--outdir', meson.current_build_dir()],
> > +)
> > +
> > +# We need this other places to ensure that this is generated before another
> > +# target, but we don't want to also include the c file
> > +# XXX: I'm not sure whether I should break the generator into two calls (yuk),
> > +# or fix meson to return an array if there is more than one file
> > +#vk_enum_to_str_h = files(vk_enum_to_str.full_path())
> 
> An option, if you think the python call is too expensive to run twice:
> python script generates to two temporary names, and two separate custom
> targets make copies to the each of the current names.

That was part of the same change above, and should have been deleted. I talked
with upstream and decided that implementing a new feature was better. In the
meantime I created a workaround by having a target that depends on this target,
but outputs (via touch) an empty file. It's not pretty, but it'll work until the
actual feature we want can land in meson (hopefully for 0.43).

I've removed this too.

Dylan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170926/bfaeaf5b/attachment.sig>


More information about the mesa-dev mailing list