My PC supports DirectX11 & Vulkan. I run my unity game with vulkan without problems.
- OS: Windows 10
- GPU: Nvidia GeForce GT750M
I need to check Vulkan support in a separate C++ project. It is necessary to know about possibility to run my game with vulkan command line arguments.
Here's the code:
bool checkVulkanSupport(VkResult* res) {
// Initialize Vulkan instance
VkInstance instance;
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
// Add validation layers
const char* validationLayers[] = { "VK_LAYER_KHRONOS_validation" };
createInfo.enabledLayerCount = 1;
createInfo.ppEnabledLayerNames = validationLayers;
*res = vkCreateInstance(&createInfo, nullptr, &instance);// << VK_ERROR_INITIALIZATION_FAILED
// Create a Vulkan instance
if (*res != VK_SUCCESS)
return false; // Vulkan instance creation failed
uint32_t deviceCount = 0;
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
if (deviceCount == 0) {
vkDestroyInstance(instance, nullptr);
return false; // No physical devices found
}
std::vector<VkPhysicalDevice> devices(deviceCount);
vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
bool supportsVulkan = false;
for (const auto& device : devices) {
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(device, &deviceProperties);
// Check if the Vulkan version is at least 1.0.0
if (deviceProperties.apiVersion >= VK_API_VERSION_1_0) {
supportsVulkan = true; // Found a Vulkan-supporting device
break; // No need to check further
}
}
vkDestroyInstance(instance, nullptr); // Clean up Vulkan instance
return supportsVulkan;
}
I don't know why, but vkCreateInstance returns VK_ERROR_INITIALIZATION_FAILED.
This part of code causes the problem:
// Initialize Vulkan instance
VkInstance instance;
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
// Add validation layers
const char* validationLayers[] = { "VK_LAYER_KHRONOS_validation" };
createInfo.enabledLayerCount = 1;
createInfo.ppEnabledLayerNames = validationLayers;
*res = vkCreateInstance(&createInfo, nullptr, &instance);// << VK_ERROR_INITIALIZATION_FAILED
Why vkCreateInstance returns VK_ERROR_INITIALIZATION_FAILED?
int main(...), compiles and shows your issue is a good place to start. it will be helpful if you could add amakecommand to compile and run your example.