Home > Enterprise >  Vulkan validation layers complain about extension not enabled, code works as if extension was enable
Vulkan validation layers complain about extension not enabled, code works as if extension was enable

Time:03-03

I am trying to use the dynamic rendering extension, to that effect I am initializing my instance this way:

    auto enabled = vk::ValidationFeatureEnableEXT::eBestPractices;
    vk::ValidationFeaturesEXT features;
    features.enabledValidationFeatureCount = 1;
    features.pEnabledValidationFeatures = &enabled;

    vk::PhysicalDeviceDynamicRenderingFeaturesKHR dynamic_rendering = {};
    dynamic_rendering.dynamicRendering = true;

    features.pNext = &dynamic_rendering;

    // Setup general information about the current application.
    vk::ApplicationInfo program_info(
        "NeverEngine",
        VK_MAKE_VERSION(1, 0, 0),
        "No Engine",
        VK_MAKE_VERSION(1, 0, 0),
        VK_API_VERSION_1_2);
    // Create Vulkan instance to communicate with the loader.
    vk::InstanceCreateInfo create_info = {};
    create_info.pNext = &features;
    create_info.pApplicationInfo = &program_info,
    create_info.enabledLayerCount = static_cast<uint32_t>(VALIDATION_LAYERS.size()),
    create_info.ppEnabledLayerNames = VALIDATION_LAYERS.data(),
    create_info.enabledExtensionCount = static_cast<uint32_t>(required_extensions.size()),
    create_info.ppEnabledExtensionNames = required_extensions.data();

    auto [result, instance] = vk::createInstanceUnique(create_info);
    Assert(result == vk::Result::eSuccess, "Error: Failed to create instance");

However I am getting these errors:

VUID-VkInstanceCreateInfo-pNext-pNext(ERROR / SPEC): msgNum: -1337267667 - Validation Error: [ VUID-VkInstanceCreateInfo-pNext-pNext ] Object 0: VK_NULL_HANDLE, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xb04aea2d | vkCreateInstance: pCreateInfo->pNext chain includes a structure with unexpected VkStructureType VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES; Allowed structures are [VkDebugReportCallbackCreateInfoEXT, VkDebugUtilsMessengerCreateInfoEXT, VkValidationFeaturesEXT, VkValidationFlagsEXT]. This error is based on the Valid Usage documentation for version 204 of the Vulkan header.  It is possible that you are using a struct from a private extension or an extension that was added to a later version of the Vulkan header, in which case the use of pCreateInfo->pNext is undefined and may not work correctly with validation enabled The Vulkan spec states: Each pNext member of any structure (including this one) in the pNext chain must be either NULL or a pointer to a valid instance of VkDebugReportCallbackCreateInfoEXT, VkDebugUtilsMessengerCreateInfoEXT, VkValidationFeaturesEXT, or VkValidationFlagsEXT (https://vulkan.lunarg.com/doc/view/1.3.204.1/linux/1.3-extensions/vkspec.html#VUID-VkInstanceCreateInfo-pNext-pNext)
    Objects: 1
        [0] 0, type: 3, name: NULL
VUID-VkInstanceCreateInfo-pNext-pNext(ERROR / SPEC): msgNum: -1337267667 - Validation Error: [ VUID-VkInstanceCreateInfo-pNext-pNext ] Object 0: VK_NULL_HANDLE, type = VK_OBJECT_TYPE_INSTANCE; | MessageID = 0xb04aea2d | vkCreateInstance: Includes a pNext pointer (pCreateInfo->pNext) to a VkStructureType (VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES), but its parent extension VK_KHR_dynamic_rendering has not been enabled. The Vulkan spec states: Each pNext member of any structure (including this one) in the pNext chain must be either NULL or a pointer to a valid instance of VkDebugReportCallbackCreateInfoEXT, VkDebugUtilsMessengerCreateInfoEXT, VkValidationFeaturesEXT, or VkValidationFlagsEXT (https://vulkan.lunarg.com/doc/view/1.3.204.1/linux/1.3-extensions/vkspec.html#VUID-VkInstanceCreateInfo-pNext-pNext)
    Objects: 1
        [0] 0, type: 1, name: NULL

My driver, headers and validation layers are the latest version 1.3.204.

If I don;t enable layers and just run my code, things seem to work fine, I can resize my window and rendering is updated as expected. Is this a bug in the validation layers?

Some research suggests I should do this instead:

const std::vector<const char*> device_extensions = {
    VK_KHR_SWAPCHAIN_EXTENSION_NAME,
    VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME,
    VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME,
};

 vk::PhysicalDeviceDynamicRenderingFeaturesKHR dynamic_rendering = {};
    dynamic_rendering.dynamicRendering = true;

    // Get the features of the selected device.
    vk::PhysicalDeviceFeatures device_features = phys_device.getFeatures();

    // The enabledLayerCount and ppEnabledLayerNames parameters are deprecated,
    // they should always be 0 and nullptr.
    // https://www.khronos.org/registry/vulkan/specs/1.1-extensions/man/html/VkDeviceCreateInfo.html
    vk::DeviceCreateInfo create_info = {};
    create_info.pNext = &dynamic_rendering;
    create_info.queueCreateInfoCount = queue_create_infos.size();
    create_info.pQueueCreateInfos = queue_create_infos.data();
    create_info.enabledLayerCount = 0;
    create_info.ppEnabledLayerNames = nullptr;
    create_info.enabledExtensionCount = device_extensions.size();
    create_info.ppEnabledExtensionNames = device_extensions.data();
    create_info.pEnabledFeatures = &device_features;

But this is returning the following error:

Message ID name: VUID-VkGraphicsPipelineCreateInfo-dynamicRendering-06052
Message: Validation Error: [ VUID-VkGraphicsPipelineCreateInfo-dynamicRendering-06052 ] Object 0: handle = 0x2357fc0, name = Logical device: NVIDIA GeForce GTX 1070, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xdf901c9e | vkCreateGraphicsPipeline: pCreateInfos[0].renderPass is VK_NULL_HANDLE but dynamicRendering is not enabled. The Vulkan spec states: If the dynamicRendering feature is not enabled, renderPass must not be VK_NULL_HANDLE (https://vulkan.lunarg.com/doc/view/1.3.204.1/linux/1.3-extensions/vkspec.html#VUID-VkGraphicsPipelineCreateInfo-dynamicRendering-06052)

I don;t understand, I AM enabling the extension.

Following the advice in teh comments, I am seeing this:

vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice) returns VkResult VK_SUCCESS (0):
    physicalDevice:                 VkPhysicalDevice = 0x32f85c0
    pCreateInfo:                    const VkDeviceCreateInfo* = 0x7fff0d9dbb20:
        sType:                          VkStructureType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO (3)
        pNext:                          const void* = NULL

Which seems to suggest the pNext is not being set properly.

CodePudding user response:

You'll probably need to add VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME to your list of device_extensions. You didn't show the code that sets up that list. The rest of it looks OK.

It isn't that unusual for a driver to go ahead and use a requested feature, even though it isn't enabled. But since that can change from driver to driver, it is always best to enable the extensions and features you need.

  • Related