mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
glsyncmeta: separate out gpu/cpu waits.
CPU waits are more expensive and are only required if the CPU is ever going to access the data. GPU waits perform inter-context synchronisation and are cheaper as they don't require CPU intervention.
This commit is contained in:
parent
44c0d75cff
commit
cd4a93da3b
4 changed files with 46 additions and 4 deletions
|
@ -260,6 +260,7 @@ gtk_gst_gl_widget_render (GtkGLArea * widget, GdkGLContext * context)
|
|||
|
||||
sync_meta = gst_buffer_get_gl_sync_meta (buffer);
|
||||
if (sync_meta) {
|
||||
/* XXX: the set_sync() seems to be needed for resizing */
|
||||
gst_gl_sync_meta_set_sync_point (sync_meta, priv->context);
|
||||
gst_gl_sync_meta_wait (sync_meta, priv->other_context);
|
||||
}
|
||||
|
|
|
@ -56,12 +56,25 @@ _default_set_sync_gl (GstGLSyncMeta * sync_meta, GstGLContext * context)
|
|||
gl->Flush ();
|
||||
GST_LOG ("setting sync object %p", sync_meta->data);
|
||||
} else {
|
||||
/* XXX: this a little over the top if the CPU is never going to
|
||||
* access the data, however this is the legacy path, so... */
|
||||
gl->Finish ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_default_wait_gl (GstGLSyncMeta * sync_meta, GstGLContext * context)
|
||||
{
|
||||
const GstGLFuncs *gl = context->gl_vtable;
|
||||
|
||||
if (sync_meta->data && gl->WaitSync) {
|
||||
GST_LOG ("waiting on sync object %p", sync_meta->data);
|
||||
gl->WaitSync ((GLsync) sync_meta->data, 0, GL_TIMEOUT_IGNORED);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_default_wait_cpu_gl (GstGLSyncMeta * sync_meta, GstGLContext * context)
|
||||
{
|
||||
const GstGLFuncs *gl = context->gl_vtable;
|
||||
GLenum res;
|
||||
|
@ -129,6 +142,7 @@ gst_buffer_add_gl_sync_meta (GstGLContext * context, GstBuffer * buffer)
|
|||
|
||||
ret->set_sync_gl = _default_set_sync_gl;
|
||||
ret->wait_gl = _default_wait_gl;
|
||||
ret->wait_cpu_gl = _default_wait_cpu_gl;
|
||||
ret->copy = _default_copy;
|
||||
ret->free_gl = _default_free_gl;
|
||||
|
||||
|
@ -174,6 +188,25 @@ gst_gl_sync_meta_wait (GstGLSyncMeta * sync_meta, GstGLContext * context)
|
|||
(GstGLContextThreadFunc) _wait, sync_meta);
|
||||
}
|
||||
|
||||
static void
|
||||
_wait_cpu (GstGLContext * context, GstGLSyncMeta * sync_meta)
|
||||
{
|
||||
g_assert (sync_meta->wait_cpu_gl != NULL);
|
||||
|
||||
GST_LOG ("waiting %p", sync_meta);
|
||||
sync_meta->wait_cpu_gl (sync_meta, context);
|
||||
}
|
||||
|
||||
void
|
||||
gst_gl_sync_meta_wait_cpu (GstGLSyncMeta * sync_meta, GstGLContext * context)
|
||||
{
|
||||
if (sync_meta->wait_cpu)
|
||||
sync_meta->wait_cpu (sync_meta, context);
|
||||
else
|
||||
gst_gl_context_thread_add (context,
|
||||
(GstGLContextThreadFunc) _wait_cpu, sync_meta);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_gst_gl_sync_meta_transform (GstBuffer * dest, GstMeta * meta,
|
||||
GstBuffer * buffer, GQuark type, gpointer data)
|
||||
|
@ -197,6 +230,8 @@ _gst_gl_sync_meta_transform (GstBuffer * dest, GstMeta * meta,
|
|||
dmeta->set_sync_gl = smeta->set_sync_gl;
|
||||
dmeta->wait = smeta->wait;
|
||||
dmeta->wait_gl = smeta->wait_gl;
|
||||
dmeta->wait_cpu = smeta->wait_cpu;
|
||||
dmeta->wait_cpu_gl = smeta->wait_cpu_gl;
|
||||
dmeta->copy = smeta->copy;
|
||||
dmeta->free = smeta->free;
|
||||
dmeta->free_gl = smeta->free_gl;
|
||||
|
@ -251,6 +286,8 @@ _gst_gl_sync_meta_init (GstGLSyncMeta * sync_meta, gpointer params,
|
|||
sync_meta->set_sync_gl = NULL;
|
||||
sync_meta->wait = NULL;
|
||||
sync_meta->wait_gl = NULL;
|
||||
sync_meta->wait_cpu = NULL;
|
||||
sync_meta->wait_cpu_gl = NULL;
|
||||
sync_meta->copy = NULL;
|
||||
sync_meta->free = NULL;
|
||||
sync_meta->free_gl = NULL;
|
||||
|
|
|
@ -42,6 +42,8 @@ struct _GstGLSyncMeta {
|
|||
void (*set_sync_gl) (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void (*wait) (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void (*wait_gl) (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void (*wait_cpu) (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void (*wait_cpu_gl) (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void (*copy) (GstGLSyncMeta * src, GstBuffer * sbuffer, GstGLSyncMeta * dest, GstBuffer * dbuffer);
|
||||
void (*free) (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void (*free_gl) (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
|
@ -57,6 +59,7 @@ GstGLSyncMeta * gst_buffer_add_gl_sync_meta_full (GstGLContext * context,
|
|||
gpointer data);
|
||||
void gst_gl_sync_meta_set_sync_point (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void gst_gl_sync_meta_wait (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
void gst_gl_sync_meta_wait_cpu (GstGLSyncMeta * sync, GstGLContext * context);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -1010,8 +1010,8 @@ _gl_sync_render_unlocked (struct gl_sync *sync)
|
|||
if (!af_meta) {
|
||||
GST_WARNING ("Failed to retreive the transformation meta from the "
|
||||
"gl_sync %p buffer %p", sync, sync->buffer);
|
||||
} else if (gst_amc_surface_texture_get_transform_matrix (sync->surface->
|
||||
texture, matrix, &error)) {
|
||||
} else if (gst_amc_surface_texture_get_transform_matrix (sync->
|
||||
surface->texture, matrix, &error)) {
|
||||
|
||||
gst_video_affine_transformation_meta_apply_matrix (af_meta, matrix);
|
||||
gst_video_affine_transformation_meta_apply_matrix (af_meta, yflip_matrix);
|
||||
|
@ -1370,6 +1370,7 @@ retry:
|
|||
sync);
|
||||
sync_meta->set_sync = _amc_gl_set_sync;
|
||||
sync_meta->wait = _amc_gl_wait;
|
||||
sync_meta->wait_cpu = _amc_gl_wait;
|
||||
sync_meta->copy = _amc_gl_copy;
|
||||
sync_meta->free = _amc_gl_free;
|
||||
|
||||
|
|
Loading…
Reference in a new issue