From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org> Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/opencl: Add wrapper to load exactly one program Date: Mon, 31 Mar 2025 09:41:00 +0200 Message-ID: <AS8P250MB0744B99F819C81405B3F85CD8FAD2@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) [-- Attachment #1: Type: text/plain, Size: 29 bytes --] Patches attached. - Andreas [-- Attachment #2: 0001-avfilter-opencl-Add-wrapper-to-load-exactly-one-prog.patch --] [-- Type: text/x-patch, Size: 10374 bytes --] From 71bf8da70361c94d9106a0bc83f1af0e96f87f84 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Sat, 29 Mar 2025 11:34:57 +0100 Subject: [PATCH 1/2] avfilter/opencl: Add wrapper to load exactly one program ff_opencl_filter_load_program() can create a program from an array of strings, yet almost all users only want to use a single one. This commit adds a specialization for this common case. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavfilter/opencl.c | 14 ++++++++++---- libavfilter/opencl.h | 12 ++++++++++-- libavfilter/vf_avgblur_opencl.c | 2 +- libavfilter/vf_colorkey_opencl.c | 2 +- libavfilter/vf_convolution_opencl.c | 2 +- libavfilter/vf_deshake_opencl.c | 2 +- libavfilter/vf_neighbor_opencl.c | 2 +- libavfilter/vf_nlmeans_opencl.c | 2 +- libavfilter/vf_overlay_opencl.c | 2 +- libavfilter/vf_pad_opencl.c | 2 +- libavfilter/vf_remap_opencl.c | 2 +- libavfilter/vf_tonemap_opencl.c | 2 +- libavfilter/vf_transpose_opencl.c | 2 +- libavfilter/vf_unsharp_opencl.c | 2 +- libavfilter/vf_xfade_opencl.c | 2 +- 15 files changed, 33 insertions(+), 19 deletions(-) diff --git a/libavfilter/opencl.c b/libavfilter/opencl.c index e91610a10e..4726d0b111 100644 --- a/libavfilter/opencl.c +++ b/libavfilter/opencl.c @@ -156,9 +156,9 @@ void ff_opencl_filter_uninit(AVFilterContext *avctx) av_buffer_unref(&ctx->device_ref); } -int ff_opencl_filter_load_program(AVFilterContext *avctx, - const char **program_source_array, - int nb_strings) +int ff_opencl_filter_load_programs(AVFilterContext *avctx, + const char **program_source_array, + int nb_strings) { OpenCLFilterContext *ctx = avctx->priv; cl_int cle; @@ -204,6 +204,12 @@ int ff_opencl_filter_load_program(AVFilterContext *avctx, return 0; } +int ff_opencl_filter_load_program(AVFilterContext *avctx, + const char *program_source) +{ + return ff_opencl_filter_load_programs(avctx, &program_source, 1); +} + int ff_opencl_filter_load_program_from_file(AVFilterContext *avctx, const char *filename) { @@ -256,7 +262,7 @@ int ff_opencl_filter_load_program_from_file(AVFilterContext *avctx, src_const = src; - err = ff_opencl_filter_load_program(avctx, &src_const, 1); + err = ff_opencl_filter_load_program(avctx, src_const); fail: fclose(file); av_freep(&src); diff --git a/libavfilter/opencl.h b/libavfilter/opencl.h index dec376766e..1448d0a3eb 100644 --- a/libavfilter/opencl.h +++ b/libavfilter/opencl.h @@ -263,9 +263,17 @@ void ff_opencl_filter_uninit(AVFilterContext *avctx); * Creates a new program and compiles it for the current device. * Will log any build errors if compilation fails. */ +int ff_opencl_filter_load_programs(AVFilterContext *avctx, + const char **program_source_array, + int nb_strings); + +/** + * Load a new OpenCL program from a string in memory. + * This is a wrapper around ff_opencl_filter_load_programs() + * for the case of a single string. + */ int ff_opencl_filter_load_program(AVFilterContext *avctx, - const char **program_source_array, - int nb_strings); + const char *program_source); /** * Load a new OpenCL program from a file. diff --git a/libavfilter/vf_avgblur_opencl.c b/libavfilter/vf_avgblur_opencl.c index 790a51ea80..edd66748d8 100644 --- a/libavfilter/vf_avgblur_opencl.c +++ b/libavfilter/vf_avgblur_opencl.c @@ -59,7 +59,7 @@ static int avgblur_opencl_init(AVFilterContext *avctx) cl_int cle; int err; - err = ff_opencl_filter_load_program(avctx, &ff_source_avgblur_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_avgblur_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_colorkey_opencl.c b/libavfilter/vf_colorkey_opencl.c index 403e763503..3b9830525f 100644 --- a/libavfilter/vf_colorkey_opencl.c +++ b/libavfilter/vf_colorkey_opencl.c @@ -50,7 +50,7 @@ static int colorkey_opencl_init(AVFilterContext *avctx) cl_int cle; int err; - err = ff_opencl_filter_load_program(avctx, &ff_source_colorkey_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_colorkey_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_convolution_opencl.c b/libavfilter/vf_convolution_opencl.c index 7193a2b0d9..ec4dd426ba 100644 --- a/libavfilter/vf_convolution_opencl.c +++ b/libavfilter/vf_convolution_opencl.c @@ -63,7 +63,7 @@ static int convolution_opencl_init(AVFilterContext *avctx) cl_int cle; int err; - err = ff_opencl_filter_load_program(avctx, &ff_source_convolution_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_convolution_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_deshake_opencl.c b/libavfilter/vf_deshake_opencl.c index dc3df0e989..0026f650c5 100644 --- a/libavfilter/vf_deshake_opencl.c +++ b/libavfilter/vf_deshake_opencl.c @@ -1250,7 +1250,7 @@ static int deshake_opencl_init(AVFilterContext *avctx) } ctx->sw_format = hw_frames_ctx->sw_format; - err = ff_opencl_filter_load_program(avctx, &ff_source_deshake_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_deshake_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_neighbor_opencl.c b/libavfilter/vf_neighbor_opencl.c index 38a1b7821e..5eb7caeb6a 100644 --- a/libavfilter/vf_neighbor_opencl.c +++ b/libavfilter/vf_neighbor_opencl.c @@ -55,7 +55,7 @@ static int neighbor_opencl_init(AVFilterContext *avctx) cl_int cle; int err; - err = ff_opencl_filter_load_program(avctx, &ff_source_neighbor_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_neighbor_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_nlmeans_opencl.c b/libavfilter/vf_nlmeans_opencl.c index ae64429efc..ff44125ef1 100644 --- a/libavfilter/vf_nlmeans_opencl.c +++ b/libavfilter/vf_nlmeans_opencl.c @@ -98,7 +98,7 @@ static int nlmeans_opencl_init(AVFilterContext *avctx, int width, int height) if (!ctx->patch_size_uv) ctx->patch_size_uv = ctx->patch_size; - err = ff_opencl_filter_load_program(avctx, &ff_source_nlmeans_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_nlmeans_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_overlay_opencl.c b/libavfilter/vf_overlay_opencl.c index e930aced04..99519c19d2 100644 --- a/libavfilter/vf_overlay_opencl.c +++ b/libavfilter/vf_overlay_opencl.c @@ -92,7 +92,7 @@ static int overlay_opencl_load(AVFilterContext *avctx, av_log(avctx, AV_LOG_DEBUG, "Using kernel %s.\n", kernel); - err = ff_opencl_filter_load_program(avctx, &source, 1); + err = ff_opencl_filter_load_program(avctx, source); if (err < 0) goto fail; diff --git a/libavfilter/vf_pad_opencl.c b/libavfilter/vf_pad_opencl.c index 9dc0290c19..55a450af76 100644 --- a/libavfilter/vf_pad_opencl.c +++ b/libavfilter/vf_pad_opencl.c @@ -92,7 +92,7 @@ static int pad_opencl_init(AVFilterContext *avctx, AVFrame *input_frame) ctx->hsub = desc->log2_chroma_w; ctx->vsub = desc->log2_chroma_h; - err = ff_opencl_filter_load_program(avctx, &ff_source_pad_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_pad_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_remap_opencl.c b/libavfilter/vf_remap_opencl.c index bb83944b2f..3fa4d2f723 100644 --- a/libavfilter/vf_remap_opencl.c +++ b/libavfilter/vf_remap_opencl.c @@ -103,7 +103,7 @@ static int remap_opencl_load(AVFilterContext *avctx, ctx->nb_planes = main_planes; - err = ff_opencl_filter_load_program(avctx, &source, 1); + err = ff_opencl_filter_load_program(avctx, source); if (err < 0) goto fail; diff --git a/libavfilter/vf_tonemap_opencl.c b/libavfilter/vf_tonemap_opencl.c index 758c0e5e94..056629c98b 100644 --- a/libavfilter/vf_tonemap_opencl.c +++ b/libavfilter/vf_tonemap_opencl.c @@ -242,7 +242,7 @@ static int tonemap_opencl_init(AVFilterContext *avctx) opencl_sources[0] = header.str; opencl_sources[1] = ff_source_tonemap_cl; opencl_sources[2] = ff_source_colorspace_common_cl; - err = ff_opencl_filter_load_program(avctx, opencl_sources, OPENCL_SOURCE_NB); + err = ff_opencl_filter_load_programs(avctx, opencl_sources, OPENCL_SOURCE_NB); av_bprint_finalize(&header, NULL); if (err < 0) diff --git a/libavfilter/vf_transpose_opencl.c b/libavfilter/vf_transpose_opencl.c index 51201a9a71..64af30f687 100644 --- a/libavfilter/vf_transpose_opencl.c +++ b/libavfilter/vf_transpose_opencl.c @@ -44,7 +44,7 @@ static int transpose_opencl_init(AVFilterContext *avctx) cl_int cle; int err; - err = ff_opencl_filter_load_program(avctx, &ff_source_transpose_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_transpose_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_unsharp_opencl.c b/libavfilter/vf_unsharp_opencl.c index 15853e8db3..aa6dcd6bc2 100644 --- a/libavfilter/vf_unsharp_opencl.c +++ b/libavfilter/vf_unsharp_opencl.c @@ -69,7 +69,7 @@ static int unsharp_opencl_init(AVFilterContext *avctx) cl_int cle; int err; - err = ff_opencl_filter_load_program(avctx, &ff_source_unsharp_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_unsharp_cl); if (err < 0) goto fail; diff --git a/libavfilter/vf_xfade_opencl.c b/libavfilter/vf_xfade_opencl.c index 96dc7e4554..1952e897b0 100644 --- a/libavfilter/vf_xfade_opencl.c +++ b/libavfilter/vf_xfade_opencl.c @@ -92,7 +92,7 @@ static int xfade_opencl_load(AVFilterContext *avctx, if (ctx->transition == CUSTOM) { err = ff_opencl_filter_load_program_from_file(avctx, ctx->source_file); } else { - err = ff_opencl_filter_load_program(avctx, &ff_source_xfade_cl, 1); + err = ff_opencl_filter_load_program(avctx, ff_source_xfade_cl); } if (err < 0) return err; -- 2.45.2 [-- Attachment #3: 0002-tools-source2c-Avoid-indirection-and-relocations.patch --] [-- Type: text/x-patch, Size: 7513 bytes --] From d507cdbeb574392ec1bd06a7b4334e54dca513b4 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Mon, 31 Mar 2025 08:48:31 +0200 Subject: [PATCH 2/2] tools/source2c: Avoid indirection and relocations Don't use non-const pointers to string literals (which entails a relocation and an indirection); instead use an ordinary const char[]. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/ffv1enc_vulkan.c | 24 ++++++++++++------------ libavcodec/vulkan/Makefile | 2 +- libavcodec/vulkan_ffv1.c | 16 ++++++++-------- libavfilter/Makefile | 2 +- libavfilter/opencl_source.h | 28 ++++++++++++++-------------- libavfilter/vf_bwdif_vulkan.c | 2 +- libavfilter/vulkan/Makefile | 2 +- tools/source2c | 2 +- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/libavcodec/ffv1enc_vulkan.c b/libavcodec/ffv1enc_vulkan.c index 5409927589..d1a30b0dd7 100644 --- a/libavcodec/ffv1enc_vulkan.c +++ b/libavcodec/ffv1enc_vulkan.c @@ -109,18 +109,18 @@ typedef struct VulkanEncodeFFv1Context { int chunks; } VulkanEncodeFFv1Context; -extern const char *ff_source_common_comp; -extern const char *ff_source_rangecoder_comp; -extern const char *ff_source_ffv1_vlc_comp; -extern const char *ff_source_ffv1_common_comp; -extern const char *ff_source_ffv1_reset_comp; -extern const char *ff_source_ffv1_enc_common_comp; -extern const char *ff_source_ffv1_enc_rct_comp; -extern const char *ff_source_ffv1_enc_vlc_comp; -extern const char *ff_source_ffv1_enc_ac_comp; -extern const char *ff_source_ffv1_enc_setup_comp; -extern const char *ff_source_ffv1_enc_comp; -extern const char *ff_source_ffv1_enc_rgb_comp; +extern const char ff_source_common_comp[]; +extern const char ff_source_rangecoder_comp[]; +extern const char ff_source_ffv1_vlc_comp[]; +extern const char ff_source_ffv1_common_comp[]; +extern const char ff_source_ffv1_reset_comp[]; +extern const char ff_source_ffv1_enc_common_comp[]; +extern const char ff_source_ffv1_enc_rct_comp[]; +extern const char ff_source_ffv1_enc_vlc_comp[]; +extern const char ff_source_ffv1_enc_ac_comp[]; +extern const char ff_source_ffv1_enc_setup_comp[]; +extern const char ff_source_ffv1_enc_comp[]; +extern const char ff_source_ffv1_enc_rgb_comp[]; typedef struct FFv1VkParameters { VkDeviceAddress slice_state; diff --git a/libavcodec/vulkan/Makefile b/libavcodec/vulkan/Makefile index e6bad486bd..655df11f4a 100644 --- a/libavcodec/vulkan/Makefile +++ b/libavcodec/vulkan/Makefile @@ -20,5 +20,5 @@ OBJS-$(CONFIG_FFV1_VULKAN_HWACCEL) += vulkan/common.o \ VULKAN = $(subst $(SRC_PATH)/,,$(wildcard $(SRC_PATH)/libavcodec/vulkan/*.comp)) .SECONDARY: $(VULKAN:.comp=.c) libavcodec/vulkan/%.c: TAG = VULKAN -libavcodec/vulkan/%.c: $(SRC_PATH)/libavcodec/vulkan/%.comp +libavcodec/vulkan/%.c: $(SRC_PATH)/libavcodec/vulkan/%.comp $(SRC_PATH)/tools/source2c $(M)$(SRC_PATH)/tools/source2c $< $@ diff --git a/libavcodec/vulkan_ffv1.c b/libavcodec/vulkan_ffv1.c index 17bfc943d4..2a28db2e7c 100644 --- a/libavcodec/vulkan_ffv1.c +++ b/libavcodec/vulkan_ffv1.c @@ -26,14 +26,14 @@ #include "libavutil/vulkan_spirv.h" #include "libavutil/mem.h" -extern const char *ff_source_common_comp; -extern const char *ff_source_rangecoder_comp; -extern const char *ff_source_ffv1_vlc_comp; -extern const char *ff_source_ffv1_common_comp; -extern const char *ff_source_ffv1_dec_setup_comp; -extern const char *ff_source_ffv1_reset_comp; -extern const char *ff_source_ffv1_dec_comp; -extern const char *ff_source_ffv1_dec_rct_comp; +extern const char ff_source_common_comp[]; +extern const char ff_source_rangecoder_comp[]; +extern const char ff_source_ffv1_vlc_comp[]; +extern const char ff_source_ffv1_common_comp[]; +extern const char ff_source_ffv1_dec_setup_comp[]; +extern const char ff_source_ffv1_reset_comp[]; +extern const char ff_source_ffv1_dec_comp[]; +extern const char ff_source_ffv1_dec_rct_comp[]; const FFVulkanDecodeDescriptor ff_vk_dec_ffv1_desc = { .codec_id = AV_CODEC_ID_FFV1, diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 7c0d879ec9..2376e11bc7 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -683,5 +683,5 @@ clean:: OPENCL = $(subst $(SRC_PATH)/,,$(wildcard $(SRC_PATH)/libavfilter/opencl/*.cl)) .SECONDARY: $(OPENCL:.cl=.c) libavfilter/opencl/%.c: TAG = OPENCL -libavfilter/opencl/%.c: $(SRC_PATH)/libavfilter/opencl/%.cl +libavfilter/opencl/%.c: $(SRC_PATH)/libavfilter/opencl/%.cl $(SRC_PATH)/tools/source2c $(M)$(SRC_PATH)/tools/source2c $< $@ diff --git a/libavfilter/opencl_source.h b/libavfilter/opencl_source.h index b6930fb686..a1c89c4cbf 100644 --- a/libavfilter/opencl_source.h +++ b/libavfilter/opencl_source.h @@ -19,19 +19,19 @@ #ifndef AVFILTER_OPENCL_SOURCE_H #define AVFILTER_OPENCL_SOURCE_H -extern const char *ff_source_avgblur_cl; -extern const char *ff_source_colorkey_cl; -extern const char *ff_source_colorspace_common_cl; -extern const char *ff_source_convolution_cl; -extern const char *ff_source_deshake_cl; -extern const char *ff_source_neighbor_cl; -extern const char *ff_source_nlmeans_cl; -extern const char *ff_source_overlay_cl; -extern const char *ff_source_pad_cl; -extern const char *ff_source_remap_cl; -extern const char *ff_source_tonemap_cl; -extern const char *ff_source_transpose_cl; -extern const char *ff_source_unsharp_cl; -extern const char *ff_source_xfade_cl; +extern const char ff_source_avgblur_cl[]; +extern const char ff_source_colorkey_cl[]; +extern const char ff_source_colorspace_common_cl[]; +extern const char ff_source_convolution_cl[]; +extern const char ff_source_deshake_cl[]; +extern const char ff_source_neighbor_cl[]; +extern const char ff_source_nlmeans_cl[]; +extern const char ff_source_overlay_cl[]; +extern const char ff_source_pad_cl[]; +extern const char ff_source_remap_cl[]; +extern const char ff_source_tonemap_cl[]; +extern const char ff_source_transpose_cl[]; +extern const char ff_source_unsharp_cl[]; +extern const char ff_source_xfade_cl[]; #endif /* AVFILTER_OPENCL_SOURCE_H */ diff --git a/libavfilter/vf_bwdif_vulkan.c b/libavfilter/vf_bwdif_vulkan.c index 549e814886..981bf76711 100644 --- a/libavfilter/vf_bwdif_vulkan.c +++ b/libavfilter/vf_bwdif_vulkan.c @@ -43,7 +43,7 @@ typedef struct BWDIFParameters { int current_field; } BWDIFParameters; -extern const char *ff_source_bwdif_comp; +extern const char ff_source_bwdif_comp[]; static av_cold int init_filter(AVFilterContext *ctx) { diff --git a/libavfilter/vulkan/Makefile b/libavfilter/vulkan/Makefile index 573eee32c7..b64e687224 100644 --- a/libavfilter/vulkan/Makefile +++ b/libavfilter/vulkan/Makefile @@ -8,5 +8,5 @@ OBJS-$(CONFIG_BWDIF_VULKAN_FILTER) += vulkan/bwdif.o VULKAN = $(subst $(SRC_PATH)/,,$(wildcard $(SRC_PATH)/libavfilter/vulkan/*.comp)) .SECONDARY: $(VULKAN:.comp=.c) libavfilter/vulkan/%.c: TAG = VULKAN -libavfilter/vulkan/%.c: $(SRC_PATH)/libavfilter/vulkan/%.comp +libavfilter/vulkan/%.c: $(SRC_PATH)/libavfilter/vulkan/%.comp $(SRC_PATH)/tools/source2c $(M)$(SRC_PATH)/tools/source2c $< $@ diff --git a/tools/source2c b/tools/source2c index 6e5f123144..05a69bbbff 100755 --- a/tools/source2c +++ b/tools/source2c @@ -25,7 +25,7 @@ name=$(basename "$input" | sed 's/\./_/') cat >$output <<EOF // Generated from $input -const char *ff_source_$name = +const char ff_source_$name[] = EOF # Convert \ to \\ and " to \", then add " to the start and end of the line. -- 2.45.2 [-- Attachment #4: Type: text/plain, Size: 251 bytes --] _______________________________________________ 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:[~2025-03-31 7:41 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-03-31 7:41 Andreas Rheinhardt [this message] 2025-04-02 14:25 ` 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=AS8P250MB0744B99F819C81405B3F85CD8FAD2@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