blurrypiano / littleVulkanEngine

Code repo for video tutorial series teaching Vulkan and computer graphics
MIT License
829 stars 147 forks source link

Validation layer errors on macOS #34

Closed Radagan closed 2 years ago

Radagan commented 2 years ago

First off, thank you so much for these videos! I've been following along very well, but I've been getting these validation layer warnings and I'm not sure what to do with them. Ideas?

validation layer: Validation Error: [ VUID-VkDeviceCreateInfo-pProperties-04451 ] Object 0: handle = 0x600003346de0, type = VK_OBJECT_TYPE_PHYSICAL_DEVICE; | MessageID = 0x3a3b6ca0 | vkCreateDevice: VK_KHR_portability_subset must be enabled because physical device VkPhysicalDevice 0x600003346de0[] supports it The Vulkan spec states: If the VK_KHR_portability_subset extension is included in pProperties of vkEnumerateDeviceExtensionProperties, ppEnabledExtensionNames must include "VK_KHR_portability_subset" (https://vulkan.lunarg.com/doc/view/1.3.211.0/mac/1.3-extensions/vkspec.html#VUID-VkDeviceCreateInfo-pProperties-04451)
validation layer: vkCreateDevice: Attempting to create a VkDevice from a VkPhysicalDevice which is from a portability driver without the VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR bit in the VkInstanceCreateInfo flags being set and the VK_KHR_portability_enumeration extension enabled. In future versions of the loader this VkPhysicalDevice will not be enumerated.

Also, after making the changes for Lesson 5, I'm getting a "EXC_BAD_ACCESS (code=1, address=0x30)" when trying to create the pipeline. I'm wondering if it is related to these validation warnings or something I messed up in following along.

All advice most appreciated!

jefferycoulter commented 2 years ago

I ran into these warnings too. I think they have to do with Vulkan on the mac M1 being somewhat in an early phase. For the validation layer warnings, there are a few things to do. First, in the window.h file, or wherever you've included glfw, add #define VK_ENABLE_BETA_EXTENSIONS right before #include <GLFW/glfw3.h>. This is necessary to address the portability subset issue since the required extensions currently aren't included in the Vulkan core. Now in device.h, go to the private device_extensions char vector, which currently contains VK_KHR_SWAPCHAIN_EXTENSION_NAME, and add to it

VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME.

This depends on another extension, VK_KHR_get_physical_device_properties2. Go to the GetRequiredExtension() function in the device.cpp file and here, after initialization of the extensions char vector, add

extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)

This should address the first warning. Now, while still in the GetRequiredExtension(), also add

extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)

Then go to CreateInstance() in device.cpp and after you initialize the VkInstanceCreateInfo create_info struct, specify a flags member, create_info.flags = VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR.

This should take care of the second warning. Not sure about the EXC_BAD_ACCESS question.

Radagan commented 2 years ago

@jefferycoulter Thank you very much for your reply! As a follow on question, my development team is a mix of M1 and Intel macs (and also Windows 11), how would I configure the project to work correctly for both? Do I need to detect the architecture and fence these changes to only M1 macs or is there a cleaner way?

Radagan commented 2 years ago

Also, thank you very much for these amazing videos! I'm way farther along than I expected to be and that's thanks to you!

jefferycoulter commented 2 years ago

I haven't tried running on Windows with the above additions yet, but I think everything should still work on Windows and mac Intel so probably you don't need to do anything. If you only want to include these additions for mac M1, then probably the easiest approach would be to add something like #ifdef __arm64__ before the additional code. I'm not sure whether a second macro would be required for Windows, it will depend on whether you're using visual studio, but you can find a list and try some different ones here: https://sourceforge.net/p/predef/wiki/Architectures/

Also, I'm not the creator of this series, just another viewer. I ran into the same warnings and happened to see your question as I was trying to figure out how to resolve it. Best of luck!

Radagan commented 2 years ago

@jefferycoulter Thank you. Best of luck to you as well!