FFmpeg
Data Structures | Macros | Functions | Variables
vulkan.h File Reference
#include "avfilter.h"
#include "libavutil/pixdesc.h"
#include "libavutil/bprint.h"
#include "libavutil/hwcontext.h"
#include "libavutil/hwcontext_vulkan.h"
#include "libavutil/vulkan_functions.h"

Go to the source code of this file.

Data Structures

struct  FFSPIRVShader
 
struct  FFVkSampler
 
struct  FFVulkanDescriptorSetBinding
 
struct  FFVkBuffer
 
struct  FFVkQueueFamilyCtx
 
struct  FFVulkanPipeline
 
struct  FFVkQueueCtx
 
struct  FFVkExecContext
 
struct  FFVulkanContext
 

Macros

#define VK_NO_PROTOTYPES
 
#define VK_ENABLE_BETA_EXTENSIONS
 
#define INDENT(N)   INDENT_##N
 
#define INDENT_0
 
#define INDENT_1   INDENT_0 " "
 
#define INDENT_2   INDENT_1 INDENT_1
 
#define INDENT_3   INDENT_2 INDENT_1
 
#define INDENT_4   INDENT_3 INDENT_1
 
#define INDENT_5   INDENT_4 INDENT_1
 
#define INDENT_6   INDENT_5 INDENT_1
 
#define C(N, S)   INDENT(N) #S "\n"
 
#define GLSLC(N, S)   av_bprintf(&shd->src, C(N, S))
 
#define GLSLA(...)   av_bprintf(&shd->src, __VA_ARGS__)
 
#define GLSLF(N, S, ...)   av_bprintf(&shd->src, C(N, S), __VA_ARGS__)
 
#define GLSLD(D)
 
#define RET(x)
 

Functions

int ff_vk_filter_init (AVFilterContext *avctx)
 General lavfi IO functions. More...
 
int ff_vk_filter_config_input (AVFilterLink *inlink)
 
int ff_vk_filter_config_output (AVFilterLink *outlink)
 
int ff_vk_filter_config_output_inplace (AVFilterLink *outlink)
 
void ff_vk_filter_uninit (AVFilterContext *avctx)
 
const char * ff_vk_ret2str (VkResult res)
 Converts Vulkan return values to strings. More...
 
int ff_vk_mt_is_np_rgb (enum AVPixelFormat pix_fmt)
 Returns 1 if the image is any sort of supported RGB. More...
 
const char * ff_vk_shader_rep_fmt (enum AVPixelFormat pixfmt)
 Gets the glsl format string for a pixel format. More...
 
void ff_vk_qf_init (AVFilterContext *avctx, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family, int nb_queues)
 Initialize a queue family with a specific number of queues. More...
 
void ff_vk_qf_rotate (FFVkQueueFamilyCtx *qf)
 Rotate through the queues in a queue family. More...
 
FFVkSamplerff_vk_init_sampler (AVFilterContext *avctx, int unnorm_coords, VkFilter filt)
 Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit() More...
 
int ff_vk_create_imageview (AVFilterContext *avctx, FFVkExecContext *e, VkImageView *v, VkImage img, VkFormat fmt, const VkComponentMapping map)
 Create an imageview. More...
 
int ff_vk_add_push_constant (AVFilterContext *avctx, FFVulkanPipeline *pl, int offset, int size, VkShaderStageFlagBits stage)
 Define a push constant for a given stage into a pipeline. More...
 
FFVulkanPipelineff_vk_create_pipeline (AVFilterContext *avctx, FFVkQueueFamilyCtx *qf)
 Inits a pipeline. More...
 
FFSPIRVShaderff_vk_init_shader (AVFilterContext *avctx, FFVulkanPipeline *pl, const char *name, VkShaderStageFlags stage)
 Inits a shader for a specific pipeline. More...
 
void ff_vk_set_compute_shader_sizes (AVFilterContext *avctx, FFSPIRVShader *shd, int local_size[3])
 Writes the workgroup size for a shader. More...
 
int ff_vk_add_descriptor_set (AVFilterContext *avctx, FFVulkanPipeline *pl, FFSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int num, int only_print_to_shader)
 Adds a descriptor set to the shader and registers them in the pipeline. More...
 
int ff_vk_compile_shader (AVFilterContext *avctx, FFSPIRVShader *shd, const char *entrypoint)
 Compiles the shader, entrypoint must be set to "main". More...
 
void ff_vk_print_shader (AVFilterContext *avctx, FFSPIRVShader *shd, int prio)
 Pretty print shader, mainly used by shader compilers. More...
 
int ff_vk_init_pipeline_layout (AVFilterContext *avctx, FFVulkanPipeline *pl)
 Initializes the pipeline layout after all shaders and descriptor sets have been finished. More...
 
int ff_vk_init_compute_pipeline (AVFilterContext *avctx, FFVulkanPipeline *pl)
 Initializes a compute pipeline. More...
 
void ff_vk_update_descriptor_set (AVFilterContext *avctx, FFVulkanPipeline *pl, int set_id)
 Updates a descriptor set via the updaters defined. More...
 
int ff_vk_create_exec_ctx (AVFilterContext *avctx, FFVkExecContext **ctx, FFVkQueueFamilyCtx *qf)
 Init an execution context for command recording and queue submission. More...
 
int ff_vk_start_exec_recording (AVFilterContext *avctx, FFVkExecContext *e)
 Begin recording to the command buffer. More...
 
void ff_vk_bind_pipeline_exec (AVFilterContext *avctx, FFVkExecContext *e, FFVulkanPipeline *pl)
 Add a command to bind the completed pipeline and its descriptor sets. More...
 
void ff_vk_update_push_exec (AVFilterContext *avctx, FFVkExecContext *e, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
 Updates push constants. More...
 
VkCommandBuffer ff_vk_get_exec_buf (AVFilterContext *avctx, FFVkExecContext *e)
 Gets the command buffer to use for this submission from the exe context. More...
 
int ff_vk_add_dep_exec_ctx (AVFilterContext *avctx, FFVkExecContext *e, AVBufferRef **deps, int nb_deps)
 Adds a generic AVBufferRef as a queue depenency. More...
 
void ff_vk_discard_exec_deps (AVFilterContext *avctx, FFVkExecContext *e)
 Discards all queue dependencies. More...
 
int ff_vk_add_exec_dep (AVFilterContext *avctx, FFVkExecContext *e, AVFrame *frame, VkPipelineStageFlagBits in_wait_dst_flag)
 Adds a frame as a queue dependency. More...
 
int ff_vk_submit_exec_queue (AVFilterContext *avctx, FFVkExecContext *e)
 Submits a command buffer to the queue for execution. More...
 
int ff_vk_create_buf (AVFilterContext *avctx, FFVkBuffer *buf, size_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
 Create a VkBuffer with the specified parameters. More...
 
int ff_vk_map_buffers (AVFilterContext *avctx, FFVkBuffer *buf, uint8_t *mem[], int nb_buffers, int invalidate)
 Maps the buffer to userspace. More...
 
int ff_vk_unmap_buffers (AVFilterContext *avctx, FFVkBuffer *buf, int nb_buffers, int flush)
 Unmaps the buffer from userspace. More...
 
void ff_vk_free_buf (AVFilterContext *avctx, FFVkBuffer *buf)
 Frees a buffer. More...
 

Variables

const VkComponentMapping ff_comp_identity_map
 

Macro Definition Documentation

◆ VK_NO_PROTOTYPES

#define VK_NO_PROTOTYPES

Definition at line 22 of file vulkan.h.

◆ VK_ENABLE_BETA_EXTENSIONS

#define VK_ENABLE_BETA_EXTENSIONS

Definition at line 23 of file vulkan.h.

◆ INDENT

#define INDENT (   N)    INDENT_##N

Definition at line 33 of file vulkan.h.

◆ INDENT_0

#define INDENT_0

Definition at line 34 of file vulkan.h.

◆ INDENT_1

#define INDENT_1   INDENT_0 " "

Definition at line 35 of file vulkan.h.

◆ INDENT_2

#define INDENT_2   INDENT_1 INDENT_1

Definition at line 36 of file vulkan.h.

◆ INDENT_3

#define INDENT_3   INDENT_2 INDENT_1

Definition at line 37 of file vulkan.h.

◆ INDENT_4

#define INDENT_4   INDENT_3 INDENT_1

Definition at line 38 of file vulkan.h.

◆ INDENT_5

#define INDENT_5   INDENT_4 INDENT_1

Definition at line 39 of file vulkan.h.

◆ INDENT_6

#define INDENT_6   INDENT_5 INDENT_1

Definition at line 40 of file vulkan.h.

◆ C

#define C (   N,
  S 
)    INDENT(N) #S "\n"

Definition at line 41 of file vulkan.h.

◆ GLSLC

#define GLSLC (   N,
  S 
)    av_bprintf(&shd->src, C(N, S))

Definition at line 42 of file vulkan.h.

◆ GLSLA

#define GLSLA (   ...)    av_bprintf(&shd->src, __VA_ARGS__)

Definition at line 43 of file vulkan.h.

◆ GLSLF

#define GLSLF (   N,
  S,
  ... 
)    av_bprintf(&shd->src, C(N, S), __VA_ARGS__)

Definition at line 44 of file vulkan.h.

◆ GLSLD

#define GLSLD (   D)
Value:
GLSLC(0, ); \
av_bprint_append_data(&shd->src, D, strlen(D)); \
GLSLC(0, )

Definition at line 45 of file vulkan.h.

◆ RET

#define RET (   x)
Value:
do { \
if ((err = (x)) < 0) \
goto fail; \
} while (0)

Definition at line 50 of file vulkan.h.

Function Documentation

◆ ff_vk_filter_init()

int ff_vk_filter_init ( AVFilterContext avctx)

General lavfi IO functions.

Definition at line 836 of file vulkan.c.

Referenced by overlay_vulkan_init().

◆ ff_vk_filter_config_input()

int ff_vk_filter_config_input ( AVFilterLink inlink)

Definition at line 704 of file vulkan.c.

◆ ff_vk_filter_config_output()

int ff_vk_filter_config_output ( AVFilterLink outlink)

◆ ff_vk_filter_config_output_inplace()

int ff_vk_filter_config_output_inplace ( AVFilterLink outlink)

Definition at line 755 of file vulkan.c.

◆ ff_vk_filter_uninit()

void ff_vk_filter_uninit ( AVFilterContext avctx)

◆ ff_vk_ret2str()

const char* ff_vk_ret2str ( VkResult  res)

◆ ff_vk_mt_is_np_rgb()

int ff_vk_mt_is_np_rgb ( enum AVPixelFormat  pix_fmt)

Returns 1 if the image is any sort of supported RGB.

Definition at line 889 of file vulkan.c.

Referenced by scale_vulkan_config_output().

◆ ff_vk_shader_rep_fmt()

const char* ff_vk_shader_rep_fmt ( enum AVPixelFormat  pixfmt)

Gets the glsl format string for a pixel format.

Definition at line 901 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_qf_init()

void ff_vk_qf_init ( AVFilterContext avctx,
FFVkQueueFamilyCtx qf,
VkQueueFlagBits  dev_family,
int  nb_queues 
)

Initialize a queue family with a specific number of queues.

If nb_queues == 0, use however many queues the queue family has.

Definition at line 92 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_qf_rotate()

void ff_vk_qf_rotate ( FFVkQueueFamilyCtx qf)

Rotate through the queues in a queue family.

Definition at line 130 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_init_sampler()

FFVkSampler* ff_vk_init_sampler ( AVFilterContext avctx,
int  unnorm_coords,
VkFilter  filt 
)

Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit()

Definition at line 849 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_create_imageview()

int ff_vk_create_imageview ( AVFilterContext avctx,
FFVkExecContext e,
VkImageView *  v,
VkImage  img,
VkFormat  fmt,
const VkComponentMapping  map 
)

Create an imageview.

Guaranteed to remain alive until the queue submission has finished executing, and will be destroyed after that.

Definition at line 922 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_add_push_constant()

int ff_vk_add_push_constant ( AVFilterContext avctx,
FFVulkanPipeline pl,
int  offset,
int  size,
VkShaderStageFlagBits  stage 
)

Define a push constant for a given stage into a pipeline.

Must be called before the pipeline layout has been initialized.

Definition at line 365 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_create_pipeline()

FFVulkanPipeline* ff_vk_create_pipeline ( AVFilterContext avctx,
FFVkQueueFamilyCtx qf 
)

Inits a pipeline.

Everything in it will be auto-freed when calling ff_vk_filter_uninit().

Definition at line 1395 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_init_shader()

FFSPIRVShader* ff_vk_init_shader ( AVFilterContext avctx,
FFVulkanPipeline pl,
const char *  name,
VkShaderStageFlags  stage 
)

Inits a shader for a specific pipeline.

Will be auto-freed on uninit.

Definition at line 976 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_set_compute_shader_sizes()

void ff_vk_set_compute_shader_sizes ( AVFilterContext avctx,
FFSPIRVShader shd,
int  local_size[3] 
)

Writes the workgroup size for a shader.

Definition at line 997 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_add_descriptor_set()

int ff_vk_add_descriptor_set ( AVFilterContext avctx,
FFVulkanPipeline pl,
FFSPIRVShader shd,
FFVulkanDescriptorSetBinding desc,
int  num,
int  only_print_to_shader 
)

Adds a descriptor set to the shader and registers them in the pipeline.

Definition at line 1094 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_compile_shader()

int ff_vk_compile_shader ( AVFilterContext avctx,
FFSPIRVShader shd,
const char *  entrypoint 
)

Compiles the shader, entrypoint must be set to "main".

Definition at line 1030 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_print_shader()

void ff_vk_print_shader ( AVFilterContext avctx,
FFSPIRVShader shd,
int  prio 
)

Pretty print shader, mainly used by shader compilers.

Definition at line 1009 of file vulkan.c.

Referenced by ff_vk_compile_shader(), and ff_vk_glslang_shader_compile().

◆ ff_vk_init_pipeline_layout()

int ff_vk_init_pipeline_layout ( AVFilterContext avctx,
FFVulkanPipeline pl 
)

Initializes the pipeline layout after all shaders and descriptor sets have been finished.

Definition at line 1290 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_init_compute_pipeline()

int ff_vk_init_compute_pipeline ( AVFilterContext avctx,
FFVulkanPipeline pl 
)

Initializes a compute pipeline.

Will pick the first shader with the COMPUTE flag set.

Definition at line 1405 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_update_descriptor_set()

void ff_vk_update_descriptor_set ( AVFilterContext avctx,
FFVulkanPipeline pl,
int  set_id 
)

Updates a descriptor set via the updaters defined.

Can be called immediately after pipeline creation, but must be called at least once before queue submission.

Definition at line 1252 of file vulkan.c.

Referenced by init_filter(), and process_frames().

◆ ff_vk_create_exec_ctx()

int ff_vk_create_exec_ctx ( AVFilterContext avctx,
FFVkExecContext **  ctx,
FFVkQueueFamilyCtx qf 
)

Init an execution context for command recording and queue submission.

WIll be auto-freed on uninit.

Definition at line 386 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_start_exec_recording()

int ff_vk_start_exec_recording ( AVFilterContext avctx,
FFVkExecContext e 
)

Begin recording to the command buffer.

Previous execution must have been completed, which ff_vk_submit_exec_queue() will ensure.

Definition at line 465 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_bind_pipeline_exec()

void ff_vk_bind_pipeline_exec ( AVFilterContext avctx,
FFVkExecContext e,
FFVulkanPipeline pl 
)

Add a command to bind the completed pipeline and its descriptor sets.

Must be called after ff_vk_start_exec_recording() and before submission.

Definition at line 1441 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_update_push_exec()

void ff_vk_update_push_exec ( AVFilterContext avctx,
FFVkExecContext e,
VkShaderStageFlagBits  stage,
int  offset,
size_t  size,
void *  src 
)

Updates push constants.

Must be called after binding a pipeline if any push constants were defined.

Definition at line 1279 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_get_exec_buf()

VkCommandBuffer ff_vk_get_exec_buf ( AVFilterContext avctx,
FFVkExecContext e 
)

Gets the command buffer to use for this submission from the exe context.

Definition at line 507 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_add_dep_exec_ctx()

int ff_vk_add_dep_exec_ctx ( AVFilterContext avctx,
FFVkExecContext e,
AVBufferRef **  deps,
int  nb_deps 
)

Adds a generic AVBufferRef as a queue depenency.

Definition at line 643 of file vulkan.c.

Referenced by ff_vk_create_imageview().

◆ ff_vk_discard_exec_deps()

void ff_vk_discard_exec_deps ( AVFilterContext avctx,
FFVkExecContext e 
)

Discards all queue dependencies.

Definition at line 449 of file vulkan.c.

Referenced by ff_vk_add_dep_exec_ctx(), ff_vk_add_exec_dep(), ff_vk_start_exec_recording(), and process_frames().

◆ ff_vk_add_exec_dep()

int ff_vk_add_exec_dep ( AVFilterContext avctx,
FFVkExecContext e,
AVFrame frame,
VkPipelineStageFlagBits  in_wait_dst_flag 
)

Adds a frame as a queue dependency.

This also manages semaphore signalling. Must be called before submission.

Definition at line 512 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_submit_exec_queue()

int ff_vk_submit_exec_queue ( AVFilterContext avctx,
FFVkExecContext e 
)

Submits a command buffer to the queue for execution.

Will block until execution has finished in order to simplify resource management.

Definition at line 593 of file vulkan.c.

Referenced by process_frames().

◆ ff_vk_create_buf()

int ff_vk_create_buf ( AVFilterContext avctx,
FFVkBuffer buf,
size_t  size,
VkBufferUsageFlags  usage,
VkMemoryPropertyFlagBits  flags 
)

Create a VkBuffer with the specified parameters.

Definition at line 192 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_map_buffers()

int ff_vk_map_buffers ( AVFilterContext avctx,
FFVkBuffer buf,
uint8_t *  mem[],
int  nb_buffers,
int  invalidate 
)

Maps the buffer to userspace.

Set invalidate to 1 if reading the contents is necessary.

Definition at line 258 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_unmap_buffers()

int ff_vk_unmap_buffers ( AVFilterContext avctx,
FFVkBuffer buf,
int  nb_buffers,
int  flush 
)

Unmaps the buffer from userspace.

Set flush to 1 to write and sync.

Definition at line 308 of file vulkan.c.

Referenced by init_filter().

◆ ff_vk_free_buf()

void ff_vk_free_buf ( AVFilterContext avctx,
FFVkBuffer buf 
)

Frees a buffer.

Definition at line 351 of file vulkan.c.

Referenced by gblur_vulkan_uninit(), overlay_vulkan_uninit(), and scale_vulkan_uninit().

Variable Documentation

◆ ff_comp_identity_map

const VkComponentMapping ff_comp_identity_map

Definition at line 47 of file vulkan.c.

Referenced by process_frames().

D
D(D(float, sse)
Definition: rematrix_init.c:29
fail
#define fail()
Definition: checkasm.h:127
GLSLC
#define GLSLC(N, S)
Definition: vulkan.h:42