EQMG / Acid

A high speed C++17 Vulkan game engine
https://equilibrium.games
MIT License
1.72k stars 154 forks source link

No ICD Drivers found with MoltenVK [macos] #135

Open s-daveb opened 7 months ago

s-daveb commented 7 months ago

Please see my reply, I may have a fix

Describe the bug I was able to build everything on my system, with minimal warnings, but when I run the program, I get an exception and vulkan layer errors.

To Reproduce

brew install molten-vk vulkan-extensionlayer vulkan-tools vulkan-volk vulkan-headers vulkan-utility-libraries vulkan-loader vulkan-validationlayers ```

cd ~/Developer/C++/Acid
cmake -B Build -G Ninja -DCMAKE_BUILD_TYPE=Debug
cmake --build Build
Build/bin/Tutorial1
Version: 0.14.3
Git: 2ff8adee3 on master
Compiled on: Darwin-22.6.0 from: Ninja with: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++

Instance Layers: VK_LAYER_KHRONOS_timeline_semaphore, VK_LAYER_KHRONOS_validation, VK_LAYER_KHRONOS_synchronization2, VK_LAYER_KHRONOS_shader_object,

Searching for ICD drivers named ../../../lib/libMoltenVK.dylib
vkCreateInstance: Found drivers that contain devices which support the portability subset, but the instance does not enumerate portability drivers! Applications that wish to enumerate portability drivers must set the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo flags and enable the VK_KHR_portability_enumeration instance extension.
vkCreateInstance: Found no drivers!
libc++abi: terminating due to uncaught exception of type std::runtime_error: Vulkan error: The requested version of Vulkan is not supported by the driver or is otherwise incompatible

*Expected behaviour** The tutorial runs

Screenshots N/A

Hardware:

Additional context

╰─➤  brew search moltenvk
==> Formulae
molten-vk ✔

╰─➤  brew search vulkan
==> Formulae
vulkan-extensionlayer ✔           vulkan-tools ✔                    vulkan-volk ✔
vulkan-headers ✔                  vulkan-utility-libraries ✔
vulkan-loader ✔                   vulkan-validationlayers ✔

I think maybe Vulkan is being initialized without portability extensions? I've done very little Vulkan programming, but when I have, I have to add:

#ifdef __APPLE__
       extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
        extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
#endif

//...

vk::InstanceCreateInfo createInfo({}, &appInfo, 0, nullptr, static_cast<uint32_t>(extensions.size()), extensions.data());

#ifdef __APPLE__
        createInfo.setFlags(vk::InstanceCreateFlagBits::eEnumeratePortabilityKHR);
#endif
s-daveb commented 7 months ago

The following patch seems to fix that ICD exception. But it turns out that MoltenVK does not support Geometry Shaders (at least on my GPU) - so I can't load the tutorials anyway.

diff --git a/Sources/Graphics/Devices/Instance.cpp b/Sources/Graphics/Devices/Instance.cpp
index 323e191db..febff8877 100644
--- a/Sources/Graphics/Devices/Instance.cpp
+++ b/Sources/Graphics/Devices/Instance.cpp
@@ -145,6 +145,12 @@ std::vector<const char *> Instance::GetExtensions() const {
    if (enableValidationLayers)
        extensions.emplace_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
    //extensions.emplace_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
+
+#ifdef __APPLE__
+       // macOS specific extensions
+   extensions.emplace_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
+   extensions.emplace_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
+#endif
    return extensions;
 }

@@ -168,6 +174,7 @@ void Instance::CreateInstance() {
        enableValidationLayers = false;
    }

+
    auto extensions = GetExtensions();

    VkInstanceCreateInfo instanceCreateInfo = {};
@@ -176,6 +183,10 @@ void Instance::CreateInstance() {
    instanceCreateInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
    instanceCreateInfo.ppEnabledExtensionNames = extensions.data();

+#ifdef __APPLE__
+   instanceCreateInfo.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR;
+#endif
+
 #if USE_DEBUG_MESSENGER
    VkDebugUtilsMessengerCreateInfoEXT debugUtilsMessengerCreateInfo = {};
 #endif
mPorst commented 6 months ago

The tutorials seem to be broken, see also this editor issue. I'm in the process of getting into the engine, the TestPhysics works on my devices (windows and linux) but seems to depend on a large ecosystem of additional classes (scene, camera, ui, ...) I tried to get tutorial1 running and I'm currently stuck at the fact that at some point the camera is queried but returns a nullptr. So I try to figure out how to create a scene... Anyway, I can't directly answer your question but hope the info helps you :)