|
|
@ -9,6 +9,7 @@
|
|
|
|
#include "vk_mem_alloc.h"
|
|
|
|
#include "vk_mem_alloc.h"
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
#include "spng.h"
|
|
|
|
#include "spng.h"
|
|
|
|
|
|
|
|
#include "stdatomic.h"
|
|
|
|
|
|
|
|
|
|
|
|
VkShaderModule load_shader_file(const char* path, VkDevice device) {
|
|
|
|
VkShaderModule load_shader_file(const char* path, VkDevice device) {
|
|
|
|
FILE* file;
|
|
|
|
FILE* file;
|
|
|
@ -314,12 +315,14 @@ VkResult create_container(
|
|
|
|
|
|
|
|
|
|
|
|
context->containers[index].address = buffer_address(gpu->device, context->containers[index].container);
|
|
|
|
context->containers[index].address = buffer_address(gpu->device, context->containers[index].container);
|
|
|
|
context->containers[index].id = container->id;
|
|
|
|
context->containers[index].id = container->id;
|
|
|
|
context->containers[index].layer_count = container->layer_count;
|
|
|
|
|
|
|
|
context->containers[index].layers = malloc(sizeof(Layer)*container->layer_count);
|
|
|
|
context->containers[index].layers = malloc(sizeof(Layer)*container->layer_count);
|
|
|
|
for(uint32_t i = 0; i < container->layer_count; i++) {
|
|
|
|
for(uint32_t i = 0; i < container->layer_count; i++) {
|
|
|
|
VK_RESULT(create_layer(i, &container->layers[i], gpu, &context->containers[index]));
|
|
|
|
VK_RESULT(create_layer(i, &container->layers[i], gpu, &context->containers[index]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
__sync_synchronize();
|
|
|
|
|
|
|
|
atomic_store(&context->containers[index].layer_count, container->layer_count);
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -330,17 +333,19 @@ VkResult create_layer(
|
|
|
|
Container* container) {
|
|
|
|
Container* container) {
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, sizeof(GPULayer), &container->layers[index].layer, &container->layers[index].layer_memory));
|
|
|
|
for(uint32_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, sizeof(GPULayer), &container->layers[index].layer[i], &container->layers[index].layer_memory[i]));
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUString)*input->num_strings, &container->layers[index].strings, &container->layers[index].strings_memory));
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUString)*input->num_strings, &container->layers[index].strings[i], &container->layers[index].strings_memory[i]));
|
|
|
|
container->layers[index].strings_buffer = malloc(sizeof(GPUString)*input->num_strings);
|
|
|
|
container->layers[index].strings_buffer = malloc(sizeof(GPUString)*input->num_strings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(input->num_codes + input->num_drawables > 0) {
|
|
|
|
if(input->num_codes + input->num_drawables > 0) {
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUDrawable)*(input->num_drawables + input->num_codes), &container->layers[index].drawables, &container->layers[index].drawables_memory));
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUDrawable)*(input->num_drawables + input->num_codes), &container->layers[index].drawables[i], &container->layers[index].drawables_memory[i]));
|
|
|
|
container->layers[index].drawables_buffer = malloc(sizeof(GPUDrawable)*input->num_drawables);
|
|
|
|
container->layers[index].drawables_buffer = malloc(sizeof(GPUDrawable)*input->num_drawables);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(uint32_t)*input->num_codes, &container->layers[index].codes, &container->layers[index].codes_memory));
|
|
|
|
VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(uint32_t)*input->num_codes, &container->layers[index].codes[i], &container->layers[index].codes_memory[i]));
|
|
|
|
container->layers[index].codes_buffer = malloc(sizeof(uint32_t)*input->num_codes);
|
|
|
|
container->layers[index].codes_buffer = malloc(sizeof(uint32_t)*input->num_codes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -350,19 +355,19 @@ VkResult create_layer(
|
|
|
|
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));
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
container->layers[index].data.strings = buffer_address(gpu->device, container->layers[index].strings);
|
|
|
|
container->layers[index].data.strings = buffer_address(gpu->device, container->layers[index].strings[i]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
container->layers[index].data.strings = 0x00000000;
|
|
|
|
container->layers[index].data.strings = 0x00000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
container->layers[index].data.codes = buffer_address(gpu->device, container->layers[index].codes);
|
|
|
|
container->layers[index].data.codes = buffer_address(gpu->device, container->layers[index].codes[i]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
container->layers[index].data.codes = 0x00000000;
|
|
|
|
container->layers[index].data.codes = 0x00000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(input->num_codes + input->num_drawables > 0) {
|
|
|
|
if(input->num_codes + input->num_drawables > 0) {
|
|
|
|
container->layers[index].data.drawables = buffer_address(gpu->device, container->layers[index].drawables);
|
|
|
|
container->layers[index].data.drawables = buffer_address(gpu->device, container->layers[index].drawables[i]);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
container->layers[index].data.drawables = 0x00000000;
|
|
|
|
container->layers[index].data.drawables = 0x00000000;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -384,14 +389,14 @@ VkResult create_layer(
|
|
|
|
memcpy(mapped, &container->layers[index].data, sizeof(GPULayer));
|
|
|
|
memcpy(mapped, &container->layers[index].data, sizeof(GPULayer));
|
|
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(gpu->device, gpu->transfer_pool);
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(gpu->device, gpu->transfer_pool);
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].layer, 0, 0, sizeof(GPULayer));
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].layer[i], 0, 0, sizeof(GPULayer));
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
if(input->num_strings > 0) {
|
|
|
|
GPUString* strings = (GPUString*)(mapped + sizeof(GPULayer));
|
|
|
|
GPUString* strings = (GPUString*)(mapped + sizeof(GPULayer));
|
|
|
|
for(uint32_t i = 0; i < input->num_strings; i++) {
|
|
|
|
for(uint32_t i = 0; i < input->num_strings; i++) {
|
|
|
|
memcpy(&strings[i], &input->strings[i], sizeof(GPUString));
|
|
|
|
memcpy(&strings[i], &input->strings[i], sizeof(GPUString));
|
|
|
|
memcpy(&container->layers[index].strings_buffer[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, sizeof(GPULayer), 0, sizeof(GPUString)*input->num_strings);
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].strings[i], sizeof(GPULayer), 0, sizeof(GPUString)*input->num_strings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(input->num_drawables > 0) {
|
|
|
|
if(input->num_drawables > 0) {
|
|
|
@ -400,7 +405,7 @@ VkResult create_layer(
|
|
|
|
memcpy(&drawables[i], &input->drawables[i], sizeof(GPUDrawable));
|
|
|
|
memcpy(&drawables[i], &input->drawables[i], sizeof(GPUDrawable));
|
|
|
|
memcpy(&container->layers[index].drawables_buffer[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, sizeof(GPULayer) + sizeof(GPUString)*input->num_strings, 0, sizeof(GPUDrawable)*input->num_drawables);
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].drawables[i], sizeof(GPULayer) + sizeof(GPUString)*input->num_strings, 0, sizeof(GPUDrawable)*input->num_drawables);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(input->num_codes > 0) {
|
|
|
|
if(input->num_codes > 0) {
|
|
|
@ -409,12 +414,13 @@ VkResult create_layer(
|
|
|
|
codes[i] = input->codes[i];
|
|
|
|
codes[i] = input->codes[i];
|
|
|
|
container->layers[index].codes_buffer[i] = input->codes[i];
|
|
|
|
container->layers[index].codes_buffer[i] = input->codes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
command_copy_buffer(command_buffer, transfer, container->layers[index].codes, sizeof(GPULayer) + sizeof(GPUString)*input->num_strings + sizeof(GPUDrawable)*input->num_drawables, 0, sizeof(uint32_t)*input->num_codes);
|
|
|
|
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));
|
|
|
|
VK_RESULT(command_end_single(gpu->device, command_buffer, gpu->transfer_pool, gpu->transfer_queue));
|
|
|
|
destroy_transfer_buffer(gpu->allocator, transfer, transfer_memory);
|
|
|
|
destroy_transfer_buffer(gpu->allocator, transfer, transfer_memory);
|
|
|
|
|
|
|
|
|
|
|
|
container->layers[index].address = buffer_address(gpu->device, container->layers[index].layer);
|
|
|
|
container->layers[index].address[i] = buffer_address(gpu->device, container->layers[index].layer[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|