Skip to content

Commit f6dd30d

Browse files
committed
lavfi/vulkan: split off lavfi-specific code into vulkan_filter.c
The issue is that libavfilter depends on libavcodec, and when doing a static build, if libavcodec also includes "libavfilter/vulkan.c", then during link-time, compiling programs will fail as there would be multiple definitions of the same symbols in both libavfilter and libavcodec's object files. Linkers are, however, more permitting if both files that include a common file that's used as a template are one-to-one identical. Hence, to make both files the same in the future, export all avfilter specific functions to a separate file. There is some work in progress to make templated files like this be compiled only once, so this is not a long-term solution. This also removes a macro that could be used to toggle SPIRV compilation capability on #include-time, as this could cause the files to be different.
1 parent e7f3279 commit f6dd30d

13 files changed

+240
-200
lines changed

libavfilter/Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ OBJS-$(CONFIG_ATADENOISE_FILTER) += vf_atadenoise.o
180180
OBJS-$(CONFIG_AVGBLUR_FILTER) += vf_avgblur.o
181181
OBJS-$(CONFIG_AVGBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
182182
opencl/avgblur.o boxblur.o
183-
OBJS-$(CONFIG_AVGBLUR_VULKAN_FILTER) += vf_avgblur_vulkan.o vulkan.o
183+
OBJS-$(CONFIG_AVGBLUR_VULKAN_FILTER) += vf_avgblur_vulkan.o vulkan.o vulkan_filter.o
184184
OBJS-$(CONFIG_BBOX_FILTER) += bbox.o vf_bbox.o
185185
OBJS-$(CONFIG_BENCH_FILTER) += f_bench.o
186186
OBJS-$(CONFIG_BILATERAL_FILTER) += vf_bilateral.o
@@ -194,7 +194,7 @@ OBJS-$(CONFIG_BOXBLUR_OPENCL_FILTER) += vf_avgblur_opencl.o opencl.o \
194194
opencl/avgblur.o boxblur.o
195195
OBJS-$(CONFIG_BWDIF_FILTER) += vf_bwdif.o yadif_common.o
196196
OBJS-$(CONFIG_CAS_FILTER) += vf_cas.o
197-
OBJS-$(CONFIG_CHROMABER_VULKAN_FILTER) += vf_chromaber_vulkan.o vulkan.o
197+
OBJS-$(CONFIG_CHROMABER_VULKAN_FILTER) += vf_chromaber_vulkan.o vulkan.o vulkan_filter.o
198198
OBJS-$(CONFIG_CHROMAHOLD_FILTER) += vf_chromakey.o
199199
OBJS-$(CONFIG_CHROMAKEY_FILTER) += vf_chromakey.o
200200
OBJS-$(CONFIG_CHROMANR_FILTER) += vf_chromanr.o
@@ -289,7 +289,7 @@ OBJS-$(CONFIG_FREEZEFRAMES_FILTER) += vf_freezeframes.o
289289
OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o
290290
OBJS-$(CONFIG_FSPP_FILTER) += vf_fspp.o qp_table.o
291291
OBJS-$(CONFIG_GBLUR_FILTER) += vf_gblur.o
292-
OBJS-$(CONFIG_GBLUR_VULKAN_FILTER) += vf_gblur_vulkan.o vulkan.o
292+
OBJS-$(CONFIG_GBLUR_VULKAN_FILTER) += vf_gblur_vulkan.o vulkan.o vulkan_filter.o
293293
OBJS-$(CONFIG_GEQ_FILTER) += vf_geq.o
294294
OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o
295295
OBJS-$(CONFIG_GRAPHMONITOR_FILTER) += f_graphmonitor.o
@@ -324,7 +324,7 @@ OBJS-$(CONFIG_LAGFUN_FILTER) += vf_lagfun.o
324324
OBJS-$(CONFIG_LATENCY_FILTER) += f_latency.o
325325
OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
326326
OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o
327-
OBJS-$(CONFIG_LIBPLACEBO_FILTER) += vf_libplacebo.o vulkan.o
327+
OBJS-$(CONFIG_LIBPLACEBO_FILTER) += vf_libplacebo.o vulkan.o vulkan_filter.o
328328
OBJS-$(CONFIG_LIBVMAF_FILTER) += vf_libvmaf.o framesync.o
329329
OBJS-$(CONFIG_LIMITDIFF_FILTER) += vf_limitdiff.o framesync.o
330330
OBJS-$(CONFIG_LIMITER_FILTER) += vf_limiter.o
@@ -370,7 +370,7 @@ OBJS-$(CONFIG_OVERLAY_CUDA_FILTER) += vf_overlay_cuda.o framesync.o vf
370370
OBJS-$(CONFIG_OVERLAY_OPENCL_FILTER) += vf_overlay_opencl.o opencl.o \
371371
opencl/overlay.o framesync.o
372372
OBJS-$(CONFIG_OVERLAY_QSV_FILTER) += vf_overlay_qsv.o framesync.o
373-
OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o
373+
OBJS-$(CONFIG_OVERLAY_VULKAN_FILTER) += vf_overlay_vulkan.o vulkan.o vulkan_filter.o
374374
OBJS-$(CONFIG_OWDENOISE_FILTER) += vf_owdenoise.o
375375
OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o
376376
OBJS-$(CONFIG_PAD_OPENCL_FILTER) += vf_pad_opencl.o opencl.o opencl/pad.o
@@ -415,7 +415,7 @@ OBJS-$(CONFIG_SCALE_CUDA_FILTER) += vf_scale_cuda.o scale_eval.o \
415415
OBJS-$(CONFIG_SCALE_NPP_FILTER) += vf_scale_npp.o scale_eval.o
416416
OBJS-$(CONFIG_SCALE_QSV_FILTER) += vf_scale_qsv.o
417417
OBJS-$(CONFIG_SCALE_VAAPI_FILTER) += vf_scale_vaapi.o scale_eval.o vaapi_vpp.o
418-
OBJS-$(CONFIG_SCALE_VULKAN_FILTER) += vf_scale_vulkan.o vulkan.o
418+
OBJS-$(CONFIG_SCALE_VULKAN_FILTER) += vf_scale_vulkan.o vulkan.o vulkan_filter.o
419419
OBJS-$(CONFIG_SCALE2REF_FILTER) += vf_scale.o scale_eval.o
420420
OBJS-$(CONFIG_SCALE2REF_NPP_FILTER) += vf_scale_npp.o scale_eval.o
421421
OBJS-$(CONFIG_SCDET_FILTER) += vf_scdet.o

libavfilter/vf_avgblur_vulkan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "libavutil/random_seed.h"
2020
#include "libavutil/opt.h"
21-
#include "vulkan.h"
21+
#include "vulkan_filter.h"
2222
#include "internal.h"
2323

2424
#define CGS 32

libavfilter/vf_chromaber_vulkan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "libavutil/random_seed.h"
2020
#include "libavutil/opt.h"
21-
#include "vulkan.h"
21+
#include "vulkan_filter.h"
2222
#include "internal.h"
2323

2424
#define CGROUPS (int [3]){ 32, 32, 1 }

libavfilter/vf_gblur_vulkan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "libavutil/random_seed.h"
2121
#include "libavutil/opt.h"
22-
#include "vulkan.h"
22+
#include "vulkan_filter.h"
2323
#include "internal.h"
2424

2525
#define CGS 32

libavfilter/vf_libplacebo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "libavutil/file.h"
2020
#include "libavutil/opt.h"
2121
#include "internal.h"
22-
#include "vulkan.h"
22+
#include "vulkan_filter.h"
2323
#include "scale_eval.h"
2424

2525
#include <libplacebo/renderer.h>

libavfilter/vf_overlay_vulkan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "libavutil/random_seed.h"
2020
#include "libavutil/opt.h"
21-
#include "vulkan.h"
21+
#include "vulkan_filter.h"
2222
#include "internal.h"
2323
#include "framesync.h"
2424

libavfilter/vf_scale_vulkan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include "libavutil/random_seed.h"
2020
#include "libavutil/opt.h"
21-
#include "vulkan.h"
21+
#include "vulkan_filter.h"
2222
#include "scale_eval.h"
2323
#include "internal.h"
2424
#include "colorspace.h"

libavfilter/vulkan.c

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -16,177 +16,4 @@
1616
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19-
#include "vulkan.h"
2019
#include "libavutil/vulkan.c"
21-
22-
static int vulkan_filter_set_device(AVFilterContext *avctx,
23-
AVBufferRef *device)
24-
{
25-
FFVulkanContext *s = avctx->priv;
26-
27-
av_buffer_unref(&s->device_ref);
28-
29-
s->device_ref = av_buffer_ref(device);
30-
if (!s->device_ref)
31-
return AVERROR(ENOMEM);
32-
33-
s->device = (AVHWDeviceContext*)s->device_ref->data;
34-
s->hwctx = s->device->hwctx;
35-
36-
return 0;
37-
}
38-
39-
static int vulkan_filter_set_frames(AVFilterContext *avctx,
40-
AVBufferRef *frames)
41-
{
42-
FFVulkanContext *s = avctx->priv;
43-
44-
av_buffer_unref(&s->frames_ref);
45-
46-
s->frames_ref = av_buffer_ref(frames);
47-
if (!s->frames_ref)
48-
return AVERROR(ENOMEM);
49-
50-
return 0;
51-
}
52-
53-
int ff_vk_filter_config_input(AVFilterLink *inlink)
54-
{
55-
int err;
56-
AVFilterContext *avctx = inlink->dst;
57-
FFVulkanContext *s = avctx->priv;
58-
FFVulkanFunctions *vk = &s->vkfn;
59-
AVHWFramesContext *input_frames;
60-
61-
if (!inlink->hw_frames_ctx) {
62-
av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
63-
"hardware frames context on the input.\n");
64-
return AVERROR(EINVAL);
65-
}
66-
67-
/* Extract the device and default output format from the first input. */
68-
if (avctx->inputs[0] != inlink)
69-
return 0;
70-
71-
input_frames = (AVHWFramesContext *)inlink->hw_frames_ctx->data;
72-
if (input_frames->format != AV_PIX_FMT_VULKAN)
73-
return AVERROR(EINVAL);
74-
75-
err = vulkan_filter_set_device(avctx, input_frames->device_ref);
76-
if (err < 0)
77-
return err;
78-
err = vulkan_filter_set_frames(avctx, inlink->hw_frames_ctx);
79-
if (err < 0)
80-
return err;
81-
82-
s->extensions = ff_vk_extensions_to_mask(s->hwctx->enabled_dev_extensions,
83-
s->hwctx->nb_enabled_dev_extensions);
84-
85-
err = ff_vk_load_functions(s->device, &s->vkfn, s->extensions, 1, 1);
86-
if (err < 0)
87-
return err;
88-
89-
vk->GetPhysicalDeviceProperties(s->hwctx->phys_dev, &s->props);
90-
vk->GetPhysicalDeviceMemoryProperties(s->hwctx->phys_dev, &s->mprops);
91-
92-
/* Default output parameters match input parameters. */
93-
s->input_format = input_frames->sw_format;
94-
if (s->output_format == AV_PIX_FMT_NONE)
95-
s->output_format = input_frames->sw_format;
96-
if (!s->output_width)
97-
s->output_width = inlink->w;
98-
if (!s->output_height)
99-
s->output_height = inlink->h;
100-
101-
return 0;
102-
}
103-
104-
int ff_vk_filter_config_output_inplace(AVFilterLink *outlink)
105-
{
106-
int err;
107-
AVFilterContext *avctx = outlink->src;
108-
FFVulkanContext *s = avctx->priv;
109-
110-
av_buffer_unref(&outlink->hw_frames_ctx);
111-
112-
if (!s->device_ref) {
113-
if (!avctx->hw_device_ctx) {
114-
av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
115-
"Vulkan device.\n");
116-
return AVERROR(EINVAL);
117-
}
118-
119-
err = vulkan_filter_set_device(avctx, avctx->hw_device_ctx);
120-
if (err < 0)
121-
return err;
122-
}
123-
124-
outlink->hw_frames_ctx = av_buffer_ref(s->frames_ref);
125-
if (!outlink->hw_frames_ctx)
126-
return AVERROR(ENOMEM);
127-
128-
outlink->w = s->output_width;
129-
outlink->h = s->output_height;
130-
131-
return 0;
132-
}
133-
134-
int ff_vk_filter_config_output(AVFilterLink *outlink)
135-
{
136-
int err;
137-
AVFilterContext *avctx = outlink->src;
138-
FFVulkanContext *s = avctx->priv;
139-
AVBufferRef *output_frames_ref;
140-
AVHWFramesContext *output_frames;
141-
142-
av_buffer_unref(&outlink->hw_frames_ctx);
143-
144-
if (!s->device_ref) {
145-
if (!avctx->hw_device_ctx) {
146-
av_log(avctx, AV_LOG_ERROR, "Vulkan filtering requires a "
147-
"Vulkan device.\n");
148-
return AVERROR(EINVAL);
149-
}
150-
151-
err = vulkan_filter_set_device(avctx, avctx->hw_device_ctx);
152-
if (err < 0)
153-
return err;
154-
}
155-
156-
output_frames_ref = av_hwframe_ctx_alloc(s->device_ref);
157-
if (!output_frames_ref) {
158-
err = AVERROR(ENOMEM);
159-
goto fail;
160-
}
161-
output_frames = (AVHWFramesContext*)output_frames_ref->data;
162-
163-
output_frames->format = AV_PIX_FMT_VULKAN;
164-
output_frames->sw_format = s->output_format;
165-
output_frames->width = s->output_width;
166-
output_frames->height = s->output_height;
167-
168-
err = av_hwframe_ctx_init(output_frames_ref);
169-
if (err < 0) {
170-
av_log(avctx, AV_LOG_ERROR, "Failed to initialise output "
171-
"frames: %d.\n", err);
172-
goto fail;
173-
}
174-
175-
outlink->hw_frames_ctx = output_frames_ref;
176-
outlink->w = s->output_width;
177-
outlink->h = s->output_height;
178-
179-
return 0;
180-
fail:
181-
av_buffer_unref(&output_frames_ref);
182-
return err;
183-
}
184-
185-
int ff_vk_filter_init(AVFilterContext *avctx)
186-
{
187-
FFVulkanContext *s = avctx->priv;
188-
189-
s->output_format = AV_PIX_FMT_NONE;
190-
191-
return 0;
192-
}

libavfilter/vulkan.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@
1919
#ifndef AVFILTER_VULKAN_H
2020
#define AVFILTER_VULKAN_H
2121

22-
#include "avfilter.h"
2322
#include "libavutil/vulkan.h"
2423

25-
/**
26-
* General lavfi IO functions
27-
*/
28-
int ff_vk_filter_init (AVFilterContext *avctx);
29-
int ff_vk_filter_config_input (AVFilterLink *inlink);
30-
int ff_vk_filter_config_output (AVFilterLink *outlink);
31-
int ff_vk_filter_config_output_inplace(AVFilterLink *outlink);
32-
3324
#endif /* AVFILTER_VULKAN_H */

0 commit comments

Comments
 (0)