From 995f92a456717a435d4e1b44f93128d6aa4ee2ea Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 12 Apr 2023 21:07:28 +0200 Subject: [PATCH 1/4] Nav: Made PageUp/PageDown/Home/End navigation also scroll parent windows. + Added ImGuiDebugLogFlags_EventSelection unused in this branch. --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 15 ++++++--------- imgui_internal.h | 6 ++++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index a86418cd..264f060d 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -51,6 +51,8 @@ Other changes: in the format string. (#6259) [@idbrii] - Nav: Made Ctrl+Tab/Ctrl+Shift+Tab windowing register ownership to held modifier so it doesn't interfere with other code when remapping those actions. (#4828, #3255, #5641) +- Nav: Made PageUp/PageDown/Home/End navigation also scroll parent windows when + necessary to make the target location fully visible (same as e.g. arrow keys). - ColorEdit: Fixed shading of S/V triangle in Hue Wheel mode. (#5200, #6254) [@jamesthomasgriffin] - TabBar: Tab-bars with ImGuiTabBarFlags_FittingPolicyScroll can be scrolled with horizontal mouse-wheel (or Shift + WheelY). (#2702) diff --git a/imgui.cpp b/imgui.cpp index e15a9348..4006a777 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -11515,17 +11515,15 @@ void ImGui::NavMoveRequestApplyResult() // Scroll to keep newly navigated item fully into view. if (g.NavLayer == ImGuiNavLayer_Main) { + ImRect rect_abs = WindowRectRelToAbs(result->Window, result->RectRel); + ScrollToRectEx(result->Window, rect_abs, g.NavMoveScrollFlags); + if (g.NavMoveFlags & ImGuiNavMoveFlags_ScrollToEdgeY) { - // FIXME: Should remove this + // FIXME: Should remove this? Or make more precise: use ScrollToRectEx() with edge? float scroll_target = (g.NavMoveDir == ImGuiDir_Up) ? result->Window->ScrollMax.y : 0.0f; SetScrollY(result->Window, scroll_target); } - else - { - ImRect rect_abs = WindowRectRelToAbs(result->Window, result->RectRel); - ScrollToRectEx(result->Window, rect_abs, g.NavMoveScrollFlags); - } } if (g.NavWindow != result->Window) @@ -14359,14 +14357,13 @@ void ImGui::ShowDebugLogWindow(bool* p_open) return; } - AlignTextToFramePadding(); - Text("Log events:"); - SameLine(); CheckboxFlags("All", &g.DebugLogFlags, ImGuiDebugLogFlags_EventMask_); + CheckboxFlags("All", &g.DebugLogFlags, ImGuiDebugLogFlags_EventMask_); SameLine(); CheckboxFlags("ActiveId", &g.DebugLogFlags, ImGuiDebugLogFlags_EventActiveId); SameLine(); CheckboxFlags("Focus", &g.DebugLogFlags, ImGuiDebugLogFlags_EventFocus); SameLine(); CheckboxFlags("Popup", &g.DebugLogFlags, ImGuiDebugLogFlags_EventPopup); SameLine(); CheckboxFlags("Nav", &g.DebugLogFlags, ImGuiDebugLogFlags_EventNav); SameLine(); if (CheckboxFlags("Clipper", &g.DebugLogFlags, ImGuiDebugLogFlags_EventClipper)) { g.DebugLogClipperAutoDisableFrames = 2; } if (IsItemHovered()) SetTooltip("Clipper log auto-disabled after 2 frames"); + //SameLine(); CheckboxFlags("Selection", &g.DebugLogFlags, ImGuiDebugLogFlags_EventSelection); SameLine(); CheckboxFlags("IO", &g.DebugLogFlags, ImGuiDebugLogFlags_EventIO); if (SmallButton("Clear")) diff --git a/imgui_internal.h b/imgui_internal.h index cd1c1e8b..ab9d81c8 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -230,6 +230,7 @@ namespace ImStb #define IMGUI_DEBUG_LOG_FOCUS(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventFocus) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) #define IMGUI_DEBUG_LOG_POPUP(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventPopup) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) #define IMGUI_DEBUG_LOG_NAV(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventNav) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) +#define IMGUI_DEBUG_LOG_SELECTION(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventSelection)IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) #define IMGUI_DEBUG_LOG_CLIPPER(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventClipper) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) #define IMGUI_DEBUG_LOG_IO(...) do { if (g.DebugLogFlags & ImGuiDebugLogFlags_EventIO) IMGUI_DEBUG_LOG(__VA_ARGS__); } while (0) @@ -1670,8 +1671,9 @@ enum ImGuiDebugLogFlags_ ImGuiDebugLogFlags_EventPopup = 1 << 2, ImGuiDebugLogFlags_EventNav = 1 << 3, ImGuiDebugLogFlags_EventClipper = 1 << 4, - ImGuiDebugLogFlags_EventIO = 1 << 5, - ImGuiDebugLogFlags_EventMask_ = ImGuiDebugLogFlags_EventActiveId | ImGuiDebugLogFlags_EventFocus | ImGuiDebugLogFlags_EventPopup | ImGuiDebugLogFlags_EventNav | ImGuiDebugLogFlags_EventClipper | ImGuiDebugLogFlags_EventIO, + ImGuiDebugLogFlags_EventSelection = 1 << 5, + ImGuiDebugLogFlags_EventIO = 1 << 6, + ImGuiDebugLogFlags_EventMask_ = ImGuiDebugLogFlags_EventActiveId | ImGuiDebugLogFlags_EventFocus | ImGuiDebugLogFlags_EventPopup | ImGuiDebugLogFlags_EventNav | ImGuiDebugLogFlags_EventClipper | ImGuiDebugLogFlags_EventSelection | ImGuiDebugLogFlags_EventIO, ImGuiDebugLogFlags_OutputToTTY = 1 << 10, // Also send output to TTY }; From 6324280432dc56fda9175ea3962484ee93a0ec53 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 13 Apr 2023 13:39:28 +0200 Subject: [PATCH 2/4] Examples: Vulkan: rework extensions setup + enable some to avoid validation layer errors. (#6109, #6172, #6101) Enable VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME, VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR --- docs/CHANGELOG.txt | 3 ++ examples/example_glfw_vulkan/main.cpp | 64 +++++++++++++++++--------- examples/example_sdl2_vulkan/main.cpp | 65 +++++++++++++++++---------- 3 files changed, 86 insertions(+), 46 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 264f060d..56d43d9b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -94,6 +94,9 @@ Other changes: (#6314) [@PathogenDavid] - Backends: WebGPU: Align buffers. Use WGSL shaders instead of SPIR-V. Add gamma uniform. (#6188) [@eliemichel] - Backends: WebGPU: Reorganized to store data in io.BackendRendererUserData like other backends. +- Examples: Vulkan: Fixed validation errors with newer VulkanSDK by explicitely querying and enabling + "VK_KHR_get_physical_device_properties2", "VK_KHR_portability_enumeration", and + VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR. (#6109, #6172, #6101) - Examples: Windows: Added 'misc/debuggers/imgui.natstepfilter' file to all Visual Studio projects, now that VS 2022 17.6 Preview 2 support adding Debug Step Filter spec files into projects. - Examples: SDL3: Updated for latest WIP SDL3 branch. (#6243) diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index f5f7f49d..d3213919 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -68,7 +68,15 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(VkDebugReportFlagsEXT flags, } #endif // IMGUI_VULKAN_DEBUG_REPORT -static void SetupVulkan(const char** extensions, uint32_t extensions_count) +static bool IsExtensionAvailable(const ImVector& properties, const char* extension) +{ + for (const VkExtensionProperties& p : properties) + if (strcmp(p.extensionName, extension) == 0) + return true; + return false; +} + +static void SetupVulkan(ImVector extensions) { VkResult err; @@ -76,31 +84,44 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count) { VkInstanceCreateInfo create_info = {}; create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; - create_info.enabledExtensionCount = extensions_count; - create_info.ppEnabledExtensionNames = extensions; -#ifdef IMGUI_VULKAN_DEBUG_REPORT + + // Enumerate available extensions + uint32_t properties_count; + ImVector properties; + vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, nullptr); + properties.resize(properties_count); + err = vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, properties.Data); + check_vk_result(err); + + // Enable required extensions + if (IsExtensionAvailable(properties, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) + extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); +#ifdef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME + if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) + { + extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; + } +#endif + // Enabling validation layers +#ifdef IMGUI_VULKAN_DEBUG_REPORT const char* layers[] = { "VK_LAYER_KHRONOS_validation" }; create_info.enabledLayerCount = 1; create_info.ppEnabledLayerNames = layers; - - // Enable debug report extension (we need additional storage, so we duplicate the user array to add our new extension to it) - const char** extensions_ext = (const char**)malloc(sizeof(const char*) * (extensions_count + 1)); - memcpy(extensions_ext, extensions, extensions_count * sizeof(const char*)); - extensions_ext[extensions_count] = "VK_EXT_debug_report"; - create_info.enabledExtensionCount = extensions_count + 1; - create_info.ppEnabledExtensionNames = extensions_ext; + extensions.push_back("VK_EXT_debug_report"); +#endif // Create Vulkan Instance + create_info.enabledExtensionCount = (uint32_t)extensions.size(); + create_info.ppEnabledExtensionNames = extensions.Data; err = vkCreateInstance(&create_info, g_Allocator, &g_Instance); check_vk_result(err); - free(extensions_ext); - // Get the function pointer (required for any extensions) + // Setup the debug report callback +#ifdef IMGUI_VULKAN_DEBUG_REPORT auto vkCreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkCreateDebugReportCallbackEXT"); IM_ASSERT(vkCreateDebugReportCallbackEXT != nullptr); - - // Setup the debug report callback VkDebugReportCallbackCreateInfoEXT debug_report_ci = {}; debug_report_ci.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT; debug_report_ci.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; @@ -108,11 +129,6 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count) debug_report_ci.pUserData = nullptr; err = vkCreateDebugReportCallbackEXT(g_Instance, &debug_report_ci, g_Allocator, &g_DebugReport); check_vk_result(err); -#else - // Create Vulkan Instance without any debug feature - err = vkCreateInstance(&create_info, g_Allocator, &g_Instance); - check_vk_result(err); - IM_UNUSED(g_DebugReport); #endif } @@ -367,9 +383,13 @@ int main(int, char**) printf("GLFW: Vulkan Not Supported\n"); return 1; } + + ImVector extensions; uint32_t extensions_count = 0; - const char** extensions = glfwGetRequiredInstanceExtensions(&extensions_count); - SetupVulkan(extensions, extensions_count); + const char** glfw_extensions = glfwGetRequiredInstanceExtensions(&extensions_count); + for (uint32_t i = 0; i < extensions_count; i++) + extensions.push_back(glfw_extensions[i]); + SetupVulkan(extensions); // Create Window Surface VkSurfaceKHR surface; diff --git a/examples/example_sdl2_vulkan/main.cpp b/examples/example_sdl2_vulkan/main.cpp index 8a2d9b7d..7c782ebb 100644 --- a/examples/example_sdl2_vulkan/main.cpp +++ b/examples/example_sdl2_vulkan/main.cpp @@ -56,7 +56,15 @@ static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(VkDebugReportFlagsEXT flags, } #endif // IMGUI_VULKAN_DEBUG_REPORT -static void SetupVulkan(const char** extensions, uint32_t extensions_count) +static bool IsExtensionAvailable(const ImVector& properties, const char* extension) +{ + for (const VkExtensionProperties& p : properties) + if (strcmp(p.extensionName, extension) == 0) + return true; + return false; +} + +static void SetupVulkan(ImVector extensions) { VkResult err; @@ -64,31 +72,44 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count) { VkInstanceCreateInfo create_info = {}; create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; - create_info.enabledExtensionCount = extensions_count; - create_info.ppEnabledExtensionNames = extensions; -#ifdef IMGUI_VULKAN_DEBUG_REPORT + + // Enumerate available extensions + uint32_t properties_count; + ImVector properties; + vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, nullptr); + properties.resize(properties_count); + err = vkEnumerateInstanceExtensionProperties(nullptr, &properties_count, properties.Data); + check_vk_result(err); + + // Enable required extensions + if (IsExtensionAvailable(properties, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) + extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); +#ifdef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME + if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) + { + extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; + } +#endif + // Enabling validation layers +#ifdef IMGUI_VULKAN_DEBUG_REPORT const char* layers[] = { "VK_LAYER_KHRONOS_validation" }; create_info.enabledLayerCount = 1; create_info.ppEnabledLayerNames = layers; - - // Enable debug report extension (we need additional storage, so we duplicate the user array to add our new extension to it) - const char** extensions_ext = (const char**)malloc(sizeof(const char*) * (extensions_count + 1)); - memcpy(extensions_ext, extensions, extensions_count * sizeof(const char*)); - extensions_ext[extensions_count] = "VK_EXT_debug_report"; - create_info.enabledExtensionCount = extensions_count + 1; - create_info.ppEnabledExtensionNames = extensions_ext; + extensions.push_back("VK_EXT_debug_report"); +#endif // Create Vulkan Instance + create_info.enabledExtensionCount = (uint32_t)extensions.size(); + create_info.ppEnabledExtensionNames = extensions.Data; err = vkCreateInstance(&create_info, g_Allocator, &g_Instance); check_vk_result(err); - free(extensions_ext); - // Get the function pointer (required for any extensions) + // Setup the debug report callback +#ifdef IMGUI_VULKAN_DEBUG_REPORT auto vkCreateDebugReportCallbackEXT = (PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkCreateDebugReportCallbackEXT"); IM_ASSERT(vkCreateDebugReportCallbackEXT != nullptr); - - // Setup the debug report callback VkDebugReportCallbackCreateInfoEXT debug_report_ci = {}; debug_report_ci.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT; debug_report_ci.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT; @@ -96,11 +117,6 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count) debug_report_ci.pUserData = nullptr; err = vkCreateDebugReportCallbackEXT(g_Instance, &debug_report_ci, g_Allocator, &g_DebugReport); check_vk_result(err); -#else - // Create Vulkan Instance without any debug feature - err = vkCreateInstance(&create_info, g_Allocator, &g_Instance); - check_vk_result(err); - IM_UNUSED(g_DebugReport); #endif } @@ -358,12 +374,13 @@ int main(int, char**) // Create window with Vulkan graphics context SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); + + ImVector extensions; uint32_t extensions_count = 0; SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, nullptr); - const char** extensions = new const char*[extensions_count]; - SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, extensions); - SetupVulkan(extensions, extensions_count); - delete[] extensions; + extensions.resize(extensions_count); + SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, extensions.Data); + SetupVulkan(extensions); // Create Window Surface VkSurfaceKHR surface; From ba98667c657aa9e84333564b3814d99e327ff7c1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 13 Apr 2023 15:57:28 +0200 Subject: [PATCH 3/4] Examples: Vulkan: further work for device extensions + tentative use o fVK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME. (#6109, #6172, #6101) --- examples/example_glfw_vulkan/main.cpp | 89 +++++++++++++++------------ examples/example_sdl2_vulkan/main.cpp | 89 +++++++++++++++------------ 2 files changed, 100 insertions(+), 78 deletions(-) diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index d3213919..43ac22f0 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -18,6 +18,7 @@ #define GLFW_INCLUDE_VULKAN #include #include +//#include // [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers. // To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma. @@ -76,7 +77,32 @@ static bool IsExtensionAvailable(const ImVector& properti return false; } -static void SetupVulkan(ImVector extensions) +static VkPhysicalDevice SetupVulkan_SelectPhysicalDevice() +{ + uint32_t gpu_count; + VkResult err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, nullptr); + check_vk_result(err); + IM_ASSERT(gpu_count > 0); + + ImVector gpus; + gpus.resize(gpu_count); + err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus.Data); + check_vk_result(err); + + // If a number >1 of GPUs got reported, find discrete GPU if present, or use first one available. This covers + // most common cases (multi-gpu/integrated+dedicated graphics). Handling more complicated setups (multiple + // dedicated GPUs) is out of scope of this sample. + for (VkPhysicalDevice& device : gpus) + { + VkPhysicalDeviceProperties properties; + vkGetPhysicalDeviceProperties(device, &properties); + if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) + return device; + } + return VK_NULL_HANDLE; +} + +static void SetupVulkan(ImVector instance_extensions) { VkResult err; @@ -95,11 +121,11 @@ static void SetupVulkan(ImVector extensions) // Enable required extensions if (IsExtensionAvailable(properties, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) - extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + instance_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); #ifdef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) { - extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; } #endif @@ -109,12 +135,12 @@ static void SetupVulkan(ImVector extensions) const char* layers[] = { "VK_LAYER_KHRONOS_validation" }; create_info.enabledLayerCount = 1; create_info.ppEnabledLayerNames = layers; - extensions.push_back("VK_EXT_debug_report"); + instance_extensions.push_back("VK_EXT_debug_report"); #endif // Create Vulkan Instance - create_info.enabledExtensionCount = (uint32_t)extensions.size(); - create_info.ppEnabledExtensionNames = extensions.Data; + create_info.enabledExtensionCount = (uint32_t)instance_extensions.Size; + create_info.ppEnabledExtensionNames = instance_extensions.Data; err = vkCreateInstance(&create_info, g_Allocator, &g_Instance); check_vk_result(err); @@ -132,35 +158,8 @@ static void SetupVulkan(ImVector extensions) #endif } - // Select GPU - { - uint32_t gpu_count; - err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, nullptr); - check_vk_result(err); - IM_ASSERT(gpu_count > 0); - - VkPhysicalDevice* gpus = (VkPhysicalDevice*)malloc(sizeof(VkPhysicalDevice) * gpu_count); - err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus); - check_vk_result(err); - - // If a number >1 of GPUs got reported, find discrete GPU if present, or use first one available. This covers - // most common cases (multi-gpu/integrated+dedicated graphics). Handling more complicated setups (multiple - // dedicated GPUs) is out of scope of this sample. - int use_gpu = 0; - for (int i = 0; i < (int)gpu_count; i++) - { - VkPhysicalDeviceProperties properties; - vkGetPhysicalDeviceProperties(gpus[i], &properties); - if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) - { - use_gpu = i; - break; - } - } - - g_PhysicalDevice = gpus[use_gpu]; - free(gpus); - } + // Select Physical Device (GPU) + g_PhysicalDevice = SetupVulkan_SelectPhysicalDevice(); // Select graphics queue family { @@ -180,8 +179,20 @@ static void SetupVulkan(ImVector extensions) // Create Logical Device (with 1 queue) { - int device_extension_count = 1; - const char* device_extensions[] = { "VK_KHR_swapchain" }; + ImVector device_extensions; + device_extensions.push_back("VK_KHR_swapchain"); + + // Enumerate physical device extension + uint32_t properties_count; + ImVector properties; + vkEnumerateDeviceExtensionProperties(g_PhysicalDevice, nullptr, &properties_count, nullptr); + properties.resize(properties_count); + vkEnumerateDeviceExtensionProperties(g_PhysicalDevice, nullptr, &properties_count, properties.Data); +#ifdef VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME + if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME)) + device_extensions.push_back(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME); +#endif + const float queue_priority[] = { 1.0f }; VkDeviceQueueCreateInfo queue_info[1] = {}; queue_info[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; @@ -192,8 +203,8 @@ static void SetupVulkan(ImVector extensions) create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; create_info.queueCreateInfoCount = sizeof(queue_info) / sizeof(queue_info[0]); create_info.pQueueCreateInfos = queue_info; - create_info.enabledExtensionCount = device_extension_count; - create_info.ppEnabledExtensionNames = device_extensions; + create_info.enabledExtensionCount = (uint32_t)device_extensions.Size; + create_info.ppEnabledExtensionNames = device_extensions.Data; err = vkCreateDevice(g_PhysicalDevice, &create_info, g_Allocator, &g_Device); check_vk_result(err); vkGetDeviceQueue(g_Device, g_QueueFamily, 0, &g_Queue); diff --git a/examples/example_sdl2_vulkan/main.cpp b/examples/example_sdl2_vulkan/main.cpp index 7c782ebb..db78acdf 100644 --- a/examples/example_sdl2_vulkan/main.cpp +++ b/examples/example_sdl2_vulkan/main.cpp @@ -17,6 +17,7 @@ #include #include #include +//#include //#define IMGUI_UNLIMITED_FRAME_RATE #ifdef _DEBUG @@ -64,7 +65,32 @@ static bool IsExtensionAvailable(const ImVector& properti return false; } -static void SetupVulkan(ImVector extensions) +static VkPhysicalDevice SetupVulkan_SelectPhysicalDevice() +{ + uint32_t gpu_count; + VkResult err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, nullptr); + check_vk_result(err); + IM_ASSERT(gpu_count > 0); + + ImVector gpus; + gpus.resize(gpu_count); + err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus.Data); + check_vk_result(err); + + // If a number >1 of GPUs got reported, find discrete GPU if present, or use first one available. This covers + // most common cases (multi-gpu/integrated+dedicated graphics). Handling more complicated setups (multiple + // dedicated GPUs) is out of scope of this sample. + for (VkPhysicalDevice& device : gpus) + { + VkPhysicalDeviceProperties properties; + vkGetPhysicalDeviceProperties(device, &properties); + if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) + return device; + } + return VK_NULL_HANDLE; +} + +static void SetupVulkan(ImVector instance_extensions) { VkResult err; @@ -83,11 +109,11 @@ static void SetupVulkan(ImVector extensions) // Enable required extensions if (IsExtensionAvailable(properties, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME)) - extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + instance_extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); #ifdef VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME)) { - extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); + instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME); create_info.flags |= VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR; } #endif @@ -97,12 +123,12 @@ static void SetupVulkan(ImVector extensions) const char* layers[] = { "VK_LAYER_KHRONOS_validation" }; create_info.enabledLayerCount = 1; create_info.ppEnabledLayerNames = layers; - extensions.push_back("VK_EXT_debug_report"); + instance_extensions.push_back("VK_EXT_debug_report"); #endif // Create Vulkan Instance - create_info.enabledExtensionCount = (uint32_t)extensions.size(); - create_info.ppEnabledExtensionNames = extensions.Data; + create_info.enabledExtensionCount = (uint32_t)instance_extensions.Size; + create_info.ppEnabledExtensionNames = instance_extensions.Data; err = vkCreateInstance(&create_info, g_Allocator, &g_Instance); check_vk_result(err); @@ -120,35 +146,8 @@ static void SetupVulkan(ImVector extensions) #endif } - // Select GPU - { - uint32_t gpu_count; - err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, nullptr); - check_vk_result(err); - IM_ASSERT(gpu_count > 0); - - VkPhysicalDevice* gpus = (VkPhysicalDevice*)malloc(sizeof(VkPhysicalDevice) * gpu_count); - err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus); - check_vk_result(err); - - // If a number >1 of GPUs got reported, find discrete GPU if present, or use first one available. This covers - // most common cases (multi-gpu/integrated+dedicated graphics). Handling more complicated setups (multiple - // dedicated GPUs) is out of scope of this sample. - int use_gpu = 0; - for (int i = 0; i < (int)gpu_count; i++) - { - VkPhysicalDeviceProperties properties; - vkGetPhysicalDeviceProperties(gpus[i], &properties); - if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) - { - use_gpu = i; - break; - } - } - - g_PhysicalDevice = gpus[use_gpu]; - free(gpus); - } + // Select Physical Device (GPU) + g_PhysicalDevice = SetupVulkan_SelectPhysicalDevice(); // Select graphics queue family { @@ -168,8 +167,20 @@ static void SetupVulkan(ImVector extensions) // Create Logical Device (with 1 queue) { - int device_extension_count = 1; - const char* device_extensions[] = { "VK_KHR_swapchain" }; + ImVector device_extensions; + device_extensions.push_back("VK_KHR_swapchain"); + + // Enumerate physical device extension + uint32_t properties_count; + ImVector properties; + vkEnumerateDeviceExtensionProperties(g_PhysicalDevice, nullptr, &properties_count, nullptr); + properties.resize(properties_count); + vkEnumerateDeviceExtensionProperties(g_PhysicalDevice, nullptr, &properties_count, properties.Data); +#ifdef VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME + if (IsExtensionAvailable(properties, VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME)) + device_extensions.push_back(VK_KHR_PORTABILITY_SUBSET_EXTENSION_NAME); +#endif + const float queue_priority[] = { 1.0f }; VkDeviceQueueCreateInfo queue_info[1] = {}; queue_info[0].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO; @@ -180,8 +191,8 @@ static void SetupVulkan(ImVector extensions) create_info.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; create_info.queueCreateInfoCount = sizeof(queue_info) / sizeof(queue_info[0]); create_info.pQueueCreateInfos = queue_info; - create_info.enabledExtensionCount = device_extension_count; - create_info.ppEnabledExtensionNames = device_extensions; + create_info.enabledExtensionCount = (uint32_t)device_extensions.Size; + create_info.ppEnabledExtensionNames = device_extensions.Data; err = vkCreateDevice(g_PhysicalDevice, &create_info, g_Allocator, &g_Device); check_vk_result(err); vkGetDeviceQueue(g_Device, g_QueueFamily, 0, &g_Queue); From 1ebb91382757777382b3629ced2a573996e46453 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 13 Apr 2023 15:51:04 +0200 Subject: [PATCH 4/4] Version 1.89.5 --- docs/CHANGELOG.txt | 18 +++++++++--------- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_tables.cpp | 2 +- imgui_widgets.cpp | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 56d43d9b..8bde6703 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -32,21 +32,19 @@ HOW TO UPDATE? ----------------------------------------------------------------------- - VERSION 1.89.5 WIP (In Progress) + VERSION 1.89.5 (Released 2023-04-13) ----------------------------------------------------------------------- -Breaking Changes: - Other changes: +- InputText: Reworked prev/next-word behavior to more closely match Visual Studio + text editor. Include '.' as a delimiter and alter varying subtle behavior with how + blanks and separators are treated when skipping words. (#6067) [@ajweeks] - InputText: Fixed a tricky edge case, ensuring value is always written back on the frame where IsItemDeactivated() returns true, in order to allow usage without user retaining underlying data. While we don't really want to encourage user not retaining underlying data, in the absence of a "late commit" behavior/flag we understand it may be desirable to take advantage of this trick. (#4714) -- InputText: Reworked prev/next-word behavior to more closely match Visual Studio - text editor. Include '.' as a delimiter and alter varying subtle behavior with how - blanks and separators are treated when skipping words. (#6067) [@ajweeks] - Drag, Sliders: Fixed parsing of text input when '+' or '#' format flags are used in the format string. (#6259) [@idbrii] - Nav: Made Ctrl+Tab/Ctrl+Shift+Tab windowing register ownership to held modifier so @@ -56,7 +54,7 @@ Other changes: - ColorEdit: Fixed shading of S/V triangle in Hue Wheel mode. (#5200, #6254) [@jamesthomasgriffin] - TabBar: Tab-bars with ImGuiTabBarFlags_FittingPolicyScroll can be scrolled with horizontal mouse-wheel (or Shift + WheelY). (#2702) -- Rendering: Using adaptative tesselation for: RadioButton, ColorEdit preview circles, +- Rendering: Using adaptive tessellation for RadioButton, ColorEdit preview circles, Windows Close and Collapse Buttons. - ButtonBehavior: Fixed an edge case where changing widget type/behavior while active and using same id could lead to an assert. (#6304) @@ -74,7 +72,7 @@ Other changes: - Fixed tapping on TableHeader() on a touch-screen. - IO: Added io.AddMouseSourceEvent() and ImGuiMouseSource enum. This is to allow backend to specify actual event source between Mouse/TouchScreen/Pen. (#2702, #2334, #2372, #3453, #5693) -- IO: Fixed support for calling io.AddXXXX functions fron inactive context (wrongly +- IO: Fixed support for calling io.AddXXXX functions from inactive context (wrongly advertised as supported in 1.89.4). (#6199, #6256, #5856) [@cfillion] - Backends: OpenGL3: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530) - Backends: OpenGL3: Properly restoring "no shader program bound" if it was the case prior to @@ -94,12 +92,14 @@ Other changes: (#6314) [@PathogenDavid] - Backends: WebGPU: Align buffers. Use WGSL shaders instead of SPIR-V. Add gamma uniform. (#6188) [@eliemichel] - Backends: WebGPU: Reorganized to store data in io.BackendRendererUserData like other backends. -- Examples: Vulkan: Fixed validation errors with newer VulkanSDK by explicitely querying and enabling +- Examples: Vulkan: Fixed validation errors with newer VulkanSDK by explicitly querying and enabling "VK_KHR_get_physical_device_properties2", "VK_KHR_portability_enumeration", and VK_INSTANCE_CREATE_ENUMERATE_PORTABILITY_BIT_KHR. (#6109, #6172, #6101) - Examples: Windows: Added 'misc/debuggers/imgui.natstepfilter' file to all Visual Studio projects, now that VS 2022 17.6 Preview 2 support adding Debug Step Filter spec files into projects. - Examples: SDL3: Updated for latest WIP SDL3 branch. (#6243) +- TestSuite: Added variety of new regression tests and improved/amended existing ones + in imgui_test_engine/ repo. [@PathogenDavid, @ocornut] ----------------------------------------------------------------------- diff --git a/imgui.cpp b/imgui.cpp index 4006a777..6272b729 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 WIP +// dear imgui, v1.89.5 // (main code and documentation) // Help: diff --git a/imgui.h b/imgui.h index 02ef16f3..6946d13f 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 WIP +// dear imgui, v1.89.5 // (headers) // Help: @@ -22,8 +22,8 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') -#define IMGUI_VERSION "1.89.5 WIP" -#define IMGUI_VERSION_NUM 18949 +#define IMGUI_VERSION "1.89.5" +#define IMGUI_VERSION_NUM 18950 #define IMGUI_HAS_TABLE /* diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 5849ffbe..fc8097ce 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 WIP +// dear imgui, v1.89.5 // (demo code) // Help: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 5bf03460..182ec833 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 WIP +// dear imgui, v1.89.5 // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index ab9d81c8..70e60000 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 WIP +// dear imgui, v1.89.5 // (internal structures/api) // You may use this file to debug, understand or extend Dear ImGui features but we don't provide any guarantee of forward compatibility. diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 8e92ff2a..6ec419d5 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 WIP +// dear imgui, v1.89.5 // (tables and columns code) /* diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 8ea6e443..1d4aee6d 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.89.5 WIP +// dear imgui, v1.89.5 // (widgets code) /*