Lines Matching +full:vulkan +full:- +full:device +full:- +full:select +full:- +full:layer
2 * Copyright (c) 2015-2016 The Khronos Group Inc.
3 * Copyright (c) 2015-2016 Valve Corporation
4 * Copyright (c) 2015-2016 LunarG, Inc.
25 * Author: Chia-I Wu <olvaffe@gmail.com>
48 #include <vulkan/vulkan.h>
53 #define APP_SHORT_NAME "vulkan"
54 #define APP_LONG_NAME "The Vulkan Triangle Demo Program"
73 demo->fp##entrypoint = \
75 if (demo->fp##entrypoint == NULL) { \
83 demo->fp##entrypoint = \
85 if (demo->fp##entrypoint == NULL) { \
271 * false indicates that layer should not bail-out of an in dbgFunc()
295 VkDevice device; member
390 if ((demo->memory_properties.memoryTypes[i].propertyFlags & in memory_type_from_properties()
405 if (demo->setup_cmd == VK_NULL_HANDLE) in demo_flush_init_cmd()
408 err = vkEndCommandBuffer(demo->setup_cmd); in demo_flush_init_cmd()
411 const VkCommandBuffer cmd_bufs[] = {demo->setup_cmd}; in demo_flush_init_cmd()
423 err = vkQueueSubmit(demo->queue, 1, &submit_info, nullFence); in demo_flush_init_cmd()
426 err = vkQueueWaitIdle(demo->queue); in demo_flush_init_cmd()
429 vkFreeCommandBuffers(demo->device, demo->cmd_pool, 1, cmd_bufs); in demo_flush_init_cmd()
430 demo->setup_cmd = VK_NULL_HANDLE; in demo_flush_init_cmd()
439 if (demo->setup_cmd == VK_NULL_HANDLE) { in demo_set_image_layout()
443 .commandPool = demo->cmd_pool, in demo_set_image_layout()
448 err = vkAllocateCommandBuffers(demo->device, &cmd, &demo->setup_cmd); in demo_set_image_layout()
467 err = vkBeginCommandBuffer(demo->setup_cmd, &cmd_buf_info); in demo_set_image_layout()
507 vkCmdPipelineBarrier(demo->setup_cmd, src_stages, dest_stages, 0, 0, NULL, in demo_set_image_layout()
530 [1] = {.depthStencil = {demo->depthStencil, 0}}, in demo_draw_build_cmd()
535 .renderPass = demo->render_pass, in demo_draw_build_cmd()
536 .framebuffer = demo->framebuffers[demo->current_buffer], in demo_draw_build_cmd()
539 .renderArea.extent.width = demo->width, in demo_draw_build_cmd()
540 .renderArea.extent.height = demo->height, in demo_draw_build_cmd()
546 err = vkBeginCommandBuffer(demo->draw_cmd, &cmd_buf_info); in demo_draw_build_cmd()
549 vkCmdBeginRenderPass(demo->draw_cmd, &rp_begin, VK_SUBPASS_CONTENTS_INLINE); in demo_draw_build_cmd()
550 vkCmdBindPipeline(demo->draw_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, in demo_draw_build_cmd()
551 demo->pipeline); in demo_draw_build_cmd()
552 vkCmdBindDescriptorSets(demo->draw_cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, in demo_draw_build_cmd()
553 demo->pipeline_layout, 0, 1, &demo->desc_set, 0, in demo_draw_build_cmd()
558 viewport.height = (float)demo->height; in demo_draw_build_cmd()
559 viewport.width = (float)demo->width; in demo_draw_build_cmd()
562 vkCmdSetViewport(demo->draw_cmd, 0, 1, &viewport); in demo_draw_build_cmd()
566 scissor.extent.width = demo->width; in demo_draw_build_cmd()
567 scissor.extent.height = demo->height; in demo_draw_build_cmd()
570 vkCmdSetScissor(demo->draw_cmd, 0, 1, &scissor); in demo_draw_build_cmd()
573 vkCmdBindVertexBuffers(demo->draw_cmd, VERTEX_BUFFER_BIND_ID, 1, in demo_draw_build_cmd()
574 &demo->vertices.buf, offsets); in demo_draw_build_cmd()
576 vkCmdDraw(demo->draw_cmd, 3, 1, 0, 0); in demo_draw_build_cmd()
577 vkCmdEndRenderPass(demo->draw_cmd); in demo_draw_build_cmd()
590 prePresentBarrier.image = demo->buffers[demo->current_buffer].image; in demo_draw_build_cmd()
592 vkCmdPipelineBarrier(demo->draw_cmd, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, in demo_draw_build_cmd()
596 err = vkEndCommandBuffer(demo->draw_cmd); in demo_draw_build_cmd()
609 err = vkCreateSemaphore(demo->device, &presentCompleteSemaphoreCreateInfo, in demo_draw()
614 err = demo->fpAcquireNextImageKHR(demo->device, demo->swapchain, UINT64_MAX, in demo_draw()
617 &demo->current_buffer); in demo_draw()
619 // demo->swapchain is out of date (e.g. the window was resized) and in demo_draw()
623 vkDestroySemaphore(demo->device, presentCompleteSemaphore, NULL); in demo_draw()
626 // demo->swapchain is not as optimal as it could be, but the platform's in demo_draw()
634 demo_set_image_layout(demo, demo->buffers[demo->current_buffer].image, in demo_draw()
656 .pCommandBuffers = &demo->draw_cmd, in demo_draw()
660 err = vkQueueSubmit(demo->queue, 1, &submit_info, nullFence); in demo_draw()
667 .pSwapchains = &demo->swapchain, in demo_draw()
668 .pImageIndices = &demo->current_buffer, in demo_draw()
672 err = demo->fpQueuePresentKHR(demo->queue, &present); in demo_draw()
674 // demo->swapchain is out of date (e.g. the window was resized) and in demo_draw()
678 // demo->swapchain is not as optimal as it could be, but the platform's in demo_draw()
684 err = vkQueueWaitIdle(demo->queue); in demo_draw()
687 vkDestroySemaphore(demo->device, presentCompleteSemaphore, NULL); in demo_draw()
692 VkSwapchainKHR oldSwapchain = demo->swapchain; in demo_prepare_buffers()
696 err = demo->fpGetPhysicalDeviceSurfaceCapabilitiesKHR( in demo_prepare_buffers()
697 demo->gpu, demo->surface, &surfCapabilities); in demo_prepare_buffers()
701 err = demo->fpGetPhysicalDeviceSurfacePresentModesKHR( in demo_prepare_buffers()
702 demo->gpu, demo->surface, &presentModeCount, NULL); in demo_prepare_buffers()
707 err = demo->fpGetPhysicalDeviceSurfacePresentModesKHR( in demo_prepare_buffers()
708 demo->gpu, demo->surface, &presentModeCount, presentModes); in demo_prepare_buffers()
712 // width and height are either both -1, or both not -1. in demo_prepare_buffers()
713 if (surfCapabilities.currentExtent.width == (uint32_t)-1) { in demo_prepare_buffers()
716 swapchainExtent.width = demo->width; in demo_prepare_buffers()
717 swapchainExtent.height = demo->height; in demo_prepare_buffers()
721 demo->width = surfCapabilities.currentExtent.width; in demo_prepare_buffers()
722 demo->height = surfCapabilities.currentExtent.height; in demo_prepare_buffers()
749 .surface = demo->surface, in demo_prepare_buffers()
751 .imageFormat = demo->format, in demo_prepare_buffers()
752 .imageColorSpace = demo->color_space, in demo_prepare_buffers()
770 err = demo->fpCreateSwapchainKHR(demo->device, &swapchain, NULL, in demo_prepare_buffers()
771 &demo->swapchain); in demo_prepare_buffers()
774 // If we just re-created an existing swapchain, we should destroy the old in demo_prepare_buffers()
779 demo->fpDestroySwapchainKHR(demo->device, oldSwapchain, NULL); in demo_prepare_buffers()
782 err = demo->fpGetSwapchainImagesKHR(demo->device, demo->swapchain, in demo_prepare_buffers()
783 &demo->swapchainImageCount, NULL); in demo_prepare_buffers()
787 (VkImage *)malloc(demo->swapchainImageCount * sizeof(VkImage)); in demo_prepare_buffers()
789 err = demo->fpGetSwapchainImagesKHR(demo->device, demo->swapchain, in demo_prepare_buffers()
790 &demo->swapchainImageCount, in demo_prepare_buffers()
794 demo->buffers = (SwapchainBuffers *)malloc(sizeof(SwapchainBuffers) * in demo_prepare_buffers()
795 demo->swapchainImageCount); in demo_prepare_buffers()
796 assert(demo->buffers); in demo_prepare_buffers()
798 for (i = 0; i < demo->swapchainImageCount; i++) { in demo_prepare_buffers()
802 .format = demo->format, in demo_prepare_buffers()
819 demo->buffers[i].image = swapchainImages[i]; in demo_prepare_buffers()
826 demo, demo->buffers[i].image, VK_IMAGE_ASPECT_COLOR_BIT, in demo_prepare_buffers()
829 color_attachment_view.image = demo->buffers[i].image; in demo_prepare_buffers()
831 err = vkCreateImageView(demo->device, &color_attachment_view, NULL, in demo_prepare_buffers()
832 &demo->buffers[i].view); in demo_prepare_buffers()
836 demo->current_buffer = 0; in demo_prepare_buffers()
850 .extent = {demo->width, demo->height, 1}, in demo_prepare_depth()
882 demo->depth.format = depth_format; in demo_prepare_depth()
885 err = vkCreateImage(demo->device, &image, NULL, &demo->depth.image); in demo_prepare_depth()
889 vkGetImageMemoryRequirements(demo->device, demo->depth.image, &mem_reqs); in demo_prepare_depth()
891 /* select memory size and type */ in demo_prepare_depth()
899 err = vkAllocateMemory(demo->device, &mem_alloc, NULL, &demo->depth.mem); in demo_prepare_depth()
904 vkBindImageMemory(demo->device, demo->depth.image, demo->depth.mem, 0); in demo_prepare_depth()
907 demo_set_image_layout(demo, demo->depth.image, VK_IMAGE_ASPECT_DEPTH_BIT, in demo_prepare_depth()
912 view.image = demo->depth.image; in demo_prepare_depth()
913 err = vkCreateImageView(demo->device, &view, NULL, &demo->depth.view); in demo_prepare_depth()
927 tex_obj->tex_width = tex_width; in demo_prepare_texture_image()
928 tex_obj->tex_height = tex_height; in demo_prepare_texture_image()
953 vkCreateImage(demo->device, &image_create_info, NULL, &tex_obj->image); in demo_prepare_texture_image()
956 vkGetImageMemoryRequirements(demo->device, tex_obj->image, &mem_reqs); in demo_prepare_texture_image()
965 err = vkAllocateMemory(demo->device, &mem_alloc, NULL, &tex_obj->mem); in demo_prepare_texture_image()
969 err = vkBindImageMemory(demo->device, tex_obj->image, tex_obj->mem, 0); in demo_prepare_texture_image()
982 vkGetImageSubresourceLayout(demo->device, tex_obj->image, &subres, in demo_prepare_texture_image()
985 err = vkMapMemory(demo->device, tex_obj->mem, 0, in demo_prepare_texture_image()
995 vkUnmapMemory(demo->device, tex_obj->mem); in demo_prepare_texture_image()
998 tex_obj->imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; in demo_prepare_texture_image()
999 demo_set_image_layout(demo, tex_obj->image, VK_IMAGE_ASPECT_COLOR_BIT, in demo_prepare_texture_image()
1000 VK_IMAGE_LAYOUT_UNDEFINED, tex_obj->imageLayout); in demo_prepare_texture_image()
1008 vkDestroyImage(demo->device, tex_obj->image, NULL); in demo_destroy_texture_image()
1009 vkFreeMemory(demo->device, tex_obj->mem, NULL); in demo_destroy_texture_image()
1021 vkGetPhysicalDeviceFormatProperties(demo->gpu, tex_format, &props); in demo_prepare_textures()
1026 !demo->use_staging_buffer) { in demo_prepare_textures()
1027 /* Device can texture using linear textures */ in demo_prepare_textures()
1028 demo_prepare_texture_image(demo, tex_colors[i], &demo->textures[i], in demo_prepare_textures()
1044 demo, tex_colors[i], &demo->textures[i], in demo_prepare_textures()
1054 demo_set_image_layout(demo, demo->textures[i].image, in demo_prepare_textures()
1056 demo->textures[i].imageLayout, in demo_prepare_textures()
1068 demo->setup_cmd, staging_texture.image, in demo_prepare_textures()
1069 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, demo->textures[i].image, in demo_prepare_textures()
1072 demo_set_image_layout(demo, demo->textures[i].image, in demo_prepare_textures()
1075 demo->textures[i].imageLayout); in demo_prepare_textures()
1119 err = vkCreateSampler(demo->device, &sampler, NULL, in demo_prepare_textures()
1120 &demo->textures[i].sampler); in demo_prepare_textures()
1124 view.image = demo->textures[i].image; in demo_prepare_textures()
1125 err = vkCreateImageView(demo->device, &view, NULL, in demo_prepare_textures()
1126 &demo->textures[i].view); in demo_prepare_textures()
1132 // clang-format off in demo_prepare_vertices()
1135 { -1.0f, -1.0f, 0.25f, 0.0f, 0.0f }, in demo_prepare_vertices()
1136 { 1.0f, -1.0f, 0.25f, 1.0f, 0.0f }, in demo_prepare_vertices()
1139 // clang-format on in demo_prepare_vertices()
1158 memset(&demo->vertices, 0, sizeof(demo->vertices)); in demo_prepare_vertices()
1160 err = vkCreateBuffer(demo->device, &buf_info, NULL, &demo->vertices.buf); in demo_prepare_vertices()
1163 vkGetBufferMemoryRequirements(demo->device, demo->vertices.buf, &mem_reqs); in demo_prepare_vertices()
1172 err = vkAllocateMemory(demo->device, &mem_alloc, NULL, &demo->vertices.mem); in demo_prepare_vertices()
1175 err = vkMapMemory(demo->device, demo->vertices.mem, 0, in demo_prepare_vertices()
1181 vkUnmapMemory(demo->device, demo->vertices.mem); in demo_prepare_vertices()
1183 err = vkBindBufferMemory(demo->device, demo->vertices.buf, in demo_prepare_vertices()
1184 demo->vertices.mem, 0); in demo_prepare_vertices()
1187 demo->vertices.vi.sType = in demo_prepare_vertices()
1189 demo->vertices.vi.pNext = NULL; in demo_prepare_vertices()
1190 demo->vertices.vi.vertexBindingDescriptionCount = 1; in demo_prepare_vertices()
1191 demo->vertices.vi.pVertexBindingDescriptions = demo->vertices.vi_bindings; in demo_prepare_vertices()
1192 demo->vertices.vi.vertexAttributeDescriptionCount = 2; in demo_prepare_vertices()
1193 demo->vertices.vi.pVertexAttributeDescriptions = demo->vertices.vi_attrs; in demo_prepare_vertices()
1195 demo->vertices.vi_bindings[0].binding = VERTEX_BUFFER_BIND_ID; in demo_prepare_vertices()
1196 demo->vertices.vi_bindings[0].stride = sizeof(vb[0]); in demo_prepare_vertices()
1197 demo->vertices.vi_bindings[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; in demo_prepare_vertices()
1199 demo->vertices.vi_attrs[0].binding = VERTEX_BUFFER_BIND_ID; in demo_prepare_vertices()
1200 demo->vertices.vi_attrs[0].location = 0; in demo_prepare_vertices()
1201 demo->vertices.vi_attrs[0].format = VK_FORMAT_R32G32B32_SFLOAT; in demo_prepare_vertices()
1202 demo->vertices.vi_attrs[0].offset = 0; in demo_prepare_vertices()
1204 demo->vertices.vi_attrs[1].binding = VERTEX_BUFFER_BIND_ID; in demo_prepare_vertices()
1205 demo->vertices.vi_attrs[1].location = 1; in demo_prepare_vertices()
1206 demo->vertices.vi_attrs[1].format = VK_FORMAT_R32G32_SFLOAT; in demo_prepare_vertices()
1207 demo->vertices.vi_attrs[1].offset = sizeof(float) * 3; in demo_prepare_vertices()
1226 err = vkCreateDescriptorSetLayout(demo->device, &descriptor_layout, NULL, in demo_prepare_descriptor_layout()
1227 &demo->desc_layout); in demo_prepare_descriptor_layout()
1234 .pSetLayouts = &demo->desc_layout, in demo_prepare_descriptor_layout()
1237 err = vkCreatePipelineLayout(demo->device, &pPipelineLayoutCreateInfo, NULL, in demo_prepare_descriptor_layout()
1238 &demo->pipeline_layout); in demo_prepare_descriptor_layout()
1246 .format = demo->format, in demo_prepare_render_pass()
1257 .format = demo->depth.format, in demo_prepare_render_pass()
1300 err = vkCreateRenderPass(demo->device, &rp_info, NULL, &demo->render_pass); in demo_prepare_render_pass()
1316 err = vkCreateShaderModule(demo->device, &moduleCreateInfo, NULL, &module); in demo_prepare_shader_module()
1325 demo->vert_shader_module = in demo_prepare_vs()
1328 return demo->vert_shader_module; in demo_prepare_vs()
1334 demo->frag_shader_module = in demo_prepare_fs()
1337 return demo->frag_shader_module; in demo_prepare_fs()
1363 pipeline.layout = demo->pipeline_layout; in demo_prepare_pipeline()
1365 vi = demo->vertices.vi; in demo_prepare_pipeline()
1438 pipeline.renderPass = demo->render_pass; in demo_prepare_pipeline()
1444 err = vkCreatePipelineCache(demo->device, &pipelineCache, NULL, in demo_prepare_pipeline()
1445 &demo->pipelineCache); in demo_prepare_pipeline()
1447 err = vkCreateGraphicsPipelines(demo->device, demo->pipelineCache, 1, in demo_prepare_pipeline()
1448 &pipeline, NULL, &demo->pipeline); in demo_prepare_pipeline()
1451 vkDestroyPipelineCache(demo->device, demo->pipelineCache, NULL); in demo_prepare_pipeline()
1453 vkDestroyShaderModule(demo->device, demo->frag_shader_module, NULL); in demo_prepare_pipeline()
1454 vkDestroyShaderModule(demo->device, demo->vert_shader_module, NULL); in demo_prepare_pipeline()
1471 err = vkCreateDescriptorPool(demo->device, &descriptor_pool, NULL, in demo_prepare_descriptor_pool()
1472 &demo->desc_pool); in demo_prepare_descriptor_pool()
1485 .descriptorPool = demo->desc_pool, in demo_prepare_descriptor_set()
1487 .pSetLayouts = &demo->desc_layout}; in demo_prepare_descriptor_set()
1488 err = vkAllocateDescriptorSets(demo->device, &alloc_info, &demo->desc_set); in demo_prepare_descriptor_set()
1493 tex_descs[i].sampler = demo->textures[i].sampler; in demo_prepare_descriptor_set()
1494 tex_descs[i].imageView = demo->textures[i].view; in demo_prepare_descriptor_set()
1500 write.dstSet = demo->desc_set; in demo_prepare_descriptor_set()
1505 vkUpdateDescriptorSets(demo->device, 1, &write, 0, NULL); in demo_prepare_descriptor_set()
1510 attachments[1] = demo->depth.view; in demo_prepare_framebuffers()
1515 .renderPass = demo->render_pass, in demo_prepare_framebuffers()
1518 .width = demo->width, in demo_prepare_framebuffers()
1519 .height = demo->height, in demo_prepare_framebuffers()
1525 demo->framebuffers = (VkFramebuffer *)malloc(demo->swapchainImageCount * in demo_prepare_framebuffers()
1527 assert(demo->framebuffers); in demo_prepare_framebuffers()
1529 for (i = 0; i < demo->swapchainImageCount; i++) { in demo_prepare_framebuffers()
1530 attachments[0] = demo->buffers[i].view; in demo_prepare_framebuffers()
1531 err = vkCreateFramebuffer(demo->device, &fb_info, NULL, in demo_prepare_framebuffers()
1532 &demo->framebuffers[i]); in demo_prepare_framebuffers()
1543 .queueFamilyIndex = demo->graphics_queue_node_index, in demo_prepare()
1546 err = vkCreateCommandPool(demo->device, &cmd_pool_info, NULL, in demo_prepare()
1547 &demo->cmd_pool); in demo_prepare()
1553 .commandPool = demo->cmd_pool, in demo_prepare()
1557 err = vkAllocateCommandBuffers(demo->device, &cmd, &demo->draw_cmd); in demo_prepare()
1591 demo->width = width; in demo_resize_callback()
1592 demo->height = height; in demo_resize_callback()
1597 while (!glfwWindowShouldClose(demo->window)) { in demo_run()
1602 if (demo->depthStencil > 0.99f) in demo_run()
1603 demo->depthIncrement = -0.001f; in demo_run()
1604 if (demo->depthStencil < 0.8f) in demo_run()
1605 demo->depthIncrement = 0.001f; in demo_run()
1607 demo->depthStencil += demo->depthIncrement; in demo_run()
1610 vkDeviceWaitIdle(demo->device); in demo_run()
1617 demo->window = glfwCreateWindow(demo->width, in demo_create_window()
1618 demo->height, in demo_create_window()
1622 if (!demo->window) { in demo_create_window()
1629 glfwSetWindowUserPointer(demo->window, demo); in demo_create_window()
1630 glfwSetWindowRefreshCallback(demo->window, demo_refresh_callback); in demo_create_window()
1631 glfwSetFramebufferSizeCallback(demo->window, demo_resize_callback); in demo_create_window()
1632 glfwSetKeyCallback(demo->window, demo_key_callback); in demo_create_window()
1636 * Return 1 (true) if all layer names specified in check_names
1637 * can be found in given layer properties.
1652 fprintf(stderr, "Cannot find layer: %s\n", check_names[i]); in demo_check_layers()
1691 demo->enabled_extension_count = 0; in demo_init_vk()
1692 demo->enabled_layer_count = 0; in demo_init_vk()
1699 demo->device_validation_layers[0] = "VK_LAYER_LUNARG_mem_tracker"; in demo_init_vk()
1700 demo->device_validation_layers[1] = "VK_LAYER_GOOGLE_unique_objects"; in demo_init_vk()
1715 if (demo->validate) { in demo_init_vk()
1720 demo->enabled_layer_count = ARRAY_SIZE(instance_validation_layers); in demo_init_vk()
1726 if (demo->validate && !validation_found) { in demo_init_vk()
1728 "required validation layer.\n\n" in demo_init_vk()
1739 "Vulkan installable client driver (ICD) installed?\nPlease " in demo_init_vk()
1746 demo->extension_names[demo->enabled_extension_count++] = required_extensions[i]; in demo_init_vk()
1747 assert(demo->enabled_extension_count < 64); in demo_init_vk()
1763 if (demo->validate) { in demo_init_vk()
1764 demo->extension_names[demo->enabled_extension_count++] = in demo_init_vk()
1768 assert(demo->enabled_extension_count < 64); in demo_init_vk()
1787 .enabledLayerCount = demo->enabled_layer_count, in demo_init_vk()
1789 .enabledExtensionCount = demo->enabled_extension_count, in demo_init_vk()
1790 .ppEnabledExtensionNames = (const char *const *)demo->extension_names, in demo_init_vk()
1795 demo->allocator.pfnAllocation = myalloc; in demo_init_vk()
1796 demo->allocator.pfnFree = myfree; in demo_init_vk()
1797 demo->allocator.pfnReallocation = myrealloc; in demo_init_vk()
1799 err = vkCreateInstance(&inst_info, &demo->allocator, &demo->inst); in demo_init_vk()
1801 ERR_EXIT("Cannot find a compatible Vulkan installable client driver " in demo_init_vk()
1810 ERR_EXIT("vkCreateInstance failed.\n\nDo you have a compatible Vulkan " in demo_init_vk()
1817 err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, NULL); in demo_init_vk()
1823 err = vkEnumeratePhysicalDevices(demo->inst, &gpu_count, in demo_init_vk()
1826 /* For tri demo we just grab the first physical device */ in demo_init_vk()
1827 demo->gpu = physical_devices[0]; in demo_init_vk()
1831 "\n\nDo you have a compatible Vulkan installable client" in demo_init_vk()
1839 demo->enabled_layer_count = 0; in demo_init_vk()
1842 vkEnumerateDeviceLayerProperties(demo->gpu, &device_layer_count, NULL); in demo_init_vk()
1848 err = vkEnumerateDeviceLayerProperties(demo->gpu, &device_layer_count, in demo_init_vk()
1852 if (demo->validate) { in demo_init_vk()
1854 demo->device_validation_layers, in demo_init_vk()
1857 demo->enabled_layer_count = device_validation_layer_count; in demo_init_vk()
1863 if (demo->validate && !validation_found) { in demo_init_vk()
1865 "a required validation layer.\n\n" in demo_init_vk()
1871 /* Look for device extensions */ in demo_init_vk()
1874 demo->enabled_extension_count = 0; in demo_init_vk()
1876 err = vkEnumerateDeviceExtensionProperties(demo->gpu, NULL, in demo_init_vk()
1884 demo->gpu, NULL, &device_extension_count, device_extensions); in demo_init_vk()
1891 demo->extension_names[demo->enabled_extension_count++] = in demo_init_vk()
1894 assert(demo->enabled_extension_count < 64); in demo_init_vk()
1904 "Vulkan installable client driver (ICD) installed?\nPlease " in demo_init_vk()
1910 if (demo->validate) { in demo_init_vk()
1911 demo->CreateDebugReportCallback = in demo_init_vk()
1913 demo->inst, "vkCreateDebugReportCallbackEXT"); in demo_init_vk()
1914 if (!demo->CreateDebugReportCallback) { in demo_init_vk()
1926 err = demo->CreateDebugReportCallback(demo->inst, &dbgCreateInfo, NULL, in demo_init_vk()
1927 &demo->msg_callback); in demo_init_vk()
1942 // Having these GIPA queries of device extension entry points both in demo_init_vk()
1944 GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfaceCapabilitiesKHR); in demo_init_vk()
1945 GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfaceFormatsKHR); in demo_init_vk()
1946 GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfacePresentModesKHR); in demo_init_vk()
1947 GET_INSTANCE_PROC_ADDR(demo->inst, GetPhysicalDeviceSurfaceSupportKHR); in demo_init_vk()
1948 GET_INSTANCE_PROC_ADDR(demo->inst, CreateSwapchainKHR); in demo_init_vk()
1949 GET_INSTANCE_PROC_ADDR(demo->inst, DestroySwapchainKHR); in demo_init_vk()
1950 GET_INSTANCE_PROC_ADDR(demo->inst, GetSwapchainImagesKHR); in demo_init_vk()
1951 GET_INSTANCE_PROC_ADDR(demo->inst, AcquireNextImageKHR); in demo_init_vk()
1952 GET_INSTANCE_PROC_ADDR(demo->inst, QueuePresentKHR); in demo_init_vk()
1954 vkGetPhysicalDeviceProperties(demo->gpu, &demo->gpu_props); in demo_init_vk()
1957 vkGetPhysicalDeviceQueueFamilyProperties(demo->gpu, &demo->queue_count, in demo_init_vk()
1960 demo->queue_props = (VkQueueFamilyProperties *)malloc( in demo_init_vk()
1961 demo->queue_count * sizeof(VkQueueFamilyProperties)); in demo_init_vk()
1962 vkGetPhysicalDeviceQueueFamilyProperties(demo->gpu, &demo->queue_count, in demo_init_vk()
1963 demo->queue_props); in demo_init_vk()
1964 assert(demo->queue_count >= 1); in demo_init_vk()
1978 .queueFamilyIndex = demo->graphics_queue_node_index, in demo_init_device()
1982 VkDeviceCreateInfo device = { in demo_init_device() local
1987 .enabledLayerCount = demo->enabled_layer_count, in demo_init_device()
1989 (const char *const *)((demo->validate) in demo_init_device()
1990 ? demo->device_validation_layers in demo_init_device()
1992 .enabledExtensionCount = demo->enabled_extension_count, in demo_init_device()
1993 .ppEnabledExtensionNames = (const char *const *)demo->extension_names, in demo_init_device()
1996 err = vkCreateDevice(demo->gpu, &device, NULL, &demo->device); in demo_init_device()
1999 GET_DEVICE_PROC_ADDR(demo->device, CreateSwapchainKHR); in demo_init_device()
2000 GET_DEVICE_PROC_ADDR(demo->device, DestroySwapchainKHR); in demo_init_device()
2001 GET_DEVICE_PROC_ADDR(demo->device, GetSwapchainImagesKHR); in demo_init_device()
2002 GET_DEVICE_PROC_ADDR(demo->device, AcquireNextImageKHR); in demo_init_device()
2003 GET_DEVICE_PROC_ADDR(demo->device, QueuePresentKHR); in demo_init_device()
2011 glfwCreateWindowSurface(demo->inst, demo->window, NULL, &demo->surface); in demo_init_vk_swapchain()
2015 (VkBool32 *)malloc(demo->queue_count * sizeof(VkBool32)); in demo_init_vk_swapchain()
2016 for (i = 0; i < demo->queue_count; i++) { in demo_init_vk_swapchain()
2017 demo->fpGetPhysicalDeviceSurfaceSupportKHR(demo->gpu, i, demo->surface, in demo_init_vk_swapchain()
2025 for (i = 0; i < demo->queue_count; i++) { in demo_init_vk_swapchain()
2026 if ((demo->queue_props[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) != 0) { in demo_init_vk_swapchain()
2041 for (i = 0; i < demo->queue_count; ++i) { in demo_init_vk_swapchain()
2067 demo->graphics_queue_node_index = graphicsQueueNodeIndex; in demo_init_vk_swapchain()
2071 vkGetDeviceQueue(demo->device, demo->graphics_queue_node_index, 0, in demo_init_vk_swapchain()
2072 &demo->queue); in demo_init_vk_swapchain()
2076 err = demo->fpGetPhysicalDeviceSurfaceFormatsKHR(demo->gpu, demo->surface, in demo_init_vk_swapchain()
2081 err = demo->fpGetPhysicalDeviceSurfaceFormatsKHR(demo->gpu, demo->surface, in demo_init_vk_swapchain()
2088 demo->format = VK_FORMAT_B8G8R8A8_UNORM; in demo_init_vk_swapchain()
2091 demo->format = surfFormats[0].format; in demo_init_vk_swapchain()
2093 demo->color_space = surfFormats[0].colorSpace; in demo_init_vk_swapchain()
2096 vkGetPhysicalDeviceMemoryProperties(demo->gpu, &demo->memory_properties); in demo_init_vk_swapchain()
2109 printf("GLFW failed to find the Vulkan loader.\nExiting ...\n"); in demo_init_connection()
2122 if (strncmp(argv[i], "--use_staging", strlen("--use_staging")) == 0) in demo_init()
2123 demo->use_staging_buffer = true; in demo_init()
2129 demo->width = 300; in demo_init()
2130 demo->height = 300; in demo_init()
2131 demo->depthStencil = 1.0; in demo_init()
2132 demo->depthIncrement = -0.01f; in demo_init()
2138 for (i = 0; i < demo->swapchainImageCount; i++) { in demo_cleanup()
2139 vkDestroyFramebuffer(demo->device, demo->framebuffers[i], NULL); in demo_cleanup()
2141 free(demo->framebuffers); in demo_cleanup()
2142 vkDestroyDescriptorPool(demo->device, demo->desc_pool, NULL); in demo_cleanup()
2144 if (demo->setup_cmd) { in demo_cleanup()
2145 vkFreeCommandBuffers(demo->device, demo->cmd_pool, 1, &demo->setup_cmd); in demo_cleanup()
2147 vkFreeCommandBuffers(demo->device, demo->cmd_pool, 1, &demo->draw_cmd); in demo_cleanup()
2148 vkDestroyCommandPool(demo->device, demo->cmd_pool, NULL); in demo_cleanup()
2150 vkDestroyPipeline(demo->device, demo->pipeline, NULL); in demo_cleanup()
2151 vkDestroyRenderPass(demo->device, demo->render_pass, NULL); in demo_cleanup()
2152 vkDestroyPipelineLayout(demo->device, demo->pipeline_layout, NULL); in demo_cleanup()
2153 vkDestroyDescriptorSetLayout(demo->device, demo->desc_layout, NULL); in demo_cleanup()
2155 vkDestroyBuffer(demo->device, demo->vertices.buf, NULL); in demo_cleanup()
2156 vkFreeMemory(demo->device, demo->vertices.mem, NULL); in demo_cleanup()
2159 vkDestroyImageView(demo->device, demo->textures[i].view, NULL); in demo_cleanup()
2160 vkDestroyImage(demo->device, demo->textures[i].image, NULL); in demo_cleanup()
2161 vkFreeMemory(demo->device, demo->textures[i].mem, NULL); in demo_cleanup()
2162 vkDestroySampler(demo->device, demo->textures[i].sampler, NULL); in demo_cleanup()
2165 for (i = 0; i < demo->swapchainImageCount; i++) { in demo_cleanup()
2166 vkDestroyImageView(demo->device, demo->buffers[i].view, NULL); in demo_cleanup()
2169 vkDestroyImageView(demo->device, demo->depth.view, NULL); in demo_cleanup()
2170 vkDestroyImage(demo->device, demo->depth.image, NULL); in demo_cleanup()
2171 vkFreeMemory(demo->device, demo->depth.mem, NULL); in demo_cleanup()
2173 demo->fpDestroySwapchainKHR(demo->device, demo->swapchain, NULL); in demo_cleanup()
2174 free(demo->buffers); in demo_cleanup()
2176 vkDestroyDevice(demo->device, NULL); in demo_cleanup()
2177 vkDestroySurfaceKHR(demo->inst, demo->surface, NULL); in demo_cleanup()
2178 vkDestroyInstance(demo->inst, &demo->allocator); in demo_cleanup()
2180 free(demo->queue_props); in demo_cleanup()
2182 glfwDestroyWindow(demo->window); in demo_cleanup()
2189 for (i = 0; i < demo->swapchainImageCount; i++) { in demo_resize()
2190 vkDestroyFramebuffer(demo->device, demo->framebuffers[i], NULL); in demo_resize()
2192 free(demo->framebuffers); in demo_resize()
2193 vkDestroyDescriptorPool(demo->device, demo->desc_pool, NULL); in demo_resize()
2195 if (demo->setup_cmd) { in demo_resize()
2196 vkFreeCommandBuffers(demo->device, demo->cmd_pool, 1, &demo->setup_cmd); in demo_resize()
2198 vkFreeCommandBuffers(demo->device, demo->cmd_pool, 1, &demo->draw_cmd); in demo_resize()
2199 vkDestroyCommandPool(demo->device, demo->cmd_pool, NULL); in demo_resize()
2201 vkDestroyPipeline(demo->device, demo->pipeline, NULL); in demo_resize()
2202 vkDestroyRenderPass(demo->device, demo->render_pass, NULL); in demo_resize()
2203 vkDestroyPipelineLayout(demo->device, demo->pipeline_layout, NULL); in demo_resize()
2204 vkDestroyDescriptorSetLayout(demo->device, demo->desc_layout, NULL); in demo_resize()
2206 vkDestroyBuffer(demo->device, demo->vertices.buf, NULL); in demo_resize()
2207 vkFreeMemory(demo->device, demo->vertices.mem, NULL); in demo_resize()
2210 vkDestroyImageView(demo->device, demo->textures[i].view, NULL); in demo_resize()
2211 vkDestroyImage(demo->device, demo->textures[i].image, NULL); in demo_resize()
2212 vkFreeMemory(demo->device, demo->textures[i].mem, NULL); in demo_resize()
2213 vkDestroySampler(demo->device, demo->textures[i].sampler, NULL); in demo_resize()
2216 for (i = 0; i < demo->swapchainImageCount; i++) { in demo_resize()
2217 vkDestroyImageView(demo->device, demo->buffers[i].view, NULL); in demo_resize()
2220 vkDestroyImageView(demo->device, demo->depth.view, NULL); in demo_resize()
2221 vkDestroyImage(demo->device, demo->depth.image, NULL); in demo_resize()
2222 vkFreeMemory(demo->device, demo->depth.mem, NULL); in demo_resize()
2224 free(demo->buffers); in demo_resize()
2226 // Second, re-perform the demo_prepare() function, which will re-create the in demo_resize()