25 #define CGROUPS (int [3]){ 32, 32, 1 } 51 C(1,
if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
52 (pos.x < (o_offset[i].x + o_size[i].x)) &&
53 (pos.y < (o_offset[i].y + o_size[i].y))) { )
54 C(2, vec4 res = texture(overlay_img[i], pos - o_offset[i]); )
55 C(2, imageStore(output_img[i], pos, res); )
57 C(2, vec4 res = texture(main_img[i], pos); )
58 C(2, imageStore(output_img[i], pos, res); )
64 C(0,
void overlay_alpha_opaque(
int i, ivec2
pos) )
66 C(1, vec4 res = texture(main_img[i], pos); )
67 C(1,
if ((o_offset[i].x <= pos.x) && (o_offset[i].y <= pos.y) &&
68 (pos.x < (o_offset[i].x + o_size[i].x)) &&
69 (pos.y < (o_offset[i].y + o_size[i].y))) { )
70 C(2, vec4 ovr = texture(overlay_img[i], pos - o_offset[i]); )
71 C(2, res = ovr * ovr.a + res * (1.0f - ovr.a); )
73 C(2, imageStore(output_img[i], pos, res); )
75 C(1, imageStore(output_img[i], pos, res); )
102 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
105 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
110 .name =
"overlay_img",
111 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
114 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
119 .name =
"output_img",
120 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
122 .mem_quali =
"writeonly",
125 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
132 .type = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
133 .mem_quali =
"readonly",
134 .mem_layout =
"std430",
135 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
137 .buf_content =
"ivec2 o_offset[3], o_size[3];",
141 VK_SHADER_STAGE_COMPUTE_BIT);
154 GLSLC(1, ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
158 GLSLC(2, overlay_alpha_opaque(
i,
pos); );
183 VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
184 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT);
233 VkCommandBuffer cmd_buf;
264 s->
main_images[
i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
265 s->
overlay_images[
i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
272 VkImageMemoryBarrier bar[3] = {
274 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
276 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
277 .oldLayout =
main->layout[
i],
279 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
280 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
281 .image =
main->img[
i],
282 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
283 .subresourceRange.levelCount = 1,
284 .subresourceRange.layerCount = 1,
287 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
289 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
290 .oldLayout = overlay->
layout[
i],
292 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
293 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
294 .image = overlay->
img[
i],
295 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
296 .subresourceRange.levelCount = 1,
297 .subresourceRange.layerCount = 1,
300 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
302 .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
305 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
306 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
307 .image = out->
img[
i],
308 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
309 .subresourceRange.levelCount = 1,
310 .subresourceRange.layerCount = 1,
314 vkCmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
315 VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0,
318 main->layout[
i] = bar[0].newLayout;
319 main->access[
i] = bar[0].dstAccessMask;
321 overlay->
layout[
i] = bar[1].newLayout;
322 overlay->
access[
i] = bar[1].dstAccessMask;
324 out->
layout[
i] = bar[2].newLayout;
325 out->
access[
i] = bar[2].dstAccessMask;
330 vkCmdDispatch(cmd_buf,
364 if (!input_main || !input_overlay)
370 if (main_fc->
sw_format != overlay_fc->sw_format) {
445 #define OFFSET(x) offsetof(OverlayVulkanContext, x) 446 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM) 479 .
name =
"overlay_vulkan",
486 .
inputs = overlay_vulkan_inputs,
487 .
outputs = overlay_vulkan_outputs,
488 .priv_class = &overlay_vulkan_class,
static int overlay_vulkan_config_output(AVFilterLink *outlink)
int ff_vk_add_exec_dep(AVFilterContext *avctx, FFVkExecContext *e, AVFrame *frame, VkPipelineStageFlagBits in_wait_dst_flag)
Adds a frame as a queue dependency.
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
int ff_vk_init_pipeline_layout(AVFilterContext *avctx, VulkanPipeline *pl)
Initializes the pipeline layout after all shaders and descriptor sets have been finished.
static const AVFilterPad overlay_vulkan_outputs[]
int ff_vk_add_descriptor_set(AVFilterContext *avctx, VulkanPipeline *pl, SPIRVShader *shd, VulkanDescriptorSetBinding *desc, int num, int only_print_to_shader)
Adds a descriptor set to the shader and registers them in the pipeline.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
void ff_vk_filter_uninit(AVFilterContext *avctx)
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Gets the glsl format string for a pixel format.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
static av_cold int init(AVCodecContext *avctx)
int ff_vk_init_compute_pipeline(AVFilterContext *avctx, VulkanPipeline *pl)
Initializes a compute pipeline.
int h
agreed upon image height
int ff_vk_create_imageview(AVFilterContext *avctx, FFVkExecContext *e, VkImageView *v, VkImage img, VkFormat fmt, const VkComponentMapping map)
Create an imageview.
int ff_vk_filter_config_output(AVFilterLink *outlink)
int ff_vk_start_exec_recording(AVFilterContext *avctx, FFVkExecContext *e)
Begin recording to the command buffer.
VkDescriptorImageInfo output_images[3]
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
#define FF_ARRAY_ELEMS(a)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
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.
static const struct @322 planes[]
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
VkImage img[AV_NUM_DATA_POINTERS]
Vulkan images to which the memory is bound to.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
const char * name
Pad name.
AVFilterContext * parent
Parent filter context.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
#define AV_PIX_FMT_FLAG_ALPHA
The pixel format has an alpha channel.
static av_cold int uninit(AVCodecContext *avctx)
int ff_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
filter_frame For filters that do not use the activate() callback
void ff_vk_set_compute_shader_sizes(AVFilterContext *avctx, SPIRVShader *shd, int local_size[3])
Writes the workgroup size for a shader.
static int overlay_vulkan_blend(FFFrameSync *fs)
int queue_family_comp_index
Queue family index for compute ops, and the amount of queues enabled.
int ff_vk_filter_init(AVFilterContext *avctx)
static const AVOption overlay_vulkan_options[]
VulkanFilterContext vkctx
static int process_frames(AVFilterContext *avctx, AVFrame *out_f, AVFrame *main_f, AVFrame *overlay_f)
A filter pad used for either input or output.
int ff_vk_unmap_buffers(AVFilterContext *avctx, FFVkBuffer *buf, int nb_buffers, int flush)
Unmaps the buffer from userspace.
A link between two filters.
int ff_vk_filter_query_formats(AVFilterContext *avctx)
General lavfi IO functions.
enum AVPixelFormat input_format
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
Create a VkBuffer with the specified parameters.
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
int(* on_event)(struct FFFrameSync *fs)
Callback called when a frame event is ready.
int w
agreed upon image width
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
static av_cold int overlay_vulkan_init(AVFilterContext *avctx)
VkSampler * ff_vk_init_sampler(AVFilterContext *avctx, int unnorm_coords, VkFilter filt)
Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit()
int ff_vk_create_exec_ctx(AVFilterContext *avctx, FFVkExecContext **ctx)
Init an execution context for command recording and queue submission.
static const AVFilterPad overlay_vulkan_inputs[]
static av_cold int init_filter(AVFilterContext *ctx)
VkAccessFlagBits access[AV_NUM_DATA_POINTERS]
Updated after every barrier.
int ff_vk_submit_exec_queue(AVFilterContext *avctx, FFVkExecContext *e)
Submits a command buffer to the queue for execution.
void ff_vk_free_buf(AVFilterContext *avctx, FFVkBuffer *buf)
Frees a buffer.
VkDescriptorBufferInfo params_desc
AVFilterContext * src
source filter
int main(int argc, char *argv[])
void ff_vk_bind_pipeline_exec(AVFilterContext *avctx, FFVkExecContext *e, VulkanPipeline *pl)
Add a command to bind the completed pipeline and its descriptor sets.
static const AVFilterPad outputs[]
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
VkDescriptorImageInfo overlay_images[3]
const VkComponentMapping ff_comp_identity_map
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
int ff_vk_compile_shader(AVFilterContext *avctx, SPIRVShader *shd, const char *entrypoint)
Compiles the shader, entrypoint must be set to "main".
uint8_t * data
The data buffer.
SPIRVShader * ff_vk_init_shader(AVFilterContext *avctx, VulkanPipeline *pl, const char *name, VkShaderStageFlags stage)
Inits a shader for a specific pipeline.
AVVulkanDeviceContext * hwctx
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
This struct describes a set or pool of "hardware" frames (i.e.
VulkanPipeline * ff_vk_create_pipeline(AVFilterContext *avctx)
Inits a pipeline.
const char * name
Filter name.
VkCommandBuffer ff_vk_get_exec_buf(AVFilterContext *avctx, FFVkExecContext *e)
Gets the command buffer to use for this submission from the exe context.
#define GET_QUEUE_COUNT(hwctx, graph, comp, tx)
AVFilterLink ** outputs
array of pointers to output links
void ff_vk_discard_exec_deps(AVFilterContext *avctx, FFVkExecContext *e)
Discards all queue dependencies.
static void overlay_vulkan_uninit(AVFilterContext *avctx)
AVFilter ff_vf_overlay_vulkan
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static int query_formats(AVFilterContext *ctx)
static const char overlay_alpha[]
AVFILTER_DEFINE_CLASS(overlay_vulkan)
enum AVPixelFormat output_format
int ff_vk_map_buffers(AVFilterContext *avctx, FFVkBuffer *buf, uint8_t *mem[], int nb_buffers, int invalidate)
Maps the buffer to userspace.
VkDescriptorImageInfo main_images[3]
int ff_vk_filter_config_input(AVFilterLink *inlink)
VkImageLayout layout[AV_NUM_DATA_POINTERS]
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
#define DUP_SAMPLER_ARRAY4(x)
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
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
#define AVERROR_EXTERNAL
Generic error in an external library.
static const char overlay_noalpha[]
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static int overlay_vulkan_activate(AVFilterContext *avctx)
void ff_vk_update_descriptor_set(AVFilterContext *avctx, VulkanPipeline *pl, int set_id)
Updates a descriptor set via the updaters defined.