|
|
|
@ -9,7 +9,7 @@
|
|
|
|
|
#include "vk_mem_alloc.h"
|
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
|
#include "spng.h"
|
|
|
|
|
#include "stdatomic.h"
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
|
|
|
|
|
|
VkShaderModule load_shader_file(const char* path, VkDevice device) {
|
|
|
|
|
FILE* file;
|
|
|
|
@ -292,13 +292,12 @@ VkResult create_container(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
|
|
|
|
for(uint32_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUContainer), &context->containers[index].container[i], &context->containers[index].container_memory[i]));
|
|
|
|
|
context->containers[index].address[i] = buffer_address(gpu->device, context->containers[index].container[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUContainer), &context->containers[index].container, &context->containers[index].container_memory));
|
|
|
|
|
|
|
|
|
|
VkBuffer transfer;
|
|
|
|
|
VmaAllocation transfer_memory;
|
|
|
|
|
void* mapped;
|
|
|
|
|
VK_RESULT(create_transfer_buffer(gpu->allocator, sizeof(GPUContainer), &transfer, &transfer_memory, &mapped));
|
|
|
|
|
fprintf(stderr, "Created container with storage buffers %p/%p\n", context->containers[index].container[0], context->containers[index].container[1]);
|
|
|
|
|
|
|
|
|
|
context->containers[index].data.offset[0] = container->offset[0];
|
|
|
|
|
context->containers[index].data.offset[1] = container->offset[1];
|
|
|
|
@ -306,22 +305,15 @@ VkResult create_container(
|
|
|
|
|
context->containers[index].data.size[1] = container->size[1];
|
|
|
|
|
context->containers[index].data.anchor = container->anchor;
|
|
|
|
|
context->containers[index].data.context = context->address;
|
|
|
|
|
memcpy(mapped, &context->containers[index].data, sizeof(GPUContainer));
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(gpu->device, gpu->transfer_pool);
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, context->containers[index].container, 0, 0, sizeof(GPUContainer));
|
|
|
|
|
VK_RESULT(command_end_single(gpu->device, command_buffer, gpu->transfer_pool, gpu->transfer_queue));
|
|
|
|
|
destroy_transfer_buffer(gpu->allocator, transfer, transfer_memory);
|
|
|
|
|
add_transfers(&context->containers[index].data, context->containers[index].container, 0, sizeof(GPUContainer), gpu);
|
|
|
|
|
|
|
|
|
|
context->containers[index].address = buffer_address(gpu->device, context->containers[index].container);
|
|
|
|
|
context->containers[index].id = container->id;
|
|
|
|
|
context->containers[index].layers = malloc(sizeof(Layer)*container->layer_count);
|
|
|
|
|
for(uint32_t i = 0; i < container->layer_count; i++) {
|
|
|
|
|
VK_RESULT(create_layer(i, &container->layers[i], gpu, &context->containers[index]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__sync_synchronize();
|
|
|
|
|
atomic_store(&context->containers[index].layer_count, container->layer_count);
|
|
|
|
|
context->containers[index].layer_count = container->layer_count;
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
@ -370,59 +362,50 @@ VkResult create_layer(
|
|
|
|
|
} else {
|
|
|
|
|
container->layers[index].data.drawables = 0x00000000;
|
|
|
|
|
}
|
|
|
|
|
container->layers[index].address[i] = buffer_address(gpu->device, container->layers[index].layer[i]);
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "Created layer with storage buffers %p/%p\n", container->layers[index].layer[0], container->layers[index].layer[1]);
|
|
|
|
|
fprintf(stderr, "String Buffers %p/%p\n", container->layers[index].strings[0], container->layers[index].strings[1]);
|
|
|
|
|
fprintf(stderr, "Code Buffers %p/%p\n", container->layers[index].codes[0], container->layers[index].codes[1]);
|
|
|
|
|
|
|
|
|
|
VkBuffer transfer;
|
|
|
|
|
VmaAllocation transfer_memory;
|
|
|
|
|
void* mapped;
|
|
|
|
|
VK_RESULT(create_transfer_buffer(gpu->allocator, sizeof(GPULayer) + sizeof(GPUString) * input->num_strings + sizeof(GPUDrawable)*input->num_drawables + sizeof(uint32_t)*input->num_codes, &transfer, &transfer_memory, &mapped));
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
container->layers[index].data.dispatch_strings.x = max_strings;
|
|
|
|
|
container->layers[index].data.dispatch_strings.y = 1;
|
|
|
|
|
container->layers[index].data.dispatch_strings.z = 1;
|
|
|
|
|
|
|
|
|
|
container->layers[index].data.max_drawables = max_drawables + max_codes;
|
|
|
|
|
container->layers[index].data.max_strings = max_strings;
|
|
|
|
|
container->layers[index].data.num_drawables = max_drawables;
|
|
|
|
|
container->layers[index].data.container = container->address;
|
|
|
|
|
memcpy(mapped, &container->layers[index].data, sizeof(GPULayer));
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(gpu->device, gpu->transfer_pool);
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].layer[i], 0, 0, sizeof(GPULayer));
|
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
|
GPUString* strings = (GPUString*)(mapped + sizeof(GPULayer));
|
|
|
|
|
for(uint32_t i = 0; i < input->num_strings; i++) {
|
|
|
|
|
memcpy(&strings[i], &input->strings[i], sizeof(GPUString));
|
|
|
|
|
memcpy(&container->layers[index].strings_buffer[i], &input->strings[i], sizeof(GPUString));
|
|
|
|
|
}
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].strings[i], sizeof(GPULayer), 0, sizeof(GPUString)*input->num_strings);
|
|
|
|
|
}
|
|
|
|
|
for(uint32_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
|
|
|
add_transfer(
|
|
|
|
|
&container->address[i],
|
|
|
|
|
container->layers[index].layer[i],
|
|
|
|
|
offsetof(GPULayer, container),
|
|
|
|
|
sizeof(VkDeviceAddress),
|
|
|
|
|
i,
|
|
|
|
|
gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(input->num_drawables > 0) {
|
|
|
|
|
GPUDrawable* drawables = (GPUDrawable*)(mapped + sizeof(GPULayer) + sizeof(GPUString)*input->num_strings);
|
|
|
|
|
for(uint32_t i = 0; i < input->num_drawables; i++) {
|
|
|
|
|
memcpy(&drawables[i], &input->drawables[i], sizeof(GPUDrawable));
|
|
|
|
|
memcpy(&container->layers[index].drawables_buffer[i], &input->drawables[i], sizeof(GPUDrawable));
|
|
|
|
|
}
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].drawables[i], sizeof(GPULayer) + sizeof(GPUString)*input->num_strings, 0, sizeof(GPUDrawable)*input->num_drawables);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
|
uint32_t* codes = (uint32_t*)(mapped + sizeof(GPULayer) + sizeof(GPUString)*input->num_strings + sizeof(GPUDrawable)*input->num_drawables);
|
|
|
|
|
for(uint32_t i = 0; i < input->num_codes; i++) {
|
|
|
|
|
codes[i] = input->codes[i];
|
|
|
|
|
container->layers[index].codes_buffer[i] = input->codes[i];
|
|
|
|
|
}
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].codes[i], sizeof(GPULayer) + sizeof(GPUString)*input->num_strings + sizeof(GPUDrawable)*input->num_drawables, 0, sizeof(uint32_t)*input->num_codes);
|
|
|
|
|
}
|
|
|
|
|
VK_RESULT(command_end_single(gpu->device, command_buffer, gpu->transfer_pool, gpu->transfer_queue));
|
|
|
|
|
destroy_transfer_buffer(gpu->allocator, transfer, transfer_memory);
|
|
|
|
|
container->layers[index].data.dispatch_strings.x = max_strings;
|
|
|
|
|
container->layers[index].data.dispatch_strings.y = 1;
|
|
|
|
|
container->layers[index].data.dispatch_strings.z = 1;
|
|
|
|
|
|
|
|
|
|
container->layers[index].address[i] = buffer_address(gpu->device, container->layers[index].layer[i]);
|
|
|
|
|
container->layers[index].data.max_drawables = max_drawables + max_codes;
|
|
|
|
|
container->layers[index].data.max_strings = max_strings;
|
|
|
|
|
container->layers[index].data.max_codes = max_codes;
|
|
|
|
|
container->layers[index].data.num_drawables = max_drawables;
|
|
|
|
|
add_transfers(&container->layers[index].data, container->layers[index].layer, 0, sizeof(GPULayer)-sizeof(VkDeviceAddress), gpu);
|
|
|
|
|
|
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
|
memcpy(container->layers[index].strings_buffer, input->strings, sizeof(GPUString)*input->num_strings);
|
|
|
|
|
add_transfers(container->layers[index].strings_buffer, container->layers[index].strings, 0, sizeof(GPUString)*input->num_strings, gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(input->num_drawables > 0) {
|
|
|
|
|
memcpy(container->layers[index].drawables_buffer, input->drawables, sizeof(GPUDrawable)*input->num_drawables);
|
|
|
|
|
add_transfers(container->layers[index].drawables_buffer, container->layers[index].drawables, 0, sizeof(GPUDrawable)*input->num_drawables, gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
|
memcpy(container->layers[index].codes_buffer, input->codes, sizeof(uint32_t)*input->num_codes);
|
|
|
|
|
add_transfers(container->layers[index].codes_buffer, container->layers[index].codes, 0, sizeof(uint32_t)*input->num_codes, gpu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|