From f0892fd9025853c2faad6da1efe096bebd4a6d48 Mon Sep 17 00:00:00 2001 From: qwertzuiopy Date: Fri, 28 Feb 2025 17:54:00 +0100 Subject: [PATCH] Fix freeze on fullscreen --- src/vulkan.c | 29 +++++++---------------------- src/vulkan.h | 1 + 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/vulkan.c b/src/vulkan.c index 5bd077e..dcda392 100644 --- a/src/vulkan.c +++ b/src/vulkan.c @@ -1,7 +1,6 @@ #include "vulkan.h" #include "kitty.h" #include "log.h" -#include "matrix.h" #include "types.h" #include "image.h" @@ -12,24 +11,6 @@ #include #include -#define VERTEX_ATTRIBUTE_COUNT 2 - -#define QUAD_VERTEX_COUNT 3 -struct Vertex quad_vertices[QUAD_VERTEX_COUNT] = { - (struct Vertex){(struct Vec2){.x = 0.0f, .y = -0.5f}, - (struct Vec3){1.0f, 0.0f, 1.0f}}, - (struct Vertex){(struct Vec2){.x = 0.5f, .y = 0.5f}, - (struct Vec3){1.0f, 0.0f, 0.2f}}, - (struct Vertex){(struct Vec2){.x = -0.5f, .y = 0.5f}, - (struct Vec3){0.2f, 0.0f, 1.0f}}, -}; - -struct UBO { - struct mat3x3 model; - struct mat3x3 view; - struct mat3x3 proj; -}; - VkVertexInputBindingDescription get_vertex_binding_description() { VkVertexInputBindingDescription description = {0}; description.binding = 0; @@ -796,9 +777,12 @@ void uninit_vk(struct Vk *state) { } void vk_draw(struct Vk *state) { - CHECK_VK_RESULT(vkWaitForFences( - state->device, 1, &state->flights[state->current_frame].in_flight_fence, - VK_TRUE, UINT64_MAX)); + if (state->should_wait_for_fences) { + CHECK_VK_RESULT(vkWaitForFences( + state->device, 1, &state->flights[state->current_frame].in_flight_fence, + VK_TRUE, UINT64_MAX)); + state->should_wait_for_fences = true; + } CHECK_VK_RESULT(vkResetFences( state->device, 1, &state->flights[state->current_frame].in_flight_fence)); @@ -815,6 +799,7 @@ void vk_draw(struct Vk *state) { meow("recreating swapchain"); CHECK_VK_RESULT(vkDeviceWaitIdle(state->device)); recreate_swapchain(state); + state->should_wait_for_fences = false; return; } else if (result < 0) { CHECK_VK_RESULT(result); diff --git a/src/vulkan.h b/src/vulkan.h index 8518f05..93ca40d 100644 --- a/src/vulkan.h +++ b/src/vulkan.h @@ -95,6 +95,7 @@ struct Vk { uint32_t width; uint32_t heigh; VkRenderPass render_pass; + bool should_wait_for_fences; struct GpuMem *mem; struct da_Kitty kitties;