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;
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,
pl_d3d11_swapchain_params(
.swapchain = swapchain,
@ -128,20 +127,18 @@ struct gpu_ctx *gpu_ctx_create(struct vo *vo, struct gl_video_opts *gl_opts)
#if HAVE_VULKAN
struct mpvk_ctx *vkctx = ra_vk_ctx_get(ctx->ra_ctx);
if (vkctx) {
ctx->pllog = vkctx->ctx;
ctx->pllog = vkctx->pllog;
ctx->gpu = vkctx->gpu;
ctx->swapchain = vkctx->swapchain;
return ctx;
}
#endif
ctx->pllog = pl_log_create(PL_API_VER, NULL);
ctx->pllog = mppl_log_create(ctx->log);
if (!ctx->pllog)
goto err_out;
mppl_ctx_set_log(ctx->pllog, ctx->log, vo->probing);
mp_verbose(ctx->log, "Initialized libplacebo %s (API v%d)\n",
PL_VERSION, PL_API_VER);
mppl_log_set_probing(ctx->pllog, vo->probing);
#if HAVE_D3D11
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;
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(
.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);
mppl_ctx_set_log(gpu->ctx, mapper->ra->log, false);
if (!pltex) {
mppl_log_set_probing(gpu->log, false);
if (!pltex)
return false;
}
struct ra_tex *ratex = talloc_ptrtype(NULL, 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);
}
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);
pl_context_update(ctx, &(struct pl_context_params) {
.log_cb = probing ? log_cb_probing : log_cb,
.log_level = msg_lev_to_pl_log[mp_msg_level(log)],
.log_priv = log,
return pl_log_create(PL_API_VER, &(struct pl_log_params) {
.log_cb = log_cb,
.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)
{
switch (prim) {

View File

@ -8,7 +8,8 @@
#include <libplacebo/context.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)
{

View File

@ -27,8 +27,8 @@
// Shared struct used to hold vulkan context information
struct mpvk_ctx {
struct mp_log *pl_log;
struct pl_context *ctx;
struct mp_log *log;
pl_log pllog;
const struct pl_vk_inst *vkinst;
const struct pl_vulkan *vulkan;
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->opts = mp_get_config_group(p, ctx->global, &vulkan_conf);
assert(vk->ctx);
assert(vk->pllog);
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,
.surface = vk->surface,
.async_transfer = p->opts->async_transfer,

View File

@ -388,7 +388,7 @@ static bool display_init(struct ra_ctx *ctx)
.instance = vk->vkinst->instance,
.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);
if (!device) {
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)
{
vk->ctx = pl_context_create(PL_API_VER, NULL);
if (!vk->ctx)
vk->log = mp_log_new(ctx, ctx->log, "libplacebo");
vk->pllog = mppl_log_create(vk->log);
if (!vk->pllog)
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[] = {
VK_KHR_SURFACE_EXTENSION_NAME,
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,
.extensions = exts,
.num_extensions = MP_ARRAY_SIZE(exts),
});
mppl_log_set_probing(vk->pllog, false);
if (!vk->vkinst)
goto error;
mppl_ctx_set_log(vk->ctx, vk->pl_log, false); // disable probing
return true;
error:
@ -43,6 +39,6 @@ void mpvk_uninit(struct mpvk_ctx *vk)
}
pl_vk_inst_destroy(&vk->vkinst);
pl_context_destroy(&vk->ctx);
TA_FREEP(&vk->pl_log);
pl_log_destroy(&vk->pllog);
TA_FREEP(&vk->log);
}