diff options
author | Lynne <dev@lynne.ee> | 2020-05-26 10:34:31 +0100 |
---|---|---|
committer | Lynne <dev@lynne.ee> | 2020-05-26 10:52:10 +0100 |
commit | 6bb718aabd648d9e2cb166364f9efae2ac245ecd (patch) | |
tree | 585ad7477f17f8829cdbed37fd2059df5a180be1 /libavutil | |
parent | 4dcb50c58a9c592b4296a3d26ebe2c61fc99ceac (diff) | |
download | ffmpeg-6bb718aabd648d9e2cb166364f9efae2ac245ecd.tar.gz |
hwcontext_vulkan: use dedicated allocation for buffers when necessary
Diffstat (limited to 'libavutil')
-rw-r--r-- | libavutil/hwcontext_vulkan.c | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/libavutil/hwcontext_vulkan.c b/libavutil/hwcontext_vulkan.c index 95c874a466..5976e33f03 100644 --- a/libavutil/hwcontext_vulkan.c +++ b/libavutil/hwcontext_vulkan.c @@ -2663,7 +2663,7 @@ static int create_buf(AVHWDeviceContext *ctx, AVBufferRef **buf, size_t imp_size { int err; VkResult ret; - VkMemoryRequirements req; + int use_ded_mem; AVVulkanDeviceContext *hwctx = ctx->hwctx; VulkanDevicePriv *p = ctx->internal->priv; @@ -2674,6 +2674,21 @@ static int create_buf(AVHWDeviceContext *ctx, AVBufferRef **buf, size_t imp_size .sharingMode = VK_SHARING_MODE_EXCLUSIVE, }; + VkBufferMemoryRequirementsInfo2 req_desc = { + .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2, + }; + VkMemoryDedicatedAllocateInfo ded_alloc = { + .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO, + .pNext = alloc_pnext, + }; + VkMemoryDedicatedRequirements ded_req = { + .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, + }; + VkMemoryRequirements2 req = { + .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, + .pNext = &ded_req, + }; + ImageBuffer *vkbuf = av_mallocz(sizeof(*vkbuf)); if (!vkbuf) return AVERROR(ENOMEM); @@ -2695,9 +2710,19 @@ static int create_buf(AVHWDeviceContext *ctx, AVBufferRef **buf, size_t imp_size return AVERROR_EXTERNAL; } - vkGetBufferMemoryRequirements(hwctx->act_dev, vkbuf->buf, &req); + req_desc.buffer = vkbuf->buf; + + vkGetBufferMemoryRequirements2(hwctx->act_dev, &req_desc, &req); + + /* In case the implementation prefers/requires dedicated allocation */ + use_ded_mem = ded_req.prefersDedicatedAllocation | + ded_req.requiresDedicatedAllocation; + if (use_ded_mem) + ded_alloc.buffer = vkbuf->buf; - err = alloc_mem(ctx, &req, flags, alloc_pnext, &vkbuf->flags, &vkbuf->mem); + err = alloc_mem(ctx, &req.memoryRequirements, flags, + use_ded_mem ? &ded_alloc : (void *)ded_alloc.pNext, + &vkbuf->flags, &vkbuf->mem); if (err) return err; |