kondrak / vkQuake2

id Software's Quake 2 v3.21 with mission packs and Vulkan support (Windows, Linux, macOS, FreeBSD, Raspberry Pi 4)
GNU General Public License v2.0
896 stars 90 forks source link

MacOS run issue "Could not create Vulkan instance" #150

Closed lexin closed 1 year ago

lexin commented 2 years ago

Hi. I successfully built the source. But when try to run have a crash Initializing Metal display ...setting mode 11: 1920 1080 2022-08-18 11:34:40.648156+0300 quake2[3123:33025] Metal API Validation Enabled Enabled extensions: VK_KHR_surface VK_MVK_macos_surface VK_KHR_get_physical_device_properties2 VK_EXT_debug_utils QVk_Init(): Could not create Vulkan instance: VK_ERROR_INCOMPATIBLE_DRIVER ref_vk::R_Init() - could not initialize Vulkan!

lexin commented 2 years ago
Screenshot 2022-08-18 at 11 36 39
d8d8d8d8sk commented 2 years ago

Funny that you mention this, I was asking around in the Vulkan discord and a moderator there posted this advice

If you are running on macOS, then vkQuake hasn't been updated to work on portability subset devices (at least the most recent change). 

If you want to fix it, you need to make the instance creation 1. add the VK_KHR_portability_enumeration extension, and 2. set the "enumerate_portability_devices" instance flag bit

They also linked this PR which fixed something similar: https://github.com/LunarG/VulkanTools/commit/035f02c355510c1e58e66c13c702ab6f2ea6c0ef

chestergan commented 2 years ago

Having this same error after building on M1 MacOS and attempting to run.

However, I am able to successfully complete the build and run the game under Vulkan SDK version 1.2.170.0.

tomgreen66 commented 2 years ago

Had a quick look - looks like the following needs adding (with some logic possibly when not required).

/tomgreen66/vkQuake2/tree/macos_vulkan

diff --git a/macos/vk_imp.m b/macos/vk_imp.m
index a8e0da9..99ff9fa 100644
--- a/macos/vk_imp.m
+++ b/macos/vk_imp.m
@@ -318,13 +318,14 @@ void Vkimp_GetInstanceExtensions(char **extensions, uint32_t *extCount)
        {
                extensions[0] = VK_KHR_SURFACE_EXTENSION_NAME;
                extensions[1] = VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
+               extensions[2] = VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME;
                // required by VK_EXT_full_screen_exclusive and VK_KHR_portability_subset
                if (vk_config.vk_khr_get_physical_device_properties2_available)
-                       extensions[2] = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME;
+                       extensions[3] = VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME;
        }

        if (extCount)
-               *extCount = vk_config.vk_khr_get_physical_device_properties2_available ? 3 : 2;
+               *extCount = vk_config.vk_khr_get_physical_device_properties2_available ? 4 : 3;
 }

 VkResult Vkimp_CreateSurface()
diff --git a/ref_vk/vk_common.c b/ref_vk/vk_common.c
index 273f208..3ce1e07 100644
--- a/ref_vk/vk_common.c
+++ b/ref_vk/vk_common.c
@@ -1662,10 +1662,11 @@ qboolean QVk_Init()
                .pDisabledValidationFeatures = NULL
        };
 #endif

        VkInstanceCreateInfo createInfo = {
                .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
                .pNext = NULL,
+               .flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR,
                .pApplicationInfo = &appInfo,
                .enabledLayerCount = 0,
                .ppEnabledLayerNames = NULL,
lexin commented 1 year ago

I used these changes https://github.com/kondrak/vkQuake2/pull/151 and it has been built successfully. And now I have an error Couldn't load pics/colormap.pcx As far as I understand - I have to add the content from a legally purchased copy. But can't find it.

tomgreen66 commented 1 year ago

The way I tend to run it is where the executable is built - e.g. under macos/release there should be a baseq2 directory and then inside baseq2 just make sure the .pak files are placed in that directory from a purchased copy (or use demo pak files). The pics/colormap.pcx is inside those pak files.