Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
imgui_impl_vulkan.h
1// dear imgui: Renderer Backend for Vulkan
2// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
3
4// Implemented features:
5// [x] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions.
6// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.
7// [x] Renderer: Multi-viewport / platform windows. With issues (flickering when creating a new viewport).
8
9// Important: on 32-bit systems, user texture binding is only supported if your imconfig file has '#define ImTextureID ImU64'.
10// See imgui_impl_vulkan.cpp file for details.
11
12// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
13// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
14
15// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
16// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
17// Learn about Dear ImGui:
18// - FAQ https://dearimgui.com/faq
19// - Getting Started https://dearimgui.com/getting-started
20// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
21// - Introduction, links and more at the top of imgui.cpp
22
23// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
24// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
25// You will use those if you want to use this rendering backend in your engine/app.
26// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
27// the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
28// Read comments in imgui_impl_vulkan.h.
29
30#pragma once
31#ifndef IMGUI_DISABLE
32#include "imgui.h" // IMGUI_IMPL_API
33
34// [Configuration] in order to use a custom Vulkan function loader:
35// (1) You'll need to disable default Vulkan function prototypes.
36// We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag.
37// In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit:
38// - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file
39// - Or as a compilation flag in your build system
40// - Or uncomment here (not recommended because you'd be modifying imgui sources!)
41// - Do not simply add it in a .cpp file!
42// (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function.
43// If you have no idea what this is, leave it alone!
44//#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES
45
46// Convenience support for Volk
47// (you can also technically use IMGUI_IMPL_VULKAN_NO_PROTOTYPES + wrap Volk via ImGui_ImplVulkan_LoadFunctions().)
48//#define IMGUI_IMPL_VULKAN_USE_VOLK
49
50#if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES)
51#define VK_NO_PROTOTYPES
52#endif
53#if defined(VK_USE_PLATFORM_WIN32_KHR) && !defined(NOMINMAX)
54#define NOMINMAX
55#endif
56
57// Vulkan includes
58#ifdef IMGUI_IMPL_VULKAN_USE_VOLK
59#include <volk.h>
60#else
61#include <vulkan/vulkan.h>
62#endif
63#if defined(VK_VERSION_1_3) || defined(VK_KHR_dynamic_rendering)
64#define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
65#endif
66
67// Initialization data, for ImGui_ImplVulkan_Init()
68// - VkDescriptorPool should be created with VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
69// and must contain a pool size large enough to hold an ImGui VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptor.
70// - When using dynamic rendering, set UseDynamicRendering=true and fill PipelineRenderingCreateInfo structure.
71// [Please zero-clear before use!]
73{
74 VkInstance Instance;
75 VkPhysicalDevice PhysicalDevice;
76 VkDevice Device;
77 uint32_t QueueFamily;
78 VkQueue Queue;
79 VkDescriptorPool DescriptorPool; // See requirements in note above
80 VkRenderPass RenderPass; // Ignored if using dynamic rendering
81 uint32_t MinImageCount; // >= 2
82 uint32_t ImageCount; // >= MinImageCount
83 VkSampleCountFlagBits MSAASamples; // 0 defaults to VK_SAMPLE_COUNT_1_BIT
84
85 // (Optional)
86 VkPipelineCache PipelineCache;
87 uint32_t Subpass;
88
89 // (Optional) Dynamic Rendering
90 // Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3.
92#ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING
93 VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo;
94#endif
95
96 // (Optional) Allocation, Debugging
97 const VkAllocationCallbacks* Allocator;
98 void (*CheckVkResultFn)(VkResult err);
99 VkDeviceSize MinAllocationSize; // Minimum allocation size. Set to 1024*1024 to satisfy zealous best practices validation layer and waste a little memory.
100};
101
102// Called by user code
103IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info);
104IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
105IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
106IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE);
107IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture();
108IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontsTexture();
109IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
110
111// Register a texture (VkDescriptorSet == ImTextureID)
112// FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem
113// Please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions.
114IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout);
115IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set);
116
117// Optional: load Vulkan functions with a custom function loader
118// This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES
119IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr);
120
121//-------------------------------------------------------------------------
122// Internal / Miscellaneous Vulkan Helpers
123// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.)
124//-------------------------------------------------------------------------
125// You probably do NOT need to use or care about those functions.
126// Those functions only exist because:
127// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
128// 2) the multi-viewport / platform window implementation needs them internally.
129// Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
130// but it is too much code to duplicate everywhere so we exceptionally expose them.
131//
132// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
133// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
134// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
135//-------------------------------------------------------------------------
136
139
140// Helpers
141IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count);
142IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wd, const VkAllocationCallbacks* allocator);
143IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
144IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
145IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
146
147// Helper structure to hold the data needed by one rendering frame
148// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
149// [Please zero-clear before use!]
151{
152 VkCommandPool CommandPool;
153 VkCommandBuffer CommandBuffer;
154 VkFence Fence;
155 VkImage Backbuffer;
156 VkImageView BackbufferView;
157 VkFramebuffer Framebuffer;
158};
159
165
166// Helper structure to hold the data needed by one rendering context into one OS window
167// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
169{
170 int Width;
172 VkSwapchainKHR Swapchain;
173 VkSurfaceKHR Surface;
174 VkSurfaceFormatKHR SurfaceFormat;
175 VkPresentModeKHR PresentMode;
176 VkRenderPass RenderPass;
179 VkClearValue ClearValue;
180 uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
181 uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
182 uint32_t SemaphoreCount; // Number of simultaneous in-flight frames + 1, to be able to use it in vkAcquireNextImageKHR
183 uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
186
188 {
189 memset((void*)this, 0, sizeof(*this));
190 PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this.
191 ClearEnable = true;
192 }
193};
194
195#endif // #ifndef IMGUI_DISABLE
Definition imgui.h:3269
Definition imgui_impl_vulkan.h:161
VkSemaphore RenderCompleteSemaphore
Definition imgui_impl_vulkan.h:163
VkSemaphore ImageAcquiredSemaphore
Definition imgui_impl_vulkan.h:162
Definition imgui_impl_vulkan.h:151
VkCommandBuffer CommandBuffer
Definition imgui_impl_vulkan.h:153
VkFramebuffer Framebuffer
Definition imgui_impl_vulkan.h:157
VkFence Fence
Definition imgui_impl_vulkan.h:154
VkCommandPool CommandPool
Definition imgui_impl_vulkan.h:152
VkImageView BackbufferView
Definition imgui_impl_vulkan.h:156
VkImage Backbuffer
Definition imgui_impl_vulkan.h:155
Definition imgui_impl_vulkan.h:169
bool ClearEnable
Definition imgui_impl_vulkan.h:178
VkSurfaceKHR Surface
Definition imgui_impl_vulkan.h:173
uint32_t SemaphoreIndex
Definition imgui_impl_vulkan.h:183
ImGui_ImplVulkanH_Window()
Definition imgui_impl_vulkan.h:187
uint32_t SemaphoreCount
Definition imgui_impl_vulkan.h:182
VkSwapchainKHR Swapchain
Definition imgui_impl_vulkan.h:172
ImGui_ImplVulkanH_Frame * Frames
Definition imgui_impl_vulkan.h:184
uint32_t FrameIndex
Definition imgui_impl_vulkan.h:180
int Height
Definition imgui_impl_vulkan.h:171
ImGui_ImplVulkanH_FrameSemaphores * FrameSemaphores
Definition imgui_impl_vulkan.h:185
VkSurfaceFormatKHR SurfaceFormat
Definition imgui_impl_vulkan.h:174
VkRenderPass RenderPass
Definition imgui_impl_vulkan.h:176
bool UseDynamicRendering
Definition imgui_impl_vulkan.h:177
VkPresentModeKHR PresentMode
Definition imgui_impl_vulkan.h:175
int Width
Definition imgui_impl_vulkan.h:170
uint32_t ImageCount
Definition imgui_impl_vulkan.h:181
VkClearValue ClearValue
Definition imgui_impl_vulkan.h:179
Definition imgui_impl_vulkan.h:73
VkSampleCountFlagBits MSAASamples
Definition imgui_impl_vulkan.h:83
bool UseDynamicRendering
Definition imgui_impl_vulkan.h:91
uint32_t Subpass
Definition imgui_impl_vulkan.h:87
const VkAllocationCallbacks * Allocator
Definition imgui_impl_vulkan.h:97
VkDeviceSize MinAllocationSize
Definition imgui_impl_vulkan.h:99
VkQueue Queue
Definition imgui_impl_vulkan.h:78
VkPhysicalDevice PhysicalDevice
Definition imgui_impl_vulkan.h:75
void(* CheckVkResultFn)(VkResult err)
Definition imgui_impl_vulkan.h:98
uint32_t QueueFamily
Definition imgui_impl_vulkan.h:77
VkInstance Instance
Definition imgui_impl_vulkan.h:74
VkDescriptorPool DescriptorPool
Definition imgui_impl_vulkan.h:79
VkDevice Device
Definition imgui_impl_vulkan.h:76
VkRenderPass RenderPass
Definition imgui_impl_vulkan.h:80
uint32_t ImageCount
Definition imgui_impl_vulkan.h:82
VkPipelineCache PipelineCache
Definition imgui_impl_vulkan.h:86
uint32_t MinImageCount
Definition imgui_impl_vulkan.h:81
Untitled