vaGetImage is currently used for all maps when read access is required
because vaDeriveImage is supposed to be very slow on old Intel HW with
i965 driver.
However, this is not the case with modern drivers and vaDeriveImage
is faster also for reading.

Add a new quirk for i965 driver that will keep the old behavior of using
vaGetImage for read access, and prefer vaDeriveImage with other drivers.
---
 libavutil/hwcontext_vaapi.c | 8 ++++++--
 libavutil/hwcontext_vaapi.h | 7 +++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/libavutil/hwcontext_vaapi.c b/libavutil/hwcontext_vaapi.c
index 95aa38d9d2..99148ba5da 100644
--- a/libavutil/hwcontext_vaapi.c
+++ b/libavutil/hwcontext_vaapi.c
@@ -377,7 +377,7 @@ static const struct {
     {
         "Intel i965 (Quick Sync)",
         "i965",
-        AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS,
+        AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS | 
AV_VAAPI_DRIVER_QUIRK_AVOID_DIRECT_MAP_READ,
     },
 #endif
     {
@@ -812,6 +812,7 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc,
 #if VA_CHECK_VERSION(1, 21, 0)
     uint32_t vaflags = 0;
 #endif
+    int use_direct_map;
 
     surface_id = (VASurfaceID)(uintptr_t)src->data[3];
     av_log(hwfc, AV_LOG_DEBUG, "Map surface %#x.\n", surface_id);
@@ -854,8 +855,11 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc,
     // faster with a copy routine which is aware of the limitation, but we
     // assume for now that the user is not aware of that and would therefore
     // prefer not to be given direct-mapped memory if they request read access.
+    use_direct_map = !(flags & AV_HWFRAME_MAP_READ) ||
+        !(hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_AVOID_DIRECT_MAP_READ);
+
     if (ctx->derive_works && dst->format == hwfc->sw_format &&
-        ((flags & AV_HWFRAME_MAP_DIRECT) || !(flags & AV_HWFRAME_MAP_READ))) {
+        ((flags & AV_HWFRAME_MAP_DIRECT) || use_direct_map)) {
         vas = vaDeriveImage(hwctx->display, surface_id, &map->image);
         if (vas != VA_STATUS_SUCCESS) {
             av_log(hwfc, AV_LOG_ERROR, "Failed to derive image from "
diff --git a/libavutil/hwcontext_vaapi.h b/libavutil/hwcontext_vaapi.h
index 0b2e071cb3..c08843bed1 100644
--- a/libavutil/hwcontext_vaapi.h
+++ b/libavutil/hwcontext_vaapi.h
@@ -58,6 +58,13 @@ enum {
      * and the results of the vaQuerySurfaceAttributes() call will be faked.
      */
     AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES = (1 << 3),
+
+    /**
+     * The driver does not map memory with fast read access.
+     * The surface map code will prefer vaGetImage instead of vaDeriveImage
+     * for read access, unless direct map was requested.
+     */
+    AV_VAAPI_DRIVER_QUIRK_AVOID_DIRECT_MAP_READ = (1 << 4),
 };
 
 /**
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to