25 #define FN_CREATING(ctx, type, shortname, array, num) \
26 static av_always_inline type *create_ ##shortname(ctx *dctx) \
28 type **array, *sctx = av_mallocz(sizeof(*sctx)); \
32 array = av_realloc_array(dctx->array, sizeof(*dctx->array), dctx->num + 1);\
38 dctx->array = array; \
39 dctx->array[dctx->num++] = sctx; \
45 .r = VK_COMPONENT_SWIZZLE_IDENTITY,
46 .g = VK_COMPONENT_SWIZZLE_IDENTITY,
47 .b = VK_COMPONENT_SWIZZLE_IDENTITY,
48 .a = VK_COMPONENT_SWIZZLE_IDENTITY,
54 #define CASE(VAL) case VAL: return #VAL
62 CASE(VK_ERROR_OUT_OF_HOST_MEMORY);
63 CASE(VK_ERROR_OUT_OF_DEVICE_MEMORY);
64 CASE(VK_ERROR_INITIALIZATION_FAILED);
65 CASE(VK_ERROR_DEVICE_LOST);
66 CASE(VK_ERROR_MEMORY_MAP_FAILED);
67 CASE(VK_ERROR_LAYER_NOT_PRESENT);
68 CASE(VK_ERROR_EXTENSION_NOT_PRESENT);
69 CASE(VK_ERROR_FEATURE_NOT_PRESENT);
70 CASE(VK_ERROR_INCOMPATIBLE_DRIVER);
71 CASE(VK_ERROR_TOO_MANY_OBJECTS);
72 CASE(VK_ERROR_FORMAT_NOT_SUPPORTED);
73 CASE(VK_ERROR_FRAGMENTED_POOL);
74 CASE(VK_ERROR_SURFACE_LOST_KHR);
75 CASE(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
76 CASE(VK_SUBOPTIMAL_KHR);
77 CASE(VK_ERROR_OUT_OF_DATE_KHR);
78 CASE(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR);
79 CASE(VK_ERROR_VALIDATION_FAILED_EXT);
80 CASE(VK_ERROR_INVALID_SHADER_NV);
81 CASE(VK_ERROR_OUT_OF_POOL_MEMORY);
82 CASE(VK_ERROR_INVALID_EXTERNAL_HANDLE);
83 CASE(VK_ERROR_NOT_PERMITTED_EXT);
84 default:
return "Unknown error";
90 VkMemoryPropertyFlagBits req_flags,
void *alloc_extension,
91 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
95 VkPhysicalDeviceProperties props;
96 VkPhysicalDeviceMemoryProperties mprops;
99 VkMemoryAllocateInfo alloc_info = {
100 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
101 .pNext = alloc_extension,
104 vkGetPhysicalDeviceProperties(
s->hwctx->phys_dev, &props);
105 vkGetPhysicalDeviceMemoryProperties(
s->hwctx->phys_dev, &mprops);
108 if (req_flags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)
109 req->size =
FFALIGN(req->size, props.limits.minMemoryMapAlignment);
111 alloc_info.allocationSize = req->size;
115 for (
int i = 0;
i < mprops.memoryTypeCount;
i++) {
117 if (!(req->memoryTypeBits & (1 <<
i)))
121 if ((mprops.memoryTypes[
i].propertyFlags & req_flags) != req_flags)
135 alloc_info.memoryTypeIndex =
index;
137 ret = vkAllocateMemory(
s->hwctx->act_dev, &alloc_info,
138 s->hwctx->alloc, mem);
139 if (ret != VK_SUCCESS) {
145 *mem_flags |= mprops.memoryTypes[
index].propertyFlags;
151 VkBufferUsageFlags
usage, VkMemoryPropertyFlagBits
flags)
158 VkBufferCreateInfo buf_spawn = {
159 .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
162 .sharingMode = VK_SHARING_MODE_EXCLUSIVE,
167 VkBufferMemoryRequirementsInfo2 req_desc = {
168 .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
170 VkMemoryDedicatedAllocateInfo ded_alloc = {
171 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
174 VkMemoryDedicatedRequirements ded_req = {
175 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
177 VkMemoryRequirements2 req = {
178 .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
182 ret = vkCreateBuffer(
s->hwctx->act_dev, &buf_spawn,
NULL, &buf->
buf);
183 if (ret != VK_SUCCESS) {
189 req_desc.buffer = buf->
buf;
191 vkGetBufferMemoryRequirements2(
s->hwctx->act_dev, &req_desc, &req);
194 use_ded_mem = ded_req.prefersDedicatedAllocation |
195 ded_req.requiresDedicatedAllocation;
197 ded_alloc.buffer = buf->
buf;
200 use_ded_mem ? &ded_alloc : (
void *)ded_alloc.pNext,
205 ret = vkBindBufferMemory(
s->hwctx->act_dev, buf->
buf, buf->
mem, 0);
206 if (ret != VK_SUCCESS) {
216 int nb_buffers,
int invalidate)
220 VkMappedMemoryRange *inval_list =
NULL;
223 for (
int i = 0;
i < nb_buffers;
i++) {
224 ret = vkMapMemory(
s->hwctx->act_dev, buf[
i].
mem, 0,
225 VK_WHOLE_SIZE, 0, (
void **)&mem[
i]);
226 if (ret != VK_SUCCESS) {
236 for (
int i = 0;
i < nb_buffers;
i++) {
237 const VkMappedMemoryRange ival_buf = {
238 .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
239 .memory = buf[
i].
mem,
240 .size = VK_WHOLE_SIZE,
242 if (buf[
i].
flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
245 (++inval_count)*
sizeof(*inval_list));
248 inval_list[inval_count - 1] = ival_buf;
252 ret = vkInvalidateMappedMemoryRanges(
s->hwctx->act_dev, inval_count,
254 if (ret != VK_SUCCESS) {
270 VkMappedMemoryRange *flush_list =
NULL;
274 for (
int i = 0;
i < nb_buffers;
i++) {
275 const VkMappedMemoryRange flush_buf = {
276 .sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE,
277 .memory = buf[
i].
mem,
278 .size = VK_WHOLE_SIZE,
280 if (buf[
i].
flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)
283 (++flush_count)*
sizeof(*flush_list));
286 flush_list[flush_count - 1] = flush_buf;
291 ret = vkFlushMappedMemoryRanges(
s->hwctx->act_dev, flush_count,
293 if (ret != VK_SUCCESS) {
300 for (
int i = 0;
i < nb_buffers;
i++)
301 vkUnmapMemory(
s->hwctx->act_dev, buf[
i].
mem);
312 if (buf->
buf != VK_NULL_HANDLE)
313 vkDestroyBuffer(
s->hwctx->act_dev, buf->
buf,
s->hwctx->alloc);
314 if (buf->
mem != VK_NULL_HANDLE)
315 vkFreeMemory(
s->hwctx->act_dev, buf->
mem,
s->hwctx->alloc);
319 int offset,
int size, VkShaderStageFlagBits stage)
321 VkPushConstantRange *pc;
329 memset(pc, 0,
sizeof(*pc));
331 pc->stageFlags = stage;
345 int queue_family =
s->queue_family_idx;
346 int nb_queues =
s->queue_count;
349 .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
350 .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
351 .queueFamilyIndex = queue_family,
353 VkCommandBufferAllocateInfo cbuf_create = {
354 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
355 .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
356 .commandBufferCount = nb_queues,
373 s->hwctx->alloc, &e->
pool);
374 if (ret != VK_SUCCESS) {
380 cbuf_create.commandPool = e->
pool;
383 ret = vkAllocateCommandBuffers(
s->hwctx->act_dev, &cbuf_create, e->
bufs);
384 if (ret != VK_SUCCESS) {
390 for (
int i = 0;
i < nb_queues;
i++) {
392 vkGetDeviceQueue(
s->hwctx->act_dev, queue_family,
i, &q->
queue);
423 VkCommandBufferBeginInfo cmd_start = {
424 .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
425 .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,
430 VkFenceCreateInfo fence_spawn = {
431 .sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
433 ret = vkCreateFence(
s->hwctx->act_dev, &fence_spawn,
s->hwctx->alloc,
435 if (ret != VK_SUCCESS) {
441 vkWaitForFences(
s->hwctx->act_dev, 1, &q->
fence, VK_TRUE, UINT64_MAX);
442 vkResetFences(
s->hwctx->act_dev, 1, &q->
fence);
448 ret = vkBeginCommandBuffer(e->
bufs[
s->cur_queue_idx], &cmd_start);
449 if (ret != VK_SUCCESS) {
461 return e->
bufs[
s->cur_queue_idx];
465 AVFrame *
frame, VkPipelineStageFlagBits in_wait_dst_flag)
505 (q->nb_frame_deps + 1) *
sizeof(*dst));
513 if (!q->frame_deps[q->nb_frame_deps]) {
528 VkSubmitInfo s_info = {
529 .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
530 .commandBufferCount = 1,
531 .pCommandBuffers = &e->
bufs[
s->cur_queue_idx],
537 .pSignalSemaphores = e->
sem_sig,
541 ret = vkEndCommandBuffer(e->
bufs[
s->cur_queue_idx]);
542 if (ret != VK_SUCCESS) {
548 ret = vkQueueSubmit(q->
queue, 1, &s_info, q->
fence);
549 if (ret != VK_SUCCESS) {
556 s->cur_queue_idx = (
s->cur_queue_idx + 1) %
s->queue_count;
568 if (!deps || !nb_deps)
578 for (
int i = 0;
i < nb_deps;
i++) {
616 s->hwctx =
s->device->hwctx;
644 "hardware frames context on the input.\n");
649 if (avctx->
inputs[0] != inlink)
667 if (!
s->output_width)
668 s->output_width = inlink->
w;
669 if (!
s->output_height)
670 s->output_height = inlink->
h;
683 if (!
s->device_ref) {
699 outlink->
w =
s->output_width;
700 outlink->
h =
s->output_height;
715 if (!
s->device_ref) {
728 if (!output_frames_ref) {
736 output_frames->
width =
s->output_width;
737 output_frames->
height =
s->output_height;
742 "frames: %d.\n", err);
747 outlink->
w =
s->output_width;
748 outlink->
h =
s->output_height;
775 VkSamplerCreateInfo sampler_info = {
776 .sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
778 .minFilter = sampler_info.magFilter,
779 .mipmapMode = unnorm_coords ? VK_SAMPLER_MIPMAP_MODE_NEAREST :
780 VK_SAMPLER_MIPMAP_MODE_LINEAR,
781 .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
782 .addressModeV = sampler_info.addressModeU,
783 .addressModeW = sampler_info.addressModeU,
784 .anisotropyEnable = VK_FALSE,
785 .compareOp = VK_COMPARE_OP_NEVER,
786 .borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK,
787 .unnormalizedCoordinates = unnorm_coords,
790 VkSampler *sampler = create_sampler(
s);
794 ret = vkCreateSampler(
s->hwctx->act_dev, &sampler_info,
795 s->hwctx->alloc, sampler);
796 if (ret != VK_SUCCESS) {
820 const int high =
desc->comp[0].depth > 8;
821 return high ?
"rgba16f" :
"rgba8";
832 vkDestroyImageView(
s->hwctx->act_dev, iv->
view,
s->hwctx->alloc);
837 VkImageView *v, VkImage
img, VkFormat fmt,
838 const VkComponentMapping
map)
843 VkImageViewCreateInfo imgview_spawn = {
844 .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
847 .viewType = VK_IMAGE_VIEW_TYPE_2D,
850 .subresourceRange = {
851 .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
861 VkResult ret = vkCreateImageView(
s->hwctx->act_dev, &imgview_spawn,
862 s->hwctx->alloc, &iv->
view);
863 if (ret != VK_SUCCESS) {
889 const
char *
name, VkShaderStageFlags stage)
897 shd->
shader.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
898 shd->
shader.stage = stage;
903 GLSLC(0, #define IS_WITHIN(v1, v2) ((v1.x < v2.x) && (v1.y < v2.y)) );
917 "local_size_y = %i, local_size_z = %i) in;\n\n",
924 const char *p = shd->
src.str;
925 const char *start = p;
930 for (
int i = 0;
i < strlen(p);
i++) {
938 av_log(avctx, prio,
"Shader %s: \n%s", shd->
name, buf.str);
943 const char *entrypoint)
947 VkShaderModuleCreateInfo shader_create;
956 shd->
shader.pName = entrypoint;
974 shader_create.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
975 shader_create.pNext =
NULL;
976 shader_create.codeSize = res->
size;
977 shader_create.flags = 0;
978 shader_create.pCode = res->
data;
980 ret = vkCreateShaderModule(
s->hwctx->act_dev, &shader_create,
NULL,
987 if (ret != VK_SUCCESS) {
994 shd->
name, shader_create.codeSize);
1007 [VK_DESCRIPTOR_TYPE_SAMPLER] = {
sizeof(VkDescriptorImageInfo),
"sampler", 1, 0, 0, 0, },
1008 [VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE] = {
sizeof(VkDescriptorImageInfo),
"texture", 1, 0, 1, 0, },
1009 [VK_DESCRIPTOR_TYPE_STORAGE_IMAGE] = {
sizeof(VkDescriptorImageInfo),
"image", 1, 1, 1, 0, },
1010 [VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT] = {
sizeof(VkDescriptorImageInfo),
"subpassInput", 1, 0, 0, 0, },
1011 [VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER] = {
sizeof(VkDescriptorImageInfo),
"sampler", 1, 0, 1, 0, },
1012 [VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER] = {
sizeof(VkDescriptorBufferInfo),
NULL, 1, 0, 0, 1, },
1013 [VK_DESCRIPTOR_TYPE_STORAGE_BUFFER] = {
sizeof(VkDescriptorBufferInfo),
"buffer", 0, 1, 0, 1, },
1014 [VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC] = {
sizeof(VkDescriptorBufferInfo),
NULL, 1, 0, 0, 1, },
1015 [VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC] = {
sizeof(VkDescriptorBufferInfo),
"buffer", 0, 1, 0, 1, },
1016 [VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER] = {
sizeof(VkBufferView),
"samplerBuffer", 1, 0, 0, 0, },
1017 [VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER] = {
sizeof(VkBufferView),
"imageBuffer", 1, 0, 0, 0, },
1022 int num,
int only_print_to_shader)
1025 VkDescriptorSetLayout *
layout;
1028 if (only_print_to_shader)
1040 VkDescriptorSetLayoutCreateInfo desc_create_layout = { 0 };
1041 VkDescriptorSetLayoutBinding *desc_binding;
1043 desc_binding =
av_mallocz(
sizeof(*desc_binding)*num);
1047 for (
int i = 0;
i < num;
i++) {
1048 desc_binding[
i].binding =
i;
1049 desc_binding[
i].descriptorType =
desc[
i].type;
1050 desc_binding[
i].descriptorCount =
FFMAX(
desc[
i].elems, 1);
1051 desc_binding[
i].stageFlags =
desc[
i].stages;
1052 desc_binding[
i].pImmutableSamplers =
desc[
i].samplers;
1055 desc_create_layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
1056 desc_create_layout.pBindings = desc_binding;
1057 desc_create_layout.bindingCount = num;
1059 ret = vkCreateDescriptorSetLayout(
s->hwctx->act_dev, &desc_create_layout,
1062 if (ret != VK_SUCCESS) {
1070 for (
int i = 0;
i < num;
i++) {
1089 VkDescriptorUpdateTemplateCreateInfo *dt;
1090 VkDescriptorUpdateTemplateEntry *des_entries;
1093 des_entries =
av_mallocz(num*
sizeof(VkDescriptorUpdateTemplateEntry));
1097 for (
int i = 0;
i < num;
i++) {
1098 des_entries[
i].dstBinding =
i;
1099 des_entries[
i].descriptorType =
desc[
i].type;
1100 des_entries[
i].descriptorCount =
FFMAX(
desc[
i].elems, 1);
1101 des_entries[
i].dstArrayElement = 0;
1113 memset(dt, 0,
sizeof(*dt));
1115 dt->sType = VK_STRUCTURE_TYPE_DESCRIPTOR_UPDATE_TEMPLATE_CREATE_INFO;
1116 dt->templateType = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET;
1117 dt->descriptorSetLayout = *
layout;
1118 dt->pDescriptorUpdateEntries = des_entries;
1119 dt->descriptorUpdateEntryCount = num;
1126 for (
int i = 0;
i < num;
i++) {
1130 if (
desc[
i].mem_layout)
1150 else if (
desc[
i].elems > 0)
1165 vkUpdateDescriptorSetWithTemplate(
s->hwctx->act_dev,
1172 VkShaderStageFlagBits stage,
int offset,
1188 VkDescriptorPoolCreateInfo pool_create_info = {
1189 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
1195 ret = vkCreateDescriptorPool(
s->hwctx->act_dev, &pool_create_info,
1198 if (ret != VK_SUCCESS) {
1206 VkDescriptorSetAllocateInfo alloc_info = {
1207 .sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO,
1217 ret = vkAllocateDescriptorSets(
s->hwctx->act_dev, &alloc_info,
1219 if (ret != VK_SUCCESS) {
1227 VkPipelineLayoutCreateInfo spawn_pipeline_layout = {
1228 .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,
1235 ret = vkCreatePipelineLayout(
s->hwctx->act_dev, &spawn_pipeline_layout,
1239 if (ret != VK_SUCCESS) {
1247 VkDescriptorUpdateTemplateCreateInfo *desc_template_info;
1257 ret = vkCreateDescriptorUpdateTemplate(
s->hwctx->act_dev,
1261 av_free((
void *)desc_template_info->pDescriptorUpdateEntries);
1262 if (ret != VK_SUCCESS) {
1278 return create_pipeline(avctx->priv);
1287 VkComputePipelineCreateInfo pipe = {
1288 .sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO,
1293 if (pl->
shaders[
i]->
shader.stage & VK_SHADER_STAGE_COMPUTE_BIT) {
1303 ret = vkCreateComputePipelines(
s->hwctx->act_dev, VK_NULL_HANDLE, 1, &pipe,
1305 if (ret != VK_SUCCESS) {
1311 pl->
bind_point = VK_PIPELINE_BIND_POINT_COMPUTE;
1333 for (
int i = 0;
i <
s->queue_count;
i++) {
1337 vkWaitForFences(
s->hwctx->act_dev, 1, &q->
fence, VK_TRUE, UINT64_MAX);
1338 vkResetFences(
s->hwctx->act_dev, 1, &q->
fence);
1343 vkDestroyFence(
s->hwctx->act_dev, q->
fence,
s->hwctx->alloc);
1357 vkFreeCommandBuffers(
s->hwctx->act_dev, e->
pool,
s->queue_count, e->
bufs);
1359 vkDestroyCommandPool(
s->hwctx->act_dev, e->
pool,
s->hwctx->alloc);
1374 vkDestroyShaderModule(
s->hwctx->act_dev, shd->
shader.module,
1379 vkDestroyPipeline(
s->hwctx->act_dev, pl->
pipeline,
s->hwctx->alloc);
1385 vkDestroyDescriptorUpdateTemplate(
s->hwctx->act_dev, pl->
desc_template[
i],
1388 vkDestroyDescriptorSetLayout(
s->hwctx->act_dev, pl->
desc_layout[
i],
1394 vkDestroyDescriptorPool(
s->hwctx->act_dev, pl->
desc_pool,
1421 for (
int i = 0;
i <
s->exec_ctx_num;
i++)
1425 for (
int i = 0;
i <
s->samplers_num;
i++) {
1426 vkDestroySampler(
s->hwctx->act_dev, *
s->samplers[
i],
s->hwctx->alloc);
1431 for (
int i = 0;
i <
s->pipelines_num;
i++)
1436 s->scratch_size = 0;
static void flush(AVCodecContext *avctx)
static cqueue * cqueue_create(int size, int max_size)
static const int8_t filt[NUMTAPS *2]
void av_bprintf(AVBPrint *buf, const char *fmt,...)
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_append_data(AVBPrint *buf, const char *data, unsigned size)
Append data to a print buffer.
#define AV_BPRINT_SIZE_UNLIMITED
#define flags(name, subs,...)
#define fc(width, name, range_min, range_max)
static enum AVPixelFormat pix_fmt
void glslang_uninit(void)
GLSlangResult * glslang_compile(const char *glsl, enum GLSlangStage stage)
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_create(uint8_t *data, buffer_size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array.
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 VDPAUPixFmtMap * map
static int create_exec_ctx(AVHWFramesContext *hwfc, VulkanExecCtx *cmd, int queue_family_index, int num_queues)
enum AVPixelFormat pixfmt
static enum AVPixelFormat pix_fmts[]
static const struct @322 planes[]
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_RGBA64
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
@ AV_PIX_FMT_RGB24
packed RGB 8:8:8, 24bpp, RGBRGB...
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
#define AV_PIX_FMT_BGR565
#define AV_PIX_FMT_RGB565
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
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
AVFilterContext * dst
dest filter
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
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.
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.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
VkMemoryPropertyFlagBits flags
VulkanPipeline * bound_pl
VkPipelineStageFlagBits * sem_wait_dst
VkPipelineShaderStageCreateInfo shader
VkPushConstantRange * push_consts
VkDescriptorUpdateTemplateCreateInfo * desc_template_info
VkDescriptorPool desc_pool
VkPipelineLayout pipeline_layout
VkDescriptorSetLayout * desc_layout
VkPipelineBindPoint bind_point
VkDescriptorPoolSize * pool_size_desc
VkDescriptorUpdateTemplate * desc_template
VkDescriptorSet * desc_set
static void print(AVTreeNode *t, int depth)
static const uint8_t offset[127][2]
int ff_vk_unmap_buffers(AVFilterContext *avctx, FFVkBuffer *buf, int nb_buffers, int flush)
Unmaps the buffer from userspace.
VkSampler * ff_vk_init_sampler(AVFilterContext *avctx, int unnorm_coords, VkFilter filt)
Create a Vulkan sampler, will be auto-freed in ff_vk_filter_uninit()
int ff_vk_map_buffers(AVFilterContext *avctx, FFVkBuffer *buf, uint8_t *mem[], int nb_buffers, int invalidate)
Maps the buffer to userspace.
int ff_vk_add_exec_dep(AVFilterContext *avctx, FFVkExecContext *e, AVFrame *frame, VkPipelineStageFlagBits in_wait_dst_flag)
Adds a frame as a queue dependency.
int ff_vk_filter_config_output_inplace(AVFilterLink *outlink)
int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size, VkBufferUsageFlags usage, VkMemoryPropertyFlagBits flags)
Create a VkBuffer with the specified parameters.
const char * ff_vk_ret2str(VkResult res)
Converts Vulkan return values to strings.
int ff_vk_add_descriptor_set(AVFilterContext *avctx, VulkanPipeline *pl, SPIRVShader *shd, VulkanDescriptorSetBinding *desc, int num, int only_print_to_shader)
Adds a descriptor set to the shader and registers them in the pipeline.
const char * ff_vk_shader_rep_fmt(enum AVPixelFormat pixfmt)
Gets the glsl format string for a pixel format.
void ff_vk_discard_exec_deps(AVFilterContext *avctx, FFVkExecContext *e)
Discards all queue dependencies.
void ff_vk_set_compute_shader_sizes(AVFilterContext *avctx, SPIRVShader *shd, int local_size[3])
Writes the workgroup size for a shader.
int ff_vk_add_dep_exec_ctx(AVFilterContext *avctx, FFVkExecContext *e, AVBufferRef **deps, int nb_deps)
Adds a generic AVBufferRef as a queue depenency.
int ff_vk_add_push_constant(AVFilterContext *avctx, VulkanPipeline *pl, int offset, int size, VkShaderStageFlagBits stage)
Define a push constant for a given stage into a pipeline.
int ff_vk_init_compute_pipeline(AVFilterContext *avctx, VulkanPipeline *pl)
Initializes a compute pipeline.
#define FN_CREATING(ctx, type, shortname, array, num)
int ff_vk_filter_config_input(AVFilterLink *inlink)
void ff_vk_update_push_exec(AVFilterContext *avctx, FFVkExecContext *e, VkShaderStageFlagBits stage, int offset, size_t size, void *src)
Updates push constants.
int ff_vk_filter_config_output(AVFilterLink *outlink)
const VkComponentMapping ff_comp_identity_map
void ff_vk_filter_uninit(AVFilterContext *avctx)
SPIRVShader * ff_vk_init_shader(AVFilterContext *avctx, VulkanPipeline *pl, const char *name, VkShaderStageFlags stage)
Inits a shader for a specific pipeline.
int ff_vk_compile_shader(AVFilterContext *avctx, SPIRVShader *shd, const char *entrypoint)
Compiles the shader, entrypoint must be set to "main".
int ff_vk_create_exec_ctx(AVFilterContext *avctx, FFVkExecContext **ctx)
Init an execution context for command recording and queue submission.
VkCommandBuffer ff_vk_get_exec_buf(AVFilterContext *avctx, FFVkExecContext *e)
Gets the command buffer to use for this submission from the exe context.
void ff_vk_update_descriptor_set(AVFilterContext *avctx, VulkanPipeline *pl, int set_id)
Updates a descriptor set via the updaters defined.
void ff_vk_bind_pipeline_exec(AVFilterContext *avctx, FFVkExecContext *e, VulkanPipeline *pl)
Add a command to bind the completed pipeline and its descriptor sets.
int ff_vk_start_exec_recording(AVFilterContext *avctx, FFVkExecContext *e)
Begin recording to the command buffer.
int ff_vk_mt_is_np_rgb(enum AVPixelFormat pix_fmt)
Returns 1 if the image is any sort of supported RGB.
static void free_pipeline(VulkanFilterContext *s, VulkanPipeline *pl)
int ff_vk_init_pipeline_layout(AVFilterContext *avctx, VulkanPipeline *pl)
Initializes the pipeline layout after all shaders and descriptor sets have been finished.
static void free_exec_ctx(VulkanFilterContext *s, FFVkExecContext *e)
void ff_vk_free_buf(AVFilterContext *avctx, FFVkBuffer *buf)
Frees a buffer.
static int vk_alloc_mem(AVFilterContext *avctx, VkMemoryRequirements *req, VkMemoryPropertyFlagBits req_flags, void *alloc_extension, VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
int ff_vk_submit_exec_queue(AVFilterContext *avctx, FFVkExecContext *e)
Submits a command buffer to the queue for execution.
int ff_vk_filter_query_formats(AVFilterContext *avctx)
General lavfi IO functions.
static int vulkan_filter_set_device(AVFilterContext *avctx, AVBufferRef *device)
int ff_vk_filter_init(AVFilterContext *avctx)
static int vulkan_filter_set_frames(AVFilterContext *avctx, AVBufferRef *frames)
static void destroy_imageview(void *opaque, uint8_t *data)
VulkanPipeline * ff_vk_create_pipeline(AVFilterContext *avctx)
Inits a pipeline.
int ff_vk_create_imageview(AVFilterContext *avctx, FFVkExecContext *e, VkImageView *v, VkImage img, VkFormat fmt, const VkComponentMapping map)
Create an imageview.
static void print_shader(AVFilterContext *avctx, SPIRVShader *shd, int prio)