From 9d3e15398b8983cab8c2f39eb85809ccfa6e2b7e Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sun, 3 Nov 2024 14:52:54 -0700 Subject: [PATCH] Zero GPU pointers before upload, recreate projection matrix on framebuffer recreation --- client/src/gpu.c | 3 ++- client/src/hex.c | 8 ++++---- client/src/main.c | 18 ++++++++++++++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/client/src/gpu.c b/client/src/gpu.c index eb14e9c..087f9b9 100644 --- a/client/src/gpu.c +++ b/client/src/gpu.c @@ -900,13 +900,14 @@ VkResult create_frame_context( VK_RESULT(vkAllocateCommandBuffers(device, &command_info, &frame->transfer_commands)); VK_RESULT(vkAllocateCommandBuffers(device, &command_info, &frame->compute_commands)); - // TODO: better defaults + frame->transfers[0].written = 0; frame->transfers[0].max_size = 1; frame->transfers[0].max_count = 1; frame->transfers[0].count = 0; frame->transfers[0].infos = malloc(sizeof(TransferInfo)*frame->transfers[0].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].written = 0; frame->transfers[1].max_size = 1; frame->transfers[1].max_count = 1; frame->transfers[1].count = 0; diff --git a/client/src/hex.c b/client/src/hex.c index 12892e5..afe406c 100644 --- a/client/src/hex.c +++ b/client/src/hex.c @@ -195,6 +195,7 @@ VkResult create_hex_context( VK_RESULT(vkCreateGraphicsPipelines(gpu->device, VK_NULL_HANDLE, 1, &graphics_pipeline_info, NULL, &context->graphics.pipeline)); + memset(&context->data, 0, sizeof(GPUHexContext)); glm_perspective(-M_PI*1/8, (float)gpu->swapchain_extent.width/(float)gpu->swapchain_extent.height, 0.01, 1000, context->data.proj); glm_mat4_identity(context->data.view); VK_RESULT(create_storage_buffer( @@ -203,9 +204,8 @@ VkResult create_hex_context( sizeof(GPUHexContext), &context->context, &context->context_memory)); - fprintf(stderr, "Created hex context %p\n", context->context); context->address = buffer_address(gpu->device, context->context); - VK_RESULT(add_transfer(&context->data, context->context, 0, sizeof(GPUHexContext) - (sizeof(GPUHexContext) - offsetof(GPUHexContext, regions)), 0, gpu)); + VK_RESULT(add_transfer(&context->data, context->context, 0, sizeof(GPUHexContext), gpu->current_frame, gpu)); return VK_SUCCESS; } @@ -233,11 +233,11 @@ VkResult create_hex_region(int32_t q, int32_t r, HexRegion** region, HexContext* sizeof(GPUHexRegion), &(*region)->region, &(*region)->region_memory)); - VK_RESULT(add_transfer(&(*region)->q, (*region)->region, offsetof(GPUHexRegion, q), sizeof(uint32_t)*2, 0, gpu)); + VK_RESULT(add_transfer(&(*region)->q, (*region)->region, offsetof(GPUHexRegion, q), sizeof(uint32_t)*2, gpu->current_frame, gpu)); (*region)->address = buffer_address(gpu->device, (*region)->region); - VK_RESULT(add_transfer(&(*region)->address, hex->context, offsetof(GPUHexContext, regions) + sizeof(VkDeviceAddress)*i, sizeof(VkDeviceAddress), 0, gpu)); + VK_RESULT(add_transfer(&(*region)->address, hex->context, offsetof(GPUHexContext, regions) + sizeof(VkDeviceAddress)*i, sizeof(VkDeviceAddress), gpu->current_frame, gpu)); return VK_SUCCESS; } diff --git a/client/src/main.c b/client/src/main.c index 5e3cca2..8f8b7ef 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -156,8 +156,22 @@ VkResult main_thread(ClientContext* context) { context->zoom != 0 || context->cur_spin[0] != 0 || context->cur_spin[1] != 0 || context->render->framebuffer_recreated == true) && frame > 0) { - // signal it as handled - context->render->framebuffer_recreated = false; + if(context->render->framebuffer_recreated == true) { + context->render->framebuffer_recreated = false; + glm_perspective( + -M_PI*1/8, + (float)context->render->swapchain_extent.width/(float)context->render->swapchain_extent.height, + 0.01, + 1000, + context->hex->data.proj); + VK_RESULT(add_transfer( + &context->hex->data.proj, + context->hex->context, + offsetof(GPUHexContext, proj), + sizeof(mat4), + context->render->current_frame, + context->render)); + } context->rotation[0] += (float)context->key_spin[0]*delta_time*context->key_spin_speed; context->rotation[0] += (float)context->cur_spin[0]*delta_time*context->cur_spin_speed;