@ -12,25 +12,14 @@
# include <wlr/config.h>
# include <wlr/config.h>
# include "render/vulkan.h"
# include "render/vulkan.h"
// Returns the name of the first extension that could not be found or NULL.
static bool check_extension ( const VkExtensionProperties * avail ,
static const char * find_extensions ( const VkExtensionProperties * avail ,
uint32_t avail_len , const char * name ) {
unsigned availc , const char * * req , unsigned reqc ) {
for ( size_t i = 0 ; i < avail_len ; i + + ) {
// check if all required extensions are supported
if ( strcmp ( avail [ i ] . extensionName , name ) = = 0 ) {
for ( size_t i = 0 ; i < reqc ; + + i ) {
return true ;
bool found = false ;
for ( size_t j = 0 ; j < availc ; + + j ) {
if ( ! strcmp ( avail [ j ] . extensionName , req [ i ] ) ) {
found = true ;
break ;
}
}
if ( ! found ) {
return req [ i ] ;
}
}
}
}
return false ;
return NULL ;
}
}
static VkBool32 debug_callback ( VkDebugUtilsMessageSeverityFlagBitsEXT severity ,
static VkBool32 debug_callback ( VkDebugUtilsMessageSeverityFlagBitsEXT severity ,
@ -134,12 +123,10 @@ struct wlr_vk_instance *vulkan_instance_create(bool debug) {
const char * extensions [ 1 ] = { 0 } ;
const char * extensions [ 1 ] = { 0 } ;
bool debug_utils_found = false ;
bool debug_utils_found = false ;
if ( debug ) {
if ( debug & & check_extension ( avail_ext_props , avail_extc ,
const char * name = VK_EXT_DEBUG_UTILS_EXTENSION_NAME ;
VK_EXT_DEBUG_UTILS_EXTENSION_NAME ) ) {
if ( find_extensions ( avail_ext_props , avail_extc , & name , 1 ) = = NULL ) {
debug_utils_found = true ;
debug_utils_found = true ;
extensions [ extensions_len + + ] = VK_EXT_DEBUG_UTILS_EXTENSION_NAME ;
extensions [ extensions_len + + ] = name ;
}
}
}
assert ( extensions_len < = sizeof ( extensions ) / sizeof ( extensions [ 0 ] ) ) ;
assert ( extensions_len < = sizeof ( extensions ) / sizeof ( extensions [ 0 ] ) ) ;
@ -328,10 +315,10 @@ VkPhysicalDevice vulkan_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd)
continue ;
continue ;
}
}
const char * name = VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME ;
bool has_drm_props = check_extension ( avail_ext_props , avail_extc ,
bool has_drm_props = find_extensions ( avail_ext_props , avail_extc , & name , 1 ) = = NULL ;
VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME ) ;
name = VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME ;
bool has_driver_props = check_extension ( avail_ext_props , avail_extc ,
bool has_driver_props = find_extensions ( avail_ext_props , avail_extc , & name , 1 ) = = NULL ;
VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME ) ;
VkPhysicalDeviceProperties2 props = { 0 } ;
VkPhysicalDeviceProperties2 props = { 0 } ;
props . sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 ;
props . sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 ;
@ -425,12 +412,12 @@ struct wlr_vk_device *vulkan_device_create(struct wlr_vk_instance *ini,
} ;
} ;
size_t extensions_len = sizeof ( extensions ) / sizeof ( extensions [ 0 ] ) ;
size_t extensions_len = sizeof ( extensions ) / sizeof ( extensions [ 0 ] ) ;
const char * not_found =
for ( size_t i = 0 ; i < extensions_len ; i + + ) {
find_extensions ( avail_ext_props , avail_extc , extensions , extensions_len ) ;
if ( ! check_extension ( avail_ext_props , avail_extc , extensions [ i ] ) ) {
if ( not_found ) {
wlr_log ( WLR_ERROR , " vulkan: required device extension %s not found " ,
wlr_log ( WLR_ERROR , " vulkan: required device extension %s not found " ,
extensions [ i ] ) ;
not_found ) ;
goto error ;
goto error ;
}
}
}
// queue families
// queue families