Go to the documentation of this file.
59 #define DEFINE_BLEND_MODE(MODE, EXPR) \
60 static const char blend_##MODE[] = "blend_"#MODE; \
61 static const char blend_##MODE##_func[] = { \
62 C(0, vec4 blend_##MODE(vec4 top, vec4 bottom, float opacity) { ) \
63 C(1, vec4 dst = EXPR; ) \
71 #define FN(EXPR) A + ((EXPR) - A) * opacity
78 #define CASE(MODE) case BLEND_##MODE: \
79 param->blend = blend_##MODE;\
80 param->blend_func = blend_##MODE##_func; \
83 switch (param->mode) {
86 default: param->blend =
NULL;
break;
100 param->
mode =
s->all_mode;
101 if (
s->all_opacity < 1)
107 "Currently the blend mode specified is not supported yet.\n");
116 char *res,
int res_len,
int flags)
147 .
name =
"top_images",
148 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
151 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
152 .updater =
s->top_images,
156 .name =
"bottom_images",
157 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
160 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
161 .updater =
s->bottom_images,
165 .name =
"output_images",
166 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
168 .mem_quali =
"writeonly",
171 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
172 .updater =
s->output_images,
183 for (
int i = 0, j = 0;
i <
planes;
i++) {
184 for (j = 0; j <
i; j++)
185 if (
s->params[
i].blend_func ==
s->params[j].blend_func)
189 GLSLD(
s->params[
i].blend_func);
196 GLSLC(1,
const ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
201 GLSLF(2,
const vec4 top = texture(top_images[%
i],
pos); ,
i);
202 GLSLF(2,
const vec4 bottom = texture(bottom_images[%
i],
pos); ,
i);
203 GLSLF(2,
const float opacity = %
f; ,
s->params[
i].opacity);
204 GLSLF(2, vec4 dst = %
s(top, bottom, opacity); ,
s->params[
i].blend);
206 GLSLF(2, imageStore(output_images[%
i],
pos, dst); ,
i);
227 VkCommandBuffer cmd_buf;
249 &
s->top_images[
i].imageView, top->img[
i],
254 &
s->bottom_images[
i].imageView, bottom->
img[
i],
259 &
s->output_images[
i].imageView,
out->img[
i],
263 s->top_images[
i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
264 s->bottom_images[
i].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
265 s->output_images[
i].imageLayout = VK_IMAGE_LAYOUT_GENERAL;
271 VkImageMemoryBarrier barriers[] = {
273 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
275 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
276 .oldLayout = top->layout[
i],
277 .newLayout =
s->top_images[
i].imageLayout,
278 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
279 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
280 .image = top->img[
i],
281 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
282 .subresourceRange.levelCount = 1,
283 .subresourceRange.layerCount = 1,
286 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
288 .dstAccessMask = VK_ACCESS_SHADER_READ_BIT,
289 .oldLayout = bottom->
layout[
i],
290 .newLayout =
s->bottom_images[
i].imageLayout,
291 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
292 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
293 .image = bottom->
img[
i],
294 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
295 .subresourceRange.levelCount = 1,
296 .subresourceRange.layerCount = 1,
299 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
301 .dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
302 .oldLayout =
out->layout[
i],
303 .newLayout =
s->output_images[
i].imageLayout,
304 .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
305 .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
306 .image =
out->img[
i],
307 .subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
308 .subresourceRange.levelCount = 1,
309 .subresourceRange.layerCount = 1,
313 vk->CmdPipelineBarrier(cmd_buf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
314 VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, 0,
317 top->layout[
i] = barriers[0].newLayout;
318 top->access[
i] = barriers[0].dstAccessMask;
320 bottom->
layout[
i] = barriers[1].newLayout;
321 bottom->
access[
i] = barriers[1].dstAccessMask;
323 out->layout[
i] = barriers[2].newLayout;
324 out->access[
i] = barriers[2].dstAccessMask;
328 vk->CmdDispatch(cmd_buf,
FFALIGN(
s->vkctx.output_width,
CGS) /
CGS,
367 if (!
s->initialized) {
370 if (top_fc->
sw_format != bottom_fc->sw_format) {
372 "Currently the sw format of the bottom video need to match the top!\n");
415 if (toplink->
w != bottomlink->
w || toplink->
h != bottomlink->
h) {
417 "(size %dx%d) do not match the corresponding "
418 "second input link %s parameters (size %dx%d)\n",
446 #define OFFSET(x) offsetof(BlendVulkanContext, x)
447 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
492 .
name =
"blend_vulkan",
501 .priv_class = &blend_vulkan_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
int ff_framesync_configure(FFFrameSync *fs)
Configure a frame sync structure.
static const struct @346 planes[]
const AVFilter ff_vf_blend_vulkan
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
void ff_framesync_uninit(FFFrameSync *fs)
Free all memory currently allocated.
#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_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
uint8_t * data
The data buffer.
int ff_framesync_get_frame(FFFrameSync *fs, unsigned in, AVFrame **rframe, unsigned get)
Get the current frame in an input.
static int config_props_output(AVFilterLink *outlink)
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.
VkShaderStageFlags stages
static void init_blend_func(FilterParamsVulkan *param)
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".
void ff_vk_uninit(FFVulkanContext *s)
Frees the main Vulkan context.
const char * name
Filter name.
A link between two filters.
#define MULTIPLY(var, const)
@ 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 av_cold int init(AVFilterContext *avctx)
FilterParamsVulkan params[4]
static const AVFilterPad blend_vulkan_outputs[]
A filter pad used for either input or output.
AVFilterPad * input_pads
array of input pads
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 AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#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.
static const AVFilterPad blend_vulkan_inputs[]
AVRational sample_aspect_ratio
agreed upon sample aspect ratio
AVRational frame_rate
Frame rate of the stream on the link, or 1/0 if unknown or variable; if left to 0/0,...
FFVkSPIRVShader * ff_vk_init_shader(FFVulkanPipeline *pl, const char *name, VkShaderStageFlags stage)
Inits a shader for a specific pipeline.
VkDescriptorImageInfo bottom_images[3]
static int activate(AVFilterContext *avctx)
static av_cold int init_filter(AVFilterContext *avctx)
#define FILTER_INPUTS(array)
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.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define fs(width, name, subs,...)
AVFilterLink ** inputs
array of pointers to input links
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.
static int config_params(AVFilterContext *avctx)
static const AVOption blend_vulkan_options[]
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_framesync_init_dualinput(FFFrameSync *fs, AVFilterContext *parent)
Initialize a frame sync structure for dualinput.
static int blend_frame(FFFrameSync *fs)
int ff_vk_init_pipeline_layout(FFVulkanContext *s, FFVulkanPipeline *pl)
Initializes the pipeline layout after all shaders and descriptor sets have been finished.
AVFilterContext * src
source filter
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
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.
This struct describes a set or pool of "hardware" frames (i.e.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
VkDescriptorImageInfo top_images[3]
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.
static av_cold void uninit(AVFilterContext *avctx)
int h
agreed upon image height
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link.
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()
#define DEFINE_BLEND_MODE(MODE, EXPR)
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.
#define flags(name, subs,...)
AVFILTER_DEFINE_CLASS(blend_vulkan)
int ff_framesync_activate(FFFrameSync *fs)
Examine the frames in the filter's input and try to produce output.
static int process_frames(AVFilterContext *avctx, AVFrame *out_frame, AVFrame *top_frame, AVFrame *bottom_frame)
AVFilterLink ** outputs
array of pointers to output links