summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.dev>2021-10-31 14:41:22 +0100
committerNiklas Haas <github-daiK1o@haasn.dev>2021-10-31 19:39:58 +0100
commitc82ffb667077cc9e03f82461e5f753c39d0c633d (patch)
tree8361807878c5eaaa1153d6b625c283180414ce9c
parent4a80de90d299ca4986945939e5b1bada057b26b3 (diff)
downloadmpv-c82ffb667077cc9e03f82461e5f753c39d0c633d.tar.bz2
mpv-c82ffb667077cc9e03f82461e5f753c39d0c633d.tar.xz
vo_gpu: libplacebo: simplify tex transfers for libplacebo 168+
Upstream libplacebo got refactored to use byte-sized strides rather than texel-sized strides. This commit makes mpv's ra_pl wrapper take advantage of that, rather than forcing a stride-fixing memcpy. Note that, technically, we would still need a stride fixing memcpy in cases when the true stride is not a multiple of the format's texel *alignment*, however this is a much rarer case and extremely unlikely to occur in practice, since all relevant formats use power-of-two texel alignments.
-rw-r--r--video/out/placebo/ra_pl.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/video/out/placebo/ra_pl.c b/video/out/placebo/ra_pl.c
index 2233434bf8..ccff9df499 100644
--- a/video/out/placebo/ra_pl.c
+++ b/video/out/placebo/ra_pl.c
@@ -207,22 +207,26 @@ static bool tex_upload_pl(struct ra *ra, const struct ra_tex_upload_params *para
};
const struct pl_buf *staging = NULL;
-
if (params->tex->params.dimensions == 2) {
- size_t texel_size = tex->params.format->texel_size;
- pl_params.stride_w = params->stride / texel_size;
- size_t stride = pl_params.stride_w * texel_size;
- int lines = tex->params.h;
if (params->rc) {
pl_params.rc = (struct pl_rect3d) {
.x0 = params->rc->x0, .x1 = params->rc->x1,
.y0 = params->rc->y0, .y1 = params->rc->y1,
};
- lines = pl_rect_h(pl_params.rc);
}
+#if PL_API_VER >= 168
+ pl_params.row_pitch = params->stride;
+#else
+ // Older libplacebo uses texel-sized strides, so we have to manually
+ // compensate for possibly misaligned sources (typically rgb24).
+ size_t texel_size = tex->params.format->texel_size;
+ pl_params.stride_w = params->stride / texel_size;
+ size_t stride = pl_params.stride_w * texel_size;
+
if (stride != params->stride) {
// Fall back to uploading via a staging buffer prepared in CPU
+ int lines = params->rc ? pl_rect_h(pl_params.rc) : tex->params.h;
staging = pl_buf_create(gpu, &(struct pl_buf_params) {
.size = lines * stride,
.memory_type = PL_BUF_MEM_HOST,
@@ -240,6 +244,7 @@ static bool tex_upload_pl(struct ra *ra, const struct ra_tex_upload_params *para
pl_params.buf = staging;
pl_params.buf_offset = 0;
}
+#endif
}
bool ok = pl_tex_upload(gpu, &pl_params);
@@ -250,16 +255,20 @@ static bool tex_upload_pl(struct ra *ra, const struct ra_tex_upload_params *para
static bool tex_download_pl(struct ra *ra, struct ra_tex_download_params *params)
{
const struct pl_tex *tex = params->tex->priv;
- size_t texel_size = tex->params.format->texel_size;
struct pl_tex_transfer_params pl_params = {
.tex = tex,
.ptr = params->dst,
- .stride_w = params->stride / texel_size,
.timer = get_active_timer(ra),
};
- uint8_t *staging = NULL;
+#if PL_API_VER >= 168
+ pl_params.row_pitch = params->stride;
+ return pl_tex_download(get_gpu(ra), &pl_params);
+#else
+ size_t texel_size = tex->params.format->texel_size;
+ pl_params.stride_w = params->stride / texel_size;
size_t stride = pl_params.stride_w * texel_size;
+ uint8_t *staging = NULL;
if (stride != params->stride) {
staging = talloc_size(NULL, tex->params.h * stride);
pl_params.ptr = staging;
@@ -276,6 +285,7 @@ static bool tex_download_pl(struct ra *ra, struct ra_tex_download_params *params
talloc_free(staging);
return ok;
+#endif
}
static struct ra_buf *buf_create_pl(struct ra *ra,