Skip to content

Commit

Permalink
Merge pull request #824 from Apprentice-Alchemist/bugfix/android-tearing
Browse files Browse the repository at this point in the history
Use an extra semaphore to ensure swapchain image presentation waits f…
  • Loading branch information
RobDangerous authored Nov 8, 2023
2 parents 7b0a981 + f446874 commit 6729b62
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,15 @@ void kinc_g5_internal_init() {
assert(!err);
}

VkSemaphoreCreateInfo presentCompleteSemaphoreCreateInfo = {0};
presentCompleteSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
presentCompleteSemaphoreCreateInfo.pNext = NULL;
presentCompleteSemaphoreCreateInfo.flags = 0;
VkSemaphoreCreateInfo semInfo = {0};
semInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
semInfo.pNext = NULL;
semInfo.flags = 0;

err = vkCreateSemaphore(vk_ctx.device, &presentCompleteSemaphoreCreateInfo, NULL, &framebuffer_available);
err = vkCreateSemaphore(vk_ctx.device, &semInfo, NULL, &framebuffer_available);
assert(!err);

err = vkCreateSemaphore(vk_ctx.device, &semInfo, NULL, &relay_semaphore);
assert(!err);
}

Expand Down Expand Up @@ -1101,16 +1104,14 @@ void kinc_g5_begin(kinc_g5_render_target_t *renderTarget, int window_index) {
}

void kinc_g5_end(int window) {
#ifdef KORE_ANDROID
vkDeviceWaitIdle(vk_ctx.device);
#endif

VkPresentInfoKHR present = {0};
present.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
present.pNext = NULL;
present.swapchainCount = 1;
present.pSwapchains = &vk_ctx.windows[vk_ctx.current_window].swapchain;
present.pImageIndices = &vk_ctx.windows[vk_ctx.current_window].current_image;
present.pWaitSemaphores = &relay_semaphore;
present.waitSemaphoreCount = 1;

VkResult err = vk.fpQueuePresentKHR(vk_ctx.queue, &present);
if (err == VK_ERROR_SURFACE_LOST_KHR) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,14 +827,14 @@ void kinc_g5_command_list_execute(kinc_g5_command_list_t *list) {
wait_for_framebuffer = false;
}
else {
submit_info.waitSemaphoreCount = 0;
submit_info.pWaitSemaphores = NULL;
submit_info.waitSemaphoreCount = 1;
submit_info.pWaitSemaphores = &relay_semaphore;
}
submit_info.pWaitDstStageMask = &pipe_stage_flags;
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers = &list->impl._buffer;
submit_info.signalSemaphoreCount = 0;
submit_info.pSignalSemaphores = NULL;
submit_info.signalSemaphoreCount = 1;
submit_info.pSignalSemaphores = &relay_semaphore;

err = vkQueueSubmit(vk_ctx.queue, 1, &submit_info, list->impl.fence);
assert(!err);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "vulkan.h"

static VkSemaphore framebuffer_available;
static VkSemaphore relay_semaphore;
static void command_list_should_wait_for_framebuffer(void);

#include "Vulkan.c.h"
Expand Down

0 comments on commit 6729b62

Please sign in to comment.