diff options
author | Lynne <dev@lynne.ee> | 2021-11-10 03:50:54 +0100 |
---|---|---|
committer | Lynne <dev@lynne.ee> | 2021-11-12 05:23:41 +0100 |
commit | f705e9ea0567c8dcf800ae1ee0647fca157c6199 (patch) | |
tree | 529e20c9015f3ee93e297097d77f38ba52c29037 /libavfilter/vulkan.h | |
parent | 246f841b53e16f2cccf3101cb61c264014f54e5c (diff) | |
download | ffmpeg-f705e9ea0567c8dcf800ae1ee0647fca157c6199.tar.gz |
lavfi/vulkan: refactor, fix and fully implement multiple queues
Diffstat (limited to 'libavfilter/vulkan.h')
-rw-r--r-- | libavfilter/vulkan.h | 103 |
1 files changed, 66 insertions, 37 deletions
diff --git a/libavfilter/vulkan.h b/libavfilter/vulkan.h index 89b76ba355..9d17d2b14f 100644 --- a/libavfilter/vulkan.h +++ b/libavfilter/vulkan.h @@ -20,6 +20,7 @@ #define AVFILTER_VULKAN_H #define VK_NO_PROTOTYPES +#define VK_ENABLE_BETA_EXTENSIONS #include "avfilter.h" #include "libavutil/pixdesc.h" @@ -52,9 +53,6 @@ goto fail; \ } while (0) -/* Useful for attaching immutable samplers to arrays */ -#define DUP_SAMPLER_ARRAY4(x) (VkSampler []){ x, x, x, x, } - typedef struct FFSPIRVShader { const char *name; /* Name for id/debugging purposes */ AVBPrint src; @@ -62,7 +60,11 @@ typedef struct FFSPIRVShader { VkPipelineShaderStageCreateInfo shader; } FFSPIRVShader; -typedef struct VulkanDescriptorSetBinding { +typedef struct FFVkSampler { + VkSampler sampler[4]; +} FFVkSampler; + +typedef struct FFVulkanDescriptorSetBinding { const char *name; VkDescriptorType type; const char *mem_layout; /* Storage images (rgba8, etc.) and buffers (std430, etc.) */ @@ -71,9 +73,9 @@ typedef struct VulkanDescriptorSetBinding { uint32_t dimensions; /* Needed for e.g. sampler%iD */ uint32_t elems; /* 0 - scalar, 1 or more - vector */ VkShaderStageFlags stages; - const VkSampler *samplers; /* Immutable samplers, length - #elems */ + FFVkSampler *sampler; /* Sampler to use for all elems */ void *updater; /* Pointer to VkDescriptor*Info */ -} VulkanDescriptorSetBinding; +} FFVulkanDescriptorSetBinding; typedef struct FFVkBuffer { VkBuffer buf; @@ -81,7 +83,15 @@ typedef struct FFVkBuffer { VkMemoryPropertyFlagBits flags; } FFVkBuffer; -typedef struct VulkanPipeline { +typedef struct FFVkQueueFamilyCtx { + int queue_family; + int nb_queues; + int cur_queue; +} FFVkQueueFamilyCtx; + +typedef struct FFVulkanPipeline { + FFVkQueueFamilyCtx *qf; + VkPipelineBindPoint bind_point; /* Contexts */ @@ -97,18 +107,21 @@ typedef struct VulkanPipeline { int push_consts_num; /* Descriptors */ - VkDescriptorSetLayout *desc_layout; - VkDescriptorPool desc_pool; - VkDescriptorSet *desc_set; - VkDescriptorUpdateTemplate *desc_template; - int desc_layout_num; - int descriptor_sets_num; - int pool_size_desc_num; + VkDescriptorSetLayout *desc_layout; + VkDescriptorPool desc_pool; + VkDescriptorSet *desc_set; + void **desc_staging; + VkDescriptorSetLayoutBinding **desc_binding; + VkDescriptorUpdateTemplate *desc_template; + 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; -} VulkanPipeline; +} FFVulkanPipeline; typedef struct FFVkQueueCtx { VkFence fence; @@ -126,6 +139,8 @@ typedef struct FFVkQueueCtx { } FFVkQueueCtx; typedef struct FFVkExecContext { + FFVkQueueFamilyCtx *qf; + VkCommandPool pool; VkCommandBuffer *bufs; FFVkQueueCtx *queues; @@ -134,7 +149,7 @@ typedef struct FFVkExecContext { int *nb_deps; int *dep_alloc_size; - VulkanPipeline *bound_pl; + FFVulkanPipeline *bound_pl; VkSemaphore *sem_wait; int sem_wait_alloc; /* Allocated sem_wait */ @@ -152,23 +167,23 @@ typedef struct FFVkExecContext { uint64_t *sem_sig_val; int sem_sig_val_alloc; + + uint64_t **sem_sig_val_dst; + int sem_sig_val_dst_alloc; } FFVkExecContext; -typedef struct VulkanFilterContext { +typedef struct FFVulkanContext { const AVClass *class; FFVulkanFunctions vkfn; FFVulkanExtensions extensions; + VkPhysicalDeviceProperties props; + VkPhysicalDeviceMemoryProperties mprops; AVBufferRef *device_ref; AVBufferRef *frames_ref; /* For in-place filtering */ AVHWDeviceContext *device; AVVulkanDeviceContext *hwctx; - /* State - mirrored with the exec ctx */ - int cur_queue_idx; - int queue_family_idx; - int queue_count; - /* Properties */ int output_width; int output_height; @@ -176,7 +191,7 @@ typedef struct VulkanFilterContext { enum AVPixelFormat input_format; /* Samplers */ - VkSampler **samplers; + FFVkSampler **samplers; int samplers_num; /* Exec contexts */ @@ -184,12 +199,12 @@ typedef struct VulkanFilterContext { int exec_ctx_num; /* Pipelines (each can have 1 shader of each type) */ - VulkanPipeline **pipelines; + FFVulkanPipeline **pipelines; int pipelines_num; void *scratch; /* Scratch memory used only in functions */ unsigned int scratch_size; -} VulkanFilterContext; +} FFVulkanContext; /* Identity mapping - r = r, b = b, g = g, a = a */ extern const VkComponentMapping ff_comp_identity_map; @@ -219,10 +234,22 @@ int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt); const char *ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt); /** + * Initialize a queue family. + * A queue limit of 0 means no limit. + */ +void ff_vk_qf_init(AVFilterContext *avctx, FFVkQueueFamilyCtx *qf, + VkQueueFlagBits dev_family, int queue_limit); + +/** + * Rotate through the queues in a queue family. + */ +void ff_vk_qf_rotate(FFVkQueueFamilyCtx *qf); + +/** * Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit() */ -VkSampler *ff_vk_init_sampler(AVFilterContext *avctx, int unnorm_coords, - VkFilter filt); +FFVkSampler *ff_vk_init_sampler(AVFilterContext *avctx, int unnorm_coords, + VkFilter filt); /** * Create an imageview. @@ -237,19 +264,20 @@ int ff_vk_create_imageview(AVFilterContext *avctx, FFVkExecContext *e, * Define a push constant for a given stage into a pipeline. * Must be called before the pipeline layout has been initialized. */ -int ff_vk_add_push_constant(AVFilterContext *avctx, VulkanPipeline *pl, +int ff_vk_add_push_constant(AVFilterContext *avctx, FFVulkanPipeline *pl, int offset, int size, VkShaderStageFlagBits stage); /** * Inits a pipeline. Everything in it will be auto-freed when calling * ff_vk_filter_uninit(). */ -VulkanPipeline *ff_vk_create_pipeline(AVFilterContext *avctx); +FFVulkanPipeline *ff_vk_create_pipeline(AVFilterContext *avctx, + FFVkQueueFamilyCtx *qf); /** * Inits a shader for a specific pipeline. Will be auto-freed on uninit. */ -FFSPIRVShader *ff_vk_init_shader(AVFilterContext *avctx, VulkanPipeline *pl, +FFSPIRVShader *ff_vk_init_shader(AVFilterContext *avctx, FFVulkanPipeline *pl, const char *name, VkShaderStageFlags stage); /** @@ -261,8 +289,8 @@ void ff_vk_set_compute_shader_sizes(AVFilterContext *avctx, FFSPIRVShader *shd, /** * Adds a descriptor set to the shader and registers them in the pipeline. */ -int ff_vk_add_descriptor_set(AVFilterContext *avctx, VulkanPipeline *pl, - FFSPIRVShader *shd, VulkanDescriptorSetBinding *desc, +int ff_vk_add_descriptor_set(AVFilterContext *avctx, FFVulkanPipeline *pl, + FFSPIRVShader *shd, FFVulkanDescriptorSetBinding *desc, int num, int only_print_to_shader); /** @@ -280,27 +308,28 @@ void ff_vk_print_shader(AVFilterContext *avctx, FFSPIRVShader *shd, int prio); * Initializes the pipeline layout after all shaders and descriptor sets have * been finished. */ -int ff_vk_init_pipeline_layout(AVFilterContext *avctx, VulkanPipeline *pl); +int ff_vk_init_pipeline_layout(AVFilterContext *avctx, FFVulkanPipeline *pl); /** * Initializes a compute pipeline. Will pick the first shader with the * COMPUTE flag set. */ -int ff_vk_init_compute_pipeline(AVFilterContext *avctx, VulkanPipeline *pl); +int ff_vk_init_compute_pipeline(AVFilterContext *avctx, FFVulkanPipeline *pl); /** * 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(AVFilterContext *avctx, VulkanPipeline *pl, +void ff_vk_update_descriptor_set(AVFilterContext *avctx, FFVulkanPipeline *pl, int set_id); /** * Init an execution context for command recording and queue submission. * WIll be auto-freed on uninit. */ -int ff_vk_create_exec_ctx(AVFilterContext *avctx, FFVkExecContext **ctx); +int ff_vk_create_exec_ctx(AVFilterContext *avctx, FFVkExecContext **ctx, + FFVkQueueFamilyCtx *qf); /** * Begin recording to the command buffer. Previous execution must have been @@ -313,7 +342,7 @@ int ff_vk_start_exec_recording(AVFilterContext *avctx, FFVkExecContext *e); * Must be called after ff_vk_start_exec_recording() and before submission. */ void ff_vk_bind_pipeline_exec(AVFilterContext *avctx, FFVkExecContext *e, - VulkanPipeline *pl); + FFVulkanPipeline *pl); /** * Updates push constants. |