|
|
@ -798,11 +798,17 @@ VkResult create_frame_context(VkDevice device, VmaAllocator allocator, VkCommand
|
|
|
|
VK_RESULT(vkAllocateCommandBuffers(device, &command_info, &frame->compute_commands));
|
|
|
|
VK_RESULT(vkAllocateCommandBuffers(device, &command_info, &frame->compute_commands));
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: better defaults
|
|
|
|
// TODO: better defaults
|
|
|
|
frame->transfer_max_size = 1;
|
|
|
|
frame->transfers[0].max_size = 1;
|
|
|
|
frame->transfer_max_count = 1;
|
|
|
|
frame->transfers[0].max_count = 1;
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, frame->transfer_max_size, &frame->transfer_buffer, &frame->transfer_memory, &frame->transfer_mapped));
|
|
|
|
frame->transfers[0].count = 0;
|
|
|
|
frame->transfer_count = 0;
|
|
|
|
frame->transfers[0].infos = malloc(sizeof(TransferInfo)*frame->transfers[0].max_count);
|
|
|
|
frame->transfer_infos = malloc(sizeof(TransferInfo)*frame->transfer_max_count);
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, frame->transfers[0].max_size, &frame->transfers[0].buffer, &frame->transfers[0].memory, &frame->transfers[0].mapped));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
frame->transfers[1].max_size = 1;
|
|
|
|
|
|
|
|
frame->transfers[1].max_count = 1;
|
|
|
|
|
|
|
|
frame->transfers[1].count = 0;
|
|
|
|
|
|
|
|
frame->transfers[1].infos = malloc(sizeof(TransferInfo)*frame->transfers[1].max_count);
|
|
|
|
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, frame->transfers[1].max_size, &frame->transfers[1].buffer, &frame->transfers[1].memory, &frame->transfers[1].mapped));
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1124,10 +1130,11 @@ VkResult add_transfer(
|
|
|
|
VkResult result;
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
|
|
FrameContext* frame = &gpu->frame[frame_index];
|
|
|
|
FrameContext* frame = &gpu->frame[frame_index];
|
|
|
|
|
|
|
|
TransferBuffer* transfer = &frame->transfers[frame->transfer_index % 2];
|
|
|
|
|
|
|
|
|
|
|
|
if(frame->transfer_written + size >= frame->transfer_max_size) {
|
|
|
|
if(transfer->written + size >= transfer->max_size) {
|
|
|
|
uint32_t new_size = 2*frame->transfer_max_size;
|
|
|
|
uint32_t new_size = 2*transfer->max_size;
|
|
|
|
while(frame->transfer_written + size >= new_size) {
|
|
|
|
while(transfer->written + size >= new_size) {
|
|
|
|
new_size *= 2;
|
|
|
|
new_size *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
VkBuffer new_transfer;
|
|
|
|
VkBuffer new_transfer;
|
|
|
@ -1135,33 +1142,33 @@ VkResult add_transfer(
|
|
|
|
void* new_transfer_data;
|
|
|
|
void* new_transfer_data;
|
|
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_transfer_buffer(gpu->allocator, new_size, &new_transfer, &new_transfer_memory, &new_transfer_data));
|
|
|
|
VK_RESULT(create_transfer_buffer(gpu->allocator, new_size, &new_transfer, &new_transfer_memory, &new_transfer_data));
|
|
|
|
memcpy(new_transfer_data, frame->transfer_mapped, frame->transfer_written);
|
|
|
|
memcpy(new_transfer_data, transfer->mapped, transfer->written);
|
|
|
|
destroy_transfer_buffer(gpu->allocator, frame->transfer_buffer, frame->transfer_memory);
|
|
|
|
destroy_transfer_buffer(gpu->allocator, transfer->buffer, transfer->memory);
|
|
|
|
frame->transfer_buffer = new_transfer;
|
|
|
|
transfer->buffer = new_transfer;
|
|
|
|
frame->transfer_memory = new_transfer_memory;
|
|
|
|
transfer->memory = new_transfer_memory;
|
|
|
|
frame->transfer_mapped = new_transfer_data;
|
|
|
|
transfer->mapped = new_transfer_data;
|
|
|
|
frame->transfer_max_size = new_size;
|
|
|
|
transfer->max_size = new_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(frame->transfer_count + 1 >= frame->transfer_max_count) {
|
|
|
|
if(transfer->count + 1 >= transfer->max_count) {
|
|
|
|
void* new_infos = malloc(sizeof(TransferInfo)*2*frame->transfer_max_count);
|
|
|
|
void* new_infos = malloc(sizeof(TransferInfo)*2*transfer->max_count);
|
|
|
|
if(new_infos == NULL) {
|
|
|
|
if(new_infos == NULL) {
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memcpy(new_infos, frame->transfer_infos, sizeof(TransferInfo)*frame->transfer_count);
|
|
|
|
memcpy(new_infos, transfer->infos, sizeof(TransferInfo)*transfer->count);
|
|
|
|
free(frame->transfer_infos);
|
|
|
|
free(transfer->infos);
|
|
|
|
frame->transfer_infos = new_infos;
|
|
|
|
transfer->infos = new_infos;
|
|
|
|
frame->transfer_max_count *= 2;
|
|
|
|
transfer->max_count *= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
memcpy(frame->transfer_mapped + frame->transfer_written, data, size);
|
|
|
|
memcpy(transfer->mapped + transfer->written, data, size);
|
|
|
|
frame->transfer_infos[frame->transfer_count].size = size;
|
|
|
|
transfer->infos[transfer->count].size = size;
|
|
|
|
frame->transfer_infos[frame->transfer_count].buffer = buffer;
|
|
|
|
transfer->infos[transfer->count].buffer = buffer;
|
|
|
|
frame->transfer_infos[frame->transfer_count].offset = offset;
|
|
|
|
transfer->infos[transfer->count].offset = offset;
|
|
|
|
|
|
|
|
|
|
|
|
frame->transfer_written += size;
|
|
|
|
transfer->written += size;
|
|
|
|
frame->transfer_count += 1;
|
|
|
|
transfer->count += 1;
|
|
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
return VK_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|