summaryrefslogtreecommitdiffstats
path: root/video/out/vulkan/context.c
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2017-09-28 23:06:56 +0200
committerMartin Herkt <652892+lachs0r@users.noreply.github.com>2017-12-25 00:47:53 +0100
commit5feaaba0fd27af34ee1fef12545f1dd96ebefddd (patch)
treecd6278cc8f8de6e2f9f66a1d8ab6c06281ad77f5 /video/out/vulkan/context.c
parent885497a4456256a147d9e7e30daa3170e461d7d6 (diff)
downloadmpv-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/context.c')
-rw-r--r--video/out/vulkan/context.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/video/out/vulkan/context.c b/video/out/vulkan/context.c
index b51bb78578..20fa5fc6d9 100644
--- a/video/out/vulkan/context.c
+++ b/video/out/vulkan/context.c
@@ -467,6 +467,11 @@ error:
return false;
}
+static void present_cb(struct priv *p, void *arg)
+{
+ p->frames_in_flight--;
+}
+
static bool submit_frame(struct ra_swapchain *sw, const struct vo_frame *frame)
{
struct priv *p = sw->priv;
@@ -475,18 +480,32 @@ static bool submit_frame(struct ra_swapchain *sw, const struct vo_frame *frame)
if (!p->swapchain)
goto error;
+ struct vk_cmd *cmd = ra_vk_submit(ra, p->images[p->last_imgidx]);
+ if (!cmd)
+ goto error;
+
int semidx = p->idx_sems++;
p->idx_sems %= p->num_sems;
+ vk_cmd_sig(cmd, p->sems_out[semidx]);
+
+ // XXX: These are the only two stages that we currently use/support for
+ // actually outputting to the swapchain. Normally, this would be handled by
+ // a dedicated vk_signal mechanism, but for now just hard-code it here as a
+ // quick work-around.
+ vk_cmd_dep(cmd, p->sems_in[semidx], VK_PIPELINE_STAGE_TRANSFER_BIT |
+ VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
+
+ p->frames_in_flight++;
+ vk_cmd_callback(cmd, (vk_cb) present_cb, p, NULL);
- if (!ra_vk_submit(ra, p->images[p->last_imgidx], p->sems_in[semidx],
- p->sems_out[semidx], &p->frames_in_flight))
+ vk_cmd_queue(vk, cmd);
+ if (!vk_flush_commands(vk))
goto error;
// Older nvidia drivers can spontaneously combust when submitting to the
// same queue as we're rendering from, in a multi-queue scenario. Safest
- // option is to cycle the queues first and then submit to the next queue.
+ // option is to flush the commands first and then submit to the next queue.
// We can drop this hack in the future, I suppose.
- vk_cmd_cycle_queues(vk);
struct vk_cmdpool *pool = vk->pool;
VkQueue queue = pool->queues[pool->idx_queues];