Go to the documentation of this file.
21 #include "../ops_internal.h"
22 #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();
96 int x_start,
int y_start,
int x_end,
int y_end)
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
167 void *spv_opaque =
NULL;
174 VK_SHADER_STAGE_COMPUTE_BIT,
175 NULL, 0, 32, 32, 1, 0);
182 for (
int n = 0; n < ops->
num_ops; n++) {
197 .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE,
198 .mem_layout = img_type,
201 .elems = (
op->rw.packed ? 1 :
op->rw.elems),
202 .stages = VK_SHADER_STAGE_COMPUTE_BIT,
217 GLSLC(1, ivec2
pos = ivec2(gl_GlobalInvocationID.xy); );
218 GLSLC(1, ivec2
size = imageSize(src_img[0]); );
222 GLSLC(1, u8vec4 u8; );
223 GLSLC(1, u16vec4 u16; );
224 GLSLC(1, u32vec4 u32; );
225 GLSLC(1, f32vec4 f32; );
229 for (
int n = 0; n < ops->
num_ops; n++) {
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);
251 GLSLF(1, imageStore(dst_img[0],
pos, %
s(%
s)); ,
254 for (
int i = 0;
i < (
op->rw.packed ? 1 :
op->rw.elems);
i++)
256 i, type_v, type_name,
i);
262 for (
int i = 0;
i < 4;
i++)
268 for (
int i = 0;
i < 4;
i++) {
269 if (!
op->c.q4[
i].den)
272 "xyzw"[
i], type_s,
op->c.q4[
i].num,
op->c.q4[
i].den,
284 err =
s->spvc->compile_shader(&
s->vkctx,
s->spvc, shd,
285 &spv_data, &spv_len,
"main",
293 s->spvc->free_shader(
s->spvc, &spv_opaque);
314 #if CONFIG_LIBSHADERC || CONFIG_LIBGLSLANG
316 err = add_ops_glsl(&
p,
s, ops, &
p.shd);
Copyright (C) 2026 Lynne.
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,...
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.
static void process(const SwsOpExec *exec, const void *priv, int x_start, int y_start, int x_end, int y_end)
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.
#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.
const SwsFrame * out_frame
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
void ff_sws_vk_uninit(SwsContext *sws)
Copyright (C) 2026 Lynne.
Global execution context for all compiled functions.
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
#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.
const AVFrame * avframe
Pointer to the original AVFrame, if there is a 1:1 correspondence.
const SwsFrame * in_frame
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.
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
static SwsInternal * sws_internal(const SwsContext *sws)
Helper struct for representing a list of operations.
Main external API structure.