|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
#include "pipeline.h"
|
|
|
|
|
#include "ui.h"
|
|
|
|
|
#include "cglm/affine.h"
|
|
|
|
|
#include "cglm/mat4.h"
|
|
|
|
|
#include "command.h"
|
|
|
|
@ -203,11 +203,6 @@ VkResult create_ui_colored_rect_pipeline(VkDevice device, VkRenderPass render_pa
|
|
|
|
|
VkVertexInputBindingDescription bindings[] = {
|
|
|
|
|
{
|
|
|
|
|
.binding = 0,
|
|
|
|
|
.stride = sizeof(vec2),
|
|
|
|
|
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.binding = 1,
|
|
|
|
|
.stride = sizeof(ColoredRect),
|
|
|
|
|
.inputRate = VK_VERTEX_INPUT_RATE_INSTANCE,
|
|
|
|
|
},
|
|
|
|
@ -217,24 +212,18 @@ VkResult create_ui_colored_rect_pipeline(VkDevice device, VkRenderPass render_pa
|
|
|
|
|
{
|
|
|
|
|
.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,
|
|
|
|
|
.binding = 0,
|
|
|
|
|
.location = 1,
|
|
|
|
|
.format = VK_FORMAT_R32G32_SFLOAT,
|
|
|
|
|
.offset = offsetof(ColoredRect, size),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
.binding = 1,
|
|
|
|
|
.location = 3,
|
|
|
|
|
.binding = 0,
|
|
|
|
|
.location = 2,
|
|
|
|
|
.format = VK_FORMAT_R32G32B32A32_SFLOAT,
|
|
|
|
|
.offset = offsetof(ColoredRect, color),
|
|
|
|
|
},
|
|
|
|
@ -340,21 +329,8 @@ VkResult create_ui_text_pipeline(VkDevice device, VkRenderPass render_pass, VkDe
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkVertexInputBindingDescription bindings[] = {
|
|
|
|
|
{
|
|
|
|
|
.binding = 0,
|
|
|
|
|
.stride = sizeof(vec2),
|
|
|
|
|
.inputRate = VK_VERTEX_INPUT_RATE_VERTEX,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
VkVertexInputAttributeDescription attributes[] = {
|
|
|
|
|
{
|
|
|
|
|
.binding = 0,
|
|
|
|
|
.location = 0,
|
|
|
|
|
.format = VK_FORMAT_R32G32_SFLOAT,
|
|
|
|
|
.offset = 0,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
VkVertexInputBindingDescription bindings[] = {};
|
|
|
|
|
VkVertexInputAttributeDescription attributes[] = {};
|
|
|
|
|
|
|
|
|
|
VkPipelineVertexInputStateCreateInfo input_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,
|
|
|
|
@ -566,7 +542,7 @@ VkResult create_text_pointers(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DrawCommand draw = {
|
|
|
|
|
.index_count = 6,
|
|
|
|
|
.vertex_count = 6,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
memcpy(mapped + 0, &draw, sizeof(DrawCommand));
|
|
|
|
@ -1005,113 +981,7 @@ VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExt
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_ui_rect_buffer(VkDevice device, Queue transfer_queue, VkCommandPool transfer_pool, VmaAllocator allocator, struct RectBuffer* rect) {
|
|
|
|
|
|
|
|
|
|
uint32_t vertex_buffer_size = 4 * sizeof(vec2);
|
|
|
|
|
uint32_t index_buffer_size = 6 * sizeof(uint32_t);
|
|
|
|
|
|
|
|
|
|
// Create temp buffer
|
|
|
|
|
VkBufferCreateInfo temp_buffer_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
|
|
|
.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT,
|
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
|
.size = vertex_buffer_size + index_buffer_size,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VmaAllocationCreateInfo temp_allocation_info = {
|
|
|
|
|
.usage = VMA_MEMORY_USAGE_CPU_TO_GPU,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create buffers
|
|
|
|
|
VmaAllocationCreateInfo allocation_info = {
|
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VkBufferCreateInfo vertex_buffer_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
|
|
|
.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
|
.size = vertex_buffer_size,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
result = vmaCreateBuffer(allocator, &vertex_buffer_info, &allocation_info, &rect->vertex, &rect->vertex_memory, NULL);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkBufferCreateInfo index_buffer_info = {
|
|
|
|
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
|
|
|
|
.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT,
|
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
|
|
|
|
.size = index_buffer_size,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
result = vmaCreateBuffer(allocator, &index_buffer_info, &allocation_info, &rect->index, &rect->index_memory, NULL);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* mapped;
|
|
|
|
|
result = vmaMapMemory(allocator, temp_buffer_memory, &mapped);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec2* mapped_vertex = (vec2*)mapped;
|
|
|
|
|
mapped_vertex[0][0] = 0.0f;
|
|
|
|
|
mapped_vertex[0][1] = 0.0f;
|
|
|
|
|
mapped_vertex[1][0] = 1.0f;
|
|
|
|
|
mapped_vertex[1][1] = 0.0f;
|
|
|
|
|
mapped_vertex[2][0] = 0.0f;
|
|
|
|
|
mapped_vertex[2][1] = 1.0f;
|
|
|
|
|
mapped_vertex[3][0] = 1.0f;
|
|
|
|
|
mapped_vertex[3][1] = 1.0f;
|
|
|
|
|
|
|
|
|
|
uint32_t* mapped_index = (uint32_t*)(mapped + vertex_buffer_size);
|
|
|
|
|
mapped_index[0] = 0;
|
|
|
|
|
mapped_index[1] = 1;
|
|
|
|
|
mapped_index[2] = 2;
|
|
|
|
|
mapped_index[3] = 1;
|
|
|
|
|
mapped_index[4] = 3;
|
|
|
|
|
mapped_index[5] = 2;
|
|
|
|
|
|
|
|
|
|
vmaUnmapMemory(allocator, temp_buffer_memory);
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer copy_buffer = command_begin_single(device, transfer_pool);
|
|
|
|
|
VkBufferCopy vertex_copy_region = {
|
|
|
|
|
.size = vertex_buffer_size,
|
|
|
|
|
.dstOffset = 0,
|
|
|
|
|
.srcOffset = 0,
|
|
|
|
|
};
|
|
|
|
|
vkCmdCopyBuffer(copy_buffer, temp_buffer, rect->vertex, 1, &vertex_copy_region);
|
|
|
|
|
|
|
|
|
|
VkBufferCopy index_copy_region = {
|
|
|
|
|
.size = index_buffer_size,
|
|
|
|
|
.dstOffset = 0,
|
|
|
|
|
.srcOffset = vertex_buffer_size,
|
|
|
|
|
};
|
|
|
|
|
vkCmdCopyBuffer(copy_buffer, temp_buffer, rect->index, 1, &index_copy_region);
|
|
|
|
|
|
|
|
|
|
result = command_end_single(device, copy_buffer, transfer_pool, transfer_queue);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vmaDestroyBuffer(allocator, temp_buffer, temp_buffer_memory);
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, vec2 window_scale, VkRenderPass render_pass, Queue transfer_queue, VkCommandPool transfer_pool, UIContext* context) {
|
|
|
|
|
VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, vec2 window_scale, VkRenderPass render_pass, UIContext* context) {
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
result = create_ui_descriptor_set(device, allocator, swapchain_extent, window_scale, &context->ui_descriptor_layout, &context->ui_descriptor_pool, &context->ui_descriptor_set, &context->ui_descriptor_memory, &context->ui_descriptor_buffer);
|
|
|
|
@ -1119,11 +989,6 @@ VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swap
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = create_ui_rect_buffer(device, transfer_queue, transfer_pool, allocator, &context->ui_rect);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
result = create_ui_colored_rect_pipeline(device, render_pass, context->ui_descriptor_layout, &context->ui_pipeline_rect);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
@ -1139,5 +1004,6 @@ VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swap
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|