MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / vulkan_pool_alloc

Function vulkan_pool_alloc

libavutil/hwcontext_vulkan.c:2875–2948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2873}
2874
2875static AVBufferRef *vulkan_pool_alloc(void *opaque, size_t size)
2876{
2877 int err;
2878 AVVkFrame *f;
2879 AVBufferRef *avbuf = NULL;
2880 AVHWFramesContext *hwfc = opaque;
2881 VulkanDevicePriv *p = hwfc->device_ctx->hwctx;
2882 VulkanFramesPriv *fp = hwfc->hwctx;
2883 AVVulkanFramesContext *hwctx = &fp->p;
2884 VkExternalMemoryHandleTypeFlags e = 0x0;
2885 VkExportMemoryAllocateInfo eminfo[AV_NUM_DATA_POINTERS];
2886
2887 VkExternalMemoryImageCreateInfo eiinfo = {
2888 .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_IMAGE_CREATE_INFO,
2889 .pNext = hwctx->create_pnext,
2890 };
2891
2892#ifdef _WIN32
2893 if (p->vkctx.extensions & FF_VK_EXT_EXTERNAL_WIN32_MEMORY)
2894 try_export_flags(hwfc, &eiinfo.handleTypes, &e, IsWindows8OrGreater()
2895 ? VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT
2896 : VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_KMT_BIT);
2897#else
2898 if (p->vkctx.extensions & FF_VK_EXT_EXTERNAL_FD_MEMORY)
2899 try_export_flags(hwfc, &eiinfo.handleTypes, &e,
2900 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT);
2901
2902 if (p->vkctx.extensions & FF_VK_EXT_EXTERNAL_DMABUF_MEMORY &&
2903 hwctx->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT)
2904 try_export_flags(hwfc, &eiinfo.handleTypes, &e,
2905 VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT);
2906#endif
2907
2908 for (int i = 0; i < av_pix_fmt_count_planes(hwfc->sw_format); i++) {
2909 eminfo[i].sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO;
2910 eminfo[i].pNext = hwctx->alloc_pnext[i];
2911 eminfo[i].handleTypes = e;
2912 }
2913
2914 err = create_frame(hwfc, &f, hwctx->tiling, hwctx->usage, hwctx->img_flags,
2915 hwctx->nb_layers,
2916 eiinfo.handleTypes ? &eiinfo : hwctx->create_pnext);
2917 if (err)
2918 return NULL;
2919
2920 err = alloc_bind_mem(hwfc, f, eminfo, sizeof(*eminfo));
2921 if (err)
2922 goto fail;
2923
2924 if ( (hwctx->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DPB_BIT_KHR) &&
2925 !(hwctx->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR))
2926 err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_DECODING_DPB);
2927 else if (hwctx->usage & VK_IMAGE_USAGE_VIDEO_DECODE_DST_BIT_KHR)
2928 err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_DECODING_DST);
2929 else if (hwctx->usage & VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR)
2930 err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_ENCODING_DPB);
2931 else if (hwctx->usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT)
2932 err = prepare_frame(hwfc, &fp->compute_exec, f, PREP_MODE_WRITE);

Callers

nothing calls this directly

Calls 7

try_export_flagsFunction · 0.85
av_pix_fmt_count_planesFunction · 0.85
alloc_bind_memFunction · 0.85
prepare_frameFunction · 0.85
av_buffer_createFunction · 0.85
vulkan_frame_freeFunction · 0.85
create_frameFunction · 0.70

Tested by

no test coverage detected