Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: David Rosca <nowrep@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Cc: David Rosca <nowrep@gmail.com>
Subject: [FFmpeg-devel] [PATCH] lavu/hwcontext_vaapi: Add direct map quirk for Intel i965 driver
Date: Wed,  7 May 2025 14:03:28 +0200
Message-ID: <20250507120326.156062-3-nowrep@gmail.com> (raw)

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-request@ffmpeg.org with subject "unsubscribe".

                 reply	other threads:[~2025-05-07 12:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250507120326.156062-3-nowrep@gmail.com \
    --to=nowrep@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git