From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 1/3] avcodec/vulkan_video: Don't use sparse table Date: Sun, 3 Mar 2024 12:35:06 +0100 Message-ID: <AS8P250MB074402E3F6CCBE7C2249F7618F5C2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) ff_vk_codec_map currently is an array indexed by AVCodecID; it has AV_CODEC_ID_FIRST_AUDIO (= 65536) entries, but uses only three of them; only 24B of 1MiB were actually used This commit fixes this by adding an AVCodecID field to the table and making it non-sparse. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/vulkan_decode.c | 17 ++++++++++++++--- libavcodec/vulkan_video.c | 11 +++++++---- libavcodec/vulkan_video.h | 6 ++---- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libavcodec/vulkan_decode.c b/libavcodec/vulkan_decode.c index fdbcbb450a..5def908a21 100644 --- a/libavcodec/vulkan_decode.c +++ b/libavcodec/vulkan_decode.c @@ -20,6 +20,7 @@ #include "vulkan_video.h" #include "vulkan_decode.h" #include "config_components.h" +#include "libavutil/avassert.h" #if CONFIG_H264_VULKAN_HWACCEL extern const VkExtensionProperties ff_vk_dec_h264_ext; @@ -43,6 +44,15 @@ static const VkExtensionProperties *dec_ext[] = { #endif }; +static const FFVkCodecMap *get_codecmap(enum AVCodecID codec_id) +{ + for (size_t i = 0; i < FF_ARRAY_ELEMS(ff_vk_codec_map); i++) + if (ff_vk_codec_map[i].codec_id == codec_id) + return &ff_vk_codec_map[i]; + av_assert1(!"unreachable"); + return NULL; +} + static const VkVideoProfileInfoKHR *get_video_profile(FFVulkanDecodeShared *ctx, enum AVCodecID codec_id) { const VkVideoProfileListInfoKHR *profile_list; @@ -737,7 +747,7 @@ static int vulkan_decode_get_profile(AVCodecContext *avctx, AVBufferRef *frames_ { VkResult ret; int max_level, base_profile, cur_profile; - const struct FFVkCodecMap *vk_codec = &ff_vk_codec_map[avctx->codec_id]; + const FFVkCodecMap *vk_codec = get_codecmap(avctx->codec_id); AVHWFramesContext *frames = (AVHWFramesContext *)frames_ref->data; AVHWDeviceContext *device = (AVHWDeviceContext *)frames->device_ref->data; AVVulkanDeviceContext *hwctx = device->hwctx; @@ -1111,6 +1121,7 @@ int ff_vk_decode_init(AVCodecContext *avctx) FFVulkanContext *s; FFVulkanFunctions *vk; const VkVideoProfileInfoKHR *profile; + const FFVkCodecMap *vk_codec; VkVideoDecodeH264SessionParametersCreateInfoKHR h264_params = { .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_H264_SESSION_PARAMETERS_CREATE_INFO_KHR, @@ -1167,9 +1178,9 @@ int ff_vk_decode_init(AVCodecContext *avctx) /* Create queue context */ qf = ff_vk_qf_init(s, &ctx->qf, VK_QUEUE_VIDEO_DECODE_BIT_KHR); + vk_codec = get_codecmap(avctx->codec_id); /* Check for support */ - if (!(s->video_props[qf].videoCodecOperations & - ff_vk_codec_map[avctx->codec_id].decode_op)) { + if (!(s->video_props[qf].videoCodecOperations & vk_codec->decode_op)) { av_log(avctx, AV_LOG_ERROR, "Decoding %s not supported on the given " "queue family %i!\n", avcodec_get_name(avctx->codec_id), qf); return AVERROR(EINVAL); diff --git a/libavcodec/vulkan_video.c b/libavcodec/vulkan_video.c index fb20315db4..a87df52871 100644 --- a/libavcodec/vulkan_video.c +++ b/libavcodec/vulkan_video.c @@ -20,20 +20,23 @@ #include "vulkan_video.h" -const FFVkCodecMap ff_vk_codec_map[AV_CODEC_ID_FIRST_AUDIO] = { - [AV_CODEC_ID_H264] = { +const FFVkCodecMap ff_vk_codec_map[3] = { + { + .codec_id = AV_CODEC_ID_H264, 0, 0, FF_VK_EXT_VIDEO_DECODE_H264, VK_VIDEO_CODEC_OPERATION_DECODE_H264_BIT_KHR, }, - [AV_CODEC_ID_HEVC] = { + { + .codec_id = AV_CODEC_ID_HEVC, 0, 0, FF_VK_EXT_VIDEO_DECODE_H265, VK_VIDEO_CODEC_OPERATION_DECODE_H265_BIT_KHR }, - [AV_CODEC_ID_AV1] = { + { + .codec_id = AV_CODEC_ID_AV1, 0, 0, FF_VK_EXT_VIDEO_DECODE_AV1, diff --git a/libavcodec/vulkan_video.h b/libavcodec/vulkan_video.h index 51f44dd543..b06e369abd 100644 --- a/libavcodec/vulkan_video.h +++ b/libavcodec/vulkan_video.h @@ -32,6 +32,7 @@ #define CODEC_VER(ver) CODEC_VER_MAJ(ver), CODEC_VER_MIN(ver), CODEC_VER_PAT(ver) typedef struct FFVkCodecMap { + enum AVCodecID codec_id; FFVulkanExtensions encode_extension; VkVideoCodecOperationFlagBitsKHR encode_op; FFVulkanExtensions decode_extension; @@ -46,10 +47,7 @@ typedef struct FFVkVideoSession { AVBufferPool *buf_pool; } FFVkVideoCommon; -/** - * Index is codec_id. - */ -extern const FFVkCodecMap ff_vk_codec_map[AV_CODEC_ID_FIRST_AUDIO]; +extern const FFVkCodecMap ff_vk_codec_map[3]; /** * Get pixfmt from a Vulkan format. -- 2.40.1 _______________________________________________ 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".
next reply other threads:[~2024-03-03 11:33 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2024-03-03 11:35 Andreas Rheinhardt [this message] 2024-03-03 11:37 ` [FFmpeg-devel] [PATCH 2/3] avcodec/vulkan: Make FFVkCodecMap decoder-only Andreas Rheinhardt 2024-03-03 11:37 ` [FFmpeg-devel] [PATCH 3/3] avcodec/vulkan_decode: Un-sparse extensions table Andreas Rheinhardt 2024-03-03 13:03 ` Lynne 2024-03-03 13:08 ` Andreas Rheinhardt 2024-03-07 0:36 ` Andreas Rheinhardt
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=AS8P250MB074402E3F6CCBE7C2249F7618F5C2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \ --to=andreas.rheinhardt@outlook.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