imgui_impl_vulkan.cpp
Go to the documentation of this file.
1 // dear imgui: Renderer for Vulkan
2 // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
3 
4 // Implemented features:
5 // [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
6 // Missing features:
7 // [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914
8 
9 // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
10 // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
11 // https://github.com/ocornut/imgui
12 
13 // The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
14 // IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
15 
16 // Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
17 // - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
18 // You will use those if you want to use this rendering back-end in your engine/app.
19 // - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
20 // the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
21 // Read comments in imgui_impl_vulkan.h.
22 
23 // CHANGELOG
24 // (minor and older changes stripped away, please see git history for details)
25 // 2019-08-01: Vulkan: Added support for specifying multisample count. Set ImGui_ImplVulkan_InitInfo::MSAASamples to one of the VkSampleCountFlagBits values to use, default is non-multisampled as before.
26 // 2019-05-29: Vulkan: Added support for large mesh (64K+ vertices), enable ImGuiBackendFlags_RendererHasVtxOffset flag.
27 // 2019-04-30: Vulkan: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
28 // 2019-04-04: *BREAKING CHANGE*: Vulkan: Added ImageCount/MinImageCount fields in ImGui_ImplVulkan_InitInfo, required for initialization (was previously a hard #define IMGUI_VK_QUEUED_FRAMES 2). Added ImGui_ImplVulkan_SetMinImageCount().
29 // 2019-04-04: Vulkan: Added VkInstance argument to ImGui_ImplVulkanH_CreateWindow() optional helper.
30 // 2019-04-04: Vulkan: Avoid passing negative coordinates to vkCmdSetScissor, which debug validation layers do not like.
31 // 2019-04-01: Vulkan: Support for 32-bit index buffer (#define ImDrawIdx unsigned int).
32 // 2019-02-16: Vulkan: Viewport and clipping rectangles correctly using draw_data->FramebufferScale to allow retina display.
33 // 2018-11-30: Misc: Setting up io.BackendRendererName so it can be displayed in the About Window.
34 // 2018-08-25: Vulkan: Fixed mishandled VkSurfaceCapabilitiesKHR::maxImageCount=0 case.
35 // 2018-06-22: Inverted the parameters to ImGui_ImplVulkan_RenderDrawData() to be consistent with other bindings.
36 // 2018-06-08: Misc: Extracted imgui_impl_vulkan.cpp/.h away from the old combined GLFW+Vulkan example.
37 // 2018-06-08: Vulkan: Use draw_data->DisplayPos and draw_data->DisplaySize to setup projection matrix and clipping rectangle.
38 // 2018-03-03: Vulkan: Various refactor, created a couple of ImGui_ImplVulkanH_XXX helper that the example can use and that viewport support will use.
39 // 2018-03-01: Vulkan: Renamed ImGui_ImplVulkan_Init_Info to ImGui_ImplVulkan_InitInfo and fields to match more closely Vulkan terminology.
40 // 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback, ImGui_ImplVulkan_Render() calls ImGui_ImplVulkan_RenderDrawData() itself.
41 // 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
42 // 2017-05-15: Vulkan: Fix scissor offset being negative. Fix new Vulkan validation warnings. Set required depth member for buffer image copy.
43 // 2016-11-13: Vulkan: Fix validation layer warnings and errors and redeclare gl_PerVertex.
44 // 2016-10-18: Vulkan: Add location decorators & change to use structs as in/out in glsl, update embedded spv (produced with glslangValidator -x). Null the released resources.
45 // 2016-08-27: Vulkan: Fix Vulkan example for use when a depth buffer is active.
46 
47 #include "imgui.h"
48 #include "imgui_impl_vulkan.h"
49 #include <stdio.h>
50 
51 // Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplVulkan_RenderDrawData()
52 // [Please zero-clear before use!]
54 {
55  VkDeviceMemory VertexBufferMemory;
56  VkDeviceMemory IndexBufferMemory;
57  VkDeviceSize VertexBufferSize;
58  VkDeviceSize IndexBufferSize;
59  VkBuffer VertexBuffer;
60  VkBuffer IndexBuffer;
61 };
62 
63 // Each viewport will hold 1 ImGui_ImplVulkanH_WindowRenderBuffers
64 // [Please zero-clear before use!]
66 {
67  uint32_t Index;
68  uint32_t Count;
70 };
71 
72 // Vulkan data
74 static VkRenderPass g_RenderPass = VK_NULL_HANDLE;
75 static VkDeviceSize g_BufferMemoryAlignment = 256;
76 static VkPipelineCreateFlags g_PipelineCreateFlags = 0x00;
77 static VkDescriptorSetLayout g_DescriptorSetLayout = VK_NULL_HANDLE;
78 static VkPipelineLayout g_PipelineLayout = VK_NULL_HANDLE;
79 static VkDescriptorSet g_DescriptorSet = VK_NULL_HANDLE;
80 static VkPipeline g_Pipeline = VK_NULL_HANDLE;
81 
82 // Font data
83 static VkSampler g_FontSampler = VK_NULL_HANDLE;
84 static VkDeviceMemory g_FontMemory = VK_NULL_HANDLE;
85 static VkImage g_FontImage = VK_NULL_HANDLE;
86 static VkImageView g_FontView = VK_NULL_HANDLE;
87 static VkDeviceMemory g_UploadBufferMemory = VK_NULL_HANDLE;
88 static VkBuffer g_UploadBuffer = VK_NULL_HANDLE;
89 
90 // Render buffers
92 
93 // Forward Declarations
96 void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame* fd, const VkAllocationCallbacks* allocator);
97 void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores* fsd, const VkAllocationCallbacks* allocator);
98 void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
99 void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator);
100 void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
101 void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator);
102 
103 //-----------------------------------------------------------------------------
104 // SHADERS
105 //-----------------------------------------------------------------------------
106 
107 // glsl_shader.vert, compiled with:
108 // # glslangValidator -V -x -o glsl_shader.vert.u32 glsl_shader.vert
109 /*
110 #version 450 core
111 layout(location = 0) in vec2 aPos;
112 layout(location = 1) in vec2 aUV;
113 layout(location = 2) in vec4 aColor;
114 layout(push_constant) uniform uPushConstant { vec2 uScale; vec2 uTranslate; } pc;
115 
116 out gl_PerVertex { vec4 gl_Position; };
117 layout(location = 0) out struct { vec4 Color; vec2 UV; } Out;
118 
119 void main()
120 {
121  Out.Color = aColor;
122  Out.UV = aUV;
123  gl_Position = vec4(aPos * pc.uScale + pc.uTranslate, 0, 1);
124 }
125 */
126 static uint32_t __glsl_shader_vert_spv[] =
127 {
128  0x07230203,0x00010000,0x00080001,0x0000002e,0x00000000,0x00020011,0x00000001,0x0006000b,
129  0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
130  0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015,
131  0x0000001b,0x0000001c,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
132  0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43,
133  0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f,
134  0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00060005,
135  0x00000019,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x00000019,0x00000000,
136  0x505f6c67,0x7469736f,0x006e6f69,0x00030005,0x0000001b,0x00000000,0x00040005,0x0000001c,
137  0x736f5061,0x00000000,0x00060005,0x0000001e,0x73755075,0x6e6f4368,0x6e617473,0x00000074,
138  0x00050006,0x0000001e,0x00000000,0x61635375,0x0000656c,0x00060006,0x0000001e,0x00000001,
139  0x61725475,0x616c736e,0x00006574,0x00030005,0x00000020,0x00006370,0x00040047,0x0000000b,
140  0x0000001e,0x00000000,0x00040047,0x0000000f,0x0000001e,0x00000002,0x00040047,0x00000015,
141  0x0000001e,0x00000001,0x00050048,0x00000019,0x00000000,0x0000000b,0x00000000,0x00030047,
142  0x00000019,0x00000002,0x00040047,0x0000001c,0x0000001e,0x00000000,0x00050048,0x0000001e,
143  0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000001,0x00000023,0x00000008,
144  0x00030047,0x0000001e,0x00000002,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,
145  0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040017,
146  0x00000008,0x00000006,0x00000002,0x0004001e,0x00000009,0x00000007,0x00000008,0x00040020,
147  0x0000000a,0x00000003,0x00000009,0x0004003b,0x0000000a,0x0000000b,0x00000003,0x00040015,
148  0x0000000c,0x00000020,0x00000001,0x0004002b,0x0000000c,0x0000000d,0x00000000,0x00040020,
149  0x0000000e,0x00000001,0x00000007,0x0004003b,0x0000000e,0x0000000f,0x00000001,0x00040020,
150  0x00000011,0x00000003,0x00000007,0x0004002b,0x0000000c,0x00000013,0x00000001,0x00040020,
151  0x00000014,0x00000001,0x00000008,0x0004003b,0x00000014,0x00000015,0x00000001,0x00040020,
152  0x00000017,0x00000003,0x00000008,0x0003001e,0x00000019,0x00000007,0x00040020,0x0000001a,
153  0x00000003,0x00000019,0x0004003b,0x0000001a,0x0000001b,0x00000003,0x0004003b,0x00000014,
154  0x0000001c,0x00000001,0x0004001e,0x0000001e,0x00000008,0x00000008,0x00040020,0x0000001f,
155  0x00000009,0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000009,0x00040020,0x00000021,
156  0x00000009,0x00000008,0x0004002b,0x00000006,0x00000028,0x00000000,0x0004002b,0x00000006,
157  0x00000029,0x3f800000,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
158  0x00000005,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,0x00000012,
159  0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,0x00000016,
160  0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,0x00000018,
161  0x00000016,0x0004003d,0x00000008,0x0000001d,0x0000001c,0x00050041,0x00000021,0x00000022,
162  0x00000020,0x0000000d,0x0004003d,0x00000008,0x00000023,0x00000022,0x00050085,0x00000008,
163  0x00000024,0x0000001d,0x00000023,0x00050041,0x00000021,0x00000025,0x00000020,0x00000013,
164  0x0004003d,0x00000008,0x00000026,0x00000025,0x00050081,0x00000008,0x00000027,0x00000024,
165  0x00000026,0x00050051,0x00000006,0x0000002a,0x00000027,0x00000000,0x00050051,0x00000006,
166  0x0000002b,0x00000027,0x00000001,0x00070050,0x00000007,0x0000002c,0x0000002a,0x0000002b,
167  0x00000028,0x00000029,0x00050041,0x00000011,0x0000002d,0x0000001b,0x0000000d,0x0003003e,
168  0x0000002d,0x0000002c,0x000100fd,0x00010038
169 };
170 
171 // glsl_shader.frag, compiled with:
172 // # glslangValidator -V -x -o glsl_shader.frag.u32 glsl_shader.frag
173 /*
174 #version 450 core
175 layout(location = 0) out vec4 fColor;
176 layout(set=0, binding=0) uniform sampler2D sTexture;
177 layout(location = 0) in struct { vec4 Color; vec2 UV; } In;
178 void main()
179 {
180  fColor = In.Color * texture(sTexture, In.UV.st);
181 }
182 */
183 static uint32_t __glsl_shader_frag_spv[] =
184 {
185  0x07230203,0x00010000,0x00080001,0x0000001e,0x00000000,0x00020011,0x00000001,0x0006000b,
186  0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
187  0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000d,0x00030010,
188  0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
189  0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000b,0x00000000,
190  0x00050006,0x0000000b,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000b,0x00000001,
191  0x00005655,0x00030005,0x0000000d,0x00006e49,0x00050005,0x00000016,0x78655473,0x65727574,
192  0x00000000,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d,0x0000001e,
193  0x00000000,0x00040047,0x00000016,0x00000022,0x00000000,0x00040047,0x00000016,0x00000021,
194  0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,
195  0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003,
196  0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a,0x00000006,
197  0x00000002,0x0004001e,0x0000000b,0x00000007,0x0000000a,0x00040020,0x0000000c,0x00000001,
198  0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000001,0x00040015,0x0000000e,0x00000020,
199  0x00000001,0x0004002b,0x0000000e,0x0000000f,0x00000000,0x00040020,0x00000010,0x00000001,
200  0x00000007,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,
201  0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020,0x00000015,0x00000000,
202  0x00000014,0x0004003b,0x00000015,0x00000016,0x00000000,0x0004002b,0x0000000e,0x00000018,
203  0x00000001,0x00040020,0x00000019,0x00000001,0x0000000a,0x00050036,0x00000002,0x00000004,
204  0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,0x00000010,0x00000011,0x0000000d,
205  0x0000000f,0x0004003d,0x00000007,0x00000012,0x00000011,0x0004003d,0x00000014,0x00000017,
206  0x00000016,0x00050041,0x00000019,0x0000001a,0x0000000d,0x00000018,0x0004003d,0x0000000a,
207  0x0000001b,0x0000001a,0x00050057,0x00000007,0x0000001c,0x00000017,0x0000001b,0x00050085,
208  0x00000007,0x0000001d,0x00000012,0x0000001c,0x0003003e,0x00000009,0x0000001d,0x000100fd,
209  0x00010038
210 };
211 
212 //-----------------------------------------------------------------------------
213 // FUNCTIONS
214 //-----------------------------------------------------------------------------
215 
216 static uint32_t ImGui_ImplVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits)
217 {
219  VkPhysicalDeviceMemoryProperties prop;
220  vkGetPhysicalDeviceMemoryProperties(v->PhysicalDevice, &prop);
221  for (uint32_t i = 0; i < prop.memoryTypeCount; i++)
222  if ((prop.memoryTypes[i].propertyFlags & properties) == properties && type_bits & (1<<i))
223  return i;
224  return 0xFFFFFFFF; // Unable to find memoryType
225 }
226 
227 static void check_vk_result(VkResult err)
228 {
230  if (v->CheckVkResultFn)
232 }
233 
234 static void CreateOrResizeBuffer(VkBuffer& buffer, VkDeviceMemory& buffer_memory, VkDeviceSize& p_buffer_size, size_t new_size, VkBufferUsageFlagBits usage)
235 {
237  VkResult err;
238  if (buffer != VK_NULL_HANDLE)
239  vkDestroyBuffer(v->Device, buffer, v->Allocator);
240  if (buffer_memory != VK_NULL_HANDLE)
241  vkFreeMemory(v->Device, buffer_memory, v->Allocator);
242 
243  VkDeviceSize vertex_buffer_size_aligned = ((new_size - 1) / g_BufferMemoryAlignment + 1) * g_BufferMemoryAlignment;
244  VkBufferCreateInfo buffer_info = {};
245  buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
246  buffer_info.size = vertex_buffer_size_aligned;
247  buffer_info.usage = usage;
248  buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
249  err = vkCreateBuffer(v->Device, &buffer_info, v->Allocator, &buffer);
251 
252  VkMemoryRequirements req;
253  vkGetBufferMemoryRequirements(v->Device, buffer, &req);
255  VkMemoryAllocateInfo alloc_info = {};
256  alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
257  alloc_info.allocationSize = req.size;
258  alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
259  err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &buffer_memory);
261 
262  err = vkBindBufferMemory(v->Device, buffer, buffer_memory, 0);
264  p_buffer_size = new_size;
265 }
266 
267 static void ImGui_ImplVulkan_SetupRenderState(ImDrawData* draw_data, VkCommandBuffer command_buffer, ImGui_ImplVulkanH_FrameRenderBuffers* rb, int fb_width, int fb_height)
268 {
269  // Bind pipeline and descriptor sets:
270  {
271  vkCmdBindPipeline(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Pipeline);
272  VkDescriptorSet desc_set[1] = { g_DescriptorSet };
273  vkCmdBindDescriptorSets(command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_PipelineLayout, 0, 1, desc_set, 0, NULL);
274  }
275 
276  // Bind Vertex And Index Buffer:
277  {
278  VkBuffer vertex_buffers[1] = { rb->VertexBuffer };
279  VkDeviceSize vertex_offset[1] = { 0 };
280  vkCmdBindVertexBuffers(command_buffer, 0, 1, vertex_buffers, vertex_offset);
281  vkCmdBindIndexBuffer(command_buffer, rb->IndexBuffer, 0, sizeof(ImDrawIdx) == 2 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32);
282  }
283 
284  // Setup viewport:
285  {
286  VkViewport viewport;
287  viewport.x = 0;
288  viewport.y = 0;
289  viewport.width = (float)fb_width;
290  viewport.height = (float)fb_height;
291  viewport.minDepth = 0.0f;
292  viewport.maxDepth = 1.0f;
293  vkCmdSetViewport(command_buffer, 0, 1, &viewport);
294  }
295 
296  // Setup scale and translation:
297  // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
298  {
299  float scale[2];
300  scale[0] = 2.0f / draw_data->DisplaySize.x;
301  scale[1] = 2.0f / draw_data->DisplaySize.y;
302  float translate[2];
303  translate[0] = -1.0f - draw_data->DisplayPos.x * scale[0];
304  translate[1] = -1.0f - draw_data->DisplayPos.y * scale[1];
305  vkCmdPushConstants(command_buffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0, sizeof(float) * 2, scale);
306  vkCmdPushConstants(command_buffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2, sizeof(float) * 2, translate);
307  }
308 }
309 
310 // Render function
311 // (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
312 void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer)
313 {
314  // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
315  int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
316  int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
317  if (fb_width <= 0 || fb_height <= 0 || draw_data->TotalVtxCount == 0)
318  return;
319 
321 
322  // Allocate array to store enough vertex/index buffers
324  if (wrb->FrameRenderBuffers == NULL)
325  {
326  wrb->Index = 0;
327  wrb->Count = v->ImageCount;
329  memset(wrb->FrameRenderBuffers, 0, sizeof(ImGui_ImplVulkanH_FrameRenderBuffers) * wrb->Count);
330  }
331  IM_ASSERT(wrb->Count == v->ImageCount);
332  wrb->Index = (wrb->Index + 1) % wrb->Count;
334 
335  VkResult err;
336 
337  // Create or resize the vertex/index buffers
338  size_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
339  size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);
340  if (rb->VertexBuffer == VK_NULL_HANDLE || rb->VertexBufferSize < vertex_size)
341  CreateOrResizeBuffer(rb->VertexBuffer, rb->VertexBufferMemory, rb->VertexBufferSize, vertex_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT);
342  if (rb->IndexBuffer == VK_NULL_HANDLE || rb->IndexBufferSize < index_size)
343  CreateOrResizeBuffer(rb->IndexBuffer, rb->IndexBufferMemory, rb->IndexBufferSize, index_size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT);
344 
345  // Upload vertex/index data into a single contiguous GPU buffer
346  {
347  ImDrawVert* vtx_dst = NULL;
348  ImDrawIdx* idx_dst = NULL;
349  err = vkMapMemory(v->Device, rb->VertexBufferMemory, 0, vertex_size, 0, (void**)(&vtx_dst));
351  err = vkMapMemory(v->Device, rb->IndexBufferMemory, 0, index_size, 0, (void**)(&idx_dst));
353  for (int n = 0; n < draw_data->CmdListsCount; n++)
354  {
355  const ImDrawList* cmd_list = draw_data->CmdLists[n];
356  memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
357  memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
358  vtx_dst += cmd_list->VtxBuffer.Size;
359  idx_dst += cmd_list->IdxBuffer.Size;
360  }
361  VkMappedMemoryRange range[2] = {};
362  range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
363  range[0].memory = rb->VertexBufferMemory;
364  range[0].size = VK_WHOLE_SIZE;
365  range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
366  range[1].memory = rb->IndexBufferMemory;
367  range[1].size = VK_WHOLE_SIZE;
368  err = vkFlushMappedMemoryRanges(v->Device, 2, range);
370  vkUnmapMemory(v->Device, rb->VertexBufferMemory);
371  vkUnmapMemory(v->Device, rb->IndexBufferMemory);
372  }
373 
374  // Setup desired Vulkan state
375  ImGui_ImplVulkan_SetupRenderState(draw_data, command_buffer, rb, fb_width, fb_height);
376 
377  // Will project scissor/clipping rectangles into framebuffer space
378  ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
379  ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
380 
381  // Render command lists
382  // (Because we merged all buffers into a single one, we maintain our own offset into them)
383  int global_vtx_offset = 0;
384  int global_idx_offset = 0;
385  for (int n = 0; n < draw_data->CmdListsCount; n++)
386  {
387  const ImDrawList* cmd_list = draw_data->CmdLists[n];
388  for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
389  {
390  const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
391  if (pcmd->UserCallback != NULL)
392  {
393  // User callback, registered via ImDrawList::AddCallback()
394  // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
396  ImGui_ImplVulkan_SetupRenderState(draw_data, command_buffer, rb, fb_width, fb_height);
397  else
398  pcmd->UserCallback(cmd_list, pcmd);
399  }
400  else
401  {
402  // Project scissor/clipping rectangles into framebuffer space
403  ImVec4 clip_rect;
404  clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
405  clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
406  clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
407  clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
408 
409  if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
410  {
411  // Negative offsets are illegal for vkCmdSetScissor
412  if (clip_rect.x < 0.0f)
413  clip_rect.x = 0.0f;
414  if (clip_rect.y < 0.0f)
415  clip_rect.y = 0.0f;
416 
417  // Apply scissor/clipping rectangle
418  VkRect2D scissor;
419  scissor.offset.x = (int32_t)(clip_rect.x);
420  scissor.offset.y = (int32_t)(clip_rect.y);
421  scissor.extent.width = (uint32_t)(clip_rect.z - clip_rect.x);
422  scissor.extent.height = (uint32_t)(clip_rect.w - clip_rect.y);
423  vkCmdSetScissor(command_buffer, 0, 1, &scissor);
424 
425  // Draw
426  vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
427  }
428  }
429  }
430  global_idx_offset += cmd_list->IdxBuffer.Size;
431  global_vtx_offset += cmd_list->VtxBuffer.Size;
432  }
433 }
434 
435 bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
436 {
438  ImGuiIO& io = ImGui::GetIO();
439 
440  unsigned char* pixels;
441  int width, height;
443  size_t upload_size = width*height*4*sizeof(char);
444 
445  VkResult err;
446 
447  // Create the Image:
448  {
449  VkImageCreateInfo info = {};
450  info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
451  info.imageType = VK_IMAGE_TYPE_2D;
452  info.format = VK_FORMAT_R8G8B8A8_UNORM;
453  info.extent.width = width;
454  info.extent.height = height;
455  info.extent.depth = 1;
456  info.mipLevels = 1;
457  info.arrayLayers = 1;
458  info.samples = VK_SAMPLE_COUNT_1_BIT;
459  info.tiling = VK_IMAGE_TILING_OPTIMAL;
460  info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
461  info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
462  info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
463  err = vkCreateImage(v->Device, &info, v->Allocator, &g_FontImage);
465  VkMemoryRequirements req;
466  vkGetImageMemoryRequirements(v->Device, g_FontImage, &req);
467  VkMemoryAllocateInfo alloc_info = {};
468  alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
469  alloc_info.allocationSize = req.size;
470  alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits);
471  err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &g_FontMemory);
473  err = vkBindImageMemory(v->Device, g_FontImage, g_FontMemory, 0);
475  }
476 
477  // Create the Image View:
478  {
479  VkImageViewCreateInfo info = {};
480  info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
481  info.image = g_FontImage;
482  info.viewType = VK_IMAGE_VIEW_TYPE_2D;
483  info.format = VK_FORMAT_R8G8B8A8_UNORM;
484  info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
485  info.subresourceRange.levelCount = 1;
486  info.subresourceRange.layerCount = 1;
487  err = vkCreateImageView(v->Device, &info, v->Allocator, &g_FontView);
489  }
490 
491  // Update the Descriptor Set:
492  {
493  VkDescriptorImageInfo desc_image[1] = {};
494  desc_image[0].sampler = g_FontSampler;
495  desc_image[0].imageView = g_FontView;
496  desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
497  VkWriteDescriptorSet write_desc[1] = {};
498  write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
499  write_desc[0].dstSet = g_DescriptorSet;
500  write_desc[0].descriptorCount = 1;
501  write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
502  write_desc[0].pImageInfo = desc_image;
503  vkUpdateDescriptorSets(v->Device, 1, write_desc, 0, NULL);
504  }
505 
506  // Create the Upload Buffer:
507  {
508  VkBufferCreateInfo buffer_info = {};
509  buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
510  buffer_info.size = upload_size;
511  buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
512  buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
513  err = vkCreateBuffer(v->Device, &buffer_info, v->Allocator, &g_UploadBuffer);
515  VkMemoryRequirements req;
516  vkGetBufferMemoryRequirements(v->Device, g_UploadBuffer, &req);
518  VkMemoryAllocateInfo alloc_info = {};
519  alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
520  alloc_info.allocationSize = req.size;
521  alloc_info.memoryTypeIndex = ImGui_ImplVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
522  err = vkAllocateMemory(v->Device, &alloc_info, v->Allocator, &g_UploadBufferMemory);
524  err = vkBindBufferMemory(v->Device, g_UploadBuffer, g_UploadBufferMemory, 0);
526  }
527 
528  // Upload to Buffer:
529  {
530  char* map = NULL;
531  err = vkMapMemory(v->Device, g_UploadBufferMemory, 0, upload_size, 0, (void**)(&map));
533  memcpy(map, pixels, upload_size);
534  VkMappedMemoryRange range[1] = {};
535  range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
536  range[0].memory = g_UploadBufferMemory;
537  range[0].size = upload_size;
538  err = vkFlushMappedMemoryRanges(v->Device, 1, range);
540  vkUnmapMemory(v->Device, g_UploadBufferMemory);
541  }
542 
543  // Copy to Image:
544  {
545  VkImageMemoryBarrier copy_barrier[1] = {};
546  copy_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
547  copy_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
548  copy_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
549  copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
550  copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
551  copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
552  copy_barrier[0].image = g_FontImage;
553  copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
554  copy_barrier[0].subresourceRange.levelCount = 1;
555  copy_barrier[0].subresourceRange.layerCount = 1;
556  vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, copy_barrier);
557 
558  VkBufferImageCopy region = {};
559  region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
560  region.imageSubresource.layerCount = 1;
561  region.imageExtent.width = width;
562  region.imageExtent.height = height;
563  region.imageExtent.depth = 1;
564  vkCmdCopyBufferToImage(command_buffer, g_UploadBuffer, g_FontImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
565 
566  VkImageMemoryBarrier use_barrier[1] = {};
567  use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
568  use_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
569  use_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
570  use_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
571  use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
572  use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
573  use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
574  use_barrier[0].image = g_FontImage;
575  use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
576  use_barrier[0].subresourceRange.levelCount = 1;
577  use_barrier[0].subresourceRange.layerCount = 1;
578  vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, use_barrier);
579  }
580 
581  // Store our identifier
582  io.Fonts->TexID = (ImTextureID)(intptr_t)g_FontImage;
583 
584  return true;
585 }
586 
588 {
590  VkResult err;
591  VkShaderModule vert_module;
592  VkShaderModule frag_module;
593 
594  // Create The Shader Modules:
595  {
596  VkShaderModuleCreateInfo vert_info = {};
597  vert_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
598  vert_info.codeSize = sizeof(__glsl_shader_vert_spv);
599  vert_info.pCode = (uint32_t*)__glsl_shader_vert_spv;
600  err = vkCreateShaderModule(v->Device, &vert_info, v->Allocator, &vert_module);
602  VkShaderModuleCreateInfo frag_info = {};
603  frag_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
604  frag_info.codeSize = sizeof(__glsl_shader_frag_spv);
605  frag_info.pCode = (uint32_t*)__glsl_shader_frag_spv;
606  err = vkCreateShaderModule(v->Device, &frag_info, v->Allocator, &frag_module);
608  }
609 
610  if (!g_FontSampler)
611  {
612  VkSamplerCreateInfo info = {};
613  info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
614  info.magFilter = VK_FILTER_LINEAR;
615  info.minFilter = VK_FILTER_LINEAR;
616  info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
617  info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
618  info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
619  info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
620  info.minLod = -1000;
621  info.maxLod = 1000;
622  info.maxAnisotropy = 1.0f;
623  err = vkCreateSampler(v->Device, &info, v->Allocator, &g_FontSampler);
625  }
626 
628  {
629  VkSampler sampler[1] = {g_FontSampler};
630  VkDescriptorSetLayoutBinding binding[1] = {};
631  binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
632  binding[0].descriptorCount = 1;
633  binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
634  binding[0].pImmutableSamplers = sampler;
635  VkDescriptorSetLayoutCreateInfo info = {};
636  info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
637  info.bindingCount = 1;
638  info.pBindings = binding;
639  err = vkCreateDescriptorSetLayout(v->Device, &info, v->Allocator, &g_DescriptorSetLayout);
641  }
642 
643  // Create Descriptor Set:
644  {
645  VkDescriptorSetAllocateInfo alloc_info = {};
646  alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
647  alloc_info.descriptorPool = v->DescriptorPool;
648  alloc_info.descriptorSetCount = 1;
649  alloc_info.pSetLayouts = &g_DescriptorSetLayout;
650  err = vkAllocateDescriptorSets(v->Device, &alloc_info, &g_DescriptorSet);
652  }
653 
654  if (!g_PipelineLayout)
655  {
656  // Constants: we are using 'vec2 offset' and 'vec2 scale' instead of a full 3d projection matrix
657  VkPushConstantRange push_constants[1] = {};
658  push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
659  push_constants[0].offset = sizeof(float) * 0;
660  push_constants[0].size = sizeof(float) * 4;
661  VkDescriptorSetLayout set_layout[1] = { g_DescriptorSetLayout };
662  VkPipelineLayoutCreateInfo layout_info = {};
663  layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
664  layout_info.setLayoutCount = 1;
665  layout_info.pSetLayouts = set_layout;
666  layout_info.pushConstantRangeCount = 1;
667  layout_info.pPushConstantRanges = push_constants;
668  err = vkCreatePipelineLayout(v->Device, &layout_info, v->Allocator, &g_PipelineLayout);
670  }
671 
672  VkPipelineShaderStageCreateInfo stage[2] = {};
673  stage[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
674  stage[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
675  stage[0].module = vert_module;
676  stage[0].pName = "main";
677  stage[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
678  stage[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
679  stage[1].module = frag_module;
680  stage[1].pName = "main";
681 
682  VkVertexInputBindingDescription binding_desc[1] = {};
683  binding_desc[0].stride = sizeof(ImDrawVert);
684  binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
685 
686  VkVertexInputAttributeDescription attribute_desc[3] = {};
687  attribute_desc[0].location = 0;
688  attribute_desc[0].binding = binding_desc[0].binding;
689  attribute_desc[0].format = VK_FORMAT_R32G32_SFLOAT;
690  attribute_desc[0].offset = IM_OFFSETOF(ImDrawVert, pos);
691  attribute_desc[1].location = 1;
692  attribute_desc[1].binding = binding_desc[0].binding;
693  attribute_desc[1].format = VK_FORMAT_R32G32_SFLOAT;
694  attribute_desc[1].offset = IM_OFFSETOF(ImDrawVert, uv);
695  attribute_desc[2].location = 2;
696  attribute_desc[2].binding = binding_desc[0].binding;
697  attribute_desc[2].format = VK_FORMAT_R8G8B8A8_UNORM;
698  attribute_desc[2].offset = IM_OFFSETOF(ImDrawVert, col);
699 
700  VkPipelineVertexInputStateCreateInfo vertex_info = {};
701  vertex_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
702  vertex_info.vertexBindingDescriptionCount = 1;
703  vertex_info.pVertexBindingDescriptions = binding_desc;
704  vertex_info.vertexAttributeDescriptionCount = 3;
705  vertex_info.pVertexAttributeDescriptions = attribute_desc;
706 
707  VkPipelineInputAssemblyStateCreateInfo ia_info = {};
708  ia_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
709  ia_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
710 
711  VkPipelineViewportStateCreateInfo viewport_info = {};
712  viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
713  viewport_info.viewportCount = 1;
714  viewport_info.scissorCount = 1;
715 
716  VkPipelineRasterizationStateCreateInfo raster_info = {};
717  raster_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
718  raster_info.polygonMode = VK_POLYGON_MODE_FILL;
719  raster_info.cullMode = VK_CULL_MODE_NONE;
720  raster_info.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
721  raster_info.lineWidth = 1.0f;
722 
723  VkPipelineMultisampleStateCreateInfo ms_info = {};
724  ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
725  if (v->MSAASamples != 0)
726  ms_info.rasterizationSamples = v->MSAASamples;
727  else
728  ms_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
729 
730  VkPipelineColorBlendAttachmentState color_attachment[1] = {};
731  color_attachment[0].blendEnable = VK_TRUE;
732  color_attachment[0].srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
733  color_attachment[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
734  color_attachment[0].colorBlendOp = VK_BLEND_OP_ADD;
735  color_attachment[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
736  color_attachment[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
737  color_attachment[0].alphaBlendOp = VK_BLEND_OP_ADD;
738  color_attachment[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
739 
740  VkPipelineDepthStencilStateCreateInfo depth_info = {};
741  depth_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
742 
743  VkPipelineColorBlendStateCreateInfo blend_info = {};
744  blend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
745  blend_info.attachmentCount = 1;
746  blend_info.pAttachments = color_attachment;
747 
748  VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
749  VkPipelineDynamicStateCreateInfo dynamic_state = {};
750  dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
751  dynamic_state.dynamicStateCount = (uint32_t)IM_ARRAYSIZE(dynamic_states);
752  dynamic_state.pDynamicStates = dynamic_states;
753 
754  VkGraphicsPipelineCreateInfo info = {};
755  info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
756  info.flags = g_PipelineCreateFlags;
757  info.stageCount = 2;
758  info.pStages = stage;
759  info.pVertexInputState = &vertex_info;
760  info.pInputAssemblyState = &ia_info;
761  info.pViewportState = &viewport_info;
762  info.pRasterizationState = &raster_info;
763  info.pMultisampleState = &ms_info;
764  info.pDepthStencilState = &depth_info;
765  info.pColorBlendState = &blend_info;
766  info.pDynamicState = &dynamic_state;
767  info.layout = g_PipelineLayout;
768  info.renderPass = g_RenderPass;
769  err = vkCreateGraphicsPipelines(v->Device, v->PipelineCache, 1, &info, v->Allocator, &g_Pipeline);
771 
772  vkDestroyShaderModule(v->Device, vert_module, v->Allocator);
773  vkDestroyShaderModule(v->Device, frag_module, v->Allocator);
774 
775  return true;
776 }
777 
779 {
781  if (g_UploadBuffer)
782  {
783  vkDestroyBuffer(v->Device, g_UploadBuffer, v->Allocator);
784  g_UploadBuffer = VK_NULL_HANDLE;
785  }
787  {
788  vkFreeMemory(v->Device, g_UploadBufferMemory, v->Allocator);
789  g_UploadBufferMemory = VK_NULL_HANDLE;
790  }
791 }
792 
794 {
798 
799  if (g_FontView) { vkDestroyImageView(v->Device, g_FontView, v->Allocator); g_FontView = VK_NULL_HANDLE; }
800  if (g_FontImage) { vkDestroyImage(v->Device, g_FontImage, v->Allocator); g_FontImage = VK_NULL_HANDLE; }
801  if (g_FontMemory) { vkFreeMemory(v->Device, g_FontMemory, v->Allocator); g_FontMemory = VK_NULL_HANDLE; }
802  if (g_FontSampler) { vkDestroySampler(v->Device, g_FontSampler, v->Allocator); g_FontSampler = VK_NULL_HANDLE; }
803  if (g_DescriptorSetLayout) { vkDestroyDescriptorSetLayout(v->Device, g_DescriptorSetLayout, v->Allocator); g_DescriptorSetLayout = VK_NULL_HANDLE; }
804  if (g_PipelineLayout) { vkDestroyPipelineLayout(v->Device, g_PipelineLayout, v->Allocator); g_PipelineLayout = VK_NULL_HANDLE; }
805  if (g_Pipeline) { vkDestroyPipeline(v->Device, g_Pipeline, v->Allocator); g_Pipeline = VK_NULL_HANDLE; }
806 }
807 
808 bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass)
809 {
810  // Setup back-end capabilities flags
811  ImGuiIO& io = ImGui::GetIO();
812  io.BackendRendererName = "imgui_impl_vulkan";
813  io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
814 
815  IM_ASSERT(info->Instance != VK_NULL_HANDLE);
816  IM_ASSERT(info->PhysicalDevice != VK_NULL_HANDLE);
817  IM_ASSERT(info->Device != VK_NULL_HANDLE);
818  IM_ASSERT(info->Queue != VK_NULL_HANDLE);
819  IM_ASSERT(info->DescriptorPool != VK_NULL_HANDLE);
820  IM_ASSERT(info->MinImageCount >= 2);
821  IM_ASSERT(info->ImageCount >= info->MinImageCount);
822  IM_ASSERT(render_pass != VK_NULL_HANDLE);
823 
824  g_VulkanInitInfo = *info;
825  g_RenderPass = render_pass;
827 
828  return true;
829 }
830 
832 {
834 }
835 
837 {
838 }
839 
840 void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count)
841 {
842  IM_ASSERT(min_image_count >= 2);
843  if (g_VulkanInitInfo.MinImageCount == min_image_count)
844  return;
845 
847  VkResult err = vkDeviceWaitIdle(v->Device);
850  g_VulkanInitInfo.MinImageCount = min_image_count;
851 }
852 
853 
854 //-------------------------------------------------------------------------
855 // Internal / Miscellaneous Vulkan Helpers
856 // (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own app.)
857 //-------------------------------------------------------------------------
858 // You probably do NOT need to use or care about those functions.
859 // Those functions only exist because:
860 // 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
861 // 2) the upcoming multi-viewport feature will need them internally.
862 // Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
863 // but it is too much code to duplicate everywhere so we exceptionally expose them.
864 //
865 // Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
866 // You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
867 // (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
868 //-------------------------------------------------------------------------
869 
870 VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space)
871 {
872  IM_ASSERT(request_formats != NULL);
873  IM_ASSERT(request_formats_count > 0);
874 
875  // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation
876  // Assuming that the default behavior is without setting this bit, there is no need for separate Swapchain image and image view format
877  // Additionally several new color spaces were introduced with Vulkan Spec v1.0.40,
878  // hence we must make sure that a format with the mostly available color space, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, is found and used.
879  uint32_t avail_count;
880  vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, NULL);
881  ImVector<VkSurfaceFormatKHR> avail_format;
882  avail_format.resize((int)avail_count);
883  vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, avail_format.Data);
884 
885  // First check if only one format, VK_FORMAT_UNDEFINED, is available, which would imply that any format is available
886  if (avail_count == 1)
887  {
888  if (avail_format[0].format == VK_FORMAT_UNDEFINED)
889  {
890  VkSurfaceFormatKHR ret;
891  ret.format = request_formats[0];
892  ret.colorSpace = request_color_space;
893  return ret;
894  }
895  else
896  {
897  // No point in searching another format
898  return avail_format[0];
899  }
900  }
901  else
902  {
903  // Request several formats, the first found will be used
904  for (int request_i = 0; request_i < request_formats_count; request_i++)
905  for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++)
906  if (avail_format[avail_i].format == request_formats[request_i] && avail_format[avail_i].colorSpace == request_color_space)
907  return avail_format[avail_i];
908 
909  // If none of the requested image formats could be found, use the first available
910  return avail_format[0];
911  }
912 }
913 
914 VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count)
915 {
916  IM_ASSERT(request_modes != NULL);
917  IM_ASSERT(request_modes_count > 0);
918 
919  // Request a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory
920  uint32_t avail_count = 0;
921  vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, NULL);
922  ImVector<VkPresentModeKHR> avail_modes;
923  avail_modes.resize((int)avail_count);
924  vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, avail_modes.Data);
925  //for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++)
926  // printf("[vulkan] avail_modes[%d] = %d\n", avail_i, avail_modes[avail_i]);
927 
928  for (int request_i = 0; request_i < request_modes_count; request_i++)
929  for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++)
930  if (request_modes[request_i] == avail_modes[avail_i])
931  return request_modes[request_i];
932 
933  return VK_PRESENT_MODE_FIFO_KHR; // Always available
934 }
935 
936 void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator)
937 {
938  IM_ASSERT(physical_device != VK_NULL_HANDLE && device != VK_NULL_HANDLE);
939  (void)physical_device;
940  (void)allocator;
941 
942  // Create Command Buffers
943  VkResult err;
944  for (uint32_t i = 0; i < wd->ImageCount; i++)
945  {
946  ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i];
948  {
949  VkCommandPoolCreateInfo info = {};
950  info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
951  info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
952  info.queueFamilyIndex = queue_family;
953  err = vkCreateCommandPool(device, &info, allocator, &fd->CommandPool);
955  }
956  {
957  VkCommandBufferAllocateInfo info = {};
958  info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
959  info.commandPool = fd->CommandPool;
960  info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
961  info.commandBufferCount = 1;
962  err = vkAllocateCommandBuffers(device, &info, &fd->CommandBuffer);
964  }
965  {
966  VkFenceCreateInfo info = {};
967  info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
968  info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
969  err = vkCreateFence(device, &info, allocator, &fd->Fence);
971  }
972  {
973  VkSemaphoreCreateInfo info = {};
974  info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
975  err = vkCreateSemaphore(device, &info, allocator, &fsd->ImageAcquiredSemaphore);
977  err = vkCreateSemaphore(device, &info, allocator, &fsd->RenderCompleteSemaphore);
979  }
980  }
981 }
982 
983 int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode)
984 {
985  if (present_mode == VK_PRESENT_MODE_MAILBOX_KHR)
986  return 3;
987  if (present_mode == VK_PRESENT_MODE_FIFO_KHR || present_mode == VK_PRESENT_MODE_FIFO_RELAXED_KHR)
988  return 2;
989  if (present_mode == VK_PRESENT_MODE_IMMEDIATE_KHR)
990  return 1;
991  IM_ASSERT(0);
992  return 1;
993 }
994 
995 // Also destroy old swap chain and in-flight frames data, if any.
996 void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count)
997 {
998  VkResult err;
999  VkSwapchainKHR old_swapchain = wd->Swapchain;
1000  err = vkDeviceWaitIdle(device);
1002 
1003  // We don't use ImGui_ImplVulkanH_DestroyWindow() because we want to preserve the old swapchain to create the new one.
1004  // Destroy old Framebuffer
1005  for (uint32_t i = 0; i < wd->ImageCount; i++)
1006  {
1007  ImGui_ImplVulkanH_DestroyFrame(device, &wd->Frames[i], allocator);
1009  }
1010  IM_FREE(wd->Frames);
1011  IM_FREE(wd->FrameSemaphores);
1012  wd->Frames = NULL;
1013  wd->FrameSemaphores = NULL;
1014  wd->ImageCount = 0;
1015  if (wd->RenderPass)
1016  vkDestroyRenderPass(device, wd->RenderPass, allocator);
1017 
1018  // If min image count was not specified, request different count of images dependent on selected present mode
1019  if (min_image_count == 0)
1021 
1022  // Create Swapchain
1023  {
1024  VkSwapchainCreateInfoKHR info = {};
1025  info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
1026  info.surface = wd->Surface;
1027  info.minImageCount = min_image_count;
1028  info.imageFormat = wd->SurfaceFormat.format;
1029  info.imageColorSpace = wd->SurfaceFormat.colorSpace;
1030  info.imageArrayLayers = 1;
1031  info.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
1032  info.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; // Assume that graphics family == present family
1033  info.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
1034  info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
1035  info.presentMode = wd->PresentMode;
1036  info.clipped = VK_TRUE;
1037  info.oldSwapchain = old_swapchain;
1038  VkSurfaceCapabilitiesKHR cap;
1039  err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, wd->Surface, &cap);
1041  if (info.minImageCount < cap.minImageCount)
1042  info.minImageCount = cap.minImageCount;
1043  else if (cap.maxImageCount != 0 && info.minImageCount > cap.maxImageCount)
1044  info.minImageCount = cap.maxImageCount;
1045 
1046  if (cap.currentExtent.width == 0xffffffff)
1047  {
1048  info.imageExtent.width = wd->Width = w;
1049  info.imageExtent.height = wd->Height = h;
1050  }
1051  else
1052  {
1053  info.imageExtent.width = wd->Width = cap.currentExtent.width;
1054  info.imageExtent.height = wd->Height = cap.currentExtent.height;
1055  }
1056  err = vkCreateSwapchainKHR(device, &info, allocator, &wd->Swapchain);
1058  err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, NULL);
1060  VkImage backbuffers[16] = {};
1061  IM_ASSERT(wd->ImageCount >= min_image_count);
1062  IM_ASSERT(wd->ImageCount < IM_ARRAYSIZE(backbuffers));
1063  err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->ImageCount, backbuffers);
1065 
1066  IM_ASSERT(wd->Frames == NULL);
1069  memset(wd->Frames, 0, sizeof(wd->Frames[0]) * wd->ImageCount);
1070  memset(wd->FrameSemaphores, 0, sizeof(wd->FrameSemaphores[0]) * wd->ImageCount);
1071  for (uint32_t i = 0; i < wd->ImageCount; i++)
1072  wd->Frames[i].Backbuffer = backbuffers[i];
1073  }
1074  if (old_swapchain)
1075  vkDestroySwapchainKHR(device, old_swapchain, allocator);
1076 
1077  // Create the Render Pass
1078  {
1079  VkAttachmentDescription attachment = {};
1080  attachment.format = wd->SurfaceFormat.format;
1081  attachment.samples = VK_SAMPLE_COUNT_1_BIT;
1082  attachment.loadOp = wd->ClearEnable ? VK_ATTACHMENT_LOAD_OP_CLEAR : VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1083  attachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
1084  attachment.stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
1085  attachment.stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
1086  attachment.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
1087  attachment.finalLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
1088  VkAttachmentReference color_attachment = {};
1089  color_attachment.attachment = 0;
1090  color_attachment.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
1091  VkSubpassDescription subpass = {};
1092  subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
1093  subpass.colorAttachmentCount = 1;
1094  subpass.pColorAttachments = &color_attachment;
1095  VkSubpassDependency dependency = {};
1096  dependency.srcSubpass = VK_SUBPASS_EXTERNAL;
1097  dependency.dstSubpass = 0;
1098  dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
1099  dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
1100  dependency.srcAccessMask = 0;
1101  dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
1102  VkRenderPassCreateInfo info = {};
1103  info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
1104  info.attachmentCount = 1;
1105  info.pAttachments = &attachment;
1106  info.subpassCount = 1;
1107  info.pSubpasses = &subpass;
1108  info.dependencyCount = 1;
1109  info.pDependencies = &dependency;
1110  err = vkCreateRenderPass(device, &info, allocator, &wd->RenderPass);
1112  }
1113 
1114  // Create The Image Views
1115  {
1116  VkImageViewCreateInfo info = {};
1117  info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
1118  info.viewType = VK_IMAGE_VIEW_TYPE_2D;
1119  info.format = wd->SurfaceFormat.format;
1120  info.components.r = VK_COMPONENT_SWIZZLE_R;
1121  info.components.g = VK_COMPONENT_SWIZZLE_G;
1122  info.components.b = VK_COMPONENT_SWIZZLE_B;
1123  info.components.a = VK_COMPONENT_SWIZZLE_A;
1124  VkImageSubresourceRange image_range = { VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1 };
1125  info.subresourceRange = image_range;
1126  for (uint32_t i = 0; i < wd->ImageCount; i++)
1127  {
1128  ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i];
1129  info.image = fd->Backbuffer;
1130  err = vkCreateImageView(device, &info, allocator, &fd->BackbufferView);
1132  }
1133  }
1134 
1135  // Create Framebuffer
1136  {
1137  VkImageView attachment[1];
1138  VkFramebufferCreateInfo info = {};
1139  info.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
1140  info.renderPass = wd->RenderPass;
1141  info.attachmentCount = 1;
1142  info.pAttachments = attachment;
1143  info.width = wd->Width;
1144  info.height = wd->Height;
1145  info.layers = 1;
1146  for (uint32_t i = 0; i < wd->ImageCount; i++)
1147  {
1148  ImGui_ImplVulkanH_Frame* fd = &wd->Frames[i];
1149  attachment[0] = fd->BackbufferView;
1150  err = vkCreateFramebuffer(device, &info, allocator, &fd->Framebuffer);
1152  }
1153  }
1154 }
1155 
1156 void ImGui_ImplVulkanH_CreateWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int width, int height, uint32_t min_image_count)
1157 {
1158  (void)instance;
1159  ImGui_ImplVulkanH_CreateWindowSwapChain(physical_device, device, wd, allocator, width, height, min_image_count);
1160  ImGui_ImplVulkanH_CreateWindowCommandBuffers(physical_device, device, wd, queue_family, allocator);
1161 }
1162 
1163 void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator)
1164 {
1165  vkDeviceWaitIdle(device); // FIXME: We could wait on the Queue if we had the queue in wd-> (otherwise VulkanH functions can't use globals)
1166  //vkQueueWaitIdle(g_Queue);
1167 
1168  for (uint32_t i = 0; i < wd->ImageCount; i++)
1169  {
1170  ImGui_ImplVulkanH_DestroyFrame(device, &wd->Frames[i], allocator);
1172  }
1173  IM_FREE(wd->Frames);
1174  IM_FREE(wd->FrameSemaphores);
1175  wd->Frames = NULL;
1176  wd->FrameSemaphores = NULL;
1177  vkDestroyRenderPass(device, wd->RenderPass, allocator);
1178  vkDestroySwapchainKHR(device, wd->Swapchain, allocator);
1179  vkDestroySurfaceKHR(instance, wd->Surface, allocator);
1180 
1181  *wd = ImGui_ImplVulkanH_Window();
1182 }
1183 
1184 void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame* fd, const VkAllocationCallbacks* allocator)
1185 {
1186  vkDestroyFence(device, fd->Fence, allocator);
1187  vkFreeCommandBuffers(device, fd->CommandPool, 1, &fd->CommandBuffer);
1188  vkDestroyCommandPool(device, fd->CommandPool, allocator);
1189  fd->Fence = VK_NULL_HANDLE;
1190  fd->CommandBuffer = VK_NULL_HANDLE;
1191  fd->CommandPool = VK_NULL_HANDLE;
1192 
1193  vkDestroyImageView(device, fd->BackbufferView, allocator);
1194  vkDestroyFramebuffer(device, fd->Framebuffer, allocator);
1195 }
1196 
1197 void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores* fsd, const VkAllocationCallbacks* allocator)
1198 {
1199  vkDestroySemaphore(device, fsd->ImageAcquiredSemaphore, allocator);
1200  vkDestroySemaphore(device, fsd->RenderCompleteSemaphore, allocator);
1201  fsd->ImageAcquiredSemaphore = fsd->RenderCompleteSemaphore = VK_NULL_HANDLE;
1202 }
1203 
1204 void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
1205 {
1206  if (buffers->VertexBuffer) { vkDestroyBuffer(device, buffers->VertexBuffer, allocator); buffers->VertexBuffer = VK_NULL_HANDLE; }
1207  if (buffers->VertexBufferMemory) { vkFreeMemory(device, buffers->VertexBufferMemory, allocator); buffers->VertexBufferMemory = VK_NULL_HANDLE; }
1208  if (buffers->IndexBuffer) { vkDestroyBuffer(device, buffers->IndexBuffer, allocator); buffers->IndexBuffer = VK_NULL_HANDLE; }
1209  if (buffers->IndexBufferMemory) { vkFreeMemory(device, buffers->IndexBufferMemory, allocator); buffers->IndexBufferMemory = VK_NULL_HANDLE; }
1210  buffers->VertexBufferSize = 0;
1211  buffers->IndexBufferSize = 0;
1212 }
1213 
1214 void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers* buffers, const VkAllocationCallbacks* allocator)
1215 {
1216  for (uint32_t n = 0; n < buffers->Count; n++)
1217  ImGui_ImplVulkanH_DestroyFrameRenderBuffers(device, &buffers->FrameRenderBuffers[n], allocator);
1218  IM_FREE(buffers->FrameRenderBuffers);
1219  buffers->FrameRenderBuffers = NULL;
1220  buffers->Index = 0;
1221  buffers->Count = 0;
1222 }
ImGui_ImplVulkanH_FrameRenderBuffers::VertexBuffer
VkBuffer VertexBuffer
Definition: imgui_impl_vulkan.cpp:59
ImGui_ImplVulkan_InitInfo::PhysicalDevice
VkPhysicalDevice PhysicalDevice
Definition: imgui_impl_vulkan.h:32
ImGui_ImplVulkanH_Frame::Fence
VkFence Fence
Definition: imgui_impl_vulkan.h:88
ImGui_ImplVulkanH_Frame::CommandBuffer
VkCommandBuffer CommandBuffer
Definition: imgui_impl_vulkan.h:87
ImDrawData::FramebufferScale
ImVec2 FramebufferScale
Definition: imgui.h:2077
ImGui_ImplVulkan_InitInfo::MinImageCount
uint32_t MinImageCount
Definition: imgui_impl_vulkan.h:38
ImGui_ImplVulkan_InitInfo
Definition: imgui_impl_vulkan.h:29
ImGui_ImplVulkanH_SelectPresentMode
VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR *request_modes, int request_modes_count)
Definition: imgui_impl_vulkan.cpp:914
ImDrawIdx
unsigned short ImDrawIdx
Definition: imgui.h:1888
height
GLint GLsizei GLsizei height
Definition: glcorearb.h:2768
ImGui_ImplVulkan_SetMinImageCount
void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count)
Definition: imgui_impl_vulkan.cpp:840
ImDrawCmd::VtxOffset
unsigned int VtxOffset
Definition: imgui.h:1876
ImDrawData::DisplayPos
ImVec2 DisplayPos
Definition: imgui.h:2075
ImGuiIO::Fonts
ImFontAtlas * Fonts
Definition: imgui.h:1435
ImDrawList::IdxBuffer
ImVector< ImDrawIdx > IdxBuffer
Definition: imgui.h:1965
ImGui_ImplVulkanH_Window::ClearEnable
bool ClearEnable
Definition: imgui_impl_vulkan.h:111
ImGui_ImplVulkanH_CreateWindowCommandBuffers
void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window *wd, uint32_t queue_family, const VkAllocationCallbacks *allocator)
Definition: imgui_impl_vulkan.cpp:936
ImGui_ImplVulkan_Init
bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo *info, VkRenderPass render_pass)
Definition: imgui_impl_vulkan.cpp:808
ImGui_ImplVulkan_CreateFontsTexture
bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
Definition: imgui_impl_vulkan.cpp:435
ImDrawData::CmdListsCount
int CmdListsCount
Definition: imgui.h:2072
ImGui_ImplVulkanH_SelectSurfaceFormat
VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat *request_formats, int request_formats_count, VkColorSpaceKHR request_color_space)
Definition: imgui_impl_vulkan.cpp:870
g_RenderPass
static VkRenderPass g_RenderPass
Definition: imgui_impl_vulkan.cpp:74
NULL
NULL
Definition: test_security_zap.cpp:405
ImVec4::z
float z
Definition: imgui.h:223
ImGui_ImplVulkanH_Frame::BackbufferView
VkImageView BackbufferView
Definition: imgui_impl_vulkan.h:90
ImGui_ImplVulkanH_GetMinImageCountFromPresentMode
int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode)
Definition: imgui_impl_vulkan.cpp:983
ImGui_ImplVulkan_NewFrame
void ImGui_ImplVulkan_NewFrame()
Definition: imgui_impl_vulkan.cpp:836
ImDrawData::CmdLists
ImDrawList ** CmdLists
Definition: imgui.h:2071
g_FontMemory
static VkDeviceMemory g_FontMemory
Definition: imgui_impl_vulkan.cpp:84
ImGui_ImplVulkanH_FrameRenderBuffers::IndexBufferMemory
VkDeviceMemory IndexBufferMemory
Definition: imgui_impl_vulkan.cpp:56
g_PipelineCreateFlags
static VkPipelineCreateFlags g_PipelineCreateFlags
Definition: imgui_impl_vulkan.cpp:76
ImGui_ImplVulkanH_WindowRenderBuffers::Count
uint32_t Count
Definition: imgui_impl_vulkan.cpp:68
ImDrawList
Definition: imgui.h:1961
ImTextureID
void * ImTextureID
Definition: imgui.h:172
imgui_impl_vulkan.h
ImGui_ImplVulkanH_FrameSemaphores
Definition: imgui_impl_vulkan.h:94
g_UploadBuffer
static VkBuffer g_UploadBuffer
Definition: imgui_impl_vulkan.cpp:88
imgui.h
ImGui_ImplVulkanH_DestroyFrame
void ImGui_ImplVulkanH_DestroyFrame(VkDevice device, ImGui_ImplVulkanH_Frame *fd, const VkAllocationCallbacks *allocator)
Definition: imgui_impl_vulkan.cpp:1184
ImVector
Definition: imgui.h:1301
ImGui_ImplVulkan_InitInfo::DescriptorPool
VkDescriptorPool DescriptorPool
Definition: imgui_impl_vulkan.h:37
ImGui_ImplVulkanH_Window::Surface
VkSurfaceKHR Surface
Definition: imgui_impl_vulkan.h:107
ImGui_ImplVulkanH_FrameSemaphores::RenderCompleteSemaphore
VkSemaphore RenderCompleteSemaphore
Definition: imgui_impl_vulkan.h:97
map
zval * map
Definition: php/ext/google/protobuf/encode_decode.c:473
ImVec2
Definition: imgui.h:208
ImGui::GetIO
IMGUI_API ImGuiIO & GetIO()
Definition: imgui.cpp:3286
ImDrawList::CmdBuffer
ImVector< ImDrawCmd > CmdBuffer
Definition: imgui.h:1964
ImDrawCmd
Definition: imgui.h:1871
g_VulkanInitInfo
static ImGui_ImplVulkan_InitInfo g_VulkanInitInfo
Definition: imgui_impl_vulkan.cpp:73
ImDrawCmd::UserCallback
ImDrawCallback UserCallback
Definition: imgui.h:1878
ImGui_ImplVulkanH_Window
Definition: imgui_impl_vulkan.h:102
ImGui_ImplVulkan_RenderDrawData
void ImGui_ImplVulkan_RenderDrawData(ImDrawData *draw_data, VkCommandBuffer command_buffer)
Definition: imgui_impl_vulkan.cpp:312
range
GLenum GLint * range
Definition: glcorearb.h:3963
check_vk_result
static void check_vk_result(VkResult err)
Definition: imgui_impl_vulkan.cpp:227
ImGui_ImplVulkanH_CreateWindowSwapChain
void ImGui_ImplVulkanH_CreateWindowSwapChain(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window *wd, const VkAllocationCallbacks *allocator, int w, int h, uint32_t min_image_count)
Definition: imgui_impl_vulkan.cpp:996
ImVec4::y
float y
Definition: imgui.h:223
g_FontView
static VkImageView g_FontView
Definition: imgui_impl_vulkan.cpp:86
ImGui_ImplVulkanH_FrameRenderBuffers
Definition: imgui_impl_vulkan.cpp:53
ImGui_ImplVulkanH_Window::Height
int Height
Definition: imgui_impl_vulkan.h:105
ImVector::Data
T * Data
Definition: imgui.h:1305
g_FontImage
static VkImage g_FontImage
Definition: imgui_impl_vulkan.cpp:85
CreateOrResizeBuffer
static void CreateOrResizeBuffer(VkBuffer &buffer, VkDeviceMemory &buffer_memory, VkDeviceSize &p_buffer_size, size_t new_size, VkBufferUsageFlagBits usage)
Definition: imgui_impl_vulkan.cpp:234
ImGui_ImplVulkan_DestroyFontUploadObjects
void ImGui_ImplVulkan_DestroyFontUploadObjects()
Definition: imgui_impl_vulkan.cpp:778
ImGui_ImplVulkanH_Window::RenderPass
VkRenderPass RenderPass
Definition: imgui_impl_vulkan.h:110
ImGui_ImplVulkanH_FrameRenderBuffers::IndexBuffer
VkBuffer IndexBuffer
Definition: imgui_impl_vulkan.cpp:60
g_BufferMemoryAlignment
static VkDeviceSize g_BufferMemoryAlignment
Definition: imgui_impl_vulkan.cpp:75
format
GLint GLint GLsizei GLint GLenum format
Definition: glcorearb.h:2773
ImDrawData
Definition: imgui.h:2068
ImVector::Size
int Size
Definition: imgui.h:1303
ImDrawVert
Definition: imgui.h:1893
ImVec2::x
float x
Definition: imgui.h:210
ImDrawCmd::ClipRect
ImVec4 ClipRect
Definition: imgui.h:1874
ImGui_ImplVulkanH_FrameRenderBuffers::VertexBufferSize
VkDeviceSize VertexBufferSize
Definition: imgui_impl_vulkan.cpp:57
ImGui_ImplVulkanH_WindowRenderBuffers::FrameRenderBuffers
ImGui_ImplVulkanH_FrameRenderBuffers * FrameRenderBuffers
Definition: imgui_impl_vulkan.cpp:69
ImGui_ImplVulkanH_FrameRenderBuffers::IndexBufferSize
VkDeviceSize IndexBufferSize
Definition: imgui_impl_vulkan.cpp:58
IM_ALLOC
#define IM_ALLOC(_SIZE)
Definition: imgui.h:1283
IM_OFFSETOF
#define IM_OFFSETOF(_TYPE, _MEMBER)
Definition: imgui.h:93
err
static UPB_NORETURN void err(tarjan *t)
Definition: ruby/ext/google/protobuf_c/upb.c:5856
IM_ARRAYSIZE
#define IM_ARRAYSIZE(_ARR)
Definition: imgui.h:88
ImGui_ImplVulkanH_Window::FrameSemaphores
ImGui_ImplVulkanH_FrameSemaphores * FrameSemaphores
Definition: imgui_impl_vulkan.h:117
buffer
Definition: buffer_processor.h:43
ImDrawData::TotalVtxCount
int TotalVtxCount
Definition: imgui.h:2074
ImVec4::x
float x
Definition: imgui.h:223
ImGuiBackendFlags_RendererHasVtxOffset
@ ImGuiBackendFlags_RendererHasVtxOffset
Definition: imgui.h:1080
ImGui_ImplVulkanH_Window::SurfaceFormat
VkSurfaceFormatKHR SurfaceFormat
Definition: imgui_impl_vulkan.h:108
g_MainWindowRenderBuffers
static ImGui_ImplVulkanH_WindowRenderBuffers g_MainWindowRenderBuffers
Definition: imgui_impl_vulkan.cpp:91
g_Pipeline
static VkPipeline g_Pipeline
Definition: imgui_impl_vulkan.cpp:80
void
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
n
GLdouble n
Definition: glcorearb.h:4153
ImGui_ImplVulkan_InitInfo::CheckVkResultFn
void(* CheckVkResultFn)(VkResult err)
Definition: imgui_impl_vulkan.h:42
ImDrawList::VtxBuffer
ImVector< ImDrawVert > VtxBuffer
Definition: imgui.h:1966
i
int i
Definition: gmock-matchers_test.cc:764
ImGui_ImplVulkanH_Window::Swapchain
VkSwapchainKHR Swapchain
Definition: imgui_impl_vulkan.h:106
g_DescriptorSet
static VkDescriptorSet g_DescriptorSet
Definition: imgui_impl_vulkan.cpp:79
req
void * req
Definition: test_req_relaxed.cpp:10
g_DescriptorSetLayout
static VkDescriptorSetLayout g_DescriptorSetLayout
Definition: imgui_impl_vulkan.cpp:77
v
const GLdouble * v
Definition: glcorearb.h:3106
__glsl_shader_vert_spv
static uint32_t __glsl_shader_vert_spv[]
Definition: imgui_impl_vulkan.cpp:126
g_PipelineLayout
static VkPipelineLayout g_PipelineLayout
Definition: imgui_impl_vulkan.cpp:78
attachment
GLenum attachment
Definition: glcorearb.h:3319
ImGui_ImplVulkan_InitInfo::Device
VkDevice Device
Definition: imgui_impl_vulkan.h:33
ImGui_ImplVulkan_MemoryType
static uint32_t ImGui_ImplVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits)
Definition: imgui_impl_vulkan.cpp:216
ImGui_ImplVulkan_SetupRenderState
static void ImGui_ImplVulkan_SetupRenderState(ImDrawData *draw_data, VkCommandBuffer command_buffer, ImGui_ImplVulkanH_FrameRenderBuffers *rb, int fb_width, int fb_height)
Definition: imgui_impl_vulkan.cpp:267
ImGui_ImplVulkanH_Window::Width
int Width
Definition: imgui_impl_vulkan.h:104
ImVector::resize
void resize(int new_size)
Definition: imgui.h:1337
sampler
GLuint sampler
Definition: glcorearb.h:3707
ImGui_ImplVulkanH_Frame::Framebuffer
VkFramebuffer Framebuffer
Definition: imgui_impl_vulkan.h:91
usage
GLsizeiptr const GLvoid GLenum usage
Definition: glcorearb.h:2943
ImVec4::w
float w
Definition: imgui.h:223
ImGui_ImplVulkanH_Frame::CommandPool
VkCommandPool CommandPool
Definition: imgui_impl_vulkan.h:86
ImDrawCallback_ResetRenderState
#define ImDrawCallback_ResetRenderState
Definition: imgui.h:1866
ImGuiIO::BackendRendererName
const char * BackendRendererName
Definition: imgui.h:1456
ImGui_ImplVulkanH_WindowRenderBuffers::Index
uint32_t Index
Definition: imgui_impl_vulkan.cpp:67
ImGui_ImplVulkanH_Window::Frames
ImGui_ImplVulkanH_Frame * Frames
Definition: imgui_impl_vulkan.h:116
ImGui_ImplVulkanH_Window::ImageCount
uint32_t ImageCount
Definition: imgui_impl_vulkan.h:114
ImGuiIO
Definition: imgui.h:1414
ImDrawData::TotalIdxCount
int TotalIdxCount
Definition: imgui.h:2073
ImVec4
Definition: imgui.h:221
ImGui_ImplVulkanH_DestroyWindow
void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window *wd, const VkAllocationCallbacks *allocator)
Definition: imgui_impl_vulkan.cpp:1163
IM_ASSERT
#define IM_ASSERT(_EXPR)
Definition: imgui.h:79
ImGui_ImplVulkan_Shutdown
void ImGui_ImplVulkan_Shutdown()
Definition: imgui_impl_vulkan.cpp:831
ImGui_ImplVulkanH_FrameRenderBuffers::VertexBufferMemory
VkDeviceMemory VertexBufferMemory
Definition: imgui_impl_vulkan.cpp:55
ImDrawData::DisplaySize
ImVec2 DisplaySize
Definition: imgui.h:2076
ImGui_ImplVulkan_InitInfo::Queue
VkQueue Queue
Definition: imgui_impl_vulkan.h:35
ImDrawCmd::IdxOffset
unsigned int IdxOffset
Definition: imgui.h:1877
ImGui_ImplVulkan_CreateDeviceObjects
bool ImGui_ImplVulkan_CreateDeviceObjects()
Definition: imgui_impl_vulkan.cpp:587
ImGui_ImplVulkanH_Window::PresentMode
VkPresentModeKHR PresentMode
Definition: imgui_impl_vulkan.h:109
pixels
GLint GLint GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: glcorearb.h:2773
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:3126
IM_FREE
#define IM_FREE(_PTR)
Definition: imgui.h:1284
ImGui_ImplVulkanH_WindowRenderBuffers
Definition: imgui_impl_vulkan.cpp:65
buffers
const GLuint * buffers
Definition: glcorearb.h:2940
ImGui_ImplVulkan_InitInfo::Instance
VkInstance Instance
Definition: imgui_impl_vulkan.h:31
ImGui_ImplVulkanH_CreateWindow
void ImGui_ImplVulkanH_CreateWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window *wd, uint32_t queue_family, const VkAllocationCallbacks *allocator, int width, int height, uint32_t min_image_count)
Definition: imgui_impl_vulkan.cpp:1156
g_FontSampler
static VkSampler g_FontSampler
Definition: imgui_impl_vulkan.cpp:83
ImGuiIO::BackendFlags
ImGuiBackendFlags BackendFlags
Definition: imgui.h:1421
ImGui_ImplVulkan_InitInfo::ImageCount
uint32_t ImageCount
Definition: imgui_impl_vulkan.h:39
g_UploadBufferMemory
static VkDeviceMemory g_UploadBufferMemory
Definition: imgui_impl_vulkan.cpp:87
ImGui_ImplVulkanH_DestroyFrameSemaphores
void ImGui_ImplVulkanH_DestroyFrameSemaphores(VkDevice device, ImGui_ImplVulkanH_FrameSemaphores *fsd, const VkAllocationCallbacks *allocator)
Definition: imgui_impl_vulkan.cpp:1197
ImGui_ImplVulkan_DestroyDeviceObjects
void ImGui_ImplVulkan_DestroyDeviceObjects()
Definition: imgui_impl_vulkan.cpp:793
h
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:4147
ImVec2::y
float y
Definition: imgui.h:210
width
GLint GLsizei width
Definition: glcorearb.h:2768
__glsl_shader_frag_spv
static uint32_t __glsl_shader_frag_spv[]
Definition: imgui_impl_vulkan.cpp:183
ImGui_ImplVulkanH_FrameSemaphores::ImageAcquiredSemaphore
VkSemaphore ImageAcquiredSemaphore
Definition: imgui_impl_vulkan.h:96
ImGui_ImplVulkanH_Frame::Backbuffer
VkImage Backbuffer
Definition: imgui_impl_vulkan.h:89
ImDrawCmd::ElemCount
unsigned int ElemCount
Definition: imgui.h:1873
ImGui_ImplVulkanH_DestroyWindowRenderBuffers
void ImGui_ImplVulkanH_DestroyWindowRenderBuffers(VkDevice device, ImGui_ImplVulkanH_WindowRenderBuffers *buffers, const VkAllocationCallbacks *allocator)
Definition: imgui_impl_vulkan.cpp:1214
ImGui_ImplVulkanH_DestroyFrameRenderBuffers
void ImGui_ImplVulkanH_DestroyFrameRenderBuffers(VkDevice device, ImGui_ImplVulkanH_FrameRenderBuffers *buffers, const VkAllocationCallbacks *allocator)
Definition: imgui_impl_vulkan.cpp:1204
ImFontAtlas::GetTexDataAsRGBA32
IMGUI_API void GetTexDataAsRGBA32(unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel=NULL)
Definition: imgui_draw.cpp:1679
ImGui_ImplVulkanH_Frame
Definition: imgui_impl_vulkan.h:84


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:54