Go to the documentation of this file.
24 #include "../ops_internal.h"
25 #include "../swscale_internal.h"
33 #if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
35 s->spvc->uninit(&
s->spvc);
54 if (
s->vkctx.device_ref &&
s->vkctx.device_ref->data != dev_ref->
data) {
58 }
else if (
s->vkctx.device_ref &&
s->vkctx.device_ref->data == dev_ref->
data) {
77 #if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
79 s->spvc = ff_vk_spirv_init();
106 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
107 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT);
109 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
110 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT);
118 0, 0, VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
120 0, 1, VK_IMAGE_LAYOUT_GENERAL, VK_NULL_HANDLE);
123 VkImageMemoryBarrier2 img_bar[8];
125 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
126 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
127 VK_ACCESS_SHADER_READ_BIT,
128 VK_IMAGE_LAYOUT_GENERAL,
129 VK_QUEUE_FAMILY_IGNORED);
131 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
132 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
133 VK_ACCESS_SHADER_WRITE_BIT,
134 VK_IMAGE_LAYOUT_GENERAL,
135 VK_QUEUE_FAMILY_IGNORED);
136 vk->CmdPipelineBarrier2(ec->buf, &(VkDependencyInfo) {
137 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
138 .pImageMemoryBarriers = img_bar,
139 .imageMemoryBarrierCount = nb_img_bar,
144 vk->CmdDispatch(ec->buf,
160 #if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
172 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
173 .mem_layout = img_type,
176 .elems =
op->rw.packed ? 1 :
op->rw.elems,
177 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
189 void *spv_opaque =
NULL;
196 VK_SHADER_STAGE_COMPUTE_BIT,
197 NULL, 0, 32, 32, 1, 0);
207 add_desc_read_write(&buf_desc[nb_desc++], &
p->src_rep,
read);
208 add_desc_read_write(&buf_desc[nb_desc++], &
p->dst_rep, write);
213 GLSLC(1, ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
214 GLSLC(1, ivec2
size = imageSize(src_img[0]); );
218 GLSLC(1, u8vec4 u8; );
219 GLSLC(1, u16vec4 u16; );
220 GLSLC(1, u32vec4 u32; );
221 GLSLC(1, f32vec4 f32; );
225 for (
int n = 0; n < ops->
num_ops; n++) {
239 }
else if (
op->rw.packed) {
240 GLSLF(1, %
s = %
s(imageLoad(src_img[0],
pos)); ,
243 for (
int i = 0;
i < (
op->rw.packed ? 1 :
op->rw.elems);
i++)
245 type_name,
"xyzw"[
i], type_s,
i);
252 }
else if (
op->rw.packed) {
253 GLSLF(1, imageStore(dst_img[0],
pos, %
s(%
s)); ,
256 for (
int i = 0;
i < (
op->rw.packed ? 1 :
op->rw.elems);
i++)
258 i, type_v, type_name,
i);
264 for (
int i = 0;
i < 4;
i++)
270 for (
int i = 0;
i < 4;
i++) {
271 if (!
op->c.q4[
i].den)
274 "xyzw"[
i], type_s,
op->c.q4[
i].num,
op->c.q4[
i].den,
286 err =
s->spvc->compile_shader(&
s->vkctx,
s->spvc, shd,
287 &spv_data, &spv_len,
"main",
295 s->spvc->free_shader(
s->spvc, &spv_opaque);
316 #if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
318 err = add_ops_glsl(&
p,
s, ops, &
p.shd);
Copyright (C) 2026 Lynne.
Represents a single filter pass in the scaling graph.
enum FFVkShaderRepFormat src_rep
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,...
const SwsOp * ff_sws_op_list_input(const SwsOpList *ops)
Returns the input operation for a given op list, or NULL if there is none (e.g.
uint8_t * data
The data buffer.
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.
RefStruct is an API for creating reference-counted objects with minimal overhead.
This structure describes decoded (raw) audio or video data.
const SwsOpBackend backend_vulkan
int ff_vk_init(FFVulkanContext *s, void *log_parent, AVBufferRef *device_ref, AVBufferRef *frames_ref)
Initializes the AVClass, in case this context is not used as the main user's context.
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
FFVkShaderRepFormat
Returns the format to use for images in shaders.
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
static int compile(SwsContext *sws, SwsOpList *ops, SwsCompiledOp *out)
void ff_vk_shader_update_img_array(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, AVFrame *f, VkImageView *views, int set, int binding, VkImageLayout layout, VkSampler sampler)
Update a descriptor in a buffer with an image array.
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags2 src_stage, VkPipelineStageFlags2 dst_stage, VkAccessFlagBits2 new_access, VkImageLayout new_layout, uint32_t new_qf)
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
Represents a view into a single field of frame data.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int ff_sws_vk_init(SwsContext *sws, AVBufferRef *dev_ref)
static int op(uint8_t **dst, const uint8_t *dst_end, GetByteContext *gb, int pixel, int count, int *x, int width, int linesize)
Perform decode operation.
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
static void * av_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void(*free_cb)(AVRefStructOpaque opaque, void *obj))
A wrapper around av_refstruct_alloc_ext_c() for the common case of a non-const qualified opaque.
const SwsOp * ff_sws_op_list_output(const SwsOpList *ops)
Returns the output operation for a given op list, or NULL if there is none.
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
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.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
#define i(width, name, range_min, range_max)
#define AV_NUM_DATA_POINTERS
enum FFVkShaderRepFormat dst_rep
static SwsContext * sws[3]
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
static void process(const SwsFrame *dst, const SwsFrame *src, int y, int h, const SwsPass *pass)
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, VkImageView views[AV_NUM_DATA_POINTERS], AVFrame *f, enum FFVkShaderRepFormat rep_fmt)
Create an imageview and add it as a dependency to an execution.
void av_bprintf(AVBPrint *buf, const char *fmt,...)
AVVulkanDeviceQueueFamily * ff_vk_qf_find(FFVulkanContext *s, VkQueueFlagBits dev_family, VkVideoCodecOperationFlagBitsKHR vid_ops)
Chooses an appropriate QF.
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.
const char * ff_sws_pixel_type_name(SwsPixelType type)
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
static void free_fn(void *priv)
A reference to a data buffer.
static void ff_sws_vk_uninit(AVRefStructOpaque opaque, void *obj)
Copyright (C) 2026 Lynne.
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
static SwsInternal * sws_internal(const SwsContext *sws)
Helper struct for representing a list of operations.
const char * ff_sws_op_type_name(SwsOpType op)
Main external API structure.
static uint32_t BS_FUNC() read(BSCTX *bc, unsigned int n)
Return n bits from the buffer, n has to be in the 0-32 range.