Zero GPU pointers before upload, recreate projection matrix on framebuffer recreation

main
noah metz 2024-11-03 14:52:54 -07:00
parent 7f6045096b
commit 9d3e15398b
3 changed files with 22 additions and 7 deletions

@ -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;

@ -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;
}

@ -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;