Home > OS >  Creating logical device in Vulkan returns -8, but only sometimes
Creating logical device in Vulkan returns -8, but only sometimes

Time:11-01

While using a class to hold my window class and Vulkan class, this error VK_ERROR_FEATURE_NOT_PRESENT is returned when I use vkCreateDevice however, when I put the same code the class is running into the main class, it works completely fine. I also had a similar problem with getting the instance extensions via SDL_Vulkan_GetInstanceExtensions.

working main.cpp

    window.createWindow();
    engine.window = window.window;

    try {
        engine.initialize();
    }
    catch (XiError error) {
        std::cout << "Error " << error.code << ": " << error.definition << std::endl;
    }

    window.instance = engine.getVkInstance();

    VkPhysicalDeviceProperties deviceProperties;
    vkGetPhysicalDeviceProperties(engine.physicalDevice, &deviceProperties);

    std::cout << deviceProperties.deviceName << ", Driver Version " << deviceProperties.driverVersion << std::endl;

    try {
        window.createSurface();
    }
    catch (XiError error) {
        std::cout << "Error " << error.code << ": " << error.definition << std::endl;
    }
    window.mainLoop();

    vkDestroyDevice(engine.logicalDevice, nullptr);

    vkDestroySurfaceKHR(engine.instance, window.surface, nullptr);
    vkDestroyInstance(engine.instance, nullptr);

    SDL_DestroyWindow(window.window);
    SDL_Quit();

not working main.cpp

    try {
        app.run();
    }
    catch (XiError error) {
        std::cout << "Error " << error.code << ": " << error.definition << std::endl;
    }

        VkPhysicalDeviceProperties deviceProperties;
        vkGetPhysicalDeviceProperties(app.engine.physicalDevice, &deviceProperties);

        std::cout << deviceProperties.deviceName << ", Driver Version " << deviceProperties.driverVersion << std::endl;

    app.window.mainLoop();
    app.shutDown();

app.run()

    window.createWindow();
    
    engine.window = window.window;
    engine.createVulkanInstance();
    
    window.instance = engine.getVkInstance();
    window.createSurface();
    
    engine.getPhysicalDevices();
    
    engine.selectPhysicalDevice();
    engine.createLogicalDevice();
    
    window.mainLoop();

app.shutDown()

    vkDestroyDevice(engine.logicalDevice, nullptr);
    
    vkDestroySurfaceKHR(engine.instance, window.surface, nullptr);
    vkDestroyInstance(engine.instance, nullptr);
    
    SDL_DestroyWindow(window.window);
    SDL_Quit();

window engine and app are pre-defined by my own classes

I've tried manually adding the different required and supported extensions, and it works, but it feels hacky and is quite a large bulk of code. If this is a weird out of scope error, I've really no idea. if any other code is needed I'll be happy to provide it and the GitHub can also be found here: https://github.com/XiniaDev/Xinia-Engine

CodePudding user response:

I think your problem is that requiredFeatures in XiEngine is not initialised. You set a few values to true, but I think you need a memset(&requiredFeatures, 0, sizeof(requiredFeatures)); or similar at the start of XiEngine::XiEngine to fix it.

  • Related