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;
264 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
265 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
268 VK_IMAGE_LAYOUT_GENERAL,
272 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
273 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
284 0, push_size, push_src);
288 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
289 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
290 VK_ACCESS_SHADER_WRITE_BIT,
291 VK_IMAGE_LAYOUT_GENERAL,
292 VK_QUEUE_FAMILY_IGNORED);
295 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
296 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
297 VK_ACCESS_SHADER_READ_BIT,
299 VK_QUEUE_FAMILY_IGNORED);
301 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
302 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
303 .pImageMemoryBarriers = img_bar,
304 .imageMemoryBarrierCount = nb_img_bar,
307 vk->CmdDispatch(exec->
buf,
321 VkSampler sampler, uint32_t wgc_z,
322 void *push_src,
size_t push_size)
329 VkImageMemoryBarrier2 img_bar[37];
331 VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
332 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
333 VK_IMAGE_LAYOUT_GENERAL;
342 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
343 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
345 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
346 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
348 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
349 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
356 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
357 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
358 VK_ACCESS_SHADER_READ_BIT,
360 VK_QUEUE_FAMILY_IGNORED);
362 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
363 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
364 VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT,
365 VK_IMAGE_LAYOUT_GENERAL,
366 VK_QUEUE_FAMILY_IGNORED);
368 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
369 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
370 VK_ACCESS_SHADER_WRITE_BIT,
371 VK_IMAGE_LAYOUT_GENERAL,
372 VK_QUEUE_FAMILY_IGNORED);
374 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
375 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
376 .pImageMemoryBarriers = img_bar,
377 .imageMemoryBarrierCount = nb_img_bar,
380 for (
int i = 0;
i < 2;
i++) {
384 VkImageView *src_views = !
i ? in_views : tmp_views;
385 VkImageView *dst_views = !
i ? tmp_views : out_views;
389 VK_IMAGE_LAYOUT_GENERAL,
392 VK_IMAGE_LAYOUT_GENERAL,
399 0, push_size, push_src);
401 vk->CmdDispatch(exec->
buf,
416 VkSampler sampler, uint32_t wgc_z,
417 void *push_src,
size_t push_size)
423 VkImageMemoryBarrier2 img_bar[128];
425 VkImageLayout in_layout = sampler != VK_NULL_HANDLE ?
426 VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL :
427 VK_IMAGE_LAYOUT_GENERAL;
437 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
438 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
440 for (
int i = 0;
i < nb_in;
i++) {
442 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
443 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT));
449 VK_IMAGE_LAYOUT_GENERAL,
451 for (
int i = 0;
i < nb_in;
i++)
460 0, push_size, push_src);
464 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
465 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
466 VK_ACCESS_SHADER_WRITE_BIT,
467 VK_IMAGE_LAYOUT_GENERAL,
468 VK_QUEUE_FAMILY_IGNORED);
469 for (
int i = 0;
i < nb_in;
i++)
471 VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT,
472 VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT,
473 VK_ACCESS_SHADER_READ_BIT,
475 VK_QUEUE_FAMILY_IGNORED);
477 vk->CmdPipelineBarrier2(exec->
buf, &(VkDependencyInfo) {
478 .sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
479 .pImageMemoryBarriers = img_bar,
480 .imageMemoryBarrierCount = nb_img_bar,
483 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(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.