40 VkImageUsageFlagBits usage_req;
45 vk_frames = frames_ctx->
hwctx;
46 vk_dev = device_ctx->
hwctx;
58 if (vk_frames->
tiling == VK_IMAGE_TILING_LINEAR)
71 usage_req = VK_IMAGE_USAGE_SAMPLED_BIT |
72 VK_IMAGE_USAGE_STORAGE_BIT;
76 if (vk_frames->
format[1] == VK_FORMAT_UNDEFINED &&
79 VkFormatProperties3 fprops = {
80 .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_3,
82 VkFormatProperties2 prop = {
83 .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
86 vk->GetPhysicalDeviceFormatProperties2(vk_dev->
phys_dev,
89 if (fprops.optimalTilingFeatures & VK_FORMAT_FEATURE_2_VIDEO_ENCODE_INPUT_BIT_KHR)
90 usage_req |= VK_IMAGE_USAGE_VIDEO_ENCODE_SRC_BIT_KHR;
93 if ((vk_frames->
usage & usage_req) != usage_req)
97 for (
int i = 0; sub[
i] != VK_FORMAT_UNDEFINED;
i++) {
98 VkFormatProperties2 prop = {
99 .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
101 vk->GetPhysicalDeviceFormatProperties2(vk_dev->
phys_dev, sub[
i],
103 no_storage |= !(prop.formatProperties.optimalTilingFeatures &
104 VK_FORMAT_FEATURE_2_STORAGE_IMAGE_BIT);
124 "Vulkan filtering requires a device context!\n");
136 vk_frames = frames_ctx->
hwctx;
137 vk_frames->
tiling = VK_IMAGE_TILING_OPTIMAL;
138 vk_frames->
usage = VK_IMAGE_USAGE_SAMPLED_BIT |
139 VK_IMAGE_USAGE_STORAGE_BIT |
140 VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
149 vk_dev = device_ctx->
hwctx;
163 s->frames_ref = frames_ref;
164 s->frames = frames_ctx;
166 s->device = device_ctx;
167 s->hwctx = device_ctx->
hwctx;
185 "hardware frames context on the input.\n");
194 if (avctx->
inputs[0] != inlink)
203 s->output_width = inlink->
w;
204 s->output_height = inlink->
h;
218 s->output_width,
s->output_height,
227 outlink->
w =
s->output_width;
228 outlink->
h =
s->output_height;
244 VkSampler sampler, uint32_t wgc_z,
245 void *push_src,
size_t push_size)
251 VkImageMemoryBarrier2 img_bar[37];
253 VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
254 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
255 VK_IMAGE_LAYOUT_GENERAL;
262 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
263 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
266 VK_IMAGE_LAYOUT_GENERAL,
270 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
271 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
282 0, push_size, push_src);
286 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
287 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
288 VK_ACCESS_SHADER_WRITE_BIT,
289 VK_IMAGE_LAYOUT_GENERAL,
290 VK_QUEUE_FAMILY_IGNORED);
293 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
294 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
295 VK_ACCESS_SHADER_READ_BIT,
297 VK_QUEUE_FAMILY_IGNORED);
299 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
300 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
301 .pImageMemoryBarriers = img_bar,
302 .imageMemoryBarrierCount = nb_img_bar,
305 vk->CmdDispatch(exec->
buf,
319 VkSampler sampler, uint32_t wgc_z,
320 void *push_src,
size_t push_size)
327 VkImageMemoryBarrier2 img_bar[37];
329 VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
330 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
331 VK_IMAGE_LAYOUT_GENERAL;
338 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
339 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
341 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
342 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
344 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
345 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
352 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
353 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
354 VK_ACCESS_SHADER_READ_BIT,
356 VK_QUEUE_FAMILY_IGNORED);
358 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
359 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
360 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
361 VK_IMAGE_LAYOUT_GENERAL,
362 VK_QUEUE_FAMILY_IGNORED);
364 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
365 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
366 VK_ACCESS_SHADER_WRITE_BIT,
367 VK_IMAGE_LAYOUT_GENERAL,
368 VK_QUEUE_FAMILY_IGNORED);
370 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
371 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
372 .pImageMemoryBarriers = img_bar,
373 .imageMemoryBarrierCount = nb_img_bar,
376 for (
int i = 0;
i < 2;
i++) {
380 VkImageView *src_views = !
i ? in_views : tmp_views;
381 VkImageView *dst_views = !
i ? tmp_views : out_views;
385 VK_IMAGE_LAYOUT_GENERAL,
388 VK_IMAGE_LAYOUT_GENERAL,
395 0, push_size, push_src);
397 vk->CmdDispatch(exec->
buf,
412 VkSampler sampler, uint32_t wgc_z,
413 void *push_src,
size_t push_size)
419 VkImageMemoryBarrier2 img_bar[128];
421 VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
422 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
423 VK_IMAGE_LAYOUT_GENERAL;
431 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
432 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
434 for (
int i = 0;
i < nb_in;
i++) {
436 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
437 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
443 VK_IMAGE_LAYOUT_GENERAL,
445 for (
int i = 0;
i < nb_in;
i++)
454 0, push_size, push_src);
458 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
459 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
460 VK_ACCESS_SHADER_WRITE_BIT,
461 VK_IMAGE_LAYOUT_GENERAL,
462 VK_QUEUE_FAMILY_IGNORED);
463 for (
int i = 0;
i < nb_in;
i++)
465 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
466 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
467 VK_ACCESS_SHADER_READ_BIT,
469 VK_QUEUE_FAMILY_IGNORED);
471 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
472 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
473 .pImageMemoryBarriers = img_bar,
474 .imageMemoryBarrierCount = nb_img_bar,
477 vk->CmdDispatch(exec->
buf,
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define i(width, name, range_min, range_max)
#define AV_NUM_DATA_POINTERS
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
const VkFormat * av_vkfmt_from_pixfmt(enum AVPixelFormat p)
Returns the optimal per-plane Vulkan format for a given sw_format, one for each plane.
static FilterLink * ff_filter_link(AVFilterLink *link)
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.
int ff_vk_load_props(FFVulkanContext *s)
Loads props/mprops/driver_props.
void ff_vk_frame_barrier(FFVulkanContext *s, FFVkExecContext *e, AVFrame *pic, VkImageMemoryBarrier2 *bar, int *nb_bar, VkPipelineStageFlags2 src_stage, VkPipelineStageFlags2 dst_stage, VkAccessFlagBits2 new_access, VkImageLayout new_layout, uint32_t new_qf)
int ff_vk_exec_start(FFVulkanContext *s, FFVkExecContext *e)
Start/submit/wait an execution.
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.
FFVkExecContext * ff_vk_exec_get(FFVulkanContext *s, FFVkExecPool *pool)
Retrieve an execution pool.
int ff_vk_exec_submit(FFVulkanContext *s, FFVkExecContext *e)
void ff_vk_exec_bind_shader(FFVulkanContext *s, FFVkExecContext *e, const FFVulkanShader *shd)
Bind a shader.
void ff_vk_exec_discard_deps(FFVulkanContext *s, FFVkExecContext *e)
int ff_vk_exec_add_dep_frame(FFVulkanContext *s, FFVkExecContext *e, AVFrame *f, VkPipelineStageFlagBits2 wait_stage, VkPipelineStageFlagBits2 signal_stage)
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.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
A reference to a data buffer.
uint8_t * data
The data buffer.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
AVBufferRef * hw_device_ctx
For filters which will create hardware frames, sets the device the filter should create them in.
A link between two filters.
int w
agreed upon image width
int h
agreed upon image height
AVFilterContext * src
source filter
AVFilterContext * dst
dest filter
This structure describes decoded (raw) audio or video data.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
This struct describes a set or pool of "hardware" frames (i.e.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int width
The allocated dimensions of the frames in this pool.
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
VkPhysicalDevice phys_dev
Physical device.
int nb_enabled_inst_extensions
const char *const * enabled_dev_extensions
Enabled device extensions.
const char *const * enabled_inst_extensions
Enabled instance extensions.
int nb_enabled_dev_extensions
Allocated as AVHWFramesContext.hwctx, used to set pool-specific options.
VkImageTiling tiling
Controls the tiling of allocated frames.
VkImageUsageFlagBits usage
Defines extra usage of output frames.
VkFormat format[AV_NUM_DATA_POINTERS]
Vulkan format for each image.
Link properties exposed to filter code, but not external callers.
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
int ff_vk_filter_process_2pass(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd_list[2], AVFrame *out, AVFrame *tmp, AVFrame *in, VkSampler sampler, uint32_t wgc_z, void *push_src, size_t push_size)
Submit a compute shader with a single in and single out with 2 stages.
int ff_vk_filter_config_input(AVFilterLink *inlink)
int ff_vk_filter_config_output(AVFilterLink *outlink)
int ff_vk_filter_process_Nin(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd, AVFrame *out, AVFrame *in[], int nb_in, VkSampler sampler, uint32_t wgc_z, void *push_src, size_t push_size)
Up to 16 inputs, one output.
int ff_vk_filter_process_simple(FFVulkanContext *vkctx, FFVkExecPool *e, FFVulkanShader *shd, AVFrame *out_f, AVFrame *in_f, VkSampler sampler, uint32_t wgc_z, void *push_src, size_t push_size)
Submit a compute shader with a zero/one input and single out for execution.
int ff_vk_filter_init_context(AVFilterContext *avctx, FFVulkanContext *s, AVBufferRef *frames_ref, int width, int height, enum AVPixelFormat sw_format)
Can be called manually, if not using ff_vk_filter_config_output.
int ff_vk_filter_init(AVFilterContext *avctx)
General lavfi IO functions.
#define FF_VK_EXT_VIDEO_MAINTENANCE_1
#define FF_VK_EXT_VIDEO_ENCODE_QUEUE
static uint64_t ff_vk_extensions_to_mask(const char *const *extensions, int nb_extensions)
static int ff_vk_load_functions(AVHWDeviceContext *ctx, FFVulkanFunctions *vk, uint64_t extensions_mask, int has_inst, int has_dev)
Function loader.