Skip to content

Commit

Permalink
igl | vulkan | Split common instance and device extensions into separ…
Browse files Browse the repository at this point in the history
…ate functions

Reviewed By: rokuz, mmaurer

Differential Revision: D65504581

fbshipit-source-id: c5c4f7f8aa595d9406de19eb6e46f328ededd33e
  • Loading branch information
corporateshark authored and facebook-github-bot committed Nov 7, 2024
1 parent 6002e71 commit 93a3c3c
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 62 deletions.
4 changes: 2 additions & 2 deletions src/igl/vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ void VulkanContext::createInstance(const size_t numExtraExtensions,
const char* IGL_NULLABLE* IGL_NULLABLE extraExtensions) {
// Enumerate all instance extensions
extensions_.enumerate(vf_);
extensions_.enableCommonExtensions(VulkanExtensions::ExtensionType::Instance, config_);
extensions_.enableCommonInstanceExtensions(config_);
for (size_t index = 0; index < numExtraExtensions; ++index) {
extensions_.enable(extraExtensions[index], VulkanExtensions::ExtensionType::Instance);
}
Expand Down Expand Up @@ -733,7 +733,7 @@ igl::Result VulkanContext::initContext(const HWDeviceDesc& desc,
}
#endif

extensions_.enableCommonExtensions(VulkanExtensions::ExtensionType::Device, config_);
extensions_.enableCommonDeviceExtensions(config_);
// Enable extra device extensions
for (size_t i = 0; i < numExtraDeviceExtensions; i++) {
extensions_.enable(extraDeviceExtensions[i], VulkanExtensions::ExtensionType::Device);
Expand Down
114 changes: 55 additions & 59 deletions src/igl/vulkan/VulkanExtensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,113 +85,109 @@ void VulkanExtensions::forceEnable(const char* extensionName, ExtensionType exte
enabledExtensions_[vectorIndex].insert(extensionName);
}

void VulkanExtensions::enableCommonExtensions(ExtensionType extensionType,
const VulkanContextConfig& config) {
if (extensionType == ExtensionType::Instance) {
enable(VK_KHR_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
enable(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, ExtensionType::Instance);
void VulkanExtensions::enableCommonInstanceExtensions(const VulkanContextConfig& config) {
enable(VK_KHR_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
enable(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, ExtensionType::Instance);
#if defined(VK_EXT_debug_utils)
enable(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, ExtensionType::Instance);
enable(VK_EXT_DEBUG_UTILS_EXTENSION_NAME, ExtensionType::Instance);
#endif
#if IGL_PLATFORM_WIN
enable(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
enable(VK_KHR_WIN32_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
#elif IGL_PLATFORM_ANDROID
enable("VK_KHR_android_surface", ExtensionType::Instance);
enable("VK_KHR_android_surface", ExtensionType::Instance);
#elif IGL_PLATFORM_LINUX
enable("VK_KHR_xlib_surface", ExtensionType::Instance);
enable("VK_KHR_xlib_surface", ExtensionType::Instance);
#elif IGL_PLATFORM_MACOS
enable(VK_EXT_METAL_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
enable(VK_EXT_METAL_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
#endif

#if IGL_PLATFORM_MACOS
// https://vulkan.lunarg.com/doc/sdk/1.3.216.0/mac/getting_started.html
if (!enable(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, ExtensionType::Instance)) {
IGL_LOG_ERROR("VK_KHR_portability_enumeration extension not supported\n");
}
// https://vulkan.lunarg.com/doc/sdk/1.3.216.0/mac/getting_started.html
if (!enable(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, ExtensionType::Instance)) {
IGL_LOG_ERROR("VK_KHR_portability_enumeration extension not supported\n");
}
#endif

#if !IGL_PLATFORM_ANDROID
if (config.enableValidation) {
enable(VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME, ExtensionType::Instance);
}
if (config.enableValidation) {
enable(VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME, ExtensionType::Instance);
}
#endif
if (config.headless) {
if (config.headless) {
#if defined(VK_EXT_headless_surface)
const bool enabledExtension =
enable(VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
const bool enabledExtension =
enable(VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME, ExtensionType::Instance);
#else
const bool enabledExtension = false;
const bool enabledExtension = false;
#endif // VK_EXT_headless_surface
if (!enabledExtension) {
IGL_LOG_ERROR("VK_EXT_headless_surface extension not supported");
}
if (!enabledExtension) {
IGL_LOG_ERROR("VK_EXT_headless_surface extension not supported");
}
if (config.swapChainColorSpace != igl::ColorSpace::SRGB_NONLINEAR) {
}
if (config.swapChainColorSpace != igl::ColorSpace::SRGB_NONLINEAR) {
#if defined(VK_EXT_swapchain_colorspace)
const bool enabledExtension =
enable(VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME, ExtensionType::Instance);
const bool enabledExtension =
enable(VK_EXT_SWAPCHAIN_COLOR_SPACE_EXTENSION_NAME, ExtensionType::Instance);
#else
const bool enabledExtension = false;
const bool enabledExtension = false;
#endif
if (!enabledExtension) {
IGL_LOG_ERROR("VK_EXT_swapchain_colorspace extension not supported\n");
}
if (!enabledExtension) {
IGL_LOG_ERROR("VK_EXT_swapchain_colorspace extension not supported\n");
}
} else if (extensionType == ExtensionType::Device) {
}
}

void VulkanExtensions::enableCommonDeviceExtensions(const VulkanContextConfig& config) {
#if defined(VK_KHR_shader_float16_int8) && VK_KHR_shader_float16_int8
enable(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, ExtensionType::Device);
#endif
#if IGL_PLATFORM_ANDROID
enable(VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, ExtensionType::Device);
enable(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME,
ExtensionType::Device);
if (config.enableDescriptorIndexing) {
enable(VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, ExtensionType::Device);
enable(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, ExtensionType::Device);
if (config.enableDescriptorIndexing) {
#endif
// On Android, vkEnumerateInstanceExtensionProperties crashes when validation layers are
// enabled for DEBUG builds. https://issuetracker.google.com/issues/209835779?pli=1 Hence,
// allow developers to not enable certain extensions on Android which are not present.
enable(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, ExtensionType::Device);
// On Android, vkEnumerateInstanceExtensionProperties crashes when validation layers are
// enabled for DEBUG builds. https://issuetracker.google.com/issues/209835779?pli=1 Hence,
// allow developers to not enable certain extensions on Android which are not present.
enable(VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, ExtensionType::Device);
#if IGL_PLATFORM_ANDROID
}
}
#endif
#if defined(VK_KHR_driver_properties)
enable(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME, ExtensionType::Device);
#endif // VK_KHR_driver_properties
#if defined(VK_KHR_shader_non_semantic_info)
#if !IGL_PLATFORM_ANDROID || !IGL_DEBUG
// On Android, vkEnumerateInstanceExtensionProperties crashes when validation layers are
// enabled for DEBUG builds. https://issuetracker.google.com/issues/209835779?pli=1 Hence,
// don't enable some extensions on Android which are not present and no way to check without
// crashing.
enable(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, ExtensionType::Device);
// On Android, vkEnumerateInstanceExtensionProperties crashes when validation layers are
// enabled for DEBUG builds. https://issuetracker.google.com/issues/209835779?pli=1 Hence,
// don't enable some extensions on Android which are not present and no way to check without
// crashing.
enable(VK_KHR_SHADER_NON_SEMANTIC_INFO_EXTENSION_NAME, ExtensionType::Device);
#endif // !IGL_PLATFORM_ANDROID || !IGL_DEBUG
#endif // VK_KHR_shader_non_semantic_info
enable(VK_KHR_SWAPCHAIN_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_SWAPCHAIN_EXTENSION_NAME, ExtensionType::Device);

#if IGL_PLATFORM_MACOS
std::ignore = IGL_DEBUG_VERIFY(enable("VK_KHR_portability_subset", ExtensionType::Device));
std::ignore = IGL_DEBUG_VERIFY(enable("VK_KHR_portability_subset", ExtensionType::Device));
#endif

#if IGL_PLATFORM_WIN
enable(VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME, ExtensionType::Device);
#endif // IGL_PLATFORM_WIN

#if IGL_PLATFORM_LINUX
enable(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, ExtensionType::Device);
enable(VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME, ExtensionType::Device);
#endif // IGL_PLATFORM_LINUX

#if defined(IGL_WITH_TRACY_GPU) && defined(VK_EXT_calibrated_timestamps)
enable(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, ExtensionType::Device);
enable(VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, ExtensionType::Device);
#endif

#if defined(VK_EXT_index_type_uint8)
has8BitIndices = enable(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, ExtensionType::Device);
has8BitIndices = enable(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, ExtensionType::Device);
#endif
} else {
IGL_DEBUG_ABORT("Unrecognized extension type when enabling common extensions.");
}
}

bool VulkanExtensions::enabled(const char* extensionName) const {
Expand Down
3 changes: 2 additions & 1 deletion src/igl/vulkan/VulkanExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class VulkanExtensions final {
/// @param extensionType The type of the extensions
/// @param validationEnabled Flag that informs the class whether the Validation Layer is
/// enabled or not.
void enableCommonExtensions(ExtensionType extensionType, const VulkanContextConfig& config);
void enableCommonInstanceExtensions(const VulkanContextConfig& config);
void enableCommonDeviceExtensions(const VulkanContextConfig& config);

/// @brief Enables the extension with name `extensionName` of the type `extensionType` if the
/// extension is available. If an instance or physical device deoesn't support the
Expand Down

0 comments on commit 93a3c3c

Please sign in to comment.