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;
385 VkQueueFlagBits dev_family);
394 int nb_queries, VkQueryType query_type,
int query_64bit,
395 const void *query_create_pnext);
409 void **
data, VkQueryResultFlagBits
flags);
432 VkSemaphore *sem,
int nb,
433 VkPipelineStageFlagBits2 stage,
436 VkPipelineStageFlagBits2 wait_stage,
437 VkPipelineStageFlagBits2 signal_stage);
439 VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar);
441 VkSemaphore *
dst, uint64_t *dst_val,
453 AVFrame *pic, VkImageMemoryBarrier2 *bar,
int *nb_bar,
454 VkPipelineStageFlags src_stage,
455 VkPipelineStageFlags dst_stage,
456 VkAccessFlagBits new_access,
457 VkImageLayout new_layout,
464 VkMemoryPropertyFlagBits req_flags,
void *alloc_extension,
465 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
467 void *pNext,
void *alloc_pNext,
468 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags);
470 void *pNext,
void *alloc_pNext,
471 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags);
477 int nb_buffers,
int invalidate);
501 void *create_pNext,
size_t size,
502 VkMemoryPropertyFlagBits mem_props);
508 int unnorm_coords, VkFilter
filt);
515 VkPipelineStageFlags stage,
516 const char *extensions[],
int nb_extensions,
517 int lg_x,
int lg_y,
int lg_z,
518 uint32_t required_subgroup_size);
530 uint8_t *spirv,
size_t spirv_len,
531 const char *entrypoint);
537 VkShaderStageFlagBits stage);
544 int singular,
int print_to_shader_only);
565 VkShaderStageFlagBits stage,
574 int set,
int bind,
int elem,
584 VkImageView *views,
int set,
int binding,
585 VkImageLayout
layout, VkSampler sampler);
VkPipelineBindPoint bind_point
const char * ff_vk_ret2str(VkResult res)
Converts Vulkan return values to strings.
int ff_vk_exec_add_dep_bool_sem(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *sem, int nb, VkPipelineStageFlagBits2 stage, int wait)
int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer **buf, uint8_t *mem[], int nb_buffers, int invalidate)
Buffer management code.
int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers, int flush)
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
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
AVVulkanFramesContext * hwfc
void ff_vk_uninit(FFVulkanContext *s)
Frees main context.
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
unsigned int frame_deps_alloc_size
uint64_t FFVulkanExtensions
int ff_vk_load_props(FFVulkanContext *s)
Loads props/mprops/driver_props.
FFVkExecContext * contexts
VkDeviceSize aligned_size
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.
VkPipelineStageFlags2 stage
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.
This structure describes decoded (raw) audio or video data.
VkShaderStageFlags stages
static int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem, int invalidate)
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup_info
static const void * ff_vk_find_struct(const void *chain, VkStructureType stype)
unsigned int sem_sig_alloc
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)
VkDescriptorBufferBindingInfoEXT * desc_bind
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.
VkSemaphoreSubmitInfo * sem_wait
void ff_vk_shader_print(void *ctx, FFVulkanShader *shd, int prio)
Output the shader code as logging data, with a specific priority.
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.
VkDescriptorSet * desc_sets
FFVkShaderRepFormat
Returns the format to use for images in shaders.
void ff_vk_shader_free(FFVulkanContext *s, FFVulkanShader *shd)
Free a shader.
unsigned int frame_update_alloc_size
VkDescriptorSetLayout * desc_layout
int ff_vk_shader_register_exec(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanShader *shd)
Register a shader with an exec pool.
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pix_fmt, enum FFVkShaderRepFormat rep_fmt)
VkPhysicalDeviceFeatures2 feats
int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e, VkSemaphore *dst, uint64_t *dst_val, AVFrame *f)
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props
VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
VkDescriptorSetLayoutBinding * binding
VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, void **data, VkQueryResultFlagBits flags)
Performs nb_queries queries and returns their results and statuses.
#define FF_ARRAY_ELEMS(a)
static void ff_vk_link_struct(void *chain, const void *in)
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
uint32_t * queue_family_dst
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.
VkPushConstantRange * push_consts
VkPhysicalDeviceDriverProperties driver_props
static enum AVPixelFormat pix_fmt
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
VkPipelineStageFlags stage
int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
const struct FFVkExecPool * parent
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.
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
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.
unsigned int access_dst_alloc
VkPhysicalDeviceCooperativeMatrixPropertiesKHR coop_matrix_props
VkQueueFamilyProperties2 * qf_props
void(* flush)(AVBSFContext *ctx)
uint32_t * bound_buffer_indices
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler, int unnorm_coords, VkFilter filt)
Create a sampler.
int ff_vk_shader_add_push_const(FFVulkanShader *shd, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
int ff_vk_create_avbuf(FFVulkanContext *s, AVBufferRef **ref, size_t size, void *pNext, void *alloc_pNext, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e)
AVHWDeviceContext * device
VkImageLayout * layout_dst
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.
unsigned int queue_family_dst_alloc
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
VkDescriptorPoolSize * desc_pool_size
#define AV_NUM_DATA_POINTERS
VkPipelineLayout pipeline_layout
enum AVPixelFormat output_format
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
int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, AVBufferRef **deps, int nb_deps, int ref)
Execution dependency management.
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, FFVulkanShader *shd)
Bind a shader.
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_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
VkDescriptorPool desc_pool
unsigned int layout_dst_alloc
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if pixfmt is a usable RGB format.
FFVulkanShaderData * reg_shd
static int ff_vk_unmap_buffer(FFVulkanContext *s, FFVkBuffer *buf, int flush)
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,...
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
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.
VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props
const VkComponentMapping ff_comp_identity_map
VkSemaphoreSubmitInfo * sem_sig
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.
enum AVPixelFormat input_format
FFVulkanDescriptorSet * desc_set
uint32_t coop_mat_props_nb
void ff_vk_exec_update_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar)
VkQueueFamilyVideoPropertiesKHR * video_props
static int ref[MAX_W *MAX_W]
void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool)
AVVulkanDeviceContext * hwctx
A reference to a data buffer.
VkCommandBuffer * cmd_bufs
VkPhysicalDeviceVulkan12Features feats_12
int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf, VkQueueFlagBits dev_family)
Chooses a QF and loads it into a context.
static int ff_vk_count_images(AVVkFrame *f)
unsigned int buf_deps_alloc_size
#define flags(name, subs,...)
AVHWFramesContext * frames
VkPhysicalDeviceOpticalFlowPropertiesNV optical_flow_props
uint64_t ** sem_sig_val_dst
VkQueueFamilyQueryResultStatusPropertiesKHR * query_props
VkCommandPool cmd_buf_pool
VkCooperativeMatrixPropertiesKHR * coop_mat_props
VkAccessFlagBits * access_dst