]> O.S.I.I.S - jp/vkvg.git/commitdiff
check instance extensions support before activation in VkvgDevice
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 8 Dec 2021 04:58:25 +0000 (05:58 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 8 Dec 2021 04:58:25 +0000 (05:58 +0100)
src/vkvg_device.c
src/vkvg_device_internal.c
src/vkvg_device_internal.h

index 43f561af79822971cbc95c8ed5a075ff7d63da82..1326b714f29f7ea208f60a8715be114899a822ed 100644 (file)
 VkvgDevice vkvg_device_create(VkSampleCountFlags samples, bool deferredResolve) {
        const char* enabledExts [10];
        uint32_t enabledExtsCount = 0, phyCount = 0;
+       _instance_extensions_check_init ();
+
 #if defined(DEBUG) && defined (VKVG_DBG_UTILS)
-       enabledExts[enabledExtsCount++] = "VK_EXT_debug_utils";
+       bool dbgUtilsSupported = _instance_extension_supported("VK_EXT_debug_utils");
+        if (dbgUtilsSupported)
+               enabledExts[enabledExtsCount++] = "VK_EXT_debug_utils";
 #endif
-       enabledExts[enabledExtsCount++] = "VK_KHR_get_physical_device_properties2";
+       if (_instance_extension_supported("VK_KHR_get_physical_device_properties2"))
+               enabledExts[enabledExtsCount++] = "VK_KHR_get_physical_device_properties2";
+
+       _instance_extensions_check_release();
 
        VkhApp app =  vkh_app_create("vkvg", 0, NULL, enabledExtsCount, enabledExts);
 
 #if defined(DEBUG) && defined (VKVG_DBG_UTILS)
-       vkh_app_enable_debug_messenger(app
-                                                                  , VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT
-                                                                  , VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT
-                                                                  , NULL);
+       if (dbgUtilsSupported)
+               vkh_app_enable_debug_messenger(app
+                                                               , VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT
+                                                               , VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT
+                                                               , NULL);
 #endif
        VkhPhyInfo* phys = vkh_app_get_phyinfos (app, &phyCount, VK_NULL_HANDLE);
        if (phyCount == 0) {
index 84a64eb8312343e79eebb032d80e23aa8f9f19f3..602323e6b597875c4447f7b80f86381949edb3dd 100644 (file)
@@ -501,6 +501,23 @@ void _check_best_image_tiling (VkvgDevice dev, VkFormat format) {
        LOG(VKVG_LOG_ERR, "vkvg create device failed: image format not supported: %d\n", format);
 }
 
+static VkExtensionProperties* instExtProps;
+static uint32_t instExtCount;
+bool _instance_extension_supported (const char* instanceName) {
+       for (uint32_t i=0; i<instExtCount; i++) {
+               if (!strcmp(instExtProps[i].extensionName, instanceName))
+                       return true;
+       }
+       return false;
+}
+void _instance_extensions_check_init () {
+       VK_CHECK_RESULT(vkEnumerateInstanceExtensionProperties(NULL, &instExtCount, NULL));
+       instExtProps =(VkExtensionProperties*)malloc(instExtCount * sizeof(VkExtensionProperties));
+       VK_CHECK_RESULT(vkEnumerateInstanceExtensionProperties(NULL, &instExtCount, instExtProps));
+}
+void _instance_extensions_check_release () {
+       free (instExtProps);
+}
 void _dump_image_format_properties (VkvgDevice dev, VkFormat format) {
        /*VkImageFormatProperties imgProps;
        VK_CHECK_RESULT(vkGetPhysicalDeviceImageFormatProperties(dev->phy,
index b317841a13792f85895dfefa8e40b152bd48682b..0cbc9532a5ae3126707ce1e93b8b99bb1a77e292 100644 (file)
@@ -117,4 +117,9 @@ void _flush_all_contexes            (VkvgDevice dev);
 void _wait_idle                                        (VkvgDevice dev);
 void _wait_and_reset_device_fence (VkvgDevice dev);
 void _submit_cmd                               (VkvgDevice dev, VkCommandBuffer* cmd, VkFence fence);
+
+bool _instance_extension_supported             (const char* instanceName);
+void _instance_extensions_check_init   ();
+void _instance_extensions_check_release ();
+
 #endif