+ }
+ % else:
+ ${e.return_type} ${e.prefixed_name(layer)}(${e.decl_params()}) __attribute__ ((weak));
+ % endif
+ % if e.guard is not None:
+#endif // ${e.guard}
+ % endif
+ % endfor
+
+ const struct anv_device_dispatch_table ${layer}_device_dispatch_table = {
+ % for e in device_entrypoints:
+ % if e.guard is not None:
+#ifdef ${e.guard}
+ % endif
+ .${e.name} = ${e.prefixed_name(layer)},
+ % if e.guard is not None:
+#endif // ${e.guard}
+ % endif
+ % endfor
+ };
+% endfor
+
+
+/** Return true if the core version or extension in which the given entrypoint
+ * is defined is enabled.
+ *
+ * If device is NULL, all device extensions are considered enabled.
+ */
+bool
+anv_instance_entrypoint_is_enabled(int index, uint32_t core_version,
+ const struct anv_instance_extension_table *instance)
+{
+ switch (index) {
+% for e in instance_entrypoints:
+ case ${e.num}:
+ /* ${e.name} */
+ % if e.core_version:
+ return ${e.core_version.c_vk_version()} <= core_version;
+ % elif e.extensions:
+ % for ext in e.extensions:
+ % if ext.type == 'instance':
+ if (instance->${ext.name[3:]}) return true;
+ % else:
+ /* All device extensions are considered enabled at the instance level */
+ return true;
+ % endif
+ % endfor
+ return false;
+ % else:
+ return true;
+ % endif
+% endfor
+ default:
+ return false;
+ }
+}
+
+/** Return true if the core version or extension in which the given entrypoint
+ * is defined is enabled.
+ *
+ * If device is NULL, all device extensions are considered enabled.
+ */
+bool
+anv_physical_device_entrypoint_is_enabled(int index, uint32_t core_version,
+ const struct anv_instance_extension_table *instance)
+{
+ switch (index) {
+% for e in physical_device_entrypoints:
+ case ${e.num}:
+ /* ${e.name} */
+ % if e.core_version:
+ return ${e.core_version.c_vk_version()} <= core_version;
+ % elif e.extensions:
+ % for ext in e.extensions:
+ % if ext.type == 'instance':
+ if (instance->${ext.name[3:]}) return true;
+ % else:
+ /* All device extensions are considered enabled at the instance level */
+ return true;
+ % endif
+ % endfor
+ return false;
+ % else:
+ return true;
+ % endif
+% endfor
+ default:
+ return false;
+ }
+}
+
+/** Return true if the core version or extension in which the given entrypoint
+ * is defined is enabled.
+ *
+ * If device is NULL, all device extensions are considered enabled.
+ */
+bool
+anv_device_entrypoint_is_enabled(int index, uint32_t core_version,
+ const struct anv_instance_extension_table *instance,
+ const struct anv_device_extension_table *device)
+{
+ switch (index) {
+% for e in device_entrypoints:
+ case ${e.num}:
+ /* ${e.name} */
+ % if e.core_version:
+ return ${e.core_version.c_vk_version()} <= core_version;
+ % elif e.extensions:
+ % for ext in e.extensions:
+ % if ext.type == 'instance':
+ <% assert False %>
+ % else:
+ if (!device || device->${ext.name[3:]}) return true;
+ % endif
+ % endfor
+ return false;
+ % else:
+ return true;
+ % endif
+% endfor
+ default:
+ return false;
+ }
+}
+
+int
+anv_get_instance_entrypoint_index(const char *name)
+{
+ return instance_string_map_lookup(name);
+}
+
+int
+anv_get_physical_device_entrypoint_index(const char *name)
+{
+ return physical_device_string_map_lookup(name);
+}
+
+int
+anv_get_device_entrypoint_index(const char *name)
+{
+ return device_string_map_lookup(name);
+}
+
+const char *
+anv_get_instance_entry_name(int index)
+{
+ return instance_entry_name(index);
+}
+
+const char *
+anv_get_physical_device_entry_name(int index)
+{
+ return physical_device_entry_name(index);
+}
+
+const char *
+anv_get_device_entry_name(int index)
+{
+ return device_entry_name(index);
+}
+
+void * __attribute__ ((noinline))
+anv_resolve_device_entrypoint(const struct gen_device_info *devinfo, uint32_t index)
+{
+ const struct anv_device_dispatch_table *genX_table;
+ switch (devinfo->gen) {
+ case 12:
+ genX_table = &gen12_device_dispatch_table;
+ break;
+ case 11:
+ genX_table = &gen11_device_dispatch_table;
+ break;
+ case 10:
+ genX_table = &gen10_device_dispatch_table;
+ break;
+ case 9:
+ genX_table = &gen9_device_dispatch_table;
+ break;
+ case 8:
+ genX_table = &gen8_device_dispatch_table;
+ break;
+ case 7:
+ if (devinfo->is_haswell)
+ genX_table = &gen75_device_dispatch_table;
+ else
+ genX_table = &gen7_device_dispatch_table;
+ break;
+ default:
+ unreachable("unsupported gen\\n");
+ }
+
+ if (genX_table->entrypoints[index])
+ return genX_table->entrypoints[index];
+ else
+ return anv_device_dispatch_table.entrypoints[index];
+}
+
+void *
+anv_lookup_entrypoint(const struct gen_device_info *devinfo, const char *name)
+{
+ int idx = anv_get_instance_entrypoint_index(name);
+ if (idx >= 0)
+ return anv_instance_dispatch_table.entrypoints[idx];
+
+ idx = anv_get_physical_device_entrypoint_index(name);
+ if (idx >= 0)
+ return anv_physical_device_dispatch_table.entrypoints[idx];
+
+ idx = anv_get_device_entrypoint_index(name);
+ if (idx >= 0)
+ return anv_resolve_device_entrypoint(devinfo, idx);
+
+ return NULL;
+}""", output_encoding='utf-8')
+