libplacebo: update log helpers

Use the pl_log APIs introduced in libplacebo v4, replacing the
deprecated pl_context concept.
This commit is contained in:
Niklas Haas 2022-02-03 16:20:18 +01:00 committed by Niklas Haas
parent e8e89fae38
commit 88c6c84b64
8 changed files with 35 additions and 38 deletions

View File

@ -89,8 +89,7 @@ static bool d3d11_pl_init(struct vo *vo, struct gpu_ctx *ctx, struct priv *p,
} }
ctx->gpu = p->d3d11->gpu; ctx->gpu = p->d3d11->gpu;
mppl_ctx_set_log(ctx->pllog, ctx->log, false); // disable probing mppl_log_set_probing(ctx->pllog, false);
ctx->swapchain = pl_d3d11_create_swapchain(p->d3d11, ctx->swapchain = pl_d3d11_create_swapchain(p->d3d11,
pl_d3d11_swapchain_params( pl_d3d11_swapchain_params(
.swapchain = swapchain, .swapchain = swapchain,
@ -128,20 +127,18 @@ struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts)
#if HAVE_VULKAN #if HAVE_VULKAN
struct mpvk_ctx *vkctx = ra_vk_ctx_get(ctx->ra_ctx); struct mpvk_ctx *vkctx = ra_vk_ctx_get(ctx->ra_ctx);
if (vkctx) { if (vkctx) {
ctx->pllog = vkctx->ctx; ctx->pllog = vkctx->pllog;
ctx->gpu = vkctx->gpu; ctx->gpu = vkctx->gpu;
ctx->swapchain = vkctx->swapchain; ctx->swapchain = vkctx->swapchain;
return ctx; return ctx;
} }
#endif #endif
ctx->pllog = pl_log_create(PL_API_VER, NULL); ctx->pllog = mppl_log_create(ctx->log);
if (!ctx->pllog) if (!ctx->pllog)
goto err_out; goto err_out;
mppl_ctx_set_log(ctx->pllog, ctx->log, vo->probing); mppl_log_set_probing(ctx->pllog, vo->probing);
mp_verbose(ctx->log, "Initialized libplacebo %s (API v%d)\n",
PL_VERSION, PL_API_VER);
#if HAVE_D3D11 #if HAVE_D3D11
if (ra_is_d3d11(ctx->ra_ctx->ra)) { if (ra_is_d3d11(ctx->ra_ctx->ra)) {
@ -162,8 +159,7 @@ struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts)
goto err_out; goto err_out;
ctx->gpu = p->opengl->gpu; ctx->gpu = p->opengl->gpu;
mppl_ctx_set_log(ctx->pllog, ctx->log, false); // disable probing mppl_log_set_probing(ctx->pllog, false);
ctx->swapchain = pl_opengl_create_swapchain(p->opengl, pl_opengl_swapchain_params( ctx->swapchain = pl_opengl_create_swapchain(p->opengl, pl_opengl_swapchain_params(
.max_swapchain_depth = vo->opts->swapchain_depth, .max_swapchain_depth = vo->opts->swapchain_depth,
)); ));

View File

@ -81,12 +81,11 @@ static bool vaapi_vk_map(struct ra_hwdec_mapper *mapper, bool probing)
}, },
}; };
mppl_ctx_set_log(gpu->ctx, mapper->ra->log, probing); mppl_log_set_probing(gpu->log, probing);
const struct pl_tex *pltex = pl_tex_create(gpu, &tex_params); const struct pl_tex *pltex = pl_tex_create(gpu, &tex_params);
mppl_ctx_set_log(gpu->ctx, mapper->ra->log, false); mppl_log_set_probing(gpu->log, false);
if (!pltex) { if (!pltex)
return false; return false;
}
struct ra_tex *ratex = talloc_ptrtype(NULL, ratex); struct ra_tex *ratex = talloc_ptrtype(NULL, ratex);
int ret = mppl_wrap_tex(mapper->ra, pltex, ratex); int ret = mppl_wrap_tex(mapper->ra, pltex, ratex);

View File

@ -48,17 +48,22 @@ static void log_cb_probing(void *priv, enum pl_log_level level, const char *msg)
mp_msg(log, pl_log_to_msg_lev[probing_map(level)], "%s\n", msg); mp_msg(log, pl_log_to_msg_lev[probing_map(level)], "%s\n", msg);
} }
void mppl_ctx_set_log(struct pl_context *ctx, struct mp_log *log, bool probing) pl_log mppl_log_create(struct mp_log *log)
{ {
assert(log); return pl_log_create(PL_API_VER, &(struct pl_log_params) {
.log_cb = log_cb,
pl_context_update(ctx, &(struct pl_context_params) { .log_level = msg_lev_to_pl_log[mp_msg_level(log)],
.log_cb = probing ? log_cb_probing : log_cb, .log_priv = log,
.log_level = msg_lev_to_pl_log[mp_msg_level(log)],
.log_priv = log,
}); });
} }
void mppl_log_set_probing(pl_log log, bool probing)
{
struct pl_log_params params = log->params;
params.log_cb = probing ? log_cb_probing : log_cb;
pl_log_update(log, &params);
}
enum pl_color_primaries mp_prim_to_pl(enum mp_csp_prim prim) enum pl_color_primaries mp_prim_to_pl(enum mp_csp_prim prim)
{ {
switch (prim) { switch (prim) {

View File

@ -8,7 +8,8 @@
#include <libplacebo/context.h> #include <libplacebo/context.h>
#include <libplacebo/colorspace.h> #include <libplacebo/colorspace.h>
void mppl_ctx_set_log(struct pl_context *ctx, struct mp_log *log, bool probing); pl_log mppl_log_create(struct mp_log *log);
void mppl_log_set_probing(pl_log log, bool probing);
static inline struct pl_rect2d mp_rect2d_to_pl(struct mp_rect rc) static inline struct pl_rect2d mp_rect2d_to_pl(struct mp_rect rc)
{ {

View File

@ -27,8 +27,8 @@
// Shared struct used to hold vulkan context information // Shared struct used to hold vulkan context information
struct mpvk_ctx { struct mpvk_ctx {
struct mp_log *pl_log; struct mp_log *log;
struct pl_context *ctx; pl_log pllog;
const struct pl_vk_inst *vkinst; const struct pl_vk_inst *vkinst;
const struct pl_vulkan *vulkan; const struct pl_vulkan *vulkan;
const struct pl_gpu *gpu; // points to vulkan->gpu for convenience const struct pl_gpu *gpu; // points to vulkan->gpu for convenience

View File

@ -162,9 +162,9 @@ bool ra_vk_ctx_init(struct ra_ctx *ctx, struct mpvk_ctx *vk,
p->params = params; p->params = params;
p->opts = mp_get_config_group(p, ctx->global, &vulkan_conf); p->opts = mp_get_config_group(p, ctx->global, &vulkan_conf);
assert(vk->ctx); assert(vk->pllog);
assert(vk->vkinst); assert(vk->vkinst);
vk->vulkan = pl_vulkan_create(vk->ctx, &(struct pl_vulkan_params) { vk->vulkan = pl_vulkan_create(vk->pllog, &(struct pl_vulkan_params) {
.instance = vk->vkinst->instance, .instance = vk->vkinst->instance,
.surface = vk->surface, .surface = vk->surface,
.async_transfer = p->opts->async_transfer, .async_transfer = p->opts->async_transfer,

View File

@ -388,7 +388,7 @@ static bool display_init(struct ra_ctx *ctx)
.instance = vk->vkinst->instance, .instance = vk->vkinst->instance,
.device_name = device_name, .device_name = device_name,
}; };
VkPhysicalDevice device = pl_vulkan_choose_device(vk->ctx, &vulkan_params); VkPhysicalDevice device = pl_vulkan_choose_device(vk->pllog, &vulkan_params);
talloc_free(device_name); talloc_free(device_name);
if (!device) { if (!device) {
MP_MSG(ctx, msgl, "Failed to open physical device.\n"); MP_MSG(ctx, msgl, "Failed to open physical device.\n");

View File

@ -3,30 +3,26 @@
bool mpvk_init(struct mpvk_ctx *vk, struct ra_ctx *ctx, const char *surface_ext) bool mpvk_init(struct mpvk_ctx *vk, struct ra_ctx *ctx, const char *surface_ext)
{ {
vk->ctx = pl_context_create(PL_API_VER, NULL); vk->log = mp_log_new(ctx, ctx->log, "libplacebo");
if (!vk->ctx) vk->pllog = mppl_log_create(vk->log);
if (!vk->pllog)
goto error; goto error;
vk->pl_log = mp_log_new(ctx, ctx->log, "libplacebo");
mppl_ctx_set_log(vk->ctx, vk->pl_log, true);
mp_verbose(vk->pl_log, "Initialized libplacebo %s (API v%d)\n",
PL_VERSION, PL_API_VER);
const char *exts[] = { const char *exts[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_EXTENSION_NAME,
surface_ext, surface_ext,
}; };
vk->vkinst = pl_vk_inst_create(vk->ctx, &(struct pl_vk_inst_params) { mppl_log_set_probing(vk->pllog, true);
vk->vkinst = pl_vk_inst_create(vk->pllog, &(struct pl_vk_inst_params) {
.debug = ctx->opts.debug, .debug = ctx->opts.debug,
.extensions = exts, .extensions = exts,
.num_extensions = MP_ARRAY_SIZE(exts), .num_extensions = MP_ARRAY_SIZE(exts),
}); });
mppl_log_set_probing(vk->pllog, false);
if (!vk->vkinst) if (!vk->vkinst)
goto error; goto error;
mppl_ctx_set_log(vk->ctx, vk->pl_log, false); // disable probing
return true; return true;
error: error:
@ -43,6 +39,6 @@ void mpvk_uninit(struct mpvk_ctx *vk)
} }
pl_vk_inst_destroy(&vk->vkinst); pl_vk_inst_destroy(&vk->vkinst);
pl_context_destroy(&vk->ctx); pl_log_destroy(&vk->pllog);
TA_FREEP(&vk->pl_log); TA_FREEP(&vk->log);
} }