hipmemory: Allow lazy sync

Store recorded hip event and wait for sync later if needed

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/9281>
This commit is contained in:
Seungha Yang 2025-06-15 21:34:36 +09:00 committed by GStreamer Marge Bot
parent e9d96fd4e7
commit 7d259c4224
3 changed files with 60 additions and 0 deletions

View File

@ -43,6 +43,8 @@ static gboolean gst_hip_buffer_pool_start (GstBufferPool * pool);
static gboolean gst_hip_buffer_pool_stop (GstBufferPool * pool);
static GstFlowReturn gst_hip_buffer_pool_alloc (GstBufferPool * pool,
GstBuffer ** buffer, GstBufferPoolAcquireParams * params);
static GstFlowReturn gst_hip_buffer_pool_acquire_buffer (GstBufferPool * pool,
GstBuffer ** buffer, GstBufferPoolAcquireParams * params);
static void
gst_hip_buffer_pool_class_init (GstHipBufferPoolClass * klass)
@ -57,6 +59,7 @@ gst_hip_buffer_pool_class_init (GstHipBufferPoolClass * klass)
pool_class->start = gst_hip_buffer_pool_start;
pool_class->stop = gst_hip_buffer_pool_stop;
pool_class->alloc_buffer = gst_hip_buffer_pool_alloc;
pool_class->acquire_buffer = gst_hip_buffer_pool_acquire_buffer;
GST_DEBUG_CATEGORY_INIT (gst_hip_buffer_pool_debug, "hipbufferpool", 0,
"hipbufferpool");
@ -177,6 +180,7 @@ gst_hip_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
gst_buffer_append_memory (buf, mem);
auto hmem = GST_HIP_MEMORY_CAST (mem);
gst_hip_memory_sync (hmem);
gst_buffer_add_video_meta_full (buf, GST_VIDEO_FRAME_FLAG_NONE,
GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
@ -187,6 +191,21 @@ gst_hip_buffer_pool_alloc (GstBufferPool * pool, GstBuffer ** buffer,
return GST_FLOW_OK;
}
static GstFlowReturn
gst_hip_buffer_pool_acquire_buffer (GstBufferPool * pool,
GstBuffer ** buffer, GstBufferPoolAcquireParams * params)
{
auto ret = GST_BUFFER_POOL_CLASS (parent_class)->acquire_buffer (pool,
buffer, params);
if (ret != GST_FLOW_OK)
return ret;
auto mem = (GstHipMemory *) gst_buffer_peek_memory (*buffer, 0);
gst_hip_memory_sync (mem);
return GST_FLOW_OK;
}
static gboolean
gst_hip_buffer_pool_start (GstBufferPool * pool)
{

View File

@ -49,6 +49,7 @@ struct _GstHipMemoryPrivate
{
~_GstHipMemoryPrivate ()
{
gst_clear_hip_event (&event);
gst_clear_hip_stream (&stream);
}
@ -61,6 +62,7 @@ struct _GstHipMemoryPrivate
gboolean texture_support = FALSE;
hipTextureObject_t texture[4][N_TEX_ADDR_MODES][N_TEX_FILTER_MODES] = { };
GstHipStream *stream = nullptr;
GstHipEvent *event = nullptr;
std::mutex lock;
};
@ -343,6 +345,9 @@ gst_hip_memory_upload (GstHipAllocator * self, GstHipMemory * mem)
if (gst_hip_result (hip_ret, priv->vendor))
hip_ret = HipStreamSynchronize (priv->vendor, stream);
/* Already synchronized */
gst_clear_hip_event (&priv->event);
GST_MEMORY_FLAG_UNSET (mem, GST_HIP_MEMORY_TRANSFER_NEED_UPLOAD);
return gst_hip_result (hip_ret, priv->vendor);
@ -387,6 +392,9 @@ gst_hip_memory_download (GstHipAllocator * self, GstHipMemory * mem)
if (gst_hip_result (hip_ret, priv->vendor))
hip_ret = HipStreamSynchronize (priv->vendor, stream);
/* Already synchronized */
gst_clear_hip_event (&priv->event);
GST_MEMORY_FLAG_UNSET (mem, GST_HIP_MEMORY_TRANSFER_NEED_DOWNLOAD);
return gst_hip_result (hip_ret, priv->vendor);
@ -681,6 +689,34 @@ gst_hip_memory_get_stream (GstHipMemory * mem)
return mem->priv->stream;
}
void
gst_hip_memory_set_event (GstHipMemory * mem, GstHipEvent * event)
{
g_return_if_fail (gst_is_hip_memory (GST_MEMORY_CAST (mem)));
auto priv = mem->priv;
std::lock_guard < std::mutex > lk (priv->lock);
gst_clear_hip_event (&priv->event);
priv->event = event;
if (priv->event)
gst_hip_event_ref (priv->event);
}
void
gst_hip_memory_sync (GstHipMemory * mem)
{
g_return_if_fail (gst_is_hip_memory (GST_MEMORY_CAST (mem)));
auto priv = mem->priv;
std::lock_guard < std::mutex > lk (priv->lock);
if (priv->event)
gst_hip_event_synchronize (priv->event);
gst_clear_hip_event (&priv->event);
}
static guint
gst_hip_allocator_calculate_alloc_height (const GstVideoInfo * info)
{

View File

@ -80,6 +80,11 @@ gboolean gst_hip_memory_get_texture (GstHipMemory * mem,
GstHipStream * gst_hip_memory_get_stream (GstHipMemory * mem);
void gst_hip_memory_set_event (GstHipMemory * mem,
GstHipEvent * event);
void gst_hip_memory_sync (GstHipMemory * mem);
struct _GstHipAllocator
{
GstAllocator allocator;