diff options
Diffstat (limited to 'video/out/vulkan/context.c')
-rw-r--r-- | video/out/vulkan/context.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c index 5d9b40cbb5..b51bb78578 100644 --- a/video/out/vulkan/context.c +++ b/video/out/vulkan/context.c @@ -121,9 +121,10 @@ struct priv { // state of the images: struct ra_tex **images; // ra_tex wrappers for the vkimages int num_images; // size of images - VkSemaphore *acquired; // pool of semaphores used to synchronize images - int num_acquired; // size of this pool - int idx_acquired; // index of next free semaphore within this pool + VkSemaphore *sems_in; // pool of semaphores used to synchronize images + VkSemaphore *sems_out; // outgoing semaphores (rendering complete) + int num_sems; + int idx_sems; // index of next free semaphore pair int last_imgidx; // the image index last acquired (for submit) }; @@ -248,13 +249,12 @@ void ra_vk_ctx_uninit(struct ra_ctx *ctx) for (int i = 0; i < p->num_images; i++) ra_tex_free(ctx->ra, &p->images[i]); - for (int i = 0; i < p->num_acquired; i++) - vkDestroySemaphore(vk->dev, p->acquired[i], MPVK_ALLOCATOR); + for (int i = 0; i < p->num_sems; i++) { + vkDestroySemaphore(vk->dev, p->sems_in[i], MPVK_ALLOCATOR); + vkDestroySemaphore(vk->dev, p->sems_out[i], MPVK_ALLOCATOR); + } vkDestroySwapchainKHR(vk->dev, p->swapchain, MPVK_ALLOCATOR); - - talloc_free(p->images); - talloc_free(p->acquired); ctx->ra->fns->destroy(ctx->ra); ctx->ra = NULL; } @@ -382,13 +382,19 @@ bool ra_vk_ctx_resize(struct ra_swapchain *sw, int w, int h) VK(vkGetSwapchainImagesKHR(vk->dev, p->swapchain, &num, vkimages)); // If needed, allocate some more semaphores - while (num > p->num_acquired) { - VkSemaphore sem; + while (num > p->num_sems) { + VkSemaphore sem_in, sem_out; static const VkSemaphoreCreateInfo seminfo = { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, }; - VK(vkCreateSemaphore(vk->dev, &seminfo, MPVK_ALLOCATOR, &sem)); - MP_TARRAY_APPEND(NULL, p->acquired, p->num_acquired, sem); + VK(vkCreateSemaphore(vk->dev, &seminfo, MPVK_ALLOCATOR, &sem_in)); + VK(vkCreateSemaphore(vk->dev, &seminfo, MPVK_ALLOCATOR, &sem_out)); + + int idx = p->num_sems++; + MP_TARRAY_GROW(p, p->sems_in, idx); + MP_TARRAY_GROW(p, p->sems_out, idx); + p->sems_in[idx] = sem_in; + p->sems_out[idx] = sem_out; } // Recreate the ra_tex wrappers @@ -396,7 +402,7 @@ bool ra_vk_ctx_resize(struct ra_swapchain *sw, int w, int h) ra_tex_free(ra, &p->images[i]); p->num_images = num; - MP_TARRAY_GROW(NULL, p->images, p->num_images); + MP_TARRAY_GROW(p, p->images, p->num_images); for (int i = 0; i < num; i++) { p->images[i] = ra_vk_wrap_swapchain_img(ra, vkimages[i], sinfo); if (!p->images[i]) @@ -444,7 +450,7 @@ static bool start_frame(struct ra_swapchain *sw, struct ra_fbo *out_fbo) uint32_t imgidx = 0; MP_TRACE(vk, "vkAcquireNextImageKHR\n"); VkResult res = vkAcquireNextImageKHR(vk->dev, p->swapchain, UINT64_MAX, - p->acquired[p->idx_acquired], NULL, + p->sems_in[p->idx_sems], NULL, &imgidx); if (res == VK_ERROR_OUT_OF_DATE_KHR) goto error; // just return in this case @@ -469,12 +475,11 @@ static bool submit_frame(struct ra_swapchain *sw, const struct vo_frame *frame) if (!p->swapchain) goto error; - VkSemaphore acquired = p->acquired[p->idx_acquired++]; - p->idx_acquired %= p->num_acquired; + int semidx = p->idx_sems++; + p->idx_sems %= p->num_sems; - VkSemaphore done; - if (!ra_vk_submit(ra, p->images[p->last_imgidx], acquired, &done, - &p->frames_in_flight)) + if (!ra_vk_submit(ra, p->images[p->last_imgidx], p->sems_in[semidx], + p->sems_out[semidx], &p->frames_in_flight)) goto error; // Older nvidia drivers can spontaneously combust when submitting to the @@ -488,7 +493,7 @@ static bool submit_frame(struct ra_swapchain *sw, const struct vo_frame *frame) VkPresentInfoKHR pinfo = { .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .waitSemaphoreCount = 1, - .pWaitSemaphores = &done, + .pWaitSemaphores = &p->sems_out[semidx], .swapchainCount = 1, .pSwapchains = &p->swapchain, .pImageIndices = &p->last_imgidx, |