|
@@ -720,3 +720,73 @@ void ImGui_ImplVulkan_Render(VkCommandBuffer command_buffer)
|
|
|
g_CommandBuffer = VK_NULL_HANDLE;
|
|
|
g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES;
|
|
|
}
|
|
|
+
|
|
|
+//-------------------------------------------------------------------------
|
|
|
+// Miscellaneous Vulkan Helpers
|
|
|
+// (Those are currently not strictly needed by the binding, but will be once if we support multi-viewports)
|
|
|
+//-------------------------------------------------------------------------
|
|
|
+
|
|
|
+#include <stdlib.h> // malloc
|
|
|
+
|
|
|
+VkSurfaceFormatKHR ImGui_ImplVulkan_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space)
|
|
|
+{
|
|
|
+ IM_ASSERT(request_formats != NULL);
|
|
|
+ IM_ASSERT(request_formats_count > 0);
|
|
|
+
|
|
|
+ // Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation
|
|
|
+ // Assuming that the default behavior is without setting this bit, there is no need for separate Swapchain image and image view format
|
|
|
+ // Additionally several new color spaces were introduced with Vulkan Spec v1.0.40,
|
|
|
+ // hence we must make sure that a format with the mostly available color space, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, is found and used.
|
|
|
+ uint32_t avail_count;
|
|
|
+ vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, NULL);
|
|
|
+ ImVector<VkSurfaceFormatKHR> avail_format;
|
|
|
+ avail_format.resize((int)avail_count);
|
|
|
+ vkGetPhysicalDeviceSurfaceFormatsKHR(physical_device, surface, &avail_count, avail_format.Data);
|
|
|
+
|
|
|
+ // First check if only one format, VK_FORMAT_UNDEFINED, is available, which would imply that any format is available
|
|
|
+ if (avail_count == 1)
|
|
|
+ {
|
|
|
+ if (avail_format[0].format == VK_FORMAT_UNDEFINED)
|
|
|
+ {
|
|
|
+ VkSurfaceFormatKHR ret;
|
|
|
+ ret.format = request_formats[0];
|
|
|
+ ret.colorSpace = request_color_space;
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // No point in searching another format
|
|
|
+ return avail_format[0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Request several formats, the first found will be used
|
|
|
+ for (int request_i = 0; request_i < request_formats_count; request_i++)
|
|
|
+ for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++)
|
|
|
+ if (avail_format[avail_i].format == request_formats[request_i] && avail_format[avail_i].colorSpace == request_color_space)
|
|
|
+ return avail_format[avail_i];
|
|
|
+
|
|
|
+ // If none of the requested image formats could be found, use the first available
|
|
|
+ return avail_format[0];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+VkPresentModeKHR ImGui_ImplVulkan_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count)
|
|
|
+{
|
|
|
+ IM_ASSERT(request_modes != NULL);
|
|
|
+ IM_ASSERT(request_modes_count > 0);
|
|
|
+
|
|
|
+ // Request a certain mode and confirm that it is available. If not use VK_PRESENT_MODE_FIFO_KHR which is mandatory
|
|
|
+ uint32_t avail_count = 0;
|
|
|
+ vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, NULL);
|
|
|
+ ImVector<VkPresentModeKHR> avail_modes;
|
|
|
+ avail_modes.resize((int)avail_count);
|
|
|
+ vkGetPhysicalDeviceSurfacePresentModesKHR(physical_device, surface, &avail_count, avail_modes.Data);
|
|
|
+ for (int request_i = 0; request_i < request_modes_count; request_i++)
|
|
|
+ for (uint32_t avail_i = 0; avail_i < avail_count; avail_i++)
|
|
|
+ if (request_modes[request_i] == avail_modes[avail_i])
|
|
|
+ return request_modes[request_i];
|
|
|
+
|
|
|
+ return VK_PRESENT_MODE_FIFO_KHR; // Always available
|
|
|
+}
|