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

Function alloc_mem

libavutil/hwcontext_vulkan.c:2315–2371  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2313}
2314
2315static int alloc_mem(AVHWDeviceContext *ctx, VkMemoryRequirements *req,
2316 VkMemoryPropertyFlagBits req_flags, const void *alloc_extension,
2317 VkMemoryPropertyFlagBits *mem_flags, VkDeviceMemory *mem)
2318{
2319 VkResult ret;
2320 int index = -1;
2321 VulkanDevicePriv *p = ctx->hwctx;
2322 FFVulkanFunctions *vk = &p->vkctx.vkfn;
2323 AVVulkanDeviceContext *dev_hwctx = &p->p;
2324 VkMemoryAllocateInfo alloc_info = {
2325 .sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
2326 .pNext = alloc_extension,
2327 .allocationSize = req->size,
2328 };
2329
2330 /* The vulkan spec requires memory types to be sorted in the "optimal"
2331 * order, so the first matching type we find will be the best/fastest one */
2332 for (int i = 0; i < p->mprops.memoryTypeCount; i++) {
2333 const VkMemoryType *type = &p->mprops.memoryTypes[i];
2334
2335 /* The memory type must be supported by the requirements (bitfield) */
2336 if (!(req->memoryTypeBits & (1 << i)))
2337 continue;
2338
2339 /* The memory type flags must include our properties */
2340 if ((type->propertyFlags & req_flags) != req_flags)
2341 continue;
2342
2343 /* The memory type must be large enough */
2344 if (req->size > p->mprops.memoryHeaps[type->heapIndex].size)
2345 continue;
2346
2347 /* Found a suitable memory type */
2348 index = i;
2349 break;
2350 }
2351
2352 if (index < 0) {
2353 av_log(ctx, AV_LOG_ERROR, "No memory type found for flags 0x%x\n",
2354 req_flags);
2355 return AVERROR(EINVAL);
2356 }
2357
2358 alloc_info.memoryTypeIndex = index;
2359
2360 ret = vk->AllocateMemory(dev_hwctx->act_dev, &alloc_info,
2361 dev_hwctx->alloc, mem);
2362 if (ret != VK_SUCCESS) {
2363 av_log(ctx, AV_LOG_ERROR, "Failed to allocate memory: %s\n",
2364 ff_vk_ret2str(ret));
2365 return AVERROR(ENOMEM);
2366 }
2367
2368 *mem_flags |= p->mprops.memoryTypes[index].propertyFlags;
2369
2370 return 0;
2371}
2372

Callers 2

alloc_bind_memFunction · 0.85

Calls 2

av_logFunction · 0.85
ff_vk_ret2strFunction · 0.85

Tested by

no test coverage detected