From: Bas Nieuwenhuizen Date: Sat, 10 Feb 2018 20:43:55 +0000 (+0100) Subject: radv: Put supported extensions in a struct. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=4db78f3a6b20cfd790dd0ac35d67f4abe94ea530;p=mesa.git radv: Put supported extensions in a struct. Reviewed-by: Dave Airlie --- diff --git a/src/amd/vulkan/meson.build b/src/amd/vulkan/meson.build index 0a7b7c0bf3c..98051560a52 100644 --- a/src/amd/vulkan/meson.build +++ b/src/amd/vulkan/meson.build @@ -32,9 +32,10 @@ radv_entrypoints = custom_target( radv_extensions_c = custom_target( 'radv_extensions.c', input : ['radv_extensions.py', vk_api_xml, vk_android_native_buffer_xml], - output : ['radv_extensions.c'], + output : ['radv_extensions.c', 'radv_extensions.h'], command : [ - prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@', '--out', '@OUTPUT@', + prog_python2, '@INPUT0@', '--xml', '@INPUT1@', '--xml', '@INPUT2@', '--out-c', '@OUTPUT0@', + '--out-h', '@OUTPUT1@' ], ) diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index 98cfd9b58a9..9ee8ae2beb0 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -303,6 +303,7 @@ radv_physical_device_init(struct radv_physical_device *device, device->rad_info.family == CHIP_RAVEN; radv_physical_device_init_mem_types(device); + radv_fill_device_extension_table(device, &device->supported_extensions); result = radv_init_wsi(device); if (result != VK_SUCCESS) { @@ -2242,6 +2243,65 @@ VkResult radv_DeviceWaitIdle( return VK_SUCCESS; } +bool +radv_instance_extension_supported(const char *name) +{ + for (unsigned i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; ++i) { + if (strcmp(name, radv_instance_extensions[i].extensionName) == 0) + return radv_supported_instance_extensions.extensions[i]; + } + return false; +} + +VkResult radv_EnumerateInstanceExtensionProperties( + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ + VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount); + + for (int i = 0; i < RADV_INSTANCE_EXTENSION_COUNT; i++) { + if (radv_supported_instance_extensions.extensions[i]) { + vk_outarray_append(&out, prop) { + *prop = radv_instance_extensions[i]; + } + } + } + + return vk_outarray_status(&out); +} + +bool +radv_physical_device_extension_supported(struct radv_physical_device *device, + const char *name) +{ + for (unsigned i = 0; i < RADV_DEVICE_EXTENSION_COUNT; ++i) { + if (strcmp(name, radv_device_extensions[i].extensionName) == 0) + return device->supported_extensions.extensions[i]; + } + return false; +} + +VkResult radv_EnumerateDeviceExtensionProperties( + VkPhysicalDevice physicalDevice, + const char* pLayerName, + uint32_t* pPropertyCount, + VkExtensionProperties* pProperties) +{ + RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice); + VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount); + + for (int i = 0; i < RADV_DEVICE_EXTENSION_COUNT; i++) { + if (device->supported_extensions.extensions[i]) { + vk_outarray_append(&out, prop) { + *prop = radv_device_extensions[i]; + } + } + } + + return vk_outarray_status(&out); +} + PFN_vkVoidFunction radv_GetInstanceProcAddr( VkInstance instance, const char* pName) diff --git a/src/amd/vulkan/radv_extensions.py b/src/amd/vulkan/radv_extensions.py index d761895d3a0..ac6ec8744e0 100644 --- a/src/amd/vulkan/radv_extensions.py +++ b/src/amd/vulkan/radv_extensions.py @@ -162,7 +162,50 @@ def _init_exts_from_xml(xml): ext = ext_name_map[ext_name] ext.type = ext_elem.attrib['type'] -_TEMPLATE = Template(COPYRIGHT + """ +_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 + }; + }; +}; + +const VkExtensionProperties radv_instance_extensions[RADV_INSTANCE_EXTENSION_COUNT]; +const VkExtensionProperties radv_device_extensions[RADV_DEVICE_EXTENSION_COUNT]; +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" @@ -189,82 +232,43 @@ _TEMPLATE = Template(COPYRIGHT + """ VK_USE_PLATFORM_XCB_KHR || \\ VK_USE_PLATFORM_XLIB_KHR) -bool -radv_instance_extension_supported(const char *name) -{ +const VkExtensionProperties radv_instance_extensions[RADV_INSTANCE_EXTENSION_COUNT] = { %for ext in instance_extensions: - if (strcmp(name, "${ext.name}") == 0) - return ${ext.enable}; + {"${ext.name}", ${ext.ext_version}}, %endfor - return false; -} +}; -VkResult radv_EnumerateInstanceExtensionProperties( - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties) -{ - VK_OUTARRAY_MAKE(out, pProperties, pPropertyCount); +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: - if (${ext.enable}) { - vk_outarray_append(&out, prop) { - *prop = (VkExtensionProperties) { - .extensionName = "${ext.name}", - .specVersion = ${ext.ext_version}, - }; - } - } + .${ext.name[3:]} = ${ext.enable}, %endfor +}; - return vk_outarray_status(&out); -} - -uint32_t -radv_physical_device_api_version(struct radv_physical_device *dev) -{ - return ${MAX_API_VERSION.c_vk_version()}; -} - -bool -radv_physical_device_extension_supported(struct radv_physical_device *device, - const char *name) +void radv_fill_device_extension_table(const struct radv_physical_device *device, + struct radv_device_extension_table* table) { %for ext in device_extensions: - if (strcmp(name, "${ext.name}") == 0) - return ${ext.enable}; + table->${ext.name[3:]} = ${ext.enable}; %endfor - return false; } -VkResult radv_EnumerateDeviceExtensionProperties( - VkPhysicalDevice physicalDevice, - const char* pLayerName, - uint32_t* pPropertyCount, - VkExtensionProperties* pProperties) +uint32_t +radv_physical_device_api_version(struct radv_physical_device *dev) { - RADV_FROM_HANDLE(radv_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); + return ${MAX_API_VERSION.c_vk_version()}; } """) if __name__ == '__main__': parser = argparse.ArgumentParser() - parser.add_argument('--out', help='Output C file.', required=True) + parser.add_argument('--out-c', help='Output C file.', required=True) + parser.add_argument('--out-h', help='Output H file.', required=True) parser.add_argument('--xml', help='Vulkan API XML file.', required=True, @@ -284,5 +288,7 @@ if __name__ == '__main__': 'device_extensions': [e for e in EXTENSIONS if e.type == 'device'], } - with open(args.out, 'w') as f: - f.write(_TEMPLATE.render(**template_env)) + 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)) diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index be9e8f43964..335c8417e77 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -57,6 +57,7 @@ #include "ac_gpu_info.h" #include "ac_surface.h" #include "radv_descriptor_set.h" +#include "radv_extensions.h" #include @@ -285,6 +286,8 @@ struct radv_physical_device { VkPhysicalDeviceMemoryProperties memory_properties; enum radv_mem_type mem_type_indices[RADV_MEM_TYPE_COUNT]; + + struct radv_device_extension_table supported_extensions; }; struct radv_instance {