From 1cb47d549b8ef06bd9081fdedb2cab04ff08a08f Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 20 Dec 2022 01:23:42 +0900 Subject: [PATCH] cudaconverter: Don't sync per conversion Caller should take care of synchronization Part-of: --- .../sys/nvcodec/gstcudaconverter.c | 21 ++++++++++++++----- .../sys/nvcodec/gstcudaconverter.h | 3 ++- .../sys/nvcodec/gstcudaconvertscale.c | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.c b/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.c index ec8e4e7f41..1183664665 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.c +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.c @@ -2069,12 +2069,15 @@ ensure_fallback_buffer (GstCudaConverter * self, gint width_in_bytes, static CUtexObject gst_cuda_converter_create_texture (GstCudaConverter * self, CUdeviceptr src, gint width, gint height, gint stride, CUfilter_mode mode, - CUarray_format format, guint channles, gint plane, CUstream stream) + CUarray_format format, guint channles, gint plane, CUstream stream, + gboolean * need_sync) { GstCudaConverterPrivate *priv = self->priv; CUresult ret; CUdeviceptr src_ptr; + *need_sync = FALSE; + src_ptr = src; if (priv->texture_align > 0 && (src_ptr % priv->texture_align) != 0) { @@ -2096,12 +2099,14 @@ gst_cuda_converter_create_texture (GstCudaConverter * self, * GST_VIDEO_INFO_COMP_PSTRIDE (&priv->in_info, plane), params.Height = GST_VIDEO_INFO_COMP_HEIGHT (&priv->in_info, plane); - ret = CuMemcpy2D (¶ms); + ret = CuMemcpy2DAsync (¶ms, stream); if (!gst_cuda_result (ret)) { GST_ERROR_OBJECT (self, "Couldn't copy to fallback buffer"); return 0; } + *need_sync = TRUE; + src_ptr = priv->fallback_buffer[plane].ptr; stride = priv->fallback_buffer[plane].stride; } @@ -2145,7 +2150,8 @@ gst_cuda_converter_unpack_rgb (GstCudaConverter * self, gboolean gst_cuda_converter_convert_frame (GstCudaConverter * converter, - GstVideoFrame * src_frame, GstVideoFrame * dst_frame, CUstream stream) + GstVideoFrame * src_frame, GstVideoFrame * dst_frame, CUstream stream, + gboolean * synchronized) { GstCudaConverterPrivate *priv; const TextureFormat *format; @@ -2159,6 +2165,7 @@ gst_cuda_converter_convert_frame (GstCudaConverter * converter, gpointer args[] = { &texture[0], &texture[1], &texture[2], &texture[3], &dst[0], &dst[1], &dst[2], &dst[3], &stride[0], &stride[1] }; + gboolean need_sync = FALSE; g_return_val_if_fail (GST_IS_CUDA_CONVERTER (converter), FALSE); g_return_val_if_fail (src_frame != NULL, FALSE); @@ -2196,7 +2203,7 @@ gst_cuda_converter_convert_frame (GstCudaConverter * converter, GST_VIDEO_FRAME_COMP_HEIGHT (src_frame, i), GST_VIDEO_FRAME_PLANE_STRIDE (src_frame, i), priv->filter_mode[i], format->array_format[i], format->channels[i], i, - stream); + stream, &need_sync); if (!texture[i]) { GST_ERROR_OBJECT (converter, "Couldn't create texture %d", i); goto out; @@ -2223,7 +2230,11 @@ gst_cuda_converter_convert_frame (GstCudaConverter * converter, goto out; } - CuStreamSynchronize (stream); + if (need_sync) + CuStreamSynchronize (stream); + + if (synchronized) + *synchronized = need_sync; ret = TRUE; diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.h b/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.h index b19c03ef14..1be9d8a9b3 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.h +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconverter.h @@ -93,7 +93,8 @@ GstCudaConverter * gst_cuda_converter_new (const GstVideoInfo * in_info, gboolean gst_cuda_converter_convert_frame (GstCudaConverter * converter, GstVideoFrame * src_frame, GstVideoFrame * dst_frame, - CUstream cuda_stream); + CUstream cuda_stream, + gboolean * synchronized); G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconvertscale.c b/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconvertscale.c index 6d5ed1a226..b779c98329 100644 --- a/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconvertscale.c +++ b/subprojects/gst-plugins-bad/sys/nvcodec/gstcudaconvertscale.c @@ -1380,7 +1380,7 @@ gst_cuda_base_convert_transform (GstBaseTransform * trans, } if (!gst_cuda_converter_convert_frame (self->converter, &in_frame, &out_frame, - gst_cuda_stream_get_handle (btrans->stream))) { + gst_cuda_stream_get_handle (btrans->stream), NULL)) { GST_ERROR_OBJECT (self, "Failed to convert frame"); ret = GST_FLOW_ERROR; }