+// vkswapchain_views = vku_create_image_views(vkswapchain_images, vknum_swapchain_images);
+// if(!vkswapchain_views) {
+// fprintf(stderr, "Failed to create swapchain image views.\n");
+// delete [] vkswapchain_images;
+// return false;
+// }
+
+ if(!create_swapchain_cmd_bufs(vk_pool)) {
+ return false;
+ }
+
+ if(!record_cmd_clear(1.0, 0.1, 0.1))
+ return false;
+ */
+
+ return true;
+}
+
+static bool create_swapchain()
+{
+ /* surface capabilities */
+ VkSurfaceCapabilitiesKHR scap;
+ if(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(vk_physical, vk_surface, &scap) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to get physical device surface capabilities\n");
+ return false;
+ }
+
+ /* presentation modes */
+ uint32_t prmode_cnt;
+ if(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physical, vk_surface, &prmode_cnt, 0) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to get physical device surface presentation modes count.\n");
+ return false;
+ }
+
+ if(prmode_cnt == 0) {
+ fprintf(stderr, "Presentation modes not found.\n");
+ return false;
+ }
+
+ VkPresentModeKHR scmode = VK_PRESENT_MODE_FIFO_KHR;
+ VkPresentModeKHR *modes = new VkPresentModeKHR[prmode_cnt];
+
+ if(vkGetPhysicalDeviceSurfacePresentModesKHR(vk_physical, vk_surface, &prmode_cnt, modes) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to get physical device presentation modes.\n");
+ return false;
+ }
+
+ for(uint32_t i=0; i<prmode_cnt; i++) {
+ if(modes[i] == VK_PRESENT_MODE_MAILBOX_KHR) {
+ scmode = VK_PRESENT_MODE_MAILBOX_KHR;
+ break;
+ }
+ if((scmode != VK_PRESENT_MODE_MAILBOX_KHR) && (modes[i] == VK_PRESENT_MODE_IMMEDIATE_KHR)) {
+ //fallback
+ scmode = VK_PRESENT_MODE_IMMEDIATE_KHR;
+ }
+ }
+
+ /* swapchain extents */
+ VkExtent2D scextent;
+ if(scap.currentExtent.width == 0xffffffff || scap.currentExtent.height == 0xffffffff) {
+ scextent.width = win_w;
+ scextent.height = win_h;
+ }
+ else {
+ scextent = scap.currentExtent;
+ win_w = scextent.width;
+ win_h = scextent.height;
+ }
+
+ /* number of swapchain images (on intel that's 3: maybe should hardcode it to 2?) */
+ num_images = scap.minImageCount; //+ 1;
+ /* intel doesn't set the maxImageCount */
+ if(scap.maxImageCount > 0 && num_images > scap.maxImageCount)
+ num_images = scap.maxImageCount;
+
+ printf("num_images : %u\n", num_images);
+ assert(num_images > 0);
+
+ /* transform flags */
+ VkSurfaceTransformFlagBitsKHR pre_transf = scap.currentTransform;
+ if(scap.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR)
+ pre_transf = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;
+
+ /* find suitable colorspace, format */
+ uint32_t fcount;
+ if(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical, vk_surface, &fcount, 0) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to get format count for physical device.\n");
+ return false;
+ }
+ if(fcount == 0) {
+ fprintf(stderr, "No color formats were found.\n");
+ return false;
+ }
+
+ VkFormat format;
+ VkColorSpaceKHR colorspace;
+
+ VkSurfaceFormatKHR *formats = new VkSurfaceFormatKHR[fcount];
+ if(vkGetPhysicalDeviceSurfaceFormatsKHR(vk_physical, vk_surface, &fcount, formats) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to get surface formats.\n");
+ return false;
+ }
+ if((fcount == 1) && (formats[0].format == VK_FORMAT_UNDEFINED)) {
+ format = VK_FORMAT_B8G8R8_UNORM;
+ } else {
+ format = formats[0].format;
+ }
+ colorspace = formats[0].colorSpace;
+
+ /* creating the swapchain */
+ VkSwapchainCreateInfoKHR sinfo;
+ memset(&sinfo, 0, sizeof sinfo);
+
+ sinfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
+ sinfo.surface = vk_surface;
+ sinfo.minImageCount = num_images;
+ sinfo.imageFormat = format;
+ sinfo.imageColorSpace = colorspace;
+ sinfo.imageExtent = scextent;
+ sinfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+ sinfo.preTransform = pre_transf;
+ sinfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
+ sinfo.imageArrayLayers = 1;
+ sinfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
+ sinfo.presentMode = scmode;
+ sinfo.oldSwapchain = VK_NULL_HANDLE; //TODO
+ sinfo.clipped = VK_TRUE; //TODO
+
+ if(vkCreateSwapchainKHR(vk_device, &sinfo, 0, &vk_swapchain) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create swapchain.\n");
+ return false;
+ }
+
+ if(vkGetSwapchainImagesKHR(vk_device, vk_swapchain, &num_images, 0) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to get the number of the swapchain images.\n");
+ return false;
+ }
+
+ images = new VkImage[num_images];
+ if(vkGetSwapchainImagesKHR(vk_device, vk_swapchain, &num_images, images) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to get the swapchain images.\n");
+ return false;
+ }
+ assert(images);
+
+ if(!create_swapchain_image_views(format)) {
+ fprintf(stderr, "Failed to create image views for the swapchain images.\n");
+ return false;
+ }
+
+ // create renderpass
+
+
+ return true;
+}
+
+static bool create_swapchain_image_views(VkFormat format)
+{
+ VkImageViewCreateInfo ivinf;
+ memset(&ivinf, 0, sizeof ivinf);
+
+ ivinf.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
+ ivinf.format = format;
+ ivinf.components = {
+ VK_COMPONENT_SWIZZLE_R,
+ VK_COMPONENT_SWIZZLE_G,
+ VK_COMPONENT_SWIZZLE_B,
+ VK_COMPONENT_SWIZZLE_A
+ };
+ ivinf.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
+ ivinf.subresourceRange.levelCount = 1;
+ ivinf.subresourceRange.layerCount = 1;
+ ivinf.viewType = VK_IMAGE_VIEW_TYPE_2D;
+
+ iviews = new VkImageView[num_images];
+ for(uint32_t i=0; i<num_images; i++) {
+ ivinf.image = images[i];
+ if(vkCreateImageView(vk_device, &ivinf, 0, &iviews[i]) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create view for the swapchain image: %d.\n", i);