Skip to content

Commit

Permalink
Use VKB_ENABLE_PORTABILITY vs. VK_ENABLE_BETA_EXTENSIONS to guard por…
Browse files Browse the repository at this point in the history
…tability subset features
  • Loading branch information
SRSaunders committed Jul 19, 2024
1 parent fcf6826 commit 6e73f7c
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 33 deletions.
9 changes: 2 additions & 7 deletions bldsys/cmake/global_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,10 @@ endif()

if(APPLE)
cmake_minimum_required(VERSION 3.24)
set(VKB_ENABLE_PORTABILITY ON CACHE BOOL "Enable portability enumeration and subset features in the framework. This is required to be set when running on Apple platforms." FORCE)
if(IOS)
set(CMAKE_XCODE_GENERATE_SCHEME TRUE)
endif ()
find_package(Vulkan)
if(Vulkan_VERSION GREATER_EQUAL 1.3)
set(VKB_ENABLE_PORTABILITY ON CACHE BOOL "Enable portability extension enumeration in the framework. This is required to be set if running MoltenVK and Vulkan 1.3+" FORCE)
else()
set(VKB_ENABLE_PORTABILITY OFF CACHE BOOL "Enable portability extension enumeration in the framework. This is required to be off if running Vulkan less than 1.3" FORCE)
endif()
endif()
endif()

set(VKB_WARNINGS_AS_ERRORS ON CACHE BOOL "Enable Warnings as Errors")
Expand Down
2 changes: 1 addition & 1 deletion components/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ if(ANDROID)
elseif(WIN32)
target_compile_definitions(vkb__core PUBLIC VK_USE_PLATFORM_WIN32_KHR PLATFORM__WINDOWS)
elseif(APPLE)
target_compile_definitions(vkb__core PUBLIC VK_USE_PLATFORM_METAL_EXT VK_ENABLE_BETA_EXTENSIONS PLATFORM__MACOS)
target_compile_definitions(vkb__core PUBLIC VK_USE_PLATFORM_METAL_EXT PLATFORM__MACOS)
elseif(UNIX)
target_compile_definitions(vkb__core PUBLIC PLATFORM__LINUX)

Expand Down
2 changes: 1 addition & 1 deletion framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ if(${VKB_VULKAN_DEBUG})
endif()

if(${VKB_ENABLE_PORTABILITY})
message(STATUS "Vulkan Portability extension is enabled")
message(STATUS "Vulkan Portability Enumeration and Portability Subset extensions are enabled")
target_compile_definitions(${PROJECT_NAME} PUBLIC VKB_ENABLE_PORTABILITY)
endif()

Expand Down
7 changes: 6 additions & 1 deletion framework/core/hpp_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,12 @@ HPPInstance::HPPInstance(const std::string &applicati
#endif

#if (defined(VKB_ENABLE_PORTABILITY))
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](vk::ExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
}
#endif

#ifdef USE_VALIDATION_LAYER_FEATURES
Expand Down
7 changes: 6 additions & 1 deletion framework/core/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,12 @@ Instance::Instance(const std::string &application_nam
#endif

#if (defined(VKB_ENABLE_PORTABILITY))
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](VkExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
#endif

// Some of the specialized layers need to be enabled explicitly
Expand Down
2 changes: 1 addition & 1 deletion framework/vulkan_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,7 @@ inline bool VulkanSample<bindingType>::prepare(const ApplicationOptions &options
}
}

#ifdef VK_ENABLE_BETA_EXTENSIONS
#ifdef VKB_ENABLE_PORTABILITY
// VK_KHR_portability_subset must be enabled if present in the implementation (e.g on macOS/iOS with beta extensions enabled)
add_device_extension(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME, /*optional=*/true);
#endif
Expand Down
22 changes: 16 additions & 6 deletions samples/api/hello_triangle/hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ void HelloTriangle::init_instance(Context &context,
uint32_t instance_extension_count;
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, nullptr));

std::vector<VkExtensionProperties> instance_extensions(instance_extension_count);
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, instance_extensions.data()));
std::vector<VkExtensionProperties> available_instance_extensions(instance_extension_count);
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, available_instance_extensions.data()));

std::vector<const char *> active_instance_extensions(required_instance_extensions);

#if defined(VKB_DEBUG) || defined(VKB_VALIDATION_LAYERS)
bool has_debug_report = false;
for (const auto &ext : instance_extensions)
for (const auto &ext : available_instance_extensions)
{
if (strcmp(ext.extensionName, VK_EXT_DEBUG_REPORT_EXTENSION_NAME) == 0)
{
Expand All @@ -197,7 +197,12 @@ void HelloTriangle::init_instance(Context &context,

#if (defined(VKB_ENABLE_PORTABILITY))
active_instance_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
active_instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](VkExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
active_instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
}
#endif

#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand All @@ -218,7 +223,7 @@ void HelloTriangle::init_instance(Context &context,
# pragma error Platform not supported
#endif

if (!validate_extensions(active_instance_extensions, instance_extensions))
if (!validate_extensions(active_instance_extensions, available_instance_extensions))
{
throw std::runtime_error("Required instance extensions are missing.");
}
Expand Down Expand Up @@ -274,7 +279,12 @@ void HelloTriangle::init_instance(Context &context,
#endif

#if (defined(VKB_ENABLE_PORTABILITY))
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](VkExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
instance_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
#endif

// Create the Vulkan instance
Expand Down
14 changes: 12 additions & 2 deletions samples/api/hpp_hello_triangle/hpp_hello_triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,12 @@ vk::Instance HPPHelloTriangle::create_instance(std::vector<const char *> const &

#if (defined(VKB_ENABLE_PORTABILITY))
active_instance_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
active_instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](vk::ExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
active_instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
}
#endif

#if defined(VK_USE_PLATFORM_ANDROID_KHR)
Expand Down Expand Up @@ -499,7 +504,12 @@ vk::Instance HPPHelloTriangle::create_instance(std::vector<const char *> const &
#endif

#if (defined(VKB_ENABLE_PORTABILITY))
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](vk::ExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
instance_info.flags |= vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR;
}
#endif

// Create the Vulkan instance
Expand Down
8 changes: 4 additions & 4 deletions samples/extensions/portability/portability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Portability::Portability() :
// Portability is a Vulkan 1.3 extension
set_api_version(VK_API_VERSION_1_3);
add_instance_extension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
add_instance_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
add_instance_extension(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, /*optional*/ true);
}

Portability::~Portability()
Expand Down Expand Up @@ -832,7 +832,7 @@ bool Portability::prepare(const vkb::ApplicationOptions &options)
// Note: Using reversed depth-buffer for increased precision, so Znear and Zfar are flipped
camera.set_perspective(60.0f, static_cast<float>(width) / static_cast<float>(height), 256.0f, 0.1f);

#ifdef VK_ENABLE_BETA_EXTENSIONS
#ifdef VKB_ENABLE_PORTABILITY
portability_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_KHR;
VkPhysicalDeviceFeatures2 device_features{};
device_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
Expand Down Expand Up @@ -867,7 +867,7 @@ void Portability::render(float delta_time)

void Portability::on_update_ui_overlay(vkb::Drawer &drawer)
{
#ifdef VK_ENABLE_BETA_EXTENSIONS
#ifdef VKB_ENABLE_PORTABILITY
std::string portability_support_list;
if (portability_features.constantAlphaColorBlendFactors)
portability_support_list += "constantAlphaColorBlendFactors\n";
Expand Down Expand Up @@ -901,7 +901,7 @@ void Portability::on_update_ui_overlay(vkb::Drawer &drawer)
portability_support_list += "vertexAttributeAccessBeyondStride\n";
drawer.text("Device Portability feature support list:\n%s", portability_support_list.c_str());
#else
drawer.text("VK_ENABLE_BETA_EXTENSIONS not enabled can't list portability feature set");
drawer.text("VKB_ENABLE_PORTABILITY not enabled can't list portability feature set");
#endif
if (drawer.header("Settings"))
{
Expand Down
2 changes: 1 addition & 1 deletion samples/extensions/portability/portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Portability : public ApiVulkanSample
public:
bool bloom = true;
bool display_skysphere = true;
#ifdef VK_ENABLE_BETA_EXTENSIONS
#ifdef VKB_ENABLE_PORTABILITY
VkPhysicalDevicePortabilitySubsetFeaturesKHR portability_features{};
#endif

Expand Down
18 changes: 15 additions & 3 deletions samples/extensions/shader_debugprintf/shader_debugprintf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,16 @@ std::unique_ptr<vkb::Instance> ShaderDebugPrintf::create_instance(bool headless)
VK_CHECK(vkEnumerateInstanceExtensionProperties(nullptr, &instance_extension_count, available_instance_extensions.data()));

// When VK_EXT_layer_settings is available at runtime, the debugPrintfEXT layer feature is enabled using the standard framework
// Note this check is necessary in the short term for backwards compatibility with SDKs < 1.3.272 without VK_EXT_layer_settings
// For backwards compatibility with SDKs < 1.3.272 without VK_EXT_layer_settings, the remainder of this custom override is required
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](VkExtensionProperties extension) { return strcmp(extension.extensionName, VK_EXT_LAYER_SETTINGS_EXTENSION_NAME) == 0; }))
{
// Run standard create_instance() from framework (with layer settings support) and return
return VulkanSample::create_instance(headless);
}

// Run remainder of this custom create_instance() (without layer settings support) and return
std::vector<const char *> enabled_extensions;
enabled_extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);

Expand All @@ -458,7 +460,12 @@ std::unique_ptr<vkb::Instance> ShaderDebugPrintf::create_instance(bool headless)
enabled_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
enabled_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
#if (defined(VKB_ENABLE_PORTABILITY))
enabled_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](VkExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
enabled_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
}
#endif

VkApplicationInfo app_info{VK_STRUCTURE_TYPE_APPLICATION_INFO};
Expand All @@ -482,7 +489,12 @@ std::unique_ptr<vkb::Instance> ShaderDebugPrintf::create_instance(bool headless)
instance_create_info.ppEnabledLayerNames = validation_layers.data();
instance_create_info.enabledLayerCount = static_cast<uint32_t>(validation_layers.size());
#if (defined(VKB_ENABLE_PORTABILITY))
instance_create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
if (std::any_of(available_instance_extensions.begin(),
available_instance_extensions.end(),
[](VkExtensionProperties extension) { return strcmp(extension.extensionName, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME) == 0; }))
{
instance_create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
}
#endif
instance_create_info.pNext = &validation_features;

Expand Down
4 changes: 2 additions & 2 deletions samples/performance/async_compute/async_compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ AsyncComputeSample::AsyncComputeSample()

void AsyncComputeSample::request_gpu_features(vkb::PhysicalDevice &gpu)
{
#ifdef VK_ENABLE_BETA_EXTENSIONS
// We need to enable the mutableComparisonSamplers feature of the VK_KHR_portability_subset extension
#ifdef VKB_ENABLE_PORTABILITY
// Since sampler_info.compareEnable = VK_TRUE, must enable the mutableComparisonSamplers feature of VK_KHR_portability_subset
auto &requested_portability_subset_features = gpu.request_extension_features<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_KHR);
requested_portability_subset_features.mutableComparisonSamplers = VK_TRUE;
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ MultithreadingRenderPasses::MultithreadingRenderPasses()

void MultithreadingRenderPasses::request_gpu_features(vkb::PhysicalDevice &gpu)
{
#ifdef VK_ENABLE_BETA_EXTENSIONS
// We need to enable the mutableComparisonSamplers feature of the VK_KHR_portability_subset extension
#ifdef VKB_ENABLE_PORTABILITY
// Since shadowmap_sampler_create_info.compareEnable = VK_TRUE, must enable the mutableComparisonSamplers feature of VK_KHR_portability_subset
auto &requested_portability_subset_features = gpu.request_extension_features<VkPhysicalDevicePortabilitySubsetFeaturesKHR>(VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PORTABILITY_SUBSET_FEATURES_KHR);
requested_portability_subset_features.mutableComparisonSamplers = VK_TRUE;
#endif
Expand Down
6 changes: 5 additions & 1 deletion third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ target_include_directories(vulkan SYSTEM INTERFACE ${VULKAN_INCLUDE_DIR})

target_compile_definitions(vulkan INTERFACE VK_NO_PROTOTYPES)

if(VKB_ENABLE_PORTABILITY)
# When portability is enabled, must enable Vulkan beta extensions for access to VK_KHR_portability_subset
target_compile_definitions(vulkan INTERFACE VK_ENABLE_BETA_EXTENSIONS)
endif()

if(ANDROID)
target_compile_definitions(vulkan INTERFACE VK_USE_PLATFORM_ANDROID_KHR)
elseif(WIN32)
target_compile_definitions(vulkan INTERFACE VK_USE_PLATFORM_WIN32_KHR)
elseif(APPLE)
target_compile_definitions(vulkan INTERFACE VK_USE_PLATFORM_METAL_EXT VK_ENABLE_BETA_EXTENSIONS)
target_compile_definitions(vulkan INTERFACE VK_USE_PLATFORM_METAL_EXT)
elseif(UNIX)
# Choose WSI based on VKB_WSI_SELECTION
if (VKB_WSI_SELECTION STREQUAL XCB OR VKB_WSI_SELECTION STREQUAL XLIB OR VKB_WSI_SELECTION STREQUAL WAYLAND)
Expand Down

0 comments on commit 6e73f7c

Please sign in to comment.