|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include "pipeline.h"
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
#include "string.h"
|
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
|
|
|
|
|
|
VkShaderModule load_shader_file(const char* path, VkDevice device) {
|
|
|
|
@ -45,7 +46,7 @@ VkShaderModule load_shader_file(const char* path, VkDevice device) {
|
|
|
|
|
return shader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_ui_polygon_pipeline(VkDevice device, VkRenderPass render_pass, VkDescriptorSetLayout descriptor_layout, VmaAllocator allocator, VkCommandPool transfer_pool, Queue transfer_queue, VmaAllocation* polygon_buffer_memory, VkBuffer* polygon_buffer, GraphicsPipeline* pipeline) {
|
|
|
|
|
VkResult create_ui_polygon_pipeline(VkDevice device, VkRenderPass render_pass, VkDescriptorSetLayout descriptor_layout, GraphicsPipeline* pipeline) {
|
|
|
|
|
VkShaderModule vert_shader = load_shader_file("shader_src/ui_polygon.vert.spv", device);
|
|
|
|
|
VkShaderModule frag_shader = load_shader_file("shader_src/ui_polygon.frag.spv", device);
|
|
|
|
|
VkPipelineShaderStageCreateInfo shader_stages[] = {
|
|
|
|
@ -103,7 +104,6 @@ VkResult create_ui_polygon_pipeline(VkDevice device, VkRenderPass render_pass, V
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo input_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
|
|
|
|
.pVertexBindingDescriptions = bindings,
|
|
|
|
@ -254,6 +254,108 @@ VkResult create_ui_polygon_pipeline(VkDevice device, VkRenderPass render_pass, V
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, VkDescriptorSetLayout* ui_descriptor_layout, VkDescriptorPool* ui_descriptor_pool, VkDescriptorSet* ui_descriptor_set, VmaAllocation* ui_descriptor_memory, VkBuffer* ui_descriptor_buffer) {
|
|
|
|
|
VkDescriptorSetLayoutBinding ui_descriptor_bindings[] = {
|
|
|
|
|
{
|
|
|
|
|
.binding = 0,
|
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
|
|
.descriptorCount = 1,
|
|
|
|
|
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkDescriptorSetLayoutCreateInfo ui_descriptor_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
|
|
|
|
|
.pBindings = ui_descriptor_bindings,
|
|
|
|
|
.bindingCount = sizeof(ui_descriptor_bindings)/sizeof(VkDescriptorSetLayoutBinding),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
result = vkCreateDescriptorSetLayout(device, &ui_descriptor_info, NULL, ui_descriptor_layout);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkDescriptorPoolSize pool_size = {
|
|
|
|
|
.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
|
|
.descriptorCount = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkDescriptorPoolCreateInfo ui_pool_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
|
|
|
|
|
.pPoolSizes = &pool_size,
|
|
|
|
|
.poolSizeCount = 1,
|
|
|
|
|
.maxSets = 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
result = vkCreateDescriptorPool(device, &ui_pool_info, NULL, ui_descriptor_pool);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkDescriptorSetAllocateInfo ui_descriptor_allocate_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
|
|
|
|
|
.pSetLayouts = ui_descriptor_layout,
|
|
|
|
|
.descriptorSetCount = 1,
|
|
|
|
|
.descriptorPool = *ui_descriptor_pool,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
result = vkAllocateDescriptorSets(device, &ui_descriptor_allocate_info, ui_descriptor_set);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkBufferCreateInfo ui_uniform_buffer_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
|
|
|
.usage = VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
|
|
|
|
|
.size = sizeof(struct UIUniform),
|
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VmaAllocationCreateInfo ui_uniform_memory_info = {
|
|
|
|
|
.usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
result = vmaCreateBuffer(allocator, &ui_uniform_buffer_info, &ui_uniform_memory_info, ui_descriptor_buffer, ui_descriptor_memory, NULL);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void * mapped;
|
|
|
|
|
result = vmaMapMemory(allocator, *ui_descriptor_memory, &mapped);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
struct UIUniform ui_uniform = {
|
|
|
|
|
.size = {swapchain_extent.width, swapchain_extent.height}
|
|
|
|
|
};
|
|
|
|
|
memcpy(mapped, &ui_uniform, sizeof(ui_uniform));
|
|
|
|
|
vmaUnmapMemory(allocator, *ui_descriptor_memory);
|
|
|
|
|
|
|
|
|
|
VkDescriptorBufferInfo ui_uniform_info = {
|
|
|
|
|
.offset = 0,
|
|
|
|
|
.range = sizeof(ui_uniform),
|
|
|
|
|
.buffer = *ui_descriptor_buffer,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkWriteDescriptorSet ui_uniform_write = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
|
|
|
|
.dstSet = *ui_descriptor_set,
|
|
|
|
|
.dstBinding = 0,
|
|
|
|
|
.dstArrayElement = 0,
|
|
|
|
|
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
|
|
.descriptorCount = 1,
|
|
|
|
|
.pBufferInfo = &ui_uniform_info,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
vkUpdateDescriptorSets(device, 1, &ui_uniform_write, 0, NULL);
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_ui_polygon_buffer(VkDevice device, Queue transfer_queue, VkCommandPool transfer_pool, VmaAllocator allocator, VmaAllocation* polygon_buffer_memory, VkBuffer* polygon_buffer) {
|
|
|
|
|
// Create and populate polygon buffer
|
|
|
|
|
uint32_t polygon_buffer_size = 3 * sizeof(vec2);
|
|
|
|
|
VkBufferCreateInfo temp_buffer_info = {
|
|
|
|
@ -269,6 +371,8 @@ VkResult create_ui_polygon_pipeline(VkDevice device, VkRenderPass render_pass, V
|
|
|
|
|
|
|
|
|
|
VkBuffer temp_buffer;
|
|
|
|
|
VmaAllocation temp_buffer_memory;
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
result = vmaCreateBuffer(allocator, &temp_buffer_info, &temp_allocation_info, &temp_buffer, &temp_buffer_memory, NULL);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|