|
|
|
@ -789,10 +789,12 @@ VkResult create_frame_context(VkDevice device, VmaAllocator allocator, VkCommand
|
|
|
|
|
};
|
|
|
|
|
VK_RESULT(vkAllocateCommandBuffers(device, &command_info, frame->transfer_commands));
|
|
|
|
|
|
|
|
|
|
// TODO: temp size values, add dynamic resizing
|
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, 1024, &frame->transfer_buffer, &frame->transfer_memory, &frame->transfer_mapped));
|
|
|
|
|
// TODO: better defaults
|
|
|
|
|
frame->transfer_max_size = 1;
|
|
|
|
|
frame->transfer_max_count = 1;
|
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, frame->transfer_max_size, &frame->transfer_buffer, &frame->transfer_memory, &frame->transfer_mapped));
|
|
|
|
|
frame->transfer_count = 0;
|
|
|
|
|
frame->transfer_infos = malloc(sizeof(TransferInfo)*10);
|
|
|
|
|
frame->transfer_infos = malloc(sizeof(TransferInfo)*frame->transfer_max_count);
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
@ -1090,3 +1092,51 @@ VkResult command_transition_image_layout(VkDevice device, VkCommandPool transfer
|
|
|
|
|
|
|
|
|
|
return command_end_single(device, command_buffer, transfer_pool, transfer_queue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult add_transfer(
|
|
|
|
|
void* data,
|
|
|
|
|
VkBuffer* buffers,
|
|
|
|
|
VkDeviceSize offset,
|
|
|
|
|
VkDeviceSize size,
|
|
|
|
|
RenderContext* gpu) {
|
|
|
|
|
VkResult result;
|
|
|
|
|
FrameContext* frame = &gpu->frame[gpu->current_frame];
|
|
|
|
|
|
|
|
|
|
while(frame->transfer_written + size >= frame->transfer_max_size) {
|
|
|
|
|
VkBuffer new_transfer;
|
|
|
|
|
VmaAllocation new_transfer_memory;
|
|
|
|
|
void* new_transfer_data;
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_transfer_buffer(gpu->allocator, 2*frame->transfer_max_size, &new_transfer, &new_transfer_memory, &new_transfer_data));
|
|
|
|
|
memcpy(new_transfer_data, frame->transfer_mapped, frame->transfer_written);
|
|
|
|
|
destroy_transfer_buffer(gpu->allocator, frame->transfer_buffer, frame->transfer_memory);
|
|
|
|
|
frame->transfer_buffer = new_transfer;
|
|
|
|
|
frame->transfer_memory = new_transfer_memory;
|
|
|
|
|
frame->transfer_mapped = new_transfer_data;
|
|
|
|
|
frame->transfer_max_size *= 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(frame->transfer_count + 1 >= frame->transfer_max_count) {
|
|
|
|
|
void* new_infos = malloc(sizeof(TransferInfo)*2*frame->transfer_max_count);
|
|
|
|
|
if(new_infos == NULL) {
|
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(new_infos, frame->transfer_infos, sizeof(TransferInfo)*frame->transfer_count);
|
|
|
|
|
free(frame->transfer_infos);
|
|
|
|
|
frame->transfer_infos = new_infos;
|
|
|
|
|
frame->transfer_max_count *= 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(frame->transfer_mapped + frame->transfer_written, data, size);
|
|
|
|
|
frame->transfer_infos[frame->transfer_count].size = size;
|
|
|
|
|
for(uint32_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) {
|
|
|
|
|
frame->transfer_infos[frame->transfer_count].buffers[i] = buffers[i];
|
|
|
|
|
}
|
|
|
|
|
frame->transfer_infos[frame->transfer_count].offset = offset;
|
|
|
|
|
|
|
|
|
|
frame->transfer_written += size;
|
|
|
|
|
frame->transfer_count += 1;
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|