+bool vku_create_renderpass()
+{
+ VkAttachmentDescription attachments[2];
+ memset(&attachments, 0, 2 * sizeof *attachments);
+
+ /* color */
+ attachments[0].format = VK_FORMAT_B8G8R8A8_UNORM;
+ attachments[0].samples = VK_SAMPLE_COUNT_1_BIT;
+ attachments[0].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
+ attachments[0].storeOp = VK_ATTACHMENT_STORE_OP_STORE;
+ attachments[0].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ attachments[0].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ attachments[0].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+ attachments[0].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
+ /* depth */
+ attachments[1].format = VK_FORMAT_D32_SFLOAT_S8_UINT; //TODO
+ attachments[1].samples = VK_SAMPLE_COUNT_1_BIT;
+ attachments[1].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
+ attachments[1].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ attachments[1].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
+ attachments[1].stencilStoreOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
+ attachments[1].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+ attachments[1].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+
+ VkAttachmentReference color_ref;
+ color_ref.attachment = 0;
+ color_ref.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
+
+ VkAttachmentReference depth_ref;
+ depth_ref.attachment = 1;
+ depth_ref.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
+
+ VkSubpassDescription subpass_desc;
+ memset(&subpass_desc, 0, sizeof subpass_desc);
+
+ subpass_desc.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
+ subpass_desc.colorAttachmentCount = 1;
+ subpass_desc.pColorAttachments = &color_ref;
+ subpass_desc.pDepthStencilAttachment = &depth_ref;
+
+ VkRenderPassCreateInfo inf;
+ memset(&inf, 0, sizeof inf);
+
+ inf.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
+ inf.attachmentCount = 2;
+ inf.pAttachments = attachments;
+ inf.subpassCount = 1;
+ inf.pSubpasses = &subpass_desc;
+
+ if(vkCreateRenderPass(vkdev, &inf, 0, &vkrpass) != VK_SUCCESS) {
+ return false;
+ }
+
+ return true;
+}
+
+bool vku_create_framebuffers(VkImageView *image_views, int count, int w, int h)
+{
+ delete vkfbufs;
+ vkfbufs = new VkFramebuffer[count];
+
+ VkFramebufferCreateInfo inf;
+ memset(&inf, 0, sizeof inf);
+
+ inf.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
+ inf.renderPass = vkrpass;
+ inf.attachmentCount = count;
+ inf.pAttachments = image_views;
+ inf.width = w;
+ inf.height = h;
+ inf.layers = 1;
+
+ for(int i=0; i<count; i++) {
+ if(vkCreateFramebuffer(vkdev, &inf, 0, &vkfbufs[i]) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create framebuffer for image view: %d\n", i);
+ delete vkfbufs;
+ return false;
+ }
+ }
+ return true;
+}
+