Skip to content

Added optional push-descriptor path allowing direct VkImageView usage as ImTextureID.#9402

Open
Seokwon-Park wants to merge 2 commits into
ocornut:dockingfrom
Seokwon-Park:vulkan_push_descriptor
Open

Added optional push-descriptor path allowing direct VkImageView usage as ImTextureID.#9402
Seokwon-Park wants to merge 2 commits into
ocornut:dockingfrom
Seokwon-Park:vulkan_push_descriptor

Conversation

@Seokwon-Park

@Seokwon-Park Seokwon-Park commented May 17, 2026

Copy link
Copy Markdown

Currently, the Vulkan backend differs from other Dear ImGui rendering backends in how user textures are submitted.

If a user wants to render a custom engine texture in the UI:

  • OpenGL: Simply pass the texture ID (GLuint cast to ImTextureID).
  • DX11: Simply pass ID3D11ShaderResourceView* as ImTextureID.
  • DX12: Simply pass D3D12_GPU_DESCRIPTOR_HANDLE as ImTextureID.
  • Vulkan: The user must call ImGui_ImplVulkan_AddTexture() to bake the VkImageView into a Descriptor Set allocated from a pool.

To resolve this inconsistency, I implemented a way to use VkImageView directly as an ImTextureID, just like other APIs do. I utilized VK_KHR_push_descriptor (promoted to core in Vulkan 1.4) to streamline this process.

How it works:

  1. Separate Bindings: Set 1 holds the VkSampler (ImGui's font sampler), and Set 0 is reserved for pushed VkImageView (VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE).
  2. Push Descriptors: Inside ImGui_ImplVulkan_RenderDrawData, use vkCmdPushDescriptorSetKHR to bind the texture directly from pcmd->GetTexID().

Before:

VkDescriptorSet uiSet = ImGui_ImplVulkan_AddTexture(sampler, myImageView, layout);
ImGui::Image((ImTextureID)uiSet, size);

After:

ImGui::Image((ImTextureID)myImageView, size); // Just like OpenGL / DX11 / DX12
  • Tested this implementation directly on the docking branch inside my custom engine, and it works fine.
  • The current implementation is intentionally minimal to demonstrate the concept and validate the workflow. I would appreciate feedback on how this could best fit Dear ImGui's preferred backend structure, feature toggles, or capability checks.
  • This path assumes textures are already transitioned to VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL before being used by ImGui.
  • Because this path depends on push descriptors, which may not be available on all Vulkan implementations, I think it would be best integrated as an explicit opt-in option rather than replacing the current behavior.

@Seokwon-Park

Copy link
Copy Markdown
Author

An optional Vulkan backend path that allows users to directly pass a VkImageView as ImTextureID by utilizing Push Descriptors, bringing Vulkan texture usage closer to the behavior of other Dear ImGui rendering backends

Based on and targeted for the docking branch.

Changes and features:

  • Added UsePushDescriptorSet flag to ImGui_ImplVulkan_InitInfo.
  • When enabled, the backend accepts VkImageView instead of VkDescriptorSet for texture identifiers.
  • Added IM_ASSERT checks to guard against incompatible API usage when the feature is enabled.
  • Maintains full backward compatibility for existing users who do not opt in to this feature.

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