summaryrefslogtreecommitdiff
path: root/libavutil/vulkan.h
diff options
context:
space:
mode:
authorLynne <dev@lynne.ee>2022-12-29 21:16:21 +0100
committerLynne <dev@lynne.ee>2023-05-29 00:41:48 +0200
commitb5eaeb1f134d973836d6e3dced271713fb97f234 (patch)
treeed4ca1f3e40ae29469adb9f9b503acf7b9ad103e /libavutil/vulkan.h
parent721b71da4aac9396a0788b9aaae4b05824a4a302 (diff)
vulkan: rewrite to support all necessary features
This commit rewrites the majority of vulkan.c to enable its use as a general-purpose high-level utility code, usable for decoding, encoding, and filtering of video frames. The dependency system was rewritten to simplify management of execution. The image handling system was rewritten to accomodate multiplane images. Due to how related all the new features were, this is a single commit.
Diffstat (limited to 'libavutil/vulkan.h')
-rw-r--r--libavutil/vulkan.h516
1 files changed, 232 insertions, 284 deletions
diff --git a/libavutil/vulkan.h b/libavutil/vulkan.h
index 3f887a782e..7f31ced41d 100644
--- a/libavutil/vulkan.h
+++ b/libavutil/vulkan.h
@@ -21,6 +21,8 @@
#define VK_NO_PROTOTYPES
+#include <stdatomic.h>
+
#include "pixdesc.h"
#include "bprint.h"
#include "hwcontext.h"
@@ -28,11 +30,6 @@
#include "hwcontext_vulkan.h"
#include "vulkan_loader.h"
-#define FF_VK_DEFAULT_USAGE_FLAGS (VK_IMAGE_USAGE_SAMPLED_BIT | \
- VK_IMAGE_USAGE_STORAGE_BIT | \
- VK_IMAGE_USAGE_TRANSFER_SRC_BIT | \
- VK_IMAGE_USAGE_TRANSFER_DST_BIT)
-
/* GLSL management macros */
#define INDENT(N) INDENT_##N
#define INDENT_0
@@ -57,6 +54,8 @@
goto fail; \
} while (0)
+#define DUP_SAMPLER(x) { x, x, x, x }
+
typedef struct FFVkSPIRVShader {
const char *name; /* Name for id/debugging purposes */
AVBPrint src;
@@ -64,19 +63,6 @@ typedef struct FFVkSPIRVShader {
VkPipelineShaderStageCreateInfo shader;
} FFVkSPIRVShader;
-typedef struct FFVkSPIRVCompiler {
- void *priv;
- int (*compile_shader)(struct FFVkSPIRVCompiler *ctx, void *avctx,
- struct FFVkSPIRVShader *shd, uint8_t **data,
- size_t *size, const char *entrypoint, void **opaque);
- void (*free_shader)(struct FFVkSPIRVCompiler *ctx, void **opaque);
- void (*uninit)(struct FFVkSPIRVCompiler **ctx);
-} FFVkSPIRVCompiler;
-
-typedef struct FFVkSampler {
- VkSampler sampler[4];
-} FFVkSampler;
-
typedef struct FFVulkanDescriptorSetBinding {
const char *name;
VkDescriptorType type;
@@ -86,8 +72,7 @@ typedef struct FFVulkanDescriptorSetBinding {
uint32_t dimensions; /* Needed for e.g. sampler%iD */
uint32_t elems; /* 0 - scalar, 1 or more - vector */
VkShaderStageFlags stages;
- FFVkSampler *sampler; /* Sampler to use for all elems */
- void *updater; /* Pointer to VkDescriptor*Info */
+ VkSampler samplers[4]; /* Sampler to use for all elems */
} FFVulkanDescriptorSetBinding;
typedef struct FFVkBuffer {
@@ -95,119 +80,133 @@ typedef struct FFVkBuffer {
VkDeviceMemory mem;
VkMemoryPropertyFlagBits flags;
size_t size;
+ VkDeviceAddress address;
+
+ /* Local use only */
+ VkPipelineStageFlags2 stage;
+ VkAccessFlags2 access;
+
+ /* Only valid when allocated via ff_vk_get_pooled_buffer with HOST_VISIBLE */
+ uint8_t *mapped_mem;
} FFVkBuffer;
typedef struct FFVkQueueFamilyCtx {
int queue_family;
int nb_queues;
- int cur_queue;
- int actual_queues;
} FFVkQueueFamilyCtx;
-typedef struct FFVulkanPipeline {
- FFVkQueueFamilyCtx *qf;
+typedef struct FFVulkanDescriptorSet {
+ VkDescriptorSetLayout layout;
+ FFVkBuffer buf;
+ uint8_t *desc_mem;
+ VkDeviceSize layout_size;
+ VkDeviceSize aligned_size; /* descriptorBufferOffsetAlignment */
+ VkDeviceSize total_size; /* Once registered to an exec context */
+ VkBufferUsageFlags usage;
+
+ VkDescriptorSetLayoutBinding *binding;
+ VkDeviceSize *binding_offset;
+ int nb_bindings;
+ int read_only;
+} FFVulkanDescriptorSet;
+
+typedef struct FFVulkanPipeline {
VkPipelineBindPoint bind_point;
/* Contexts */
VkPipelineLayout pipeline_layout;
VkPipeline pipeline;
- /* Shaders */
- FFVkSPIRVShader **shaders;
- int shaders_num;
-
/* Push consts */
VkPushConstantRange *push_consts;
int push_consts_num;
+ /* Workgroup */
+ int wg_size[3];
+
/* Descriptors */
- VkDescriptorSetLayout *desc_layout;
- VkDescriptorPool desc_pool;
- VkDescriptorSet *desc_set;
-#if VK_USE_64_BIT_PTR_DEFINES == 1
- void **desc_staging;
-#else
- uint64_t *desc_staging;
-#endif
- VkDescriptorSetLayoutBinding **desc_binding;
- VkDescriptorUpdateTemplate *desc_template;
- int *desc_set_initialized;
- int desc_layout_num;
- int descriptor_sets_num;
- int total_descriptor_sets;
- int pool_size_desc_num;
-
- /* Temporary, used to store data in between initialization stages */
- VkDescriptorUpdateTemplateCreateInfo *desc_template_info;
- VkDescriptorPoolSize *pool_size_desc;
+ FFVulkanDescriptorSet *desc_set;
+ VkDescriptorBufferBindingInfoEXT *desc_bind;
+ uint32_t *bound_buffer_indices;
+ int nb_descriptor_sets;
} FFVulkanPipeline;
-typedef struct FFVkQueueCtx {
- VkFence fence;
+typedef struct FFVkExecContext {
+ int idx;
+ const struct FFVkExecPool *parent;
+
+ /* Queue for the execution context */
VkQueue queue;
+ int qf;
+ int qi;
+
+ /* Command buffer for the context */
+ VkCommandBuffer buf;
+
+ /* Fence for the command buffer */
+ VkFence fence;
- int synchronous;
- int submitted;
+ void *query_data;
+ int query_idx;
/* Buffer dependencies */
AVBufferRef **buf_deps;
int nb_buf_deps;
- int buf_deps_alloc_size;
+ unsigned int buf_deps_alloc_size;
/* Frame dependencies */
AVFrame **frame_deps;
+ unsigned int frame_deps_alloc_size;
int nb_frame_deps;
- int frame_deps_alloc_size;
-} FFVkQueueCtx;
-
-typedef struct FFVkExecContext {
- FFVkQueueFamilyCtx *qf;
- VkCommandPool pool;
- VkCommandBuffer *bufs;
- FFVkQueueCtx *queues;
-
- struct {
- int idx;
- VkQueryPool pool;
- uint8_t *data;
-
- int nb_queries;
- int nb_results;
- int nb_statuses;
- int elem_64bits;
- size_t data_per_queue;
- int status_stride;
- } query;
+ VkSemaphoreSubmitInfo *sem_wait;
+ unsigned int sem_wait_alloc;
+ int sem_wait_cnt;
- AVBufferRef ***deps;
- int *nb_deps;
- int *dep_alloc_size;
+ VkSemaphoreSubmitInfo *sem_sig;
+ unsigned int sem_sig_alloc;
+ int sem_sig_cnt;
- FFVulkanPipeline *bound_pl;
+ uint64_t **sem_sig_val_dst;
+ unsigned int sem_sig_val_dst_alloc;
+ int sem_sig_val_dst_cnt;
- VkSemaphore *sem_wait;
- int sem_wait_alloc; /* Allocated sem_wait */
- int sem_wait_cnt;
+ uint8_t *frame_locked;
+ unsigned int frame_locked_alloc_size;
- uint64_t *sem_wait_val;
- int sem_wait_val_alloc;
+ VkAccessFlagBits *access_dst;
+ unsigned int access_dst_alloc;
- VkPipelineStageFlagBits *sem_wait_dst;
- int sem_wait_dst_alloc; /* Allocated sem_wait_dst */
+ VkImageLayout *layout_dst;
+ unsigned int layout_dst_alloc;
- VkSemaphore *sem_sig;
- int sem_sig_alloc; /* Allocated sem_sig */
- int sem_sig_cnt;
+ uint32_t *queue_family_dst;
+ unsigned int queue_family_dst_alloc;
- uint64_t *sem_sig_val;
- int sem_sig_val_alloc;
-
- uint64_t **sem_sig_val_dst;
- int sem_sig_val_dst_alloc;
+ uint8_t *frame_update;
+ unsigned int frame_update_alloc_size;
} FFVkExecContext;
+typedef struct FFVkExecPool {
+ FFVkQueueFamilyCtx *qf;
+ FFVkExecContext *contexts;
+ atomic_int_least64_t idx;
+
+ VkCommandPool cmd_buf_pool;
+ VkCommandBuffer *cmd_bufs;
+ int pool_size;
+
+ VkQueryPool query_pool;
+ void *query_data;
+ int query_results;
+ int query_statuses;
+ int query_64bit;
+ int query_status_stride;
+ int nb_queries;
+ size_t qd_size;
+} FFVkExecPool;
+
typedef struct FFVulkanContext {
const AVClass *class; /* Filters and encoders use this */
@@ -216,14 +215,17 @@ typedef struct FFVulkanContext {
VkPhysicalDeviceProperties2 props;
VkPhysicalDeviceDriverProperties driver_props;
VkPhysicalDeviceMemoryProperties mprops;
+ VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops;
+ VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props;
VkQueueFamilyQueryResultStatusPropertiesKHR *query_props;
VkQueueFamilyVideoPropertiesKHR *video_props;
VkQueueFamilyProperties2 *qf_props;
+ int tot_nb_qfs;
- AVBufferRef *device_ref;
AVHWDeviceContext *device;
AVVulkanDeviceContext *hwctx;
+ AVBufferRef *input_frames_ref;
AVBufferRef *frames_ref;
AVHWFramesContext *frames;
AVVulkanFramesContext *hwfc;
@@ -231,28 +233,11 @@ typedef struct FFVulkanContext {
uint32_t qfs[5];
int nb_qfs;
- FFVkSPIRVCompiler *spirv_compiler;
-
/* Properties */
int output_width;
int output_height;
enum AVPixelFormat output_format;
enum AVPixelFormat input_format;
-
- /* Samplers */
- FFVkSampler **samplers;
- int samplers_num;
-
- /* Exec contexts */
- FFVkExecContext **exec_ctx;
- int exec_ctx_num;
-
- /* Pipelines (each can have 1 shader of each type) */
- FFVulkanPipeline **pipelines;
- int pipelines_num;
-
- void *scratch; /* Scratch memory used only in functions */
- unsigned int scratch_size;
} FFVulkanContext;
/* Identity mapping - r = r, b = b, g = g, a = a */
@@ -264,244 +249,207 @@ extern const VkComponentMapping ff_comp_identity_map;
const char *ff_vk_ret2str(VkResult res);
/**
- * Loads props/mprops/driver_props
- */
-int ff_vk_load_props(FFVulkanContext *s);
-
-/**
- * Returns 1 if the image is any sort of supported RGB
+ * Returns 1 if pixfmt is a usable RGB format.
*/
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt);
/**
- * Gets the glsl format string for a pixel format
+ * Returns the format to use for images in shaders.
*/
const char *ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt);
/**
- * Setup the queue families from the hardware device context.
- * Necessary for image creation to work.
- */
-void ff_vk_qf_fill(FFVulkanContext *s);
-
-/**
- * Allocate device memory.
- */
-int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req,
- VkMemoryPropertyFlagBits req_flags, void *alloc_extension,
- VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
-
-/**
- * Get a queue family index and the number of queues. nb is optional.
+ * Loads props/mprops/driver_props
*/
-int ff_vk_qf_get_index(FFVulkanContext *s, VkQueueFlagBits dev_family, int *nb);
+int ff_vk_load_props(FFVulkanContext *s);
/**
- * Initialize a queue family with a specific number of queues.
- * If nb_queues == 0, use however many queues the queue family has.
+ * Chooses a QF and loads it into a context.
*/
int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
- VkQueueFlagBits dev_family, int nb_queues);
-
-/**
- * Rotate through the queues in a queue family.
- */
-int ff_vk_qf_rotate(FFVkQueueFamilyCtx *qf);
-
-/**
- * Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit()
- */
-FFVkSampler *ff_vk_init_sampler(FFVulkanContext *s, int unnorm_coords,
- VkFilter filt);
+ VkQueueFlagBits dev_family);
/**
- * Create an imageview.
- * Guaranteed to remain alive until the queue submission has finished executing,
- * and will be destroyed after that.
+ * Allocates/frees an execution pool.
+ * ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add()
+ * has been called.
*/
-int ff_vk_create_imageview(FFVulkanContext *s, FFVkExecContext *e,
- VkImageView *v, VkImage img, VkFormat fmt,
- const VkComponentMapping map);
+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);
+void ff_vk_exec_pool_free(FFVulkanContext *s, FFVkExecPool *pool);
/**
- * Define a push constant for a given stage into a pipeline.
- * Must be called before the pipeline layout has been initialized.
+ * Retrieve an execution pool. Threadsafe.
*/
-int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size,
- VkShaderStageFlagBits stage);
+FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool);
/**
- * Inits a pipeline. Everything in it will be auto-freed when calling
- * ff_vk_filter_uninit().
+ * Performs nb_queries queries and returns their results and statuses.
+ * Execution must have been waited on to produce valid results.
*/
-FFVulkanPipeline *ff_vk_create_pipeline(FFVulkanContext *s, FFVkQueueFamilyCtx *qf);
+VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e,
+ void **data, int64_t *status);
/**
- * Inits a shader for a specific pipeline. Will be auto-freed on uninit.
+ * Start/submit/wait an execution.
+ * ff_vk_exec_start() always waits on a submission, so using ff_vk_exec_wait()
+ * is not necessary (unless using it is just better).
*/
-FFVkSPIRVShader *ff_vk_init_shader(FFVulkanPipeline *pl, const char *name,
- VkShaderStageFlags stage);
+int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e);
+int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e);
+void ff_vk_exec_wait(FFVulkanContext *s, FFVkExecContext *e);
/**
- * Writes the workgroup size for a shader.
+ * Execution dependency management.
+ * Can attach buffers to executions that will only be unref'd once the
+ * buffer has finished executing.
+ * Adding a frame dep will *lock the frame*, until either the dependencies
+ * are discarded, the execution is submitted, or a failure happens.
+ * update_frame will update the frame's properties before it is unlocked,
+ * only if submission was successful.
*/
-void ff_vk_set_compute_shader_sizes(FFVkSPIRVShader *shd, int local_size[3]);
+int ff_vk_exec_add_dep_buf(FFVulkanContext *s, FFVkExecContext *e,
+ AVBufferRef **deps, int nb_deps, int ref);
+int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f,
+ VkPipelineStageFlagBits2 wait_stage,
+ VkPipelineStageFlagBits2 signal_stage);
+void ff_vk_exec_update_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f,
+ VkImageMemoryBarrier2 *bar, uint32_t *nb_img_bar);
+int ff_vk_exec_mirror_sem_value(FFVulkanContext *s, FFVkExecContext *e,
+ VkSemaphore *dst, uint64_t *dst_val,
+ AVFrame *f);
+void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e);
/**
- * Adds a descriptor set to the shader and registers them in the pipeline.
+ * Create an imageview and add it as a dependency to an execution.
*/
-int ff_vk_add_descriptor_set(FFVulkanContext *s, FFVulkanPipeline *pl,
- FFVkSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc,
- int num, int only_print_to_shader);
+int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
+ VkImageView views[AV_NUM_DATA_POINTERS],
+ AVFrame *f);
-/**
- * Compiles the shader, entrypoint must be set to "main".
- */
-int ff_vk_compile_shader(FFVulkanContext *s, FFVkSPIRVShader *shd,
- const char *entrypoint);
+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);
/**
- * Pretty print shader, mainly used by shader compilers.
+ * Memory/buffer/image allocation helpers.
*/
-void ff_vk_print_shader(void *ctx, FFVkSPIRVShader *shd, int prio);
-
-/**
- * Initializes the pipeline layout after all shaders and descriptor sets have
- * been finished.
- */
-int ff_vk_init_pipeline_layout(FFVulkanContext *s, FFVulkanPipeline *pl);
+int ff_vk_alloc_mem(FFVulkanContext *s, VkMemoryRequirements *req,
+ VkMemoryPropertyFlagBits req_flags, void *alloc_extension,
+ VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem);
+int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size,
+ void *pNext, void *alloc_pNext,
+ VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags);
+int ff_vk_create_avbuf(FFVulkanContext *s, AVBufferRef **ref, size_t size,
+ void *pNext, void *alloc_pNext,
+ VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags);
/**
- * Initializes a compute pipeline. Will pick the first shader with the
- * COMPUTE flag set.
+ * Buffer management code.
*/
-int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl);
+int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer **buf, uint8_t *mem[],
+ int nb_buffers, int invalidate);
+int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer **buf, int nb_buffers,
+ int flush);
-/**
- * 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.
- */
-void ff_vk_update_descriptor_set(FFVulkanContext *s, FFVulkanPipeline *pl,
- int set_id);
+static inline int ff_vk_map_buffer(FFVulkanContext *s, FFVkBuffer *buf, uint8_t **mem,
+ int invalidate)
+{
+ return ff_vk_map_buffers(s, (FFVkBuffer *[]){ buf }, mem,
+ 1, invalidate);
+}
-/**
- * Init an execution context for command recording and queue submission.
- * WIll be auto-freed on uninit.
- */
-int ff_vk_create_exec_ctx(FFVulkanContext *s, FFVkExecContext **ctx,
- FFVkQueueFamilyCtx *qf);
+static inline int ff_vk_unmap_buffer(FFVulkanContext *s, FFVkBuffer *buf, int flush)
+{
+ return ff_vk_unmap_buffers(s, (FFVkBuffer *[]){ buf }, 1, flush);
+}
-/**
- * Create a query pool for a command context.
- * elem_64bits exists to troll driver devs for compliance. All results
- * and statuses returned should be 32 bits, unless this is set, then it's 64bits.
- */
-int ff_vk_create_exec_ctx_query_pool(FFVulkanContext *s, FFVkExecContext *e,
- int nb_queries, VkQueryType type,
- int elem_64bits, void *create_pnext);
+void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf);
-/**
- * Get results for query.
- * Returns the status of the query.
- * Sets *res to the status of the queries.
- */
-int ff_vk_get_exec_ctx_query_results(FFVulkanContext *s, FFVkExecContext *e,
- int query_idx, void **data, int64_t *status);
+/** Initialize a pool and create AVBufferRefs containing FFVkBuffer.
+ * Threadsafe to use. Buffers are automatically mapped on creation if
+ * VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT is set in mem_props. Users should
+ * synchronize access themselvesd. Mainly meant for device-local buffers. */
+int ff_vk_get_pooled_buffer(FFVulkanContext *ctx, AVBufferPool **buf_pool,
+ AVBufferRef **buf, VkBufferUsageFlags usage,
+ void *create_pNext, size_t size,
+ VkMemoryPropertyFlagBits mem_props);
/**
- * Begin recording to the command buffer. Previous execution must have been
- * completed, which ff_vk_submit_exec_queue() will ensure.
+ * Create a sampler.
*/
-int ff_vk_start_exec_recording(FFVulkanContext *s, FFVkExecContext *e);
+int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler,
+ int unnorm_coords, VkFilter filt);
/**
- * Add a command to bind the completed pipeline and its descriptor sets.
- * Must be called after ff_vk_start_exec_recording() and before submission.
+ * Shader management.
*/
-void ff_vk_bind_pipeline_exec(FFVulkanContext *s, FFVkExecContext *e,
- FFVulkanPipeline *pl);
+int ff_vk_shader_init(FFVulkanPipeline *pl, FFVkSPIRVShader *shd, const char *name,
+ VkShaderStageFlags stage);
+void ff_vk_shader_set_compute_sizes(FFVkSPIRVShader *shd, int x, int y, int z);
+void ff_vk_shader_print(void *ctx, FFVkSPIRVShader *shd, int prio);
+int ff_vk_shader_create(FFVulkanContext *s, FFVkSPIRVShader *shd,
+ uint8_t *spirv, size_t spirv_size, const char *entrypoint);
+void ff_vk_shader_free(FFVulkanContext *s, FFVkSPIRVShader *shd);
/**
- * Updates push constants.
- * Must be called after binding a pipeline if any push constants were defined.
+ * Add/update push constants for execution.
*/
+int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size,
+ VkShaderStageFlagBits stage);
void ff_vk_update_push_exec(FFVulkanContext *s, FFVkExecContext *e,
- VkShaderStageFlagBits stage, int offset,
- size_t size, void *src);
+ FFVulkanPipeline *pl,
+ VkShaderStageFlagBits stage,
+ int offset, size_t size, void *src);
/**
- * Gets the command buffer to use for this submission from the exe context.
+ * Add descriptor to a pipeline. Must be called before pipeline init.
*/
-VkCommandBuffer ff_vk_get_exec_buf(FFVkExecContext *e);
+int ff_vk_pipeline_descriptor_set_add(FFVulkanContext *s, FFVulkanPipeline *pl,
+ FFVkSPIRVShader *shd,
+ FFVulkanDescriptorSetBinding *desc, int nb,
+ int read_only, int print_to_shader_only);
-/**
- * Adds a generic AVBufferRef as a queue depenency.
- */
-int ff_vk_add_dep_exec_ctx(FFVulkanContext *s, FFVkExecContext *e,
- AVBufferRef **deps, int nb_deps);
-
-/**
- * Discards all queue dependencies
- */
-void ff_vk_discard_exec_deps(FFVkExecContext *e);
+/* Initialize/free a pipeline. */
+int ff_vk_init_compute_pipeline(FFVulkanContext *s, FFVulkanPipeline *pl,
+ FFVkSPIRVShader *shd);
+void ff_vk_pipeline_free(FFVulkanContext *s, FFVulkanPipeline *pl);
/**
- * Adds a frame as a queue dependency. This also manages semaphore signalling.
- * Must be called before submission.
+ * Register a pipeline with an exec pool.
+ * Pool may be NULL if all descriptor sets are read-only.
*/
-int ff_vk_add_exec_dep(FFVulkanContext *s, FFVkExecContext *e, AVFrame *frame,
- VkPipelineStageFlagBits in_wait_dst_flag);
+int ff_vk_exec_pipeline_register(FFVulkanContext *s, FFVkExecPool *pool,
+ FFVulkanPipeline *pl);
-/**
- * Submits a command buffer to the queue for execution. Will not block.
- */
-int ff_vk_submit_exec_queue(FFVulkanContext *s, FFVkExecContext *e);
-
-/**
- * Wait on a command buffer's execution. Mainly useful for debugging and
- * development.
- */
-void ff_vk_wait_on_exec_ctx(FFVulkanContext *s, FFVkExecContext *e);
-
-/**
- * Create a VkBuffer with the specified parameters.
- */
-int ff_vk_create_buf(FFVulkanContext *s, FFVkBuffer *buf, size_t size,
- void *pNext, void *alloc_pNext,
- VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags);
-
-/**
- * Maps the buffer to userspace. Set invalidate to 1 if reading the contents
- * is necessary.
- */
-int ff_vk_map_buffers(FFVulkanContext *s, FFVkBuffer *buf, uint8_t *mem[],
- int nb_buffers, int invalidate);
-
-/**
- * Unmaps the buffer from userspace. Set flush to 1 to write and sync.
- */
-int ff_vk_unmap_buffers(FFVulkanContext *s, FFVkBuffer *buf, int nb_buffers,
- int flush);
+/* Bind pipeline */
+void ff_vk_exec_bind_pipeline(FFVulkanContext *s, FFVkExecContext *e,
+ FFVulkanPipeline *pl);
-/**
- * Frees a buffer.
- */
-void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf);
+/* Update sampler/image/buffer descriptors. e may be NULL for read-only descriptors. */
+int ff_vk_set_descriptor_sampler(FFVulkanContext *s, FFVulkanPipeline *pl,
+ FFVkExecContext *e, int set, int bind, int offs,
+ VkSampler *sampler);
+int ff_vk_set_descriptor_image(FFVulkanContext *s, FFVulkanPipeline *pl,
+ FFVkExecContext *e, int set, int bind, int offs,
+ VkImageView view, VkImageLayout layout, VkSampler sampler);
+int ff_vk_set_descriptor_buffer(FFVulkanContext *s, FFVulkanPipeline *pl,
+ FFVkExecContext *e, int set, int bind, int offs,
+ VkDeviceAddress addr, VkDeviceSize len, VkFormat fmt);
-/**
- * Creates an image, allocates and binds memory in the given
- * idx value of the dst frame. If mem is non-NULL, then no memory will be
- * allocated, but instead the given memory will be bound to the image.
- */
-int ff_vk_image_create(FFVulkanContext *s, AVVkFrame *dst, int idx,
- int width, int height, VkFormat fmt, VkImageTiling tiling,
- VkImageUsageFlagBits usage, VkImageCreateFlags flags,
- void *create_pnext,
- VkDeviceMemory *mem, void *alloc_pnext);
+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);
/**
- * Frees the main Vulkan context.
+ * Frees main context.
*/
void ff_vk_uninit(FFVulkanContext *s);