From 24dab0d402f9cf9ff24af077ea6c5349e2e956f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Fri, 18 Mar 2022 14:44:20 +0100 Subject: [PATCH] check scalar block layout device support if compile option is enabled --- CMakeLists.txt | 5 ++++ include/vkvg.h | 5 ++-- src/vkvg_device.c | 58 +++++++++++++++++++++++++---------------- tests/common/vkengine.c | 15 ++++++----- 4 files changed, 51 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b01b9847..5c1f1ae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,10 @@ ENDIF() if (CMAKE_BUILD_TYPE STREQUAL "Debug") ADD_DEFINITIONS (-DDEBUG) OPTION(ENABLE_VALIDATION "enable vulkan validation layer" ON) + OPTION(VKVG_USE_MESA_OVERLAY "enable VK_LAYER_MESA_overlay if present." OFF) + IF (VKVG_USE_MESA_OVERLAY) + ADD_DEFINITIONS (-DVKVG_USE_MESA_OVERLAY) + ENDIF () OPTION(ENABLE_DBG_UTILS "enable VK_EXT_debug_utils extension" ON) OPTION(ENABLE_WIRED_FILL "enable wired polygon draw to check vertices and primitives" OFF) IF (UNIX) @@ -45,6 +49,7 @@ ELSE() UNSET(ENABLE_VALIDATION CACHE) UNSET(ENABLE_DBG_UTILS CACHE) UNSET(ENABLE_WIRED_FILL CACHE) + UNSET(VKVG_USE_MESA_OVERLAY CACHE) IF (ANDROID) SET(CMAKE_${LANG}_FLAGS "${CMAKE_CXX_FLAGS} -O3 -w -ansi -pedantic") ELSEIF (UNIX) diff --git a/include/vkvg.h b/include/vkvg.h index 1b720e29..7313bd36 100644 --- a/include/vkvg.h +++ b/include/vkvg.h @@ -682,9 +682,10 @@ void vkvg_get_required_instance_extensions (const char** pExtensions, uint32_t* * @param pExtensions a valid pointer to the array of extension names to fill, the size may be queried * by calling this method with pExtension being a NULL pointer. * @param pExtCount a valid pointer to an integer that will be fill with the required extension count. - */ + * @return #VKVG_STATUS_SUCCESS or #VKVG_STATUS_DEVICE_ERROR if a fatal error occured. +*/ vkvg_public -void vkvg_get_required_device_extensions (VkPhysicalDevice phy, const char** pExtensions, uint32_t* pExtCount); +vkvg_status_t vkvg_get_required_device_extensions(VkPhysicalDevice phy, const char** pExtensions, uint32_t* pExtCount); /** * @brief get vulkan device creation requirement to fit vkvg needs. * diff --git a/src/vkvg_device.c b/src/vkvg_device.c index a9c32c9d..11ff1af3 100644 --- a/src/vkvg_device.c +++ b/src/vkvg_device.c @@ -152,12 +152,14 @@ bool _get_dev_extension_is_supported (VkExtensionProperties* pExtensionPropertie return false; } #define _CHECK_DEV_EXT(ext) { \ -if (_get_dev_extension_is_supported(pExtensionProperties, extensionCount, #ext)){ \ - if (pExtensions) \ - pExtensions[*pExtCount] = #ext; \ - (*pExtCount)++; \ + if (_get_dev_extension_is_supported(pExtensionProperties, extensionCount, #ext)){\ + if (pExtensions) \ + pExtensions[*pExtCount] = #ext; \ + (*pExtCount)++; \ + }\ } -void vkvg_get_required_device_extensions (VkPhysicalDevice phy, const char** pExtensions, uint32_t* pExtCount) { + +vkvg_status_t vkvg_get_required_device_extensions (VkPhysicalDevice phy, const char** pExtensions, uint32_t* pExtCount) { VkExtensionProperties* pExtensionProperties; uint32_t extensionCount; @@ -168,14 +170,23 @@ void vkvg_get_required_device_extensions (VkPhysicalDevice phy, const char** pEx VK_CHECK_RESULT(vkEnumerateDeviceExtensionProperties(phy, NULL, &extensionCount, pExtensionProperties)); //https://vulkan.lunarg.com/doc/view/1.2.162.0/mac/1.2-extensions/vkspec.html#VK_KHR_portability_subset - _CHECK_DEV_EXT(VK_KHR_portability_subset) + _CHECK_DEV_EXT(VK_KHR_portability_subset); - if (_get_dev_extension_is_supported(pExtensionProperties, extensionCount, "VK_EXT_scalar_block_layout")) - if (pExtensions) - pExtensions[*pExtCount] = "VK_EXT_scalar_block_layout"; - (*pExtCount)++; +#ifdef VKVG_VK_SCALAR_BLOCK_SUPPORTED + //ensure feature is implemented by driver. + VkPhysicalDeviceFeatures2 phyFeat2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; + VkPhysicalDeviceScalarBlockLayoutFeatures scalarBlockLayoutSupport = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES}; + phyFeat2.pNext = &scalarBlockLayoutSupport; + vkGetPhysicalDeviceFeatures2(phy, &phyFeat2); + if (!scalarBlockLayoutSupport.scalarBlockLayout) { + LOG(VKVG_LOG_ERR, "CREATE Device failed, vkvg compiled with VKVG_VK_SCALAR_BLOCK_SUPPORTED and feature is not implemented for physical device.\n"); + return VKVG_STATUS_DEVICE_ERROR; } + _CHECK_DEV_EXT(VK_EXT_scalar_block_layout) +#endif + + return VKVG_STATUS_SUCCESS; } //enabledFeature12 is guarantied to be the first in pNext chain @@ -187,23 +198,25 @@ const void* vkvg_get_device_requirements (VkPhysicalDeviceFeatures* pEnabledFeat void* pNext = NULL; -#ifdef VKVG_VK_SCALAR_BLOCK_SUPPORTED #ifdef VK_VERSION_1_2 static VkPhysicalDeviceVulkan12Features enabledFeatures12 = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES, - .scalarBlockLayout = VK_TRUE + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES +#ifdef VKVG_VK_SCALAR_BLOCK_SUPPORTED + ,.scalarBlockLayout = VK_TRUE +#endif }; enabledFeatures12.pNext = pNext; pNext = &enabledFeatures12; #else static VkPhysicalDeviceScalarBlockLayoutFeaturesEXT scalarBlockFeat = { - .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT, - .scalarBlockLayout = VK_TRUE + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT +#ifdef VKVG_VK_SCALAR_BLOCK_SUPPORTED + ,.scalarBlockLayout = VK_TRUE +#endif }; scalarBlockFeat.pNext = pNext; pNext = &scalarBlockFeat; -#endif #endif return pNext; @@ -281,13 +294,12 @@ VkvgDevice vkvg_device_create(VkSampleCountFlags samples, bool deferredResolve) enabledExtsCount=0; - VkPhysicalDeviceFeatures2 phyFeat2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; - VkPhysicalDeviceScalarBlockLayoutFeatures scalarBlockLayoutSupport = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES}; - phyFeat2.pNext = &scalarBlockLayoutSupport; - - vkGetPhysicalDeviceFeatures2 (pi->phy, &phyFeat2); - - vkvg_get_required_device_extensions (pi->phy, enabledExts, &enabledExtsCount); + if (vkvg_get_required_device_extensions (pi->phy, enabledExts, &enabledExtsCount) != VKVG_STATUS_SUCCESS){ + dev->status = VKVG_STATUS_DEVICE_ERROR; + vkh_app_free_phyinfos (phyCount, phys); + vkh_app_destroy (app); + return dev; + } VkPhysicalDeviceFeatures enabledFeatures = {0}; const void* pNext = vkvg_get_device_requirements (&enabledFeatures); diff --git a/tests/common/vkengine.c b/tests/common/vkengine.c index bf27d05d..b1e8a9d7 100644 --- a/tests/common/vkengine.c +++ b/tests/common/vkengine.c @@ -134,6 +134,10 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR if (vkh_layer_is_present("VK_LAYER_KHRONOS_validation")) enabledLayers[enabledLayersCount++] = "VK_LAYER_KHRONOS_validation"; #endif +#ifdef VKVG_USE_MESA_OVERLAY + if (vkh_layer_is_present("VK_LAYER_MESA_overlay")) + enabledLayers[enabledLayersCount++] = "VK_LAYER_MESA_overlay"; +#endif #ifdef VKVG_USE_RENDERDOC if (vkh_layer_is_present("VK_LAYER_RENDERDOC_Capture")) @@ -207,13 +211,10 @@ vk_engine_t* vkengine_create (VkPhysicalDeviceType preferedGPU, VkPresentModeKHR enabledExtsCount=0; - VkPhysicalDeviceFeatures2 phyFeat2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; - VkPhysicalDeviceScalarBlockLayoutFeatures scalarBlockLayoutSupport = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES}; - phyFeat2.pNext = &scalarBlockLayoutSupport; - - vkGetPhysicalDeviceFeatures2(pi->phy, &phyFeat2); - - vkvg_get_required_device_extensions (pi->phy, enabledExts, &enabledExtsCount); + if (vkvg_get_required_device_extensions (pi->phy, enabledExts, &enabledExtsCount) != VKVG_STATUS_SUCCESS) { + perror ("vkvg_get_required_device_extensions failed, enable log for details.\n"); + exit(-1); + } TRY_LOAD_DEVICE_EXT (VK_KHR_swapchain) VkPhysicalDeviceFeatures enabledFeatures = {0};