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 }
79 VkPipelineShaderStageCreateInfo
shader;
247 VkPhysicalDeviceExternalMemoryHostPropertiesEXT
hprops;
294 const VkBaseInStructure *in = chain;
296 if (in->sType == stype)
307 VkBaseOutStructure *
out = chain;
311 out->pNext = (
void *)in;
349 VkQueueFlagBits dev_family);
358 int nb_queries, VkQueryType query_type,
int query_64bit,
359 const void *query_create_pnext);
373 void **
data, VkQueryResultFlagBits
flags);
396 VkSemaphore *sem,
int nb,
397 VkPipelineStageFlagBits2 stage,
400 VkPipelineStageFlagBits2 wait_stage,
401 VkPipelineStageFlagBits2 signal_stage);
403 VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar);
405 VkSemaphore *
dst, uint64_t *dst_val,
417 AVFrame *pic, VkImageMemoryBarrier2 *bar,
int *nb_bar,
418 VkPipelineStageFlags src_stage,
419 VkPipelineStageFlags dst_stage,
420 VkAccessFlagBits new_access,
421 VkImageLayout new_layout,
428 VkMemoryPropertyFlagBits req_flags,
void *alloc_extension,
429 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
431 void *pNext,
void *alloc_pNext,
432 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags);
434 void *pNext,
void *alloc_pNext,
435 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags);
441 int nb_buffers,
int invalidate);
465 void *create_pNext,
size_t size,
466 VkMemoryPropertyFlagBits mem_props);
472 int unnorm_coords, VkFilter
filt);
478 VkShaderStageFlags stage, uint32_t required_subgroup_size);
482 uint8_t *spirv,
size_t spirv_size,
const char *entrypoint);
489 VkShaderStageFlagBits stage);
492 VkShaderStageFlagBits stage,
501 int singular,
int print_to_shader_only);
526 VkImageView *views,
int set,
int binding,
527 VkImageLayout
layout, VkSampler sampler);
VkPipelineBindPoint bind_point
AVPixelFormat
Pixel format.
VkDescriptorPoolSize * desc_pool_size
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.
VkPipelineLayout pipeline_layout
FFVkExecContext * contexts
void ff_vk_update_descriptor_img_array(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkExecContext *e, AVFrame *f, VkImageView *views, int set, int binding, VkImageLayout layout, VkSampler sampler)
VkDeviceSize aligned_size
int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size, VkShaderStageFlagBits stage)
Add/update push constants for execution.
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.
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.
int ff_vk_set_descriptor_buffer(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkExecContext *e, int set, int bind, int elem, FFVkBuffer *buf, VkDeviceSize offset, VkDeviceSize len, VkFormat fmt)
unsigned int sem_sig_alloc
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
VkDescriptorPool desc_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
VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e, void **data, VkQueryResultFlagBits flags)
Performs nb_queries queries and returns their results and statuses.
static void ff_vk_link_struct(void *chain, const void *in)
VkPhysicalDeviceFeatures2 feats
static const void * ff_vk_find_struct(const void *chain, VkStructureType stype)
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
void ff_vk_pipeline_free(FFVulkanContext *s, FFVulkanPipeline *pl)
int ff_vk_shader_create(FFVulkanContext *s, FFVkSPIRVShader *shd, uint8_t *spirv, size_t spirv_size, const char *entrypoint)
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.
VkDescriptorSet * desc_sets
int ff_vk_shader_init(FFVulkanPipeline *pl, FFVkSPIRVShader *shd, const char *name, VkShaderStageFlags stage, uint32_t required_subgroup_size)
Shader management.
#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
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.
FFVkExecPool * assoc_pool
VkPhysicalDeviceDriverProperties driver_props
static enum AVPixelFormat pix_fmt
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)
void ff_vk_shader_set_compute_sizes(FFVkSPIRVShader *shd, int x, int y, int z)
const struct FFVkExecPool * parent
FFVkExecContext * ff_vk_exec_get(FFVkExecPool *pool)
Retrieve an execution pool.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
Describe the class of an AVClass context structure.
unsigned int sem_sig_val_dst_alloc
int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd)
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)
static int ff_vk_count_images(AVVkFrame *f)
int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e, AVBufferRef **deps, int nb_deps, int ref)
Execution dependency management.
void ff_vk_shader_free(FFVulkanContext *s, FFVkSPIRVShader *shd)
AVHWDeviceContext * device
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an 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.
#define AV_NUM_DATA_POINTERS
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf)
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
enum AVPixelFormat output_format
VkMemoryPropertyFlagBits flags
int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl, FFVkSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int nb, int singular, int print_to_shader_only)
Add descriptor to a pipeline.
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
const char * ff_vk_ret2str(VkResult res)
Converts Vulkan return values to strings.
void ff_vk_update_push_exec(FFVulkanContext *s, FFVkExecContext *e, FFVulkanPipeline *pl, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
VkPushConstantRange * push_consts
VkPipelineShaderStageCreateInfo shader
unsigned int layout_dst_alloc
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
uint32_t coop_mat_props_nb
FFVulkanDescriptorSet * desc_set
VkQueueFamilyVideoPropertiesKHR * video_props
static int ref[MAX_W *MAX_W]
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup_info
int ff_vk_exec_pipeline_register(FFVulkanContext *s, FFVkExecPool *pool, FFVulkanPipeline *pl)
Register a pipeline with an exec pool.
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)
void ff_vk_shader_print(void *ctx, FFVkSPIRVShader *shd, int prio)
VkDescriptorBufferBindingInfoEXT * desc_bind
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)
VkDescriptorSetLayout * desc_layout
VkCommandPool cmd_buf_pool
VkCooperativeMatrixPropertiesKHR * coop_mat_props
uint32_t * bound_buffer_indices
void ff_vk_exec_bind_pipeline(FFVulkanContext *s, FFVkExecContext *e, FFVulkanPipeline *pl)
VkAccessFlagBits * access_dst