[FFmpeg-cvslog] lavfi/vulkan: use dedicated allocation for buffers when necessary

Lynne git at videolan.org
Tue May 26 12:58:33 EEST 2020


ffmpeg | branch: master | Lynne <dev at lynne.ee> | Mon May 25 15:36:41 2020 +0100| [fb49d5c0b18c7cdb2d6c324c3d92b5aaebd74ef6] | committer: Lynne

lavfi/vulkan: use dedicated allocation for buffers when necessary

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fb49d5c0b18c7cdb2d6c324c3d92b5aaebd74ef6
---

 libavfilter/vulkan.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/libavfilter/vulkan.c b/libavfilter/vulkan.c
index 301ee4354f..c3badaee29 100644
--- a/libavfilter/vulkan.c
+++ b/libavfilter/vulkan.c
@@ -152,7 +152,7 @@ int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size,
 {
     int err;
     VkResult ret;
-    VkMemoryRequirements req;
+    int use_ded_mem;
     VulkanFilterContext *s = avctx->priv;
 
     VkBufferCreateInfo buf_spawn = {
@@ -164,6 +164,21 @@ int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size,
                                 but should be ok */
     };
 
+    VkBufferMemoryRequirementsInfo2 req_desc = {
+        .sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
+    };
+    VkMemoryDedicatedAllocateInfo ded_alloc = {
+        .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
+        .pNext = NULL,
+    };
+    VkMemoryDedicatedRequirements ded_req = {
+        .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS,
+    };
+    VkMemoryRequirements2 req = {
+        .sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
+        .pNext = &ded_req,
+    };
+
     ret = vkCreateBuffer(s->hwctx->act_dev, &buf_spawn, NULL, &buf->buf);
     if (ret != VK_SUCCESS) {
         av_log(avctx, AV_LOG_ERROR, "Failed to create buffer: %s\n",
@@ -171,9 +186,19 @@ int ff_vk_create_buf(AVFilterContext *avctx, FFVkBuffer *buf, size_t size,
         return AVERROR_EXTERNAL;
     }
 
-    vkGetBufferMemoryRequirements(s->hwctx->act_dev, buf->buf, &req);
+    req_desc.buffer = buf->buf;
+
+    vkGetBufferMemoryRequirements2(s->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 = buf->buf;
 
-    err = vk_alloc_mem(avctx, &req, flags, NULL, &buf->flags, &buf->mem);
+    err = vk_alloc_mem(avctx, &req.memoryRequirements, flags,
+                       use_ded_mem ? &ded_alloc : (void *)ded_alloc.pNext,
+                       &buf->flags, &buf->mem);
     if (err)
         return err;
 



More information about the ffmpeg-cvslog mailing list