2021-11-19 06:46:15 +00:00
|
|
|
/*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AVUTIL_VULKAN_H
|
|
|
|
#define AVUTIL_VULKAN_H
|
|
|
|
|
2022-11-23 13:04:48 +00:00
|
|
|
#define VK_NO_PROTOTYPES
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
#include <stdatomic.h>
|
|
|
|
|
2023-06-06 22:24:43 +00:00
|
|
|
#include "thread.h"
|
2021-11-19 06:46:15 +00:00
|
|
|
#include "pixdesc.h"
|
|
|
|
#include "bprint.h"
|
|
|
|
#include "hwcontext.h"
|
|
|
|
#include "vulkan_functions.h"
|
2021-11-19 14:17:24 +00:00
|
|
|
#include "hwcontext_vulkan.h"
|
lavfi/vulkan: split off lavfi-specific code into vulkan_filter.c
The issue is that libavfilter depends on libavcodec, and when doing a
static build, if libavcodec also includes "libavfilter/vulkan.c", then
during link-time, compiling programs will fail as there would be multiple
definitions of the same symbols in both libavfilter and libavcodec's
object files.
Linkers are, however, more permitting if both files that include
a common file that's used as a template are one-to-one identical.
Hence, to make both files the same in the future, export all avfilter
specific functions to a separate file.
There is some work in progress to make templated files like this be
compiled only once, so this is not a long-term solution.
This also removes a macro that could be used to toggle SPIRV compilation
capability on #include-time, as this could cause the files to be different.
2021-11-19 14:13:35 +00:00
|
|
|
#include "vulkan_loader.h"
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/* GLSL management macros */
|
|
|
|
#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"
|
2023-03-24 01:22:06 +00:00
|
|
|
|
|
|
|
#define GLSLC(N, S) \
|
|
|
|
do { \
|
|
|
|
av_bprintf(&shd->src, C(N, S)); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define GLSLA(...) \
|
|
|
|
do { \
|
|
|
|
av_bprintf(&shd->src, __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define GLSLF(N, S, ...) \
|
|
|
|
do { \
|
|
|
|
av_bprintf(&shd->src, C(N, S), __VA_ARGS__); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define GLSLD(D) \
|
|
|
|
do { \
|
|
|
|
av_bprintf(&shd->src, "\n"); \
|
|
|
|
av_bprint_append_data(&shd->src, D, strlen(D)); \
|
|
|
|
av_bprintf(&shd->src, "\n"); \
|
|
|
|
} while (0)
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/* Helper, pretty much every Vulkan return value needs to be checked */
|
|
|
|
#define RET(x) \
|
|
|
|
do { \
|
|
|
|
if ((err = (x)) < 0) \
|
|
|
|
goto fail; \
|
|
|
|
} while (0)
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
#define DUP_SAMPLER(x) { x, x, x, x }
|
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
typedef struct FFVkSPIRVShader {
|
|
|
|
const char *name; /* Name for id/debugging purposes */
|
|
|
|
AVBPrint src;
|
|
|
|
int local_size[3]; /* Compute shader workgroup sizes */
|
|
|
|
VkPipelineShaderStageCreateInfo shader;
|
2023-03-05 23:19:12 +00:00
|
|
|
VkPipelineShaderStageRequiredSubgroupSizeCreateInfo subgroup_info;
|
2021-11-19 06:46:15 +00:00
|
|
|
} FFVkSPIRVShader;
|
|
|
|
|
|
|
|
typedef struct FFVulkanDescriptorSetBinding {
|
|
|
|
const char *name;
|
|
|
|
VkDescriptorType type;
|
|
|
|
const char *mem_layout; /* Storage images (rgba8, etc.) and buffers (std430, etc.) */
|
|
|
|
const char *mem_quali; /* readonly, writeonly, etc. */
|
|
|
|
const char *buf_content; /* For buffers */
|
|
|
|
uint32_t dimensions; /* Needed for e.g. sampler%iD */
|
|
|
|
uint32_t elems; /* 0 - scalar, 1 or more - vector */
|
|
|
|
VkShaderStageFlags stages;
|
2022-12-29 20:16:21 +00:00
|
|
|
VkSampler samplers[4]; /* Sampler to use for all elems */
|
2021-11-19 06:46:15 +00:00
|
|
|
} FFVulkanDescriptorSetBinding;
|
|
|
|
|
|
|
|
typedef struct FFVkBuffer {
|
|
|
|
VkBuffer buf;
|
|
|
|
VkDeviceMemory mem;
|
|
|
|
VkMemoryPropertyFlagBits flags;
|
2022-12-16 00:47:42 +00:00
|
|
|
size_t size;
|
2022-12-29 20:16:21 +00:00
|
|
|
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;
|
2021-11-19 06:46:15 +00:00
|
|
|
} FFVkBuffer;
|
|
|
|
|
|
|
|
typedef struct FFVkQueueFamilyCtx {
|
|
|
|
int queue_family;
|
|
|
|
int nb_queues;
|
|
|
|
} FFVkQueueFamilyCtx;
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
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;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
int read_only;
|
|
|
|
} FFVulkanDescriptorSet;
|
|
|
|
|
|
|
|
typedef struct FFVulkanPipeline {
|
2021-11-19 06:46:15 +00:00
|
|
|
VkPipelineBindPoint bind_point;
|
|
|
|
|
|
|
|
/* Contexts */
|
|
|
|
VkPipelineLayout pipeline_layout;
|
|
|
|
VkPipeline pipeline;
|
|
|
|
|
|
|
|
/* Push consts */
|
|
|
|
VkPushConstantRange *push_consts;
|
|
|
|
int push_consts_num;
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
/* Workgroup */
|
|
|
|
int wg_size[3];
|
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
/* Descriptors */
|
2022-12-29 20:16:21 +00:00
|
|
|
FFVulkanDescriptorSet *desc_set;
|
|
|
|
VkDescriptorBufferBindingInfoEXT *desc_bind;
|
|
|
|
uint32_t *bound_buffer_indices;
|
|
|
|
int nb_descriptor_sets;
|
2021-11-19 06:46:15 +00:00
|
|
|
} FFVulkanPipeline;
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
typedef struct FFVkExecContext {
|
|
|
|
int idx;
|
|
|
|
const struct FFVkExecPool *parent;
|
2023-06-06 22:24:43 +00:00
|
|
|
pthread_mutex_t lock;
|
2022-12-29 20:16:21 +00:00
|
|
|
|
|
|
|
/* Queue for the execution context */
|
2021-11-19 06:46:15 +00:00
|
|
|
VkQueue queue;
|
2022-12-29 20:16:21 +00:00
|
|
|
int qf;
|
|
|
|
int qi;
|
|
|
|
|
|
|
|
/* Command buffer for the context */
|
|
|
|
VkCommandBuffer buf;
|
|
|
|
|
|
|
|
/* Fence for the command buffer */
|
|
|
|
VkFence fence;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
void *query_data;
|
|
|
|
int query_idx;
|
2022-12-22 04:02:50 +00:00
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
/* Buffer dependencies */
|
|
|
|
AVBufferRef **buf_deps;
|
|
|
|
int nb_buf_deps;
|
2022-12-29 20:16:21 +00:00
|
|
|
unsigned int buf_deps_alloc_size;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/* Frame dependencies */
|
|
|
|
AVFrame **frame_deps;
|
2022-12-29 20:16:21 +00:00
|
|
|
unsigned int frame_deps_alloc_size;
|
2021-11-19 06:46:15 +00:00
|
|
|
int nb_frame_deps;
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
VkSemaphoreSubmitInfo *sem_wait;
|
|
|
|
unsigned int sem_wait_alloc;
|
|
|
|
int sem_wait_cnt;
|
2022-12-22 04:03:32 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
VkSemaphoreSubmitInfo *sem_sig;
|
|
|
|
unsigned int sem_sig_alloc;
|
|
|
|
int sem_sig_cnt;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
uint64_t **sem_sig_val_dst;
|
|
|
|
unsigned int sem_sig_val_dst_alloc;
|
|
|
|
int sem_sig_val_dst_cnt;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
uint8_t *frame_locked;
|
|
|
|
unsigned int frame_locked_alloc_size;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
VkAccessFlagBits *access_dst;
|
|
|
|
unsigned int access_dst_alloc;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
VkImageLayout *layout_dst;
|
|
|
|
unsigned int layout_dst_alloc;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
uint32_t *queue_family_dst;
|
|
|
|
unsigned int queue_family_dst_alloc;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
uint8_t *frame_update;
|
|
|
|
unsigned int frame_update_alloc_size;
|
2021-11-19 06:46:15 +00:00
|
|
|
} FFVkExecContext;
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
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;
|
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
typedef struct FFVulkanContext {
|
|
|
|
const AVClass *class; /* Filters and encoders use this */
|
|
|
|
|
|
|
|
FFVulkanFunctions vkfn;
|
|
|
|
FFVulkanExtensions extensions;
|
2022-12-19 06:57:22 +00:00
|
|
|
VkPhysicalDeviceProperties2 props;
|
|
|
|
VkPhysicalDeviceDriverProperties driver_props;
|
2021-11-19 06:46:15 +00:00
|
|
|
VkPhysicalDeviceMemoryProperties mprops;
|
2022-12-29 20:16:21 +00:00
|
|
|
VkPhysicalDeviceExternalMemoryHostPropertiesEXT hprops;
|
|
|
|
VkPhysicalDeviceDescriptorBufferPropertiesEXT desc_buf_props;
|
2023-03-05 23:19:12 +00:00
|
|
|
VkPhysicalDeviceSubgroupSizeControlProperties subgroup_props;
|
2022-12-22 16:37:51 +00:00
|
|
|
VkQueueFamilyQueryResultStatusPropertiesKHR *query_props;
|
|
|
|
VkQueueFamilyVideoPropertiesKHR *video_props;
|
|
|
|
VkQueueFamilyProperties2 *qf_props;
|
2022-12-29 20:16:21 +00:00
|
|
|
int tot_nb_qfs;
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2023-04-13 10:18:12 +00:00
|
|
|
VkPhysicalDeviceShaderAtomicFloatFeaturesEXT atomic_float_feats;
|
|
|
|
VkPhysicalDeviceVulkan12Features feats_12;
|
|
|
|
VkPhysicalDeviceFeatures2 feats;
|
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
AVHWDeviceContext *device;
|
|
|
|
AVVulkanDeviceContext *hwctx;
|
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
AVBufferRef *input_frames_ref;
|
2021-11-19 06:46:15 +00:00
|
|
|
AVBufferRef *frames_ref;
|
|
|
|
AVHWFramesContext *frames;
|
|
|
|
AVVulkanFramesContext *hwfc;
|
|
|
|
|
2022-11-23 12:03:58 +00:00
|
|
|
uint32_t qfs[5];
|
|
|
|
int nb_qfs;
|
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
/* Properties */
|
|
|
|
int output_width;
|
|
|
|
int output_height;
|
|
|
|
enum AVPixelFormat output_format;
|
|
|
|
enum AVPixelFormat input_format;
|
|
|
|
} FFVulkanContext;
|
|
|
|
|
2023-01-11 08:37:18 +00:00
|
|
|
static inline int ff_vk_count_images(AVVkFrame *f)
|
|
|
|
{
|
|
|
|
int cnt = 0;
|
|
|
|
while (f->img[cnt])
|
|
|
|
cnt++;
|
|
|
|
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2023-03-02 12:02:25 +00:00
|
|
|
static inline const void *ff_vk_find_struct(const void *chain, VkStructureType stype)
|
|
|
|
{
|
|
|
|
const VkBaseInStructure *in = chain;
|
|
|
|
while (in) {
|
|
|
|
if (in->sType == stype)
|
|
|
|
return in;
|
|
|
|
|
|
|
|
in = in->pNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
/* Identity mapping - r = r, b = b, g = g, a = a */
|
|
|
|
extern const VkComponentMapping ff_comp_identity_map;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts Vulkan return values to strings
|
|
|
|
*/
|
|
|
|
const char *ff_vk_ret2str(VkResult res);
|
|
|
|
|
2022-12-19 06:57:22 +00:00
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Returns 1 if pixfmt is a usable RGB format.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
|
|
|
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt);
|
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Returns the format to use for images in shaders.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
|
|
|
const char *ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt);
|
|
|
|
|
2022-11-23 12:03:58 +00:00
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Loads props/mprops/driver_props
|
2022-12-22 16:37:51 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
int ff_vk_load_props(FFVulkanContext *s);
|
2022-12-22 16:37:51 +00:00
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Chooses a QF and loads it into a context.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-22 16:37:51 +00:00
|
|
|
int ff_vk_qf_init(FFVulkanContext *s, FFVkQueueFamilyCtx *qf,
|
2022-12-29 20:16:21 +00:00
|
|
|
VkQueueFlagBits dev_family);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Allocates/frees an execution pool.
|
|
|
|
* ff_vk_exec_pool_init_desc() MUST be called if ff_vk_exec_descriptor_set_add()
|
|
|
|
* has been called.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Retrieve an execution pool. Threadsafe.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
FFVkExecContext *ff_vk_exec_get(FFVkExecPool *pool);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Performs nb_queries queries and returns their results and statuses.
|
|
|
|
* Execution must have been waited on to produce valid results.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
VkResult ff_vk_exec_get_query(FFVulkanContext *s, FFVkExecContext *e,
|
|
|
|
void **data, int64_t *status);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* 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).
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* 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.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Create an imageview and add it as a dependency to an execution.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
int ff_vk_create_imageviews(FFVulkanContext *s, FFVkExecContext *e,
|
|
|
|
VkImageView views[AV_NUM_DATA_POINTERS],
|
|
|
|
AVFrame *f);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Memory/buffer/image allocation helpers.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Buffer management code.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
|
|
|
}
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
static inline int ff_vk_unmap_buffer(FFVulkanContext *s, FFVkBuffer *buf, int flush)
|
|
|
|
{
|
|
|
|
return ff_vk_unmap_buffers(s, (FFVkBuffer *[]){ buf }, 1, flush);
|
|
|
|
}
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
void ff_vk_free_buf(FFVulkanContext *s, FFVkBuffer *buf);
|
2022-12-22 04:03:32 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
/** 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);
|
2022-12-22 04:03:32 +00:00
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Create a sampler.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
int ff_vk_init_sampler(FFVulkanContext *s, VkSampler *sampler,
|
|
|
|
int unnorm_coords, VkFilter filt);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Shader management.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
int ff_vk_shader_init(FFVulkanPipeline *pl, FFVkSPIRVShader *shd, const char *name,
|
2023-03-05 23:19:12 +00:00
|
|
|
VkShaderStageFlags stage, uint32_t required_subgroup_size);
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Add/update push constants for execution.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
int ff_vk_add_push_constant(FFVulkanPipeline *pl, int offset, int size,
|
|
|
|
VkShaderStageFlagBits stage);
|
2021-11-19 06:46:15 +00:00
|
|
|
void ff_vk_update_push_exec(FFVulkanContext *s, FFVkExecContext *e,
|
2022-12-29 20:16:21 +00:00
|
|
|
FFVulkanPipeline *pl,
|
|
|
|
VkShaderStageFlagBits stage,
|
|
|
|
int offset, size_t size, void *src);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Add descriptor to a pipeline. Must be called before pipeline init.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
/* 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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Register a pipeline with an exec pool.
|
|
|
|
* Pool may be NULL if all descriptor sets are read-only.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
2022-12-29 20:16:21 +00:00
|
|
|
int ff_vk_exec_pipeline_register(FFVulkanContext *s, FFVkExecPool *pool,
|
|
|
|
FFVulkanPipeline *pl);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
/* Bind pipeline */
|
|
|
|
void ff_vk_exec_bind_pipeline(FFVulkanContext *s, FFVkExecContext *e,
|
|
|
|
FFVulkanPipeline *pl);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
/* 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);
|
2021-11-19 06:46:15 +00:00
|
|
|
|
2022-12-29 20:16:21 +00:00
|
|
|
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);
|
2022-11-23 12:05:59 +00:00
|
|
|
|
2021-11-19 06:46:15 +00:00
|
|
|
/**
|
2022-12-29 20:16:21 +00:00
|
|
|
* Frees main context.
|
2021-11-19 06:46:15 +00:00
|
|
|
*/
|
|
|
|
void ff_vk_uninit(FFVulkanContext *s);
|
|
|
|
|
|
|
|
#endif /* AVUTIL_VULKAN_H */
|