summaryrefslogtreecommitdiffstats
path: root/video/out/opengl/osd.c
diff options
context:
space:
mode:
authorNiklas Haas <git@haasn.xyz>2017-08-16 22:13:51 +0200
committerNiklas Haas <git@haasn.xyz>2017-08-18 00:34:34 +0200
commit46d86da6300ebcd2134996c76b9238fcf8e0fb6e (patch)
treea9ac0b463aba5ea47112b5e93ec6570f7b37fbe2 /video/out/opengl/osd.c
parent9ca5a2a5d839476d8a597fcc124cce41279928bc (diff)
downloadmpv-46d86da6300ebcd2134996c76b9238fcf8e0fb6e.tar.bz2
mpv-46d86da6300ebcd2134996c76b9238fcf8e0fb6e.tar.xz
vo_opengl: refactor RA texture and buffer updates
- tex_uploads args are moved to a struct - the ability to directly upload texture data without going through a buffer is made explicit - the concept of buffer updates and buffer polling is made more explicit and generalized to buf_update as well (not just mapped buffers) - the ability to call tex_upload/buf_update on a tex/buf is made explicit during tex/buf creation - uploading from buffers now uses an explicit offset instead of implicitly comparing *src against buf->data, because not all buffers may actually be persistently mapped - the initial_data = immutable requirement is dropped. (May be re-added later for D3D11 if that ever becomes a thing) This change helps the vulkan abstraction immensely and also helps move common code (like the PBO pooling) out of ra_gl and into the opengl/utils.c This also technically has the side-benefit / side-constraint of using PBOs for OSD texture uploads as well, which actually seems to help performance on machines where --opengl-pbo is faster than the naive code path. Because of this, I decided to hook up the OSD code to the opengl-pbo option as well. One drawback of this refactor is that the GL_STREAM_COPY hack for texture uploads "got lost", but I think I'm happy with that going away anyway since DR almost fully deprecates it, and it's not the "right thing" anyway - but instead an nvidia-only hack to make this stuff work somewhat better on NUMA systems with discrete GPUs. Another change is that due to the way fencing works with ra_buf (we get one fence per ra_buf per upload) we have to use multiple ra_bufs instead of offsets into a shared buffer. But for OpenGL this is probably better anyway. It's possible that in future, we could support having independent “buffer slices” (each with their own fence/sync object), but this would be an optimization more than anything. I also think that we could address the underlying problem (memory closeness) differently by making the ra_vk memory allocator smart enough to chunk together allocations under the hood.
Diffstat (limited to 'video/out/opengl/osd.c')
-rw-r--r--video/out/opengl/osd.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/video/out/opengl/osd.c b/video/out/opengl/osd.c
index c41e10d900..967b81e535 100644
--- a/video/out/opengl/osd.c
+++ b/video/out/opengl/osd.c
@@ -54,6 +54,7 @@ struct mpgl_osd_part {
enum sub_bitmap_format format;
int change_id;
struct ra_tex *texture;
+ struct tex_upload pbo;
int w, h;
int num_subparts;
int prev_num_subparts;
@@ -70,6 +71,7 @@ struct mpgl_osd {
const struct ra_format *fmt_table[SUBBITMAP_COUNT];
bool formats[SUBBITMAP_COUNT];
bool change_flag; // for reporting to API user only
+ bool want_pbo;
// temporary
int stereo_mode;
struct mp_osd_res osd_res;
@@ -77,7 +79,7 @@ struct mpgl_osd {
};
struct mpgl_osd *mpgl_osd_init(struct ra *ra, struct mp_log *log,
- struct osd_state *osd)
+ struct osd_state *osd, bool want_pbo)
{
struct mpgl_osd *ctx = talloc_ptrtype(NULL, ctx);
*ctx = (struct mpgl_osd) {
@@ -86,6 +88,7 @@ struct mpgl_osd *mpgl_osd_init(struct ra *ra, struct mp_log *log,
.ra = ra,
.change_flag = true,
.scratch = talloc_zero_size(ctx, 1),
+ .want_pbo = want_pbo,
};
ctx->fmt_table[SUBBITMAP_LIBASS] = ra_find_unorm_format(ra, 1, 1);
@@ -108,6 +111,7 @@ void mpgl_osd_destroy(struct mpgl_osd *ctx)
for (int n = 0; n < MAX_OSD_PARTS; n++) {
struct mpgl_osd_part *p = ctx->parts[n];
ra_tex_free(ctx->ra, &p->texture);
+ tex_upload_uninit(ctx->ra, &p->pbo);
}
talloc_free(ctx);
}
@@ -161,18 +165,22 @@ static bool upload_osd(struct mpgl_osd *ctx, struct mpgl_osd_part *osd,
.format = fmt,
.render_src = true,
.src_linear = true,
+ .host_mutable = true,
};
osd->texture = ra_tex_create(ra, &params);
if (!osd->texture)
goto done;
}
- struct mp_rect rc = {0, 0, imgs->packed_w, imgs->packed_h};
- ra->fns->tex_upload(ra, osd->texture, imgs->packed->planes[0],
- imgs->packed->stride[0], &rc, RA_TEX_UPLOAD_DISCARD,
- NULL);
+ struct ra_tex_upload_params params = {
+ .tex = osd->texture,
+ .src = imgs->packed->planes[0],
+ .invalidate = true,
+ .rc = &(struct mp_rect){0, 0, imgs->packed_w, imgs->packed_h},
+ .stride = imgs->packed->stride[0],
+ };
- ok = true;
+ ok = tex_upload(ra, &osd->pbo, ctx->want_pbo, &params);
done:
return ok;