+
+vku_descriptor *vku_create_descriptor(VkDescriptorType type,
+ VkFlags stage, int binding_point,
+ int size, int num_desc)
+{
+ vku_descriptor *desc = new vku_descriptor;
+
+ desc->type = type;
+ desc->size = size;
+ desc->stage_flags = stage;
+ desc->binding_point = binding_point;
+
+ VkDescriptorSetLayoutBinding dslb;
+ memset(&dslb, 0, sizeof dslb);
+
+ dslb.binding = binding_point;
+ dslb.descriptorType = type;
+ dslb.descriptorCount = num_desc;
+ dslb.stageFlags = stage;
+
+ VkDescriptorSetLayoutCreateInfo dslinf;
+ memset(&dslinf, 0, sizeof dslinf);
+
+ dslinf.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
+ dslinf.bindingCount = 1;
+ dslinf.pBindings = &dslb;
+
+ if(vkCreateDescriptorSetLayout(vk_device, &dslinf, 0, &desc->layout) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create vku_descriptor.\n");
+ return 0;
+ }
+
+ return desc;
+}
+
+void vku_destroy_descriptor(vku_descriptor *desc)
+{
+ vkDestroyDescriptorSetLayout(vk_device, desc->layout, 0);
+ delete desc;
+}
+
+bool vku_create_descriptor_pool(vku_descriptor **descriptors, int num_desc)
+{
+ if(vk_dpool)
+ vkDestroyDescriptorPool(vk_device, vk_dpool, 0);
+
+ VkDescriptorPoolCreateInfo dpinf;
+ memset(&dpinf, 0, sizeof dpinf);
+ dpinf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
+ dpinf.maxSets = 1;
+
+ dpinf.poolSizeCount = num_desc;
+
+ std::vector<VkDescriptorPoolSize> sizes;
+ for(int i=0; i<num_desc; i++) {
+ VkDescriptorPoolSize psz;
+ psz.type = descriptors[i]->type;
+ psz.descriptorCount = 1;
+ sizes.push_back(psz);
+ }
+
+ dpinf.pPoolSizes = sizes.data();
+
+ if(vkCreateDescriptorPool(vk_device, &dpinf, 0, &vk_dpool) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create descriptor pool.\n");
+ return false;
+ }
+
+ return true;
+}
+
+void vku_destroy_descriptor_pool()
+{
+ vkDestroyDescriptorPool(vk_device, vk_dpool, 0);
+}
+
+bool vku_allocate_descriptor_sets(vku_descriptor **desc, int num_desc, VkDescriptorSet set)
+{
+ VkDescriptorSetAllocateInfo dainf;
+ memset(&dainf, 0, sizeof dainf);
+
+ dainf.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
+ dainf.descriptorPool = vk_dpool;
+ dainf.descriptorSetCount = num_desc;
+
+ std::vector<VkDescriptorSetLayout> layouts;
+ for(int i=0; i<num_desc; i++) {
+ layouts.push_back(desc[i]->layout);
+ }
+
+ dainf.pSetLayouts = layouts.data();
+
+ if(vkAllocateDescriptorSets(vk_device, &dainf, &set) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to allocate descriptor sets.\n");
+ return false;
+ }
+ return true;
+}
+
+void vku_free_descriptor_sets(VkDescriptorSet *sets, int num)
+{
+ vkFreeDescriptorSets(vk_device, vk_dpool, num, sets);
+}
+
+bool vku_update_descriptor_sets(VkDescriptorSet *sets, int num_sets)
+{
+// std::vector
+ return true;
+}
+
+VkPipelineCache vku_create_pipeline_cache()
+{
+ VkPipelineCacheCreateInfo cinf;
+ memset(&cinf, 0, sizeof cinf);
+ cinf.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
+
+ VkPipelineCache cache;
+ if(vkCreatePipelineCache(vk_device, &cinf, 0, &cache) != VK_SUCCESS) {
+ fprintf(stderr, "Failed to create pipeline cache.\n");
+ return 0;
+ }
+ return cache;
+}
+
+void vku_destroy_pipeline_cache(VkPipelineCache cache)
+{
+ vkDestroyPipelineCache(vk_device, cache, 0);
+}
+
+void vku_pl_init_shader_stage_state_info(VkPipelineShaderStageCreateInfo *ssinf,
+ VkShaderStageFlagBits stage, VkShaderModule sm)
+{
+ memset(ssinf, 0, sizeof *ssinf);
+ ssinf->sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ ssinf->stage = stage;
+ ssinf->module = sm;
+ ssinf->pName = "main";
+}
+
+void vku_pl_init_input_asm_state_info(VkPipelineInputAssemblyStateCreateInfo *iasinf)
+{
+ memset(iasinf, 0, sizeof *iasinf);
+ iasinf->sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
+ iasinf->topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
+}
+
+void vku_pl_init_viewport_state_info(VkPipelineViewportStateCreateInfo *vsinf,
+ VkViewport *viewports, int num_viewports, VkRect2D *scissors,
+ int num_scissors)
+{
+ memset(vsinf, 0, sizeof *vsinf);
+ vsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
+ vsinf->viewportCount = num_viewports;
+ vsinf->scissorCount = num_scissors;
+ vsinf->pViewports = viewports;
+ vsinf->pScissors = scissors;
+}
+
+void vku_pl_init_rasterization_state_info(VkPipelineRasterizationStateCreateInfo *rsinf)
+{
+ memset(rsinf, 0, sizeof *rsinf);
+ rsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
+ rsinf->polygonMode = VK_POLYGON_MODE_FILL;
+ rsinf->cullMode = VK_CULL_MODE_FRONT_BIT;
+ rsinf->frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
+}
+
+void vku_pl_init_multisample_state_info(VkPipelineMultisampleStateCreateInfo *msinf)
+{
+ memset(msinf, 0, sizeof *msinf);
+ msinf->sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
+ msinf->rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
+}
+
+void vku_pl_init_depth_stencil_state_info(VkPipelineDepthStencilStateCreateInfo *dsinf,
+ bool enable)
+{
+ memset(dsinf, 0, sizeof *dsinf);
+ dsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
+ dsinf->depthTestEnable = enable ? VK_TRUE : VK_FALSE;
+}
+
+void vku_pl_init_color_blend_state_info(VkPipelineColorBlendStateCreateInfo *cbsinf,
+ bool enable)
+{
+ memset(cbsinf, 0, sizeof *cbsinf);
+ cbsinf->sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
+ //TODO
+}