Delted commited object file. Renamed shaders. Started ui text pipeline.

main
noah metz 2024-10-13 16:04:12 -06:00
parent b2a8d283f6
commit 4e7813499f
7 changed files with 170 additions and 95 deletions

@ -24,6 +24,14 @@ typedef struct UIUniformStruct {
typedef struct UILayerStruct { typedef struct UILayerStruct {
VkBuffer colored_rects; VkBuffer colored_rects;
uint32_t colored_rect_count; uint32_t colored_rect_count;
VkBuffer textured_rects;
uint32_t textured_rect_count;
VkDescriptorSet textured_rect_descriptor;
VkBuffer texts;
uint32_t text_count;
VkDescriptorSet text_descriptor;
} UILayer; } UILayer;
struct RectBuffer { struct RectBuffer {
@ -34,7 +42,7 @@ struct RectBuffer {
VmaAllocation index_memory; VmaAllocation index_memory;
}; };
VkResult create_ui_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDescriptorSetLayout descriptor_layout, GraphicsPipeline* pipeline); VkResult create_ui_colored_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDescriptorSetLayout descriptor_layout, GraphicsPipeline* pipeline);
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); 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);

@ -77,7 +77,6 @@ typedef struct RenderContextStruct {
VkFence* in_flight_fences; VkFence* in_flight_fences;
VkBuffer ui_descriptor_buffer; VkBuffer ui_descriptor_buffer;
VmaAllocation ui_descriptor_memory; VmaAllocation ui_descriptor_memory;
VkDescriptorSetLayout ui_descriptor_layout; VkDescriptorSetLayout ui_descriptor_layout;

@ -48,102 +48,22 @@ VkShaderModule load_shader_file(const char* path, VkDevice device) {
return shader; return shader;
} }
VkResult create_ui_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDescriptorSetLayout descriptor_layout, GraphicsPipeline* pipeline) { VkResult create_ui_pipeline(
VkShaderModule vert_shader = load_shader_file("shader_src/ui_polygon.vert.spv", device); VkDevice device,
VkShaderModule frag_shader = load_shader_file("shader_src/ui_polygon.frag.spv", device); VkRenderPass render_pass,
VkPipelineShaderStageCreateInfo shader_stages[] = { VkPipelineShaderStageCreateInfo* shader_stages,
{ uint32_t shader_stage_count,
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, VkPipelineVertexInputStateCreateInfo input_info,
.stage = VK_SHADER_STAGE_VERTEX_BIT, VkPipelineLayoutCreateInfo layout_info,
.module = vert_shader, VkPipelineInputAssemblyStateCreateInfo input_assembly_info,
.pName = "main", GraphicsPipeline* pipeline) {
}, VkResult result;
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = frag_shader,
.pName = "main",
},
};
VkVertexInputBindingDescription bindings[] = {
{
.binding = 0,
.stride = sizeof(vec2),
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
},
{
.binding = 1,
.stride = sizeof(ColoredRect),
.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE,
},
};
VkVertexInputAttributeDescription attributes[] = {
{
.binding = 0,
.location = 0,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = 0,
},
{
.binding = 1,
.location = 1,
.format = VK_FORMAT_R32G32B32_SFLOAT,
.offset = offsetof(ColoredRect, pos),
},
{
.binding = 1,
.location = 2,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = offsetof(ColoredRect, size),
},
{
.binding = 1,
.location = 3,
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
.offset = offsetof(ColoredRect, color),
},
};
VkPipelineVertexInputStateCreateInfo input_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.pVertexBindingDescriptions = bindings,
.vertexBindingDescriptionCount = sizeof(bindings)/sizeof(VkVertexInputBindingDescription),
.pVertexAttributeDescriptions = attributes,
.vertexAttributeDescriptionCount = sizeof(attributes)/sizeof(VkVertexInputAttributeDescription),
};
VkPipelineLayoutCreateInfo layout_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = 1,
.pSetLayouts = &descriptor_layout,
};
VkResult result = vkCreatePipelineLayout(device, &layout_info, 0, &pipeline->layout); result = vkCreatePipelineLayout(device, &layout_info, 0, &pipeline->layout);
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
return result; return result;
} }
VkDynamicState dynamic_states[] = {
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR,
};
uint32_t dynamic_state_count = sizeof(dynamic_states)/sizeof(VkDynamicState);
VkPipelineDynamicStateCreateInfo dynamic_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.dynamicStateCount = dynamic_state_count,
.pDynamicStates = dynamic_states,
};
VkPipelineInputAssemblyStateCreateInfo input_assembly_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.primitiveRestartEnable = VK_FALSE,
};
VkViewport viewport = { VkViewport viewport = {
.x = 0.0f, .x = 0.0f,
.y = 0.0f, .y = 0.0f,
@ -232,9 +152,22 @@ VkResult create_ui_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDe
.blendConstants[3] = 0.0f, .blendConstants[3] = 0.0f,
}; };
VkDynamicState dynamic_states[] = {
VK_DYNAMIC_STATE_VIEWPORT,
VK_DYNAMIC_STATE_SCISSOR,
};
uint32_t dynamic_state_count = sizeof(dynamic_states)/sizeof(VkDynamicState);
VkPipelineDynamicStateCreateInfo dynamic_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO,
.dynamicStateCount = dynamic_state_count,
.pDynamicStates = dynamic_states,
};
VkGraphicsPipelineCreateInfo draw_pipeline_info = { VkGraphicsPipelineCreateInfo draw_pipeline_info = {
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
.stageCount = sizeof(shader_stages)/sizeof(VkPipelineShaderStageCreateInfo), .stageCount = shader_stage_count,
.pStages = shader_stages, .pStages = shader_stages,
.pVertexInputState = &input_info, .pVertexInputState = &input_info,
.pInputAssemblyState = &input_assembly_info, .pInputAssemblyState = &input_assembly_info,
@ -255,6 +188,141 @@ VkResult create_ui_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDe
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
return result; return result;
} }
return VK_SUCCESS;
}
VkResult create_ui_colored_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDescriptorSetLayout ui_descriptor_layout, GraphicsPipeline* pipeline) {
VkShaderModule vert_shader = load_shader_file("shader_src/ui_colored_rect.vert.spv", device);
VkShaderModule frag_shader = load_shader_file("shader_src/ui_colored_rect.frag.spv", device);
VkPipelineShaderStageCreateInfo shader_stages[] = {
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = vert_shader,
.pName = "main",
},
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = frag_shader,
.pName = "main",
},
};
VkVertexInputBindingDescription bindings[] = {
{
.binding = 0,
.stride = sizeof(vec2),
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
},
{
.binding = 1,
.stride = sizeof(ColoredRect),
.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE,
},
};
VkVertexInputAttributeDescription attributes[] = {
{
.binding = 0,
.location = 0,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = 0,
},
{
.binding = 1,
.location = 1,
.format = VK_FORMAT_R32G32B32_SFLOAT,
.offset = offsetof(ColoredRect, pos),
},
{
.binding = 1,
.location = 2,
.format = VK_FORMAT_R32G32_SFLOAT,
.offset = offsetof(ColoredRect, size),
},
{
.binding = 1,
.location = 3,
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
.offset = offsetof(ColoredRect, color),
},
};
VkPipelineVertexInputStateCreateInfo input_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.pVertexBindingDescriptions = bindings,
.vertexBindingDescriptionCount = sizeof(bindings)/sizeof(VkVertexInputBindingDescription),
.pVertexAttributeDescriptions = attributes,
.vertexAttributeDescriptionCount = sizeof(attributes)/sizeof(VkVertexInputAttributeDescription),
};
VkPipelineLayoutCreateInfo layout_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = 1,
.pSetLayouts = &ui_descriptor_layout,
};
VkPipelineInputAssemblyStateCreateInfo input_assembly_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.primitiveRestartEnable = VK_FALSE,
};
VkResult result = create_ui_pipeline(device, render_pass, shader_stages, sizeof(shader_stages)/sizeof(VkPipelineShaderStageCreateInfo), input_info, layout_info, input_assembly_info, pipeline);
if(result != VK_SUCCESS) {
return result;
}
return VK_SUCCESS;
}
VkResult create_ui_text_pipeline(VkDevice device, VkRenderPass render_pass, VkDescriptorSetLayout ui_descriptor_layout, GraphicsPipeline* pipeline) {
VkShaderModule vert_shader = load_shader_file("shader_src/ui_text.vert.spv", device);
VkShaderModule frag_shader = load_shader_file("shader_src/ui_text.frag.spv", device);
VkPipelineShaderStageCreateInfo shader_stages[] = {
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_VERTEX_BIT,
.module = vert_shader,
.pName = "main",
},
{
.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,
.stage = VK_SHADER_STAGE_FRAGMENT_BIT,
.module = frag_shader,
.pName = "main",
},
};
VkVertexInputBindingDescription bindings[] = {};
VkVertexInputAttributeDescription attributes[] = {};
VkPipelineVertexInputStateCreateInfo input_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
.pVertexBindingDescriptions = bindings,
.vertexBindingDescriptionCount = sizeof(bindings)/sizeof(VkVertexInputBindingDescription),
.pVertexAttributeDescriptions = attributes,
.vertexAttributeDescriptionCount = sizeof(attributes)/sizeof(VkVertexInputAttributeDescription),
};
VkDescriptorSetLayout all_layouts[] = {ui_descriptor_layout};
VkPipelineLayoutCreateInfo layout_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
.setLayoutCount = sizeof(all_layouts)/sizeof(VkDescriptorSetLayout),
.pSetLayouts = all_layouts,
};
VkPipelineInputAssemblyStateCreateInfo input_assembly_info = {
.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,
.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
.primitiveRestartEnable = VK_FALSE,
};
VkResult result = create_ui_pipeline(device, render_pass, shader_stages, sizeof(shader_stages)/sizeof(VkPipelineShaderStageCreateInfo), input_info, layout_info, input_assembly_info, pipeline);
if(result != VK_SUCCESS) {
return result;
}
return VK_SUCCESS; return VK_SUCCESS;
} }

@ -949,7 +949,7 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
return result; return result;
} }
result = create_ui_rect_pipeline(context->device, context->world_render_pass, context->ui_descriptor_layout, &context->ui_pipeline_rect); result = create_ui_colored_rect_pipeline(context->device, context->world_render_pass, context->ui_descriptor_layout, &context->ui_pipeline_rect);
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
return result; return result;
} }

Binary file not shown.