From: green-hand-shandong 
<[email protected]>

The per-row aclrtMemcpy loop in transfer_data_from dominated hwdownload
cost (750-frame 1080p download: 18s). When the AVFrame linesize equals
the device width stride (the common case), copy Y and UV as two bulk
memcpys instead: 18s -> 6s (3x). Full hw transcode 1080p->720p
(decode -> scale_ascend -> encode zero_copy) improves from 47 fps to
113 fps (2.4x), MD5 unchanged vs software decode.

An earlier variant copied the whole padded frame in one call and
corrupted the heap when the host allocation was smaller than the
device padded frame; the two-plane form uses exact plane sizes.

Signed-off-by: green-hand-shandong 
<[email protected]>
---
 libavutil/hwcontext_ascend.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libavutil/hwcontext_ascend.c b/libavutil/hwcontext_ascend.c
index fcff3d50c6..5187e3a662 100644
--- a/libavutil/hwcontext_ascend.c
+++ b/libavutil/hwcontext_ascend.c
@@ -348,6 +348,23 @@ static int ascend_transfer_data_from(AVHWFramesContext 
*hwfc,
             av_log(hwfc, AV_LOG_WARNING, "ascend: SetCurrentContext %d\n", 
arc);
     }
 
+    /* When the AVFrame linesize equals the device width stride (the
+     * common case), each plane is contiguous on both sides: copy Y and
+     * UV as two bulk memcpys using the actual host plane sizes. */
+    if (dst->linesize[0] == wstride && dst->linesize[1] == wstride) {
+        const size_t y_bytes = (size_t)wstride * hstride;
+        const size_t c_bytes = (size_t)wstride * (hstride / 2);
+
+        if (aclrtMemcpy(dst->data[0], y_bytes, dev_base, y_bytes,
+                        ACL_MEMCPY_DEVICE_TO_HOST) != 0)
+            return AVERROR_EXTERNAL;
+        if (aclrtMemcpy(dst->data[1], c_bytes,
+                        dev_base + y_bytes, c_bytes,
+                        ACL_MEMCPY_DEVICE_TO_HOST) != 0)
+            return AVERROR_EXTERNAL;
+        return 0;
+    }
+
     for (int p = 0; p < 2 && !ret; p++) {
         const uint8_t *src_p = dev_base + (p == 0 ? 0 : (size_t)wstride * 
hstride);
         uint8_t *dst_p = p == 0 ? dst->data[0] : dst->data[1];
-- 
2.25.1


_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to