Skip to content

[ET-VK][mac] Allow vulkan binaries to work with Vulkan SDK + fixes to enable debugPrintf extension #7957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions backends/vulkan/runtime/vk_api/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,52 @@ VkInstance create_instance(const RuntimeConfig& config) {
std::vector<const char*> enabled_layers;
std::vector<const char*> enabled_extensions;

std::vector<const char*> requested_layers;
std::vector<const char*> requested_extensions;

if (config.enable_validation_messages) {
std::vector<const char*> requested_layers{
// "VK_LAYER_LUNARG_api_dump",
"VK_LAYER_KHRONOS_validation",
};
std::vector<const char*> requested_extensions{
requested_layers.emplace_back("VK_LAYER_KHRONOS_validation");
#ifdef VK_EXT_debug_report
VK_EXT_DEBUG_REPORT_EXTENSION_NAME,
requested_extensions.emplace_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
#endif /* VK_EXT_debug_report */
};

find_requested_layers_and_extensions(
enabled_layers,
enabled_extensions,
requested_layers,
requested_extensions);
}

VkInstanceCreateFlags instance_flags = 0;
#ifdef __APPLE__
instance_flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
requested_extensions.emplace_back(
VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
#endif

find_requested_layers_and_extensions(
enabled_layers,
enabled_extensions,
requested_layers,
requested_extensions);

const void* instance_create_next = nullptr;
// VkConfig on Mac platforms does not expose debugPrintf settings for whatever
// reason so it has to be enabled manually.
#if defined(__APPLE__) && defined(VULKAN_DEBUG)
std::vector<VkValidationFeatureEnableEXT> enabled_validation_features{
VK_VALIDATION_FEATURE_ENABLE_DEBUG_PRINTF_EXT,
};
VkValidationFeaturesEXT validation_features = {
VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT, // sType
nullptr, // pNext
static_cast<uint32_t>(
enabled_validation_features.size()), // enabledValidationFeatureCount
enabled_validation_features.data(), // pEnabledValidationFeatures
0,
nullptr, // pDisabledValidationFeatures
};
instance_create_next = &validation_features;
#endif /* __APPLE__ && VULKAN_DEBUG */

const VkInstanceCreateInfo instance_create_info{
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType
nullptr, // pNext
0u, // flags
instance_create_next, // pNext
instance_flags, // flags
&application_info, // pApplicationInfo
static_cast<uint32_t>(enabled_layers.size()), // enabledLayerCount
enabled_layers.data(), // ppEnabledLayerNames
Expand Down
20 changes: 16 additions & 4 deletions backends/vulkan/targets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,31 @@ def define_common_targets(is_fbcode = False):
"fbsource//third-party/swiftshader/lib/linux-x64:libvk_swiftshader_so",
]
else:
link_moltenvk = read_config("etvk", "link_moltenvk", "1") == "1"
mac_deps = default_deps
if link_moltenvk:
mac_deps = [
"//third-party/khronos:moltenVK_static"
]
mac_flags = default_flags
if link_moltenvk:
mac_flags = []

VK_API_DEPS += select({
"DEFAULT": default_deps,
"ovr_config//os:android": android_deps,
"ovr_config//os:macos": [
"//third-party/khronos:moltenVK_static"
],
"ovr_config//os:macos": mac_deps,
})
VK_API_PREPROCESSOR_FLAGS += select({
"DEFAULT": default_flags,
"ovr_config//os:android": android_flags,
"ovr_config//os:macos": []
"ovr_config//os:macos": mac_flags,
})

debug_mode = read_config("etvk", "debug", "0") == "1"
if debug_mode:
VK_API_PREPROCESSOR_FLAGS += ["-DVULKAN_DEBUG"]

runtime.cxx_library(
name = "vulkan_compute_api{}".format(suffix),
compiler_flags = get_vulkan_compiler_flags(),
Expand Down
Loading