Go to the documentation of this file.
66 C(1, vec2 npos = (vec2(
pos) + 0.5
f) / imageSize(output_img[idx]); )
67 C(1, npos *= crop_range; )
68 C(1, npos += crop_off; )
69 C(1,
return texture(input_img[idx], npos); )
76 C(1,
src *= yuv_matrix; )
77 C(1,
if (fullrange == 1) { )
78 C(2,
src += vec4(0.0, 0.5, 0.5, 0.0); )
80 C(2,
src *= vec4(219.0 / 255.0, 224.0 / 255.0, 224.0 / 255.0, 1.0); )
81 C(2,
src += vec4(16.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 0.0); )
90 C(1, imageStore(output_img[0],
pos, vec4(
src.r, 0.0, 0.0, 0.0)); )
91 C(1,
pos /= ivec2(2); )
92 C(1, imageStore(output_img[1],
pos, vec4(
src.g,
src.b, 0.0, 0.0)); )
99 C(1, imageStore(output_img[0],
pos, vec4(
src.r, 0.0, 0.0, 0.0)); )
100 C(1,
pos /= ivec2(2); )
101 C(1, imageStore(output_img[1],
pos, vec4(
src.g, 0.0, 0.0, 0.0)); )
102 C(1, imageStore(output_img[2],
pos, vec4(
src.b, 0.0, 0.0, 0.0)); )
109 C(1, imageStore(output_img[0],
pos, vec4(
src.r, 0.0, 0.0, 0.0)); )
110 C(1, imageStore(output_img[1],
pos, vec4(
src.g, 0.0, 0.0, 0.0)); )
111 C(1, imageStore(output_img[2],
pos, vec4(
src.b, 0.0, 0.0, 0.0)); )
120 void *spv_opaque =
NULL;
121 VkFilter sampler_mode;
132 sampler_mode = VK_FILTER_NEAREST;
135 sampler_mode = VK_FILTER_LINEAR;
139 spv = ff_vk_spirv_init();
155 VK_SHADER_STAGE_COMPUTE_BIT,
160 GLSLC(0,
layout(push_constant, std430) uniform pushConstants { );
161 GLSLC(1, mat4 yuv_matrix; );
162 GLSLC(1,
int crop_x; );
163 GLSLC(1,
int crop_y; );
164 GLSLC(1,
int crop_w; );
165 GLSLC(1,
int crop_h; );
170 VK_SHADER_STAGE_COMPUTE_BIT);
175 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
178 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
182 .name =
"output_img",
183 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
185 .mem_quali =
"writeonly",
188 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
196 if (
s->vkctx.output_format !=
s->vkctx.input_format) {
200 switch (
s->vkctx.output_format) {
210 GLSLC(1, ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
212 GLSLC(1, vec2 c_r = vec2(crop_w, crop_h) / in_d; );
213 GLSLC(1, vec2 c_o = vec2(crop_x, crop_y) / in_d; );
216 if (
s->vkctx.output_format ==
s->vkctx.input_format) {
217 for (
int i = 0;
i <
desc[1].elems;
i++) {
224 GLSLF(2, imageStore(output_img[%
i],
pos, res); ,
i);
232 switch (
s->vkctx.output_format) {
236 default:
return AVERROR(EINVAL);
242 if (
s->vkctx.output_format !=
s->vkctx.input_format) {
244 double tmp_mat[3][3];
254 for (
int y = 0; y < 3; y++)
255 for (
int x = 0; x < 3; x++)
256 s->opts.yuv_matrix[x][y] = tmp_mat[x][y];
257 s->opts.yuv_matrix[3][3] = 1.0;
299 s->sampler, &
s->opts,
sizeof(
s->opts)));
311 out->color_range =
s->out_range;
312 if (
s->vkctx.output_format !=
s->vkctx.input_format)
344 if (
s->out_format_string) {
351 s->vkctx.output_format =
s->vkctx.input_format;
354 if (
s->vkctx.output_format !=
s->vkctx.input_format) {
391 #define OFFSET(x) offsetof(ScaleVulkanContext, x)
392 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
430 .
p.
name =
"scale_vulkan",
432 .p.priv_class = &scale_vulkan_class,
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
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
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
int ff_vk_shader_init(FFVulkanContext *s, FFVulkanShader *shd, const char *name, VkPipelineStageFlags stage, const char *extensions[], int nb_extensions, int lg_x, int lg_y, int lg_z, uint32_t required_subgroup_size)
Initialize a shader object, with a specific set of extensions, type+bind, local group size,...
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd, 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.
int ff_vk_exec_pool_init(FFVulkanContext *s, AVVulkanDeviceQueueFamily *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.
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
enum AVColorSpace colorspace
YUV colorspace type.
#define FILTER_INPUTS(array)
This structure describes decoded (raw) audio or video data.
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
@ AVCOL_RANGE_JPEG
Full range content.
static const AVFilterPad scale_vulkan_outputs[]
const struct AVLumaCoefficients * av_csp_luma_coeffs_from_avcsp(enum AVColorSpace csp)
Retrieves the Luma coefficients necessary to construct a conversion matrix from an enum constant desc...
struct ScaleVulkanContext::@355 opts
static const AVOption scale_vulkan_options[]
static const char rgb2yuv[]
static const char write_nv12[]
int ff_scale_eval_dimensions(void *log_ctx, const char *w_expr, const char *h_expr, AVFilterLink *inlink, AVFilterLink *outlink, int *ret_w, int *ret_h)
Parse and evaluate string expressions for width and height.
Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar calculations.
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
void(* uninit)(struct FFVkSPIRVCompiler **ctx)
const char * name
Filter name.
A link between two filters.
static const char write_420[]
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
AVFILTER_DEFINE_CLASS(scale_vulkan)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.
void * priv
private data for use by the filter
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
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
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int scale_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
const FFFilter ff_vf_scale_vulkan
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
#define FILTER_OUTPUTS(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
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
static void scale_vulkan_uninit(AVFilterContext *avctx)
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
AVFilterLink ** inputs
array of pointers to input links
int ff_vk_filter_config_output(AVFilterLink *outlink)
enum AVColorRange out_range
@ AVCOL_RANGE_UNSPECIFIED
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
AVVulkanDeviceQueueFamily * qf
int(* init)(AVBSFContext *ctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
AVFilterContext * src
source filter
int(* compile_shader)(FFVulkanContext *s, struct FFVkSPIRVCompiler *ctx, FFVulkanShader *shd, uint8_t **data, size_t *size, const char *entrypoint, void **opaque)
#define AVERROR_EXTERNAL
Generic error in an external library.
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
void av_frame_side_data_remove_by_props(AVFrameSideData ***sd, int *nb_sd, int props)
Remove and free all side data instances that match any of the given side data properties.
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
static void uninit(AVBSFContext *ctx)
void ff_fill_rgb2yuv_table(const AVLumaCoefficients *coeffs, double rgb2yuv[3][3])
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static const char scale_bilinear[]
static const char write_444[]
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, uint8_t *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
static const AVFilterPad scale_vulkan_inputs[]
const char * name
Pad name.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
void(* free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque)
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
int h
agreed upon image height
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
int ff_vk_filter_config_input(AVFilterLink *inlink)
AVFilter p
The public AVFilter.
AVVulkanDeviceContext * hwctx
VkDevice act_dev
Active device.
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
static int scale_vulkan_config_output(AVFilterLink *outlink)
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
@ AV_OPT_TYPE_STRING
Underlying C type is a uint8_t* that is either NULL or points to a C string allocated with the av_mal...
AVColorRange
Visual content value range.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)