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

Backends: Vulkan: Custom window surface format with dynamic rendering #6999

Conversation

raaavioli
Copy link

@raaavioli raaavioli commented Nov 11, 2023

Background

ImGui_ImplVulkan_CreateWindow currently selects one out of four formats from VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8_UNORM, VK_FORMAT_R8G8B8_UNORM. The selected wd->SurfaceFormat is later used to create the swapchain and the frame's BackbufferView.

The backbuffer view is used in the VkRenderingAttachmentInfo when using dynamic rendering. If the selected surface format does not match the format set on the VkPipelineRenderingCreateInfoKHR, a validation error is triggered:

Message: Validation Error: [ VUID-vkCmdDrawIndexed-colorAttachmentCount-06180 ] VkRenderingInfo::pColorAttachments[0].imageView format (VK_FORMAT_B8G8R8A8_UNORM) must match corresponding format in VkPipelineRenderingCreateInfo::pColorAttachmentFormats[0] (VK_FORMAT_B8G8R8A8_SRGB) The Vulkan spec states: If the current render pass instance was begun with vkCmdBeginRendering and VkRenderingInfo::colorAttachmentCount greater than 0, then each element of the VkRenderingInfo::pColorAttachments array with a imageView not equal to VK_NULL_HANDLE must have been created with a VkFormat equal to the corresponding element of VkPipelineRenderingCreateInfo::pColorAttachmentFormats used to create the currently bound graphics pipeline

In my case, I use VK_FORMAT_B8G8R8A8_SRGB as ColorAttachmentFormat when creating the pipeline, and the BackbufferView defaults to VK_FORMAT_B8G8R8A8_UNORM, which is invalid.

Proposal

To solve this, I propose using the ColorAttachmentFormat as the primary requestSurfaceImageFormat when dynamic rendering is enabled, which will cause both the swapchain and the BackbufferView to have the same format as we create the pipeline with.

@ocornut ocornut changed the title Custom window surface format with dynamic rendering Backends: Vulkan: Custom window surface format with dynamic rendering Nov 13, 2023
ocornut pushed a commit that referenced this pull request Nov 15, 2023
… secondary window when enabling UseDynamicRendering. (#6999, #5446, #5037)
@ocornut
Copy link
Owner

ocornut commented Nov 15, 2023

Thank you for the PR.
Merged as 6695006. Thank you!

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