[vlc-devel] [PATCH 2/2] nvdec: wait copies before releasing the CUDA frame

quentin.chateau at deepskycorp.com quentin.chateau at deepskycorp.com
Mon Mar 23 18:11:41 CET 2020


From: Quentin Chateau <quentin.chateau at deepskycorp.com>

---
 modules/hw/nvdec/nvdec.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/modules/hw/nvdec/nvdec.c b/modules/hw/nvdec/nvdec.c
index d2ec909fbc..a012a90eb9 100644
--- a/modules/hw/nvdec/nvdec.c
+++ b/modules/hw/nvdec/nvdec.c
@@ -489,13 +489,19 @@ static int CUDAAPI HandlePictureDisplay(void *p_opaque, CUVIDPARSERDISPINFO *p_d
                 .WidthInBytes   = i_pitch,
                 .Height         = plane.i_visible_lines,
             };
-            result = CALL_CUDA_DEC(cuMemcpy2D, &cu_cpy);
+            result = CALL_CUDA_DEC(cuMemcpy2DAsync, &cu_cpy, 0);
             if (result != VLC_SUCCESS)
                 goto error;
             srcY += p_sys->decoderHeight;
         }
     }
 
+    // Wait until copies are finished
+    result = CALL_CUDA_DEC(cuStreamSynchronize, 0);
+    if (unlikely(result != VLC_SUCCESS))
+        goto error;
+    }
+
     // Release surface on GPU
     result = CALL_CUVID(cuvidUnmapVideoFrame, p_sys->cudecoder, frameDevicePtr);
     if (unlikely(result != VLC_SUCCESS))
@@ -522,7 +528,13 @@ static int CUDAAPI HandlePictureDisplay(void *p_opaque, CUVIDPARSERDISPINFO *p_d
 
 error:
     if (frameDevicePtr)
+    {
+        // Synchronize stream to wait for potentitally pending copies
+        // then unmap the frame.
+        // No need to check for errors, there is nothing we can do anyway
+        CALL_CUDA_DEC(cuStreamSynchronize, 0);
         CALL_CUVID(cuvidUnmapVideoFrame, p_sys->cudecoder, frameDevicePtr);
+    }
     CALL_CUDA_DEC(cuCtxPopCurrent, NULL);
     if (p_pic)
         picture_Release(p_pic);
-- 
2.17.1



More information about the vlc-devel mailing list