Skip to content

Conversation

@olivier-gerard
Copy link

Followup to issue #8940.

  • Adding helper function ImGui_ImplVulkanH_Window* ImGui_ImplVulkan_GetWindowDataFromViewport(ImGuiViewport* viewport) to retrieve the window related to a viewport. I tested it for screenshot generation, but usage could be wider.
  • Adding optional field SwapchainImageUsage to struct ImGui_ImplVulkan_InitInfo to be able to specify additional usage for swapchain images (eg VK_IMAGE_USAGE_TRANSFER_SRC_BIT for a screenshot). This adds an argument to ImGui_ImplVulkanH_CreateOrResizeWindow, but default value has been set to keep the examples simple.

@ocornut
Copy link
Owner

ocornut commented Sep 22, 2025

Hello,

I have merged a first commit e639ff3 which include only ImGui_ImplVulkanH_GetWindowDataFromViewport() (note that I renamed the function from your version, moved it higher in the first). I am also not sure why you added the (viewport->Flags & ImGuiViewportFlags_OwnedByApp) test, what is the reason?

@olivier-gerard
Copy link
Author

Hi,

Thanks.
You're right, the check is not supposed to be here. I should have removed it as it is oriented to my idea of screenshot, but now that the getter function is more generic it brings nothing good.

Just to know for another time, would you have preferred if I made 2 PR (one for ImGui_ImplVulkanH_GetWindowDataFromViewport and the other one for the image flag) ? As it is two tiny changes I wanted to avoid pollution, but on the other hand it is always good to split topics...

@ocornut
Copy link
Owner

ocornut commented Sep 23, 2025

Making two commits in the same PR would be nice for this sorts of thing. But the first change is so simple it was easy to isolate that.

For the second change: I would like to look more globally at all the Vulkan related requests to configure how secondary viewports are created, and possibly work on those together.

if you feel like inspecting all vulkan issues to list ones related or even perhaps come with a more global plan that’d be nice, but otherwise I’ll tackle this at some point either way.

@olivier-gerard
Copy link
Author

I tried listing the issues on Vulkan related to configuration of secondary viewports or VulkanInitInfo, but I only come up with 2 others, I must have missing stuff...
I have #8585 and #8686
#8271 could also be in the list, but I'm not sure it's still active since 8585

@ocornut
Copy link
Owner

ocornut commented Sep 25, 2025

Right, I though there were more, but I reviewed the list and I agree that's all there is.

Reference, for others backends

@ocornut
Copy link
Owner

ocornut commented Sep 26, 2025

#8585 is solved now.

Some more at #8111 (comment)
Commit in third-party branch SuperRonan@5b9a62f

ocornut added a commit that referenced this pull request Sep 26, 2025
…rameter to ImGui_ImplVulkanH_CreateOrResizeWindow(). (#8946, #8110, #8111, #8686)

Default to VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT.
ocornut added a commit that referenced this pull request Sep 26, 2025
…o: RenderPass, Subpass, MSAASamples, PipelineRenderingCreateInfo. (#8946, #8110, #8111, #8686)
ocornut added a commit that referenced this pull request Sep 26, 2025
@ocornut
Copy link
Owner

ocornut commented Sep 26, 2025

I have pushed a couple of rework of the Vulkan backend:

  • 01686c6 Backends: Vulkan: added a way to specify custom vertex/fragment shaders.
  • 5fe9622 (Breaking) Backends: Vulkan: added VkImageUsageFlags image_usage parameter to ImGui_ImplVulkanH_CreateOrResizeWindow().
  • cc0a669 Backends: Vulkan: minor internal renames/tweaks to reduce further patches.
  • e312b99 (Breaking) Backends: Vulkan: renamed ImGui_ImplVulkan_MainPipelineCreateInfo to ImGui_ImplVulkan_PipelineInfo.
  • 3470e61 (Breaking) Backends: Vulkan: moved fields in ImGui_ImplVulkan_InitInfo: RenderPass, Subpass, MSAASamples, PipelineRenderingCreateInfo.
  • e4e3c2c Backends: Vulkan: amends for docking. Add PipelineInfoForViewports and SwapChainImageUsage.

As a result this (and therefore #8940) should be solved, but please confirm!

@olivier-gerard
Copy link
Author

I was seeing SwapchainImageUsage as additional flags (ie I need to set init_info.PipelineInfoForViewports.SwapChainImageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT and not only the 2nd one. As the color attachment bit is mandatory it could be added at the last moment, but it is not big deal.

With latest commit e4e3c2c I have crash or error at each frame, which is more anoying me. I diffed your changes and didn't find yet the cause. I think it is due to using MSAASamples to 8 bits and not 1. (I don't use dynamic rendering)

The main viewport is fine, but when I create a second one, if I set init_info.PipelineInfoForViewports.MSAASamples = static_cast<VkSampleCountFlagBits>(msaaSamples) then it crashes (vk device lost)
Error is

ERROR: SPEC [8cb637c2][VUID-vkCmdDrawIndexed-renderPass-02684] : vkCmdDrawIndexed(): pSubpasses[0].pColorAttachments[0].attachment is incompatible between VkRenderPass 0xaf00000000af (from VkCommandBuffer 0x28bbf358ea0) and VkRenderPass 0x550000000055[Render pass] (from VkPipeline 0xd200000000d2), pAttachments[0].samples (VK_SAMPLE_COUNT_1_BIT) != pAttachments[0].samples (VK_SAMPLE_COUNT_8_BIT).
The Vulkan spec states: The current render pass must be compatible with the renderPass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS (https://vulkan.lunarg.com/doc/view/1.4.321.1/windows/antora/spec/latest/chapters/drawing.html#VUID-vkCmdDrawIndexed-renderPass-02684)

If I set the init_info.PipelineInfoForViewports.MSAASamples = 0, then it does not crash, but error are

ERROR: SPEC [3108bb9b][VUID-VkGraphicsPipelineCreateInfo-multisampledRenderToSingleSampled-06853] : vkCreateGraphicsPipelines(): pCreateInfos[0].pMultisampleState->rasterizationSamples (1) does not match the number of samples of the RenderPass color and/or depth attachment (8).
The Vulkan spec states: If the pipeline requires fragment output interface state, and none of the VK_AMD_mixed_attachment_samples extension, the VK_NV_framebuffer_mixed_samples extension, or the multisampledRenderToSingleSampled feature are enabled, rasterizationSamples is not dynamic, and if subpass uses color and/or depth/stencil attachments, then the rasterizationSamples member of pMultisampleState must be the same as the sample count for those subpass attachments (https://vulkan.lunarg.com/doc/view/1.4.321.1/windows/antora/spec/latest/chapters/pipelines.html#VUID-VkGraphicsPipelineCreateInfo-multisampledRenderToSingleSampled-06853)

ERROR: SPEC [8cb637c2][VUID-vkCmdDrawIndexed-renderPass-02684] : vkCmdDrawIndexed(): pSubpasses[0].pColorAttachments[0].attachment is incompatible between VkRenderPass 0xa900000000a9 (from VkCommandBuffer 0x27300119630) and VkRenderPass 0x550000000055[Render pass] (from VkPipeline 0xcc00000000cc), pAttachments[0].samples (VK_SAMPLE_COUNT_1_BIT) != pAttachments[0].samples (VK_SAMPLE_COUNT_8_BIT).
The Vulkan spec states: The current render pass must be compatible with the renderPass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS (https://vulkan.lunarg.com/doc/view/1.4.321.1/windows/antora/spec/latest/chapters/drawing.html#VUID-vkCmdDrawIndexed-renderPass-02684)

ERROR: SPEC [8cb637c2][VUID-vkCmdDrawIndexed-renderPass-02684] : vkCmdDrawIndexed(): pSubpasses[0].pDepthStencilAttachment->attachment is incompatible between VkRenderPass 0xa900000000a9 (from VkCommandBuffer 0x27300119630) and VkRenderPass 0x550000000055[Render pass] (from VkPipeline 0xcc00000000cc), the first is VK_ATTACHMENT_UNUSED while the second is 1.
The Vulkan spec states: The current render pass must be compatible with the renderPass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS (https://vulkan.lunarg.com/doc/view/1.4.321.1/windows/antora/spec/latest/chapters/drawing.html#VUID-vkCmdDrawIndexed-renderPass-02684)

ERROR: SPEC [8cb637c2][VUID-vkCmdDrawIndexed-renderPass-02684] : vkCmdDrawIndexed(): dependencyCount is incompatible between VkRenderPass 0xa900000000a9 (from VkCommandBuffer 0x27300119630) and VkRenderPass 0x550000000055[Render pass] (from VkPipeline 0xcc00000000cc), 1 != 3.
The Vulkan spec states: The current render pass must be compatible with the renderPass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS (https://vulkan.lunarg.com/doc/view/1.4.321.1/windows/antora/spec/latest/chapters/drawing.html#VUID-vkCmdDrawIndexed-renderPass-02684)

@ocornut ocornut reopened this Sep 29, 2025
@olivier-gerard
Copy link
Author

olivier-gerard commented Sep 29, 2025

Ok got it, it is because you are passing my (main, 8 bits) render pass when creating secondary pipelines instead of passing the secondary (1 bit one, attached to the window).
I fixed it adding pipeline_info->RenderPass = wd->RenderPass; line 2017 just before the assert IM_ASSERT(pipeline_info->RenderPass != VK_NULL_HANDLE && "Did you set ImGui_ImplVulkan_InitInfo::PipelineInfoForViewports.RenderPass?"); // Since 1.92.4 it is required.

Then the copy at line 1326 info->PipelineInfoForViewports.RenderPass = info->PipelineInfoMain.RenderPass; may not be necessary

After the fix I only have the issue about semaphore, which was present before, I saw an issue about this #8923

ocornut added a commit that referenced this pull request Sep 29, 2025
@ocornut
Copy link
Owner

ocornut commented Sep 29, 2025

I was seeing SwapchainImageUsage as additional flags

Seems sensible. Pushed this change bad3c14.

Ok got it, it is because you are passing my (main, 8 bits) render pass when creating secondary pipelines instead of passing the secondary (1 bit one, attached to the window).
I fixed it adding pipeline_info->RenderPass = wd->RenderPass; line 2017 just before the assert IM_ASSERT(pipeline_info->RenderPass != VK_NULL_HANDLE && "Did you set ImGui_ImplVulkan_InitInfo::PipelineInfoForViewports.RenderPass?"); // Since 1.92.4 it is required.
Then the copy at line 1326 info->PipelineInfoForViewports.RenderPass = info->PipelineInfoMain.RenderPass; may not be necessary

Hmm... this means that PipelineInfoForViewports.RenderPass is unused, right?
In this case the comments in ImGui_ImplVulkan_PipelineInfo should reworked accordingly?

@olivier-gerard
Copy link
Author

Yes in my understanding ImGui_ImplVulkan_PipelineInfo::RenderPass, Subpass and MSAASamples shall be set only for main viewport (I didn't look for PipelineRenderingCreateInfo as I don't have dynamic rendering). But I'm not a Vulkan expert at all...

ocornut added a commit that referenced this pull request Sep 29, 2025
…wport always use the RenderPass created by the ImGui_ImplVulkanH_CreateOrResizeWindow(). (#8946, #8110)
@ocornut
Copy link
Owner

ocornut commented Sep 29, 2025

I pushed 1f020e5

@ocornut ocornut closed this Sep 29, 2025
ocornut added a commit that referenced this pull request Oct 23, 2025
…ACHMENT_BIT which is added automatically. (#8946, #8110, #8111, #8686)

Merge bad3c14 which was accidentally only pushed to docking. No important side effect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants