Go to the documentation of this file.
19 #ifndef AVUTIL_VULKAN_H
20 #define AVUTIL_VULKAN_H
22 #define VK_NO_PROTOTYPES
24 #include <stdatomic.h>
34 #define INDENT(N) INDENT_##N
36 #define INDENT_1 INDENT_0 " "
37 #define INDENT_2 INDENT_1 INDENT_1
38 #define INDENT_3 INDENT_2 INDENT_1
39 #define INDENT_4 INDENT_3 INDENT_1
40 #define INDENT_5 INDENT_4 INDENT_1
41 #define INDENT_6 INDENT_5 INDENT_1
42 #define C(N, S) INDENT(N) #S "\n"
46 av_bprintf(&shd->src, C(N, S)); \
51 av_bprintf(&shd->src, __VA_ARGS__); \
54 #define GLSLF(N, S, ...) \
56 av_bprintf(&shd->src, C(N, S), __VA_ARGS__); \
61 av_bprintf(&shd->src, "\n"); \
62 av_bprint_append_data(&shd->src, D, strlen(D)); \
63 av_bprintf(&shd->src, "\n"); \
69 if ((err = (x)) < 0) \
73 #define DUP_SAMPLER(x) { x, x, x, x }
272 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
hprops;
319 const VkBaseInStructure *in = chain;
321 if (in->sType == stype)
332 VkBaseOutStructure *
out = chain;
336 out->pNext = (
void *)in;
374 VkQueueFlagBits dev_family);
383 int nb_queries, VkQueryType query_type,
int query_64bit,
384 const void *query_create_pnext);
398 void **
data, VkQueryResultFlagBits
flags);
421 VkSemaphore *sem,
int nb,
422 VkPipelineStageFlagBits2 stage,
425 VkPipelineStageFlagBits2 wait_stage,
426 VkPipelineStageFlagBits2 signal_stage);
428 VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar);
430 VkSemaphore *
dst, uint64_t *dst_val,
442 AVFrame *pic, VkImageMemoryBarrier2 *bar,
int *nb_bar,
443 VkPipelineStageFlags src_stage,
444 VkPipelineStageFlags dst_stage,
445 VkAccessFlagBits new_access,
446 VkImageLayout new_layout,
453 VkMemoryPropertyFlagBits req_flags,
void *alloc_extension,
454 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
456 void *pNext,
void *alloc_pNext,
457 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags);
459 void *pNext,
void *alloc_pNext,
460 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags);
466 int nb_buffers,
int invalidate);
490 void *create_pNext,
size_t size,
491 VkMemoryPropertyFlagBits mem_props);
497 int unnorm_coords, VkFilter
filt);
504 VkPipelineStageFlags stage,
505 const char *extensions[],
int nb_extensions,
506 int lg_x,
int lg_y,
int lg_z,
507 uint32_t required_subgroup_size);
519 uint8_t *spirv,
size_t spirv_len,
520 const char *entrypoint);
526 VkShaderStageFlagBits stage);
533 int singular,
int print_to_shader_only);
554 VkShaderStageFlagBits stage,
563 int set,
int bind,
int elem,
573 VkImageView *views,
int set,
int binding,
574 VkImageLayout
layout, VkSampler sampler);
VkPipelineBindPoint bind_point
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
AVPixelFormat
Pixel format.
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
AVVulkanFramesContext * hwfc
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
unsigned int frame_deps_alloc_size
int ff_vk_load_props(FFVulkanContext *s)
Loads props/mprops/driver_props.
uint64_t FFVulkanExtensions
FFVkExecContext * contexts
VkDeviceSize aligned_size
VkPipelineStageFlags2 stage
int ff_vk_create_avbuf(FFVulkanContext *s, AVBufferRef **ref, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
This structure describes decoded (raw) audio or video data.
void ff_vk_shader_print(void *ctx, FFVulkanShader *shd, int prio)
Output the shader code as logging data, with a specific priority.
VkShaderStageFlags stages
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.
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup_info
unsigned int sem_sig_alloc
VkDescriptorBufferBindingInfoEXT * desc_bind
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
void ff_vk_exec_update_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar)
VkSemaphoreSubmitInfo * sem_wait
VkDescriptorSet * desc_sets
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.
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *dst, uint64_t *dst_val, AVFrame *f)
unsigned int frame_update_alloc_size
VkDescriptorSetLayout * desc_layout
VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, void **data, VkQueryResultFlagBits flags)
Performs nb_queries queries and returns their results and statuses.
int ff_vk_shader_update_desc_buffer(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, int set, int bind, int elem, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len, VkFormat fmt)
Update a descriptor in a buffer with a buffer.
static void ff_vk_link_struct(void *chain, const void *in)
int ff_vk_shader_add_descriptor_set(FFVulkanContext *s, FFVulkanShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a shader.
VkPhysicalDeviceFeatures2 feats
static const void * ff_vk_find_struct(const void *chain, VkStructureType stype)
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props
int ff_vk_exec_pool_init(FFVulkanContext *s, FFVkQueueFamilyCtx *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.
VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats
int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers, int flush)
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
VkDescriptorSetLayoutBinding * binding
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Returns the format to use for images in shaders.
#define FF_ARRAY_ELEMS(a)
int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family)
Chooses a QF and loads it into a context.
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
uint32_t * queue_family_dst
VkPushConstantRange * push_consts
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e, VkImageView views[AV_NUM_DATA_POINTERS], AVFrame *f)
Create an imageview and add it as a dependency to an execution.
VkPhysicalDeviceDriverProperties driver_props
static enum AVPixelFormat pix_fmt
VkPipelineStageFlags stage
int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVBufferPool **buf_pool, AVBufferRef **buf, VkBufferUsageFlags usage, void *create_pNext, size_t size, VkMemoryPropertyFlagBits mem_props)
Initialize a pool and create AVBufferRefs containing FFVkBuffer.
static int ff_vk_unmap_buffer(FFVulkanContext *s, FFVkBuffer *buf, int flush)
const struct FFVkExecPool * parent
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
FFVulkanDescriptorSetData * desc_set_buf
Describe the class of an AVClass context structure.
unsigned int sem_sig_val_dst_alloc
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
unsigned int access_dst_alloc
VkPhysicalDeviceCooperativeMatrixPropertiesKHR coop_matrix_props
VkQueueFamilyProperties2 * qf_props
void(* flush)(AVBSFContext *ctx)
int ff_vk_shader_link(FFVulkanContext *s, FFVulkanShader *shd, uint8_t *spirv, size_t spirv_len, const char *entrypoint)
Link a shader into an executable.
static int ff_vk_count_images(AVVkFrame *f)
uint32_t * bound_buffer_indices
int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, AVBufferRef **deps, int nb_deps, int ref)
Execution dependency management.
AVHWDeviceContext * device
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
VkImageLayout * layout_dst
unsigned int queue_family_dst_alloc
int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer **buf, uint8_t *mem[], int nb_buffers, int invalidate)
Buffer management code.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req, VkMemoryPropertyFlagBits req_flags, void *alloc_extension, VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
Memory/buffer/image allocation helpers.
VkDescriptorPoolSize * desc_pool_size
#define AV_NUM_DATA_POINTERS
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
VkPipelineLayout pipeline_layout
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
enum AVPixelFormat output_format
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd)
Bind a shader.
VkMemoryPropertyFlagBits flags
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
const VkComponentMapping ff_comp_identity_map
int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *sem, int nb, VkPipelineStageFlagBits2 stage, int wait)
AVBufferRef * input_frames_ref
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
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
const char * ff_vk_ret2str(VkResult res)
Converts Vulkan return values to strings.
VkDescriptorPool desc_pool
unsigned int layout_dst_alloc
FFVulkanShaderData * reg_shd
VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops
VkPhysicalDeviceProperties2 props
unsigned int frame_locked_alloc_size
static const int8_t filt[NUMTAPS *2]
FFVulkanExtensions extensions
VkPhysicalDeviceMemoryProperties mprops
VkDeviceSize * binding_offset
unsigned int sem_wait_alloc
This struct describes a set or pool of "hardware" frames (i.e.
intptr_t atomic_int_least64_t
VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props
enum AVPixelFormat pixfmt
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
VkSemaphoreSubmitInfo * sem_sig
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
enum AVPixelFormat input_format
FFVulkanDescriptorSet * desc_set
uint32_t coop_mat_props_nb
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,...
VkQueueFamilyVideoPropertiesKHR * video_props
static int ref[MAX_W *MAX_W]
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
AVVulkanDeviceContext * hwctx
A reference to a data buffer.
VkCommandBuffer * cmd_bufs
VkPhysicalDeviceVulkan12Features feats_12
unsigned int buf_deps_alloc_size
#define flags(name, subs,...)
AVHWFramesContext * frames
VkPhysicalDeviceOpticalFlowPropertiesNV optical_flow_props
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags src_stage, VkPipelineStageFlags dst_stage, VkAccessFlagBits new_access, VkImageLayout new_layout, uint32_t new_qf)
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
uint64_t ** sem_sig_val_dst
VkQueueFamilyQueryResultStatusPropertiesKHR * query_props
int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
void ff_vk_shader_update_push_const(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
Update push constant in a shader.
VkCommandPool cmd_buf_pool
VkCooperativeMatrixPropertiesKHR * coop_mat_props
VkAccessFlagBits * access_dst