Skip to content

Commit bad3c14

Browse files
committed
Backends: Vulkan: SwapChainImageUsage assume VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT which is added automatically. (#8946, #8110, #8111, #8686)
Amend e4e3c2c.
1 parent e4e3c2c commit bad3c14

File tree

7 files changed

+14
-18
lines changed

7 files changed

+14
-18
lines changed

backends/imgui_impl_vulkan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, V
16831683
info.imageFormat = wd->SurfaceFormat.format;
16841684
info.imageColorSpace = wd->SurfaceFormat.colorSpace;
16851685
info.imageArrayLayers = 1;
1686-
info.imageUsage = (image_usage != 0) ? image_usage : VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1686+
info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | image_usage;
16871687
info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; // Assume that graphics family == present family
16881688
info.preTransform = (cap.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) ? VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR : cap.currentTransform;
16891689
info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;

backends/imgui_impl_vulkan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct ImGui_ImplVulkan_PipelineInfo
7878
#endif
7979

8080
// For Secondary viewports only (created/managed by backend)
81-
VkImageUsageFlags SwapChainImageUsage; // 0 defaults to VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT. Add e.g. VK_IMAGE_USAGE_TRANSFER_SRC_BIT if you need to capture from viewports.
81+
VkImageUsageFlags SwapChainImageUsage; // Extra flags for vkCreateSwapchainKHR() calls for secondary viewports. We automatically add VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT. You can add e.g. VK_IMAGE_USAGE_TRANSFER_SRC_BIT if you need to capture from viewports.
8282
};
8383

8484
// Initialization data, for ImGui_ImplVulkan_Init()

docs/CHANGELOG.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ Breaking Changes:
5656
(introduced very recently and only used by `ImGui_ImplVulkan_CreateMainPipeline()`
5757
so it should not affect many users). (#8110, #8111)
5858
- Backends: Vulkan: helper ImGui_ImplVulkanH_CreateOrResizeWindow() added a
59-
`VkImageUsageFlags image_usage` argument.
60-
It was previously hardcoded to `VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT` and defaults
61-
to that when the value is 0. In theory the function is an internal helper but
62-
since it's used by our examples some may have used it. (#8946, #8111, #8686)
59+
`VkImageUsageFlags image_usage` argument to specific extra flags for calls to
60+
vkCreateSwapchainKHR() done for secondary viewports. We automatically add
61+
`VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT`. In theory the function is an internal
62+
helper but since it's used by our examples some may have used it. (#8946, #8111, #8686)
6363

6464
Other Changes:
6565

examples/example_glfw_vulkan/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
5454
static ImGui_ImplVulkanH_Window g_MainWindowData;
5555
static uint32_t g_MinImageCount = 2;
5656
static bool g_SwapChainRebuild = false;
57-
static VkImageUsageFlags g_SwapChainImageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
5857

5958
static void glfw_error_callback(int error, const char* description)
6059
{
@@ -240,7 +239,7 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
240239

241240
// Create SwapChain, RenderPass, Framebuffer, etc.
242241
IM_ASSERT(g_MinImageCount >= 2);
243-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, g_SwapChainImageUsage);
242+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, 0);
244243
}
245244

246245
static void CleanupVulkan()
@@ -470,7 +469,7 @@ int main(int, char**)
470469
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
471470
{
472471
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
473-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, g_SwapChainImageUsage);
472+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, 0);
474473
g_MainWindowData.FrameIndex = 0;
475474
g_SwapChainRebuild = false;
476475
}

examples/example_sdl2_vulkan/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
4949
static ImGui_ImplVulkanH_Window g_MainWindowData;
5050
static uint32_t g_MinImageCount = 2;
5151
static bool g_SwapChainRebuild = false;
52-
static VkImageUsageFlags g_SwapChainImageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
5352

5453
static void check_vk_result(VkResult err)
5554
{
@@ -231,7 +230,7 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
231230

232231
// Create SwapChain, RenderPass, Framebuffer, etc.
233232
IM_ASSERT(g_MinImageCount >= 2);
234-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, g_SwapChainImageUsage);
233+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, 0);
235234
}
236235

237236
static void CleanupVulkan()
@@ -490,7 +489,7 @@ int main(int, char**)
490489
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
491490
{
492491
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
493-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, g_SwapChainImageUsage);
492+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, 0);
494493
g_MainWindowData.FrameIndex = 0;
495494
g_SwapChainRebuild = false;
496495
}

examples/example_sdl3_vulkan/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
5151
static ImGui_ImplVulkanH_Window g_MainWindowData;
5252
static uint32_t g_MinImageCount = 2;
5353
static bool g_SwapChainRebuild = false;
54-
static VkImageUsageFlags g_SwapChainImageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
5554

5655
static void check_vk_result(VkResult err)
5756
{
@@ -233,7 +232,7 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
233232

234233
// Create SwapChain, RenderPass, Framebuffer, etc.
235234
IM_ASSERT(g_MinImageCount >= 2);
236-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, g_SwapChainImageUsage);
235+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, 0);
237236
}
238237

239238
static void CleanupVulkan()
@@ -492,7 +491,7 @@ int main(int, char**)
492491
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
493492
{
494493
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
495-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_height, fb_height, g_MinImageCount, g_SwapChainImageUsage);
494+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, fb_height, fb_height, g_MinImageCount, 0);
496495
g_MainWindowData.FrameIndex = 0;
497496
g_SwapChainRebuild = false;
498497
}

examples/example_win32_vulkan/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
4747
static ImGui_ImplVulkanH_Window g_MainWindowData;
4848
static uint32_t g_MinImageCount = 2;
4949
static bool g_SwapChainRebuild = false;
50-
static VkImageUsageFlags g_SwapChainImageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
5150

5251
static void check_vk_result(VkResult err)
5352
{
@@ -229,7 +228,7 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
229228

230229
// Create SwapChain, RenderPass, Framebuffer, etc.
231230
IM_ASSERT(g_MinImageCount >= 2);
232-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, g_SwapChainImageUsage);
231+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount, 0);
233232
}
234233

235234
static void CleanupVulkan()
@@ -583,7 +582,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
583582
if (fb_width > 0 && fb_height > 0 && (g_SwapChainRebuild || g_MainWindowData.Width != fb_width || g_MainWindowData.Height != fb_height))
584583
{
585584
ImGui_ImplVulkan_SetMinImageCount(g_MinImageCount);
586-
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, g_SwapChainImageUsage);
585+
ImGui_ImplVulkanH_CreateOrResizeWindow(g_Instance, g_PhysicalDevice, g_Device, &g_MainWindowData, g_QueueFamily, g_Allocator, fb_width, fb_height, g_MinImageCount, 0);
587586
g_MainWindowData.FrameIndex = 0;
588587
g_SwapChainRebuild = false;
589588
}

0 commit comments

Comments
 (0)