92 VkFilter sampler_mode;
98 int chroma_planes = 0;
106 sampler_mode = VK_FILTER_NEAREST;
109 sampler_mode = VK_FILTER_LINEAR;
113 if (
s->vkctx.output_format ==
s->vkctx.input_format) {
118 switch (
s->vkctx.output_format) {
122 default:
return AVERROR(EINVAL);
139 (uint32_t []) { 32, 32, 1 }, 0);
144 .type = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
146 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
150 .name =
"output_img",
151 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
153 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
160 VK_SHADER_STAGE_COMPUTE_BIT);
164 double tmp_mat[3][3];
175 for (
int y = 0; y < 3; y++)
176 for (
int x = 0; x < 3; x++)
177 s->opts.yuv_matrix[x][y] = tmp_mat[x][y];
178 s->opts.yuv_matrix[3][3] = 1.0;
182 s->opts.in_dims[0] =
frames->width;
183 s->opts.in_dims[1] =
frames->height;
209 (uint32_t []) { 32, 32, 1 }, 0);
212 VK_SHADER_STAGE_COMPUTE_BIT);
217 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
218 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
222 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
223 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
251 offset[0] = x * ((1 <<
desc->log2_chroma_w) - 1) / 256.0f;
252 offset[1] = y * ((1 <<
desc->log2_chroma_h) - 1) / 256.0f;
285 out->color_range =
s->out_range;
288 else if (
s->vkctx.output_format !=
s->vkctx.input_format &&
293 if (!
s->initialized) {
314 s->sampler, 1, &
s->opts,
sizeof(
s->opts)));
353 if (
s->out_format_string) {
360 s->vkctx.output_format =
s->vkctx.input_format;
364 if (
s->vkctx.output_format ==
s->vkctx.input_format) {
370 if (inlink->
w != outlink->
w || inlink->
w != outlink->
w) {
374 }
else if ((inlink->
w == outlink->
w || inlink->
h == outlink->
h) &&
375 (
s->vkctx.input_format !=
s->vkctx.output_format)) {
381 s->scaler ==
F_NEAREST ?
"point" :
"bilinear", 0);
382 }
else if (
s->vkctx.output_format !=
s->vkctx.input_format) {
438#define OFFSET(x) offsetof(ScaleVulkanContext, x)
439#define FLAGS (AV_OPT_FLAG_FILTERING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
480 .p.name =
"scale_vulkan",
482 .p.priv_class = &scale_vulkan_class,
const FFFilter ff_vf_scale_vulkan
static AVFormatContext * ctx
static AVDictionary * opts
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
int(* init)(AVBSFContext *ctx)
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
@ AV_OPT_TYPE_INT
Underlying C type is int.
@ 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 AVFILTER_FLAG_HWDEVICE
The filter can create hardware frames using AVFilterContext.hw_device_ctx.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
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.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_SIDE_DATA_PROP_SIZE_DEPENDENT
Side data depends on the video dimensions.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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...
int sws_scale_frame(SwsContext *sws, AVFrame *dst, const AVFrame *src)
Scale source data from src and write the output to dst.
SwsContext * sws_alloc_context(void)
Allocate an empty SwsContext and set its fields to default values.
void sws_free_context(SwsContext **ctx)
Free the context and everything associated with it, and write NULL to the provided pointer.
int av_opt_set(void *obj, const char *name, const char *val, int search_flags)
static av_cold void uninit(AVBitStreamFilterContext *ctx)
void ff_fill_rgb2yuv_table(const AVLumaCoefficients *coeffs, double rgb2yuv[3][3])
#define FILTER_INPUTS(array)
#define FILTER_OUTPUTS(array)
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
#define AVFILTER_DEFINE_CLASS(fname)
#define FILTER_QUERY_FUNC2(func)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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.
void ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, const FFVulkanDescriptorSetBinding *desc, int nb, int singular)
Add descriptor to a shader.
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
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.
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
int av_chroma_location_enum_to_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
AVChromaLocation
Location of chroma samples.
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCHROMA_LOC_UNSPECIFIED
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
#define AV_PIX_FMT_RGBA64
#define AV_PIX_FMT_BAYER_RGGB16
@ 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...
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
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_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.
@ SCALE_FORCE_OAR_DISABLE
uint8_t * data
The data buffer.
int plane
Which of the 4 planes contains the component.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
enum AVChromaLocation chroma_location
Agreed upon chroma sample location, for video with subsampled chroma.
AVFilterContext * dst
dest filter
A filter pad used for either input or output.
This structure describes decoded (raw) audio or video data.
enum AVChromaLocation chroma_location
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
enum AVColorSpace colorspace
YUV colorspace type.
This struct describes a set or pool of "hardware" frames (i.e.
Struct containing luma coefficients to be used for RGB to YUV/YCoCg, or similar calculations.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
const VkAllocationCallbacks * alloc
Custom memory allocator, else NULL.
VkDevice act_dev
Active device.
AVVulkanDeviceContext * hwctx
enum AVColorRange out_range
AVVulkanDeviceQueueFamily * qf
Main external API structure.
static int scale_vulkan_query_formats(const AVFilterContext *avctx, AVFilterFormatsConfig **cfg_in, AVFilterFormatsConfig **cfg_out)
const unsigned int ff_debayer_comp_spv_len
static int scale_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
static const AVFilterPad scale_vulkan_outputs[]
static int scale_vulkan_config_output(AVFilterLink *outlink)
static const AVFilterPad scale_vulkan_inputs[]
const unsigned char ff_debayer_comp_spv_data[]
static av_cold int init_debayer(AVFilterContext *ctx, AVFrame *in)
const unsigned char ff_scale_comp_spv_data[]
const unsigned int ff_scale_comp_spv_len
static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in)
static void scale_vulkan_uninit(AVFilterContext *avctx)
static const AVOption scale_vulkan_options[]
static void chroma_loc_offset(float offset[2], enum AVChromaLocation loc, const AVPixFmtDescriptor *desc)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define FF_VK_DEFAULT_EXEC_CONTEXTS
#define SPEC_LIST_ADD(name, idx, val_bits, val)
#define SPEC_LIST_CREATE(name, max_length, max_size)
int ff_vk_filter_config_input(AVFilterLink *inlink)
int ff_vk_filter_config_output(AVFilterLink *outlink)
int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd, AVFrame *out_f, AVFrame *in_f, VkSampler sampler, uint32_t wgc_z, void *push_src, size_t push_size)
Submit a compute shader with a zero/one input and single out for execution.
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.