[Mesa-dev] [PATCH 3/4] anv: generate entry points from vk.xml

Jason Ekstrand jason at jlekstrand.net
Thu Jan 12 23:18:09 UTC 2017


I made a quick comment below.  With that, this patch is

Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>

Assuming you pulled 1 and 2 from master of the public github repo for
Khronos, they are

Acked-by: Jason Ekstrand <jason at jlekstrand.net>

On Thu, Jan 12, 2017 at 1:43 PM, Lionel Landwerlin <
lionel.g.landwerlin at intel.com> wrote:

> Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
> ---
>  src/intel/vulkan/Makefile.am            |  15 ++--
>  src/intel/vulkan/anv_entrypoints_gen.py | 125
> +++++++++++++++++---------------
>  2 files changed, 71 insertions(+), 69 deletions(-)
>
> diff --git a/src/intel/vulkan/Makefile.am b/src/intel/vulkan/Makefile.am
> index df7645fb13..d32b57f267 100644
> --- a/src/intel/vulkan/Makefile.am
> +++ b/src/intel/vulkan/Makefile.am
> @@ -23,11 +23,6 @@ include Makefile.sources
>
>  vulkan_includedir = $(includedir)/vulkan
>
> -vulkan_include_HEADERS = \
> -       $(top_srcdir)/include/vulkan/vk_platform.h \
> -       $(top_srcdir)/include/vulkan/vulkan.h \
> -       $(top_srcdir)/include/vulkan/vulkan_intel.h
> -
>  lib_LTLIBRARIES = libvulkan_intel.la
>
>  check_LTLIBRARIES = libvulkan-test.la
> @@ -138,12 +133,14 @@ VULKAN_LIB_DEPS += \
>  nodist_EXTRA_libvulkan_intel_la_SOURCES = dummy.cpp
>  libvulkan_intel_la_SOURCES = $(VULKAN_GEM_FILES)
>
> -anv_entrypoints.h : anv_entrypoints_gen.py $(vulkan_include_HEADERS)
> -       $(AM_V_GEN) cat $(vulkan_include_HEADERS) |\
> +vulkan_api_xml = $(top_srcdir)/src/vulkan/registry/vk.xml
> +
> +anv_entrypoints.h : anv_entrypoints_gen.py $(vulkan_api_xml)
> +       $(AM_V_GEN) cat $(vulkan_api_xml) |\
>         $(PYTHON2) $(srcdir)/anv_entrypoints_gen.py header > $@
>
> -anv_entrypoints.c : anv_entrypoints_gen.py $(vulkan_include_HEADERS)
> -       $(AM_V_GEN) cat $(vulkan_include_HEADERS) |\
> +anv_entrypoints.c : anv_entrypoints_gen.py $(vulkan_api_xml)
> +       $(AM_V_GEN) cat $(vulkan_api_xml) |\
>         $(PYTHON2) $(srcdir)/anv_entrypoints_gen.py code > $@
>
>  BUILT_SOURCES = $(VULKAN_GENERATED_FILES)
> diff --git a/src/intel/vulkan/anv_entrypoints_gen.py
> b/src/intel/vulkan/anv_entrypoints_gen.py
> index 9d23dbb358..e303b7e8e8 100644
> --- a/src/intel/vulkan/anv_entrypoints_gen.py
> +++ b/src/intel/vulkan/anv_entrypoints_gen.py
> @@ -23,13 +23,7 @@
>  #
>
>  import fileinput, re, sys
> -
> -# Each function typedef in the vulkan.h header is all on one line and
> matches
> -# this regepx. We hope that won't change.
> -
> -p = re.compile('typedef ([^ ]*) *\((?:VKAPI_PTR)?
> *\*PFN_vk([^(]*)\)(.*);')
> -
> -entrypoints = []
> +import xml.etree.ElementTree as ET
>
>  # We generate a static hash table for entry point lookup
>  # (vkGetProcAddress). We use a linear congruential generator for our hash
> @@ -51,29 +45,11 @@ def hash(name):
>
>      return h
>
> -def get_platform_guard_macro(name):
> -    if "Xlib" in name:
> -        return "VK_USE_PLATFORM_XLIB_KHR"
> -    elif "Xcb" in name:
> -        return "VK_USE_PLATFORM_XCB_KHR"
> -    elif "Wayland" in name:
> -        return "VK_USE_PLATFORM_WAYLAND_KHR"
> -    elif "Mir" in name:
> -        return "VK_USE_PLATFORM_MIR_KHR"
> -    elif "Android" in name:
> -        return "VK_USE_PLATFORM_ANDROID_KHR"
> -    elif "Win32" in name:
> -        return "VK_USE_PLATFORM_WIN32_KHR"
> -    else:
> -        return None
> -
> -def print_guard_start(name):
> -    guard = get_platform_guard_macro(name)
> +def print_guard_start(guard):
>      if guard is not None:
>          print "#ifdef {0}".format(guard)
>
> -def print_guard_end(name):
> -    guard = get_platform_guard_macro(name)
> +def print_guard_end(guard):
>      if guard is not None:
>          print "#endif // {0}".format(guard)
>
> @@ -87,18 +63,48 @@ elif (sys.argv[1] == "code"):
>      opt_code = True
>      sys.argv.pop()
>
> -# Parse the entry points in the header
> -
> -i = 0
> -for line in fileinput.input():
> -    m  = p.match(line)
> -    if (m):
> -        if m.group(2) == 'VoidFunction':
> -            continue
> -        fullname = "vk" + m.group(2)
> -        h = hash(fullname)
> -        entrypoints.append((m.group(1), m.group(2), m.group(3), i, h))
> -        i = i + 1
> +# Extract the entry points from the registry
> +def get_entrypoints(doc, entrypoints_to_defines):
> +    i = 0
> +    entrypoints = []
> +    commands = doc.findall('./commands/command')
> +    for command in commands:
>

If you use python's "itertools", you can avoid incrementing "i".  Just do

for i, command in itertools.iterate(commands):


> +        type = command.find('./proto/type').text
> +        name = command.find('./proto/name').text[2:]
> +        params = map(lambda p: "".join(p.itertext()),
> command.findall('./param'))
> +        params = ', '.join(params)
> +        if name in entrypoints_to_defines:
> +            guard = entrypoints_to_defines[name]
> +        else:
> +            guard = None
> +        entrypoints.append((type, name, params, i, hash(name), guard))
> +        i += 1
> +    return entrypoints
> +
> +# Maps entry points to extension defines
> +def get_entrypoints_defines(doc):
> +    entrypoints_to_defines = {}
> +    extensions = doc.findall('./extensions/extension')
> +    for extension in extensions:
> +        define = extension.get('protect')
> +        entrypoints = extension.findall('./require/command')
> +        for entrypoint in entrypoints:
> +            name = entrypoint.get('name')[2:]
> +            entrypoints_to_defines[name] = define
> +    return entrypoints_to_defines
> +
> +doc = ET.parse(sys.stdin)
> +entrypoints = get_entrypoints(doc, get_entrypoints_defines(doc))
> +
> +# Manually add CreateDmaBufImageINTEL for which we don't have an extension
> +# defined.
> +entrypoints.append(('VkResult', 'CreateDmaBufImageINTEL',
> +                    'VkDevice _device,' +
> +                    'const VkDmaBufImageCreateInfo* pCreateInfo, ' +
> +                    'const VkAllocationCallbacks* pAllocator,' +
> +                    'VkDeviceMemory* pMem,' +
> +                    'VkImage* pImage', len(entrypoints),
> +                    hash('CreateDmaBufImageINTEL'), None))
>
>  # For outputting entrypoints.h we generate a anv_EntryPoint() prototype
>  # per entry point.
> @@ -111,8 +117,7 @@ if opt_header:
>      print "      void *entrypoints[%d];" % len(entrypoints)
>      print "      struct {"
>
> -    for type, name, args, num, h in entrypoints:
> -        guard = get_platform_guard_macro(name)
> +    for type, name, args, num, h, guard in entrypoints:
>          if guard is not None:
>              print "#ifdef {0}".format(guard)
>              print "         PFN_vk{0} {0};".format(name)
> @@ -127,14 +132,14 @@ if opt_header:
>
>      print "void anv_set_dispatch_devinfo(const struct gen_device_info
> *info);\n"
>
> -    for type, name, args, num, h in entrypoints:
> -        print_guard_start(name)
> -        print "%s anv_%s%s;" % (type, name, args)
> -        print "%s gen7_%s%s;" % (type, name, args)
> -        print "%s gen75_%s%s;" % (type, name, args)
> -        print "%s gen8_%s%s;" % (type, name, args)
> -        print "%s gen9_%s%s;" % (type, name, args)
> -        print_guard_end(name)
> +    for type, name, args, num, h, guard in entrypoints:
> +        print_guard_start(guard)
> +        print "%s anv_%s(%s);" % (type, name, args)
> +        print "%s gen7_%s(%s);" % (type, name, args)
> +        print "%s gen75_%s(%s);" % (type, name, args)
> +        print "%s gen8_%s(%s);" % (type, name, args)
> +        print "%s gen9_%s(%s);" % (type, name, args)
> +        print_guard_end(guard)
>      exit()
>
>
> @@ -180,7 +185,7 @@ static const char strings[] ="""
>
>  offsets = []
>  i = 0;
> -for type, name, args, num, h in entrypoints:
> +for type, name, args, num, h, guard in entrypoints:
>      print "   \"vk%s\\0\"" % name
>      offsets.append(i)
>      i += 2 + len(name) + 1
> @@ -189,7 +194,7 @@ print "   ;"
>  # Now generate the table of all entry points
>
>  print "\nstatic const struct anv_entrypoint entrypoints[] = {"
> -for type, name, args, num, h in entrypoints:
> +for type, name, args, num, h, guard in entrypoints:
>      print "   { %5d, 0x%08x }," % (offsets[num], h)
>  print "};\n"
>
> @@ -202,15 +207,15 @@ print """
>  """
>
>  for layer in [ "anv", "gen7", "gen75", "gen8", "gen9" ]:
> -    for type, name, args, num, h in entrypoints:
> -        print_guard_start(name)
> -        print "%s %s_%s%s __attribute__ ((weak));" % (type, layer, name,
> args)
> -        print_guard_end(name)
> +    for type, name, args, num, h, guard in entrypoints:
> +        print_guard_start(guard)
> +        print "%s %s_%s(%s) __attribute__ ((weak));" % (type, layer,
> name, args)
> +        print_guard_end(guard)
>      print "\nconst struct anv_dispatch_table %s_layer = {" % layer
> -    for type, name, args, num, h in entrypoints:
> -        print_guard_start(name)
> +    for type, name, args, num, h, guard in entrypoints:
> +        print_guard_start(guard)
>          print "   .%s = %s_%s," % (name, layer, name)
> -        print_guard_end(name)
> +        print_guard_end(guard)
>      print "};\n"
>
>  print """
> @@ -251,7 +256,7 @@ anv_resolve_entrypoint(const struct gen_device_info
> *devinfo, uint32_t index)
>
>  map = [none for f in xrange(hash_size)]
>  collisions = [0 for f in xrange(10)]
> -for type, name, args, num, h in entrypoints:
> +for type, name, args, num, h, guard in entrypoints:
>      level = 0
>      while map[h & hash_mask] != none:
>          h = h + prime_step
> @@ -286,7 +291,7 @@ for i in xrange(0, hash_size, 8):
>              print "0x%04x," % (map[j] & 0xffff),
>      print
>
> -print "};"
> +print "};"
>
>  # Finally we generate the hash table lookup function.  The hash function
> and
>  # linear probing algorithm matches the hash table generated above.
> --
> 2.11.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170112/43d70a66/attachment-0001.html>


More information about the mesa-dev mailing list