From: Samuel Pitoiset Date: Mon, 11 May 2020 09:33:00 +0000 (+0200) Subject: radv: use the common code for generating extensions and dispatch tables X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=857051c5c63e238f606652acb1e1f9610de68758;p=mesa.git radv: use the common code for generating extensions and dispatch tables Signed-off-by: Samuel Pitoiset Acked-by: Lionel Landwerlin Reviewed-by: Bas Nieuwenhuizen Reviewed-by: Eric Engestrom Part-of: --- diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index c4440a20b72..10d9b34e14b 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -394,7 +394,9 @@ radv_physical_device_try_create(struct radv_instance *instance, } radv_physical_device_init_mem_types(device); - radv_fill_device_extension_table(device, &device->supported_extensions); + + radv_physical_device_get_supported_extensions(device, + &device->supported_extensions); if (drm_device) device->bus_info = *drm_device->businfo.pci; @@ -657,7 +659,7 @@ VkResult radv_CreateInstance( } if (idx >= RADV_INSTANCE_EXTENSION_COUNT || - !radv_supported_instance_extensions.extensions[idx]) { + !radv_instance_extensions_supported.extensions[idx]) { vk_free2(&default_alloc, pAllocator, instance); return vk_error(instance, VK_ERROR_EXTENSION_NOT_PRESENT); } @@ -4935,7 +4937,7 @@ VkResult radv_EnumerateInstanceExtensionProperties( VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount); for (int i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; i++) { - if (radv_supported_instance_extensions.extensions[i]) { + if (radv_instance_extensions_supported.extensions[i]) { vk_outarray_append(&out, prop) { *prop = radv_instance_extensions[i]; } diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py index bf9f87a0aca..0549a09f377 100644 --- a/src/amd/vulkan/radv_extensions.py +++ b/src/amd/vulkan/radv_extensions.py @@ -25,34 +25,17 @@ COPYRIGHT = """\ """ import argparse -import copy +import os.path import re -import xml.etree.cElementTree as et +import sys -from mako.template import Template +VULKAN_UTIL = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../vulkan/util')) +sys.path.append(VULKAN_UTIL) -def _bool_to_c_expr(b): - if b is True: - return 'true' - if b is False: - return 'false' - return b +from vk_extensions import * +from vk_extensions_gen import * -class Extension: - def __init__(self, name, ext_version, enable): - self.name = name - self.ext_version = int(ext_version) - if enable is True: - self.enable = 'true'; - elif enable is False: - self.enable = 'false'; - else: - self.enable = enable; - -class ApiVersion: - def __init__(self, version, enable): - self.version = version - self.enable = _bool_to_c_expr(enable) +MAX_API_VERSION = '1.2.128' # Supported API versions. Each one is the maximum patch version for the given # version. Version come in increasing order and each version is available if @@ -199,315 +182,12 @@ EXTENSIONS = [ Extension('VK_NV_compute_shader_derivatives', 1, True), ] -class VkVersion: - def __init__(self, string): - split = string.split('.') - self.major = int(split[0]) - self.minor = int(split[1]) - if len(split) > 2: - assert len(split) == 3 - self.patch = int(split[2]) - else: - self.patch = None - - # Sanity check. The range bits are required by the definition of the - # VK_MAKE_VERSION macro - assert self.major < 1024 and self.minor < 1024 - assert self.patch is None or self.patch < 4096 - assert(str(self) == string) - - def __str__(self): - ver_list = [str(self.major), str(self.minor)] - if self.patch is not None: - ver_list.append(str(self.patch)) - return '.'.join(ver_list) - - def c_vk_version(self): - patch = self.patch if self.patch is not None else 0 - ver_list = [str(self.major), str(self.minor), str(patch)] - return 'VK_MAKE_VERSION(' + ', '.join(ver_list) + ')' - - def __int_ver(self): - # This is just an expansion of VK_VERSION - patch = self.patch if self.patch is not None else 0 - return (self.major << 22) | (self.minor << 12) | patch - - def __gt__(self, other): - # If only one of them has a patch version, "ignore" it by making - # other's patch version match self. - if (self.patch is None) != (other.patch is None): - other = copy.copy(other) - other.patch = self.patch - - return self.__int_ver() > other.__int_ver() - - MAX_API_VERSION = VkVersion('0.0.0') for version in API_VERSIONS: version.version = VkVersion(version.version) assert version.version > MAX_API_VERSION MAX_API_VERSION = version.version -def _init_exts_from_xml(xml): - """ Walk the Vulkan XML and fill out extra extension information. """ - - xml = et.parse(xml) - - ext_name_map = {} - for ext in EXTENSIONS: - ext_name_map[ext.name] = ext - - for ext_elem in xml.findall('.extensions/extension'): - ext_name = ext_elem.attrib['name'] - if ext_name not in ext_name_map: - continue - - ext = ext_name_map[ext_name] - ext.type = ext_elem.attrib['type'] - ext.promotedto = ext_elem.attrib.get('promotedto', None) - try: - ext.requires = ext_elem.attrib['requires'].split(',') - except KeyError: - ext.requires = [] - - def extra_deps(ext): - if ext.type == 'instance': - check = 'instance->enabled_extensions.{}'.format(ext.name[3:]) - if ext.promotedto is not None: - # the xml contains values like VK_VERSION_1_1, but we need to - # translate them to VK_API_VERSION_1_1 for the apiVersion check - api_ver = ext.promotedto.replace('VK_VER', 'VK_API_VER') - check = '({} || instance->apiVersion >= {})'.format(check, api_ver) - return set([check]) - - deps = set() - for dep in ext.requires: - deps |= extra_deps(ext_name_map[dep]) - - return deps - - for ext in EXTENSIONS: - if ext.type == 'device': - ext.enable = '(' + ext.enable + ')' - for dep in extra_deps(ext): - ext.enable += ' && ' + dep - -# Mapping between extension name and the android version in which the extension -# was whitelisted in Android CTS. -allowed_android_version = { - # Allowed Instance KHR Extensions - "VK_KHR_surface": 26, - "VK_KHR_display": 26, - "VK_KHR_android_surface": 26, - "VK_KHR_mir_surface": 26, - "VK_KHR_wayland_surface": 26, - "VK_KHR_win32_surface": 26, - "VK_KHR_xcb_surface": 26, - "VK_KHR_xlib_surface": 26, - "VK_KHR_get_physical_device_properties2": 26, - "VK_KHR_get_surface_capabilities2": 26, - "VK_KHR_external_memory_capabilities": 28, - "VK_KHR_external_semaphore_capabilities": 28, - "VK_KHR_external_fence_capabilities": 28, - "VK_KHR_device_group_creation": 28, - "VK_KHR_get_display_properties2": 29, - "VK_KHR_surface_protected_capabilities": 29, - - # Allowed Device KHR Extensions - "VK_KHR_swapchain": 26, - "VK_KHR_display_swapchain": 26, - "VK_KHR_sampler_mirror_clamp_to_edge": 26, - "VK_KHR_shader_draw_parameters": 26, - "VK_KHR_shader_float_controls": 29, - "VK_KHR_shader_float16_int8": 29, - "VK_KHR_maintenance1": 26, - "VK_KHR_push_descriptor": 26, - "VK_KHR_descriptor_update_template": 26, - "VK_KHR_incremental_present": 26, - "VK_KHR_shared_presentable_image": 26, - "VK_KHR_storage_buffer_storage_class": 28, - "VK_KHR_8bit_storage": 29, - "VK_KHR_16bit_storage": 28, - "VK_KHR_get_memory_requirements2": 28, - "VK_KHR_external_memory": 28, - "VK_KHR_external_memory_fd": 28, - "VK_KHR_external_memory_win32": 28, - "VK_KHR_external_semaphore": 28, - "VK_KHR_external_semaphore_fd": 28, - "VK_KHR_external_semaphore_win32": 28, - "VK_KHR_external_fence": 28, - "VK_KHR_external_fence_fd": 28, - "VK_KHR_external_fence_win32": 28, - "VK_KHR_win32_keyed_mutex": 28, - "VK_KHR_dedicated_allocation": 28, - "VK_KHR_variable_pointers": 28, - "VK_KHR_relaxed_block_layout": 28, - "VK_KHR_bind_memory2": 28, - "VK_KHR_maintenance2": 28, - "VK_KHR_image_format_list": 28, - "VK_KHR_sampler_ycbcr_conversion": 28, - "VK_KHR_device_group": 28, - "VK_KHR_multiview": 28, - "VK_KHR_maintenance3": 28, - "VK_KHR_draw_indirect_count": 28, - "VK_KHR_create_renderpass2": 28, - "VK_KHR_depth_stencil_resolve": 29, - "VK_KHR_driver_properties": 28, - "VK_KHR_swapchain_mutable_format": 29, - "VK_KHR_shader_atomic_int64": 29, - "VK_KHR_vulkan_memory_model": 29, - - "VK_GOOGLE_display_timing": 26, - "VK_ANDROID_native_buffer": 26, - "VK_ANDROID_external_memory_android_hardware_buffer": 28, -} - -# Extensions with these prefixes are checked in Android CTS, and thus must be -# whitelisted per the preceding dict. -android_extension_whitelist_prefixes = ( - "VK_KHX", - "VK_KHR", - "VK_GOOGLE", - "VK_ANDROID" -) - -def GetExtensionCondition(ext_name, condition): - """ If |ext_name| is an extension that Android CTS cares about, prepend - a condition to ensure that the extension is only enabled for Android - versions in which the extension is whitelisted in CTS. """ - if not ext_name.startswith(android_extension_whitelist_prefixes): - return condition - allowed_version = allowed_android_version.get(ext_name, 9999) - return "(!ANDROID || ANDROID_API_LEVEL >= %d) && (%s)" % (allowed_version, - condition) - -_TEMPLATE_H = Template(COPYRIGHT + """ -#ifndef RADV_EXTENSIONS_H -#define RADV_EXTENSIONS_H - -enum { - RADV_INSTANCE_EXTENSION_COUNT = ${len(instance_extensions)}, - RADV_DEVICE_EXTENSION_COUNT = ${len(device_extensions)}, -}; - -struct radv_instance_extension_table { - union { - bool extensions[RADV_INSTANCE_EXTENSION_COUNT]; - struct { -%for ext in instance_extensions: - bool ${ext.name[3:]}; -%endfor - }; - }; -}; - -struct radv_device_extension_table { - union { - bool extensions[RADV_DEVICE_EXTENSION_COUNT]; - struct { -%for ext in device_extensions: - bool ${ext.name[3:]}; -%endfor - }; - }; -}; - -extern const VkExtensionProperties radv_instance_extensions[RADV_INSTANCE_EXTENSION_COUNT]; -extern const VkExtensionProperties radv_device_extensions[RADV_DEVICE_EXTENSION_COUNT]; -extern const struct radv_instance_extension_table radv_supported_instance_extensions; - - -struct radv_physical_device; - -void radv_fill_device_extension_table(const struct radv_physical_device *device, - struct radv_device_extension_table* table); -#endif -""") - -_TEMPLATE_C = Template(COPYRIGHT + """ -#include "radv_private.h" - -#include "vk_util.h" - -/* Convert the VK_USE_PLATFORM_* defines to booleans */ -%for platform in ['ANDROID_KHR', 'WAYLAND_KHR', 'XCB_KHR', 'XLIB_KHR', 'DISPLAY_KHR', 'XLIB_XRANDR_EXT']: -#ifdef VK_USE_PLATFORM_${platform} -# undef VK_USE_PLATFORM_${platform} -# define VK_USE_PLATFORM_${platform} true -#else -# define VK_USE_PLATFORM_${platform} false -#endif -%endfor - -/* And ANDROID too */ -#ifdef ANDROID -# undef ANDROID -# define ANDROID true -#else -# define ANDROID false -# define ANDROID_API_LEVEL 0 -#endif - -#define RADV_HAS_SURFACE (VK_USE_PLATFORM_WAYLAND_KHR || \\ - VK_USE_PLATFORM_XCB_KHR || \\ - VK_USE_PLATFORM_XLIB_KHR || \\ - VK_USE_PLATFORM_DISPLAY_KHR) - -static const uint32_t MAX_API_VERSION = ${MAX_API_VERSION.c_vk_version()}; - -const VkExtensionProperties radv_instance_extensions[RADV_INSTANCE_EXTENSION_COUNT] = { -%for ext in instance_extensions: - {"${ext.name}", ${ext.ext_version}}, -%endfor -}; - -const VkExtensionProperties radv_device_extensions[RADV_DEVICE_EXTENSION_COUNT] = { -%for ext in device_extensions: - {"${ext.name}", ${ext.ext_version}}, -%endfor -}; - -const struct radv_instance_extension_table radv_supported_instance_extensions = { -%for ext in instance_extensions: - .${ext.name[3:]} = ${GetExtensionCondition(ext.name, ext.enable)}, -%endfor -}; - -void radv_fill_device_extension_table(const struct radv_physical_device *device, - struct radv_device_extension_table* table) -{ - const struct radv_instance *instance = device->instance; -%for ext in device_extensions: - table->${ext.name[3:]} = ${GetExtensionCondition(ext.name, ext.enable)}; -%endfor -} - -VkResult radv_EnumerateInstanceVersion( - uint32_t* pApiVersion) -{ - *pApiVersion = MAX_API_VERSION; - return VK_SUCCESS; -} - -uint32_t -radv_physical_device_api_version(struct radv_physical_device *dev) -{ - uint32_t version = 0; - - uint32_t override = vk_get_version_override(); - if (override) - return MIN2(override, MAX_API_VERSION); - -%for version in API_VERSIONS: - if (!(${version.enable})) - return version; - version = ${version.version.c_vk_version()}; - -%endfor - return version; -} -""") - if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--out-c', help='Output C file.', required=True) @@ -519,21 +199,4 @@ if __name__ == '__main__': dest='xml_files') args = parser.parse_args() - for filename in args.xml_files: - _init_exts_from_xml(filename) - - for ext in EXTENSIONS: - assert ext.type == 'instance' or ext.type == 'device' - - template_env = { - 'API_VERSIONS': API_VERSIONS, - 'MAX_API_VERSION': MAX_API_VERSION, - 'instance_extensions': [e for e in EXTENSIONS if e.type == 'instance'], - 'device_extensions': [e for e in EXTENSIONS if e.type == 'device'], - 'GetExtensionCondition': GetExtensionCondition, - } - - with open(args.out_c, 'w') as f: - f.write(_TEMPLATE_C.render(**template_env)) - with open(args.out_h, 'w') as f: - f.write(_TEMPLATE_H.render(**template_env)) + gen_extensions('radv', args.xml_files, API_VERSIONS, MAX_API_VERSION, EXTENSIONS, args.out_c, args.out_h)