|
|
|
@ -275,10 +275,13 @@ VkResult create_ui_pipeline(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_container(
|
|
|
|
|
uint32_t id,
|
|
|
|
|
float x,
|
|
|
|
|
float y,
|
|
|
|
|
float width,
|
|
|
|
|
float height,
|
|
|
|
|
uint32_t layer_count,
|
|
|
|
|
UILayerInput* layers,
|
|
|
|
|
RenderContext* gpu,
|
|
|
|
|
UIContainerStorage* memory) {
|
|
|
|
|
VkResult result;
|
|
|
|
@ -302,61 +305,95 @@ VkResult create_container(
|
|
|
|
|
destroy_transfer_buffer(gpu->allocator, transfer, transfer_memory);
|
|
|
|
|
|
|
|
|
|
memory->address = buffer_address(gpu->device, memory->container);
|
|
|
|
|
memory->id = id;
|
|
|
|
|
memory->layer_count = layer_count;
|
|
|
|
|
memory->layers = malloc(sizeof(UILayerStorage)*layer_count);
|
|
|
|
|
for(uint32_t i = 0; i < layer_count; i++) {
|
|
|
|
|
VK_RESULT(create_layer(i, layers[i].strings, layers[i].codes, layers[i].drawables, layers[i].font, gpu, memory));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_layer(
|
|
|
|
|
uint32_t max_strings,
|
|
|
|
|
uint32_t max_codes,
|
|
|
|
|
uint32_t max_drawables,
|
|
|
|
|
uint32_t font_index,
|
|
|
|
|
uint32_t index,
|
|
|
|
|
uint32_t strings,
|
|
|
|
|
uint32_t codes,
|
|
|
|
|
uint32_t drawables,
|
|
|
|
|
uint32_t font,
|
|
|
|
|
RenderContext* gpu,
|
|
|
|
|
UIContainerStorage* container,
|
|
|
|
|
UILayerStorage* memory) {
|
|
|
|
|
UIContainerStorage* container) {
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, sizeof(UILayer), &memory->layer, &memory->layer_memory));
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(UIString)*max_strings, &memory->strings, &memory->strings_memory))
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(UIDrawable)*(max_drawables + max_codes), &memory->drawables, &memory->drawables_memory));
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(uint32_t)*max_codes, &memory->codes, &memory->codes_memory));
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, sizeof(UILayer), &container->layers[index].layer, &container->layers[index].layer_memory));
|
|
|
|
|
if(strings > 0) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(UIString)*strings, &container->layers[index].strings, &container->layers[index].strings_memory))
|
|
|
|
|
}
|
|
|
|
|
if(codes + drawables > 0) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(UIDrawable)*(drawables + codes), &container->layers[index].drawables, &container->layers[index].drawables_memory));
|
|
|
|
|
}
|
|
|
|
|
if(codes > 0) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(uint32_t)*codes, &container->layers[index].codes, &container->layers[index].codes_memory));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkBuffer transfer;
|
|
|
|
|
VmaAllocation transfer_memory;
|
|
|
|
|
void* mapped;
|
|
|
|
|
VK_RESULT(create_transfer_buffer(gpu->allocator, sizeof(UILayer), &transfer, &transfer_memory, &mapped));
|
|
|
|
|
|
|
|
|
|
memory->data.strings = buffer_address(gpu->device, memory->strings);
|
|
|
|
|
memory->data.codes = buffer_address(gpu->device, memory->codes);
|
|
|
|
|
if(strings > 0) {
|
|
|
|
|
container->layers[index].data.strings = buffer_address(gpu->device, container->layers[index].strings);
|
|
|
|
|
} else {
|
|
|
|
|
container->layers[index].data.strings = 0x00000000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(codes > 0) {
|
|
|
|
|
container->layers[index].data.codes = buffer_address(gpu->device, container->layers[index].codes);
|
|
|
|
|
} else {
|
|
|
|
|
container->layers[index].data.codes = 0x00000000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(codes + drawables > 0) {
|
|
|
|
|
container->layers[index].data.drawables = buffer_address(gpu->device, container->layers[index].drawables);
|
|
|
|
|
} else {
|
|
|
|
|
container->layers[index].data.drawables = 0x00000000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memory->data.drawables = buffer_address(gpu->device, memory->drawables);
|
|
|
|
|
|
|
|
|
|
memory->data.draw.first_vertex = 0;
|
|
|
|
|
memory->data.draw.vertex_count = 6;
|
|
|
|
|
memory->data.draw.first_instance = 0;
|
|
|
|
|
memory->data.draw.instance_count = 0;
|
|
|
|
|
container->layers[index].data.draw.first_vertex = 0;
|
|
|
|
|
container->layers[index].data.draw.vertex_count = 6;
|
|
|
|
|
container->layers[index].data.draw.first_instance = 0;
|
|
|
|
|
container->layers[index].data.draw.instance_count = 0;
|
|
|
|
|
|
|
|
|
|
memory->data.dispatch_strings.x = 0;
|
|
|
|
|
memory->data.dispatch_strings.y = 1;
|
|
|
|
|
memory->data.dispatch_strings.z = 1;
|
|
|
|
|
container->layers[index].data.dispatch_strings.x = strings;
|
|
|
|
|
container->layers[index].data.dispatch_strings.y = 1;
|
|
|
|
|
container->layers[index].data.dispatch_strings.z = 1;
|
|
|
|
|
|
|
|
|
|
memory->data.font_index = font_index;
|
|
|
|
|
memory->data.max_drawables = max_drawables;
|
|
|
|
|
memory->data.max_strings = max_strings;
|
|
|
|
|
memory->data.num_drawables = 0;
|
|
|
|
|
memory->data.container = container->address;
|
|
|
|
|
memcpy(mapped, &memory->data, sizeof(UILayer));
|
|
|
|
|
container->layers[index].data.font_index = font;
|
|
|
|
|
container->layers[index].data.max_drawables = drawables + codes;
|
|
|
|
|
container->layers[index].data.max_strings = strings;
|
|
|
|
|
container->layers[index].data.num_drawables = drawables;
|
|
|
|
|
container->layers[index].data.container = container->address;
|
|
|
|
|
memcpy(mapped, &container->layers[index].data, sizeof(UILayer));
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(gpu->device, gpu->transfer_pool);
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, memory->layer, 0, 0, sizeof(UILayer));
|
|
|
|
|
vkCmdFillBuffer(command_buffer, memory->strings, 0, sizeof(UIString)*max_strings, 0x00000000);
|
|
|
|
|
vkCmdFillBuffer(command_buffer, memory->drawables, 0, sizeof(UIDrawable)*max_drawables, 0x00000000);
|
|
|
|
|
vkCmdFillBuffer(command_buffer, memory->codes, 0, sizeof(uint32_t)*max_codes, 0x00000000);
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].layer, 0, 0, sizeof(UILayer));
|
|
|
|
|
if(strings > 0) {
|
|
|
|
|
vkCmdFillBuffer(command_buffer, container->layers[index].strings, 0, sizeof(UIString)*strings, 0x00000000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(codes + drawables > 0) {
|
|
|
|
|
vkCmdFillBuffer(command_buffer, container->layers[index].drawables, 0, sizeof(UIDrawable)*(drawables+codes), 0x00000000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(codes > 0) {
|
|
|
|
|
vkCmdFillBuffer(command_buffer, container->layers[index].codes, 0, sizeof(uint32_t)*codes, 0x00000000);
|
|
|
|
|
}
|
|
|
|
|
VK_RESULT(command_end_single(gpu->device, command_buffer, gpu->transfer_pool, gpu->transfer_queue));
|
|
|
|
|
vkQueueWaitIdle(gpu->transfer_queue.handle);
|
|
|
|
|
destroy_transfer_buffer(gpu->allocator, transfer, transfer_memory);
|
|
|
|
|
|
|
|
|
|
memory->address = buffer_address(gpu->device, memory->layer);
|
|
|
|
|
container->layers[index].address = buffer_address(gpu->device, container->layers[index].layer);
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|