Fix VK_KHR_portability_subset validation errors on macOS, fix OpenMP build issues on macOS

(cherry picked from commit d2f6713c418ea5bdd2c3fcee922def5854e534d4)
This commit is contained in:
Stephen Saunders 2022-05-09 14:16:16 -04:00
parent 2810087752
commit ae8ad09f6e
3 changed files with 52 additions and 7 deletions

View file

@ -8,6 +8,10 @@
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
*/
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
// SRS - This is needed to make visible VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME
#define VK_ENABLE_BETA_EXTENSIONS
#endif
#include <VulkanDevice.h>
#include <unordered_set>
@ -279,6 +283,14 @@ namespace vks
enableDebugMarkers = true;
}
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
// SRS - When running on iOS/macOS with MoltenVK, must enable the VK_KHR_portability_subset device extension
if (extensionSupported(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME))
{
deviceExtensions.push_back(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME);
}
#endif
if (deviceExtensions.size() > 0)
{
for (const char* enabledExtension : deviceExtensions)

View file

@ -55,6 +55,14 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
instanceExtensions.push_back(VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME);
#endif
#if (defined(VK_USE_PLATFORM_IOS_MVK) || defined(VK_USE_PLATFORM_MACOS_MVK))
// SRS - When running on iOS/macOS with MoltenVK, enable VkPhysicalDeviceFeatures2 if not already enabled (required by VK_KHR_portability_subset)
if (std::find(enabledInstanceExtensions.begin(), enabledInstanceExtensions.end(), VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME) == enabledInstanceExtensions.end())
{
enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
}
#endif
#if defined(VK_USE_PLATFORM_MACOS_MVK) && (VK_HEADER_VERSION >= 216)
instanceExtensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
instanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
@ -75,6 +83,14 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
}
}
#if defined(VK_KHR_portability_enumeration)
// SRS - When VK_KHR_portability_enumeration is defined and supported, enable it to properly enumerate the physical device
if (std::find(supportedInstanceExtensions.begin(), supportedInstanceExtensions.end(), VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) != supportedInstanceExtensions.end())
{
enabledInstanceExtensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
}
#endif
// Enabled requested instance extensions
if (enabledInstanceExtensions.size() > 0)
{
@ -102,11 +118,19 @@ VkResult VulkanExampleBase::createInstance(bool enableValidation)
{
if (settings.validation)
{
instanceExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME); // SRS - Dependency when VK_EXT_DEBUG_MARKER is enabled
instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
}
#if defined(VK_KHR_portability_enumeration)
// SRS - When VK_KHR_portability_enumeration is defined and enabled, the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR flag must be set
if (std::find(instanceExtensions.begin(), instanceExtensions.end(), VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) != instanceExtensions.end())
{
instanceCreateInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
#endif
// The VK_LAYER_KHRONOS_validation contains all current validation functionality.
// Note that on Android this layer requires at least NDK r20

View file

@ -12,15 +12,23 @@ function(buildExample EXAMPLE_NAME)
SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h)
ENDIF()
if(APPLE)
# SRS - Use MacPorts paths as default since they are the same on x86 and Apple Silicon, can override on cmake command line
if(NOT OpenMP_omp_LIBRARY)
set(OpenMP_omp_LIBRARY /opt/local/lib/libomp/libomp.dylib)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_C_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_C_FLAGS "-Xclang -fopenmp")
set(OpenMP_C_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY /opt/local/lib/libomp/libomp.dylib)
if(NOT OpenMP_C_INCLUDE_DIR)
set(OpenMP_C_INCLUDE_DIR /opt/local/include/libomp)
endif()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang\$")
set(OpenMP_CXX_FLAGS "-Xpreprocessor -fopenmp")
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
set(OpenMP_CXX_LIB_NAMES "omp")
set(OpenMP_omp_LIBRARY /opt/local/lib/libomp/libomp.dylib)
if(NOT OpenMP_CXX_INCLUDE_DIR)
set(OpenMP_CXX_INCLUDE_DIR /opt/local/include/libomp)
endif()
endif()
endif()
find_package(OpenMP)
@ -51,14 +59,15 @@ function(buildExample EXAMPLE_NAME)
endif(WIN32)
set_target_properties(${EXAMPLE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
if(OpenMP_CXX_FOUND)
target_compile_options(${EXAMPLE_NAME} PRIVATE ${OpenMP_CXX_FLAGS})
#if(OpenMP_CXX_FOUND)
# SRS - target_compile_options is not needed when using target_link_libraries(<target> OpenMP::OpenMP_CXX) syntax below
#target_compile_options(${EXAMPLE_NAME} PRIVATE ${OpenMP_CXX_FLAGS})
IF(${EXAMPLE_NAME} STREQUAL "texture3d")
if(OpenMP_CXX_FOUND)
target_link_libraries(${EXAMPLE_NAME} OpenMP::OpenMP_CXX)
endif()
endif()
endif()
#endif()
if(RESOURCE_INSTALL_DIR)
install(TARGETS ${EXAMPLE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})