implement system dependency detection for vulkan headers
The official Vulkan headers don't include the VK_MVK_moltenvk. Use macro
to guard related code.
Test: CC=clang CXX=clang++ cmake ../ -G Ninja -D VIRGL_RENDERER_UNSTABLE_APIS=ON -DDEPENDENCY_RESOLUTION=SYSTEM && ninja
Change-Id: Iddc57d3ddef9c81406788016c6c163af861d3eaa
diff --git a/stream-servers/vulkan/VkCommonOperations.cpp b/stream-servers/vulkan/VkCommonOperations.cpp
index c4f5848..3e444a9 100644
--- a/stream-servers/vulkan/VkCommonOperations.cpp
+++ b/stream-servers/vulkan/VkCommonOperations.cpp
@@ -531,8 +531,10 @@
extensionsSupported(exts, externalMemoryInstanceExtNames);
bool externalSemaphoreCapabilitiesSupported =
extensionsSupported(exts, externalSemaphoreInstanceExtNames);
+#ifdef VK_MVK_moltenvk
bool moltenVKSupported =
(vk->vkGetMTLTextureMVK != nullptr) && (vk->vkSetMTLTextureMVK != nullptr);
+#endif
VkInstanceCreateInfo instCi = {
VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, 0, 0, nullptr, 0, nullptr, 0, nullptr,
@@ -546,12 +548,14 @@
}
}
+#ifdef VK_MVK_moltenvk
if (moltenVKSupported) {
// We don't need both moltenVK and external memory. Disable
// external memory if moltenVK is supported.
externalMemoryCapabilitiesSupported = false;
enabledExtensions.clear();
}
+#endif
for (auto extension : SwapChainStateVk::getRequiredInstanceExtensions()) {
enabledExtensions.emplace(extension);
@@ -640,7 +644,9 @@
sVkEmulation->instanceSupportsExternalMemoryCapabilities = externalMemoryCapabilitiesSupported;
sVkEmulation->instanceSupportsExternalSemaphoreCapabilities = externalSemaphoreCapabilitiesSupported;
+#ifdef VK_MVK_moltenvk
sVkEmulation->instanceSupportsMoltenVK = moltenVKSupported;
+#endif
if (sVkEmulation->instanceSupportsExternalMemoryCapabilities) {
sVkEmulation->getImageFormatProperties2Func = vk_util::getVkInstanceProcAddrWithFallback<
@@ -654,6 +660,7 @@
vk_util::getVkInstanceProcAddrWithFallback<vk_util::vk_fn_info::GetPhysicalDeviceFeatures2>(
{ivk->vkGetInstanceProcAddr, vk->vkGetInstanceProcAddr}, sVkEmulation->instance);
+#ifdef VK_MVK_moltenvk
if (sVkEmulation->instanceSupportsMoltenVK) {
sVkEmulation->setMTLTextureFunc = reinterpret_cast<PFN_vkSetMTLTextureMVK>(
vk->vkGetInstanceProcAddr(sVkEmulation->instance, "vkSetMTLTextureMVK"));
@@ -670,6 +677,7 @@
}
// LOG(VERBOSE) << "Instance supports VK_MVK_moltenvk.";
}
+#endif
uint32_t physdevCount = 0;
ivk->vkEnumeratePhysicalDevices(sVkEmulation->instance, &physdevCount, nullptr);
@@ -1811,16 +1819,16 @@
return false;
}
+#if defined(VK_MVK_moltenvk) && defined(__APPLE__)
if (sVkEmulation->instanceSupportsMoltenVK) {
sVkEmulation->getMTLTextureFunc(res.image, &res.mtlTexture);
if (!res.mtlTexture) {
fprintf(stderr, "%s: Failed to get MTLTexture.\n", __func__);
}
-#ifdef __APPLE__
CFRetain(res.mtlTexture);
-#endif
}
+#endif
bool glExported = sVkEmulation->deviceInfo.supportsExternalMemory &&
sVkEmulation->deviceInfo.glInteropSupported && glCompatible && !vulkanOnly;