Go to the documentation of this file.
46 C(0, shared vec4 cache[DIR(gl_WorkGroupSize) + FILTER_RADIUS*2 + 1]; )
48 C(0,
void distort(
const ivec2
pos,
const int idx) )
50 C(1,
const uint cp = DIR(gl_LocalInvocationID) + FILTER_RADIUS; )
52 C(1, cache[cp] = texture(input_img[idx],
pos); )
54 C(1,
const ivec2 loc_l =
pos - INC(FILTER_RADIUS); )
55 C(1, cache[cp - FILTER_RADIUS] = texture(input_img[idx], loc_l); )
57 C(1,
const ivec2 loc_h =
pos + INC(DIR(gl_WorkGroupSize)); )
58 C(1, cache[cp + DIR(gl_WorkGroupSize)] = texture(input_img[idx], loc_h); )
62 C(1, vec4 sum = vec4(0); )
63 C(1,
for (
int p = -FILTER_RADIUS; p <= FILTER_RADIUS; p++) )
64 C(2, sum += cache[cp + p]; )
66 C(1, sum /= vec4(FILTER_RADIUS*2 + 1); )
67 C(1, imageStore(output_img[idx],
pos, sum); )
82 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
85 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
89 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
91 .mem_quali =
"writeonly",
94 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
101 if (!desc_i[0].sampler)
105 desc_i[0].
updater =
s->input_images;
113 VK_SHADER_STAGE_COMPUTE_BIT);
121 GLSLF(0, #define FILTER_RADIUS (%
i) ,
s->size_x - 1);
122 GLSLC(0, #define INC(x) (ivec2(x, 0)) );
123 GLSLC(0, #define DIR(var) (var.x) );
128 GLSLC(1,
const ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
133 if (
s->planes & (1 <<
i)) {
136 GLSLF(2, vec4 res = texture(input_img[%
i],
pos); ,
i);
137 GLSLF(2, imageStore(output_img[%
i],
pos, res); ,
i);
151 desc_i[1].
updater =
s->output_images;
158 VK_SHADER_STAGE_COMPUTE_BIT);
166 GLSLF(0, #define FILTER_RADIUS (%
i) ,
s->size_y - 1);
167 GLSLC(0, #define INC(x) (ivec2(0, x)) );
168 GLSLC(0, #define DIR(var) (var.y) );
173 GLSLC(1,
const ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
178 if (
s->planes & (1 <<
i)) {
181 GLSLF(2, vec4 res = texture(input_img[%
i],
pos); ,
i);
182 GLSLF(2, imageStore(output_img[%
i],
pos, res); ,
i);
208 VkCommandBuffer cmd_buf;
227 &
s->input_images[
i].imageView, in->
img[
i],
232 &
s->tmp_images[
i].imageView,
tmp->img[
i],
237 &
s->output_images[
i].imageView,
out->img[
i],
241 s->input_images[
i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
242 s->tmp_images[
i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
243 s->output_images[
i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
250 VkImageMemoryBarrier bar[] = {
252 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
254 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
256 .newLayout =
s->input_images[
i].imageLayout,
257 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
258 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
260 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
261 .subresourceRange.levelCount = 1,
262 .subresourceRange.layerCount = 1,
265 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
267 .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_SHADER_READ_BIT,
268 .oldLayout =
tmp->layout[
i],
269 .newLayout =
s->tmp_images[
i].imageLayout,
270 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
271 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
272 .image =
tmp->img[
i],
273 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
274 .subresourceRange.levelCount = 1,
275 .subresourceRange.layerCount = 1,
278 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
280 .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
281 .oldLayout =
out->layout[
i],
282 .newLayout =
s->output_images[
i].imageLayout,
283 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
284 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
285 .image =
out->img[
i],
286 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
287 .subresourceRange.levelCount = 1,
288 .subresourceRange.layerCount = 1,
292 vk->CmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
293 VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0,
296 in->
layout[
i] = bar[0].newLayout;
297 in->
access[
i] = bar[0].dstAccessMask;
299 tmp->layout[
i] = bar[1].newLayout;
300 tmp->access[
i] = bar[1].dstAccessMask;
302 out->layout[
i] = bar[2].newLayout;
303 out->access[
i] = bar[2].dstAccessMask;
309 s->vkctx.output_height, 1);
313 vk->CmdDispatch(cmd_buf,
s->vkctx.output_width,
382 #define OFFSET(x) offsetof(AvgBlurVulkanContext, x)
383 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
411 .
name =
"avgblur_vulkan",
419 .priv_class = &avgblur_vulkan_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static const struct @346 planes[]
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
const VkComponentMapping ff_comp_identity_map
static const AVFilterPad avgblur_vulkan_outputs[]
FFVulkanPipeline * pl_ver
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
static const AVFilterPad avgblur_vulkan_inputs[]
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
void ff_vk_bind_pipeline_exec(FFVulkanContext *s, FFVkExecContext *e, FFVulkanPipeline *pl)
Add a command to bind the completed pipeline and its descriptor sets.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
int ff_vk_compile_shader(FFVulkanContext *s, FFVkSPIRVShader *shd, const char *entrypoint)
Compiles the shader, entrypoint must be set to "main".
const AVFilter ff_vf_avgblur_vulkan
void ff_vk_uninit(FFVulkanContext *s)
Frees the main Vulkan context.
const char * name
Filter name.
static void avgblur_vulkan_uninit(AVFilterContext *avctx)
static const char blur_kernel[]
A link between two filters.
AVFILTER_DEFINE_CLASS(avgblur_vulkan)
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int ff_vk_add_exec_dep(FFVulkanContext *s, FFVkExecContext *e, AVFrame *frame, VkPipelineStageFlagBits in_wait_dst_flag)
Adds a frame as a queue dependency.
VkCommandBuffer ff_vk_get_exec_buf(FFVkExecContext *e)
Gets the command buffer to use for this submission from the exe context.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
void * priv
private data for use by the filter
static const AVOption avgblur_vulkan_options[]
A filter pad used for either input or output.
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
void ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family, int nb_queues)
Initialize a queue family with a specific number of queues.
#define FF_ARRAY_ELEMS(a)
int ff_vk_create_imageview(FFVulkanContext *s, FFVkExecContext *e, VkImageView *v, VkImage img, VkFormat fmt, const VkComponentMapping map)
Create an imageview.
VkDescriptorImageInfo input_images[3]
int(* init)(AVBSFContext *ctx)
FFVkSPIRVShader * ff_vk_init_shader(FFVulkanPipeline *pl, const char *name, VkShaderStageFlags stage)
Inits a shader for a specific pipeline.
static int process_frames(AVFilterContext *avctx, AVFrame *out_f, AVFrame *tmp_f, AVFrame *in_f)
#define FILTER_INPUTS(array)
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
void ff_vk_update_descriptor_set(FFVulkanContext *s, FFVulkanPipeline *pl, int set_id)
Updates a descriptor set via the updaters defined.
int ff_vk_start_exec_recording(FFVulkanContext *s, FFVkExecContext *e)
Begin recording to the command buffer.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
VkDescriptorImageInfo output_images[3]
int ff_vk_create_exec_ctx(FFVulkanContext *s, FFVkExecContext **ctx, FFVkQueueFamilyCtx *qf)
Init an execution context for command recording and queue submission.
int ff_vk_filter_config_output(AVFilterLink *outlink)
void ff_vk_qf_rotate(FFVkQueueFamilyCtx *qf)
Rotate through the queues in a queue family.
void ff_vk_discard_exec_deps(FFVkExecContext *e)
Discards all queue dependencies.
int main(int argc, char **argv)
VkAccessFlagBits access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int ff_vk_init_pipeline_layout(FFVulkanContext *s, FFVulkanPipeline *pl)
Initializes the pipeline layout after all shaders and descriptor sets have been finished.
VkDescriptorImageInfo tmp_images[3]
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
int ff_vk_submit_exec_queue(FFVulkanContext *s, FFVkExecContext *e)
Submits a command buffer to the queue for execution.
#define AVERROR_EXTERNAL
Generic error in an external library.
const VkFormat * av_vkfmt_from_pixfmt(enum AVPixelFormat p)
Returns the format of each image up to the number of planes for a given sw_format.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl)
Initializes a compute pipeline.
#define i(width, name, range_min, range_max)
int w
agreed upon image width
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Gets the glsl format string for a pixel format.
const char * name
Pad name.
FFVulkanPipeline * ff_vk_create_pipeline(FFVulkanContext *s, FFVkQueueFamilyCtx *qf)
Inits a pipeline.
int ff_vk_add_descriptor_set(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int num, int only_print_to_shader)
Adds a descriptor set to the shader and registers them in the pipeline.
int h
agreed upon image height
FFVkSampler * ff_vk_init_sampler(FFVulkanContext *s, int unnorm_coords, VkFilter filt)
Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit()
static int avgblur_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
int ff_vk_filter_config_input(AVFilterLink *inlink)
VkImageLayout layout[AV_NUM_DATA_POINTERS]
#define FILTER_OUTPUTS(array)
void ff_vk_set_compute_shader_sizes(FFVkSPIRVShader *shd, int local_size[3])
Writes the workgroup size for a shader.
static av_cold int uninit(AVCodecContext *avctx)
FFVulkanPipeline * pl_hor