gallium: add separate PIPE_CAP_INT64_DIVMOD
[mesa.git] / src / intel / vulkan / anv_entrypoints_gen.py
index 546829f7f71eadd8a2b16adf6fb2f5bf45a5d918..0eb523d7ac9ba314ab16fe710c402a52b3377585 100644 (file)
 # IN THE SOFTWARE.
 #
 
-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 sys
+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,47 @@ 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):
+    entrypoints = []
+    commands = doc.findall('./commands/command')
+    for i, command in enumerate(commands):
+        type = command.find('./proto/type').text
+        fullname = command.find('./proto/name').text
+        shortname = fullname[2:]
+        params = map(lambda p: "".join(p.itertext()), command.findall('./param'))
+        params = ', '.join(params)
+        if fullname in entrypoints_to_defines:
+            guard = entrypoints_to_defines[fullname]
+        else:
+            guard = None
+        entrypoints.append((type, shortname, params, i, hash(fullname), guard))
+    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:
+            fullname = entrypoint.get('name')
+            entrypoints_to_defines[fullname] = 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('vkCreateDmaBufImageINTEL'), None))
 
 # For outputting entrypoints.h we generate a anv_EntryPoint() prototype
 # per entry point.
@@ -111,25 +116,29 @@ if opt_header:
     print "      void *entrypoints[%d];" % len(entrypoints)
     print "      struct {"
 
-    for type, name, args, num, h in entrypoints:
-        print_guard_start(name)
-        print "         %s (*%s)%s;" % (type, name, args)
-        print_guard_end(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)
+            print "#else"
+            print "         void *{0};".format(name)
+            print "#endif"
+        else:
+            print "         PFN_vk{0} {0};".format(name)
     print "      };\n"
     print "   };\n"
     print "};\n"
 
-    print "void anv_set_dispatch_devinfo(const struct brw_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 "%s anv_validate_%s%s;" % (type, name, args)
-        print_guard_end(name)
+    print "void anv_set_dispatch_devinfo(const struct gen_device_info *info);\n"
+
+    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()
 
 
@@ -175,83 +184,48 @@ static const char strings[] ="""
 
 offsets = []
 i = 0;
-for type, name, args, num, h in entrypoints:
-    print_guard_start(name)
+for type, name, args, num, h, guard in entrypoints:
     print "   \"vk%s\\0\"" % name
     offsets.append(i)
     i += 2 + len(name) + 1
-    print_guard_end(name)
-print """   ;
-
-/* Weak aliases for all potential validate functions. These will resolve to
- * NULL if they're not defined, which lets the resolve_entrypoint() function
- * either pick a validate wrapper if available or just plug in the actual
- * entry point.
- */
-"""
+print "   ;"
 
-# Now generate the table of all entry points and their validation functions
+# Now generate the table of all entry points
 
 print "\nstatic const struct anv_entrypoint entrypoints[] = {"
-for type, name, args, num, h in entrypoints:
-    print_guard_start(name)
+for type, name, args, num, h, guard in entrypoints:
     print "   { %5d, 0x%08x }," % (offsets[num], h)
-    print_guard_end(name)
 print "};\n"
 
-for layer in [ "anv", "validate", "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)
+print """
+
+/* Weak aliases for all potential implementations. These will resolve to
+ * NULL if they're not defined, which lets the resolve_entrypoint() function
+ * either pick the correct entry point.
+ */
+"""
+
+for layer in [ "anv", "gen7", "gen75", "gen8", "gen9" ]:
+    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 """
-#ifdef DEBUG
-static bool enable_validate = true;
-#else
-static bool enable_validate = false;
-#endif
-
-/* We can't use symbols that need resolving (like, oh, getenv) in the resolve
- * function. This means that we have to determine whether or not to use the
- * validation layer sometime before that. The constructor function attribute asks
- * the dynamic linker to invoke determine_validate() at dlopen() time which
- * works.
- */
-static void __attribute__ ((constructor))
-determine_validate(void)
-{
-   const char *s = getenv("ANV_VALIDATE");
-
-   if (s)
-      enable_validate = atoi(s);
-}
-
-static const struct brw_device_info *dispatch_devinfo;
-
-void
-anv_set_dispatch_devinfo(const struct brw_device_info *devinfo)
-{
-   dispatch_devinfo = devinfo;
-}
-
-void * __attribute__ ((noinline))
-anv_resolve_entrypoint(uint32_t index)
+static void * __attribute__ ((noinline))
+anv_resolve_entrypoint(const struct gen_device_info *devinfo, uint32_t index)
 {
-   if (enable_validate && validate_layer.entrypoints[index])
-      return validate_layer.entrypoints[index];
-
-   if (dispatch_devinfo == NULL) {
+   if (devinfo == NULL) {
       return anv_layer.entrypoints[index];
    }
 
-   switch (dispatch_devinfo->gen) {
+   switch (devinfo->gen) {
    case 9:
       if (gen9_layer.entrypoints[index])
          return gen9_layer.entrypoints[index];
@@ -261,7 +235,7 @@ anv_resolve_entrypoint(uint32_t index)
          return gen8_layer.entrypoints[index];
       /* fall through */
    case 7:
-      if (dispatch_devinfo->is_haswell && gen75_layer.entrypoints[index])
+      if (devinfo->is_haswell && gen75_layer.entrypoints[index])
          return gen75_layer.entrypoints[index];
 
       if (gen7_layer.entrypoints[index])
@@ -275,24 +249,13 @@ anv_resolve_entrypoint(uint32_t index)
 }
 """
 
-# Now output ifuncs and their resolve helpers for all entry points. The
-# resolve helper calls resolve_entrypoint() with the entry point index, which
-# lets the resolver look it up in the table.
-
-for type, name, args, num, h in entrypoints:
-    print_guard_start(name)
-    print "static void *resolve_%s(void) { return anv_resolve_entrypoint(%d); }" % (name, num)
-    print "%s vk%s%s\n   __attribute__ ((ifunc (\"resolve_%s\"), visibility (\"default\")));\n" % (type, name, args, name)
-    print_guard_end(name)
-
-
 # Now generate the hash table used for entry point look up.  This is a
 # uint16_t table of entry point indices. We use 0xffff to indicate an entry
 # in the hash table is empty.
 
 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
@@ -327,14 +290,14 @@ 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.
 
 print """
 void *
-anv_lookup_entrypoint(const char *name)
+anv_lookup_entrypoint(const struct gen_device_info *devinfo, const char *name)
 {
    static const uint32_t prime_factor = %d;
    static const uint32_t prime_step = %d;
@@ -358,6 +321,6 @@ anv_lookup_entrypoint(const char *name)
    if (strcmp(name, strings + e->name) != 0)
       return NULL;
 
-   return anv_resolve_entrypoint(i);
+   return anv_resolve_entrypoint(devinfo, i);
 }
 """ % (prime_factor, prime_step, hash_mask)