diff --git a/client/include/gpu.h b/client/include/gpu.h index 9107ad3..322b87a 100644 --- a/client/include/gpu.h +++ b/client/include/gpu.h @@ -85,9 +85,7 @@ typedef struct FrameContextStruct { VkSemaphore render; VkSemaphore transfer; VkSemaphore compute; - VkSemaphore frame; - uint64_t frame_index; uint64_t transfer_index; uint64_t compute_index; diff --git a/client/include/ui.h b/client/include/ui.h index 114335b..afb6fb2 100644 --- a/client/include/ui.h +++ b/client/include/ui.h @@ -105,11 +105,6 @@ typedef struct GPUDrawableStruct { } GPUDrawable; typedef struct GPULayerStruct { - VkDeviceAddress strings; - VkDeviceAddress codes; - - VkDeviceAddress drawables; - DrawCommand draw; DispatchCommand dispatch_strings; @@ -118,6 +113,9 @@ typedef struct GPULayerStruct { uint32_t max_strings; uint32_t num_drawables; + VkDeviceAddress strings; + VkDeviceAddress codes; + VkDeviceAddress drawables; VkDeviceAddress container; } GPULayer; diff --git a/client/shader_src/ui_common.glsl b/client/shader_src/ui_common.glsl index 678399a..fc3ee96 100644 --- a/client/shader_src/ui_common.glsl +++ b/client/shader_src/ui_common.glsl @@ -88,10 +88,6 @@ layout(std430, buffer_reference) readonly buffer Container { }; layout(std430, buffer_reference) readonly buffer Layer { - StringList strings; - CodeList codes; - DrawableList drawables; - DrawCommand draw; DispatchCommand dispatch; @@ -100,6 +96,9 @@ layout(std430, buffer_reference) readonly buffer Layer { uint max_strings; uint num_drawables; + StringList strings; + CodeList codes; + DrawableList drawables; Container container; }; diff --git a/client/src/draw.c b/client/src/draw.c index b1d53dd..d16b50d 100644 --- a/client/src/draw.c +++ b/client/src/draw.c @@ -87,11 +87,11 @@ VkResult draw_frame( VK_RESULT(vkEndCommandBuffer(transfer_commands)); frame->transfer_index += 1; - VkPipelineStageFlags transfer_wait_stages[] = {VK_PIPELINE_STAGE_TRANSFER_BIT}; + transfer->count = 0; + transfer->written = 0; + VkTimelineSemaphoreSubmitInfo transfer_timeline = { .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO, - .waitSemaphoreValueCount = 1, - .pWaitSemaphoreValues = &frame->frame_index, .signalSemaphoreValueCount = 1, .pSignalSemaphoreValues = &frame->transfer_index, }; @@ -101,14 +101,9 @@ VkResult draw_frame( .pCommandBuffers = &transfer_commands, .pSignalSemaphores = &frame->transfer, .signalSemaphoreCount = 1, - .pWaitSemaphores = &frame->frame, - .pWaitDstStageMask = transfer_wait_stages, - .waitSemaphoreCount = 1, .pNext = &transfer_timeline, }; VK_RESULT(vkQueueSubmit(context->transfer_queue.handle, 1, &transfer_submit, VK_NULL_HANDLE)); - transfer->count = 0; - transfer->written = 0; VkCommandBuffer compute_commands = frame->compute_commands; VK_RESULT(vkResetCommandBuffer(compute_commands, 0)); @@ -183,12 +178,11 @@ VkResult draw_frame( vkCmdEndRenderPass(command_buffer); VK_RESULT(vkEndCommandBuffer(command_buffer)); - frame->frame_index += 1; VkPipelineStageFlags wait_stages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT}; VkSemaphore wait_semaphores[] = {frame->image, frame->compute}; - VkSemaphore signal_semaphores[] = {frame->render, frame->frame}; + VkSemaphore signal_semaphores[] = {frame->render}; uint64_t wait_values[] = {0, frame->compute_index}; - uint64_t signal_values[] = {0, frame->frame_index}; + uint64_t signal_values[] = {0}; VkTimelineSemaphoreSubmitInfo timeline_info = { .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO, .signalSemaphoreValueCount = sizeof(signal_values)/sizeof(uint64_t), diff --git a/client/src/gpu.c b/client/src/gpu.c index dcccbb9..375678f 100644 --- a/client/src/gpu.c +++ b/client/src/gpu.c @@ -781,10 +781,8 @@ VkResult create_frame_context(VkDevice device, VmaAllocator allocator, VkCommand frame->image = create_semaphore(device); frame->render = create_semaphore(device); frame->transfer = create_timeline_semaphore(device); - frame->frame = create_timeline_semaphore(device); frame->compute = create_timeline_semaphore(device); - frame->frame_index = 0; frame->transfer_index = 0; frame->compute_index = 0; diff --git a/client/src/main.c b/client/src/main.c index ab48025..8b93d28 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -189,12 +189,17 @@ VkResult main_thread(ClientContext* context) { // double last_draw = 0; - double draw_interval = 0.5; - double frame_count = 0; + double draw_interval = 1; uint32_t* mapped_codes = context->ui.containers[0].layers[0].codes_buffer; GPUString* mapped_string = context->ui.containers[0].layers[0].strings_buffer; char str[11] = "1234567890"; map_string(str, mapped_codes, 0, 0, &context->ui); + VK_RESULT(add_transfers( + context->ui.containers[0].layers[0].codes_buffer, + context->ui.containers[0].layers[0].codes, + 0, + 10*sizeof(uint32_t), + &context->render)); int test = 0; // @@ -205,25 +210,20 @@ VkResult main_thread(ClientContext* context) { // Very odd, but must be a clue, adding transfers when current_frame == 0 consistently causes // the rendering glitch, and current_frame == 1 has no rendering glitch - if((frame_time - last_draw) > draw_interval && context->render.current_frame == 0) { + if((frame_time - last_draw) > draw_interval && context->render.current_frame == 1) { test = (test + 1) % 7; mapped_string->length = test; last_draw = frame_time; - frame_count = 0; - VK_RESULT(add_transfers( - context->ui.containers[0].layers[0].codes_buffer, - context->ui.containers[0].layers[0].codes, - 0, - 10*sizeof(uint32_t), - &context->render)); VK_RESULT(add_transfers( &context->ui.containers[0].layers[0].strings_buffer[0].length, context->ui.containers[0].layers[0].strings, offsetof(GPUString, length), sizeof(uint32_t), &context->render)); + + fprintf(stderr, "Added transfers for %d\n", test); } // @@ -233,7 +233,6 @@ VkResult main_thread(ClientContext* context) { glfwDestroyWindow(context->window); } - frame_count += 1; } return 0; diff --git a/client/src/ui.c b/client/src/ui.c index 0388873..5bf1ad6 100644 --- a/client/src/ui.c +++ b/client/src/ui.c @@ -329,39 +329,55 @@ VkResult create_layer( uint32_t max_codes = (input->num_codes > input->max_codes) ? input->num_codes : input->max_codes; uint32_t max_drawables = (input->num_drawables > input->max_drawables) ? input->num_drawables : input->max_drawables; + if(max_strings > 0) { + container->layers[index].strings_buffer = malloc(sizeof(GPUString)*max_strings); + } + + if(max_drawables > 0) { + container->layers[index].drawables_buffer = malloc(sizeof(GPUDrawable)*max_drawables); + } + + if(max_codes > 0) { + container->layers[index].codes_buffer = malloc(sizeof(uint32_t)*max_codes); + } + 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(max_strings > 0) { VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUString)*max_strings, &container->layers[index].strings[i], &container->layers[index].strings_memory[i])); - container->layers[index].strings_buffer = malloc(sizeof(GPUString)*max_strings); + VkDeviceAddress address = buffer_address(gpu->device, container->layers[index].strings[i]); + add_transfer( + &address, + container->layers[index].layer[i], + offsetof(GPULayer, strings), + sizeof(VkDeviceAddress), + i, + gpu); } if(max_codes + max_drawables > 0) { VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(GPUDrawable)*(max_drawables + max_codes), &container->layers[index].drawables[i], &container->layers[index].drawables_memory[i])); - container->layers[index].drawables_buffer = malloc(sizeof(GPUDrawable)*max_drawables); + VkDeviceAddress address = buffer_address(gpu->device, container->layers[index].drawables[i]); + add_transfer( + &address, + container->layers[index].layer[i], + offsetof(GPULayer, drawables), + sizeof(VkDeviceAddress), + i, + gpu); } if(max_codes > 0) { VK_RESULT(create_storage_buffer(gpu->allocator, 0, sizeof(uint32_t)*max_codes, &container->layers[index].codes[i], &container->layers[index].codes_memory[i])); - container->layers[index].codes_buffer = malloc(sizeof(uint32_t)*max_codes); + VkDeviceAddress address = buffer_address(gpu->device, container->layers[index].codes[i]); + add_transfer( + &address, + container->layers[index].layer[i], + offsetof(GPULayer, codes), + sizeof(VkDeviceAddress), + i, + gpu); } - if(max_strings > 0) { - container->layers[index].data.strings = buffer_address(gpu->device, container->layers[index].strings[i]); - } else { - container->layers[index].data.strings = 0x00000000; - } - - if(max_codes > 0) { - container->layers[index].data.codes = buffer_address(gpu->device, container->layers[index].codes[i]); - } else { - container->layers[index].data.codes = 0x00000000; - } - - if(max_codes + max_drawables > 0) { - container->layers[index].data.drawables = buffer_address(gpu->device, container->layers[index].drawables[i]); - } 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]); @@ -391,7 +407,7 @@ VkResult create_layer( 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); + add_transfers(&container->layers[index].data, container->layers[index].layer, 0, sizeof(GPULayer)-4*sizeof(VkDeviceAddress), gpu); if(input->num_strings > 0) { memcpy(container->layers[index].strings_buffer, input->strings, sizeof(GPUString)*input->num_strings);