Skip to content

Commit

Permalink
vo_gpu: vulkan: refactor vk_cmdpool
Browse files Browse the repository at this point in the history
1. No more static arrays (deps / callbacks / queues / cmds)
2. Allows safely recording multiple commands at the same time
3. Uses resources optimally by never over-allocating commands
  • Loading branch information
haasn authored and mia-0 committed Dec 24, 2017
1 parent ad50e64 commit 4e34615
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 194 deletions.
7 changes: 7 additions & 0 deletions ta/ta_talloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ char *ta_talloc_asprintf_append_buffer(char *s, const char *fmt, ...) TA_PRF(2,
(idxvar)--; \
} while (0)

// Returns whether or not there was any element to pop.
#define MP_TARRAY_POP(p, idxvar, out) \
((idxvar) > 0 \
? (*(out) = (p)[--(idxvar)], true) \
: false \
)

#define talloc_struct(ctx, type, ...) \
talloc_memdup(ctx, &(type) TA_EXPAND_ARGS(__VA_ARGS__), sizeof(type))

Expand Down
2 changes: 1 addition & 1 deletion video/out/vulkan/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct mpvk_ctx {

struct vk_malloc *alloc; // memory allocator for this device
struct vk_cmdpool *pool; // primary command pool for this device
struct vk_cmd *last_cmd; // most recently submitted command
struct vk_cmd *last_cmd; // most recently submitted (pending) command
struct spirv_compiler *spirv; // GLSL -> SPIR-V compiler

// Cached capabilities
Expand Down
12 changes: 6 additions & 6 deletions video/out/vulkan/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ const struct m_sub_options vulkan_conf = {
{"fifo-relaxed", SWAP_FIFO_RELAXED},
{"mailbox", SWAP_MAILBOX},
{"immediate", SWAP_IMMEDIATE})),
OPT_INTRANGE("vulkan-queue-count", dev_opts.queue_count, 0, 1,
MPVK_MAX_QUEUES, OPTDEF_INT(1)),
OPT_INTRANGE("vulkan-queue-count", dev_opts.queue_count, 0, 1, 8,
OPTDEF_INT(1)),
{0}
},
.size = sizeof(struct vulkan_opts)
Expand Down Expand Up @@ -244,7 +244,7 @@ void ra_vk_ctx_uninit(struct ra_ctx *ctx)
struct priv *p = ctx->swapchain->priv;
struct mpvk_ctx *vk = p->vk;

mpvk_pool_wait_idle(vk, vk->pool);
mpvk_dev_wait_cmds(vk, UINT64_MAX);

for (int i = 0; i < p->num_images; i++)
ra_tex_free(ctx->ra, &p->images[i]);
Expand Down Expand Up @@ -355,7 +355,7 @@ bool ra_vk_ctx_resize(struct ra_swapchain *sw, int w, int h)
// more than one swapchain already active, so we need to flush any pending
// asynchronous swapchain release operations that may be ongoing.
while (p->old_swapchain)
mpvk_dev_poll_cmds(vk, 100000); // 100μs
mpvk_dev_wait_cmds(vk, 100000); // 100μs

VkSwapchainCreateInfoKHR sinfo = p->protoInfo;
sinfo.imageExtent = (VkExtent2D){ w, h };
Expand Down Expand Up @@ -483,7 +483,7 @@ static bool submit_frame(struct ra_swapchain *sw, const struct vo_frame *frame)
// 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->qindex];
VkQueue queue = pool->queues[pool->idx_queues];

VkPresentInfoKHR pinfo = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
Expand All @@ -506,7 +506,7 @@ static void swap_buffers(struct ra_swapchain *sw)
struct priv *p = sw->priv;

while (p->frames_in_flight >= sw->ctx->opts.swapchain_depth)
mpvk_dev_poll_cmds(p->vk, 100000); // 100μs
mpvk_dev_wait_cmds(p->vk, 100000); // 100μs
}

static const struct ra_swapchain_fns vulkan_swapchain = {
Expand Down
2 changes: 1 addition & 1 deletion video/out/vulkan/ra_vk.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static void vk_destroy_ra(struct ra *ra)
struct mpvk_ctx *vk = ra_vk_get(ra);

vk_flush(ra, NULL);
mpvk_dev_wait_idle(vk);
mpvk_dev_wait_cmds(vk, UINT64_MAX);
ra_tex_free(ra, &p->clear_tex);

talloc_free(ra);
Expand Down
Loading

0 comments on commit 4e34615

Please sign in to comment.