I am trying to create an instance for a basic Vulkan renderer. When creating an instance on Mac I am using the same code that I used in visual studio on windows. I am using Xcode on Mac with C++. Immediately after creating an instance when creating a debug messenger an assert is called in Vulkan.h called VULKAN_HPP_ASSERT. When putting create instance in a try catch statement with a throw runtime error then I get an error that says it is from improper use of vkWaitForFences. This code works on windows with no errors. I have no idea as to what is causing the error.
I have tried checking the version and I have set up a bunch of debug statements to make sure all the layers and extensions are supported. They are all successful and supported.
debug print statements:
System can Support vulkan variant: 0,
Major: 1,
Minor: 3,
Patch: 280
Supperted Extensions:
VK_KHR_device_group_creation
VK_KHR_external_fence_capabilities
VK_KHR_external_memory_capabilities
VK_KHR_external_semaphore_capabilities
VK_KHR_get_physical_device_properties2
VK_KHR_get_surface_capabilities2
VK_KHR_surface
VK_EXT_debug_report
VK_EXT_debug_utils
VK_EXT_headless_surface
VK_EXT_layer_settings
VK_EXT_metal_surface
VK_EXT_surface_maintenance1
VK_EXT_swapchain_colorspace
VK_MVK_macos_surface
VK_KHR_portability_enumeration
VK_LUNARG_direct_driver_loading
Required Extensions:
“VK_KHR_surface
“VK_EXT_metal_surface
“VK_EXT_debug_utils
VK_KHR_surface is a supported extension
VK_EXT_metal_surface is a supported extension
VK_EXT_debug_utils is a supported extension
Requested Layers:
VK_LAYER_KHRONOS_validation
Supperted Layers:
VK_LAYER_LUNARG_api_dump
VK_LAYER_KHRONOS_profiles
VK_LAYER_KHRONOS_validation
VK_LAYER_LUNARG_screenshot
VK_LAYER_KHRONOS_synchronization2
VK_LAYER_KHRONOS_shader_object
VK_LAYER_KHRONOS_validation is a supported layer
code:
void Engine::createInstance(const char* appName)
{
if (m_Debug)
{
std::cout << “Instance being created…” << std::endl;
}
//unsigned int version{ 0 };
unsigned int version{ 0 };
if (vk::enumerateInstanceVersion(&version) == vk::Result::eSuccess)
{
if (m_Debug)
{
std::cout << "System can Support vulkan variant: " <<
VK_API_VERSION_VARIANT(version)
<< ",nMajor: " << VK_API_VERSION_MAJOR(version)
<< ",nMinor: " << VK_API_VERSION_MINOR(version)
<< ",nPatch: " << VK_API_VERSION_PATCH(version) << "n";
}
}
else
{
std::cout << "Failed to check Instance version";
}
version &= ~(0xFFFU);
version = VK_MAKE_API_VERSION(0, 1, 0, 0);
vk::ApplicationInfo appInfo = vk::ApplicationInfo(
appName,
version,
appName,
version,
version
);
// Extensions
unsigned int glfwExtensionCount = 0;
const char** glfwExtensions;
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
std::vector<const char*> extensions(glfwExtensions, glfwExtensions +
glfwExtensionCount);
if (m_Debug)
{
extensions.push_back("VK_EXT_debug_utils");
}
//Validation Layers
std::vector<const char*> layers;
if (m_Debug)
{
layers.push_back("VK_LAYER_KHRONOS_validation");
}
if (!supportedAdditions(nullptr, extensions, layers))
{
throw std::runtime_error("Extensions or Layers are not supported.nYou should check
to see if you are using the right extensions or layers");
}
vk::InstanceCreateInfo createInfo = vk::InstanceCreateInfo(
vk::InstanceCreateFlags(),
&appInfo,
static_cast<unsigned int>(layers.size()), layers.data(),
static_cast<unsigned int>(extensions.size()), extensions.data()
);
try
{
m_Instance = vk::createInstance(createInfo);
if (m_Debug)
{
std::cout << "Successfully created instance" << std::endl;
}
}
catch (const vk::SystemError& err)
{
//throw std::runtime_error("Failed to create Vulkan instance: " +
std::string(err.what())); //vkWaitForFences error on this line
}
}
void Engine::createDebugMessenger()
{
std::cout << "nCreating debug messenger..." << std::endl;
m_Dldi = vk::DispatchLoaderDynamic(m_Instance, vkGetInstanceProcAddr);//ASSERT on this
line
... rest of create debug messenger function
Eriond is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.