Go to the documentation of this file.
79 C(1, vec2 npos = (vec2(
pos) + 0.5
f) / imageSize(output_img[idx]); )
80 C(1, npos *= crop_range; )
81 C(1, npos += crop_off; )
82 C(1,
return texture(input_img[idx], npos); )
89 C(1,
src *= yuv_matrix; )
90 C(1,
if (fullrange == 1) { )
91 C(2,
src += vec4(0.0, 0.5, 0.5, 0.0); )
93 C(2,
src *= vec4(219.0 / 255.0, 224.0 / 255.0, 224.0 / 255.0, 1.0); )
94 C(2,
src += vec4(16.0 / 255.0, 128.0 / 255.0, 128.0 / 255.0, 0.0); )
103 C(1, imageStore(output_img[0],
pos, vec4(
src.r, 0.0, 0.0, 0.0)); )
104 C(1,
pos /= ivec2(2); )
105 C(1, imageStore(output_img[1],
pos, vec4(
src.g,
src.b, 0.0, 0.0)); )
112 C(1, imageStore(output_img[0],
pos, vec4(
src.r, 0.0, 0.0, 0.0)); )
113 C(1,
pos /= ivec2(2); )
114 C(1, imageStore(output_img[1],
pos, vec4(
src.g, 0.0, 0.0, 0.0)); )
115 C(1, imageStore(output_img[2],
pos, vec4(
src.b, 0.0, 0.0, 0.0)); )
122 C(1, imageStore(output_img[0],
pos, vec4(
src.r, 0.0, 0.0, 0.0)); )
123 C(1, imageStore(output_img[1],
pos, vec4(
src.g, 0.0, 0.0, 0.0)); )
124 C(1, imageStore(output_img[2],
pos, vec4(
src.b, 0.0, 0.0, 0.0)); )
134 if (
s->vkctx.output_format !=
s->vkctx.input_format) {
138 switch (
s->vkctx.output_format) {
148 GLSLC(1, ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
150 GLSLC(1, vec2 c_r = vec2(crop_w, crop_h) / in_d; );
151 GLSLC(1, vec2 c_o = vec2(crop_x, crop_y) / in_d; );
154 if (
s->vkctx.output_format ==
s->vkctx.input_format) {
155 for (
int i = 0;
i <
desc[1].elems;
i++) {
162 GLSLF(2, imageStore(output_img[%
i],
pos, res); ,
i);
170 switch (
s->vkctx.output_format) {
174 default:
return AVERROR(EINVAL);
180 if (
s->vkctx.output_format !=
s->vkctx.input_format) {
182 double tmp_mat[3][3];
192 for (
int y = 0; y < 3; y++)
193 for (
int x = 0; x < 3; x++)
194 s->opts.yuv_matrix[x][y] = tmp_mat[x][y];
195 s->opts.yuv_matrix[3][3] = 1.0;
206 void *spv_opaque =
NULL;
207 VkFilter sampler_mode;
218 sampler_mode = VK_FILTER_NEAREST;
221 sampler_mode = VK_FILTER_LINEAR;
225 spv = ff_vk_spirv_init();
236 VK_SHADER_STAGE_COMPUTE_BIT,
244 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
246 .mem_quali =
"readonly",
249 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
253 .name =
"output_img",
254 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
256 .mem_quali =
"writeonly",
259 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
265 GLSLC(0,
layout(push_constant, std430) uniform pushConstants { );
266 GLSLC(1, mat4 yuv_matrix; );
267 GLSLC(1,
int crop_x; );
268 GLSLC(1,
int crop_y; );
269 GLSLC(1,
int crop_w; );
270 GLSLC(1,
int crop_h; );
275 VK_SHADER_STAGE_COMPUTE_BIT);
310 (uint32_t []) { 32, 32, 1 }, 0);
313 VK_SHADER_STAGE_COMPUTE_BIT);
318 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
319 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
323 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
324 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
372 out->color_range =
s->out_range;
373 if (
s->vkctx.output_format !=
s->vkctx.input_format)
377 if (!
s->initialized) {
392 s->sampler, &
s->opts,
sizeof(
s->opts)));
429 if (
s->out_format_string) {
436 s->vkctx.output_format =
s->vkctx.input_format;
440 if (
s->vkctx.output_format ==
s->vkctx.input_format) {
455 }
else if (
s->vkctx.output_format !=
s->vkctx.input_format) {
493 #define OFFSET(x) offsetof(ScaleVulkanContext, x)
494 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
535 .
p.
name =
"scale_vulkan",
537 .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.
static av_cold int init_debayer(AVFilterContext *ctx, AVFrame *in)
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
const unsigned char ff_debayer_comp_spv_data[]
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...
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)
#define SPEC_LIST_ADD(name, idx, val_bits, val)
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 av_opt_set(void *obj, const char *name, const char *val, int search_flags)
@ 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
static AVFormatContext * ctx
@ 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
#define AV_PIX_FMT_RGBA64
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
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)
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, const char *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
#define SPEC_LIST_CREATE(name, max_length, max_size)
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.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
#define i(width, name, range_min, range_max)
#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])
int w
agreed upon image width
static const char scale_bilinear[]
static const char write_444[]
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.
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
int h
agreed upon image height
struct ScaleVulkanContext::@421 opts
@ 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.
@ SCALE_FORCE_OAR_DISABLE
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
static int scale_vulkan_config_output(AVFilterLink *outlink)
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image dimensions or settings change in any way sws_scale_frame() is itself just a light-weight wrapper that runs ff_sws_graph_create() whenever the format changes
@ 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...
#define AV_PIX_FMT_BAYER_RGGB16
AVColorRange
Visual content value range.
Main external API structure.
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
#define FILTER_SINGLE_PIXFMT(pix_fmt_)
int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by, double w_adj)
Transform evaluated width and height obtained from ff_scale_eval_dimensions into actual target width ...
int ff_vk_shader_load(FFVulkanShader *shd, VkPipelineStageFlags stage, VkSpecializationInfo *spec, uint32_t wg_size[3], uint32_t required_subgroup_size)
Initialize a shader object.
static int init_scale_shader(AVFilterContext *ctx, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, AVFrame *in)
const unsigned int ff_debayer_comp_spv_len