mirror of
https://github.com/ocornut/imgui.git
synced 2025-09-06 03:18:21 +00:00
Backends: Vulkan: moved helpers to backend: ImGui_ImplVulkanH_SelectPhysicalDevice(), ImGui_ImplVulkanH_SelectQueueFamilyIndex(). (#8180)
This commit is contained in:
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
|
// 2025-01-06: Vulkan: Added more ImGui_ImplVulkanH_XXXX helper functions to simplify our examples.
|
||||||
// 2024-12-11: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222)
|
// 2024-12-11: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222)
|
||||||
// 2024-11-27: Vulkan: Make user-provided descriptor pool optional. As a convenience, when setting init_info->DescriptorPoolSize the backend will create one itself. (#8172, #4867)
|
// 2024-11-27: Vulkan: Make user-provided descriptor pool optional. As a convenience, when setting init_info->DescriptorPoolSize the backend will create one itself. (#8172, #4867)
|
||||||
// 2024-10-07: Vulkan: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
// 2024-10-07: Vulkan: Changed default texture sampler to Clamp instead of Repeat/Wrap.
|
||||||
@@ -1334,6 +1335,49 @@ VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_d
|
|||||||
return VK_PRESENT_MODE_FIFO_KHR; // Always available
|
return VK_PRESENT_MODE_FIFO_KHR; // Always available
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkPhysicalDevice ImGui_ImplVulkanH_SelectPhysicalDevice(VkInstance instance)
|
||||||
|
{
|
||||||
|
uint32_t gpu_count;
|
||||||
|
VkResult err = vkEnumeratePhysicalDevices(instance, &gpu_count, nullptr);
|
||||||
|
check_vk_result(err);
|
||||||
|
IM_ASSERT(gpu_count > 0);
|
||||||
|
|
||||||
|
ImVector<VkPhysicalDevice> gpus;
|
||||||
|
gpus.resize(gpu_count);
|
||||||
|
err = vkEnumeratePhysicalDevices(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use first GPU (Integrated) is a Discrete one is not available.
|
||||||
|
if (gpu_count > 0)
|
||||||
|
return gpus[0];
|
||||||
|
return VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t ImGui_ImplVulkanH_SelectQueueFamilyIndex(VkPhysicalDevice physical_device)
|
||||||
|
{
|
||||||
|
uint32_t count;
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &count, nullptr);
|
||||||
|
ImVector<VkQueueFamilyProperties> queues_properties;
|
||||||
|
queues_properties.resize((int)count);
|
||||||
|
vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &count, queues_properties.Data);
|
||||||
|
for (uint32_t i = 0; i < count; i++)
|
||||||
|
if (queues_properties[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
||||||
|
return i;
|
||||||
|
return (uint32_t)-1;
|
||||||
|
}
|
||||||
|
|
||||||
void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator)
|
void ImGui_ImplVulkanH_CreateWindowCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wd, uint32_t queue_family, const VkAllocationCallbacks* allocator)
|
||||||
{
|
{
|
||||||
IM_ASSERT(physical_device != VK_NULL_HANDLE && device != VK_NULL_HANDLE);
|
IM_ASSERT(physical_device != VK_NULL_HANDLE && device != VK_NULL_HANDLE);
|
||||||
|
@@ -135,18 +135,24 @@ struct ImGui_ImplVulkan_RenderState
|
|||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// Internal / Miscellaneous Vulkan Helpers
|
// Internal / Miscellaneous Vulkan Helpers
|
||||||
// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.)
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
// Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.
|
||||||
|
//
|
||||||
// You probably do NOT need to use or care about those functions.
|
// You probably do NOT need to use or care about those functions.
|
||||||
// Those functions only exist because:
|
// Those functions only exist because:
|
||||||
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
|
||||||
// 2) the multi-viewport / platform window implementation needs them internally.
|
// 2) the multi-viewport / platform window implementation needs them internally.
|
||||||
// Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
|
// Generally we avoid exposing any kind of superfluous high-level helpers in the backends,
|
||||||
// but it is too much code to duplicate everywhere so we exceptionally expose them.
|
// but it is too much code to duplicate everywhere so we exceptionally expose them.
|
||||||
//
|
//
|
||||||
// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
|
// Your engine/app will likely _already_ have code to setup all that stuff (swap chain,
|
||||||
// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
|
// render pass, frame buffers, etc.). You may read this code if you are curious, but
|
||||||
// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
|
// it is recommended you use you own custom tailored code to do equivalent work.
|
||||||
|
//
|
||||||
|
// We don't provide a strong guarantee that we won't change those functions API.
|
||||||
|
//
|
||||||
|
// The ImGui_ImplVulkanH_XXX functions should NOT interact with any of the state used
|
||||||
|
// by the regular ImGui_ImplVulkan_XXX functions).
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
struct ImGui_ImplVulkanH_Frame;
|
struct ImGui_ImplVulkanH_Frame;
|
||||||
@@ -157,6 +163,8 @@ IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkIns
|
|||||||
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator);
|
IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator);
|
||||||
IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
|
IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
|
||||||
IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
|
IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
|
||||||
|
IMGUI_IMPL_API VkPhysicalDevice ImGui_ImplVulkanH_SelectPhysicalDevice(VkInstance instance);
|
||||||
|
IMGUI_IMPL_API uint32_t ImGui_ImplVulkanH_SelectQueueFamilyIndex(VkPhysicalDevice physical_device);
|
||||||
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
|
||||||
|
|
||||||
// Helper structure to hold the data needed by one rendering frame
|
// Helper structure to hold the data needed by one rendering frame
|
||||||
|
@@ -70,6 +70,8 @@ Other changes:
|
|||||||
- Backends: Metal: Fixed resource leak when using multiple contexts. (#7419) [@anszom]
|
- Backends: Metal: Fixed resource leak when using multiple contexts. (#7419) [@anszom]
|
||||||
- Backends: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for
|
- Backends: Vulkan: Fixed setting VkSwapchainCreateInfoKHR::preTransform for
|
||||||
platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222) [@Zer0xFF]
|
platforms not supporting VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR. (#8222) [@Zer0xFF]
|
||||||
|
- Backends: Vulkan: Added a few more ImGui_ImplVulkanH_XXX helper functions
|
||||||
|
primarily for the purpose of making our examples simpler.
|
||||||
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------
|
-----------------------------------------------------------------------
|
||||||
|
@@ -85,35 +85,6 @@ static bool IsExtensionAvailable(const ImVector<VkExtensionProperties>& properti
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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<VkPhysicalDevice> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use first GPU (Integrated) is a Discrete one is not available.
|
|
||||||
if (gpu_count > 0)
|
|
||||||
return gpus[0];
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetupVulkan(ImVector<const char*> instance_extensions)
|
static void SetupVulkan(ImVector<const char*> instance_extensions)
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
@@ -177,23 +148,12 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select Physical Device (GPU)
|
// Select Physical Device (GPU)
|
||||||
g_PhysicalDevice = SetupVulkan_SelectPhysicalDevice();
|
g_PhysicalDevice = ImGui_ImplVulkanH_SelectPhysicalDevice(g_Instance);
|
||||||
|
IM_ASSERT(g_PhysicalDevice != VK_NULL_HANDLE);
|
||||||
|
|
||||||
// Select graphics queue family
|
// Select graphics queue family
|
||||||
{
|
g_QueueFamily = ImGui_ImplVulkanH_SelectQueueFamilyIndex(g_PhysicalDevice);
|
||||||
uint32_t count;
|
IM_ASSERT(g_QueueFamily != (uint32_t)-1);
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(g_PhysicalDevice, &count, nullptr);
|
|
||||||
VkQueueFamilyProperties* queues = (VkQueueFamilyProperties*)malloc(sizeof(VkQueueFamilyProperties) * count);
|
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(g_PhysicalDevice, &count, queues);
|
|
||||||
for (uint32_t i = 0; i < count; i++)
|
|
||||||
if (queues[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
|
||||||
{
|
|
||||||
g_QueueFamily = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free(queues);
|
|
||||||
IM_ASSERT(g_QueueFamily != (uint32_t)-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Logical Device (with 1 queue)
|
// Create Logical Device (with 1 queue)
|
||||||
{
|
{
|
||||||
|
@@ -87,7 +87,7 @@ int main(int, char**)
|
|||||||
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
printf("Error: SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||||
|
|
||||||
|
@@ -73,35 +73,6 @@ static bool IsExtensionAvailable(const ImVector<VkExtensionProperties>& properti
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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<VkPhysicalDevice> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use first GPU (Integrated) is a Discrete one is not available.
|
|
||||||
if (gpu_count > 0)
|
|
||||||
return gpus[0];
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetupVulkan(ImVector<const char*> instance_extensions)
|
static void SetupVulkan(ImVector<const char*> instance_extensions)
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
@@ -165,23 +136,12 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select Physical Device (GPU)
|
// Select Physical Device (GPU)
|
||||||
g_PhysicalDevice = SetupVulkan_SelectPhysicalDevice();
|
g_PhysicalDevice = ImGui_ImplVulkanH_SelectPhysicalDevice(g_Instance);
|
||||||
|
IM_ASSERT(g_PhysicalDevice != VK_NULL_HANDLE);
|
||||||
|
|
||||||
// Select graphics queue family
|
// Select graphics queue family
|
||||||
{
|
g_QueueFamily = ImGui_ImplVulkanH_SelectQueueFamilyIndex(g_PhysicalDevice);
|
||||||
uint32_t count;
|
IM_ASSERT(g_QueueFamily != (uint32_t)-1);
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(g_PhysicalDevice, &count, nullptr);
|
|
||||||
VkQueueFamilyProperties* queues = (VkQueueFamilyProperties*)malloc(sizeof(VkQueueFamilyProperties) * count);
|
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(g_PhysicalDevice, &count, queues);
|
|
||||||
for (uint32_t i = 0; i < count; i++)
|
|
||||||
if (queues[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
|
||||||
{
|
|
||||||
g_QueueFamily = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free(queues);
|
|
||||||
IM_ASSERT(g_QueueFamily != (uint32_t)-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Logical Device (with 1 queue)
|
// Create Logical Device (with 1 queue)
|
||||||
{
|
{
|
||||||
|
@@ -78,35 +78,6 @@ static bool IsExtensionAvailable(const ImVector<VkExtensionProperties>& properti
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
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<VkPhysicalDevice> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use first GPU (Integrated) is a Discrete one is not available.
|
|
||||||
if (gpu_count > 0)
|
|
||||||
return gpus[0];
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void SetupVulkan(ImVector<const char*> instance_extensions)
|
static void SetupVulkan(ImVector<const char*> instance_extensions)
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
@@ -170,23 +141,12 @@ static void SetupVulkan(ImVector<const char*> instance_extensions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Select Physical Device (GPU)
|
// Select Physical Device (GPU)
|
||||||
g_PhysicalDevice = SetupVulkan_SelectPhysicalDevice();
|
g_PhysicalDevice = ImGui_ImplVulkanH_SelectPhysicalDevice(g_Instance);
|
||||||
|
IM_ASSERT(g_PhysicalDevice != VK_NULL_HANDLE);
|
||||||
|
|
||||||
// Select graphics queue family
|
// Select graphics queue family
|
||||||
{
|
g_QueueFamily = ImGui_ImplVulkanH_SelectQueueFamilyIndex(g_PhysicalDevice);
|
||||||
uint32_t count;
|
IM_ASSERT(g_QueueFamily != (uint32_t)-1);
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(g_PhysicalDevice, &count, nullptr);
|
|
||||||
VkQueueFamilyProperties* queues = (VkQueueFamilyProperties*)malloc(sizeof(VkQueueFamilyProperties) * count);
|
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(g_PhysicalDevice, &count, queues);
|
|
||||||
for (uint32_t i = 0; i < count; i++)
|
|
||||||
if (queues[i].queueFlags & VK_QUEUE_GRAPHICS_BIT)
|
|
||||||
{
|
|
||||||
g_QueueFamily = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
free(queues);
|
|
||||||
IM_ASSERT(g_QueueFamily != (uint32_t)-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Logical Device (with 1 queue)
|
// Create Logical Device (with 1 queue)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user