diff options
Diffstat (limited to 'src/intel/vulkan')
-rw-r--r-- | src/intel/vulkan/anv_device.c | 157 | ||||
-rw-r--r-- | src/intel/vulkan/anv_extensions.py | 118 | ||||
-rw-r--r-- | src/intel/vulkan/anv_private.h | 4 |
3 files changed, 126 insertions, 153 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index c72a1006749..70b5cd1ec68 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -406,102 +406,6 @@ anv_physical_device_finish(struct anv_physical_device *device) close(device->local_fd); } -static const VkExtensionProperties global_extensions[] = { - { - .extensionName = VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_SURFACE_EXTENSION_NAME, - .specVersion = 25, - }, -#ifdef VK_USE_PLATFORM_WAYLAND_KHR - { - .extensionName = VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME, - .specVersion = 6, - }, -#endif -#ifdef VK_USE_PLATFORM_XCB_KHR - { - .extensionName = VK_KHR_XCB_SURFACE_EXTENSION_NAME, - .specVersion = 6, - }, -#endif -#ifdef VK_USE_PLATFORM_XLIB_KHR - { - .extensionName = VK_KHR_XLIB_SURFACE_EXTENSION_NAME, - .specVersion = 6, - }, -#endif -}; - -static const VkExtensionProperties device_extensions[] = { - { - .extensionName = VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_MAINTENANCE1_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHR_SWAPCHAIN_EXTENSION_NAME, - .specVersion = 68, - }, - { - .extensionName = VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME, - .specVersion = 1, - }, - { - .extensionName = VK_KHX_MULTIVIEW_EXTENSION_NAME, - .specVersion = 1, - }, -}; - static void * default_alloc_func(void *pUserData, size_t size, size_t align, VkSystemAllocationScope allocationScope) @@ -556,15 +460,8 @@ VkResult anv_CreateInstance( } for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { - bool found = false; - for (uint32_t j = 0; j < ARRAY_SIZE(global_extensions); j++) { - if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], - global_extensions[j].extensionName) == 0) { - found = true; - break; - } - } - if (!found) + const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i]; + if (!anv_instance_extension_supported(ext_name)) return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); } @@ -1130,15 +1027,8 @@ VkResult anv_CreateDevice( assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO); for (uint32_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) { - bool found = false; - for (uint32_t j = 0; j < ARRAY_SIZE(device_extensions); j++) { - if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], - device_extensions[j].extensionName) == 0) { - found = true; - break; - } - } - if (!found) + const char *ext_name = pCreateInfo->ppEnabledExtensionNames[i]; + if (!anv_physical_device_extension_supported(physical_device, ext_name)) return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT); } @@ -1348,45 +1238,6 @@ void anv_DestroyDevice( vk_free(&device->alloc, device); } -VkResult anv_EnumerateInstanceExtensionProperties( - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties) -{ - if (pProperties == NULL) { - *pPropertyCount = ARRAY_SIZE(global_extensions); - return VK_SUCCESS; - } - - *pPropertyCount = MIN2(*pPropertyCount, ARRAY_SIZE(global_extensions)); - typed_memcpy(pProperties, global_extensions, *pPropertyCount); - - if (*pPropertyCount < ARRAY_SIZE(global_extensions)) - return VK_INCOMPLETE; - - return VK_SUCCESS; -} - -VkResult anv_EnumerateDeviceExtensionProperties( - VkPhysicalDevice physicalDevice, - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties) -{ - if (pProperties == NULL) { - *pPropertyCount = ARRAY_SIZE(device_extensions); - return VK_SUCCESS; - } - - *pPropertyCount = MIN2(*pPropertyCount, ARRAY_SIZE(device_extensions)); - typed_memcpy(pProperties, device_extensions, *pPropertyCount); - - if (*pPropertyCount < ARRAY_SIZE(device_extensions)) - return VK_INCOMPLETE; - - return VK_SUCCESS; -} - VkResult anv_EnumerateInstanceLayerProperties( uint32_t* pPropertyCount, VkLayerProperties* pProperties) diff --git a/src/intel/vulkan/anv_extensions.py b/src/intel/vulkan/anv_extensions.py index f325fe84da8..005a514eca8 100644 --- a/src/intel/vulkan/anv_extensions.py +++ b/src/intel/vulkan/anv_extensions.py @@ -63,3 +63,121 @@ EXTENSIONS = [ Extension('VK_KHR_xlib_surface', 6, 'VK_USE_PLATFORM_XLIB_KHR'), Extension('VK_KHX_multiview', 1, True), ] + +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'] + + for ext in EXTENSIONS: + assert ext.type == 'instance' or ext.type == 'device' + +TEMPLATE = Template(COPYRIGHT + """ +#include "anv_private.h" + +#include "vk_util.h" + +/* Convert the VK_USE_PLATFORM_* defines to booleans */ +%for platform in ['ANDROID', 'WAYLAND', 'XCB', 'XLIB']: +#ifdef VK_USE_PLATFORM_${platform}_KHR +# undef VK_USE_PLATFORM_${platform}_KHR +# define VK_USE_PLATFORM_${platform}_KHR true +#else +# define VK_USE_PLATFORM_${platform}_KHR false +#endif +%endfor + +bool +anv_instance_extension_supported(const char *name) +{ +%for ext in instance_extensions: + if (strcmp(name, "${ext.name}") == 0) + return ${ext.enable}; +%endfor + return false; +} + +VkResult anv_EnumerateInstanceExtensionProperties( + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ + VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount); + +%for ext in instance_extensions: + if (${ext.enable}) { + vk_outarray_append(&out, prop) { + *prop = (VkExtensionProperties) { + .extensionName = "${ext.name}", + .specVersion = ${ext.ext_version}, + }; + } + } +%endfor + + return vk_outarray_status(&out); +} + +bool +anv_physical_device_extension_supported(struct anv_physical_device *device, + const char *name) +{ +%for ext in device_extensions: + if (strcmp(name, "${ext.name}") == 0) + return ${ext.enable}; +%endfor + return false; +} + +VkResult anv_EnumerateDeviceExtensionProperties( + VkPhysicalDevice physicalDevice, + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ + ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice); + VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount); + (void)device; + +%for ext in device_extensions: + if (${ext.enable}) { + vk_outarray_append(&out, prop) { + *prop = (VkExtensionProperties) { + .extensionName = "${ext.name}", + .specVersion = ${ext.ext_version}, + }; + } + } +%endfor + + return vk_outarray_status(&out); +} +""") + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--out', help='Output C file.', required=True) + parser.add_argument('--xml', help='Vulkan API XML file.', required=True) + args = parser.parse_args() + + init_exts_from_xml(args.xml) + + template_env = { + 'instance_extensions': [e for e in EXTENSIONS if e.type == 'instance'], + 'device_extensions': [e for e in EXTENSIONS if e.type == 'device'], + } + + with open(args.out, 'w') as f: + f.write(TEMPLATE.render(**template_env)) diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 86c430397c8..818f6990dc7 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -684,6 +684,10 @@ struct anv_instance { VkResult anv_init_wsi(struct anv_physical_device *physical_device); void anv_finish_wsi(struct anv_physical_device *physical_device); +bool anv_instance_extension_supported(const char *name); +bool anv_physical_device_extension_supported(struct anv_physical_device *dev, + const char *name); + struct anv_queue { VK_LOADER_DATA _loader_data; |