From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 2/8] avutil/vulkan_loader: Avoid redundant strings and relocations
Date: Sun, 3 Mar 2024 19:42:44 +0100
Message-ID: <AS8P250MB074448B08B87D35C791ABA3F8F5C2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <AS8P250MB0744636F6E1B70D50EB6644A8F5C2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM>
There are three possible names for the functions requested;
they only differ in an extension: "", "EXT" or "KHR".
Yet vk_load_info contained pointers to all these strings.
This is wasteful and this commit changes it to avoid
the latter two strings. This saves 6353B of strings,
1776 B of .data.rel.ro as well as 5328 B due to the removed
relocations (corresponding to 2 * 111 removed pointers)
in lavc/vulkan_decode.o alone (ff_vk_load_functions()
is inlined in lavfi/vulkan_filter.c, lavu/hwcontext_vulkan.c
and lavc_vulkan_decode.c, so the savings are three times
this for shared builds; for static builds, the number may
be smaller depending upon whether strings are deduplicated).
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavutil/vulkan_loader.h | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/libavutil/vulkan_loader.h b/libavutil/vulkan_loader.h
index f88722f28f..07b6316089 100644
--- a/libavutil/vulkan_loader.h
+++ b/libavutil/vulkan_loader.h
@@ -19,6 +19,9 @@
#ifndef AVUTIL_VULKAN_LOADER_H
#define AVUTIL_VULKAN_LOADER_H
+#include <stdio.h>
+
+#include "avassert.h"
#include "vulkan_functions.h"
/* Macro to turn a function name into a loader struct */
@@ -28,7 +31,7 @@
req_dev, \
offsetof(FFVulkanFunctions, name), \
ext_flag, \
- { "vk"#name, "vk"#name"EXT", "vk"#name"KHR" } \
+ "vk"#name, \
},
static inline uint64_t ff_vk_extensions_to_mask(const char * const *extensions,
@@ -98,7 +101,7 @@ static inline int ff_vk_load_functions(AVHWDeviceContext *ctx,
int req_dev;
size_t struct_offset;
FFVulkanExtensions ext_flag;
- const char *names[3];
+ const char *name;
} vk_load_info[] = {
FN_LIST(PFN_LOAD_INFO)
#ifdef _WIN32
@@ -108,6 +111,8 @@ static inline int ff_vk_load_functions(AVHWDeviceContext *ctx,
for (int i = 0; i < FF_ARRAY_ELEMS(vk_load_info); i++) {
const struct FunctionLoadInfo *load = &vk_load_info[i];
+ static const char extensions[][4] = { "", "EXT", "KHR" };
+ const char *name = load->name;
PFN_vkVoidFunction fn;
if (load->req_dev && !has_dev)
@@ -115,15 +120,19 @@ static inline int ff_vk_load_functions(AVHWDeviceContext *ctx,
if (load->req_inst && !has_inst)
continue;
- for (int j = 0; j < FF_ARRAY_ELEMS(load->names); j++) {
- const char *name = load->names[j];
+ for (int j = 0; j < FF_ARRAY_ELEMS(extensions); j++) {
+ char ext_name[128];
+ av_unused int n;
+
+ n = snprintf(ext_name, sizeof(ext_name), "%s%s", name, extensions[j]);
+ av_assert1(n < sizeof(ext_name));
if (load->req_dev)
- fn = vk->GetDeviceProcAddr(hwctx->act_dev, name);
+ fn = vk->GetDeviceProcAddr(hwctx->act_dev, ext_name);
else if (load->req_inst)
- fn = hwctx->get_proc_addr(hwctx->inst, name);
+ fn = hwctx->get_proc_addr(hwctx->inst, ext_name);
else
- fn = hwctx->get_proc_addr(NULL, name);
+ fn = hwctx->get_proc_addr(NULL, ext_name);
if (fn)
break;
@@ -131,7 +140,7 @@ static inline int ff_vk_load_functions(AVHWDeviceContext *ctx,
if (!fn && ((extensions_mask &~ FF_VK_EXT_NO_FLAG) & load->ext_flag)) {
av_log(ctx, AV_LOG_ERROR, "Loader error, function \"%s\" indicated "
- "as supported, but got NULL function pointer!\n", load->names[0]);
+ "as supported, but got NULL function pointer!\n", name);
return AVERROR_EXTERNAL;
}
--
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 prev parent reply other threads:[~2024-03-03 18:41 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 18:41 [FFmpeg-devel] [PATCH 1/8] avutil/vulkan: Don't autoinclude vulkan_loader.h Andreas Rheinhardt
2024-03-03 18:42 ` Andreas Rheinhardt [this message]
2024-03-03 18:42 ` [FFmpeg-devel] [PATCH 3/8] avutil/vulkan_loader: Use smaller types Andreas Rheinhardt
2024-03-03 18:42 ` [FFmpeg-devel] [PATCH 4/8] avutil/vulkan_loader: Avoid relocations for strings Andreas Rheinhardt
2024-03-03 18:42 ` [FFmpeg-devel] [PATCH 5/8] avutil/vulkan: Avoid shadowing Andreas Rheinhardt
2024-03-03 18:42 ` [FFmpeg-devel] [PATCH 6/8] avutil/vulkan: Make ff_vk_set_descriptor_image() static Andreas Rheinhardt
2024-03-03 18:42 ` [FFmpeg-devel] [PATCH 7/8] avutil/vulkan: Remove unused ff_vk_set_descriptor_sampler() Andreas Rheinhardt
2024-03-03 18:42 ` [FFmpeg-devel] [PATCH 8/8] avutil/vulkan: Move functions only used by lavfi to it Andreas Rheinhardt
2024-03-03 21:49 ` Lynne
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=AS8P250MB074448B08B87D35C791ABA3F8F5C2@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