FFmpeg
vf_avgblur_vulkan.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) Lynne
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/random_seed.h"
22 #include "libavutil/opt.h"
23 #include "vulkan_filter.h"
24 #include "vulkan_spirv.h"
25 
26 #include "filters.h"
27 #include "video.h"
28 
29 typedef struct AvgBlurVulkanContext {
31 
35  VkSampler sampler;
38 
39  /* Push constants / options */
40  struct {
41  float filter_norm[4];
43  } opts;
44 
45  int size_x;
46  int size_y;
47  int planes;
49 
50 static const char blur_kernel[] = {
51  C(0, void distort(const ivec2 pos, const int idx) )
52  C(0, { )
53  C(1, vec4 sum = vec4(0); )
54  C(1, for (int y = -filter_len.y; y <= filter_len.y; y++) )
55  C(1, for (int x = -filter_len.x; x <= filter_len.x; x++) )
56  C(2, sum += texture(input_img[idx], pos + ivec2(x, y)); )
57  C(0, )
58  C(1, imageStore(output_img[idx], pos, sum * filter_norm); )
59  C(0, } )
60 };
61 
63 {
64  int err;
65  uint8_t *spv_data;
66  size_t spv_len;
67  void *spv_opaque = NULL;
68  AvgBlurVulkanContext *s = ctx->priv;
69  FFVulkanContext *vkctx = &s->vkctx;
70  const int planes = av_pix_fmt_count_planes(s->vkctx.output_format);
71  FFVkSPIRVShader *shd;
72  FFVkSPIRVCompiler *spv;
74 
75  spv = ff_vk_spirv_init();
76  if (!spv) {
77  av_log(ctx, AV_LOG_ERROR, "Unable to initialize SPIR-V compiler!\n");
78  return AVERROR_EXTERNAL;
79  }
80 
81  ff_vk_qf_init(vkctx, &s->qf, VK_QUEUE_COMPUTE_BIT);
82  RET(ff_vk_exec_pool_init(vkctx, &s->qf, &s->e, s->qf.nb_queues*4, 0, 0, 0, NULL));
83  RET(ff_vk_init_sampler(vkctx, &s->sampler, 1, VK_FILTER_LINEAR));
84  RET(ff_vk_shader_init(&s->pl, &s->shd, "avgblur_compute",
85  VK_SHADER_STAGE_COMPUTE_BIT, 0));
86  shd = &s->shd;
87 
88  ff_vk_shader_set_compute_sizes(shd, 32, 1, 1);
89 
91  {
92  .name = "input_img",
93  .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
94  .dimensions = 2,
95  .elems = planes,
96  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
97  .samplers = DUP_SAMPLER(s->sampler),
98  },
99  {
100  .name = "output_img",
101  .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
102  .mem_layout = ff_vk_shader_rep_fmt(s->vkctx.output_format),
103  .mem_quali = "writeonly",
104  .dimensions = 2,
105  .elems = planes,
106  .stages = VK_SHADER_STAGE_COMPUTE_BIT,
107  },
108  };
109 
110  RET(ff_vk_pipeline_descriptor_set_add(vkctx, &s->pl, shd, desc, 2, 0, 0));
111 
112  GLSLC(0, layout(push_constant, std430) uniform pushConstants { );
113  GLSLC(1, vec4 filter_norm; );
114  GLSLC(1, ivec2 filter_len; );
115  GLSLC(0, }; );
116  GLSLC(0, );
117 
118  ff_vk_add_push_constant(&s->pl, 0, sizeof(s->opts),
119  VK_SHADER_STAGE_COMPUTE_BIT);
120 
121  GLSLD( blur_kernel );
122  GLSLC(0, void main() );
123  GLSLC(0, { );
124  GLSLC(1, ivec2 size; );
125  GLSLC(1, const ivec2 pos = ivec2(gl_GlobalInvocationID.xy); );
126  for (int i = 0; i < planes; i++) {
127  GLSLC(0, );
128  GLSLF(1, size = imageSize(output_img[%i]); ,i);
129  GLSLC(1, if (!IS_WITHIN(pos, size)) );
130  GLSLC(2, return; );
131  if (s->planes & (1 << i)) {
132  GLSLF(1, distort(pos, %i); ,i);
133  } else {
134  GLSLF(1, vec4 res = texture(input_img[%i], pos); ,i);
135  GLSLF(1, imageStore(output_img[%i], pos, res); ,i);
136  }
137  }
138  GLSLC(0, } );
139 
140  RET(spv->compile_shader(spv, ctx, &s->shd, &spv_data, &spv_len, "main",
141  &spv_opaque));
142  RET(ff_vk_shader_create(vkctx, &s->shd, spv_data, spv_len, "main"));
143 
144  RET(ff_vk_init_compute_pipeline(vkctx, &s->pl, &s->shd));
145  RET(ff_vk_exec_pipeline_register(vkctx, &s->e, &s->pl));
146 
147  s->initialized = 1;
148  s->opts.filter_len[0] = s->size_x - 1;
149  s->opts.filter_len[1] = s->size_y - 1;
150 
151  s->opts.filter_norm[0] = s->opts.filter_len[0]*2 + 1;
152  s->opts.filter_norm[0] = 1.0/(s->opts.filter_norm[0]*s->opts.filter_norm[0]);
153  s->opts.filter_norm[1] = s->opts.filter_norm[0];
154  s->opts.filter_norm[2] = s->opts.filter_norm[0];
155  s->opts.filter_norm[3] = s->opts.filter_norm[0];
156 
157 fail:
158  if (spv_opaque)
159  spv->free_shader(spv, &spv_opaque);
160  if (spv)
161  spv->uninit(&spv);
162 
163  return err;
164 }
165 
167 {
168  int err;
169  AVFrame *out = NULL;
170  AVFilterContext *ctx = link->dst;
171  AvgBlurVulkanContext *s = ctx->priv;
172  AVFilterLink *outlink = ctx->outputs[0];
173 
174  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
175  if (!out) {
176  err = AVERROR(ENOMEM);
177  goto fail;
178  }
179 
180  if (!s->initialized)
181  RET(init_filter(ctx, in));
182 
183  RET(ff_vk_filter_process_simple(&s->vkctx, &s->e, &s->pl,
184  out, in, s->sampler, &s->opts, sizeof(s->opts)));
185 
186  err = av_frame_copy_props(out, in);
187  if (err < 0)
188  goto fail;
189 
190  av_frame_free(&in);
191 
192  return ff_filter_frame(outlink, out);
193 
194 fail:
195  av_frame_free(&in);
196  av_frame_free(&out);
197  return err;
198 }
199 
201 {
202  AvgBlurVulkanContext *s = avctx->priv;
203  FFVulkanContext *vkctx = &s->vkctx;
204  FFVulkanFunctions *vk = &vkctx->vkfn;
205 
206  ff_vk_exec_pool_free(vkctx, &s->e);
207  ff_vk_pipeline_free(vkctx, &s->pl);
208  ff_vk_shader_free(vkctx, &s->shd);
209 
210  if (s->sampler)
211  vk->DestroySampler(vkctx->hwctx->act_dev, s->sampler,
212  vkctx->hwctx->alloc);
213 
214  ff_vk_uninit(&s->vkctx);
215 
216  s->initialized = 0;
217 }
218 
219 #define OFFSET(x) offsetof(AvgBlurVulkanContext, x)
220 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
222  { "sizeX", "Set horizontal radius", OFFSET(size_x), AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 32, .flags = FLAGS },
223  { "sizeY", "Set vertical radius", OFFSET(size_y), AV_OPT_TYPE_INT, { .i64 = 3 }, 1, 32, .flags = FLAGS },
224  { "planes", "Set planes to filter (bitmask)", OFFSET(planes), AV_OPT_TYPE_INT, {.i64 = 0xF}, 0, 0xF, .flags = FLAGS },
225  { NULL },
226 };
227 
228 AVFILTER_DEFINE_CLASS(avgblur_vulkan);
229 
231  {
232  .name = "default",
233  .type = AVMEDIA_TYPE_VIDEO,
234  .filter_frame = &avgblur_vulkan_filter_frame,
235  .config_props = &ff_vk_filter_config_input,
236  },
237 };
238 
240  {
241  .name = "default",
242  .type = AVMEDIA_TYPE_VIDEO,
243  .config_props = &ff_vk_filter_config_output,
244  },
245 };
246 
248  .name = "avgblur_vulkan",
249  .description = NULL_IF_CONFIG_SMALL("Apply avgblur mask to input video"),
250  .priv_size = sizeof(AvgBlurVulkanContext),
256  .priv_class = &avgblur_vulkan_class,
257  .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
258  .flags = AVFILTER_FLAG_HWDEVICE,
259 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:116
ff_vk_pipeline_free
void ff_vk_pipeline_free(FFVulkanContext *s, FFVulkanPipeline *pl)
Definition: vulkan.c:1830
AvgBlurVulkanContext
Definition: vf_avgblur_vulkan.c:29
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
FLAGS
#define FLAGS
Definition: vf_avgblur_vulkan.c:220
avgblur_vulkan_outputs
static const AVFilterPad avgblur_vulkan_outputs[]
Definition: vf_avgblur_vulkan.c:239
out
FILE * out
Definition: movenc.c:55
avgblur_vulkan_inputs
static const AVFilterPad avgblur_vulkan_inputs[]
Definition: vf_avgblur_vulkan.c:230
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1023
ff_vk_qf_init
int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family)
Chooses a QF and loads it into a context.
Definition: vulkan.c:227
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:160
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:258
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
ff_vk_filter_init
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
Definition: vulkan_filter.c:234
ff_vk_shader_create
int ff_vk_shader_create(FFVulkanContext *s, FFVkSPIRVShader *shd, uint8_t *spirv, size_t spirv_size, const char *entrypoint)
Definition: vulkan.c:1399
AVOption
AVOption.
Definition: opt.h:429
AvgBlurVulkanContext::pl
FFVulkanPipeline pl
Definition: vf_avgblur_vulkan.c:36
ff_vf_avgblur_vulkan
const AVFilter ff_vf_avgblur_vulkan
Definition: vf_avgblur_vulkan.c:247
ff_vk_uninit
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
Definition: vulkan.c:1859
FFVkSPIRVCompiler::uninit
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
Definition: vulkan_spirv.h:33
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
avgblur_vulkan_uninit
static void avgblur_vulkan_uninit(AVFilterContext *avctx)
Definition: vf_avgblur_vulkan.c:200
ff_vk_shader_set_compute_sizes
void ff_vk_shader_set_compute_sizes(FFVkSPIRVShader *shd, int x, int y, int z)
Definition: vulkan.c:1357
AvgBlurVulkanContext::initialized
int initialized
Definition: vf_avgblur_vulkan.c:32
planes
static const struct @446 planes[]
AvgBlurVulkanContext::sampler
VkSampler sampler
Definition: vf_avgblur_vulkan.c:35
blur_kernel
static const char blur_kernel[]
Definition: vf_avgblur_vulkan.c:50
video.h
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(avgblur_vulkan)
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3005
AVVulkanDeviceContext::alloc
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.
Definition: hwcontext_vulkan.h:63
ff_vk_add_push_constant
int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
Definition: vulkan.c:1127
AvgBlurVulkanContext::filter_norm
float filter_norm[4]
Definition: vf_avgblur_vulkan.c:41
AVFilterContext::priv
void * priv
private data for use by the filter
Definition: avfilter.h:422
fail
#define fail()
Definition: checkasm.h:188
vulkan_filter.h
avgblur_vulkan_options
static const AVOption avgblur_vulkan_options[]
Definition: vf_avgblur_vulkan.c:221
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
C
s EdgeDetect Foobar g libavfilter vf_edgedetect c libavfilter vf_foobar c edit libavfilter and add an entry for foobar following the pattern of the other filters edit libavfilter allfilters and add an entry for foobar following the pattern of the other filters configure make j< whatever > ffmpeg ffmpeg i you should get a foobar png with Lena edge detected That s your new playground is ready Some little details about what s going which in turn will define variables for the build system and the C
Definition: writing_filters.txt:58
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
main
int main
Definition: dovi_rpuenc.c:37
s
#define s(width, name)
Definition: cbs_vp9.c:198
filters.h
ctx
AVFormatContext * ctx
Definition: movenc.c:49
FFVkSPIRVCompiler::compile_shader
int(* compile_shader)(struct FFVkSPIRVCompiler *ctx, void *avctx, struct FFVkSPIRVShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
Definition: vulkan_spirv.h:29
ff_vk_exec_pool_free
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
Definition: vulkan.c:237
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:259
link
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a link
Definition: filter_design.txt:23
AvgBlurVulkanContext::e
FFVkExecPool e
Definition: vf_avgblur_vulkan.c:33
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:711
GLSLD
#define GLSLD(D)
Definition: vulkan.h:59
AvgBlurVulkanContext::qf
FFVkQueueFamilyCtx qf
Definition: vf_avgblur_vulkan.c:34
OFFSET
#define OFFSET(x)
Definition: vf_avgblur_vulkan.c:219
ff_vk_filter_config_output
int ff_vk_filter_config_output(AVFilterLink *outlink)
Definition: vulkan_filter.c:210
ff_vk_init_compute_pipeline
int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd)
Definition: vulkan.c:1771
AvgBlurVulkanContext::size_y
int size_y
Definition: vf_avgblur_vulkan.c:46
ff_vk_exec_pool_init
int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, FFVkExecPool *pool, int nb_contexts, int nb_queries, VkQueryType query_type, int query_64bit, const void *query_create_pnext)
Allocates/frees an execution pool.
Definition: vulkan.c:277
FFVulkanContext
Definition: vulkan.h:229
FFVulkanPipeline
Definition: vulkan.h:132
AvgBlurVulkanContext::filter_len
int32_t filter_len[2]
Definition: vf_avgblur_vulkan.c:42
FF_FILTER_FLAG_HWFRAME_AWARE
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
Definition: filters.h:206
ff_vk_shader_init
int ff_vk_shader_init(FFVulkanPipeline *pl, FFVkSPIRVShader *shd, const char *name, VkShaderStageFlags stage, uint32_t required_subgroup_size)
Shader management.
Definition: vulkan.c:1331
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
AvgBlurVulkanContext::planes
int planes
Definition: vf_avgblur_vulkan.c:47
FFVulkanDescriptorSetBinding
Definition: vulkan.h:83
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
AVFILTER_FLAG_HWDEVICE
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
Definition: avfilter.h:138
size
int size
Definition: twinvq_data.h:10344
FFVkQueueFamilyCtx
Definition: vulkan.h:110
AvgBlurVulkanContext::vkctx
FFVulkanContext vkctx
Definition: vf_avgblur_vulkan.c:30
init_filter
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
Definition: vf_avgblur_vulkan.c:62
AVERROR_EXTERNAL
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:59
ff_vk_filter_process_simple
int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanPipeline *pl, AVFrame *out_f, AVFrame *in_f, VkSampler sampler, void *push_src, size_t push_size)
Submit a compute shader with a zero/one input and single out for execution.
Definition: vulkan_filter.c:243
FFVkSPIRVCompiler
Definition: vulkan_spirv.h:27
layout
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel layout
Definition: filter_design.txt:18
AvgBlurVulkanContext::opts
struct AvgBlurVulkanContext::@320 opts
uninit
static void uninit(AVBSFContext *ctx)
Definition: pcm_rechunk.c:68
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
DUP_SAMPLER
#define DUP_SAMPLER(x)
Definition: vulkan.h:73
ff_vk_shader_rep_fmt
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Returns the format to use for images in shaders.
Definition: vulkan.c:1191
AvgBlurVulkanContext::size_x
int size_x
Definition: vf_avgblur_vulkan.c:45
vulkan_spirv.h
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
GLSLF
#define GLSLF(N, S,...)
Definition: vulkan.h:54
FFVkSPIRVCompiler::free_shader
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
Definition: vulkan_spirv.h:32
AVFilter
Filter definition.
Definition: avfilter.h:166
ff_vk_pipeline_descriptor_set_add
int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a pipeline.
Definition: vulkan.c:1449
FFVulkanContext::vkfn
FFVulkanFunctions vkfn
Definition: vulkan.h:232
FFVkExecPool
Definition: vulkan.h:211
pos
unsigned int pos
Definition: spdifenc.c:414
random_seed.h
FFVkSPIRVShader
Definition: vulkan.h:75
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
AVFilterContext
An instance of a filter.
Definition: avfilter.h:407
avgblur_vulkan_filter_frame
static int avgblur_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
Definition: vf_avgblur_vulkan.c:166
desc
const char * desc
Definition: libsvtav1.c:79
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:44
ff_vk_filter_config_input
int ff_vk_filter_config_input(AVFilterLink *inlink)
Definition: vulkan_filter.c:177
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
FFVulkanContext::hwctx
AVVulkanDeviceContext * hwctx
Definition: vulkan.h:255
AVVulkanDeviceContext::act_dev
VkDevice act_dev
Active device.
Definition: hwcontext_vulkan.h:84
ff_vk_init_sampler
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
Definition: vulkan.c:1147
ff_vk_exec_pipeline_register
int ff_vk_exec_pipeline_register(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanPipeline *pl)
Register a pipeline with an exec pool.
Definition: vulkan.c:1563
int32_t
int32_t
Definition: audioconvert.c:56
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_vk_shader_free
void ff_vk_shader_free(FFVulkanContext *s, FFVkSPIRVShader *shd)
Definition: vulkan.c:1390
AvgBlurVulkanContext::shd
FFVkSPIRVShader shd
Definition: vf_avgblur_vulkan.c:37
FILTER_SINGLE_PIXFMT
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
Definition: filters.h:248
RET
#define RET(x)
Definition: vulkan.h:67
FFVulkanFunctions
Definition: vulkan_functions.h:249