mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-24 15:50:25 +01:00
This commit is contained in:
parent
201d589714
commit
f87b152522
@ -192,16 +192,9 @@ static void resize_vulkan(GLFWwindow* /*window*/, int w, int h)
|
|||||||
|
|
||||||
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
||||||
static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(
|
static VKAPI_ATTR VkBool32 VKAPI_CALL debug_report(
|
||||||
VkDebugReportFlagsEXT, //flags,
|
VkDebugReportFlagsEXT flags, VkDebugReportObjectTypeEXT objectType, uint64_t object, size_t location, int32_t messageCode, const char* pLayerPrefix, const char* pMessage, void* pUserData)
|
||||||
VkDebugReportObjectTypeEXT objectType,
|
|
||||||
uint64_t, //object,
|
|
||||||
size_t, //location,
|
|
||||||
int32_t, //messageCode,
|
|
||||||
const char*, //pLayerPrefix,
|
|
||||||
const char* pMessage,
|
|
||||||
void*) //pUserData)
|
|
||||||
{
|
{
|
||||||
printf( "ObjectType : %i\nMessage : %s\n\n", objectType, pMessage );
|
printf("[vulkan] ObjectType: %i\nMessage: %s\n\n", objectType, pMessage );
|
||||||
return VK_FALSE;
|
return VK_FALSE;
|
||||||
}
|
}
|
||||||
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
||||||
@ -217,6 +210,9 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
|
|
||||||
VkInstanceCreateInfo create_info = {};
|
VkInstanceCreateInfo create_info = {};
|
||||||
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
|
create_info.enabledExtensionCount = extensions_count;
|
||||||
|
create_info.ppEnabledExtensionNames = glfw_extensions;
|
||||||
|
|
||||||
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
||||||
// enabling multiple validation layers grouped as lunarg standard validation
|
// enabling multiple validation layers grouped as lunarg standard validation
|
||||||
const char* layers[] = {"VK_LAYER_LUNARG_standard_validation"};
|
const char* layers[] = {"VK_LAYER_LUNARG_standard_validation"};
|
||||||
@ -230,9 +226,6 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
extensions[ extensions_count ] = "VK_EXT_debug_report";
|
extensions[ extensions_count ] = "VK_EXT_debug_report";
|
||||||
create_info.enabledExtensionCount = extensions_count+1;
|
create_info.enabledExtensionCount = extensions_count+1;
|
||||||
create_info.ppEnabledExtensionNames = extensions;
|
create_info.ppEnabledExtensionNames = extensions;
|
||||||
#else
|
|
||||||
create_info.enabledExtensionCount = extensions_count;
|
|
||||||
create_info.ppEnabledExtensionNames = glfw_extensions;
|
|
||||||
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
||||||
|
|
||||||
err = vkCreateInstance(&create_info, g_Allocator, &g_Instance);
|
err = vkCreateInstance(&create_info, g_Allocator, &g_Instance);
|
||||||
@ -253,7 +246,7 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
(PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkCreateDebugReportCallbackEXT");
|
(PFN_vkCreateDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkCreateDebugReportCallbackEXT");
|
||||||
|
|
||||||
err = vkCreateDebugReportCallbackEXT( g_Instance, &debug_report_ci, g_Allocator, &g_Debug_Report );
|
err = vkCreateDebugReportCallbackEXT( g_Instance, &debug_report_ci, g_Allocator, &g_Debug_Report );
|
||||||
check_vk_result( err );
|
check_vk_result(err);
|
||||||
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,21 +262,16 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, NULL);
|
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, NULL);
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
|
|
||||||
if( gpu_count == 1 ) { // only one gpu, assume it has a graphics queue family and use it
|
|
||||||
err = vkEnumeratePhysicalDevices( g_Instance, &gpu_count, &g_Gpu );
|
|
||||||
check_vk_result( err );
|
|
||||||
} else {
|
|
||||||
VkPhysicalDevice* gpus = (VkPhysicalDevice*)malloc(sizeof(VkPhysicalDevice) * gpu_count);
|
VkPhysicalDevice* gpus = (VkPhysicalDevice*)malloc(sizeof(VkPhysicalDevice) * gpu_count);
|
||||||
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus);
|
err = vkEnumeratePhysicalDevices(g_Instance, &gpu_count, gpus);
|
||||||
check_vk_result(err);
|
check_vk_result(err);
|
||||||
|
|
||||||
// here a number > 1 of GPUs got reported, you should find the best fit GPU for your purpose
|
// If a number >1 of GPUs got reported, you should find the best fit GPU for your purpose
|
||||||
// e.g. VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU if available, or with the greatest memory available, etc.
|
// e.g. VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU if available, or with the greatest memory available, etc.
|
||||||
// for sake of simplicity we'll just take the first one, assuming it has a graphics queue family
|
// for sake of simplicity we'll just take the first one, assuming it has a graphics queue family.
|
||||||
g_Gpu = gpus[0];
|
g_Gpu = gpus[0];
|
||||||
free(gpus);
|
free(gpus);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Get queue
|
// Get queue
|
||||||
{
|
{
|
||||||
@ -316,8 +304,8 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
// Get Surface Format
|
// Get Surface Format
|
||||||
{
|
{
|
||||||
// Per Spec Format and View Format are expected to be the same unless VK_IMAGE_CREATE_MUTABLE_BIT was set at image creation
|
// 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 behaviour is without setting this bit, there is no need for seperate Spapchain image and image view format
|
// Assuming that the default behavior is without setting this bit, there is no need for separate Spawchain image and image view format
|
||||||
// additionally severeal new color spaces were introduced with Vulkan Spec v1.0.40
|
// 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
|
// 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 count;
|
uint32_t count;
|
||||||
vkGetPhysicalDeviceSurfaceFormatsKHR(g_Gpu, g_Surface, &count, NULL);
|
vkGetPhysicalDeviceSurfaceFormatsKHR(g_Gpu, g_Surface, &count, NULL);
|
||||||
@ -360,10 +348,8 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
|
|
||||||
// if none of the requested image formats could be found, use the first available
|
// if none of the requested image formats could be found, use the first available
|
||||||
if (!requestedFound)
|
if (!requestedFound)
|
||||||
{
|
|
||||||
g_SurfaceFormat = formats[0];
|
g_SurfaceFormat = formats[0];
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(formats);
|
free(formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -377,9 +363,9 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
g_PresentMode = VK_PRESENT_MODE_FIFO_KHR;
|
g_PresentMode = VK_PRESENT_MODE_FIFO_KHR;
|
||||||
#endif
|
#endif
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR( g_Gpu, g_Surface, &count, nullptr );
|
vkGetPhysicalDeviceSurfacePresentModesKHR(g_Gpu, g_Surface, &count, nullptr);
|
||||||
VkPresentModeKHR* presentModes = ( VkPresentModeKHR* )malloc( sizeof( VkQueueFamilyProperties ) * count );
|
VkPresentModeKHR* presentModes = (VkPresentModeKHR*)malloc(sizeof(VkQueueFamilyProperties) * count);
|
||||||
vkGetPhysicalDeviceSurfacePresentModesKHR( g_Gpu, g_Surface, &count, presentModes );
|
vkGetPhysicalDeviceSurfacePresentModesKHR(g_Gpu, g_Surface, &count, presentModes);
|
||||||
bool presentModeAvailable = false;
|
bool presentModeAvailable = false;
|
||||||
for (size_t i = 0; i < count; i++)
|
for (size_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
@ -390,7 +376,7 @@ static void setup_vulkan(GLFWwindow* window)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( !presentModeAvailable )
|
if( !presentModeAvailable )
|
||||||
g_PresentMode = VK_PRESENT_MODE_FIFO_KHR; // allways available
|
g_PresentMode = VK_PRESENT_MODE_FIFO_KHR; // always available
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -511,8 +497,7 @@ static void cleanup_vulkan()
|
|||||||
|
|
||||||
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
#ifdef IMGUI_VULKAN_DEBUG_REPORT
|
||||||
// get the proc address of the function pointer, required for used extensions
|
// get the proc address of the function pointer, required for used extensions
|
||||||
auto vkDestroyDebugReportCallbackEXT =
|
auto vkDestroyDebugReportCallbackEXT = (PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkDestroyDebugReportCallbackEXT");
|
||||||
(PFN_vkDestroyDebugReportCallbackEXT)vkGetInstanceProcAddr(g_Instance, "vkDestroyDebugReportCallbackEXT");
|
|
||||||
vkDestroyDebugReportCallbackEXT(g_Instance, g_Debug_Report, g_Allocator);
|
vkDestroyDebugReportCallbackEXT(g_Instance, g_Debug_Report, g_Allocator);
|
||||||
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
#endif // IMGUI_VULKAN_DEBUG_REPORT
|
||||||
|
|
||||||
@ -584,8 +569,7 @@ static void frame_end()
|
|||||||
static void frame_present()
|
static void frame_present()
|
||||||
{
|
{
|
||||||
VkResult err;
|
VkResult err;
|
||||||
// If IMGUI_UNLIMITED_FRAME_RATE is defined we present the latest but one frame
|
// If IMGUI_UNLIMITED_FRAME_RATE is defined we present the latest but one frame. Otherwise we present the latest rendered frame
|
||||||
// Othrewise we present the latest rendered frame
|
|
||||||
#ifdef IMGUI_UNLIMITED_FRAME_RATE
|
#ifdef IMGUI_UNLIMITED_FRAME_RATE
|
||||||
uint32_t PresentIndex = (g_FrameIndex + IMGUI_VK_QUEUED_FRAMES - 1) % IMGUI_VK_QUEUED_FRAMES;
|
uint32_t PresentIndex = (g_FrameIndex + IMGUI_VK_QUEUED_FRAMES - 1) % IMGUI_VK_QUEUED_FRAMES;
|
||||||
#else
|
#else
|
||||||
@ -682,10 +666,9 @@ int main(int, char**)
|
|||||||
bool show_another_window = false;
|
bool show_another_window = false;
|
||||||
ImVec4 clear_color = ImColor(114, 144, 154);
|
ImVec4 clear_color = ImColor(114, 144, 154);
|
||||||
|
|
||||||
// When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain
|
// When IMGUI_UNLIMITED_FRAME_RATE is defined we render into latest image acquired from the swapchain but we display the image which was rendered before.
|
||||||
// but we display the image which was rendered before
|
// Hence we must render once and increase the g_FrameIndex without presenting, which we do before entering the render loop.
|
||||||
// hence we must render once and increase the g_FrameIndex without presenting, which we do befor entering the render loop
|
// This is also the reason why frame_end() is split into frame_end() and frame_present(), the later one not being called here.
|
||||||
// this is also the reason why frame_end() is split into frame_end() and frame_present(), the latter one not being called here
|
|
||||||
#ifdef IMGUI_UNLIMITED_FRAME_RATE
|
#ifdef IMGUI_UNLIMITED_FRAME_RATE
|
||||||
ImGui_ImplGlfwVulkan_NewFrame();
|
ImGui_ImplGlfwVulkan_NewFrame();
|
||||||
frame_begin();
|
frame_begin();
|
||||||
|
Loading…
Reference in New Issue
Block a user