Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic rendering and Vulkan 1.3 and higher #8326

Open
mklefrancois opened this issue Jan 17, 2025 · 4 comments
Open

Dynamic rendering and Vulkan 1.3 and higher #8326

mklefrancois opened this issue Jan 17, 2025 · 4 comments

Comments

@mklefrancois
Copy link

Version/Branch of Dear ImGui:

Version 1.91,3, Branch : docking

Back-ends:

imgui_impl_vulkan.cpp

Compiler, OS:

Windows 11

Full config/build information:

No response

Details:

With dynamic rendering active, the Vulkan backend loads vkCmdBeginRenderingKHR and vkCmdEndRenderingKHR, but those are only valid when the extension VK_KHR_dynamic_rendering was added to the device creation, where vkCmdBeginRendering and vkCmdEndRendering (without KHR), exists if the Vulkan 1.3 API is used.

See vkCmdBeginRenderingKHR specification.

My suggestion would be to add to ImGui_ImplVulkan_InitInfo an .ApiVersion and do something like

      if(info->ApiVersion < VK_API_VERSION_1_3)
      {
        ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR =
            reinterpret_cast<PFN_vkCmdBeginRenderingKHR>(vkGetInstanceProcAddr(info->Instance, "vkCmdBeginRenderingKHR"));
        ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR =
            reinterpret_cast<PFN_vkCmdEndRenderingKHR>(vkGetInstanceProcAddr(info->Instance, "vkCmdEndRenderingKHR"));
      }
      else
      {
        ImGuiImplVulkanFuncs_vkCmdBeginRenderingKHR =
            reinterpret_cast<PFN_vkCmdBeginRenderingKHR>(vkGetInstanceProcAddr(info->Instance, "vkCmdBeginRendering"));
        ImGuiImplVulkanFuncs_vkCmdEndRenderingKHR =
            reinterpret_cast<PFN_vkCmdEndRenderingKHR>(vkGetInstanceProcAddr(info->Instance, "vkCmdEndRendering"));
      }

Screenshots/Video:

No response

Minimal, Complete and Verifiable Example code:

I don't have the example public yet, but found this while porting and modernizing https://github.com/nvpro-samples/vk_mini_samples to Vulkan 1.4

@ocornut
Copy link
Owner

ocornut commented Jan 17, 2025

Thank you for your report. Would using compile-time e.g VK_VERSION_1_3 also works?

We currently do this:

#if defined(VK_VERSION_1_3) || defined(VK_KHR_dynamic_rendering)
#define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
#endif

The loading code is currently in two locations I'm going to share the existing code to facilitate further updates.

@mklefrancois
Copy link
Author

Thanks for the quick reply!

Someone could still create its VkInstance with a lower version of the api. This is done by setting VkApplicationInfo.apiVersion

Example

    VkApplicationInfo appInfo{
        .sType              = VK_STRUCTURE_TYPE_APPLICATION_INFO,
        .pApplicationName   = m_settings.applicationName,
        .applicationVersion = VK_MAKE_VERSION(1, 0, 0),
        .pEngineName        = "My Engine",
        .engineVersion      = VK_MAKE_VERSION(1, 0, 0),
        .apiVersion         = VK_VERSION_1_2;  /// m_settings.apiVersion,
    };

    VkInstanceCreateInfo createInfo{
        .sType                   = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
        .pNext                   = m_settings.instanceCreateInfoExt,
        .pApplicationInfo        = &appInfo,
        .enabledLayerCount       = uint32_t(layers.size()),
        .ppEnabledLayerNames     = layers.data(),
        .enabledExtensionCount   = uint32_t(m_settings.instanceExtensions.size()),
        .ppEnabledExtensionNames = m_settings.instanceExtensions.data(),
    };

    VkResult result = vkCreateInstance(&createInfo, m_settings.alloc, &m_instance);

In this case the API will be 1.2 and the 1.3 features will not be available.
Unfortunately, it is not possible to query the vkInstance to know which API it was created with. It is only possible to query the maximum API the loader supports, the same with VkPhysicalDevice. So the only reasonable method I see is to ask for the API version. The Vulkan Memory Allocator (VMA) does the same thing, it asks for the API used by the instance.

@mklefrancois
Copy link
Author

My suggestion was to make it backward compatible. But since Vulkan 1.4 is out, and 1.3 has been around for quite a while, we could assume that Vulkan applications these days always use 1.3 and up. But I could be wrong.

@mklefrancois
Copy link
Author

If you are looking for a test application, there is the NVIDIA nvpro-sample vk_minimal_latest.

If the fix works the line 900 could be removed.

P-S. This sample will be updated using Vulkan 1.4 on Monday, with the release of the NVIDIA driver supporting Vulkan 1.4, or delayed if the driver isn't published.
P-S.2. I really like your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants