mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-19 13:18:32 +00:00
c/main: stop allocating vkCommandBuffer each blit
This commit is contained in:
parent
e931e0fed9
commit
a6c30b4083
|
@ -169,6 +169,11 @@ comp_window_peek_create(struct comp_compositor *c)
|
||||||
COMP_ERROR(c, "vkCreateSemaphore: %s", vk_result_string(ret));
|
COMP_ERROR(c, "vkCreateSemaphore: %s", vk_result_string(ret));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = vk_init_cmd_buffer(vk, &w->cmd);
|
||||||
|
if (ret != VK_SUCCESS) {
|
||||||
|
COMP_ERROR(c, "vk_init_cmd_buffer: %s", vk_result_string(ret));
|
||||||
|
}
|
||||||
|
|
||||||
os_thread_helper_init(&w->oth);
|
os_thread_helper_init(&w->oth);
|
||||||
os_thread_helper_start(&w->oth, window_peek_run_thread, w);
|
os_thread_helper_start(&w->oth, window_peek_run_thread, w);
|
||||||
|
|
||||||
|
@ -187,6 +192,9 @@ comp_window_peek_destroy(struct comp_window_peek **w_ptr)
|
||||||
|
|
||||||
SDL_DestroyWindow(w->window);
|
SDL_DestroyWindow(w->window);
|
||||||
|
|
||||||
|
struct vk_bundle *vk = get_vk(w);
|
||||||
|
vk->vkFreeCommandBuffers(vk->device, vk->cmd_pool, 1, &w->cmd);
|
||||||
|
|
||||||
comp_target_swapchain_cleanup(&w->base);
|
comp_target_swapchain_cleanup(&w->base);
|
||||||
os_thread_helper_destroy(&w->oth);
|
os_thread_helper_destroy(&w->oth);
|
||||||
|
|
||||||
|
@ -222,12 +230,15 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
|
|
||||||
struct vk_bundle *vk = get_vk(w);
|
struct vk_bundle *vk = get_vk(w);
|
||||||
|
|
||||||
VkCommandBuffer cmd;
|
|
||||||
vk_init_cmd_buffer(vk, &cmd);
|
|
||||||
|
|
||||||
// For submitting commands.
|
// For submitting commands.
|
||||||
os_mutex_lock(&vk->cmd_pool_mutex);
|
os_mutex_lock(&vk->cmd_pool_mutex);
|
||||||
|
|
||||||
|
VkCommandBufferBeginInfo begin_info = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
|
||||||
|
};
|
||||||
|
|
||||||
|
ret = vk->vkBeginCommandBuffer(w->cmd, &begin_info);
|
||||||
|
|
||||||
VkImageSubresourceRange range = {
|
VkImageSubresourceRange range = {
|
||||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
.baseMipLevel = 0,
|
.baseMipLevel = 0,
|
||||||
|
@ -239,7 +250,7 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
// Barrier to make source a source
|
// Barrier to make source a source
|
||||||
vk_cmd_image_barrier_locked( //
|
vk_cmd_image_barrier_locked( //
|
||||||
vk, // vk_bundle
|
vk, // vk_bundle
|
||||||
cmd, // cmdbuffer
|
w->cmd, // cmdbuffer
|
||||||
src, // image
|
src, // image
|
||||||
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // srcAccessMask
|
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // srcAccessMask
|
||||||
VK_ACCESS_TRANSFER_READ_BIT, // dstAccessMask
|
VK_ACCESS_TRANSFER_READ_BIT, // dstAccessMask
|
||||||
|
@ -252,7 +263,7 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
// Barrier to make destination a destination
|
// Barrier to make destination a destination
|
||||||
vk_cmd_image_barrier_locked( //
|
vk_cmd_image_barrier_locked( //
|
||||||
vk, // vk_bundle
|
vk, // vk_bundle
|
||||||
cmd, // cmdbuffer
|
w->cmd, // cmdbuffer
|
||||||
dst, // image
|
dst, // image
|
||||||
0, // srcAccessMask
|
0, // srcAccessMask
|
||||||
VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
|
VK_ACCESS_TRANSFER_WRITE_BIT, // dstAccessMask
|
||||||
|
@ -281,7 +292,7 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
blit.dstOffsets[1].z = 1;
|
blit.dstOffsets[1].z = 1;
|
||||||
|
|
||||||
vk->vkCmdBlitImage( //
|
vk->vkCmdBlitImage( //
|
||||||
cmd, // commandBuffer
|
w->cmd, // commandBuffer
|
||||||
src, // srcImage
|
src, // srcImage
|
||||||
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // srcImageLayout
|
VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // srcImageLayout
|
||||||
dst, // dstImage
|
dst, // dstImage
|
||||||
|
@ -294,7 +305,7 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
// Reset destination
|
// Reset destination
|
||||||
vk_cmd_image_barrier_locked( //
|
vk_cmd_image_barrier_locked( //
|
||||||
vk, // vk_bundle
|
vk, // vk_bundle
|
||||||
cmd, // cmdbuffer
|
w->cmd, // cmdbuffer
|
||||||
dst, // image
|
dst, // image
|
||||||
VK_ACCESS_TRANSFER_WRITE_BIT, // srcAccessMask
|
VK_ACCESS_TRANSFER_WRITE_BIT, // srcAccessMask
|
||||||
0, // dstAccessMask
|
0, // dstAccessMask
|
||||||
|
@ -307,7 +318,7 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
// Reset src
|
// Reset src
|
||||||
vk_cmd_image_barrier_locked( //
|
vk_cmd_image_barrier_locked( //
|
||||||
vk, // vk_bundle
|
vk, // vk_bundle
|
||||||
cmd, // cmdbuffer
|
w->cmd, // cmdbuffer
|
||||||
src, // image
|
src, // image
|
||||||
VK_ACCESS_TRANSFER_READ_BIT, // srcAccessMask
|
VK_ACCESS_TRANSFER_READ_BIT, // srcAccessMask
|
||||||
0, // dstAccessMask
|
0, // dstAccessMask
|
||||||
|
@ -317,17 +328,15 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // dstStageMask
|
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, // dstStageMask
|
||||||
range); // subresourceRange
|
range); // subresourceRange
|
||||||
|
|
||||||
ret = vk->vkEndCommandBuffer(cmd);
|
ret = vk->vkEndCommandBuffer(w->cmd);
|
||||||
|
|
||||||
|
os_mutex_unlock(&vk->cmd_pool_mutex);
|
||||||
|
|
||||||
if (ret != VK_SUCCESS) {
|
if (ret != VK_SUCCESS) {
|
||||||
VK_ERROR(vk, "Error: Could not end command buffer.\n");
|
VK_ERROR(vk, "Error: Could not end command buffer.\n");
|
||||||
vk->vkFreeCommandBuffers(vk->device, vk->cmd_pool, 1, &cmd);
|
|
||||||
os_mutex_unlock(&vk->cmd_pool_mutex);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
os_mutex_unlock(&vk->cmd_pool_mutex);
|
|
||||||
|
|
||||||
VkPipelineStageFlags submit_flags = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
VkPipelineStageFlags submit_flags = VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||||
|
|
||||||
// Waits for command to finish.
|
// Waits for command to finish.
|
||||||
|
@ -338,7 +347,7 @@ comp_window_peek_blit(struct comp_window_peek *w, VkImage src, int32_t width, in
|
||||||
.pWaitSemaphores = &w->acquire,
|
.pWaitSemaphores = &w->acquire,
|
||||||
.pWaitDstStageMask = &submit_flags,
|
.pWaitDstStageMask = &submit_flags,
|
||||||
.commandBufferCount = 1,
|
.commandBufferCount = 1,
|
||||||
.pCommandBuffers = &cmd,
|
.pCommandBuffers = &w->cmd,
|
||||||
.signalSemaphoreCount = 1,
|
.signalSemaphoreCount = 1,
|
||||||
.pSignalSemaphores = &w->submit,
|
.pSignalSemaphores = &w->submit,
|
||||||
};
|
};
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct comp_window_peek
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
VkSemaphore acquire;
|
VkSemaphore acquire;
|
||||||
VkSemaphore submit;
|
VkSemaphore submit;
|
||||||
|
VkCommandBuffer cmd;
|
||||||
|
|
||||||
struct os_thread_helper oth;
|
struct os_thread_helper oth;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue