summaryrefslogtreecommitdiffstats
path: root/video/out/vulkan/utils.c
blob: 7d9c519c125356291257df015d927a7346dfe4f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "video/out/placebo/utils.h"
#include "utils.h"

bool mpvk_init(struct mpvk_ctx *vk, struct ra_ctx *ctx, const char *surface_ext)
{
    vk->ctx = pl_context_create(PL_API_VER, NULL);
    if (!vk->ctx)
        goto error;

    vk->pl_log = mp_log_new(ctx, ctx->log, "libplacebo");
    mppl_ctx_set_log(vk->ctx, vk->pl_log, true);

    const char *exts[] = {
        VK_KHR_SURFACE_EXTENSION_NAME,
        surface_ext,
    };

    vk->vkinst = pl_vk_inst_create(vk->ctx, &(struct pl_vk_inst_params) {
        .debug = ctx->opts.debug,
        .extensions = exts,
        .num_extensions = MP_ARRAY_SIZE(exts),
    });

    if (!vk->vkinst)
        goto error;

    mppl_ctx_set_log(vk->ctx, vk->pl_log, false); // disable probing
    return true;

error:
    mpvk_uninit(vk);
    return false;
}

void mpvk_uninit(struct mpvk_ctx *vk)
{
    if (vk->surface) {
        assert(vk->vkinst);
        vkDestroySurfaceKHR(vk->vkinst->instance, vk->surface, NULL);
        vk->surface = NULL;
    }

    pl_vk_inst_destroy(&vk->vkinst);
    pl_context_destroy(&vk->ctx);
    TA_FREEP(&vk->pl_log);
}