diff options
author | Niklas Haas <git@haasn.xyz> | 2017-09-28 23:06:56 +0200 |
---|---|---|
committer | Martin Herkt <652892+lachs0r@users.noreply.github.com> | 2017-12-25 00:47:53 +0100 |
commit | 5feaaba0fd27af34ee1fef12545f1dd96ebefddd (patch) | |
tree | cd6278cc8f8de6e2f9f66a1d8ab6c06281ad77f5 /video/out/vulkan/utils.c | |
parent | 885497a4456256a147d9e7e30daa3170e461d7d6 (diff) | |
download | mpv-5feaaba0fd27af34ee1fef12545f1dd96ebefddd.tar.bz2 mpv-5feaaba0fd27af34ee1fef12545f1dd96ebefddd.tar.xz |
vo_gpu: vulkan: refactor command submission
Instead of being submitted immediately, commands are appended into an
internal submission queue, and the actual submission is done once per
frame (at the same time as queue cycling). Again, the benefits are not
immediately obvious because nothing benefits from this yet, but it will
make more sense for an upcoming vk_signal mechanism.
This also cleans up the way the ra_vk submission interacts with the
synchronization/callbacks from the ra_vk_ctx. Although currently, the
way the dependency is signalled is a bit hacky: normally it would be
associated with the ra_tex itself and waited on in the appropriate stage
implicitly. But that code is just temporary, so I'm keeping it in there
for a better commit order.
Diffstat (limited to 'video/out/vulkan/utils.c')
-rw-r--r-- | video/out/vulkan/utils.c | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/video/out/vulkan/utils.c b/video/out/vulkan/utils.c index 7c8511a9d2..ee5a524947 100644 --- a/video/out/vulkan/utils.c +++ b/video/out/vulkan/utils.c @@ -665,42 +665,65 @@ error: return NULL; } -bool vk_cmd_submit(struct mpvk_ctx *vk, struct vk_cmd *cmd) +void vk_cmd_queue(struct mpvk_ctx *vk, struct vk_cmd *cmd) { struct vk_cmdpool *pool = cmd->pool; VK(vkEndCommandBuffer(cmd->buf)); - VkSubmitInfo sinfo = { - .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, - .commandBufferCount = 1, - .pCommandBuffers = &cmd->buf, - .waitSemaphoreCount = cmd->num_deps, - .pWaitSemaphores = cmd->deps, - .pWaitDstStageMask = cmd->depstages, - .signalSemaphoreCount = cmd->num_sigs, - .pSignalSemaphores = cmd->sigs, - }; - VK(vkResetFences(vk->dev, 1, &cmd->fence)); - VK(vkQueueSubmit(cmd->queue, 1, &sinfo, cmd->fence)); - MP_TRACE(vk, "Submitted command on queue %p (QF %d)\n", (void *)cmd->queue, - pool->qf); - + MP_TARRAY_APPEND(pool, pool->cmds_queued, pool->num_cmds_queued, cmd); vk->last_cmd = cmd; - MP_TARRAY_APPEND(pool, pool->cmds_pending, pool->num_cmds_pending, cmd); - return true; + return; error: vk_cmd_reset(vk, cmd); MP_TARRAY_APPEND(pool, pool->cmds_available, pool->num_cmds_available, cmd); - return false; } -void vk_cmd_cycle_queues(struct mpvk_ctx *vk) +bool vk_flush_commands(struct mpvk_ctx *vk) { + bool ret = true; + struct vk_cmdpool *pool = vk->pool; + for (int i = 0; i < pool->num_cmds_queued; i++) { + struct vk_cmd *cmd = pool->cmds_queued[i]; + + VkSubmitInfo sinfo = { + .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO, + .commandBufferCount = 1, + .pCommandBuffers = &cmd->buf, + .waitSemaphoreCount = cmd->num_deps, + .pWaitSemaphores = cmd->deps, + .pWaitDstStageMask = cmd->depstages, + .signalSemaphoreCount = cmd->num_sigs, + .pSignalSemaphores = cmd->sigs, + }; + + VK(vkQueueSubmit(cmd->queue, 1, &sinfo, cmd->fence)); + MP_TARRAY_APPEND(pool, pool->cmds_pending, pool->num_cmds_pending, cmd); + + if (mp_msg_test(vk->log, MSGL_TRACE)) { + MP_TRACE(vk, "Submitted command on queue %p (QF %d):\n", + (void *)cmd->queue, pool->qf); + for (int n = 0; n < cmd->num_deps; n++) + MP_TRACE(vk, " waits on semaphore %p\n", (void *)cmd->deps[n]); + for (int n = 0; n < cmd->num_sigs; n++) + MP_TRACE(vk, " signals semaphore %p\n", (void *)cmd->sigs[n]); + } + continue; + +error: + vk_cmd_reset(vk, cmd); + MP_TARRAY_APPEND(pool, pool->cmds_available, pool->num_cmds_available, cmd); + ret = false; + } + + pool->num_cmds_queued = 0; + + // Rotate the queues to ensure good parallelism across frames pool->idx_queues = (pool->idx_queues + 1) % pool->num_queues; + return ret; } const VkImageSubresourceRange vk_range = { |