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

Function alloc_bind_mem

libavutil/hwcontext_vulkan.c:2448–2515  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2446}
2447
2448static int alloc_bind_mem(AVHWFramesContext *hwfc, AVVkFrame *f,
2449 void *alloc_pnext, size_t alloc_pnext_stride)
2450{
2451 int img_cnt = 0, err;
2452 VkResult ret;
2453 AVHWDeviceContext *ctx = hwfc->device_ctx;
2454 VulkanDevicePriv *p = ctx->hwctx;
2455 AVVulkanDeviceContext *hwctx = &p->p;
2456 FFVulkanFunctions *vk = &p->vkctx.vkfn;
2457 VkBindImageMemoryInfo bind_info[AV_NUM_DATA_POINTERS] = { { 0 } };
2458
2459 while (f->img[img_cnt]) {
2460 int use_ded_mem;
2461 VkImageMemoryRequirementsInfo2 req_desc = {
2462 .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2,
2463 .image = f->img[img_cnt],
2464 };
2465 VkMemoryDedicatedAllocateInfo ded_alloc = {
2466 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
2467 .pNext = (void *)(((uint8_t *)alloc_pnext) + img_cnt*alloc_pnext_stride),
2468 };
2469 VkMemoryDedicatedRequirements ded_req = {
2470 .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
2471 };
2472 VkMemoryRequirements2 req = {
2473 .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
2474 .pNext = &ded_req,
2475 };
2476
2477 vk->GetImageMemoryRequirements2(hwctx->act_dev, &req_desc, &req);
2478
2479 if (f->tiling == VK_IMAGE_TILING_LINEAR)
2480 req.memoryRequirements.size = FFALIGN(req.memoryRequirements.size,
2481 p->props.properties.limits.minMemoryMapAlignment);
2482
2483 /* In case the implementation prefers/requires dedicated allocation */
2484 use_ded_mem = ded_req.prefersDedicatedAllocation |
2485 ded_req.requiresDedicatedAllocation;
2486 if (use_ded_mem)
2487 ded_alloc.image = f->img[img_cnt];
2488
2489 /* Allocate memory */
2490 if ((err = alloc_mem(ctx, &req.memoryRequirements,
2491 f->tiling == VK_IMAGE_TILING_LINEAR ?
2492 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT :
2493 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
2494 use_ded_mem ? &ded_alloc : (void *)ded_alloc.pNext,
2495 &f->flags, &f->mem[img_cnt])))
2496 return err;
2497
2498 f->size[img_cnt] = req.memoryRequirements.size;
2499 bind_info[img_cnt].sType = VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_INFO;
2500 bind_info[img_cnt].image = f->img[img_cnt];
2501 bind_info[img_cnt].memory = f->mem[img_cnt];
2502
2503 img_cnt++;
2504 }
2505

Callers 1

vulkan_pool_allocFunction · 0.85

Calls 3

alloc_memFunction · 0.85
av_logFunction · 0.85
ff_vk_ret2strFunction · 0.85

Tested by

no test coverage detected