Consolidate overlapping transfers(no mechanism yet to consolidate transfers that dont overlap completely

main
noah metz 2024-11-06 15:47:58 -07:00
parent 034ee66224
commit d2f1f5d5fd
2 changed files with 26 additions and 2 deletions

@ -94,6 +94,13 @@ VkResult draw_frame(
VkDeviceSize src_offset = 0;
for(uint32_t tid = 0; tid < transfer->count; tid++) {
#ifdef DEBUG_GPU_TRANSFERS
fprintf(stderr, "Transferring %lld bytes: ", transfer->infos[tid].size);
for(VkDeviceSize i = 0; i < transfer->infos[tid].size; i++) {
fprintf(stderr, "%02X", ((uint8_t*)transfer->mapped)[src_offset + i]);
}
fprintf(stderr, " to %p\n", transfer->infos[tid].buffer);
#endif
command_copy_buffer(
transfer_commands,
transfer->buffer,

@ -1294,8 +1294,25 @@ VkResult add_transfer(
VkDeviceSize src_offset = 0;
for(uint32_t i = 0; i < transfer->count; i++) {
if(transfer->infos[i].buffer == buffer && transfer->infos[i].size == size && transfer->infos[i].offset == offset) {
memcpy(transfer->mapped + src_offset, data, size);
/*
Adding size 32 write to 0x4b000000004b at offset 0
size = 32, offset = 0, info->offset = 0
Adding size 8 write to 0x4b000000004b at offset 44
size = 8, offset = 44, info->offset = 0
Transferring 32 bytes: 90605F3D228D5A448B925AC4C8FA45429E195A42E0EE36C4E0CA214400B07F3F to 0x4b000000004b
*/
VkDeviceSize diff = offset - transfer->infos[i].offset;
if(transfer->infos[i].buffer == buffer
&& transfer->infos[i].offset <= offset
&& transfer->infos[i].size >= (size + diff)) {
#ifdef DEBUG_GPU_TRANSFERS
fprintf(stderr, "Adding size %lld write to %p at offset %lld with diff %lld\n", size, buffer, src_offset + diff, diff);
#endif
memcpy(transfer->mapped + src_offset + diff, data, size);
return VK_SUCCESS;
} else {
src_offset += transfer->infos[i].size;