|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
#include "pipeline.h"
|
|
|
|
|
#include "cglm/affine.h"
|
|
|
|
|
#include "cglm/mat4.h"
|
|
|
|
|
#include "stdio.h"
|
|
|
|
|
#include "stdlib.h"
|
|
|
|
|
#include "string.h"
|
|
|
|
@ -329,9 +331,15 @@ VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExt
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
struct UIUniform ui_uniform = {
|
|
|
|
|
.size = {swapchain_extent.width, swapchain_extent.height}
|
|
|
|
|
};
|
|
|
|
|
struct UIUniform ui_uniform;
|
|
|
|
|
vec3 screen_offset = {-1.0, -1.0, 0.0};
|
|
|
|
|
vec3 screen_scale = {1.0/(float)swapchain_extent.width, 1.0/(float)swapchain_extent.height, 1.0};
|
|
|
|
|
glm_mat4_identity(ui_uniform.screen);
|
|
|
|
|
glm_translate(ui_uniform.screen, screen_offset);
|
|
|
|
|
glm_scale(ui_uniform.screen, screen_scale);
|
|
|
|
|
for(uint32_t i = 0; i < 4; i ++) {
|
|
|
|
|
fprintf(stderr, "%f %f %f %f\n", ui_uniform.screen[0][i], ui_uniform.screen[1][i], ui_uniform.screen[2][i], ui_uniform.screen[3][i]);
|
|
|
|
|
}
|
|
|
|
|
memcpy(mapped, &ui_uniform, sizeof(ui_uniform));
|
|
|
|
|
vmaUnmapMemory(allocator, *ui_descriptor_memory);
|
|
|
|
|
|
|
|
|
@ -355,14 +363,22 @@ VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExt
|
|
|
|
|
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);
|
|
|
|
|
VkResult create_ui_polygon_buffer(VkDevice device, Queue transfer_queue, VkCommandPool transfer_pool, VmaAllocator allocator, struct UIPolygon* polygon, VmaAllocation* polygon_vertex_memory, VmaAllocation* polygon_index_memory) {
|
|
|
|
|
|
|
|
|
|
// Create and populate polygon buffers
|
|
|
|
|
polygon->indices = 6;
|
|
|
|
|
polygon->vertices = 4;
|
|
|
|
|
polygon->vertex_offset = 0;
|
|
|
|
|
polygon->index_offset = 0;
|
|
|
|
|
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 = polygon_buffer_size
|
|
|
|
|
.size = vertex_buffer_size + index_buffer_size,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VmaAllocationCreateInfo temp_allocation_info = {
|
|
|
|
@ -378,44 +394,75 @@ VkResult create_ui_polygon_buffer(VkDevice device, Queue transfer_queue, VkComma
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkBufferCreateInfo buffer_info = {
|
|
|
|
|
// 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 = polygon_buffer_size,
|
|
|
|
|
.size = vertex_buffer_size,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VmaAllocationCreateInfo allocation_info = {
|
|
|
|
|
.usage = VMA_MEMORY_USAGE_GPU_ONLY,
|
|
|
|
|
result = vmaCreateBuffer(allocator, &vertex_buffer_info, &allocation_info, &polygon->vertex_buffer, polygon_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, &buffer_info, &allocation_info, polygon_buffer, polygon_buffer_memory, NULL);
|
|
|
|
|
result = vmaCreateBuffer(allocator, &index_buffer_info, &allocation_info, &polygon->index_buffer, polygon_index_memory, NULL);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vec2* mapped;
|
|
|
|
|
result = vmaMapMemory(allocator, temp_buffer_memory, (void**)&mapped);
|
|
|
|
|
void* mapped;
|
|
|
|
|
result = vmaMapMemory(allocator, temp_buffer_memory, &mapped);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mapped[0][0] = 0.0f;
|
|
|
|
|
mapped[0][1] = 0.0f;
|
|
|
|
|
mapped[1][0] = 1.0f;
|
|
|
|
|
mapped[1][1] = 0.0f;
|
|
|
|
|
mapped[2][0] = 0.0f;
|
|
|
|
|
mapped[2][1] = 1.0f;
|
|
|
|
|
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 copy_region = {
|
|
|
|
|
.size = polygon_buffer_size,
|
|
|
|
|
VkBufferCopy vertex_copy_region = {
|
|
|
|
|
.size = vertex_buffer_size,
|
|
|
|
|
.dstOffset = 0,
|
|
|
|
|
.srcOffset = 0,
|
|
|
|
|
};
|
|
|
|
|
vkCmdCopyBuffer(copy_buffer, temp_buffer, *polygon_buffer, 1, ©_region);
|
|
|
|
|
vkCmdCopyBuffer(copy_buffer, temp_buffer, polygon->vertex_buffer, 1, &vertex_copy_region);
|
|
|
|
|
|
|
|
|
|
VkBufferCopy index_copy_region = {
|
|
|
|
|
.size = index_buffer_size,
|
|
|
|
|
.dstOffset = 0,
|
|
|
|
|
.srcOffset = vertex_buffer_size,
|
|
|
|
|
};
|
|
|
|
|
vkCmdCopyBuffer(copy_buffer, temp_buffer, polygon->index_buffer, 1, &index_copy_region);
|
|
|
|
|
|
|
|
|
|
result = command_end_single(device, copy_buffer, transfer_pool, transfer_queue);
|
|
|
|
|
if(result != VK_SUCCESS) {
|
|
|
|
|