Skip to content

Commit

Permalink
check scalar block layout device support if compile option is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbruyere committed Mar 18, 2022
1 parent 3cc9d30 commit 24dab0d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions include/vkvg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
58 changes: 35 additions & 23 deletions src/vkvg_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
15 changes: 8 additions & 7 deletions tests/common/vkengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 24dab0d

Please sign in to comment.