|
|
|
@ -48,102 +48,22 @@ VkShaderModule load_shader_file(const char* path, VkDevice device) {
|
|
|
|
|
return shader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_ui_rect_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[] = {
|
|
|
|
|
{
|
|
|
|
|
.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 = &descriptor_layout,
|
|
|
|
|
};
|
|
|
|
|
VkResult create_ui_pipeline(
|
|
|
|
|
VkDevice device,
|
|
|
|
|
VkRenderPass render_pass,
|
|
|
|
|
VkPipelineShaderStageCreateInfo* shader_stages,
|
|
|
|
|
uint32_t shader_stage_count,
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo input_info,
|
|
|
|
|
VkPipelineLayoutCreateInfo layout_info,
|
|
|
|
|
VkPipelineInputAssemblyStateCreateInfo input_assembly_info,
|
|
|
|
|
GraphicsPipeline* pipeline) {
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
VkResult result = vkCreatePipelineLayout(device, &layout_info, 0, &pipeline->layout);
|
|
|
|
|
result = vkCreatePipelineLayout(device, &layout_info, 0, &pipeline->layout);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
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 = {
|
|
|
|
|
.x = 0.0f,
|
|
|
|
|
.y = 0.0f,
|
|
|
|
@ -232,9 +152,22 @@ VkResult create_ui_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDe
|
|
|
|
|
.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 = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
|
|
|
|
|
.stageCount = sizeof(shader_stages)/sizeof(VkPipelineShaderStageCreateInfo),
|
|
|
|
|
.stageCount = shader_stage_count,
|
|
|
|
|
.pStages = shader_stages,
|
|
|
|
|
.pVertexInputState = &input_info,
|
|
|
|
|
.pInputAssemblyState = &input_assembly_info,
|
|
|
|
@ -255,6 +188,141 @@ VkResult create_ui_rect_pipeline(VkDevice device, VkRenderPass render_pass, VkDe
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|