backup
[demo] / src / vulkan / vk.cc
index 9297e63..a0f7751 100644 (file)
@@ -56,10 +56,11 @@ static void begin_drawing();
 static void end_drawing();
 
 static bool create_swapchain(VkSwapchainKHR *sc);
-static bool begin_init_command_buffer(VkCommandBuffer *cb);
 static bool create_zbuffer();
 static bool create_renderpass();
-static bool create_framebuffers(VkFramebuffer *fb, VkImageView *views);
+static bool create_framebuffers();
+static bool create_pipelines();
+static bool begin_init_command_buffer(VkCommandBuffer *cb);
 static bool end_init_command_buffer(VkCommandBuffer *cb);
 static bool allocate_rendering_command_buffers(VkCommandBuffer *bufs);
 static void free_rendering_command_buffers(VkCommandBuffer *bufs, int count);
@@ -124,11 +125,16 @@ bool init_vulkan()
                return false;
        }
 
-       if(!create_framebuffers(fbs, iviews)) {
+       if(!create_framebuffers()) {
                fprintf(stderr, "Failed to create the framebuffer.\n");
                return false;
        }
 
+       if(!create_pipelines()) {
+               fprintf(stderr, "Failed to create the pipelines.\n");
+               return false;
+       }
+
        if(!end_init_command_buffer(&init_buf)) {
                fprintf(stderr, "Failed to end the command buffer.\n");
                return false;
@@ -442,7 +448,7 @@ static bool create_renderpass()
        return true;
 }
 
-static bool create_framebuffers(VkFramebuffer *fb, VkImageView *views)
+static bool create_framebuffers()
 {
        /* framebuffer attachments */
        VkImageView fb_att[2];
@@ -459,8 +465,8 @@ static bool create_framebuffers(VkFramebuffer *fb, VkImageView *views)
        fbinf.layers = 1;
 
        for(int i=0; i<2; i++) {
-               fb_att[0] = views[i];
-               if(vkCreateFramebuffer(vk_device, &fbinf, 0, &fb[i]) != VK_SUCCESS) {
+               fb_att[0] = iviews[i];
+               if(vkCreateFramebuffer(vk_device, &fbinf, 0, &fbs[i]) != VK_SUCCESS) {
                        fprintf(stderr, "Failed to create framebuffer %i\n", i);
                        return false;
                }
@@ -468,6 +474,57 @@ static bool create_framebuffers(VkFramebuffer *fb, VkImageView *views)
        return true;
 }
 
+static bool create_pipelines()
+{
+       VkDescriptorSetLayoutBinding dslb[1];
+       memset(&dslb[0], 0, sizeof dslb[0]);
+       dslb[0].binding = 0;
+       dslb[0].descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
+       dslb[0].descriptorCount = 1;
+       dslb[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
+
+       VkDescriptorSetLayoutCreateInfo dslinf;
+       memset(&dslinf, 0, sizeof dslinf);
+       dslinf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
+       dslinf.bindingCount = 1; //dslb.size();
+       dslinf.pBindings = dslb;
+
+       VkDescriptorSetLayout dsl;
+       if(vkCreateDescriptorSetLayout(vk_device, &dslinf, 0, &dsl) != VK_SUCCESS) {
+               fprintf(stderr, "Failed to create descriptor set layout.\n");
+               return false;
+       }
+
+       VkPipelineLayoutCreateInfo pinf;
+       memset(&pinf, 0, sizeof pinf);
+       pinf.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
+       pinf.setLayoutCount = 1;
+       pinf.pSetLayouts = &dsl;
+
+       VkPipelineLayout pl;
+       if(vkCreatePipelineLayout(vk_device, &pinf, 0, &pl) != VK_SUCCESS) {
+               fprintf(stderr, "Failed to create pipeline layout.\n");
+               return false;
+       }
+
+       VkPipelineCacheCreateInfo pcinf;
+       memset(&pcinf, 0, sizeof pcinf);
+       pcinf.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
+
+       VkPipelineCache pcache;
+       if(vkCreatePipelineCache(vk_device, &pcinf, 0, &pcache) != VK_SUCCESS) {
+               fprintf(stderr, "Failed to create pipeline cache.\n");
+               return false;
+       }
+
+       VkGraphicsPipelineCreateInfo ginf;
+       memset(&ginf, 0, sizeof ginf);
+       ginf.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
+       ginf.stageCount = 2;
+
+       return true;
+}
+
 static bool end_init_command_buffer(VkCommandBuffer *cb)
 {
        if(vkEndCommandBuffer(*cb) != VK_SUCCESS) {